@c6fc/spellcraft 0.0.2 → 0.0.3
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/package.json +1 -1
- package/src/index.js +12 -30
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -10,6 +10,8 @@ const { Jsonnet } = require("@hanazuki/node-jsonnet");
|
|
10
10
|
|
11
11
|
const baseDir = process.cwd();
|
12
12
|
|
13
|
+
const thisPackage = JSON.parse(fs.readFileSync("./package.json"));
|
14
|
+
|
13
15
|
/**
|
14
16
|
* @constant {object} defaultFileTypeHandlers
|
15
17
|
* @description Default handlers for different file types based on their extensions.
|
@@ -328,30 +330,15 @@ exports.SpellFrame = class SpellFrame {
|
|
328
330
|
console.log(`[+] Successfully installed ${npmPackage}.`);
|
329
331
|
}
|
330
332
|
|
331
|
-
const
|
332
|
-
if (!fs.existsSync(packageJsonPath)) {
|
333
|
-
throw new Error(`[!] Package ${npmPackage} is missing package.json at ${packageJsonPath}`);
|
334
|
-
}
|
335
|
-
|
336
|
-
const packageConfig = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
337
|
-
const spellcraftConfig = packageConfig.config || packageConfig.spellcraft; // Allow 'spellcraft' key too
|
333
|
+
const spellcraftConfig = thisPackage.config || thisPackage.spellcraft; // Allow 'spellcraft' key too
|
338
334
|
|
339
335
|
if (!name && !spellcraftConfig?.spellcraft_module_default_name) {
|
340
|
-
console.log("Package config:",
|
336
|
+
console.log("Package config:", thisPackage);
|
341
337
|
throw new Error(`[!] No import name specified for ${npmPackage}, and it has no 'spellcraft_module_default_name' in its package.json config.`);
|
342
338
|
}
|
343
339
|
|
344
|
-
// Check if this project is also a module, which shouldn't contain a spellcraft_modules directory.
|
345
|
-
const thisPackageJsonPath = path.join(baseDir, 'package.json');
|
346
|
-
if (!fs.existsSync(npmPath)) {
|
347
|
-
throw new Error(`[!] There's no package.json for your project. Create one with 'npm init' first`);
|
348
|
-
}
|
349
|
-
|
350
|
-
const thisPackageConfig = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
351
|
-
const thisSpellcraftConfig = packageConfig.config || packageConfig.spellcraft; // Allow 'spellcraft' key too
|
352
|
-
|
353
340
|
// Only link if this package is not a module itself.
|
354
|
-
if (!!!
|
341
|
+
if (!!!spellcraftConfig?.spellcraft_module_default_name) {
|
355
342
|
|
356
343
|
const packagesDirPath = path.join(baseDir, 'spellcraft_modules');
|
357
344
|
if (!fs.existsSync(packagesDirPath)) {
|
@@ -375,7 +362,7 @@ exports.SpellFrame = class SpellFrame {
|
|
375
362
|
npmPackage.split('@')[0]; // Handles name and name@version
|
376
363
|
|
377
364
|
const packagesKey = name || spellcraftConfig.spellcraft_module_default_name;
|
378
|
-
packages[
|
365
|
+
packages[npmPackage] = packagesKey; // Store the clean package name
|
379
366
|
|
380
367
|
fs.writeFileSync(packagesFilePath, JSON.stringify(packages, null, "\t"));
|
381
368
|
console.log(`[+] Linked ${npmPackage} as SpellCraft module '${packagesKey}'`);
|
@@ -405,15 +392,10 @@ exports.SpellFrame = class SpellFrame {
|
|
405
392
|
// Path to the dynamically generated libsonnet file that imports all modules
|
406
393
|
const dynamicModulesImportFile = path.resolve(__dirname, '../modules/modules');
|
407
394
|
|
408
|
-
// It's crucial this file is managed carefully.
|
409
|
-
// If it exists from a previous failed run or other reasons, it might cause issues.
|
410
|
-
// Option 1: Delete if exists (simple, ensures clean state for this run)
|
411
395
|
if (fs.existsSync(dynamicModulesImportFile)) {
|
412
|
-
|
413
|
-
fs.unlinkSync(dynamicModulesImportFile); // Or ensure it's correctly generated by loadModulesFromModuleDirectory
|
396
|
+
fs.unlinkSync(dynamicModulesImportFile);
|
414
397
|
}
|
415
|
-
|
416
|
-
// loadModulesFromModuleDirectory now handles creation/overwriting.
|
398
|
+
|
417
399
|
|
418
400
|
this.loadModulesFromModuleDirectory(dynamicModulesImportFile);
|
419
401
|
|
@@ -459,10 +441,10 @@ exports.SpellFrame = class SpellFrame {
|
|
459
441
|
return [];
|
460
442
|
}
|
461
443
|
|
462
|
-
const spellcraftConfig =
|
444
|
+
const spellcraftConfig = thisPackage.config || thisPackage.spellcraft; // Allow 'spellcraft' key too
|
463
445
|
|
464
446
|
if (!!spellcraftConfig?.spellcraft_module_default_name) {
|
465
|
-
console.log("This package is a SpellCraft module. Skipping directory-based module import.");
|
447
|
+
console.log("[-] This package is a SpellCraft module. Skipping directory-based module import.");
|
466
448
|
return []
|
467
449
|
}
|
468
450
|
|
@@ -495,7 +477,7 @@ exports.SpellFrame = class SpellFrame {
|
|
495
477
|
return [];
|
496
478
|
}
|
497
479
|
|
498
|
-
return Object.entries(packages).map(([
|
480
|
+
return Object.entries(packages).map(([npmPackageName, moduleKey]) => {
|
499
481
|
return this.loadModuleByName(moduleKey, npmPackageName);
|
500
482
|
}).filter(Boolean); // Filter out any undefined results if a module fails to load
|
501
483
|
}
|
@@ -510,7 +492,7 @@ exports.SpellFrame = class SpellFrame {
|
|
510
492
|
loadModuleByName(moduleKey, npmPackageName) {
|
511
493
|
const packageJsonPath = path.join(baseDir, 'node_modules', npmPackageName, 'package.json');
|
512
494
|
if (!fs.existsSync(packageJsonPath)) {
|
513
|
-
console.
|
495
|
+
console.trace(`[!] package.json not found for module '${moduleKey}' (package: ${npmPackageName}) at ${packageJsonPath}. Skipping.`);
|
514
496
|
return false;
|
515
497
|
}
|
516
498
|
|