@tgrv/void-cli 1.0.3 → 1.0.5

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 +133 -105
  2. package/package.json +1 -1
package/bin/void.js CHANGED
@@ -189,20 +189,32 @@ function runBuild(pluginPathArg) {
189
189
  // Copy WASM
190
190
  fs.copyFileSync(builtWasmPath, path.join(buildOutputDir, "plugin.wasm"));
191
191
 
192
- // Write package.json
193
- const pkgJson = {
194
- name: pluginName,
195
- version: manifest.version || "1.0.0",
196
- type: "module",
197
- main: "index.js",
198
- dependencies: {
199
- "@tgrv/void-runtime": "^1.0.0",
200
- },
201
- publishConfig: {
202
- access: "public"
192
+ // Clean up temporary compiled WASM
193
+ if (path.dirname(builtWasmPath) === absolutePluginDir) {
194
+ try {
195
+ fs.unlinkSync(builtWasmPath);
196
+ } catch (e) {
197
+ // Ignore
203
198
  }
204
- };
205
- fs.writeFileSync(path.join(buildOutputDir, "package.json"), JSON.stringify(pkgJson, null, 2));
199
+ }
200
+
201
+ // Write package.json if it does not already exist
202
+ const packageJsonPath = path.join(buildOutputDir, "package.json");
203
+ if (!fs.existsSync(packageJsonPath)) {
204
+ const pkgJson = {
205
+ name: pluginName,
206
+ version: manifest.version || "1.0.0",
207
+ type: "module",
208
+ main: "index.js",
209
+ dependencies: {
210
+ "@tgrv/void-runtime": "^1.0.0",
211
+ },
212
+ publishConfig: {
213
+ access: "public"
214
+ }
215
+ };
216
+ fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2));
217
+ }
206
218
 
207
219
  // Generate standard ESM index.js loader
208
220
  const indexJsContent = `import { runtime } from "@tgrv/void-runtime";
@@ -223,6 +235,91 @@ export default plugin;
223
235
  return buildOutputDir;
224
236
  }
225
237
 
238
+ function runAdd(pluginName, appDir) {
239
+ const configInfo = findConfig(appDir);
240
+ if (!configInfo) {
241
+ console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
242
+ process.exit(1);
243
+ }
244
+
245
+ const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
246
+
247
+ // Look up local build directory
248
+ let localBuildDir = null;
249
+
250
+ const scanLocations = [
251
+ path.join(workspaceDir, "plugins"),
252
+ path.join(workspaceDir, "packages"),
253
+ path.join(workspaceDir, "sdk")
254
+ ];
255
+
256
+ for (const root of scanLocations) {
257
+ if (fs.existsSync(root)) {
258
+ const subdirs = fs.readdirSync(root);
259
+ for (const subdir of subdirs) {
260
+ const pPath = path.join(root, subdir);
261
+ if (fs.statSync(pPath).isDirectory()) {
262
+ // Scans nested scopes (e.g. plugins/math/@tgrv/void-math)
263
+ const entries = fs.readdirSync(pPath);
264
+ for (const entry of entries) {
265
+ if (entry.startsWith("@")) {
266
+ const scopePath = path.join(pPath, entry);
267
+ const subfolders = fs.readdirSync(scopePath);
268
+ for (const name of subfolders) {
269
+ const pkgPath = path.join(scopePath, name, "package.json");
270
+ if (fs.existsSync(pkgPath)) {
271
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
272
+ if (pkg.name === pluginName) {
273
+ localBuildDir = path.join(scopePath, name);
274
+ break;
275
+ }
276
+ }
277
+ }
278
+ }
279
+ if (localBuildDir) break;
280
+ }
281
+ }
282
+ if (localBuildDir) break;
283
+ }
284
+ }
285
+ if (localBuildDir) break;
286
+ }
287
+
288
+ const targetPluginDir = path.join(appDir, "node_modules", pluginName);
289
+ ensureDir(path.dirname(targetPluginDir));
290
+
291
+ if (localBuildDir) {
292
+ console.log(`${info} Installing local build of '${colors.bold}${pluginName}${colors.reset}' from ${localBuildDir} to ${targetPluginDir}...`);
293
+ if (fs.existsSync(targetPluginDir)) {
294
+ fs.rmSync(targetPluginDir, { recursive: true, force: true });
295
+ }
296
+ copyFolderRecursive(localBuildDir, targetPluginDir);
297
+ } else {
298
+ console.log(`${info} Installing '${colors.bold}${pluginName}${colors.reset}' from NPM registry...`);
299
+ const npmSuccess = runCommand(`npm install ${pluginName}`, { cwd: appDir });
300
+ if (!npmSuccess) {
301
+ console.error(`${cross} ${colors.red}Error: Failed to install package '${pluginName}' via npm.${colors.reset}`);
302
+ process.exit(1);
303
+ }
304
+ }
305
+
306
+ // Update package.json of the application
307
+ const pkgPath = path.join(appDir, "package.json");
308
+ if (fs.existsSync(pkgPath)) {
309
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
310
+ pkg.dependencies = pkg.dependencies || {};
311
+ pkg.dependencies[pluginName] = "1.0.0";
312
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
313
+ }
314
+
315
+ // Update void.config.json
316
+ config.plugins = config.plugins || {};
317
+ config.plugins[pluginName] = "^1.0.0";
318
+ fs.writeFileSync(configInfo.configPath, JSON.stringify(config, null, 2));
319
+
320
+ console.log(`${tick} ${colors.green}Successfully added '${pluginName}'!${colors.reset}\n`);
321
+ }
322
+
226
323
  async function main() {
227
324
  switch (command) {
228
325
  case "init": {
@@ -232,9 +329,11 @@ async function main() {
232
329
 
233
330
  console.log(`\n${info} Initializing Void project at: ${colors.bold}${targetDir}${colors.reset}`);
234
331
 
332
+ const hasExistingPkg = fs.existsSync(path.join(targetDir, "package.json"));
333
+
235
334
  // Initialize package.json if not exists
236
335
  const pkgPath = path.join(targetDir, "package.json");
237
- if (!fs.existsSync(pkgPath)) {
336
+ if (!hasExistingPkg) {
238
337
  const defaultPkg = {
239
338
  name: path.basename(targetDir),
240
339
  version: "1.0.0",
@@ -254,10 +353,11 @@ async function main() {
254
353
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
255
354
  }
256
355
 
257
- // Write default application app.js
258
- const appPath = path.join(targetDir, "app.js");
259
- if (!fs.existsSync(appPath)) {
260
- const appContent = `import math from "@tgrv/void-math";
356
+ // If it's a fresh project, write default app.js
357
+ if (!hasExistingPkg) {
358
+ const appPath = path.join(targetDir, "app.js");
359
+ if (!fs.existsSync(appPath)) {
360
+ const appContent = `import math from "@tgrv/void-math";
261
361
 
262
362
  console.log("=== Void Application ===");
263
363
 
@@ -267,7 +367,8 @@ try {
267
367
  console.error("Error running application:", e.message);
268
368
  }
269
369
  `;
270
- fs.writeFileSync(appPath, appContent);
370
+ fs.writeFileSync(appPath, appContent);
371
+ }
271
372
  }
272
373
 
273
374
  // Install void-runtime via NPM
@@ -277,11 +378,19 @@ try {
277
378
  console.error(`${cross} ${colors.red}Failed to install @tgrv/void-runtime via npm.${colors.reset}`);
278
379
  }
279
380
 
381
+ // If it's a fresh project, also install @tgrv/void-math using the shared installer logic
382
+ if (!hasExistingPkg) {
383
+ runAdd("@tgrv/void-math", targetDir);
384
+ }
385
+
280
386
  console.log(`${tick} ${colors.green}Successfully initialized Void project!${colors.reset}`);
281
- console.log(`\nTo add plugins, you can run:`);
282
- console.log(` ${colors.cyan}npx void add <plugin-name>${colors.reset}`);
283
- console.log(`For example:`);
284
- console.log(` ${colors.cyan}npx void add @tgrv/void-math${colors.reset}\n`);
387
+ if (!hasExistingPkg) {
388
+ console.log(`\nTo run the starter app, execute:`);
389
+ console.log(` ${colors.cyan}node app.js${colors.reset}\n`);
390
+ } else {
391
+ console.log(`\nTo add plugins, you can run:`);
392
+ console.log(` ${colors.cyan}npx void add <plugin-name>${colors.reset}\n`);
393
+ }
285
394
  break;
286
395
  }
287
396
 
@@ -373,88 +482,7 @@ try {
373
482
  console.error(`${cross} ${colors.red}Error: Please specify the plugin to add. e.g. void add @tgrv/void-math${colors.reset}`);
374
483
  process.exit(1);
375
484
  }
376
-
377
- const configInfo = findConfig(process.cwd());
378
- if (!configInfo) {
379
- console.error(`${cross} ${colors.red}Error: void.config.json not found. Run 'void init' first.${colors.reset}`);
380
- process.exit(1);
381
- }
382
-
383
- const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
384
-
385
- // Look up local build directory inside the plugins/ or packages/ directory tree
386
- let localBuildDir = null;
387
-
388
- const scanLocations = [
389
- path.join(workspaceDir, "plugins"),
390
- path.join(workspaceDir, "packages")
391
- ];
392
-
393
- for (const root of scanLocations) {
394
- if (fs.existsSync(root)) {
395
- const subdirs = fs.readdirSync(root);
396
- for (const subdir of subdirs) {
397
- const pPath = path.join(root, subdir);
398
- if (fs.statSync(pPath).isDirectory()) {
399
- // Scans nested scopes (e.g. plugins/math/@tgrv/void-math)
400
- const entries = fs.readdirSync(pPath);
401
- for (const entry of entries) {
402
- if (entry.startsWith("@")) {
403
- const scopePath = path.join(pPath, entry);
404
- const subfolders = fs.readdirSync(scopePath);
405
- for (const name of subfolders) {
406
- const pkgPath = path.join(scopePath, name, "package.json");
407
- if (fs.existsSync(pkgPath)) {
408
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
409
- if (pkg.name === pluginName) {
410
- localBuildDir = path.join(scopePath, name);
411
- break;
412
- }
413
- }
414
- }
415
- }
416
- if (localBuildDir) break;
417
- }
418
- }
419
- if (localBuildDir) break;
420
- }
421
- }
422
- if (localBuildDir) break;
423
- }
424
-
425
- const targetPluginDir = path.join(process.cwd(), "node_modules", pluginName);
426
- ensureDir(path.dirname(targetPluginDir));
427
-
428
- if (localBuildDir) {
429
- console.log(`${info} Installing local build of '${colors.bold}${pluginName}${colors.reset}' from ${localBuildDir} to ${targetPluginDir}...`);
430
- if (fs.existsSync(targetPluginDir)) {
431
- fs.rmSync(targetPluginDir, { recursive: true, force: true });
432
- }
433
- copyFolderRecursive(localBuildDir, targetPluginDir);
434
- } else {
435
- console.log(`${info} Installing '${colors.bold}${pluginName}${colors.reset}' from NPM registry...`);
436
- const npmSuccess = runCommand(`npm install ${pluginName}`, { cwd: process.cwd() });
437
- if (!npmSuccess) {
438
- console.error(`${cross} ${colors.red}Error: Failed to install package '${pluginName}' via npm.${colors.reset}`);
439
- process.exit(1);
440
- }
441
- }
442
-
443
- // Update package.json of the application
444
- const pkgPath = path.join(process.cwd(), "package.json");
445
- if (fs.existsSync(pkgPath)) {
446
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
447
- pkg.dependencies = pkg.dependencies || {};
448
- pkg.dependencies[pluginName] = "1.0.0";
449
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
450
- }
451
-
452
- // Update void.config.json
453
- config.plugins = config.plugins || {};
454
- config.plugins[pluginName] = "^1.0.0";
455
- fs.writeFileSync(configInfo.configPath, JSON.stringify(config, null, 2));
456
-
457
- console.log(`${tick} ${colors.green}Successfully added '${pluginName}'!${colors.reset}\n`);
485
+ runAdd(pluginName, process.cwd());
458
486
  break;
459
487
  }
460
488
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgrv/void-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "void": "./bin/void.js"