@initx-plugin/manager 0.0.2 → 0.0.4
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +76 -77
- package/package.json +10 -11
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ declare class PluginManagerPlugin extends InitxPlugin {
|
|
|
5
5
|
matching: string;
|
|
6
6
|
description: string;
|
|
7
7
|
}[];
|
|
8
|
-
handle(
|
|
8
|
+
handle(context: InitxContext, type: string, ...others: string[]): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export { PluginManagerPlugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare class PluginManagerPlugin extends InitxPlugin {
|
|
|
5
5
|
matching: string;
|
|
6
6
|
description: string;
|
|
7
7
|
}[];
|
|
8
|
-
handle(
|
|
8
|
+
handle(context: InitxContext, type: string, ...others: string[]): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export { PluginManagerPlugin as default };
|
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;
|
|
@@ -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,12 +145,50 @@ async function showPluginList() {
|
|
|
151
145
|
console.log(columnify(displayTable));
|
|
152
146
|
}
|
|
153
147
|
|
|
154
|
-
async function
|
|
155
|
-
const
|
|
156
|
-
const
|
|
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
|
+
|
|
180
|
+
async function updatePlugin(options) {
|
|
181
|
+
const includeDev = options.dev || false;
|
|
182
|
+
const [developmentPlugins, fetchedPlugins] = await loadingFunction(
|
|
183
|
+
"Fetching plugins",
|
|
184
|
+
() => Promise.all([
|
|
185
|
+
fetchDevelopmentPlugins(),
|
|
186
|
+
fetchPlugins()
|
|
187
|
+
])
|
|
188
|
+
);
|
|
157
189
|
const pluginNames = [];
|
|
158
190
|
const pluginRootMap = fetchedPlugins.reduce((acc, { name, root }) => {
|
|
159
|
-
if (
|
|
191
|
+
if (!includeDev && developmentPlugins.includes(name)) {
|
|
160
192
|
return acc;
|
|
161
193
|
}
|
|
162
194
|
pluginNames.push(name);
|
|
@@ -168,13 +200,19 @@ async function updatePlugin() {
|
|
|
168
200
|
Object.keys(pluginRootMap).forEach((name) => {
|
|
169
201
|
const packageInfo = fs.readJsonSync(path.join(pluginRootMap[name], "package.json"));
|
|
170
202
|
const pluginInfo = searchPluginsInfo.find((plugin) => plugin.name === name);
|
|
171
|
-
if (!pluginInfo
|
|
203
|
+
if (!pluginInfo) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const isDevelopmentPlugin = developmentPlugins.includes(name);
|
|
207
|
+
const condition = isDevelopmentPlugin ? !includeDev : packageInfo.version === pluginInfo.version;
|
|
208
|
+
if (condition) {
|
|
172
209
|
return;
|
|
173
210
|
}
|
|
174
211
|
needUpdatePlugins.push({
|
|
175
212
|
name,
|
|
176
213
|
version: packageInfo.version,
|
|
177
|
-
target: pluginInfo.version
|
|
214
|
+
target: pluginInfo.version,
|
|
215
|
+
isDev: isDevelopmentPlugin
|
|
178
216
|
});
|
|
179
217
|
});
|
|
180
218
|
if (needUpdatePlugins.length === 0) {
|
|
@@ -182,9 +220,11 @@ async function updatePlugin() {
|
|
|
182
220
|
return;
|
|
183
221
|
}
|
|
184
222
|
log.info("Need update plugins:");
|
|
185
|
-
needUpdatePlugins.
|
|
186
|
-
|
|
187
|
-
|
|
223
|
+
console.log(columnify(needUpdatePlugins.map(({ name, version, target, isDev }) => ({
|
|
224
|
+
name: nameColor(name),
|
|
225
|
+
version: dim(gray(`${isDev ? "[dev] " : ""}${version}`)),
|
|
226
|
+
target
|
|
227
|
+
}))));
|
|
188
228
|
const confirm = await inquirer.confirm("Do you want to update these plugins?");
|
|
189
229
|
if (!confirm) {
|
|
190
230
|
log.warn("Update canceled");
|
|
@@ -197,71 +237,30 @@ async function updatePlugin() {
|
|
|
197
237
|
);
|
|
198
238
|
log.success(`Plugins updated: ${displayNames}`);
|
|
199
239
|
}
|
|
200
|
-
async function
|
|
240
|
+
async function fetchDevelopmentPlugins() {
|
|
201
241
|
const npmListResult = await c("npm", ["list", "-g", "--depth=0"]);
|
|
202
|
-
const
|
|
242
|
+
const pluginNames = [];
|
|
203
243
|
npmListResult.content.split(/\r?\n/).forEach((line) => {
|
|
204
244
|
const metched = /(?:@initx-plugin\/|initx-plugin-)[^@]+/.exec(line);
|
|
205
245
|
if (metched && line.includes("->")) {
|
|
206
|
-
|
|
246
|
+
pluginNames.push(metched[0]);
|
|
207
247
|
}
|
|
208
248
|
});
|
|
209
|
-
return
|
|
210
|
-
}
|
|
211
|
-
|
|
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)}`);
|
|
249
|
+
return pluginNames;
|
|
242
250
|
}
|
|
243
251
|
|
|
244
|
-
var __defProp = Object.defineProperty;
|
|
245
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
246
|
-
var __publicField = (obj, key, value) => {
|
|
247
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
248
|
-
return value;
|
|
249
|
-
};
|
|
250
252
|
class PluginManagerPlugin extends InitxPlugin {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
]);
|
|
259
|
-
}
|
|
260
|
-
async handle(_ctx, type, ...others) {
|
|
253
|
+
matchers = [
|
|
254
|
+
{
|
|
255
|
+
matching: "plugin",
|
|
256
|
+
description: "Plugin Manager"
|
|
257
|
+
}
|
|
258
|
+
];
|
|
259
|
+
async handle(context, type, ...others) {
|
|
261
260
|
const [name] = others;
|
|
262
261
|
switch (type) {
|
|
263
262
|
case "list": {
|
|
264
|
-
showPluginList();
|
|
263
|
+
await showPluginList();
|
|
265
264
|
break;
|
|
266
265
|
}
|
|
267
266
|
case "add": {
|
|
@@ -269,7 +268,7 @@ class PluginManagerPlugin extends InitxPlugin {
|
|
|
269
268
|
break;
|
|
270
269
|
}
|
|
271
270
|
case "update": {
|
|
272
|
-
await updatePlugin();
|
|
271
|
+
await updatePlugin(context.cliOptions);
|
|
273
272
|
break;
|
|
274
273
|
}
|
|
275
274
|
case "remove": {
|
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.4",
|
|
5
5
|
"description": "initx plugin manager",
|
|
6
6
|
"author": "imba97",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,24 +24,23 @@
|
|
|
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.27",
|
|
28
|
+
"@initx-plugin/utils": "^0.0.27",
|
|
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
|
-
"@types/node": "^22.
|
|
39
|
-
"bumpp": "^9.
|
|
40
|
-
"eslint": "^9.
|
|
41
|
-
"lint-staged": "^15.
|
|
37
|
+
"@types/node": "^22.10.2",
|
|
38
|
+
"bumpp": "^9.9.2",
|
|
39
|
+
"eslint": "^9.17.0",
|
|
40
|
+
"lint-staged": "^15.3.0",
|
|
42
41
|
"simple-git-hooks": "^2.11.1",
|
|
43
|
-
"typescript": "^5.
|
|
44
|
-
"unbuild": "^
|
|
42
|
+
"typescript": "^5.7.2",
|
|
43
|
+
"unbuild": "^3.1.0"
|
|
45
44
|
},
|
|
46
45
|
"simple-git-hooks": {
|
|
47
46
|
"pre-commit": "pnpm lint-staged"
|