Skip to content

Commit

Permalink
Replace inline bash script with a typescript file
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed May 12, 2024
1 parent 134bf04 commit 4d9a6a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions packages/scanner/build-selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-console */
import { exec } from 'child_process';

const targetArch = process.env.npm_config_target_arch ?? 'x64';

const commands: { [key: string]: string } = {
'arm64': 'npm run build-macos-arm64',
'x64': 'npm run build-macos'
};

const defaultCommand = 'npm run build-linux-windows';

const commandToRun = commands[targetArch] || defaultCommand;

exec(commandToRun, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error.message}`);
return;
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
});
5 changes: 3 additions & 2 deletions packages/scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "index.d.ts",
"scripts": {
"build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics",
"build-release": "if [ \"$npm_config_target_arch\" == \"arm64\" ]; then npm run build-macos-arm64; elif [ \"$npm_config_target_arch\" == \"x64\" ]; then npm run build-macos; else npm run build-linux-windows; fi",
"build-release": "ts-node build-selector.ts",
"build-linux-windows": "cargo-cp-artifact -nc index.node -- cargo build --release --message-format=json-render-diagnostics",
"build-macos": "cargo-cp-artifact -nc index.node -- cargo build --target x86_64-apple-darwin --release --message-format=json-render-diagnostics",
"build-macos-arm64": "cargo-cp-artifact -nc index.node -- cargo build --target aarch64-apple-darwin --release --message-format=json-render-diagnostics",
Expand All @@ -26,6 +26,7 @@
},
"homepage": "https://github.com/nukeop/nuclear#readme",
"devDependencies": {
"cargo-cp-artifact": "^0.1"
"cargo-cp-artifact": "^0.1",
"ts-node": "^10.9.2"
}
}

0 comments on commit 4d9a6a0

Please sign in to comment.