6a23e79f4c
dev deploys to /opt/dukang-staging (819x, *-test domains); main deploys to production. Staging uses full Mock with shared WeChat app ids. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
843 B
JavaScript
32 lines
843 B
JavaScript
const { config } = require('dotenv');
|
|
const { spawnSync } = require('child_process');
|
|
const { existsSync } = require('fs');
|
|
const { resolve } = require('path');
|
|
|
|
const apiRoot = resolve(__dirname, '..');
|
|
const envFile = process.env.DUKANG_ENV_FILE
|
|
?? (process.env.APP_ENV === 'staging' ? '.env.staging' : '.env.production');
|
|
const envPath = resolve(apiRoot, envFile);
|
|
|
|
if (!existsSync(envPath)) {
|
|
console.error(`[with-api-env] 未找到 ${envPath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
config({ path: envPath, override: true });
|
|
|
|
const args = process.argv.slice(2);
|
|
if (args.length === 0) {
|
|
console.error('用法: node scripts/with-api-env.cjs <command> [args...]');
|
|
process.exit(1);
|
|
}
|
|
|
|
const result = spawnSync(args[0], args.slice(1), {
|
|
cwd: apiRoot,
|
|
stdio: 'inherit',
|
|
env: process.env,
|
|
shell: true,
|
|
});
|
|
|
|
process.exit(result.status ?? 1);
|