@tgrv/void-cli 1.0.7 → 1.0.8
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 +99 -33
- 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
|
-
|
|
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 = {
|
|
@@ -268,48 +283,99 @@ function runAdd(pluginNameInput, appDir) {
|
|
|
268
283
|
process.exit(1);
|
|
269
284
|
}
|
|
270
285
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
// Look up local build directory
|
|
286
|
+
let pluginName = pluginNameInput;
|
|
287
|
+
let requestedVersion = null;
|
|
275
288
|
let localBuildDir = null;
|
|
276
289
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
290
|
+
// Check if input is a local path
|
|
291
|
+
const isPath = pluginNameInput.startsWith(".") ||
|
|
292
|
+
pluginNameInput.startsWith("/") ||
|
|
293
|
+
pluginNameInput.startsWith("\\") ||
|
|
294
|
+
pluginNameInput.includes(":\\");
|
|
295
|
+
|
|
296
|
+
if (isPath) {
|
|
297
|
+
const absolutePath = path.resolve(appDir, pluginNameInput);
|
|
298
|
+
if (fs.existsSync(absolutePath)) {
|
|
299
|
+
const stats = fs.statSync(absolutePath);
|
|
300
|
+
const searchDir = stats.isDirectory() ? absolutePath : path.dirname(absolutePath);
|
|
301
|
+
|
|
302
|
+
const voidJsonPath = path.join(searchDir, "void.json");
|
|
303
|
+
const packageJsonPath = path.join(searchDir, "package.json");
|
|
304
|
+
|
|
305
|
+
if (fs.existsSync(voidJsonPath)) {
|
|
306
|
+
try {
|
|
307
|
+
const manifest = JSON.parse(fs.readFileSync(voidJsonPath, "utf8"));
|
|
308
|
+
pluginName = manifest.name;
|
|
309
|
+
if (manifest.buildDir) {
|
|
310
|
+
const buildPath = path.join(searchDir, manifest.buildDir);
|
|
311
|
+
if (fs.existsSync(buildPath)) {
|
|
312
|
+
localBuildDir = buildPath;
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
localBuildDir = searchDir;
|
|
316
|
+
}
|
|
317
|
+
} catch (e) {
|
|
318
|
+
console.error(`${cross} ${colors.red}Error parsing void.json at path: ${voidJsonPath}${colors.reset}`);
|
|
319
|
+
}
|
|
320
|
+
} else if (fs.existsSync(packageJsonPath)) {
|
|
321
|
+
try {
|
|
322
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
323
|
+
pluginName = pkg.name;
|
|
324
|
+
localBuildDir = searchDir;
|
|
325
|
+
} catch (e) {
|
|
326
|
+
console.error(`${cross} ${colors.red}Error parsing package.json at path: ${packageJsonPath}${colors.reset}`);
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
pluginName = path.basename(searchDir);
|
|
330
|
+
localBuildDir = searchDir;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
const parsed = parsePackageSpec(pluginNameInput);
|
|
335
|
+
pluginName = parsed.name;
|
|
336
|
+
requestedVersion = parsed.version;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const config = JSON.parse(fs.readFileSync(configInfo.configPath, "utf8"));
|
|
340
|
+
|
|
341
|
+
if (!localBuildDir) {
|
|
342
|
+
const scanLocations = [
|
|
343
|
+
path.join(workspaceDir, "plugins"),
|
|
344
|
+
path.join(workspaceDir, "packages"),
|
|
345
|
+
path.join(workspaceDir, "sdk")
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
for (const root of scanLocations) {
|
|
349
|
+
if (fs.existsSync(root)) {
|
|
350
|
+
const subdirs = fs.readdirSync(root);
|
|
351
|
+
for (const subdir of subdirs) {
|
|
352
|
+
const pPath = path.join(root, subdir);
|
|
353
|
+
if (fs.statSync(pPath).isDirectory()) {
|
|
354
|
+
// Scans nested scopes (e.g. plugins/math/@tgrv/void-math)
|
|
355
|
+
const entries = fs.readdirSync(pPath);
|
|
356
|
+
for (const entry of entries) {
|
|
357
|
+
if (entry.startsWith("@")) {
|
|
358
|
+
const scopePath = path.join(pPath, entry);
|
|
359
|
+
const subfolders = fs.readdirSync(scopePath);
|
|
360
|
+
for (const name of subfolders) {
|
|
361
|
+
const pkgPath = path.join(scopePath, name, "package.json");
|
|
362
|
+
if (fs.existsSync(pkgPath)) {
|
|
363
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
364
|
+
if (pkg.name === pluginName) {
|
|
365
|
+
localBuildDir = path.join(scopePath, name);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
302
368
|
}
|
|
303
369
|
}
|
|
304
370
|
}
|
|
371
|
+
if (localBuildDir) break;
|
|
305
372
|
}
|
|
306
|
-
if (localBuildDir) break;
|
|
307
373
|
}
|
|
374
|
+
if (localBuildDir) break;
|
|
308
375
|
}
|
|
309
|
-
if (localBuildDir) break;
|
|
310
376
|
}
|
|
377
|
+
if (localBuildDir) break;
|
|
311
378
|
}
|
|
312
|
-
if (localBuildDir) break;
|
|
313
379
|
}
|
|
314
380
|
|
|
315
381
|
const targetPluginDir = path.join(appDir, "node_modules", pluginName);
|