@initx-plugin/manager 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +45 -51
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { fetchPlugins, InitxPlugin } from '@initx-plugin/core';
|
|
2
|
-
import { c, log, inquirer } from '@initx-plugin/utils';
|
|
2
|
+
import { c, loadingFunction, log, inquirer } from '@initx-plugin/utils';
|
|
3
3
|
import { green, blue, reset, dim, gray } from 'picocolors';
|
|
4
|
-
import ora from 'ora';
|
|
5
4
|
import path from 'node:path';
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
5
|
import columnify from 'columnify';
|
|
6
|
+
import fs from 'fs-extra';
|
|
8
7
|
|
|
9
8
|
const installedPluginInfo = {
|
|
10
9
|
once: false,
|
|
@@ -24,12 +23,6 @@ function nameColor(name) {
|
|
|
24
23
|
}
|
|
25
24
|
return blue(name);
|
|
26
25
|
}
|
|
27
|
-
async function loadingFunction(message, fn) {
|
|
28
|
-
const spinner = ora(message).start();
|
|
29
|
-
return fn().finally(() => {
|
|
30
|
-
spinner.stop();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
26
|
async function getInstalledPluginNames() {
|
|
34
27
|
if (installedPluginInfo.once) {
|
|
35
28
|
return installedPluginInfo.names;
|
|
@@ -53,11 +46,11 @@ async function searchPlugin(pluginNames) {
|
|
|
53
46
|
}
|
|
54
47
|
try {
|
|
55
48
|
const json = JSON.parse(result.content);
|
|
56
|
-
if (finedNames.includes(json.name)) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
finedNames.push(json.name);
|
|
60
49
|
json.forEach((plugin) => {
|
|
50
|
+
if (finedNames.includes(plugin.name)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
finedNames.push(plugin.name);
|
|
61
54
|
plugins.push({
|
|
62
55
|
name: plugin.name,
|
|
63
56
|
version: plugin.version,
|
|
@@ -82,7 +75,7 @@ async function addPlugin(targetPlugin) {
|
|
|
82
75
|
if (availablePlugins.length === 2) {
|
|
83
76
|
const displayContnet = [];
|
|
84
77
|
for (const plugin of availablePlugins) {
|
|
85
|
-
displayContnet.push(await displayInfo(plugin));
|
|
78
|
+
displayContnet.push(await displayInfo(plugin, true));
|
|
86
79
|
}
|
|
87
80
|
index = await inquirer.select(
|
|
88
81
|
"Which plugin do you want to install?",
|
|
@@ -126,15 +119,16 @@ async function searchAvailablePlugins(targetPlugin) {
|
|
|
126
119
|
async function installPlugin(name) {
|
|
127
120
|
return c("npm", ["install", "-g", name]);
|
|
128
121
|
}
|
|
129
|
-
async function displayInfo({ name, version, description }) {
|
|
122
|
+
async function displayInfo({ name, version, description }, hasTab = false) {
|
|
130
123
|
const isInstalled = await isInstalledPlugin(name);
|
|
124
|
+
const spaceChar = hasTab ? " " : " ";
|
|
131
125
|
const display = {
|
|
132
126
|
name: nameColor(name),
|
|
133
127
|
version: reset(dim(gray(`@${version}`))),
|
|
134
|
-
description: reset(description)
|
|
135
|
-
installed: isInstalled ? dim(green(" [already]")) :
|
|
128
|
+
description: `${spaceChar}${reset(description)}`,
|
|
129
|
+
installed: isInstalled ? dim(green(" [already]")) : spaceChar
|
|
136
130
|
};
|
|
137
|
-
return `${display.name}${display.version}${display.installed}
|
|
131
|
+
return `${display.name}${display.version}${display.installed}${display.description}`;
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
async function showPluginList() {
|
|
@@ -151,6 +145,38 @@ async function showPluginList() {
|
|
|
151
145
|
console.log(columnify(displayTable));
|
|
152
146
|
}
|
|
153
147
|
|
|
148
|
+
async function removePlugin(targetName) {
|
|
149
|
+
const plugins = await fetchPlugins();
|
|
150
|
+
const removePluginNames = [
|
|
151
|
+
officialName(targetName),
|
|
152
|
+
communityName(targetName)
|
|
153
|
+
];
|
|
154
|
+
const removePlugins = plugins.filter(({ name }) => removePluginNames.includes(name));
|
|
155
|
+
if (removePlugins.length === 0) {
|
|
156
|
+
const displayNames = removePluginNames.map(nameColor).join(" or ");
|
|
157
|
+
log.warn(`Plugin ${displayNames} is not installed`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let index = 0;
|
|
161
|
+
let needConfirm = true;
|
|
162
|
+
if (removePlugins.length === 2) {
|
|
163
|
+
index = await inquirer.select("Which plugin do you want to remove?", removePlugins.map(({ name }) => nameColor(name)));
|
|
164
|
+
needConfirm = false;
|
|
165
|
+
}
|
|
166
|
+
const removePlugin2 = removePlugins[index];
|
|
167
|
+
if (needConfirm) {
|
|
168
|
+
const confirmResult = await inquirer.confirm(`Are you sure you want to remove ${nameColor(removePlugin2.name)}?`);
|
|
169
|
+
if (!confirmResult) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
await loadingFunction(
|
|
174
|
+
`Removing ${nameColor(removePlugin2.name)}...`,
|
|
175
|
+
() => c("npm", ["uninstall", "-g", removePlugin2.name])
|
|
176
|
+
);
|
|
177
|
+
log.success(`Removed ${nameColor(removePlugin2.name)}`);
|
|
178
|
+
}
|
|
179
|
+
|
|
154
180
|
async function updatePlugin() {
|
|
155
181
|
const excludedPlugins = await fetchExcludedPlugins();
|
|
156
182
|
const fetchedPlugins = await fetchPlugins();
|
|
@@ -209,38 +235,6 @@ async function fetchExcludedPlugins() {
|
|
|
209
235
|
return excludedPlugins;
|
|
210
236
|
}
|
|
211
237
|
|
|
212
|
-
async function removePlugin(targetName) {
|
|
213
|
-
const plugins = await fetchPlugins();
|
|
214
|
-
const removePluginNames = [
|
|
215
|
-
officialName(targetName),
|
|
216
|
-
communityName(targetName)
|
|
217
|
-
];
|
|
218
|
-
const removePlugins = plugins.filter(({ name }) => removePluginNames.includes(name));
|
|
219
|
-
if (removePlugins.length === 0) {
|
|
220
|
-
const displayNames = removePluginNames.map(nameColor).join(" or ");
|
|
221
|
-
log.warn(`Plugin ${displayNames} is not installed`);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
let index = 0;
|
|
225
|
-
let needConfirm = true;
|
|
226
|
-
if (removePlugins.length === 2) {
|
|
227
|
-
index = await inquirer.select("Which plugin do you want to remove?", removePlugins.map(({ name }) => nameColor(name)));
|
|
228
|
-
needConfirm = false;
|
|
229
|
-
}
|
|
230
|
-
const removePlugin2 = removePlugins[index];
|
|
231
|
-
if (needConfirm) {
|
|
232
|
-
const confirmResult = await inquirer.confirm(`Are you sure you want to remove ${nameColor(removePlugin2.name)}?`);
|
|
233
|
-
if (!confirmResult) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
await loadingFunction(
|
|
238
|
-
`Removing ${nameColor(removePlugin2.name)}...`,
|
|
239
|
-
() => c("npm", ["uninstall", "-g", removePlugin2.name])
|
|
240
|
-
);
|
|
241
|
-
log.success(`Removed ${nameColor(removePlugin2.name)}`);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
238
|
var __defProp = Object.defineProperty;
|
|
245
239
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
246
240
|
var __publicField = (obj, key, value) => {
|
|
@@ -261,7 +255,7 @@ class PluginManagerPlugin extends InitxPlugin {
|
|
|
261
255
|
const [name] = others;
|
|
262
256
|
switch (type) {
|
|
263
257
|
case "list": {
|
|
264
|
-
showPluginList();
|
|
258
|
+
await showPluginList();
|
|
265
259
|
break;
|
|
266
260
|
}
|
|
267
261
|
case "add": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@initx-plugin/manager",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "initx plugin manager",
|
|
6
6
|
"author": "imba97",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,15 +24,14 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@initx-plugin/core": "^0.0.
|
|
28
|
-
"@initx-plugin/utils": "^0.0.
|
|
27
|
+
"@initx-plugin/core": "^0.0.25",
|
|
28
|
+
"@initx-plugin/utils": "^0.0.25",
|
|
29
29
|
"columnify": "^1.6.0",
|
|
30
30
|
"fs-extra": "^11.2.0",
|
|
31
|
-
"ora": "^8.1.1",
|
|
32
31
|
"picocolors": "^1.1.1"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@imba97/eslint-config": "^0.0.
|
|
34
|
+
"@imba97/eslint-config": "^0.0.5",
|
|
36
35
|
"@types/columnify": "^1.5.4",
|
|
37
36
|
"@types/fs-extra": "^11.0.4",
|
|
38
37
|
"@types/node": "^22.9.0",
|