Skip to content

Commit

Permalink
build: use execFileSync for npm scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta authored and kittaakos committed May 9, 2023
1 parent 192aac5 commit 33ab2a6
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 247 deletions.
30 changes: 14 additions & 16 deletions arduino-ide-extension/scripts/download-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@
const version = '1.10.0';

(async () => {
const os = require('os');
const { promises: fs } = require('fs');
const path = require('path');
const os = require('node:os');
const { promises: fs } = require('node:fs');
const path = require('node:path');
const shell = require('shelljs');
const { v4 } = require('uuid');
const { exec } = require('./utils');

const repository = path.join(os.tmpdir(), `${v4()}-arduino-examples`);
if (shell.mkdir('-p', repository).code !== 0) {
shell.exit(1);
}

if (
shell.exec(
`git clone https://github.com/arduino/arduino-examples.git ${repository}`
).code !== 0
) {
shell.exit(1);
}
exec(
'git',
['clone', 'https://github.com/arduino/arduino-examples.git', repository],
shell
);

if (
shell.exec(`git -C ${repository} checkout tags/${version} -b ${version}`)
.code !== 0
) {
shell.exit(1);
}
exec(
'git',
['-C', repository, 'checkout', `tags/${version}`, '-b', version],
shell
);

const destination = path.join(__dirname, '..', 'Examples');
shell.mkdir('-p', destination);
Expand Down
82 changes: 3 additions & 79 deletions arduino-ide-extension/scripts/download-fwuploader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-check

(async () => {
const fs = require('fs');
const path = require('path');
const temp = require('temp');
const path = require('node:path');
const shell = require('shelljs');
const semver = require('semver');
const downloader = require('./downloader');
const { taskBuildFromGit } = require('./utils');

const version = (() => {
const pkg = require(path.join(__dirname, '..', 'package.json'));
Expand Down Expand Up @@ -86,81 +85,6 @@
shell.exit(1);
}
} else {
// We assume an object with `owner`, `repo`, commitish?` properties.
const { owner, repo, commitish } = version;
if (!owner) {
shell.echo(`Could not retrieve 'owner' from ${JSON.stringify(version)}`);
shell.exit(1);
}
if (!repo) {
shell.echo(`Could not retrieve 'repo' from ${JSON.stringify(version)}`);
shell.exit(1);
}
const url = `https://github.com/${owner}/${repo}.git`;
shell.echo(
`Building Firmware Uploader from ${url}. Commitish: ${
commitish ? commitish : 'HEAD'
}`
);

if (fs.existsSync(destinationPath)) {
shell.echo(
`Skipping the Firmware Uploader build because it already exists: ${destinationPath}`
);
return;
}

if (shell.mkdir('-p', buildFolder).code !== 0) {
shell.echo('Could not create build folder.');
shell.exit(1);
}

const tempRepoPath = temp.mkdirSync();
shell.echo(`>>> Cloning Firmware Uploader source to ${tempRepoPath}...`);
if (shell.exec(`git clone ${url} ${tempRepoPath}`).code !== 0) {
shell.exit(1);
}
shell.echo('<<< Cloned Firmware Uploader repo.');

if (commitish) {
shell.echo(`>>> Checking out ${commitish}...`);
if (
shell.exec(`git -C ${tempRepoPath} checkout ${commitish}`).code !== 0
) {
shell.exit(1);
}
shell.echo(`<<< Checked out ${commitish}.`);
}

shell.echo(`>>> Building the Firmware Uploader...`);
if (shell.exec('go build', { cwd: tempRepoPath }).code !== 0) {
shell.exit(1);
}
shell.echo('<<< Firmware Uploader build done.');

if (!fs.existsSync(path.join(tempRepoPath, fwuploderName))) {
shell.echo(
`Could not find the Firmware Uploader at ${path.join(
tempRepoPath,
fwuploderName
)}.`
);
shell.exit(1);
}

const builtFwUploaderPath = path.join(tempRepoPath, fwuploderName);
shell.echo(
`>>> Copying Firmware Uploader from ${builtFwUploaderPath} to ${destinationPath}...`
);
if (shell.cp(builtFwUploaderPath, destinationPath).code !== 0) {
shell.exit(1);
}
shell.echo(`<<< Copied the Firmware Uploader.`);

shell.echo('<<< Verifying Firmware Uploader...');
if (!fs.existsSync(destinationPath)) {
shell.exit(1);
}
shell.echo('>>> Verified Firmware Uploader.');
taskBuildFromGit(version, destinationPath, 'Firmware Uploader');
}
})();
Loading

0 comments on commit 33ab2a6

Please # to comment.