Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getAllPlugins() {
const dir: string = getCoreBaseDir();
if (!existsSync(dir)) {
return [];
}
const files = readdirSync(dir);
const plugins = files.filter(file => {
return /midway-plugin/.test(file);
});
return plugins;
}
async updatePlugin(newPlugin) {
const plugin = newPlugin.replace(/@.*$/, '');
const oldVersion = this.getPluginVersion(plugin);
const dir: string = getCoreBaseDir();
await this.execPromise(`cd ${dir};rm -rf ${plugin}`);
await this.execPromise(
`cd ${join(dir, '../')};${this.options.npm ||
'npm'} install ${newPlugin} --production`
);
const newVersion = this.getPluginVersion(plugin);
this.core.cli.log(
` - update '${plugin}'${oldVersion ? ` from ${oldVersion}` : ''}${
newVersion ? ` to ${newVersion}` : ''
}`
);
}
async install() {
if (typeof this.options.install === 'string') {
const plugin = this.options.install.replace(/@.*$/, '');
const dir: string = getCoreBaseDir();
await this.execPromise(
`cd ${join(dir, '../')};${this.options.npm || 'npm'} install ${
this.options.install
} --production`
);
this.core.cli.log(` - installed '${plugin}'`);
} else {
this.core.cli.log(`please user plugin -i=`);
}
}
getPluginVersion(plugin) {
const dir: string = getCoreBaseDir();
const pkgJson = join(dir, plugin, 'package.json');
let version = '';
try {
version = JSON.parse(readFileSync(pkgJson).toString()).version;
} catch (E) {}
return version;
}