[chore] add script to build all rust scripts

This commit is contained in:
MathieuG-P
2024-03-08 16:31:20 +01:00
parent 7c034550fb
commit d0fee6aaca
3 changed files with 36 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
import path from 'path';
import { copyFileSync, existsSync, readdirSync } from 'fs-extra';
import { execSync } from 'child_process';
const eternalsFolder = path.join(__dirname, '..', '..', 'externals');
// Get rust project folders from externals
const rustProjects = readdirSync(eternalsFolder).filter(folder => existsSync(path.join(eternalsFolder, folder, 'Cargo.toml')));
// Build each rust project in release mode
rustProjects.forEach(project => {
console.log(`Building ${project}`);
execSync(`cargo build --release`, {
cwd: path.join(eternalsFolder, project),
stdio: 'inherit',
});
});
// Copy the built files exe to the assests/scripts folder
rustProjects.forEach(project => {
// read the project name from Cargo.toml using toml parser
const projectMetadata = execSync('cargo metadata --no-deps --format-version 1', {
cwd: path.join(eternalsFolder, project),
stdio: 'pipe',
});
const projectMetadataJson = JSON.parse(projectMetadata);
const projectName = projectMetadataJson.packages[0].name;
const source = path.join(eternalsFolder, project, 'target', 'release', `${projectName}.exe`);
const destination = path.join(__dirname, '..', '..', 'assets', 'scripts', `${projectName}.exe`);
console.log(`Copying ${source} to ${destination}`);
copyFileSync(source, destination);
});
+1
View File
@@ -3,6 +3,7 @@
"description": "Manage maps, mods and more for Beat Saber",
"main": "./src/main/main.ts",
"scripts": {
"build-rust-scripts": "node -r esbuild-register ./.erb/scripts/build-rust-scripts.js",
"build": "concurrently \"npm run build:main\" \"npm run build:renderer\"",
"build:dll": "cross-env NODE_ENV=development webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts",
"build:main": "cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.main.prod.ts",
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "bs-manager",
"version": "1.4.4",
"version": "1.5.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "bs-manager",
"version": "1.4.4",
"version": "1.5.0",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {