feat(cli): --db-sync options

This commit is contained in:
chenos 2022-05-20 15:49:17 +08:00
parent 8a26b8dd77
commit 747851f2b1
3 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,6 @@
const chalk = require('chalk'); const chalk = require('chalk');
const { Command } = require('commander'); const { Command } = require('commander');
const { runInstall, run, postCheck, nodeCheck, promptForTs } = require('../util'); const { runAppCommand, runInstall, run, postCheck, nodeCheck, promptForTs } = require('../util');
const { getPortPromise } = require('portfinder'); const { getPortPromise } = require('portfinder');
/** /**
@ -14,6 +14,7 @@ module.exports = (cli) => {
.option('-p, --port [port]') .option('-p, --port [port]')
.option('--client') .option('--client')
.option('--server') .option('--server')
.option('--db-sync')
.allowUnknownOption() .allowUnknownOption()
.action(async (opts) => { .action(async (opts) => {
promptForTs(); promptForTs();
@ -44,7 +45,10 @@ module.exports = (cli) => {
port: 1 * clientPost + 1, port: 1 * clientPost + 1,
}); });
} }
await runInstall(); await runAppCommand('install', ['--silent']);
if (opts.dbSync) {
await runAppCommand('db:sync');
}
if (server || !client) { if (server || !client) {
console.log('starting server', serverPost); console.log('starting server', serverPost);
const argv = [ const argv = [

View File

@ -13,6 +13,7 @@ module.exports = (cli) => {
cli cli
.command('start') .command('start')
.option('-p, --port [port]') .option('-p, --port [port]')
.option('--db-sync')
.allowUnknownOption() .allowUnknownOption()
.action(async (opts) => { .action(async (opts) => {
if (opts.port) { if (opts.port) {
@ -38,7 +39,10 @@ module.exports = (cli) => {
return; return;
} }
await postCheck(opts); await postCheck(opts);
await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'install', '-s']); await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'install', '--silent']);
if (opts.dbSync) {
await run('node', [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, 'db:sync']);
}
run('pm2-runtime', ['start', `packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, '--', ...process.argv.slice(2)]); run('pm2-runtime', ['start', `packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, '--', ...process.argv.slice(2)]);
}); });
}; };

View File

@ -7,12 +7,13 @@ export default (app: Application) => {
.option('-f, --force') .option('-f, --force')
.option('-c, --clean') .option('-c, --clean')
.option('-s, --silent') .option('-s, --silent')
.option('-r, --repeat [repeat]')
.action(async (...cliArgs) => { .action(async (...cliArgs) => {
let installed = false; let installed = false;
const [opts] = cliArgs; const [opts] = cliArgs;
try { try {
await app.db.auth({ repeat: 1 }); await app.db.auth({ repeat: opts.repeat || 1 });
} catch (error) { } catch (error) {
console.log(chalk.red('Unable to connect to the database. Please check the database environment variables in the .env file.')); console.log(chalk.red('Unable to connect to the database. Please check the database environment variables in the .env file.'));
return; return;