Skip to content

Commit cd07fbb

Browse files
author
Akos Kitta
committed
build: use execFileSync for npm scripts
Signed-off-by: Akos Kitta <[email protected]>
1 parent 83c13ee commit cd07fbb

File tree

4 files changed

+223
-247
lines changed

4 files changed

+223
-247
lines changed

Diff for: arduino-ide-extension/scripts/download-examples.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,29 @@
44
const version = '1.10.0';
55

66
(async () => {
7-
const os = require('os');
8-
const { promises: fs } = require('fs');
9-
const path = require('path');
7+
const os = require('node:os');
8+
const { promises: fs } = require('node:fs');
9+
const path = require('node:path');
1010
const shell = require('shelljs');
1111
const { v4 } = require('uuid');
12+
const { exec } = require('./utils');
1213

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

18-
if (
19-
shell.exec(
20-
`git clone https://github.com/arduino/arduino-examples.git ${repository}`
21-
).code !== 0
22-
) {
23-
shell.exit(1);
24-
}
19+
exec(
20+
'git',
21+
['clone', 'https://github.com/arduino/arduino-examples.git', repository],
22+
shell
23+
);
2524

26-
if (
27-
shell.exec(`git -C ${repository} checkout tags/${version} -b ${version}`)
28-
.code !== 0
29-
) {
30-
shell.exit(1);
31-
}
25+
exec(
26+
'git',
27+
['-C', repository, 'checkout', `tags/${version}`, '-b', version],
28+
shell
29+
);
3230

3331
const destination = path.join(__dirname, '..', 'Examples');
3432
shell.mkdir('-p', destination);

Diff for: arduino-ide-extension/scripts/download-fwuploader.js

+3-79
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// @ts-check
22

33
(async () => {
4-
const fs = require('fs');
5-
const path = require('path');
6-
const temp = require('temp');
4+
const path = require('node:path');
75
const shell = require('shelljs');
86
const semver = require('semver');
97
const downloader = require('./downloader');
8+
const { taskBuildFromGit } = require('./utils');
109

1110
const version = (() => {
1211
const pkg = require(path.join(__dirname, '..', 'package.json'));
@@ -86,81 +85,6 @@
8685
shell.exit(1);
8786
}
8887
} else {
89-
// We assume an object with `owner`, `repo`, commitish?` properties.
90-
const { owner, repo, commitish } = version;
91-
if (!owner) {
92-
shell.echo(`Could not retrieve 'owner' from ${JSON.stringify(version)}`);
93-
shell.exit(1);
94-
}
95-
if (!repo) {
96-
shell.echo(`Could not retrieve 'repo' from ${JSON.stringify(version)}`);
97-
shell.exit(1);
98-
}
99-
const url = `https://github.com/${owner}/${repo}.git`;
100-
shell.echo(
101-
`Building Firmware Uploader from ${url}. Commitish: ${
102-
commitish ? commitish : 'HEAD'
103-
}`
104-
);
105-
106-
if (fs.existsSync(destinationPath)) {
107-
shell.echo(
108-
`Skipping the Firmware Uploader build because it already exists: ${destinationPath}`
109-
);
110-
return;
111-
}
112-
113-
if (shell.mkdir('-p', buildFolder).code !== 0) {
114-
shell.echo('Could not create build folder.');
115-
shell.exit(1);
116-
}
117-
118-
const tempRepoPath = temp.mkdirSync();
119-
shell.echo(`>>> Cloning Firmware Uploader source to ${tempRepoPath}...`);
120-
if (shell.exec(`git clone ${url} ${tempRepoPath}`).code !== 0) {
121-
shell.exit(1);
122-
}
123-
shell.echo('<<< Cloned Firmware Uploader repo.');
124-
125-
if (commitish) {
126-
shell.echo(`>>> Checking out ${commitish}...`);
127-
if (
128-
shell.exec(`git -C ${tempRepoPath} checkout ${commitish}`).code !== 0
129-
) {
130-
shell.exit(1);
131-
}
132-
shell.echo(`<<< Checked out ${commitish}.`);
133-
}
134-
135-
shell.echo(`>>> Building the Firmware Uploader...`);
136-
if (shell.exec('go build', { cwd: tempRepoPath }).code !== 0) {
137-
shell.exit(1);
138-
}
139-
shell.echo('<<< Firmware Uploader build done.');
140-
141-
if (!fs.existsSync(path.join(tempRepoPath, fwuploderName))) {
142-
shell.echo(
143-
`Could not find the Firmware Uploader at ${path.join(
144-
tempRepoPath,
145-
fwuploderName
146-
)}.`
147-
);
148-
shell.exit(1);
149-
}
150-
151-
const builtFwUploaderPath = path.join(tempRepoPath, fwuploderName);
152-
shell.echo(
153-
`>>> Copying Firmware Uploader from ${builtFwUploaderPath} to ${destinationPath}...`
154-
);
155-
if (shell.cp(builtFwUploaderPath, destinationPath).code !== 0) {
156-
shell.exit(1);
157-
}
158-
shell.echo(`<<< Copied the Firmware Uploader.`);
159-
160-
shell.echo('<<< Verifying Firmware Uploader...');
161-
if (!fs.existsSync(destinationPath)) {
162-
shell.exit(1);
163-
}
164-
shell.echo('>>> Verified Firmware Uploader.');
88+
taskBuildFromGit(version, destinationPath, 'Firmware Uploader');
16589
}
16690
})();

0 commit comments

Comments
 (0)