@qelos/plugins-cli 0.0.28 → 0.0.30

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qelos/plugins-cli",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "CLI to manage QELOS plugins",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
@@ -86,6 +86,50 @@ function getStagedFiles() {
86
86
  }
87
87
  }
88
88
 
89
+ /**
90
+ * Find configuration files that reference a specific HTML file via $ref
91
+ * @param {string} refPath - The referenced file path (relative)
92
+ * @param {string} basePath - Base path to search for configurations
93
+ * @returns {string[]} Array of configuration file paths that reference the HTML file
94
+ */
95
+ function findReferencingConfigs(refPath, basePath) {
96
+ const referencingConfigs = [];
97
+ const configsDir = path.join(basePath, 'configs');
98
+
99
+ if (!fs.existsSync(configsDir)) {
100
+ return referencingConfigs;
101
+ }
102
+
103
+ const configFiles = fs.readdirSync(configsDir)
104
+ .filter(file => file.endsWith('.config.json'));
105
+
106
+ for (const file of configFiles) {
107
+ const filePath = path.join(configsDir, file);
108
+ try {
109
+ const content = fs.readFileSync(filePath, 'utf-8');
110
+ const config = JSON.parse(content);
111
+
112
+ // Check all $ref references in the config
113
+ const refs = findAllRefs(config);
114
+
115
+ // Check if any ref matches our target HTML file
116
+ // Normalize paths for comparison (handle ./ and different separators)
117
+ const normalizedRefPath = refPath.replace(/^\.\//, '').replace(/\\/g, '/');
118
+
119
+ if (refs.some(ref => {
120
+ const normalizedRef = ref.replace(/^\.\//, '').replace(/\\/g, '/');
121
+ return normalizedRef === normalizedRefPath;
122
+ })) {
123
+ referencingConfigs.push(filePath);
124
+ }
125
+ } catch (error) {
126
+ logger.debug(`Failed to parse config ${file}: ${error.message}`);
127
+ }
128
+ }
129
+
130
+ return referencingConfigs;
131
+ }
132
+
89
133
  /**
90
134
  * Find integration files that reference a specific file via $ref
91
135
  * @param {string} refPath - The referenced file path (relative)
@@ -230,13 +274,24 @@ function classifyFiles(files, basePath) {
230
274
  } else if (ext === '.html') {
231
275
  // HTML files can be in different contexts:
232
276
  // 1. In plugins directory -> micro-frontends (part of a plugin)
233
- // 2. In configs directory -> standalone HTML configs
277
+ // 2. In configs directory -> These are typically referenced by configs, not pushed directly
234
278
  // 3. Other locations -> treat as micro-frontends
235
279
 
236
280
  if (relativePath.includes('configs/') || relativePath.includes('configs\\')) {
237
- // HTML file in configs directory - treat as a config file
238
- classified.configs.push(fullPath);
239
- logger.debug(`Found HTML config file: ${relativePath}`);
281
+ // HTML file in configs directory - these are usually referenced by config files, not pushed directly
282
+ logger.debug(`Found HTML file in configs directory (will be pushed via referencing config): ${relativePath}`);
283
+
284
+ // Find configs that reference this HTML file
285
+ const refPath = './' + path.relative('configs', relativePath);
286
+ const referencingConfigs = findReferencingConfigs(refPath, basePath);
287
+
288
+ // Add the referencing configs to the configs list
289
+ for (const configPath of referencingConfigs) {
290
+ if (!classified.configs.includes(configPath)) {
291
+ classified.configs.push(configPath);
292
+ logger.debug(`Found config referencing HTML ${relativePath}: ${path.basename(configPath)}`);
293
+ }
294
+ }
240
295
  } else {
241
296
  // Find plugins that contain this HTML file (micro-frontends)
242
297
  classified.microFrontends.push(fullPath);
@@ -391,6 +446,39 @@ export function prepareTempDirectories(classifiedFiles, tempDir) {
391
446
  }
392
447
  }
393
448
 
449
+ // If this is a config, check for $ref files and copy them too
450
+ if (type === 'configs' && file.endsWith('.config.json')) {
451
+ try {
452
+ const content = fs.readFileSync(dest, 'utf-8');
453
+ const config = JSON.parse(content);
454
+ const refs = findAllRefs(config);
455
+
456
+ for (const ref of refs) {
457
+ if (copiedRefs.has(ref)) continue;
458
+
459
+ // Resolve the ref path relative to the original file location
460
+ const originalDir = path.dirname(file);
461
+ const refSourcePath = path.resolve(originalDir, ref);
462
+
463
+ if (fs.existsSync(refSourcePath)) {
464
+ // Create the same directory structure in temp
465
+ // The ref is relative to the config file, so we need to copy it to the same relative path
466
+ const refDestPath = path.join(tempDir, 'configs', ref);
467
+ const refDestDir = path.dirname(refDestPath);
468
+
469
+ fs.mkdirSync(refDestDir, { recursive: true });
470
+ fs.copyFileSync(refSourcePath, refDestPath);
471
+ copiedRefs.add(ref);
472
+ logger.debug(`Copied referenced file ${ref} from ${refSourcePath} to ${refDestPath}`);
473
+ } else {
474
+ logger.debug(`Referenced file not found: ${refSourcePath}`);
475
+ }
476
+ }
477
+ } catch (error) {
478
+ logger.debug(`Failed to process refs for ${path.basename(file)}: ${error.message}`);
479
+ }
480
+ }
481
+
394
482
  // If this is a plugin, check for micro-frontend HTML files and copy them too
395
483
  if (type === 'plugins' && file.endsWith('.plugin.json')) {
396
484
  try {