fix: plugin load collections (#3499)
This commit is contained in:
parent
ea35d103ac
commit
b71f12560a
@ -92,11 +92,19 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
return this.app.createLogger(options);
|
return this.app.createLogger(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
get _sourceDir() {
|
protected _sourceDir: string;
|
||||||
if (basename(__dirname) === 'src') {
|
|
||||||
return 'src';
|
protected async getSourceDir() {
|
||||||
|
if (this._sourceDir) {
|
||||||
|
return this._sourceDir;
|
||||||
}
|
}
|
||||||
return this.isPreset ? 'lib' : 'dist';
|
if (await this.isDev()) {
|
||||||
|
return (this._sourceDir = 'src');
|
||||||
|
}
|
||||||
|
if (basename(__dirname) === 'src') {
|
||||||
|
return (this._sourceDir = 'src');
|
||||||
|
}
|
||||||
|
return (this._sourceDir = this.isPreset ? 'lib' : 'dist');
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadCommands() {
|
async loadCommands() {
|
||||||
@ -104,7 +112,7 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
const directory = resolve(
|
const directory = resolve(
|
||||||
process.env.NODE_MODULES_PATH,
|
process.env.NODE_MODULES_PATH,
|
||||||
this.options.packageName,
|
this.options.packageName,
|
||||||
this._sourceDir,
|
await this.getSourceDir(),
|
||||||
'server/commands',
|
'server/commands',
|
||||||
);
|
);
|
||||||
const patten = `${directory}/*.{${extensions.join(',')}}`;
|
const patten = `${directory}/*.{${extensions.join(',')}}`;
|
||||||
@ -130,7 +138,7 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
const directory = resolve(
|
const directory = resolve(
|
||||||
process.env.NODE_MODULES_PATH,
|
process.env.NODE_MODULES_PATH,
|
||||||
this.options.packageName,
|
this.options.packageName,
|
||||||
this._sourceDir,
|
await this.getSourceDir(),
|
||||||
'server/migrations',
|
'server/migrations',
|
||||||
);
|
);
|
||||||
return await this.app.loadMigrations({
|
return await this.app.loadMigrations({
|
||||||
@ -178,7 +186,7 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
const directory = resolve(
|
const directory = resolve(
|
||||||
process.env.NODE_MODULES_PATH,
|
process.env.NODE_MODULES_PATH,
|
||||||
this.options.packageName,
|
this.options.packageName,
|
||||||
this._sourceDir,
|
await this.getSourceDir(),
|
||||||
'server/collections',
|
'server/collections',
|
||||||
);
|
);
|
||||||
if (await fsExists(directory)) {
|
if (await fsExists(directory)) {
|
||||||
@ -197,6 +205,19 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
return this.app.i18n.t(text, { ns: this.options['packageName'], ...(options as any) });
|
return this.app.i18n.t(text, { ns: this.options['packageName'], ...(options as any) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async isDev() {
|
||||||
|
if (!this.options.packageName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const file = await fs.promises.realpath(
|
||||||
|
resolve(process.env.NODE_MODULES_PATH || resolve(process.cwd(), 'node_modules'), this.options.packageName),
|
||||||
|
);
|
||||||
|
if (file.startsWith(resolve(process.cwd(), 'packages'))) {
|
||||||
|
return !!process.env.IS_DEV_CMD;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async toJSON(options: any = {}) {
|
async toJSON(options: any = {}) {
|
||||||
const { locale = 'en-US' } = options;
|
const { locale = 'en-US' } = options;
|
||||||
const { name, packageName, packageJson } = this.options;
|
const { name, packageName, packageJson } = this.options;
|
||||||
|
Loading…
Reference in New Issue
Block a user