@tgrv/void-cli 1.0.6 → 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 +111 -34
- 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 = {
|
|
@@ -199,7 +214,7 @@ function runBuild(pluginPathArg) {
|
|
|
199
214
|
}
|
|
200
215
|
}
|
|
201
216
|
|
|
202
|
-
// Write package.json if it does not already exist
|
|
217
|
+
// Write package.json if it does not already exist, or check version if it does
|
|
203
218
|
const packageJsonPath = path.join(buildOutputDir, "package.json");
|
|
204
219
|
if (!fs.existsSync(packageJsonPath)) {
|
|
205
220
|
const pkgJson = {
|
|
@@ -215,6 +230,17 @@ function runBuild(pluginPathArg) {
|
|
|
215
230
|
}
|
|
216
231
|
};
|
|
217
232
|
fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
233
|
+
} else {
|
|
234
|
+
try {
|
|
235
|
+
const existingPkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
236
|
+
if (existingPkg.version !== manifest.version) {
|
|
237
|
+
console.log(`${info} Version mismatch detected in ${packageJsonPath}. Updating from ${existingPkg.version} to ${manifest.version} to match void.json.`);
|
|
238
|
+
existingPkg.version = manifest.version || "1.0.0";
|
|
239
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(existingPkg, null, 2));
|
|
240
|
+
}
|
|
241
|
+
} catch (err) {
|
|
242
|
+
console.warn(`${warning} Failed to check/update existing package.json version: ${err.message}`);
|
|
243
|
+
}
|
|
218
244
|
}
|
|
219
245
|
|
|
220
246
|
// Generate standard ESM index.js loader
|
|
@@ -257,48 +283,99 @@ function runAdd(pluginNameInput, appDir) {
|
|
|
257
283
|
process.exit(1);
|
|
258
284
|
}
|
|
259
285
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// Look up local build directory
|
|
286
|
+
let pluginName = pluginNameInput;
|
|
287
|
+
let requestedVersion = null;
|
|
264
288
|
let localBuildDir = null;
|
|
265
289
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
}
|
|
291
368
|
}
|
|
292
369
|
}
|
|
293
370
|
}
|
|
371
|
+
if (localBuildDir) break;
|
|
294
372
|
}
|
|
295
|
-
if (localBuildDir) break;
|
|
296
373
|
}
|
|
374
|
+
if (localBuildDir) break;
|
|
297
375
|
}
|
|
298
|
-
if (localBuildDir) break;
|
|
299
376
|
}
|
|
377
|
+
if (localBuildDir) break;
|
|
300
378
|
}
|
|
301
|
-
if (localBuildDir) break;
|
|
302
379
|
}
|
|
303
380
|
|
|
304
381
|
const targetPluginDir = path.join(appDir, "node_modules", pluginName);
|