feat(cli): --db-sync options
This commit is contained in:
		
							parent
							
								
									8a26b8dd77
								
							
						
					
					
						commit
						747851f2b1
					
				@ -1,6 +1,6 @@
 | 
			
		||||
const chalk = require('chalk');
 | 
			
		||||
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');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -14,6 +14,7 @@ module.exports = (cli) => {
 | 
			
		||||
    .option('-p, --port [port]')
 | 
			
		||||
    .option('--client')
 | 
			
		||||
    .option('--server')
 | 
			
		||||
    .option('--db-sync')
 | 
			
		||||
    .allowUnknownOption()
 | 
			
		||||
    .action(async (opts) => {
 | 
			
		||||
      promptForTs();
 | 
			
		||||
@ -44,7 +45,10 @@ module.exports = (cli) => {
 | 
			
		||||
          port: 1 * clientPost + 1,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
      await runInstall();
 | 
			
		||||
      await runAppCommand('install', ['--silent']);
 | 
			
		||||
      if (opts.dbSync) {
 | 
			
		||||
        await runAppCommand('db:sync');
 | 
			
		||||
      }
 | 
			
		||||
      if (server || !client) {
 | 
			
		||||
        console.log('starting server', serverPost);
 | 
			
		||||
        const argv = [
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@ module.exports = (cli) => {
 | 
			
		||||
  cli
 | 
			
		||||
    .command('start')
 | 
			
		||||
    .option('-p, --port [port]')
 | 
			
		||||
    .option('--db-sync')
 | 
			
		||||
    .allowUnknownOption()
 | 
			
		||||
    .action(async (opts) => {
 | 
			
		||||
      if (opts.port) {
 | 
			
		||||
@ -38,7 +39,10 @@ module.exports = (cli) => {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      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)]);
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -7,12 +7,13 @@ export default (app: Application) => {
 | 
			
		||||
    .option('-f, --force')
 | 
			
		||||
    .option('-c, --clean')
 | 
			
		||||
    .option('-s, --silent')
 | 
			
		||||
    .option('-r, --repeat [repeat]')
 | 
			
		||||
    .action(async (...cliArgs) => {
 | 
			
		||||
      let installed = false;
 | 
			
		||||
      const [opts] = cliArgs;
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        await app.db.auth({ repeat: 1 });
 | 
			
		||||
        await app.db.auth({ repeat: opts.repeat || 1 });
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.log(chalk.red('Unable to connect to the database. Please check the database environment variables in the .env file.'));
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user