@tgrv/void-cli 1.0.7 → 1.0.9

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 +144 -33
  2. package/package.json +1 -1
package/bin/void.js CHANGED
@@ -10,7 +10,22 @@ const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
11
  const cliRoot = path.resolve(__dirname, "..");
12
12
  const isLocalDev = fs.existsSync(path.join(cliRoot, "../../packages/void-runtime"));
13
- const workspaceDir = isLocalDev ? path.resolve(cliRoot, "../..") : process.cwd();
13
+
14
+ function findWorkspaceRoot(dir) {
15
+ const checkPath = path.join(dir, "packages", "void-runtime");
16
+ if (fs.existsSync(checkPath)) {
17
+ return dir;
18
+ }
19
+ const parent = path.dirname(dir);
20
+ if (parent === dir) {
21
+ return null;
22
+ }
23
+ return findWorkspaceRoot(parent);
24
+ }
25
+
26
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
27
+ const workspaceDir = workspaceRoot || (isLocalDev ? path.resolve(cliRoot, "../..") : process.cwd());
28
+
14
29
 
15
30
  // ANSI Color formatting codes
16
31
  const colors = {
@@ -85,6 +100,50 @@ function copyFolderRecursive(src, dest, replacements = {}) {
85
100
  }
86
101
  }
87
102
 
103
+ function copyNonSourceFiles(src, dest, buildOutputDir) {
104
+ ensureDir(dest);
105
+ const entries = fs.readdirSync(src, { withFileTypes: true });
106
+ for (const entry of entries) {
107
+ const srcPath = path.join(src, entry.name);
108
+ const destPath = path.join(dest, entry.name);
109
+
110
+ // Prevent copying the build output directory into itself
111
+ if (srcPath === buildOutputDir || srcPath.startsWith(buildOutputDir + path.sep)) {
112
+ continue;
113
+ }
114
+
115
+ // Skip standard build/dev folders
116
+ if (entry.name === "@void" ||
117
+ entry.name === "@tgrv" ||
118
+ entry.name === "target" ||
119
+ entry.name === ".git" ||
120
+ entry.name === "node_modules") {
121
+ continue;
122
+ }
123
+
124
+ if (entry.isDirectory()) {
125
+ copyNonSourceFiles(srcPath, destPath, buildOutputDir);
126
+ } else {
127
+ const ext = path.extname(entry.name).toLowerCase();
128
+ const filename = entry.name.toLowerCase();
129
+
130
+ // Exclude Go/Rust/Cargo files and build binaries/configs
131
+ if (ext === ".go" ||
132
+ ext === ".rs" ||
133
+ filename === "cargo.toml" ||
134
+ filename === "cargo.lock" ||
135
+ filename === "go.mod" ||
136
+ filename === "go.sum" ||
137
+ filename === "void.json" ||
138
+ filename === "plugin.wasm") {
139
+ continue;
140
+ }
141
+
142
+ fs.copyFileSync(srcPath, destPath);
143
+ }
144
+ }
145
+ }
146
+
88
147
  const args = process.argv.slice(2);
89
148
  const command = args[0];
90
149
 
@@ -243,6 +302,7 @@ const plugin = await runtime.load(
243
302
  export default plugin;
244
303
  `;
245
304
  fs.writeFileSync(path.join(buildOutputDir, "index.js"), indexJsContent);
305
+ copyNonSourceFiles(absolutePluginDir, buildOutputDir, buildOutputDir);
246
306
  console.log(`${tick} ${colors.green}Successfully completed compilation & packaging!${colors.reset}`);
247
307
  return buildOutputDir;
248
308
  }
@@ -268,48 +328,99 @@ function runAdd(pluginNameInput, appDir) {
268
328
  process.exit(1);
269
329
  }
270
330
 
271
- const { name: pluginName, version: requestedVersion } = parsePackageSpec(pluginNameInput);
272
- const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
273
-
274
- // Look up local build directory
331
+ let pluginName = pluginNameInput;
332
+ let requestedVersion = null;
275
333
  let localBuildDir = null;
276
334
 
277
- const scanLocations = [
278
- path.join(workspaceDir, "plugins"),
279
- path.join(workspaceDir, "packages"),
280
- path.join(workspaceDir, "sdk")
281
- ];
282
-
283
- for (const root of scanLocations) {
284
- if (fs.existsSync(root)) {
285
- const subdirs = fs.readdirSync(root);
286
- for (const subdir of subdirs) {
287
- const pPath = path.join(root, subdir);
288
- if (fs.statSync(pPath).isDirectory()) {
289
- // Scans nested scopes (e.g. plugins/math/@tgrv/void-math)
290
- const entries = fs.readdirSync(pPath);
291
- for (const entry of entries) {
292
- if (entry.startsWith("@")) {
293
- const scopePath = path.join(pPath, entry);
294
- const subfolders = fs.readdirSync(scopePath);
295
- for (const name of subfolders) {
296
- const pkgPath = path.join(scopePath, name, "package.json");
297
- if (fs.existsSync(pkgPath)) {
298
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
299
- if (pkg.name === pluginName) {
300
- localBuildDir = path.join(scopePath, name);
301
- break;
335
+ // Check if input is a local path
336
+ const isPath = pluginNameInput.startsWith(".") ||
337
+ pluginNameInput.startsWith("/") ||
338
+ pluginNameInput.startsWith("\\") ||
339
+ pluginNameInput.includes(":\\");
340
+
341
+ if (isPath) {
342
+ const absolutePath = path.resolve(appDir, pluginNameInput);
343
+ if (fs.existsSync(absolutePath)) {
344
+ const stats = fs.statSync(absolutePath);
345
+ const searchDir = stats.isDirectory() ? absolutePath : path.dirname(absolutePath);
346
+
347
+ const voidJsonPath = path.join(searchDir, "void.json");
348
+ const packageJsonPath = path.join(searchDir, "package.json");
349
+
350
+ if (fs.existsSync(voidJsonPath)) {
351
+ try {
352
+ const manifest = JSON.parse(fs.readFileSync(voidJsonPath, "utf8"));
353
+ pluginName = manifest.name;
354
+ if (manifest.buildDir) {
355
+ const buildPath = path.join(searchDir, manifest.buildDir);
356
+ if (fs.existsSync(buildPath)) {
357
+ localBuildDir = buildPath;
358
+ }
359
+ } else {
360
+ localBuildDir = searchDir;
361
+ }
362
+ } catch (e) {
363
+ console.error(`${cross} ${colors.red}Error parsing void.json at path: ${voidJsonPath}${colors.reset}`);
364
+ }
365
+ } else if (fs.existsSync(packageJsonPath)) {
366
+ try {
367
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
368
+ pluginName = pkg.name;
369
+ localBuildDir = searchDir;
370
+ } catch (e) {
371
+ console.error(`${cross} ${colors.red}Error parsing package.json at path: ${packageJsonPath}${colors.reset}`);
372
+ }
373
+ } else {
374
+ pluginName = path.basename(searchDir);
375
+ localBuildDir = searchDir;
376
+ }
377
+ }
378
+ } else {
379
+ const parsed = parsePackageSpec(pluginNameInput);
380
+ pluginName = parsed.name;
381
+ requestedVersion = parsed.version;
382
+ }
383
+
384
+ const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
385
+
386
+ if (!localBuildDir) {
387
+ const scanLocations = [
388
+ path.join(workspaceDir, "plugins"),
389
+ path.join(workspaceDir, "packages"),
390
+ path.join(workspaceDir, "sdk")
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
+ }
302
413
  }
303
414
  }
304
415
  }
416
+ if (localBuildDir) break;
305
417
  }
306
- if (localBuildDir) break;
307
418
  }
419
+ if (localBuildDir) break;
308
420
  }
309
- if (localBuildDir) break;
310
421
  }
422
+ if (localBuildDir) break;
311
423
  }
312
- if (localBuildDir) break;
313
424
  }
314
425
 
315
426
  const targetPluginDir = path.join(appDir, "node_modules", pluginName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgrv/void-cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "void": "./bin/void.js"