mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
* refactor: plugin build and plugin template * refactor: plugins' deps * refactor: plugins bugs * feat: add plugin static middleware * fix: bugs * refactor: frontend plugin add from remote * refactor: delete useless app/client/plugins * fix: requirejs move to local * fix: tests case * refactor: add src/client and src/server dir check * fix: lodash tree shaking * refactor: add BUILD_TIP * refactor: add file size tip * fix: bugs * fix: bug * fix: change china-division * fix: change plugins response * fix: recover dynamicImport * fix: change server src entry * fix: test error * fix: plugins sourcemap => false * fix: production file error * refactor: change build tools to vite and tsup * fix: yarn.lock * fix: bugs * fix: server build bugs * fix: delete .fatherrc.ts * fix: bug * fix: bug * fix: bugs * fix: bugs * fix: bugs * refactor: add plugin d.ts * refactor: delete fatherrc * refactor: delete father scripts * refactor: build bug * fix: bug * fix: deps adjust * fix: add build tips * fix: bug * refactor: ignore plugins when build client * docs: update doc * refactor: docs and build * fix: bug * refactor: build deps * fix: add USER_REMOTE_PLUGIN env * feat: add plugin static cache * feat: add build deps cache * fix: bugs * test: add test * fix: add plugin depden on plugin tip * fix: adjust shouldDevDependencies * fix: deps * fix: ajust deps * fix: mobile style error * fix: map error * fix: test * fix: bug * feat: lodash and dayjs import from themself * feat: @emotion/css 、ahooks and lodash to global * fix: theme-editor plugin error * fix: review * feat: move all plugins' dependencies to devDependencies * feat: change build * feat: add devPlugins * fix: bug * fix: bugs * fix: bugs * fix: bugs * feat: build bugs * fix: bugs * fix: bugs * fix: review * fix: bug * fix: change deps build * fix: bugs * fix: bug * fix: bug * fix: bugs * fix: bug * fix: bug * fix: multi language * fix: dist * fix: cronstrue * fix: getPackageClientStaticUrl * fix: antd dayjs locale * fix: plugin' d.ts import from dist * fix: multi language * fix: build types error * fix: requireModule * fix: plugin lifecycle * fix: client resource * fix: improve code * fix: locale * feat: custom build * fix: require locale * fix: improve code * fix: improve code * fix: skip preset * fix: collection undefined * feat: yarn build * fix: remove enabled * fix: update dockerfile * fix: formily version * docs: update v12 changelog * fix: devDependencies * feat: @nocobase/app * feat: generateAppDir * fix: improve code * fix: 0.11.1-alpha.5 * fix: missing @nocobase/client * fix: error * fix: add .npmignore * feat: upgrade antd version * fix: dependencies * fix: peerDependencies * fix: remove china-division dep * fix: toposort deps * fix: update dockerfile * fix: plugin template * fix: app client outputPath * feat: update docs * fix: nginx server root * fix: storage/.app-dev * fix: getChinaDivisionData * feat: plugin info * feat: update docs * fix: docs menu --------- Co-authored-by: chenos <chenlinxh@gmail.com>
183 lines
5.3 KiB
JavaScript
183 lines
5.3 KiB
JavaScript
const chalk = require('chalk');
|
|
const crypto = require('crypto');
|
|
const { existsSync } = require('fs');
|
|
const { join, resolve } = require('path');
|
|
const { Generator } = require('@umijs/utils');
|
|
const { downloadPackageFromNpm, updateJsonFile } = require('./util');
|
|
|
|
class AppGenerator extends Generator {
|
|
constructor(options) {
|
|
const { context = {}, ...opts } = options;
|
|
super(opts);
|
|
this.context = context;
|
|
this.env = this.parseEnvs();
|
|
}
|
|
|
|
parseEnvs() {
|
|
const envs = this.args.env;
|
|
const items = {};
|
|
for (const env of envs) {
|
|
const keys = env.split('=');
|
|
if (keys.length !== 2) {
|
|
console.log(`${chalk.red(env)} is not a valid environment value`);
|
|
process.exit(1);
|
|
}
|
|
items[keys[0]] = keys[1];
|
|
}
|
|
return items;
|
|
}
|
|
|
|
checkDbEnv() {
|
|
const dialect = this.args.dbDialect;
|
|
const env = this.env;
|
|
if (dialect === 'sqlite') {
|
|
return;
|
|
}
|
|
if (!env.DB_DATABASE || !env.DB_USER || !env.DB_PASSWORD) {
|
|
console.log(
|
|
chalk.red(
|
|
`Please set DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD in .env file to complete database settings`,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
checkProjectPath() {
|
|
if (existsSync(this.cwd)) {
|
|
console.log(chalk.red('Project directory already exists'));
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
checkDialect() {
|
|
const dialect = this.args.dbDialect;
|
|
const supportDialects = ['mysql', 'sqlite', 'postgres'];
|
|
if (!supportDialects.includes(dialect)) {
|
|
console.log(
|
|
`dialect ${chalk.red(dialect)} is not supported, currently supported dialects are ${chalk.green(
|
|
supportDialects.join(','),
|
|
)}.`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
getContext() {
|
|
const env = this.env;
|
|
const envs = [];
|
|
const dependencies = [];
|
|
const { dbDialect, allDbDialect } = this.args;
|
|
|
|
if (allDbDialect) {
|
|
dependencies.push(`"mysql2": "^2.3.3"`);
|
|
dependencies.push(`"pg": "^8.7.3"`);
|
|
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
}
|
|
|
|
switch (dbDialect) {
|
|
case 'sqlite':
|
|
if (!allDbDialect) {
|
|
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
}
|
|
envs.push(`DB_STORAGE=${env.DB_STORAGE || 'storage/db/nocobase.sqlite'}`);
|
|
break;
|
|
case 'mysql':
|
|
if (!allDbDialect) {
|
|
dependencies.push(`"mysql2": "^2.3.3"`);
|
|
}
|
|
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
|
|
envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
|
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
|
|
envs.push(`DB_USER=${env.DB_USER || ''}`);
|
|
envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
|
|
break;
|
|
case 'postgres':
|
|
if (!allDbDialect) {
|
|
dependencies.push(`"pg": "^8.7.3"`);
|
|
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
}
|
|
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
|
|
envs.push(`DB_PORT=${env.DB_PORT || 5432}`);
|
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
|
|
envs.push(`DB_USER=${env.DB_USER || ''}`);
|
|
envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
|
|
break;
|
|
}
|
|
|
|
const keys = ['PLUGIN_PACKAGE_PREFIX', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USER', 'DB_PASSWORD', 'DB_STORAGE'];
|
|
|
|
for (const key in env) {
|
|
if (keys.includes(key)) {
|
|
continue;
|
|
}
|
|
envs.push(`${key}=${env[key]}`);
|
|
}
|
|
|
|
return {
|
|
...this.context,
|
|
dependencies: dependencies.join(`,\n `),
|
|
envs: envs.join(`\n`),
|
|
env: {
|
|
APP_PORT: 13000,
|
|
APP_ENV: 'development',
|
|
DB_DIALECT: dbDialect,
|
|
APP_KEY: crypto.randomBytes(256).toString('base64'),
|
|
PLUGIN_PACKAGE_PREFIX: `@nocobase/plugin-,@nocobase/preset-,@${this.context.name}/plugin-`,
|
|
...env,
|
|
},
|
|
};
|
|
}
|
|
|
|
async downloadServerPackage() {
|
|
const { name } = this.context;
|
|
console.log('Download: @nocobase/app-server');
|
|
const serverPackageDir = resolve(this.cwd, 'packages/app/server');
|
|
await downloadPackageFromNpm('@nocobase/app-server', serverPackageDir);
|
|
await updateJsonFile(resolve(serverPackageDir, 'package.json'), (data) => {
|
|
data['name'] = `@${name}/app-server`;
|
|
data['version'] = '0.1.0';
|
|
return data;
|
|
});
|
|
}
|
|
|
|
async downloadClientPackage() {
|
|
const { name } = this.context;
|
|
console.log('Download: @nocobase/app-client');
|
|
const clientPackageDir = resolve(this.cwd, 'packages/app/client');
|
|
await downloadPackageFromNpm('@nocobase/app-client', clientPackageDir);
|
|
await updateJsonFile(resolve(clientPackageDir, 'package.json'), (data) => {
|
|
data['name'] = `@${name}/app-client`;
|
|
data['version'] = '0.1.0';
|
|
return data;
|
|
});
|
|
}
|
|
|
|
async writing() {
|
|
this.checkProjectPath();
|
|
this.checkDialect();
|
|
|
|
const { name } = this.context;
|
|
|
|
console.log(`Creating a new NocoBase application at ${chalk.green(name)}`);
|
|
console.log('Creating files');
|
|
|
|
this.copyDirectory({
|
|
context: this.getContext(),
|
|
path: join(__dirname, '../templates/app'),
|
|
target: this.cwd,
|
|
});
|
|
|
|
this.checkDbEnv();
|
|
|
|
console.log('');
|
|
console.log(chalk.green(`$ cd ${name}`));
|
|
console.log(chalk.green(`$ yarn install`));
|
|
console.log(chalk.green(`$ yarn nocobase install`));
|
|
console.log(chalk.green(`$ yarn dev`));
|
|
console.log('');
|
|
}
|
|
}
|
|
|
|
exports.AppGenerator = AppGenerator;
|