Skip to content

Commit

Permalink
Preserve exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
BarnabyShearer committed Mar 28, 2024
1 parent c3a9176 commit 7ea50bb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
10 changes: 5 additions & 5 deletions bin/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const release = process.argv[3];

fs.writeFileSync("src/release.ts", `export default "${release}";`);

await cmd(`wrangler secret:bulk /dev/stdin --env ${env}`);
await cmd(
cmd(`wrangler secret:bulk /dev/stdin --env ${env}`);
cmd(
`sentry-cli releases --org change-engine --project ${basename(process.cwd())} new ${release} --finalize`,
);

await cmd(
cmd(
`sentry-cli releases --org change-engine --project ${basename(process.cwd())} set-commits ${release}`,
);

await cmd(`wrangler deploy --env ${env} --outdir dist`);
cmd(`wrangler deploy --env ${env} --outdir dist`);

await cmd(
cmd(
`sentry-cli sourcemaps --org change-engine --project ${basename(process.cwd())} upload --release="${release}" dist`,
);
2 changes: 1 addition & 1 deletion bin/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"use strict";
import { cmd } from "../src/cmd.mjs";

await cmd("wrangler dev");
cmd("wrangler dev");
2 changes: 1 addition & 1 deletion bin/format.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"use strict";
import { cmd } from "../src/cmd.mjs";

await cmd("prettier --write . !tsconfig.json !test/api.d.ts");
cmd("prettier --write . !tsconfig.json !test/api.d.ts");
4 changes: 2 additions & 2 deletions bin/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"use strict";
import { cmd } from "../src/cmd.mjs";

await cmd("eslint --max-warnings=0 src");
await cmd("prettier --check . !tsconfig.json !test/api.d.ts");
cmd("eslint --max-warnings=0 src");
cmd("prettier --check . !tsconfig.json !test/api.d.ts");
6 changes: 3 additions & 3 deletions bin/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import openapiTS from "openapi-typescript";
import { Miniflare } from "miniflare";

if (fs.existsSync("wrangler.toml")) {
await cmd("wrangler deploy --dry-run --outdir=dist");
cmd("wrangler deploy --dry-run --outdir=dist");
const miniflare = new Miniflare({
modules: true,
scriptPath: "dist/index.js",
});
const request = await fetch(
const request = fetch(
`${await miniflare.ready}doc`,
{ SENTRY_DSN: null, SENTRY_ENVIRONMENT: null },
null,
Expand All @@ -21,7 +21,7 @@ if (fs.existsSync("wrangler.toml")) {
await miniflare.dispose();
fs.writeFileSync("test/api.d.ts", types);
}
await cmd("vitest --globals --no-file-parallelism", [
cmd("vitest --globals --no-file-parallelism", [
...(!process.argv.slice(2).includes("-w") &&
!process.argv.slice(2).includes("--watch")
? ["--run"]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "two-stroke",
"packageManager": "[email protected]",
"type": "module",
"version": "1.0.10",
"version": "1.0.11",
"devDependencies": {
"@types/eslint": "^8.56.5",
"@types/node": "^20.11.25",
Expand Down
17 changes: 10 additions & 7 deletions src/cmd.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { spawn } from "child_process";
import { spawnSync } from "child_process";

export function cmd(cmd, args = []) {
const p = spawn(cmd.split(" ")[0], [...cmd.split(" ").slice(1), ...args], {
stdio: "inherit",
});
return new Promise((resolve) => {
p.on("exit", resolve);
});
const { error, status } = spawnSync(
cmd.split(" ")[0],
[...cmd.split(" ").slice(1), ...args],
{
stdio: "inherit",
},
);
if (status) process.exit(status);
if (error) throw error;
}

0 comments on commit 7ea50bb

Please sign in to comment.