Skip to content

Commit

Permalink
fix: setup failed on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Jul 23, 2022
1 parent 8262910 commit 08228ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"start": "node dist/index.js",
"build": "tsup",
"format": "prettier --write '**/*.{js,ts}' '!dist'",
"postinstall": "cd env/rs && cargo build --release --bin agent && rm target/release/agent && cd ../.. || true"
"postinstall": "node dist/index.js setup"
},
"files": [
"dist",
Expand Down
27 changes: 27 additions & 0 deletions src/commands/setup/index.ts
@@ -0,0 +1,27 @@
import path from "node:path";
import fs from "node:fs";
import { execSync } from "node:child_process";
import { OptionValues, Command } from "commander";

export default function setup(opts: OptionValues, cmd: Command) {
console.log("Setting up ...");

const dir = path.resolve(__dirname, "..", "env", "rs");
try {
execSync("cargo build --release --bin agent", {
cwd: dir,
stdio: process.env.VERBOSE ? "inherit" : "ignore",
});
fs.rmSync(path.resolve(dir, "target", "release", "agent"));
} catch (err) {
if (process.env.VERBOSE) {
console.error(
`Rust deps pre-build failed, but it should not be a problem: ${
(err as Error).message
}`,
);
}
}

console.log("Setup complete.");
}
2 changes: 2 additions & 0 deletions src/index.ts
Expand Up @@ -9,6 +9,7 @@ import test from "./commands/test";
import run from "./commands/run";
import env from "./commands/env";
import perf from "./commands/perf";
import setup from "./commands/setup";

const package_info = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"),
Expand All @@ -18,6 +19,7 @@ const program = new commander.Command().version(`${package_info.name} ${package_

program.command("check").description("check for language support").action(check);
program.command("perf").description("run performance tests").action(perf);
program.command("setup").description("setup (optional)").action(setup);

program
.command("env")
Expand Down

0 comments on commit 08228ae

Please sign in to comment.