update:增加文档模式
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user