ToolJet/cli/src/commands/plugin/install.ts
Midhun G S 72db6f6d8c
Tooljet CLI deployment and sanity check (#2096)
* feature-2054 plugin cli

* plugin cli

* readme changes

* npm publish

* Review comments

* Review comments

* cli fix

* added build flag
2022-02-05 06:49:49 +05:30

35 lines
1.2 KiB
TypeScript

import { Command, Flags, CliUx } from '@oclif/core';
const execa = require('execa');
const path = require('path');
const fs = require('fs');
export default class Install extends Command {
static flags = {
plugin: Flags.string({ required: true }),
};
static description = 'Installs a new npm module inside a tooljet plugin';
static examples = [`$ tooljet plugin install <npm_module> --plugin <plugin_name>`];
static args = [{ name: 'npm_module', description: 'Name of the npm module', required: true }];
async run(): Promise<void> {
const { args, flags } = await this.parse(Install);
const plugin = flags.plugin;
const pluginPath = path.join('plugins', 'packages', `${plugin}`);
if (!fs.existsSync(pluginPath)) {
this.log(
'\x1b[41m%s\x1b[0m',
'Error : Plugin not found, make sure that you are runing this command in Tooljet directory'
);
process.exit(1);
}
CliUx.ux.action.start('adding npm module');
await execa('npm', ['i', `${args.npm_module}`], { cwd: pluginPath });
CliUx.ux.action.stop();
this.log('\x1b[42m', '\x1b[30m', `Package: ${args.npm_module} added to ${plugin}`, '\x1b[0m');
}
}