2022-05-18 16:40:55 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
const { resolve } = require('path');
|
2023-11-16 04:33:56 +00:00
|
|
|
const fs = require('fs');
|
2023-09-03 02:59:33 +00:00
|
|
|
const chalk = require('chalk');
|
2023-09-15 00:51:20 +00:00
|
|
|
const { genTsConfigPaths } = require('../src/util');
|
2022-05-18 16:40:55 +00:00
|
|
|
|
|
|
|
const env = {
|
|
|
|
APP_ENV: 'development',
|
|
|
|
APP_KEY: 'test-jwt-secret',
|
|
|
|
APP_PORT: 13000,
|
|
|
|
API_BASE_PATH: '/api/',
|
|
|
|
DB_DIALECT: 'sqlite',
|
|
|
|
DB_STORAGE: 'storage/db/nocobase.sqlite',
|
2022-06-01 04:25:21 +00:00
|
|
|
DB_TIMEZONE: '+00:00',
|
2022-05-18 16:40:55 +00:00
|
|
|
DEFAULT_STORAGE_TYPE: 'local',
|
|
|
|
LOCAL_STORAGE_DEST: 'storage/uploads',
|
2023-09-12 14:39:23 +00:00
|
|
|
PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
|
2022-09-26 15:47:07 +00:00
|
|
|
MFSU_AD: 'none',
|
2023-09-12 14:39:23 +00:00
|
|
|
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
|
2022-12-02 06:23:07 +00:00
|
|
|
PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
|
2023-08-01 16:07:52 +00:00
|
|
|
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
|
2023-09-13 04:21:29 +00:00
|
|
|
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
|
2022-05-18 16:40:55 +00:00
|
|
|
};
|
|
|
|
|
2022-06-14 07:46:48 +00:00
|
|
|
if (!process.env.APP_ENV_PATH && process.argv[2] && process.argv[2] === 'test') {
|
2023-11-16 04:33:56 +00:00
|
|
|
if (fs.existsSync(resolve(process.cwd(), '.env.test'))) {
|
2022-06-14 07:46:48 +00:00
|
|
|
process.env.APP_ENV_PATH = '.env.test';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-16 04:33:56 +00:00
|
|
|
if (process.argv[2] === 'e2e') {
|
|
|
|
// 用于存放 playwright 自动生成的相关的文件
|
|
|
|
if (!fs.existsSync('playwright')) {
|
|
|
|
fs.mkdirSync('playwright');
|
|
|
|
}
|
|
|
|
if (!fs.existsSync('.env.e2e') && fs.existsSync('.env.e2e.example')) {
|
|
|
|
const env = fs.readFileSync('.env.e2e.example');
|
|
|
|
fs.writeFileSync('.env.e2e', env);
|
|
|
|
}
|
|
|
|
if (!fs.existsSync('.env.e2e')) {
|
|
|
|
throw new Error('Please create .env.e2e file first!');
|
|
|
|
}
|
|
|
|
process.env.APP_ENV_PATH = '.env.e2e';
|
|
|
|
}
|
|
|
|
|
2023-09-15 00:51:20 +00:00
|
|
|
genTsConfigPaths();
|
|
|
|
|
2022-05-18 16:40:55 +00:00
|
|
|
dotenv.config({
|
|
|
|
path: resolve(process.cwd(), process.env.APP_ENV_PATH || '.env'),
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const key in env) {
|
|
|
|
if (!process.env[key]) {
|
|
|
|
process.env[key] = env[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-16 04:33:56 +00:00
|
|
|
if (process.argv[2] === 'e2e' && !process.env.APP_BASE_URL) {
|
|
|
|
process.env.APP_BASE_URL = `http://127.0.0.1:${process.env.APP_PORT}`;
|
|
|
|
}
|
|
|
|
|
2023-09-03 02:59:33 +00:00
|
|
|
if (require('semver').satisfies(process.version, '<16')) {
|
|
|
|
console.error(chalk.red('[nocobase cli]: Node.js version must be >= 16'));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2023-02-10 03:16:36 +00:00
|
|
|
if (require('semver').satisfies(process.version, '>16') && !process.env.UNSET_NODE_OPTIONS) {
|
|
|
|
if (process.env.NODE_OPTIONS) {
|
|
|
|
let opts = process.env.NODE_OPTIONS;
|
|
|
|
if (!opts.includes('--openssl-legacy-provider')) {
|
|
|
|
opts = opts + ' --openssl-legacy-provider';
|
|
|
|
}
|
|
|
|
if (!opts.includes('--no-experimental-fetch')) {
|
|
|
|
opts = opts + ' --no-experimental-fetch';
|
|
|
|
}
|
|
|
|
process.env.NODE_OPTIONS = opts;
|
|
|
|
} else {
|
|
|
|
process.env.NODE_OPTIONS = '--openssl-legacy-provider --no-experimental-fetch';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 16:40:55 +00:00
|
|
|
const cli = require('../src/cli');
|
|
|
|
|
|
|
|
cli.parse(process.argv);
|