mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-04-25 15:57:20 +00:00

To fix all security vulnerabilities detected by `Dependabot`. - remove `shelljs`. replace with `fs` and `console`. - remove `uuid`. replace with `@phosphor/coreutils`. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
160 lines
5.1 KiB
JavaScript
Executable File
160 lines
5.1 KiB
JavaScript
Executable File
// @ts-check
|
|
// The links to the downloads as of today (28.08.2019) are the following:
|
|
// - https://downloads.arduino.cc/arduino-language-server/nightly/arduino-language-server_${SUFFIX}
|
|
// - https://downloads.arduino.cc/arduino-language-server/clangd/clangd_${VERSION}_${SUFFIX}
|
|
|
|
(() => {
|
|
const path = require('path');
|
|
const downloader = require('./downloader');
|
|
const { goBuildFromGit } = require('./utils');
|
|
|
|
const [DEFAULT_LS_VERSION, DEFAULT_CLANGD_VERSION] = (() => {
|
|
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
if (!pkg) return [undefined, undefined];
|
|
|
|
const { arduino } = pkg;
|
|
if (!arduino) return [undefined, undefined];
|
|
|
|
const { clangd } = arduino;
|
|
const languageServer = arduino['arduino-language-server'];
|
|
if (!languageServer) return [undefined, undefined];
|
|
if (!clangd) return [undefined, undefined];
|
|
|
|
return [languageServer.version, clangd.version];
|
|
})();
|
|
|
|
if (!DEFAULT_LS_VERSION) {
|
|
console.log(
|
|
`Could not retrieve Arduino Language Server version info from the 'package.json'.`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!DEFAULT_CLANGD_VERSION) {
|
|
console.log(
|
|
`Could not retrieve clangd version info from the 'package.json'.`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const yargs = require('@theia/core/shared/yargs')
|
|
.option('ls-version', {
|
|
alias: 'lv',
|
|
default: DEFAULT_LS_VERSION,
|
|
describe: `The version of the 'arduino-language-server' to download. Defaults to ${DEFAULT_LS_VERSION}.`,
|
|
})
|
|
.option('clangd-version', {
|
|
alias: 'cv',
|
|
default: DEFAULT_CLANGD_VERSION,
|
|
choices: [DEFAULT_CLANGD_VERSION, 'snapshot_20210124'],
|
|
describe: `The version of 'clangd' to download. Defaults to ${DEFAULT_CLANGD_VERSION}.`,
|
|
})
|
|
.option('force-download', {
|
|
alias: 'fd',
|
|
default: false,
|
|
describe: `If set, this script force downloads the 'arduino-language-server' even if it already exists on the file system.`,
|
|
})
|
|
.version(false)
|
|
.parse();
|
|
|
|
const lsVersion = yargs['ls-version'];
|
|
const clangdVersion = yargs['clangd-version'];
|
|
const force = yargs['force-download'];
|
|
const { platform, arch } = process;
|
|
const platformArch = platform + '-' + arch;
|
|
const resourcesFolder = path.join(
|
|
__dirname,
|
|
'..',
|
|
'src',
|
|
'node',
|
|
'resources'
|
|
);
|
|
const lsExecutablePath = path.join(
|
|
resourcesFolder,
|
|
`arduino-language-server${platform === 'win32' ? '.exe' : ''}`
|
|
);
|
|
let clangdExecutablePath, clangFormatExecutablePath, lsSuffix, clangdSuffix;
|
|
|
|
switch (platformArch) {
|
|
case 'darwin-x64':
|
|
clangdExecutablePath = path.join(resourcesFolder, 'clangd');
|
|
clangFormatExecutablePath = path.join(resourcesFolder, 'clang-format');
|
|
lsSuffix = 'macOS_64bit.tar.gz';
|
|
clangdSuffix = 'macOS_64bit';
|
|
break;
|
|
case 'darwin-arm64':
|
|
clangdExecutablePath = path.join(resourcesFolder, 'clangd');
|
|
clangFormatExecutablePath = path.join(resourcesFolder, 'clang-format');
|
|
lsSuffix = 'macOS_ARM64.tar.gz';
|
|
clangdSuffix = 'macOS_ARM64';
|
|
break;
|
|
case 'linux-x64':
|
|
clangdExecutablePath = path.join(resourcesFolder, 'clangd');
|
|
clangFormatExecutablePath = path.join(resourcesFolder, 'clang-format');
|
|
lsSuffix = 'Linux_64bit.tar.gz';
|
|
clangdSuffix = 'Linux_64bit';
|
|
break;
|
|
case 'linux-arm64':
|
|
clangdExecutablePath = path.join(resourcesFolder, 'clangd');
|
|
clangFormatExecutablePath = path.join(resourcesFolder, 'clang-format');
|
|
lsSuffix = 'Linux_ARM64.tar.gz';
|
|
clangdSuffix = 'Linux_ARM64';
|
|
break;
|
|
case 'win32-x64':
|
|
clangdExecutablePath = path.join(resourcesFolder, 'clangd.exe');
|
|
clangFormatExecutablePath = path.join(
|
|
resourcesFolder,
|
|
'clang-format.exe'
|
|
);
|
|
lsSuffix = 'Windows_64bit.zip';
|
|
clangdSuffix = 'Windows_64bit';
|
|
break;
|
|
default:
|
|
throw new Error(`Unsupported platform/arch: ${platformArch}.`);
|
|
}
|
|
if (!lsSuffix || !clangdSuffix) {
|
|
console.log(
|
|
`The arduino-language-server is not available for ${platform} ${arch}.`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (typeof lsVersion === 'string') {
|
|
const lsUrl = `https://downloads.arduino.cc/arduino-language-server/${
|
|
lsVersion === 'nightly'
|
|
? 'nightly/arduino-language-server'
|
|
: 'arduino-language-server_' + lsVersion
|
|
}_${lsSuffix}`;
|
|
downloader.downloadUnzipAll(
|
|
lsUrl,
|
|
resourcesFolder,
|
|
lsExecutablePath,
|
|
force
|
|
);
|
|
} else {
|
|
goBuildFromGit(lsVersion, lsExecutablePath, 'language-server');
|
|
}
|
|
|
|
const clangdUrl = `https://downloads.arduino.cc/tools/clangd_${clangdVersion}_${clangdSuffix}.tar.bz2`;
|
|
downloader.downloadUnzipAll(
|
|
clangdUrl,
|
|
resourcesFolder,
|
|
clangdExecutablePath,
|
|
force,
|
|
{
|
|
strip: 1,
|
|
}
|
|
); // `strip`: the new clangd (12.x) is zipped into a folder, so we have to strip the outmost folder.
|
|
|
|
const clangdFormatUrl = `https://downloads.arduino.cc/tools/clang-format_${clangdVersion}_${clangdSuffix}.tar.bz2`;
|
|
downloader.downloadUnzipAll(
|
|
clangdFormatUrl,
|
|
resourcesFolder,
|
|
clangFormatExecutablePath,
|
|
force,
|
|
{
|
|
strip: 1,
|
|
}
|
|
);
|
|
})();
|