mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 13:37:28 +00:00
Improvements : ToolJet CLI (#6155)
* remove repo url prompt for creating a new plugin * deprecating : creating new plugins for datasource/plugins * package version upgraded to v0.0.14 * fixes: delete cmd * delete prompt confirms marketplace plugins * removes repo from json
This commit is contained in:
parent
9d2252ac68
commit
d1ec7942d1
4 changed files with 79 additions and 77 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@tooljet/cli",
|
||||
"description": "tooljet cli tool",
|
||||
"version": "0.0.13",
|
||||
"version": "0.0.14",
|
||||
"bin": {
|
||||
"tooljet": "./bin/run"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ export default class Create extends Command {
|
|||
static flags = {
|
||||
type: Flags.string({ options: ['database', 'api', 'cloud-storage'] }),
|
||||
build: Flags.boolean({ char: 'b' }),
|
||||
marketplace: Flags.boolean({ char: 'm' }),
|
||||
};
|
||||
static description = 'Create a new tooljet plugin';
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ export default class Create extends Command {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
let { type, marketplace } = flags;
|
||||
let { type } = flags;
|
||||
|
||||
const name = await CliUx.ux.prompt('Enter plugin display name');
|
||||
|
||||
|
|
@ -48,19 +47,7 @@ export default class Create extends Command {
|
|||
type = responses.type;
|
||||
}
|
||||
|
||||
if (!marketplace) {
|
||||
const responses: any = await inquirer.prompt([
|
||||
{
|
||||
name: 'marketplace',
|
||||
message: 'is it a marketplace integration?',
|
||||
type: 'confirm',
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
marketplace = responses.marketplace;
|
||||
}
|
||||
|
||||
const pluginsPath = marketplace ? 'marketplace' : 'plugins';
|
||||
const pluginsPath = 'marketplace';
|
||||
const docsPath = 'docs';
|
||||
const defaultTemplates = path.join(pluginsPath, '_templates');
|
||||
|
||||
|
|
@ -72,9 +59,7 @@ export default class Create extends Command {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
let repoUrl;
|
||||
|
||||
const commonHygenArgs = [
|
||||
const hygenArgs = [
|
||||
'plugin',
|
||||
'new',
|
||||
'--name',
|
||||
|
|
@ -87,22 +72,14 @@ export default class Create extends Command {
|
|||
`${pluginsPath}`,
|
||||
];
|
||||
|
||||
const hygenArgs = !marketplace ? [...commonHygenArgs, '--docs_path', `${docsPath}`] : commonHygenArgs;
|
||||
|
||||
if (marketplace) {
|
||||
const buffer = fs.readFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), 'utf8');
|
||||
const pluginsJson = JSON.parse(buffer);
|
||||
pluginsJson.map((plugin: any) => {
|
||||
if (plugin.id === args.plugin_name.toLowerCase()) {
|
||||
this.log('\x1b[41m%s\x1b[0m', 'Error : Plugin id already exists');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
repoUrl = await CliUx.ux.prompt('Please enter the repository URL if hosted on GitHub', {
|
||||
required: false,
|
||||
});
|
||||
}
|
||||
const buffer = fs.readFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), 'utf8');
|
||||
const pluginsJson = JSON.parse(buffer);
|
||||
pluginsJson.map((plugin: any) => {
|
||||
if (plugin.id === args.plugin_name.toLowerCase()) {
|
||||
this.log('\x1b[41m%s\x1b[0m', 'Error : Plugin id already exists');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
CliUx.ux.action.start('creating plugin');
|
||||
|
||||
|
|
@ -118,28 +95,19 @@ export default class Create extends Command {
|
|||
debug: !!process.env.DEBUG,
|
||||
});
|
||||
|
||||
if (marketplace) {
|
||||
await execa('npm', ['i'], { cwd: pluginsPath });
|
||||
const plugin = {
|
||||
name: args.plugin_name,
|
||||
description: `${type} plugin from ${args.plugin_name}`,
|
||||
version: '1.0.0',
|
||||
id: `${args.plugin_name.toLowerCase()}`,
|
||||
author: 'Tooljet',
|
||||
timestamp: new Date().toUTCString(),
|
||||
};
|
||||
|
||||
const buffer = fs.readFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), 'utf8');
|
||||
const pluginsJson = JSON.parse(buffer);
|
||||
const plugin = {
|
||||
name: args.plugin_name,
|
||||
repo: repoUrl || '',
|
||||
description: `${type} plugin from ${args.plugin_name}`,
|
||||
version: '1.0.0',
|
||||
id: `${args.plugin_name.toLowerCase()}`,
|
||||
author: 'Tooljet',
|
||||
timestamp: new Date().toUTCString(),
|
||||
};
|
||||
pluginsJson.push(plugin);
|
||||
|
||||
pluginsJson.push(plugin);
|
||||
|
||||
const jsonString = JSON.stringify(pluginsJson, null, 2);
|
||||
fs.writeFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), jsonString);
|
||||
} else {
|
||||
await execa('npx', ['lerna', 'link', 'convert'], { cwd: pluginsPath });
|
||||
}
|
||||
const jsonString = JSON.stringify(pluginsJson, null, 2);
|
||||
fs.writeFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), jsonString);
|
||||
|
||||
CliUx.ux.action.stop();
|
||||
|
||||
|
|
@ -147,11 +115,7 @@ export default class Create extends Command {
|
|||
|
||||
if (flags.build) {
|
||||
CliUx.ux.action.start('building plugins');
|
||||
if (marketplace) {
|
||||
await execa('npm', ['run', 'build', '--workspaces'], { cwd: pluginsPath });
|
||||
} else {
|
||||
await execa.command('npm run build:plugins', { cwd: process.cwd() });
|
||||
}
|
||||
await execa('npm', ['run', 'build', '--workspaces'], { cwd: pluginsPath });
|
||||
CliUx.ux.action.stop();
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +124,7 @@ export default class Create extends Command {
|
|||
|
||||
const subtree = CliUx.ux.tree();
|
||||
subtree.insert(`${args.plugin_name}`);
|
||||
tree.nodes[pluginsPath].insert(marketplace ? 'plugins' : 'packages', subtree);
|
||||
tree.nodes[pluginsPath].insert('plugins', subtree);
|
||||
|
||||
tree.display();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export default class Delete extends Command {
|
|||
|
||||
static flags = {
|
||||
build: Flags.boolean({ char: 'b' }),
|
||||
marketplace: Flags.boolean({ char: 'm' }), // TODO: remove this flag, and make it default
|
||||
};
|
||||
|
||||
static examples = [`$ tooljet plugin delete <name> [--build]`];
|
||||
|
|
@ -19,11 +20,32 @@ export default class Delete extends Command {
|
|||
async run(): Promise<void> {
|
||||
const { args, flags } = await this.parse(Delete);
|
||||
|
||||
const pluginsPath = 'plugins';
|
||||
const pluginPath = path.join('plugins', 'packages', `${args.plugin_name}`);
|
||||
const pluginDocPath = path.join('docs', 'docs', 'data-sources', `${args.plugin_name}.md`);
|
||||
if (!flags.marketplace) {
|
||||
const responses: any = await inquirer.prompt([
|
||||
{
|
||||
name: 'marketplace',
|
||||
message: 'Is this a marketplace plugin?',
|
||||
type: 'confirm',
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
flags.marketplace = responses.marketplace;
|
||||
}
|
||||
|
||||
if (!(fs.existsSync(pluginsPath) && fs.existsSync(pluginPath) && fs.existsSync(pluginDocPath))) {
|
||||
const pluginsPath = flags.marketplace ? 'marketplace' : 'plugins';
|
||||
const pluginPath =
|
||||
pluginsPath === 'marketplace'
|
||||
? path.join('marketplace', 'plugins', args.plugin_name)
|
||||
: path.join('plugins', 'packages', `${args.plugin_name}`);
|
||||
|
||||
const pluginDocPath =
|
||||
pluginsPath !== 'marketplace' ? path.join('docs', 'docs', 'data-sources', `${args.plugin_name}.md`) : '';
|
||||
|
||||
if (
|
||||
!(fs.existsSync(pluginsPath) && fs.existsSync(pluginPath) && !flags.marketplace
|
||||
? fs.existsSync(pluginDocPath)
|
||||
: true)
|
||||
) {
|
||||
this.log(
|
||||
'\x1b[41m%s\x1b[0m',
|
||||
'Error : Plugin not found, make sure that you are running this command in Tooljet directory'
|
||||
|
|
@ -35,21 +57,41 @@ export default class Delete extends Command {
|
|||
.prompt({
|
||||
name: 'confirm',
|
||||
type: 'confirm',
|
||||
message: 'Are you sure?',
|
||||
message: `Please confirm: Do you want to proceed with deleting the plugin [${args.plugin_name}] from your local machine?`,
|
||||
default: 'yes',
|
||||
})
|
||||
.then(async (answers: any) => {
|
||||
if (answers.confirm) {
|
||||
CliUx.ux.action.start('deleting plugin');
|
||||
rimraf.sync(pluginPath);
|
||||
rimraf.sync(pluginDocPath);
|
||||
await execa('npx', ['lerna', 'link', 'convert'], { cwd: pluginsPath });
|
||||
CliUx.ux.action.stop();
|
||||
if (flags.marketplace) {
|
||||
const pluginsJson = JSON.parse(
|
||||
fs.readFileSync(path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'), 'utf8')
|
||||
);
|
||||
const index = pluginsJson.findIndex((plugin: any) => plugin.name === args.plugin_name);
|
||||
pluginsJson.splice(index, 1);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join('server', 'src', 'assets', 'marketplace', 'plugins.json'),
|
||||
JSON.stringify(pluginsJson, null, 2)
|
||||
);
|
||||
|
||||
if (flags.build) {
|
||||
CliUx.ux.action.start('building plugins');
|
||||
await execa.command('npm run build:plugins', { cwd: process.cwd() });
|
||||
CliUx.ux.action.stop();
|
||||
|
||||
if (flags.build) {
|
||||
await execa('npm', ['run', 'build', '--workspaces'], { cwd: pluginsPath });
|
||||
CliUx.ux.action.stop();
|
||||
}
|
||||
} else {
|
||||
rimraf.sync(pluginDocPath);
|
||||
await execa('npx', ['lerna', 'link', 'convert'], { cwd: pluginsPath });
|
||||
CliUx.ux.action.stop();
|
||||
|
||||
if (flags.build) {
|
||||
CliUx.ux.action.start('building plugins');
|
||||
await execa.command('npm run build:plugins', { cwd: process.cwd() });
|
||||
CliUx.ux.action.stop();
|
||||
}
|
||||
}
|
||||
|
||||
this.log('\x1b[42m', '\x1b[30m', `Plugin: ${args.plugin_name} deleted successfully`, '\x1b[0m');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
[
|
||||
{
|
||||
"name": "plivo",
|
||||
"repo": "",
|
||||
"description": "Datasource plugin for Plivo",
|
||||
"version": "1.0.0",
|
||||
"id": "plivo",
|
||||
|
|
@ -10,7 +9,6 @@
|
|||
},
|
||||
{
|
||||
"name": "github",
|
||||
"repo": "",
|
||||
"description": "Datasource plugin for GitHub",
|
||||
"version": "1.0.0",
|
||||
"id": "github",
|
||||
|
|
@ -19,8 +17,7 @@
|
|||
},
|
||||
{
|
||||
"name": "openai",
|
||||
"repo": "",
|
||||
"description": "Datasource plugin from openai",
|
||||
"description": "api plugin from openai",
|
||||
"version": "1.0.0",
|
||||
"id": "openai",
|
||||
"author": "Tooljet",
|
||||
|
|
@ -28,7 +25,6 @@
|
|||
},
|
||||
{
|
||||
"name": "AWS Textract",
|
||||
"repo": "",
|
||||
"description": "Datasource plugin from textract",
|
||||
"version": "1.0.0",
|
||||
"id": "textract",
|
||||
|
|
|
|||
Loading…
Reference in a new issue