@tgrv/void-cli 1.0.5 → 1.0.7
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/bin/void.js +82 -8
- package/package.json +1 -1
package/bin/void.js
CHANGED
|
@@ -99,6 +99,7 @@ ${colors.bold}Usage:${colors.reset}
|
|
|
99
99
|
${colors.green}void publish [plugin-path]${colors.reset} - Build and publish the plugin to npm registry (default: .)
|
|
100
100
|
${colors.green}void add <plugin-name>${colors.reset} - Add a plugin from registry/local build into application
|
|
101
101
|
${colors.green}void remove <plugin-name>${colors.reset} - Remove a plugin from application and configuration
|
|
102
|
+
${colors.green}void update${colors.reset} - Update all installed plugins to their latest versions
|
|
102
103
|
${colors.green}void view <plugin-name>${colors.reset} - Inspect an installed plugin and list all its exposed functions
|
|
103
104
|
`);
|
|
104
105
|
process.exit(0);
|
|
@@ -198,7 +199,7 @@ function runBuild(pluginPathArg) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
|
|
201
|
-
// Write package.json if it does not already exist
|
|
202
|
+
// Write package.json if it does not already exist, or check version if it does
|
|
202
203
|
const packageJsonPath = path.join(buildOutputDir, "package.json");
|
|
203
204
|
if (!fs.existsSync(packageJsonPath)) {
|
|
204
205
|
const pkgJson = {
|
|
@@ -214,6 +215,17 @@ function runBuild(pluginPathArg) {
|
|
|
214
215
|
}
|
|
215
216
|
};
|
|
216
217
|
fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
218
|
+
} else {
|
|
219
|
+
try {
|
|
220
|
+
const existingPkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
221
|
+
if (existingPkg.version !== manifest.version) {
|
|
222
|
+
console.log(`${info} Version mismatch detected in ${packageJsonPath}. Updating from ${existingPkg.version} to ${manifest.version} to match void.json.`);
|
|
223
|
+
existingPkg.version = manifest.version || "1.0.0";
|
|
224
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(existingPkg, null, 2));
|
|
225
|
+
}
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.warn(`${warning} Failed to check/update existing package.json version: ${err.message}`);
|
|
228
|
+
}
|
|
217
229
|
}
|
|
218
230
|
|
|
219
231
|
// Generate standard ESM index.js loader
|
|
@@ -235,13 +247,28 @@ export default plugin;
|
|
|
235
247
|
return buildOutputDir;
|
|
236
248
|
}
|
|
237
249
|
|
|
238
|
-
function
|
|
250
|
+
function parsePackageSpec(spec) {
|
|
251
|
+
if (spec.startsWith("@")) {
|
|
252
|
+
const parts = spec.slice(1).split("@");
|
|
253
|
+
const name = "@" + parts[0];
|
|
254
|
+
const version = parts[1] || null;
|
|
255
|
+
return { name, version };
|
|
256
|
+
} else {
|
|
257
|
+
const parts = spec.split("@");
|
|
258
|
+
const name = parts[0];
|
|
259
|
+
const version = parts[1] || null;
|
|
260
|
+
return { name, version };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function runAdd(pluginNameInput, appDir) {
|
|
239
265
|
const configInfo = findConfig(appDir);
|
|
240
266
|
if (!configInfo) {
|
|
241
267
|
console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
|
|
242
268
|
process.exit(1);
|
|
243
269
|
}
|
|
244
270
|
|
|
271
|
+
const { name: pluginName, version: requestedVersion } = parsePackageSpec(pluginNameInput);
|
|
245
272
|
const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
|
|
246
273
|
|
|
247
274
|
// Look up local build directory
|
|
@@ -288,19 +315,37 @@ function runAdd(pluginName, appDir) {
|
|
|
288
315
|
const targetPluginDir = path.join(appDir, "node_modules", pluginName);
|
|
289
316
|
ensureDir(path.dirname(targetPluginDir));
|
|
290
317
|
|
|
318
|
+
let resolvedVersion = "1.0.0";
|
|
319
|
+
|
|
291
320
|
if (localBuildDir) {
|
|
292
321
|
console.log(`${info} Installing local build of '${colors.bold}${pluginName}${colors.reset}' from ${localBuildDir} to ${targetPluginDir}...`);
|
|
293
322
|
if (fs.existsSync(targetPluginDir)) {
|
|
294
323
|
fs.rmSync(targetPluginDir, { recursive: true, force: true });
|
|
295
324
|
}
|
|
296
325
|
copyFolderRecursive(localBuildDir, targetPluginDir);
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
const localPkgPath = path.join(localBuildDir, "package.json");
|
|
329
|
+
if (fs.existsSync(localPkgPath)) {
|
|
330
|
+
const localPkg = JSON.parse(fs.readFileSync(localPkgPath, "utf8"));
|
|
331
|
+
resolvedVersion = localPkg.version || "1.0.0";
|
|
332
|
+
}
|
|
333
|
+
} catch (e) {}
|
|
297
334
|
} else {
|
|
298
|
-
console.log(`${info} Installing '${colors.bold}${
|
|
299
|
-
const npmSuccess = runCommand(`npm install ${
|
|
335
|
+
console.log(`${info} Installing '${colors.bold}${pluginNameInput}${colors.reset}' from NPM registry...`);
|
|
336
|
+
const npmSuccess = runCommand(`npm install ${pluginNameInput}`, { cwd: appDir });
|
|
300
337
|
if (!npmSuccess) {
|
|
301
|
-
console.error(`${cross} ${colors.red}Error: Failed to install package '${
|
|
338
|
+
console.error(`${cross} ${colors.red}Error: Failed to install package '${pluginNameInput}' via npm.${colors.reset}`);
|
|
302
339
|
process.exit(1);
|
|
303
340
|
}
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
const installedPkgPath = path.join(appDir, "node_modules", pluginName, "package.json");
|
|
344
|
+
if (fs.existsSync(installedPkgPath)) {
|
|
345
|
+
const installedPkg = JSON.parse(fs.readFileSync(installedPkgPath, "utf8"));
|
|
346
|
+
resolvedVersion = installedPkg.version || "1.0.0";
|
|
347
|
+
}
|
|
348
|
+
} catch (e) {}
|
|
304
349
|
}
|
|
305
350
|
|
|
306
351
|
// Update package.json of the application
|
|
@@ -308,18 +353,42 @@ function runAdd(pluginName, appDir) {
|
|
|
308
353
|
if (fs.existsSync(pkgPath)) {
|
|
309
354
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
310
355
|
pkg.dependencies = pkg.dependencies || {};
|
|
311
|
-
pkg.dependencies[pluginName] =
|
|
356
|
+
pkg.dependencies[pluginName] = `^${resolvedVersion}`;
|
|
312
357
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
313
358
|
}
|
|
314
359
|
|
|
315
360
|
// Update void.config.json
|
|
316
361
|
config.plugins = config.plugins || {};
|
|
317
|
-
config.plugins[pluginName] =
|
|
362
|
+
config.plugins[pluginName] = `^${resolvedVersion}`;
|
|
318
363
|
fs.writeFileSync(configInfo.configPath, JSON.stringify(config, null, 2));
|
|
319
364
|
|
|
320
|
-
console.log(`${tick} ${colors.green}Successfully added '${pluginName}'!${colors.reset}\n`);
|
|
365
|
+
console.log(`${tick} ${colors.green}Successfully added '${pluginName}' (version ^${resolvedVersion})!${colors.reset}\n`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function runUpdate(appDir) {
|
|
369
|
+
const configInfo = findConfig(appDir);
|
|
370
|
+
if (!configInfo) {
|
|
371
|
+
console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
|
|
372
|
+
process.exit(1);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
|
|
376
|
+
const plugins = config.plugins || {};
|
|
377
|
+
const pluginNames = Object.keys(plugins);
|
|
378
|
+
|
|
379
|
+
if (pluginNames.length === 0) {
|
|
380
|
+
console.log(`${info} No plugins configured to update.`);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
console.log(`\n${info} Updating plugins to latest versions...`);
|
|
385
|
+
for (const name of pluginNames) {
|
|
386
|
+
runAdd(`${name}@latest`, appDir);
|
|
387
|
+
}
|
|
388
|
+
console.log(`${tick} ${colors.green}All plugins updated successfully!${colors.reset}\n`);
|
|
321
389
|
}
|
|
322
390
|
|
|
391
|
+
|
|
323
392
|
async function main() {
|
|
324
393
|
switch (command) {
|
|
325
394
|
case "init": {
|
|
@@ -535,6 +604,11 @@ try {
|
|
|
535
604
|
break;
|
|
536
605
|
}
|
|
537
606
|
|
|
607
|
+
case "update": {
|
|
608
|
+
runUpdate(process.cwd());
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
|
|
538
612
|
case "view": {
|
|
539
613
|
const pluginName = args[1];
|
|
540
614
|
if (!pluginName) {
|