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