forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.ts
More file actions
104 lines (89 loc) · 3.46 KB
/
delete.ts
File metadata and controls
104 lines (89 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Command, CliUx, Flags } from '@oclif/core';
import * as inquirer from 'inquirer';
const execa = require('execa');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
export default class Delete extends Command {
static description = 'Delete a tooljet plugin';
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]`];
static args = [{ name: 'plugin_name', description: 'Name of the plugin', required: true }];
async run(): Promise<void> {
const { args, flags } = await this.parse(Delete);
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;
}
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'
);
process.exit(1);
}
void inquirer
.prompt({
name: 'confirm',
type: 'confirm',
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);
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)
);
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');
} else {
CliUx.ux.action.stop();
this.log(`Aborted by user`);
}
});
}
}