feat(create-nocobase-app): add --all-db-dialect option

This commit is contained in:
chenos 2022-05-19 11:49:41 +08:00
parent 8a3c3a487c
commit fd2c39c50e
2 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@ const cli = new Command('create-nocobase');
cli cli
.arguments('<name>', 'directory of new NocoBase app') .arguments('<name>', 'directory of new NocoBase app')
.option('--quickstart', 'quickstart app creation') .option('--quickstart', 'quickstart app creation')
.option('--all-db-deps', 'install all database dialect dependencies') .option('-a, --all-db-dialect', 'install all database dialect dependencies')
.option('-d, --db-dialect <dbDialect>', 'database dialect, current support sqlite/mysql/postgres', 'sqlite') .option('-d, --db-dialect <dbDialect>', 'database dialect, current support sqlite/mysql/postgres', 'sqlite')
.option('-e, --env <env>', 'environment variables write into .env file', concat, []) .option('-e, --env <env>', 'environment variables write into .env file', concat, [])
.description('create a new application') .description('create a new application')

View File

@ -66,9 +66,9 @@ class AppGenerator extends Generator {
const env = this.env; const env = this.env;
const envs = []; const envs = [];
const dependencies = []; const dependencies = [];
const { dbDialect, allDbDeps } = this.args; const { dbDialect, allDbDialect } = this.args;
if (allDbDeps) { if (allDbDialect) {
dependencies.push(`"mysql2": "^2.3.3"`); dependencies.push(`"mysql2": "^2.3.3"`);
dependencies.push(`"pg": "^8.7.3"`); dependencies.push(`"pg": "^8.7.3"`);
dependencies.push(`"pg-hstore": "^2.3.4"`); dependencies.push(`"pg-hstore": "^2.3.4"`);
@ -77,13 +77,13 @@ class AppGenerator extends Generator {
switch (dbDialect) { switch (dbDialect) {
case 'sqlite': case 'sqlite':
if (!allDbDeps) { if (!allDbDialect) {
dependencies.push(`"sqlite3": "^5.0.8"`); dependencies.push(`"sqlite3": "^5.0.8"`);
} }
envs.push(`DB_STORAGE=${env.DB_STORAGE || 'storages/db/nocobase.sqlite'}`); envs.push(`DB_STORAGE=${env.DB_STORAGE || 'storages/db/nocobase.sqlite'}`);
break; break;
case 'mysql': case 'mysql':
if (!allDbDeps) { if (!allDbDialect) {
dependencies.push(`"mysql2": "^2.3.3"`); dependencies.push(`"mysql2": "^2.3.3"`);
} }
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`); envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
@ -93,7 +93,7 @@ class AppGenerator extends Generator {
envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`); envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
break; break;
case 'postgres': case 'postgres':
if (!allDbDeps) { if (!allDbDialect) {
dependencies.push(`"pg": "^8.7.3"`); dependencies.push(`"pg": "^8.7.3"`);
dependencies.push(`"pg-hstore": "^2.3.4"`); dependencies.push(`"pg-hstore": "^2.3.4"`);
} }
@ -125,7 +125,7 @@ class AppGenerator extends Generator {
const serverPackageDir = resolve(this.cwd, 'packages/app/server'); const serverPackageDir = resolve(this.cwd, 'packages/app/server');
await downloadPackageFromNpm('@nocobase/app-server', serverPackageDir); await downloadPackageFromNpm('@nocobase/app-server', serverPackageDir);
await updateJsonFile(resolve(serverPackageDir, 'package.json'), (data) => { await updateJsonFile(resolve(serverPackageDir, 'package.json'), (data) => {
data['name'] = `@${name}/server`; data['name'] = `@${name}/app-server`;
data['version'] = '0.1.0'; data['version'] = '0.1.0';
return data; return data;
}); });
@ -137,7 +137,7 @@ class AppGenerator extends Generator {
const clientPackageDir = resolve(this.cwd, 'packages/app/client'); const clientPackageDir = resolve(this.cwd, 'packages/app/client');
await downloadPackageFromNpm('@nocobase/app-client', clientPackageDir); await downloadPackageFromNpm('@nocobase/app-client', clientPackageDir);
await updateJsonFile(resolve(clientPackageDir, 'package.json'), (data) => { await updateJsonFile(resolve(clientPackageDir, 'package.json'), (data) => {
data['name'] = `@${name}/client`; data['name'] = `@${name}/app-client`;
data['version'] = '0.1.0'; data['version'] = '0.1.0';
return data; return data;
}); });