fix(build): make command compatible on windows

This commit is contained in:
kerms 2025-06-09 18:15:24 +02:00
parent fc9648ea8b
commit 9c6db50de2
2 changed files with 33 additions and 8 deletions

View File

@ -4,15 +4,15 @@
"private": true,
"type": "module",
"scripts": {
"dev": ". ./set_env.sh && vite",
"devh": ". ./set_env.sh && vite --host",
"build": "run-p type-check \"build-only {@}\" --",
"preview": ". ./set_env.sh && vite preview",
"previewh": ". ./set_env.sh && vite preview --host",
"build-only": ". ./set_env.sh && vite build",
"build:dev": ". ./set_env.sh && vite build --mode development",
"dev": "node scripts/gen-env.mjs",
"devh": "node scripts/gen-env.mjs --host",
"build": "run-p type-check build-only --",
"preview": "node scripts/gen-env.mjs preview",
"previewh": "node scripts/gen-env.mjs preview --host",
"build-only": "node scripts/gen-env.mjs build",
"build:dev": "NODE_ENV=development node scripts/gen-env.mjs build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"lint": "eslint . --ext .vue,.js,.jsx,.ts,.tsx --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {

25
scripts/gen-env.mjs Normal file
View File

@ -0,0 +1,25 @@
import { execSync, spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const gitTag = execSync('git describe --tags')
.toString().trim().split('-').slice(0, 2).join('-');
const lastCommit = execSync('git log -1 --format=%cd')
.toString().trim();
// run whatever came after “npm run dev …”
const argsFromNpm = process.argv.slice(2); // e.g. ["--host"]
spawn(
process.platform === 'win32' ? 'npx.cmd' : 'npx',
['vite', ...argsFromNpm],
{
stdio: 'inherit',
env: {
...process.env,
VITE_APP_GIT_TAG: gitTag,
VITE_APP_LAST_COMMIT: lastCommit
}
}
).on('exit', code => process.exit(code));