mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
feat(cli): quickstart
This commit is contained in:
parent
e81c63fc95
commit
99ad54afb6
@ -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:
|
||||
|
@ -15,6 +15,7 @@ module.exports = (cli) => {
|
||||
.option('--client')
|
||||
.option('--server')
|
||||
.option('--db-sync')
|
||||
.option('--quickstart')
|
||||
.allowUnknownOption()
|
||||
.action(async (opts) => {
|
||||
promptForTs();
|
||||
|
@ -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) {
|
||||
|
@ -88,6 +88,7 @@ interface StartOptions {
|
||||
cliArgs?: any[];
|
||||
dbSync?: boolean;
|
||||
listen?: ListenOptions;
|
||||
quickstart?: boolean;
|
||||
}
|
||||
|
||||
export class ApplicationVersion {
|
||||
@ -386,6 +387,17 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
await this.db.sync();
|
||||
}
|
||||
|
||||
if (options.quickstart) {
|
||||
if (await this.isInstalled()) {
|
||||
console.log('upgrading...');
|
||||
await this.upgrade({ ...options, method: 'upgrade' });
|
||||
} else {
|
||||
console.log('installing...');
|
||||
await this.install(options);
|
||||
}
|
||||
await this.reload({ ...options, method: 'load' });
|
||||
}
|
||||
|
||||
await this.emitAsync('beforeStart', this, options);
|
||||
|
||||
if (options?.listen?.port) {
|
||||
@ -478,6 +490,12 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> 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());
|
||||
|
||||
|
@ -12,22 +12,8 @@ export default (app: Application) => {
|
||||
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?.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:');
|
||||
|
@ -7,12 +7,15 @@ export default (app: Application) => {
|
||||
.option('-p, --port [post]')
|
||||
.option('-h, --host [host]')
|
||||
.option('--db-sync')
|
||||
.option('--quickstart')
|
||||
.action(async (...cliArgs) => {
|
||||
const [opts] = cliArgs;
|
||||
const port = opts.port || process.env.APP_PORT || 13000;
|
||||
const host = opts.host || process.env.APP_HOST || '0.0.0.0';
|
||||
const quickstart = opts.quickstart;
|
||||
|
||||
await app.start({
|
||||
quickstart,
|
||||
dbSync: opts?.dbSync,
|
||||
cliArgs,
|
||||
listen: {
|
||||
|
Loading…
Reference in New Issue
Block a user