-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.js
executable file
·148 lines (135 loc) · 4.01 KB
/
cli.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env node
const path = require('path');
const args = require('args');
const chalk = require('chalk');
const ora = require('ora');
const { api, utils } = require('dext-core-utils');
const debug = process.env.NODE_ENV === 'development';
args.command(['search', 's'], 'Seach for plugins or themes.', (name, sub) => {
const searchTerm = sub[0];
if (!searchTerm) {
console.log(chalk.yellow('Search must be called with an search term'));
return;
}
const spinner = ora(chalk.green(`Searching for "${searchTerm}"...`)).start();
return api
.search(searchTerm)
.then(results => {
spinner.color = 'green';
spinner.text = chalk.green(`Results for "${searchTerm}":`);
spinner.succeed();
let resultsMessage;
if (results.length) {
resultsMessage = results.reduce(
(prev, result) => `${prev}- ${result.name}: ${result.desc}\n`,
''
);
} else {
resultsMessage = chalk.yellow('no packages found');
}
console.log(resultsMessage);
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
});
args.command(
['install', 'i'],
'Install a new plugin or theme.',
(name, sub) => {
const plugin = sub[0];
const spinner = ora(chalk.green(`${plugin} : Installing...`)).start();
return api
.install(plugin, utils.paths.getPluginPath(plugin), { debug })
.then(() => {
spinner.color = 'green';
spinner.text = chalk.green(`${plugin} : Installed successfully!`);
spinner.succeed();
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
}
);
args.command(
['uninstall', 'u'],
'Uninstall a plugin or theme.',
(name, sub) => {
const plugin = sub[0];
const spinner = ora(chalk.green(`${plugin} : Uninstalling...`)).start();
return api
.uninstall(plugin, utils.paths.getPluginPath(plugin))
.then(() => {
spinner.color = 'green';
spinner.text = chalk.green(`${plugin} : Uninstalled successfully!`);
spinner.succeed();
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
}
);
args.command(['theme', 't'], 'Sets a theme.', (name, sub) => {
const theme = sub[0];
const spinner = ora(chalk.green(`${theme} : setting theme...`)).start();
return api
.setTheme(theme)
.then(() => {
spinner.color = 'green';
spinner.text = chalk.green(`${theme} : Theme has been set successfully!`);
spinner.succeed();
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
});
args.command(['link'], 'Creates a symlink for the current plugin.', () => {
const plugin = path.basename(process.cwd());
const spinner = ora(chalk.green('Linking...')).start();
return api
.createSymLink(plugin, process.cwd())
.then(data => {
spinner.color = 'green';
spinner.text = chalk.green(`Linked: ${data.srcPath} -> ${data.destPath}`);
spinner.succeed();
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
});
args.command(['unlink'], 'Removes the symlink for the current plugin.', () => {
const plugin = path.basename(process.cwd());
const spinner = ora(chalk.green('Unlinking...')).start();
return api
.removeSymLink(plugin)
.then(data => {
spinner.color = 'green';
spinner.text = chalk.green(`Unlinked: ${data.destPath}`);
spinner.succeed();
})
.catch(err => {
spinner.color = 'red';
spinner.text = chalk.red(err);
spinner.fail();
});
});
args.command(['config'], 'Display the raw config.', () =>
api
.getConfig()
.then(data => console.log(JSON.stringify(data, null, 2)))
.catch(err => console.error(chalk.red(err)))
);
const flags = args.parse(process.argv);
if (Object.keys(flags).length !== 0) {
args.showHelp();
}