diff --git a/src/commands/reset.js b/src/commands/reset.js index b56ae89..7df3765 100644 --- a/src/commands/reset.js +++ b/src/commands/reset.js @@ -4,7 +4,7 @@ const inquirer = require('inquirer'); const path = require('path'); const { glob } = require('glob'); const config = require('../lib/config'); -const { discoverComponents } = require('../lib/discover'); +const { discoverComponents, toGlobPattern } = require('../lib/discover'); const { getDomain, getComponentTypes } = require('../lib/vnextConfig'); const { getJsonMetadata, findAllJson, detectComponentType } = require('../lib/workflow'); const { publishComponent, reinitializeSystem } = require('../lib/api'); @@ -93,7 +93,7 @@ async function resetCommand(options) { } // Find JSONs in this folder only - const pattern = path.join(dir, '**/*.json'); + const pattern = toGlobPattern(dir, '**/*.json'); const files = await glob(pattern, { ignore: [ '**/.meta/**', diff --git a/src/lib/csx.js b/src/lib/csx.js index 13f5cbb..ef5a356 100644 --- a/src/lib/csx.js +++ b/src/lib/csx.js @@ -93,7 +93,8 @@ function getCsxLocation(csxPath, projectRoot) { /** * Updates ALL CSX codes in a JSON file * Updates all references with the same location - * Supports encoding types: NAT (native/plain text), B64 (Base64, default) + * Encoding handling: absent/B64 -> Base64 (default), NAT -> native source as + * an escaped JSON string, any other value (e.g. REF) -> left untouched * @param {string} jsonPath - JSON file path * @param {string} csxLocation - CSX location path * @param {string} base64Code - Base64 encoded CSX content @@ -122,17 +123,22 @@ async function updateCodeInJson(jsonPath, csxLocation, base64Code, nativeCode) { } if (obj.location === csxLocation && 'code' in obj) { - // Check encoding type: NAT = Native (plain text), B64 or empty = Base64 (default) + // Encoding decides how the CSX content is embedded: + // absent / B64 -> Base64 (default) + // NAT -> JSON-stringified native source + // anything else (e.g. REF) -> leave untouched const encoding = obj.encoding ? obj.encoding.toUpperCase() : 'B64'; - - if (encoding === 'NAT') { - // Native encoding - write plain text content - obj.code = nativeCode; - } else { - // B64 or default - write Base64 encoded content + + if (encoding === 'B64') { obj.code = base64Code; + updateCount++; + } else if (encoding === 'NAT') { + // Native source as-is; JSON.stringify of the whole document escapes + // newlines/quotes so the stored value becomes a normal JSON string. + obj.code = nativeCode; + updateCount++; } - updateCount++; + // Other encodings (e.g. REF) are intentionally skipped — no modification. } // Scan all elements in array or object diff --git a/src/lib/discover.js b/src/lib/discover.js index 4917be5..1bdb43c 100644 --- a/src/lib/discover.js +++ b/src/lib/discover.js @@ -3,6 +3,19 @@ const path = require('path'); const fs = require('fs'); const { getComponentsRoot, getComponentTypes } = require('./vnextConfig'); +/** + * Builds a glob pattern with forward slashes. + * glob treats backslashes as escape characters, so on Windows a pattern built + * with path.join (which uses "\") breaks "**" recursion and nested files are + * never matched. Always feed glob forward-slash separators. + * @param {string} dir - Base directory + * @param {string} suffix - Glob suffix, e.g. "**\/*.json" + * @returns {string} Forward-slash glob pattern + */ +function toGlobPattern(dir, suffix) { + return path.join(dir, suffix).split(path.sep).join('/'); +} + /** * Discovers component folders based on vnext.config.json paths * Only scans folders defined in paths, ignores everything else @@ -35,8 +48,8 @@ async function discoverComponents(projectRoot) { * @returns {Promise} JSON file paths */ async function findJsonInComponent(componentDir) { - const pattern = path.join(componentDir, '**/*.json'); - + const pattern = toGlobPattern(componentDir, '**/*.json'); + const files = await glob(pattern, { ignore: [ '**/.meta/**', @@ -90,7 +103,7 @@ async function findAllCsxInComponents(projectRoot) { // Only scan folders that were discovered from paths for (const [type, componentDir] of Object.entries(discovered)) { if (componentDir) { - const pattern = path.join(componentDir, '**/*.csx'); + const pattern = toGlobPattern(componentDir, '**/*.csx'); const files = await glob(pattern, { ignore: [ '**/.meta/**', @@ -157,6 +170,7 @@ function detectComponentTypeFromPath(filePath, componentTypes) { } module.exports = { + toGlobPattern, discoverComponents, findJsonInComponent, findAllJsonFiles, diff --git a/src/lib/workflow.js b/src/lib/workflow.js index df92c7a..3cbd2b2 100644 --- a/src/lib/workflow.js +++ b/src/lib/workflow.js @@ -4,7 +4,7 @@ const { glob } = require('glob'); const { publishComponent } = require('./api'); const { getInstanceId, deleteWorkflow } = require('./db'); const { getComponentTypes } = require('./vnextConfig'); -const { discoverComponents, findJsonInComponent } = require('./discover'); +const { discoverComponents, findJsonInComponent, toGlobPattern } = require('./discover'); /** * Gets key and version values from JSON file @@ -167,7 +167,7 @@ async function getGitChangedJson(projectRoot) { * @returns {Promise} JSON file paths */ async function findAllJsonInComponent(componentDir) { - const pattern = path.join(componentDir, '**/*.json'); + const pattern = toGlobPattern(componentDir, '**/*.json'); const files = await glob(pattern, { ignore: [ '**/.meta/**',