update:增加文档模式

This commit is contained in:
dlandy
2026-04-15 13:47:39 +08:00
parent e04405d0bc
commit 8973d46a42
38 changed files with 2193 additions and 83 deletions

View File

@@ -1,5 +1,26 @@
const { spawn, spawnSync } = require('child_process');
const IS_WINDOWS = process.platform === 'win32';
function quoteWindowsArg(value) {
const text = String(value ?? '');
if (text.length === 0) {
return '""';
}
if (!/[\s"&()^<>|]/.test(text)) {
return text;
}
return `"${text
.replace(/(\\*)"/g, '$1$1\\"')
.replace(/(\\+)$/g, '$1$1')}"`;
}
function buildWindowsCommand(command, args) {
return [command, ...args].map(quoteWindowsArg).join(' ');
}
function normalizeWrappedEnv(name) {
const value = process.env[name];
if (!value || value.length < 2) {
@@ -14,11 +35,17 @@ function normalizeWrappedEnv(name) {
}
function run(command, args, options = {}) {
const result = spawnSync(command, args, {
stdio: 'inherit',
env: process.env,
...options,
});
const result = IS_WINDOWS
? spawnSync('cmd.exe', ['/d', '/s', '/c', buildWindowsCommand(command, args)], {
stdio: 'inherit',
env: process.env,
...options,
})
: spawnSync(command, args, {
stdio: 'inherit',
env: process.env,
...options,
});
if (result.error) {
throw result.error;
@@ -29,23 +56,34 @@ function run(command, args, options = {}) {
}
}
function launch(command, args, options = {}) {
return IS_WINDOWS
? spawn('cmd.exe', ['/d', '/s', '/c', buildWindowsCommand(command, args)], {
stdio: 'inherit',
env: process.env,
...options,
})
: spawn(command, args, {
stdio: 'inherit',
env: process.env,
...options,
});
}
function main() {
if (!process.env.DATABASE_URL) {
process.env.DATABASE_URL = 'file:./dev.db';
}
normalizeWrappedEnv('DATABASE_URL');
run(process.platform === 'win32' ? 'npx.cmd' : 'npx', ['prisma', 'migrate', 'deploy']);
run('npx', ['prisma', 'migrate', 'deploy']);
const args = process.argv.slice(2);
if (args.length === 0) {
return;
}
const child = spawn(args[0], args.slice(1), {
stdio: 'inherit',
env: process.env,
});
const child = launch(args[0], args.slice(1));
child.on('exit', (code, signal) => {
if (signal) {