@tgrv/void-cli 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/bin/void.js +70 -7
  2. 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);
@@ -235,13 +236,28 @@ export default plugin;
235
236
  return buildOutputDir;
236
237
  }
237
238
 
238
- function runAdd(pluginName, appDir) {
239
+ function parsePackageSpec(spec) {
240
+ if (spec.startsWith("@")) {
241
+ const parts = spec.slice(1).split("@");
242
+ const name = "@" + parts[0];
243
+ const version = parts[1] || null;
244
+ return { name, version };
245
+ } else {
246
+ const parts = spec.split("@");
247
+ const name = parts[0];
248
+ const version = parts[1] || null;
249
+ return { name, version };
250
+ }
251
+ }
252
+
253
+ function runAdd(pluginNameInput, appDir) {
239
254
  const configInfo = findConfig(appDir);
240
255
  if (!configInfo) {
241
256
  console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
242
257
  process.exit(1);
243
258
  }
244
259
 
260
+ const { name: pluginName, version: requestedVersion } = parsePackageSpec(pluginNameInput);
245
261
  const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
246
262
 
247
263
  // Look up local build directory
@@ -288,19 +304,37 @@ function runAdd(pluginName, appDir) {
288
304
  const targetPluginDir = path.join(appDir, "node_modules", pluginName);
289
305
  ensureDir(path.dirname(targetPluginDir));
290
306
 
307
+ let resolvedVersion = "1.0.0";
308
+
291
309
  if (localBuildDir) {
292
310
  console.log(`${info} Installing local build of '${colors.bold}${pluginName}${colors.reset}' from ${localBuildDir} to ${targetPluginDir}...`);
293
311
  if (fs.existsSync(targetPluginDir)) {
294
312
  fs.rmSync(targetPluginDir, { recursive: true, force: true });
295
313
  }
296
314
  copyFolderRecursive(localBuildDir, targetPluginDir);
315
+
316
+ try {
317
+ const localPkgPath = path.join(localBuildDir, "package.json");
318
+ if (fs.existsSync(localPkgPath)) {
319
+ const localPkg = JSON.parse(fs.readFileSync(localPkgPath, "utf8"));
320
+ resolvedVersion = localPkg.version || "1.0.0";
321
+ }
322
+ } catch (e) {}
297
323
  } else {
298
- console.log(`${info} Installing '${colors.bold}${pluginName}${colors.reset}' from NPM registry...`);
299
- const npmSuccess = runCommand(`npm install ${pluginName}`, { cwd: appDir });
324
+ console.log(`${info} Installing '${colors.bold}${pluginNameInput}${colors.reset}' from NPM registry...`);
325
+ const npmSuccess = runCommand(`npm install ${pluginNameInput}`, { cwd: appDir });
300
326
  if (!npmSuccess) {
301
- console.error(`${cross} ${colors.red}Error: Failed to install package '${pluginName}' via npm.${colors.reset}`);
327
+ console.error(`${cross} ${colors.red}Error: Failed to install package '${pluginNameInput}' via npm.${colors.reset}`);
302
328
  process.exit(1);
303
329
  }
330
+
331
+ try {
332
+ const installedPkgPath = path.join(appDir, "node_modules", pluginName, "package.json");
333
+ if (fs.existsSync(installedPkgPath)) {
334
+ const installedPkg = JSON.parse(fs.readFileSync(installedPkgPath, "utf8"));
335
+ resolvedVersion = installedPkg.version || "1.0.0";
336
+ }
337
+ } catch (e) {}
304
338
  }
305
339
 
306
340
  // Update package.json of the application
@@ -308,18 +342,42 @@ function runAdd(pluginName, appDir) {
308
342
  if (fs.existsSync(pkgPath)) {
309
343
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
310
344
  pkg.dependencies = pkg.dependencies || {};
311
- pkg.dependencies[pluginName] = "1.0.0";
345
+ pkg.dependencies[pluginName] = `^${resolvedVersion}`;
312
346
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
313
347
  }
314
348
 
315
349
  // Update void.config.json
316
350
  config.plugins = config.plugins || {};
317
- config.plugins[pluginName] = "^1.0.0";
351
+ config.plugins[pluginName] = `^${resolvedVersion}`;
318
352
  fs.writeFileSync(configInfo.configPath, JSON.stringify(config, null, 2));
319
353
 
320
- console.log(`${tick} ${colors.green}Successfully added '${pluginName}'!${colors.reset}\n`);
354
+ console.log(`${tick} ${colors.green}Successfully added '${pluginName}' (version ^${resolvedVersion})!${colors.reset}\n`);
355
+ }
356
+
357
+ function runUpdate(appDir) {
358
+ const configInfo = findConfig(appDir);
359
+ if (!configInfo) {
360
+ console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
361
+ process.exit(1);
362
+ }
363
+
364
+ const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
365
+ const plugins = config.plugins || {};
366
+ const pluginNames = Object.keys(plugins);
367
+
368
+ if (pluginNames.length === 0) {
369
+ console.log(`${info} No plugins configured to update.`);
370
+ return;
371
+ }
372
+
373
+ console.log(`\n${info} Updating plugins to latest versions...`);
374
+ for (const name of pluginNames) {
375
+ runAdd(`${name}@latest`, appDir);
376
+ }
377
+ console.log(`${tick} ${colors.green}All plugins updated successfully!${colors.reset}\n`);
321
378
  }
322
379
 
380
+
323
381
  async function main() {
324
382
  switch (command) {
325
383
  case "init": {
@@ -535,6 +593,11 @@ try {
535
593
  break;
536
594
  }
537
595
 
596
+ case "update": {
597
+ runUpdate(process.cwd());
598
+ break;
599
+ }
600
+
538
601
  case "view": {
539
602
  const pluginName = args[1];
540
603
  if (!pluginName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgrv/void-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "void": "./bin/void.js"