Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 0155c71

Browse files
authored
Changing to use spawnSync, also fixing #95
Fixes #95
1 parent a454244 commit 0155c71

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

.bin/create-rust-webpack.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
#!/usr/bin/env node
22

3-
const { spawn } = require("child_process");
4-
const fs = require("fs");
3+
const { spawnSync } = require("child_process");
4+
const fs = require("fs");
5+
6+
function run(cmd, args, opts) {
7+
const output = spawnSync(cmd, args, opts);
8+
9+
if (output.error != null) {
10+
throw output.error;
11+
}
12+
13+
if (output.status !== 0) {
14+
throw new Error("Bad error code when running `" + cmd + " " + args.join(" ") + "`: " + output.status);
15+
}
16+
}
517

618
let folderName = '.';
719

820
if (process.argv.length >= 3) {
9-
folderName = process.argv[2];
21+
folderName = process.argv[2];
1022
if (!fs.existsSync(folderName)) {
1123
fs.mkdirSync(folderName);
1224
}
1325
}
1426

15-
const clone = spawn("git", ["clone", "https://github.com/rustwasm/rust-webpack-template.git", folderName]);
16-
17-
clone.on("close", (code) => {
18-
if (code !== 0) {
19-
handleError("install", code);
20-
} else {
21-
console.log(" 🦀 Rust + 🕸 WebAssembly + Webpack = ❤️ ");
22-
23-
const install = spawn('npm', ['install'], { cwd: folderName });
24-
install.on("close", (code) => {
25-
if (code !== 0) {
26-
handleError("install", code);
27-
} else {
28-
console.log(" Installed dependencies ✅ ");
29-
}
30-
});
31-
}
32-
});
27+
run("git", ["clone", "https://github.com/rustwasm/rust-webpack-template.git", folderName]);
3328

34-
function handleError(type, errCode) {
35-
// TODO(sven): handle error here
36-
console.error()
37-
process.exit(errCode);
38-
}
29+
console.log(" 🦀 Rust + 🕸 WebAssembly + Webpack = ❤️ ");
30+
31+
run("npm", ["install"], { cwd: folderName, shell: true });
32+
33+
console.log(" Installed dependencies ✅ ");

0 commit comments

Comments
 (0)