feat: more console log
This commit is contained in:
parent
bbc7f67b15
commit
f15c67afd5
@ -114,6 +114,7 @@ class AppGenerator extends Generator {
|
||||
APP_ENV: 'development',
|
||||
DB_DIALECT: dbDialect,
|
||||
APP_KEY: crypto.randomBytes(256).toString('base64'),
|
||||
PLUGIN_PACKAGE_PREFIX: `@nocobase/plugin-,@nocobase/preset-,@${this.context.name}/plugin-`,
|
||||
...env,
|
||||
},
|
||||
};
|
||||
|
@ -5,6 +5,8 @@ APP_PORT={{{env.APP_PORT}}}
|
||||
API_BASE_PATH=/api/
|
||||
API_BASE_URL=
|
||||
|
||||
PLUGIN_PACKAGE_PREFIX={{{env.PLUGIN_PACKAGE_PREFIX}}}
|
||||
|
||||
DB_LOGGING=off
|
||||
DB_DIALECT={{{env.DB_DIALECT}}}
|
||||
{{{envs}}}
|
||||
|
@ -9,7 +9,6 @@ import { Server } from 'http';
|
||||
import { i18n, InitOptions } from 'i18next';
|
||||
import Koa, { DefaultContext as KoaDefaultContext, DefaultState as KoaDefaultState } from 'koa';
|
||||
import compose from 'koa-compose';
|
||||
import { isBoolean } from 'lodash';
|
||||
import semver from 'semver';
|
||||
import { promisify } from 'util';
|
||||
import { createACL } from './acl';
|
||||
@ -314,6 +313,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
|
||||
async load(options?: any) {
|
||||
if (options?.reload) {
|
||||
console.log(`Reload the application configuration`);
|
||||
const oldDb = this._db;
|
||||
this.init();
|
||||
await oldDb.close();
|
||||
@ -427,17 +427,18 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
return;
|
||||
}
|
||||
|
||||
if (options?.clean) {
|
||||
await this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);
|
||||
console.log('Database dialect: ' + this.db.sequelize.getDialect());
|
||||
|
||||
if (options?.clean || options?.sync?.force) {
|
||||
console.log('Truncate database and reload app configuration');
|
||||
await this.db.clean({ drop: true });
|
||||
await this.reload({ method: 'install' });
|
||||
}
|
||||
|
||||
await this.emitAsync('beforeInstall', this, options);
|
||||
|
||||
await this.db.sync(options?.sync);
|
||||
await this.db.sync();
|
||||
await this.pm.install(options);
|
||||
await this.version.update();
|
||||
|
||||
await this.emitAsync('afterInstall', this, options);
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,8 @@ export default (app: Application) => {
|
||||
let command = '$ yarn nocobase install -f';
|
||||
console.log(chalk.yellow(command));
|
||||
console.log();
|
||||
console.log(chalk.red('This operation will clear the database!!!'));
|
||||
console.log();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ export default (app: Application) => {
|
||||
.argument('<method>')
|
||||
.arguments('<plugins...>')
|
||||
.action(async (method, plugins, options, ...args) => {
|
||||
if (method === 'add') {
|
||||
const { run } = require('@nocobase/cli/src/util');
|
||||
console.log('Install dependencies and rebuild workspaces');
|
||||
await run('yarn', ['install']);
|
||||
}
|
||||
app.pm.clientWrite({ method, plugins });
|
||||
});
|
||||
};
|
||||
|
@ -176,7 +176,7 @@ export class PluginManager {
|
||||
});
|
||||
const pluginName = instance.getName();
|
||||
if (this.plugins.has(pluginName)) {
|
||||
throw new Error(`plugin name [${pluginName}] exists`);
|
||||
throw new Error(`plugin name [${pluginName}] already exists`);
|
||||
}
|
||||
this.plugins.set(pluginName, instance);
|
||||
return instance;
|
||||
@ -194,9 +194,7 @@ export class PluginManager {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
console.log(`adding ${plugin} plugin`);
|
||||
const packageName = await PluginManager.findPackage(plugin);
|
||||
console.log(`adding ${packageName}`);
|
||||
const packageJson = require(`${packageName}/package.json`);
|
||||
const instance = this.addStatic(plugin, {
|
||||
...options,
|
||||
@ -318,7 +316,7 @@ export class PluginManager {
|
||||
}
|
||||
|
||||
static getPackageName(name: string) {
|
||||
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
|
||||
const prefixes = this.getPluginPkgPrefix();
|
||||
for (const prefix of prefixes) {
|
||||
try {
|
||||
require.resolve(`${prefix}${name}`);
|
||||
@ -330,25 +328,32 @@ export class PluginManager {
|
||||
throw new Error(`${name} plugin does not exist`);
|
||||
}
|
||||
|
||||
static getPluginPkgPrefix() {
|
||||
return (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
|
||||
}
|
||||
|
||||
static async findPackage(name: string) {
|
||||
try {
|
||||
const packageName = this.getPackageName(name);
|
||||
return packageName;
|
||||
} catch (error) {
|
||||
const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
|
||||
console.log(`\`${name}\` plugin not found locally`);
|
||||
const prefixes = this.getPluginPkgPrefix();
|
||||
for (const prefix of prefixes) {
|
||||
try {
|
||||
const packageName = `${prefix}${name}`;
|
||||
console.log(`Try to find ${packageName}`);
|
||||
await execa('npm', ['v', packageName, 'versions']);
|
||||
console.log(`${packageName} is downloading...`);
|
||||
console.log(`${packageName} downloading`);
|
||||
await execa('yarn', ['add', packageName, '-W']);
|
||||
console.log(`${packageName} downloaded`);
|
||||
return packageName;
|
||||
} catch (error) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`${name} plugin does not exist`);
|
||||
throw new Error(`No available packages found, ${name} plugin does not exist`);
|
||||
}
|
||||
|
||||
static resolvePlugin(pluginName: string) {
|
||||
|
@ -35,10 +35,13 @@ export class PresetNocoBase extends Plugin {
|
||||
if (options?.method !== 'upgrade') {
|
||||
return;
|
||||
}
|
||||
const version = await this.app.version.get();
|
||||
console.log(`The version number before upgrade is ${version}`);
|
||||
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
|
||||
if (result) {
|
||||
const r = await this.db.collectionExistsInDb('applicationPlugins');
|
||||
if (r) {
|
||||
console.log(`Clear the installed application plugins`);
|
||||
await this.db.getRepository('applicationPlugins').destroy({ truncate: true });
|
||||
await this.app.reload();
|
||||
}
|
||||
@ -47,10 +50,12 @@ export class PresetNocoBase extends Plugin {
|
||||
this.app.on('beforeUpgrade', async () => {
|
||||
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
|
||||
if (result) {
|
||||
console.log(`Initialize all built-in plugins`);
|
||||
await this.addBuiltInPlugins();
|
||||
}
|
||||
});
|
||||
this.app.on('beforeInstall', async () => {
|
||||
console.log(`Initialize all built-in plugins`);
|
||||
await this.addBuiltInPlugins();
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user