|
1 | 1 | // @ts-check
|
2 |
| -// The links to the downloads as of today (11.08.) are the followings: |
3 |
| -// - https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli-nightly-latest-${FILE_NAME} |
4 |
| -// - https://downloads.arduino.cc/arduino-cli/arduino-cli-latest-${FILE_NAME} |
| 2 | +// The links to the downloads as of today (19.08.) are the followings: |
| 3 | +// In order to get the latest nightly build for your platform use the following links replacing <DATE> with the current date, using the format YYYYMMDD (i.e for 2019/Aug/06 use 20190806 ) |
| 4 | +// Linux 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Linux_64bit.tar.gz |
| 5 | +// Linux ARM 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Linux_ARM64.tar.gz |
| 6 | +// Windows 64 bit: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_Windows_64bit.zip |
| 7 | +// Mac OSX: https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-<DATE>_macOS_64bit.tar.gz |
5 | 8 |
|
6 | 9 | (async () => {
|
7 | 10 |
|
8 |
| - const DEFAULT_VERSION = 'nightly'; |
| 11 | + // TODO: currently, the download dates are one day behind. |
| 12 | + // https://typefox.slack.com/archives/CJJHJCJSJ/p1567062276016400 |
| 13 | + const DEFAULT_VERSION = require('moment')().subtract(1, 'day').format('YYYYMMDD'); |
9 | 14 |
|
10 | 15 | const os = require('os');
|
11 | 16 | const fs = require('fs');
|
|
14 | 19 | const download = require('download');
|
15 | 20 | const decompress = require('decompress');
|
16 | 21 | const unzip = require('decompress-unzip');
|
17 |
| - const untarbz = require('decompress-tarbz2'); |
| 22 | + const untargz = require('decompress-targz'); |
18 | 23 |
|
19 | 24 | process.on('unhandledRejection', (reason, _) => {
|
20 | 25 | shell.echo(String(reason));
|
|
31 | 36 | .option('cli-version', {
|
32 | 37 | alias: 'cv',
|
33 | 38 | default: DEFAULT_VERSION,
|
34 |
| - choices: [ |
35 |
| - // 'latest', // TODO: How do we get the source for `latest`. Currently, `latest` is the `0.3.7-alpha.preview`. |
36 |
| - 'nightly' |
37 |
| - ], |
38 |
| - describe: `The version of the 'arduino-cli' to download. Defaults to ${DEFAULT_VERSION}.` |
| 39 | + describe: `The version of the 'arduino-cli' to download with the YYYYMMDD format. Defaults to ${DEFAULT_VERSION}.` |
39 | 40 | })
|
40 | 41 | .option('force-download', {
|
41 | 42 | alias: 'fd',
|
|
68 | 69 |
|
69 | 70 | const suffix = (() => {
|
70 | 71 | switch (platform) {
|
71 |
| - case 'darwin': return 'macosx.zip'; |
72 |
| - case 'win32': return 'windows.zip'; |
| 72 | + case 'darwin': return 'macOS_64bit.tar.gz'; |
| 73 | + case 'win32': return 'Windows_64bit.zip'; |
73 | 74 | case 'linux': {
|
74 | 75 | switch (arch) {
|
75 |
| - case 'arm64': return 'linuxarm.tar.bz2'; |
76 |
| - case 'x32': return 'linux32.tar.bz2'; |
77 |
| - case 'x64': return 'linux64.tar.bz2'; |
| 76 | + case 'arm64': return 'Linux_ARM64.tar.gz'; |
| 77 | + case 'x64': return 'Linux_64bit.tar.gz'; |
78 | 78 | default: return undefined;
|
79 | 79 | }
|
80 | 80 | }
|
|
86 | 86 | shell.exit(1);
|
87 | 87 | }
|
88 | 88 |
|
89 |
| - const url = `https://downloads.arduino.cc/arduino-cli/${version === 'nightly' ? 'nightly/' : ''}arduino-cli-${version}-latest-${suffix}`; |
| 89 | + const url = `https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-${version}_${suffix}`; |
90 | 90 | shell.echo(`>>> Downloading 'arduino-cli' from '${url}'...`);
|
91 | 91 | const data = await download(url);
|
92 | 92 | shell.echo(`<<< Download succeeded.`);
|
93 | 93 | shell.echo('>>> Decompressing CLI...');
|
94 | 94 | const files = await decompress(data, downloads, {
|
95 | 95 | plugins: [
|
96 | 96 | unzip(),
|
97 |
| - untarbz() |
| 97 | + untargz() |
98 | 98 | ]
|
99 | 99 | });
|
100 |
| - shell.echo('<<< Decompressing succeeded.'); |
101 |
| - |
102 |
| - if (files.length !== 1) { |
| 100 | + if (files.length === 0) { |
103 | 101 | shell.echo('Error ocurred when decompressing the CLI.');
|
104 | 102 | shell.exit(1);
|
105 | 103 | }
|
106 |
| - if (shell.mv('-f', path.join(downloads, files[0].path), cli).code !== 0) { |
| 104 | + const cliIndex = files.findIndex(f => f.path.startsWith('arduino-cli')); |
| 105 | + if (cliIndex === -1) { |
| 106 | + shell.echo('The downloaded artifact does not contains the CLI.'); |
| 107 | + shell.exit(1); |
| 108 | + } |
| 109 | + shell.echo('<<< Decompressing succeeded.'); |
| 110 | + |
| 111 | + if (shell.mv('-f', path.join(downloads, files[cliIndex].path), cli).code !== 0) { |
107 | 112 | shell.echo(`Could not move file to ${cli}.`);
|
108 | 113 | shell.exit(1);
|
109 | 114 | }
|
|
0 commit comments