From b96cdea2fc3d0cd6226bc6d5754a5f89b7b7dc9b Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 5 Dec 2022 22:19:22 +0800 Subject: [PATCH] feat(cli): quickstart (#1204) --- docker/nocobase/docker-entrypoint.sh | 5 +---- packages/core/cli/src/commands/start.js | 5 +++++ packages/core/server/src/application.ts | 6 ++++++ packages/core/server/src/commands/install.ts | 20 +++++++------------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docker/nocobase/docker-entrypoint.sh b/docker/nocobase/docker-entrypoint.sh index 7ebf1defa..0d18f6b8c 100755 --- a/docker/nocobase/docker-entrypoint.sh +++ b/docker/nocobase/docker-entrypoint.sh @@ -13,10 +13,7 @@ if [ ! -f "/app/nocobase/package.json" ]; then tar -zxf /app/nocobase.tar.gz --absolute-names -C /app/nocobase fi -cd /app/nocobase && yarn nocobase db:auth --retry=30 -cd /app/nocobase && yarn nocobase install -s -cd /app/nocobase && yarn nocobase upgrade -S -cd /app/nocobase && yarn start +cd /app/nocobase && yarn start --quickstart # Run command with node if the first argument contains a "-" or is not a system command. The last # part inside the "{}" is a workaround for the following bug in ash/dash: diff --git a/packages/core/cli/src/commands/start.js b/packages/core/cli/src/commands/start.js index b31ff1a3b..16b91903e 100644 --- a/packages/core/cli/src/commands/start.js +++ b/packages/core/cli/src/commands/start.js @@ -15,6 +15,7 @@ module.exports = (cli) => { .option('-p, --port [port]') .option('-d, --daemon') .option('--db-sync') + .option('--quickstart') .allowUnknownOption() .action(async (opts) => { if (opts.port) { @@ -40,6 +41,10 @@ module.exports = (cli) => { return; } await postCheck(opts); + if (opts.quickstart) { + await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'install', '--ignore-installed']); + await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'upgrade']); + } if (opts.dbSync) { await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'db:sync']); } diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 1f045f0ad..edf260634 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -478,6 +478,12 @@ export class Application exten return true; } + async isInstalled() { + return ( + (await this.db.collectionExistsInDb('applicationVersion')) || (await this.db.collectionExistsInDb('collections')) + ); + } + async install(options: InstallOptions = {}) { console.log('Database dialect: ' + this.db.sequelize.getDialect()); diff --git a/packages/core/server/src/commands/install.ts b/packages/core/server/src/commands/install.ts index fdacfa26a..d272002dc 100644 --- a/packages/core/server/src/commands/install.ts +++ b/packages/core/server/src/commands/install.ts @@ -8,26 +8,20 @@ export default (app: Application) => { .option('-c, --clean') .option('-s, --silent') .option('-r, --retry [retry]') + .option('-I, --ignore-installed') .action(async (...cliArgs) => { let installed = false; const [opts] = cliArgs; - try { - await app.db.auth({ retry: opts.retry || 1 }); - } catch (error) { - console.log( - chalk.red( - 'Unable to connect to the database. Please check the database environment variables in the .env file.', - ), - ); - return; + if (opts.ignoreInstalled) { + if (await app.isInstalled()) { + console.log('Application installed'); + return; + } } if (!opts?.clean && !opts?.force) { - if ( - (await app.db.collectionExistsInDb('applicationVersion')) || - (await app.db.collectionExistsInDb('collections')) - ) { + if (await app.isInstalled()) { installed = true; if (!opts.silent) { console.log('NocoBase is already installed. To reinstall, please execute:');