@intlayer/engine 9.8.0 → 9.8.2

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.
Files changed (170) hide show
  1. package/dist/assets/initConfig/templates/cjs.txt +16 -15
  2. package/dist/assets/initConfig/templates/json.txt +8 -7
  3. package/dist/assets/initConfig/templates/mjs.txt +16 -15
  4. package/dist/assets/initConfig/templates/ts.txt +16 -15
  5. package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
  6. package/dist/cjs/build.cjs +9 -9
  7. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +3 -3
  8. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +2 -2
  9. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +2 -2
  10. package/dist/cjs/buildIntlayerDictionary/writeNestedDictionary.cjs +2 -2
  11. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +2 -2
  12. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +2 -2
  13. package/dist/cjs/cleanOutputDir.cjs +1 -1
  14. package/dist/cjs/cleanRemovedContentDeclaration.cjs +1 -1
  15. package/dist/cjs/cli.cjs +22 -7
  16. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -1
  17. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +2 -2
  18. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +2 -2
  19. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +2 -2
  20. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +2 -2
  21. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +2 -2
  22. package/dist/cjs/createType/createModuleAugmentation.cjs +1 -1
  23. package/dist/cjs/createType/createType.cjs +1 -1
  24. package/dist/cjs/detectFormatCommand.cjs +45 -0
  25. package/dist/cjs/detectFormatCommand.cjs.map +1 -1
  26. package/dist/cjs/handleContentDeclarationFileChange.cjs +2 -2
  27. package/dist/cjs/init/aiSetup.cjs +280 -0
  28. package/dist/cjs/init/aiSetup.cjs.map +1 -0
  29. package/dist/cjs/init/cms.cjs +50 -6
  30. package/dist/cjs/init/cms.cjs.map +1 -1
  31. package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs +2 -2
  32. package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs +1 -1
  33. package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs +1 -1
  34. package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs +1 -1
  35. package/dist/cjs/init/index.cjs +29 -3
  36. package/dist/cjs/init/index.cjs.map +1 -1
  37. package/dist/cjs/init/utils/configManipulation.cjs +47 -10
  38. package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
  39. package/dist/cjs/init/utils/fileSystem.cjs +2 -2
  40. package/dist/cjs/init/utils/githubActions.cjs +1 -1
  41. package/dist/cjs/init/utils/index.cjs +11 -0
  42. package/dist/cjs/init/utils/intlayerDependencies.cjs +2 -2
  43. package/dist/cjs/init/utils/packageManager.cjs +1 -1
  44. package/dist/cjs/init/utils/toolConfigManipulation.cjs +247 -0
  45. package/dist/cjs/init/utils/toolConfigManipulation.cjs.map +1 -0
  46. package/dist/cjs/initConfig/index.cjs +1 -1
  47. package/dist/cjs/installLSP.cjs +1 -1
  48. package/dist/cjs/installMCP/installMCP.cjs +44 -2
  49. package/dist/cjs/installMCP/installMCP.cjs.map +1 -1
  50. package/dist/cjs/installSkills/index.cjs +1 -1
  51. package/dist/cjs/listGitFiles.cjs +1 -1
  52. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +1 -1
  53. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -1
  54. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +1 -1
  55. package/dist/cjs/loadDictionaries/log.cjs +1 -1
  56. package/dist/cjs/prepareIntlayer.cjs +2 -2
  57. package/dist/cjs/scan/index.cjs +7 -7
  58. package/dist/cjs/syncPluginKit/createFileAdapter.cjs +1 -1
  59. package/dist/cjs/utils/buildComponentFilesList.cjs +1 -1
  60. package/dist/cjs/utils/contentWatcherLock.cjs +2 -2
  61. package/dist/cjs/utils/readDictionariesFromDisk.cjs +1 -1
  62. package/dist/cjs/utils/runOnce.cjs +2 -2
  63. package/dist/cjs/utils/withFileLock.cjs +2 -2
  64. package/dist/cjs/watcher.cjs +4 -4
  65. package/dist/cjs/writeConfiguration/index.cjs +2 -2
  66. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +1 -1
  67. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +3 -12
  68. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  69. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +3 -12
  70. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  71. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +2 -11
  72. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -1
  73. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs +2 -11
  74. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs.map +1 -1
  75. package/dist/cjs/writeFileIfChanged.cjs +2 -2
  76. package/dist/esm/_virtual/_utils_asset.mjs +1 -1
  77. package/dist/esm/build.mjs +9 -9
  78. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +3 -3
  79. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +2 -2
  80. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +2 -2
  81. package/dist/esm/buildIntlayerDictionary/writeNestedDictionary.mjs +2 -2
  82. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +2 -2
  83. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +2 -2
  84. package/dist/esm/cleanOutputDir.mjs +1 -1
  85. package/dist/esm/cleanRemovedContentDeclaration.mjs +1 -1
  86. package/dist/esm/cli.mjs +12 -11
  87. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -1
  88. package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +2 -2
  89. package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +2 -2
  90. package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +2 -2
  91. package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +2 -2
  92. package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +2 -2
  93. package/dist/esm/createType/createModuleAugmentation.mjs +1 -1
  94. package/dist/esm/createType/createType.mjs +1 -1
  95. package/dist/esm/detectFormatCommand.mjs +43 -1
  96. package/dist/esm/detectFormatCommand.mjs.map +1 -1
  97. package/dist/esm/handleContentDeclarationFileChange.mjs +2 -2
  98. package/dist/esm/init/aiSetup.mjs +270 -0
  99. package/dist/esm/init/aiSetup.mjs.map +1 -0
  100. package/dist/esm/init/cms.mjs +50 -8
  101. package/dist/esm/init/cms.mjs.map +1 -1
  102. package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs +2 -2
  103. package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs +1 -1
  104. package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs +1 -1
  105. package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs +1 -1
  106. package/dist/esm/init/index.mjs +29 -3
  107. package/dist/esm/init/index.mjs.map +1 -1
  108. package/dist/esm/init/utils/configManipulation.mjs +47 -11
  109. package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
  110. package/dist/esm/init/utils/fileSystem.mjs +2 -2
  111. package/dist/esm/init/utils/githubActions.mjs +1 -1
  112. package/dist/esm/init/utils/index.mjs +3 -2
  113. package/dist/esm/init/utils/intlayerDependencies.mjs +2 -2
  114. package/dist/esm/init/utils/packageManager.mjs +1 -1
  115. package/dist/esm/init/utils/toolConfigManipulation.mjs +236 -0
  116. package/dist/esm/init/utils/toolConfigManipulation.mjs.map +1 -0
  117. package/dist/esm/initConfig/index.mjs +1 -1
  118. package/dist/esm/installLSP.mjs +1 -1
  119. package/dist/esm/installMCP/installMCP.mjs +44 -3
  120. package/dist/esm/installMCP/installMCP.mjs.map +1 -1
  121. package/dist/esm/installSkills/index.mjs +1 -1
  122. package/dist/esm/listGitFiles.mjs +1 -1
  123. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +1 -1
  124. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +1 -1
  125. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +1 -1
  126. package/dist/esm/loadDictionaries/log.mjs +1 -1
  127. package/dist/esm/prepareIntlayer.mjs +2 -2
  128. package/dist/esm/scan/index.mjs +7 -7
  129. package/dist/esm/syncPluginKit/createFileAdapter.mjs +1 -1
  130. package/dist/esm/utils/buildComponentFilesList.mjs +1 -1
  131. package/dist/esm/utils/contentWatcherLock.mjs +2 -2
  132. package/dist/esm/utils/readDictionariesFromDisk.mjs +1 -1
  133. package/dist/esm/utils/runOnce.mjs +2 -2
  134. package/dist/esm/utils/withFileLock.mjs +2 -2
  135. package/dist/esm/watcher.mjs +4 -4
  136. package/dist/esm/writeConfiguration/index.mjs +2 -2
  137. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +1 -1
  138. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +4 -13
  139. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  140. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +4 -13
  141. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  142. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +3 -12
  143. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -1
  144. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs +3 -12
  145. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs.map +1 -1
  146. package/dist/esm/writeFileIfChanged.mjs +2 -2
  147. package/dist/types/build.d.ts +15 -15
  148. package/dist/types/cli.d.ts +14 -13
  149. package/dist/types/detectFormatCommand.d.ts +24 -0
  150. package/dist/types/detectFormatCommand.d.ts.map +1 -1
  151. package/dist/types/init/aiSetup.d.ts +69 -0
  152. package/dist/types/init/aiSetup.d.ts.map +1 -0
  153. package/dist/types/init/cms.d.ts +13 -1
  154. package/dist/types/init/cms.d.ts.map +1 -1
  155. package/dist/types/init/index.d.ts.map +1 -1
  156. package/dist/types/init/utils/configManipulation.d.ts +14 -0
  157. package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
  158. package/dist/types/init/utils/index.d.ts +3 -2
  159. package/dist/types/init/utils/toolConfigManipulation.d.ts +46 -0
  160. package/dist/types/init/utils/toolConfigManipulation.d.ts.map +1 -0
  161. package/dist/types/installMCP/installMCP.d.ts +6 -0
  162. package/dist/types/installMCP/installMCP.d.ts.map +1 -1
  163. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +1 -1
  164. package/dist/types/scan/index.d.ts +2 -2
  165. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
  166. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  167. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  168. package/dist/types/writeContentDeclaration/writeMarkdownFile.d.ts.map +1 -1
  169. package/dist/types/writeContentDeclaration/writeYamlFile.d.ts.map +1 -1
  170. package/package.json +10 -10
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolConfigManipulation.mjs","names":[],"sources":["../../../../src/init/utils/toolConfigManipulation.ts"],"sourcesContent":["import * as recast from 'recast';\nimport { typescriptParser } from '../../utils/babelParser';\nimport { firstInsertIndex, isModuleScopeBinding } from './astImports';\nimport { LINT_PLUGIN_PACKAGE_NAME } from './lintConfig';\nimport { PRETTIER_PLUGIN_PACKAGE_NAME } from './prettierConfig';\n\nconst { builders: b, namedTypes: n } = recast.types;\n\n/** ESLint flat config file names, in the order ESLint resolves them. */\nexport const ESLINT_FLAT_CONFIG_FILES = [\n 'eslint.config.js',\n 'eslint.config.mjs',\n 'eslint.config.cjs',\n 'eslint.config.ts',\n 'eslint.config.mts',\n 'eslint.config.cts',\n];\n\n/** Prettier config files holding JavaScript / TypeScript. */\nexport const SCRIPT_PRETTIER_CONFIG_FILES = [\n 'prettier.config.js',\n 'prettier.config.mjs',\n 'prettier.config.cjs',\n 'prettier.config.ts',\n 'prettier.config.mts',\n 'prettier.config.cts',\n '.prettierrc.js',\n '.prettierrc.mjs',\n '.prettierrc.cjs',\n '.prettierrc.ts',\n '.prettierrc.mts',\n '.prettierrc.cts',\n];\n\n/** Prettier config files holding YAML. */\nexport const YAML_PRETTIER_CONFIG_FILES = [\n '.prettierrc.yaml',\n '.prettierrc.yml',\n];\n\n/**\n * Outcome of a config patch: `updated` carries the rewritten file, `already`\n * means the plugin is wired, `unsupported` that the file shape is not one the\n * patcher can edit safely (the caller prints the manual snippet instead).\n */\nexport type ToolConfigPatchResult =\n | { status: 'updated'; content: string }\n | { status: 'already' | 'unsupported' };\n\n/** Local name the plugin default import is bound to. */\nconst LINT_PLUGIN_BINDING = 'intlayer';\n\n/**\n * Prints the AST with the quote style the file already uses (single quotes\n * unless the source prefers double ones), so injected strings match it.\n */\nconst printWithSourceQuotes = (ast: any, source: string): string => {\n const singleQuoteCount = (source.match(/'/g) ?? []).length;\n const doubleQuoteCount = (source.match(/\"/g) ?? []).length;\n\n return recast.print(ast, {\n quote: doubleQuoteCount > singleQuoteCount ? 'double' : 'single',\n }).code;\n};\n\n/** Whether the file is CommonJS (`require` / `module.exports`). */\nconst isCommonJsFile = (content: string, extension: string): boolean =>\n extension === 'cjs' ||\n extension === 'cts' ||\n (content.includes('module.exports') && !/^\\s*import\\s/m.test(content));\n\n/** Strips `satisfies` / `as` / parentheses wrappers from an expression. */\nconst unwrapExpression = (expression: any): any => {\n let current = expression;\n\n while (\n current &&\n (current.type === 'TSSatisfiesExpression' ||\n current.type === 'TSAsExpression' ||\n current.type === 'ParenthesizedExpression')\n ) {\n current = current.expression;\n }\n\n return current;\n};\n\n/** Finds the initializer of a top-level `const|let|var <name> = …`. */\nconst findTopLevelInitializer = (ast: any, name: string): any => {\n for (const statement of ast.program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration'\n ? statement.declaration\n : statement;\n\n if (declaration?.type !== 'VariableDeclaration') continue;\n\n for (const declarator of declaration.declarations) {\n if (declarator.id?.type === 'Identifier' && declarator.id.name === name) {\n return declarator.init;\n }\n }\n }\n\n return undefined;\n};\n\n/**\n * Resolves the exported config expression (`export default …` or\n * `module.exports = …`), following one identifier indirection\n * (`const config = …; export default config`).\n */\nconst findExportedConfigExpression = (ast: any): any => {\n let exported: any;\n\n for (const statement of ast.program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n exported = statement.declaration;\n } else if (\n statement.type === 'ExpressionStatement' &&\n statement.expression.type === 'AssignmentExpression' &&\n recast.print(statement.expression.left).code === 'module.exports'\n ) {\n exported = statement.expression.right;\n }\n }\n\n const unwrapped = unwrapExpression(exported);\n\n if (unwrapped?.type === 'Identifier') {\n return unwrapExpression(findTopLevelInitializer(ast, unwrapped.name));\n }\n\n return unwrapped;\n};\n\n/** Adds `import <binding> from '<source>'` (or its `require` form). */\nconst addDefaultImport = (\n ast: any,\n binding: string,\n source: string,\n isCommonJs: boolean\n): void => {\n const declaration = isCommonJs\n ? b.variableDeclaration('const', [\n b.variableDeclarator(\n b.identifier(binding),\n b.callExpression(b.identifier('require'), [b.stringLiteral(source)])\n ),\n ])\n : b.importDeclaration(\n [b.importDefaultSpecifier(b.identifier(binding))],\n b.stringLiteral(source)\n );\n\n const body = ast.program.body;\n let insertIndex = firstInsertIndex(ast);\n\n if (isCommonJs) {\n // Group with the leading `const … = require(…)` statements.\n while (\n insertIndex < body.length &&\n body[insertIndex].type === 'VariableDeclaration' &&\n body[insertIndex].declarations.every(\n (declarator: any) =>\n declarator.init?.type === 'CallExpression' &&\n declarator.init.callee?.name === 'require'\n )\n ) {\n insertIndex++;\n }\n }\n\n body.splice(insertIndex, 0, declaration);\n};\n\n/**\n * Adds `...intlayer.configs.recommended` to an ESLint flat config, importing\n * `eslint-plugin-intlayer` when needed. Handles the exported array, and the\n * `defineConfig(…)` / `tseslint.config(…)` / `composer(…)`-style helpers\n * (array argument or variadic configs).\n */\nexport const addIntlayerPresetToEslintFlatConfig = (\n content: string,\n extension: string\n): ToolConfigPatchResult => {\n if (content.includes(LINT_PLUGIN_PACKAGE_NAME)) return { status: 'already' };\n\n let ast: any;\n try {\n ast = recast.parse(content, { parser: typescriptParser });\n } catch {\n return { status: 'unsupported' };\n }\n\n const configExpression = findExportedConfigExpression(ast);\n\n /** Array the preset is spread into, when the config is (or wraps) one. */\n const targetArray =\n configExpression?.type === 'ArrayExpression'\n ? configExpression\n : configExpression?.type === 'CallExpression' &&\n configExpression.arguments.length === 1 &&\n unwrapExpression(configExpression.arguments[0])?.type ===\n 'ArrayExpression'\n ? unwrapExpression(configExpression.arguments[0])\n : undefined;\n\n const isVariadicHelper =\n !targetArray && configExpression?.type === 'CallExpression';\n\n if (!targetArray && !isVariadicHelper) return { status: 'unsupported' };\n\n // A name clash with an unrelated `intlayer` binding falls back to an alias.\n const binding = isModuleScopeBinding(ast, LINT_PLUGIN_BINDING)\n ? 'intlayerPlugin'\n : LINT_PLUGIN_BINDING;\n\n if (isModuleScopeBinding(ast, binding)) return { status: 'unsupported' };\n\n const presetSpread = b.spreadElement(\n b.memberExpression(\n b.memberExpression(b.identifier(binding), b.identifier('configs')),\n b.identifier('recommended')\n )\n );\n\n if (targetArray) {\n targetArray.elements.push(presetSpread);\n } else {\n configExpression.arguments.push(presetSpread);\n }\n\n addDefaultImport(\n ast,\n binding,\n LINT_PLUGIN_PACKAGE_NAME,\n isCommonJsFile(content, extension)\n );\n\n return { status: 'updated', content: printWithSourceQuotes(ast, content) };\n};\n\n/**\n * Adds `prettier-plugin-intlayer` to the `plugins` of a JavaScript /\n * TypeScript Prettier config (`export default {…}`, `module.exports = {…}`,\n * or an exported `const config = {…}`).\n */\nexport const addIntlayerPluginToPrettierScriptConfig = (\n content: string\n): ToolConfigPatchResult => {\n if (content.includes(PRETTIER_PLUGIN_PACKAGE_NAME)) {\n return { status: 'already' };\n }\n\n let ast: any;\n try {\n ast = recast.parse(content, { parser: typescriptParser });\n } catch {\n return { status: 'unsupported' };\n }\n\n const configObject = findExportedConfigExpression(ast);\n\n if (!n.ObjectExpression.check(configObject)) {\n return { status: 'unsupported' };\n }\n\n const pluginsProperty = (configObject.properties as any[]).find(\n (property) =>\n (property.key?.name ?? property.key?.value) === 'plugins' &&\n property.type !== 'SpreadElement'\n );\n const pluginLiteral = b.stringLiteral(PRETTIER_PLUGIN_PACKAGE_NAME);\n\n if (!pluginsProperty) {\n configObject.properties.push(\n b.property(\n 'init',\n b.identifier('plugins'),\n b.arrayExpression([pluginLiteral])\n )\n );\n } else if (\n unwrapExpression(pluginsProperty.value)?.type === 'ArrayExpression'\n ) {\n unwrapExpression(pluginsProperty.value).elements.push(pluginLiteral);\n } else {\n return { status: 'unsupported' };\n }\n\n return { status: 'updated', content: printWithSourceQuotes(ast, content) };\n};\n\n/**\n * Adds `prettier-plugin-intlayer` to a YAML Prettier config: appends a\n * `plugins` block, or extends an existing block / flow list.\n */\nexport const addIntlayerPluginToPrettierYamlConfig = (\n content: string\n): ToolConfigPatchResult => {\n if (content.includes(PRETTIER_PLUGIN_PACKAGE_NAME)) {\n return { status: 'already' };\n }\n\n const pluginsLineMatch = content.match(/^plugins:[ \\t]*(.*)$/m);\n\n if (!pluginsLineMatch) {\n const separator = content.length > 0 && !content.endsWith('\\n') ? '\\n' : '';\n return {\n status: 'updated',\n content: `${content}${separator}plugins:\\n - ${PRETTIER_PLUGIN_PACKAGE_NAME}\\n`,\n };\n }\n\n const inlineValue = (pluginsLineMatch[1] ?? '').trim();\n\n // Flow list: `plugins: [a, b]` / `plugins: []`.\n const flowListMatch = inlineValue.match(/^\\[(.*)\\]$/);\n if (flowListMatch) {\n const items = (flowListMatch[1] ?? '').trim();\n const nextList = items\n ? `[${items}, ${PRETTIER_PLUGIN_PACKAGE_NAME}]`\n : `[${PRETTIER_PLUGIN_PACKAGE_NAME}]`;\n\n return {\n status: 'updated',\n content: content.replace(pluginsLineMatch[0], `plugins: ${nextList}`),\n };\n }\n\n if (inlineValue !== '') return { status: 'unsupported' };\n\n // Block list: append after the last `- item` of the block.\n const lines = content.split('\\n');\n const pluginsLineIndex = lines.findIndex((line) =>\n line.startsWith('plugins:')\n );\n let lastItemIndex = pluginsLineIndex;\n let indentation = ' ';\n\n for (let index = pluginsLineIndex + 1; index < lines.length; index++) {\n const line = lines[index] ?? '';\n const itemMatch = line.match(/^([ \\t]*)-\\s/);\n if (itemMatch) {\n lastItemIndex = index;\n indentation = itemMatch[1] ?? '';\n } else if (line.trim() !== '' && !/^\\s/.test(line)) {\n break;\n }\n }\n\n lines.splice(\n lastItemIndex + 1,\n 0,\n `${indentation}- ${PRETTIER_PLUGIN_PACKAGE_NAME}`\n );\n\n return { status: 'updated', content: lines.join('\\n') };\n};\n\n/** Content declaration extensions TanStack Router must not treat as routes. */\nexport const CONTENT_DECLARATION_ROUTE_IGNORE_PATTERN =\n '\\\\.content\\\\.(ts|tsx|js|jsx|mjs|cjs|json|jsonc|json5|md|mdx|yaml|yml)$';\n\n/** TanStack plugins accepting a router config, and where it lives. */\nconst TANSTACK_ROUTER_PLUGINS: Record<string, 'root' | 'router'> = {\n tanstackStart: 'router',\n tanstackRouter: 'root',\n TanStackRouterVite: 'root',\n};\n\n/** Whether a Vite config registers a TanStack Router / Start plugin. */\nexport const hasTanStackRouterVitePlugin = (content: string): boolean =>\n Object.keys(TANSTACK_ROUTER_PLUGINS).some((pluginName) =>\n content.includes(`${pluginName}(`)\n );\n\n/**\n * Sets `routeFileIgnorePattern` on the TanStack Start / Router Vite plugin so\n * co-located `.content.*` files are not picked up as route files. An existing\n * string pattern is combined with the content one.\n */\nexport const setTanStackRouteFileIgnorePattern = (\n content: string\n): ToolConfigPatchResult => {\n let ast: any;\n try {\n ast = recast.parse(content, { parser: typescriptParser });\n } catch {\n return { status: 'unsupported' };\n }\n\n // Mutated inside the visitor: an object keeps TS from narrowing it away.\n const outcome: { status: ToolConfigPatchResult['status'] } = {\n status: 'unsupported',\n };\n\n recast.visit(ast, {\n visitCallExpression(path) {\n const { callee, arguments: callArguments } = path.node as any;\n const location =\n callee.type === 'Identifier'\n ? TANSTACK_ROUTER_PLUGINS[callee.name]\n : undefined;\n\n if (!location) return this.traverse(path);\n\n if (callArguments.length === 0) {\n callArguments.push(b.objectExpression([]));\n }\n\n let optionsObject = callArguments[0];\n if (optionsObject.type !== 'ObjectExpression') return false;\n\n if (location === 'router') {\n let routerProperty = optionsObject.properties.find(\n (property: any) =>\n (property.key?.name ?? property.key?.value) === 'router'\n );\n\n if (!routerProperty) {\n routerProperty = b.property(\n 'init',\n b.identifier('router'),\n b.objectExpression([])\n );\n optionsObject.properties.push(routerProperty);\n }\n\n if (routerProperty.value?.type !== 'ObjectExpression') return false;\n optionsObject = routerProperty.value;\n }\n\n const ignoreProperty = optionsObject.properties.find(\n (property: any) =>\n (property.key?.name ?? property.key?.value) ===\n 'routeFileIgnorePattern'\n );\n\n if (!ignoreProperty) {\n optionsObject.properties.push(\n b.property(\n 'init',\n b.identifier('routeFileIgnorePattern'),\n b.stringLiteral(CONTENT_DECLARATION_ROUTE_IGNORE_PATTERN)\n )\n );\n outcome.status = 'updated';\n } else if (\n ignoreProperty.value?.type === 'StringLiteral' &&\n ignoreProperty.value.value.includes('.content')\n ) {\n outcome.status = 'already';\n } else if (ignoreProperty.value?.type === 'StringLiteral') {\n ignoreProperty.value = b.stringLiteral(\n `(?:${ignoreProperty.value.value})|(?:${CONTENT_DECLARATION_ROUTE_IGNORE_PATTERN})`\n );\n outcome.status = 'updated';\n }\n\n return false;\n },\n });\n\n if (outcome.status === 'updated') {\n return { status: 'updated', content: printWithSourceQuotes(ast, content) };\n }\n\n return { status: outcome.status };\n};\n"],"mappings":";;;;;;;AAMA,MAAM,EAAE,UAAU,GAAG,YAAY,MAAM,OAAO;;AAG9C,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,6BAA6B,CACxC,oBACA,iBACF;;AAYA,MAAM,sBAAsB;;;;;AAM5B,MAAM,yBAAyB,KAAU,WAA2B;CAClE,MAAM,oBAAoB,OAAO,MAAM,IAAI,KAAK,CAAC,EAAC,CAAE;CACpD,MAAM,oBAAoB,OAAO,MAAM,IAAI,KAAK,CAAC,EAAC,CAAE;CAEpD,OAAO,OAAO,MAAM,KAAK,EACvB,OAAO,mBAAmB,mBAAmB,WAAW,SAC1D,CAAC,CAAC,CAAC;AACL;;AAGA,MAAM,kBAAkB,SAAiB,cACvC,cAAc,SACd,cAAc,SACb,QAAQ,SAAS,gBAAgB,KAAK,CAAC,gBAAgB,KAAK,OAAO;;AAGtE,MAAM,oBAAoB,eAAyB;CACjD,IAAI,UAAU;CAEd,OACE,YACC,QAAQ,SAAS,2BAChB,QAAQ,SAAS,oBACjB,QAAQ,SAAS,4BAEnB,UAAU,QAAQ;CAGpB,OAAO;AACT;;AAGA,MAAM,2BAA2B,KAAU,SAAsB;CAC/D,KAAK,MAAM,aAAa,IAAI,QAAQ,MAAM;EACxC,MAAM,cACJ,UAAU,SAAS,2BACf,UAAU,cACV;EAEN,IAAI,aAAa,SAAS,uBAAuB;EAEjD,KAAK,MAAM,cAAc,YAAY,cACnC,IAAI,WAAW,IAAI,SAAS,gBAAgB,WAAW,GAAG,SAAS,MACjE,OAAO,WAAW;CAGxB;AAGF;;;;;;AAOA,MAAM,gCAAgC,QAAkB;C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,iBAAiB,CAAC,CAAC,CACvB;IACA,cAAc,WAAW,KAAK,cAAc;GAC9C;GAEA,IAAI,eAAe,OAAO,SAAS,oBAAoB,OAAO;GAC9D,gBAAgB,eAAe;EACjC;EAEA,MAAM,iBAAiB,cAAc,WAAW,MAC7C,cACE,SAAS,KAAK,QAAQ,SAAS,KAAK,WACrC,wBACJ;EAEA,IAAI,CAAC,gBAAgB;GACnB,cAAc,WAAW,KACvB,EAAE,SACA,QACA,EAAE,WAAW,wBAAwB,GACrC,EAAE,cAAc,wCAAwC,CAC1D,CACF;GACA,QAAQ,SAAS;EACnB,OAAO,IACL,eAAe,OAAO,SAAS,mBAC/B,eAAe,MAAM,MAAM,SAAS,UAAU,GAE9C,QAAQ,SAAS;OACZ,IAAI,eAAe,OAAO,SAAS,iBAAiB;GACzD,eAAe,QAAQ,EAAE,cACvB,MAAM,eAAe,MAAM,MAAM,OAAO,yCAAyC,EACnF;GACA,QAAQ,SAAS;EACnB;EAEA,OAAO;CACT,EACF,CAAC;CAED,IAAI,QAAQ,WAAW,WACrB,OAAO;EAAE,QAAQ;EAAW,SAAS,sBAAsB,KAAK,OAAO;CAAE;CAG3E,OAAO,EAAE,QAAQ,QAAQ,OAAO;AAClC"}
@@ -1,7 +1,7 @@
1
1
  import { readAsset } from "../_virtual/_utils_asset.mjs";
2
2
  import { colorizePath, logger, v } from "@intlayer/config/logger";
3
- import { join, relative } from "node:path";
4
3
  import { writeFile } from "node:fs/promises";
4
+ import { join, relative } from "node:path";
5
5
  import { searchConfigurationFile } from "@intlayer/config/node";
6
6
 
7
7
  // src/initConfig/index.ts
@@ -1,5 +1,5 @@
1
- import { promises } from "node:fs";
2
1
  import path from "node:path";
2
+ import { promises } from "node:fs";
3
3
 
4
4
  // src/installLSP.ts
5
5
  const VSCODE_DIR = ".vscode";
@@ -1,11 +1,18 @@
1
1
  import { PLATFORMS_METADATA } from "../installSkills/index.mjs";
2
- import { promises } from "node:fs";
3
2
  import path from "node:path";
3
+ import { promises } from "node:fs";
4
4
 
5
5
  // src/installMCP/installMCP.ts
6
6
  /** Transports accepted by `intlayer init mcp --transport`. */
7
7
  const MCP_TRANSPORTS = ["stdio", "sse"];
8
8
  const MCP_CONFIG_FILENAME = "mcp.json";
9
+ /** Package run by the stdio MCP server entry. */
10
+ const MCP_PACKAGE_NAME = "@intlayer/mcp";
11
+ /**
12
+ * `npx` spec of the MCP server. The dist-tag makes `npx` resolve the published
13
+ * version on start, where a bare name keeps serving its cached copy.
14
+ */
15
+ const getMCPPackageSpecifier = (distTag = "latest") => `${MCP_PACKAGE_NAME}@${distTag}`;
9
16
  /** Project-scoped MCP configuration file read by Claude Code. */
10
17
  const CLAUDE_CODE_MCP_CONFIG_FILENAME = ".mcp.json";
11
18
  /** Platforms whose MCP entries declare their transport as `type`. */
@@ -21,7 +28,7 @@ const getMCPServerConfig = (platform, transport) => {
21
28
  const isTypedTransport = TYPED_TRANSPORT_PLATFORMS.includes(platform);
22
29
  if (transport === "stdio") return {
23
30
  command: "npx",
24
- args: ["-y", "@intlayer/mcp"],
31
+ args: ["-y", getMCPPackageSpecifier()],
25
32
  ...isTypedTransport ? { type: "stdio" } : {}
26
33
  };
27
34
  return {
@@ -51,6 +58,40 @@ const installMCP = async (projectRoot, platform, transport) => {
51
58
  await promises.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
52
59
  return `MCP server configuration updated in ${configPath}`;
53
60
  };
61
+ /** Matches `@intlayer/mcp`, optionally followed by a version or dist-tag. */
62
+ const MCP_PACKAGE_ARGUMENT_PATTERN = /^@intlayer\/mcp(@.+)?$/;
63
+ /**
64
+ * Points the stdio Intlayer MCP entries of every platform config of the
65
+ * project at the given dist-tag (`npx -y @intlayer/mcp@latest`), so agents
66
+ * start the upgraded server. Returns the config files that were rewritten.
67
+ */
68
+ const upgradeMCPConfigs = async (projectRoot, distTag = "latest") => {
69
+ const packageSpecifier = getMCPPackageSpecifier(distTag);
70
+ const configPaths = [...new Set(Object.keys(PLATFORMS_METADATA).map((platform) => getMCPConfigPath(projectRoot, platform)))];
71
+ const updatedConfigPaths = [];
72
+ for (const configPath of configPaths) {
73
+ let config;
74
+ try {
75
+ config = JSON.parse(await promises.readFile(configPath, "utf-8"));
76
+ } catch {
77
+ continue;
78
+ }
79
+ let isUpdated = false;
80
+ for (const serversKey of ["servers", "mcpServers"]) {
81
+ const servers = config[serversKey];
82
+ for (const server of Object.values(servers ?? {})) server.args = server.args?.map((argument) => {
83
+ if (!MCP_PACKAGE_ARGUMENT_PATTERN.test(argument) || argument === packageSpecifier) return argument;
84
+ isUpdated = true;
85
+ return packageSpecifier;
86
+ });
87
+ }
88
+ if (isUpdated) {
89
+ await promises.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
90
+ updatedConfigPaths.push(configPath);
91
+ }
92
+ }
93
+ return updatedConfigPaths;
94
+ };
54
95
 
55
- export { MCP_TRANSPORTS, installMCP };
96
+ export { MCP_TRANSPORTS, installMCP, upgradeMCPConfigs };
56
97
  //# sourceMappingURL=installMCP.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"installMCP.mjs","names":["fs"],"sources":["../../../src/installMCP/installMCP.ts"],"sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport { PLATFORMS_METADATA, type Platform } from '../installSkills';\n\nexport type MCPTransport = 'stdio' | 'sse';\n\n/** Transports accepted by `intlayer init mcp --transport`. */\nexport const MCP_TRANSPORTS: MCPTransport[] = ['stdio', 'sse'];\n\nconst MCP_CONFIG_FILENAME = 'mcp.json';\n\n/** Project-scoped MCP configuration file read by Claude Code. */\nconst CLAUDE_CODE_MCP_CONFIG_FILENAME = '.mcp.json';\n\n/** One MCP server entry, as written under the platform's servers key. */\ntype MCPServerConfig = {\n command?: string;\n args?: string[];\n url?: string;\n type?: MCPTransport;\n transport?: MCPTransport;\n};\n\n/** Parsed MCP configuration file, keeping any unrelated keys untouched. */\ntype MCPConfigFile = Record<string, unknown>;\n\n/** Platforms whose MCP entries declare their transport as `type`. */\nconst TYPED_TRANSPORT_PLATFORMS: Platform[] = ['VSCode', 'Claude'];\n\n/** Resolves the MCP configuration file written for a platform. */\nconst getMCPConfigPath = (projectRoot: string, platform: Platform): string => {\n if (platform === 'Claude') {\n return path.join(projectRoot, CLAUDE_CODE_MCP_CONFIG_FILENAME);\n }\n\n // e.g. `.cursor/skills` → `.cursor/mcp.json`\n const relativeDir = path.dirname(PLATFORMS_METADATA[platform]?.dir ?? '.');\n\n return path.join(projectRoot, relativeDir, MCP_CONFIG_FILENAME);\n};\n\n/** Builds the Intlayer MCP server entry for a platform and transport. */\nconst getMCPServerConfig = (\n platform: Platform,\n transport: MCPTransport\n): MCPServerConfig => {\n const isTypedTransport = TYPED_TRANSPORT_PLATFORMS.includes(platform);\n\n if (transport === 'stdio') {\n return {\n command: 'npx',\n args: ['-y', '@intlayer/mcp'],\n ...(isTypedTransport ? { type: 'stdio' } : {}),\n };\n }\n\n return {\n url: 'https://mcp.intlayer.org',\n ...(isTypedTransport ? { type: 'sse' } : { transport: 'sse' }),\n };\n};\n\n/**\n * Installs the Intlayer MCP server configuration for a specific platform.\n * Every platform is configured at the project level (Claude Code included,\n * through `.mcp.json`), so nothing outside the project is modified.\n */\nexport const installMCP = async (\n projectRoot: string,\n platform: Platform,\n transport: MCPTransport\n): Promise<string> => {\n const configPath = getMCPConfigPath(projectRoot, platform);\n const serversKey = platform === 'VSCode' ? 'servers' : 'mcpServers';\n\n // Ensure the configuration directory exists\n await fs.mkdir(path.dirname(configPath), { recursive: true });\n\n let config: MCPConfigFile = {};\n try {\n const content = await fs.readFile(configPath, 'utf-8');\n config = JSON.parse(content) as MCPConfigFile;\n } catch {\n // File doesn't exist or is invalid JSON, start fresh\n }\n\n const servers = (config[serversKey] ?? {}) as Record<string, MCPServerConfig>;\n\n config[serversKey] = {\n ...servers,\n intlayer: getMCPServerConfig(platform, transport),\n };\n\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');\n\n return `MCP server configuration updated in ${configP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names":["fs"],"sources":["../../../src/installMCP/installMCP.ts"],"sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport { PLATFORMS_METADATA, type Platform } from '../installSkills';\n\nexport type MCPTransport = 'stdio' | 'sse';\n\n/** Transports accepted by `intlayer init mcp --transport`. */\nexport const MCP_TRANSPORTS: MCPTransport[] = ['stdio', 'sse'];\n\nconst MCP_CONFIG_FILENAME = 'mcp.json';\n\n/** Package run by the stdio MCP server entry. */\nconst MCP_PACKAGE_NAME = '@intlayer/mcp';\n\n/**\n * `npx` spec of the MCP server. The dist-tag makes `npx` resolve the published\n * version on start, where a bare name keeps serving its cached copy.\n */\nconst getMCPPackageSpecifier = (distTag: string = 'latest'): string =>\n `${MCP_PACKAGE_NAME}@${distTag}`;\n\n/** Project-scoped MCP configuration file read by Claude Code. */\nconst CLAUDE_CODE_MCP_CONFIG_FILENAME = '.mcp.json';\n\n/** One MCP server entry, as written under the platform's servers key. */\ntype MCPServerConfig = {\n command?: string;\n args?: string[];\n url?: string;\n type?: MCPTransport;\n transport?: MCPTransport;\n};\n\n/** Parsed MCP configuration file, keeping any unrelated keys untouched. */\ntype MCPConfigFile = Record<string, unknown>;\n\n/** Platforms whose MCP entries declare their transport as `type`. */\nconst TYPED_TRANSPORT_PLATFORMS: Platform[] = ['VSCode', 'Claude'];\n\n/** Resolves the MCP configuration file written for a platform. */\nconst getMCPConfigPath = (projectRoot: string, platform: Platform): string => {\n if (platform === 'Claude') {\n return path.join(projectRoot, CLAUDE_CODE_MCP_CONFIG_FILENAME);\n }\n\n // e.g. `.cursor/skills` → `.cursor/mcp.json`\n const relativeDir = path.dirname(PLATFORMS_METADATA[platform]?.dir ?? '.');\n\n return path.join(projectRoot, relativeDir, MCP_CONFIG_FILENAME);\n};\n\n/** Builds the Intlayer MCP server entry for a platform and transport. */\nconst getMCPServerConfig = (\n platform: Platform,\n transport: MCPTransport\n): MCPServerConfig => {\n const isTypedTransport = TYPED_TRANSPORT_PLATFORMS.includes(platform);\n\n if (transport === 'stdio') {\n return {\n command: 'npx',\n args: ['-y', getMCPPackageSpecifier()],\n ...(isTypedTransport ? { type: 'stdio' } : {}),\n };\n }\n\n return {\n url: 'https://mcp.intlayer.org',\n ...(isTypedTransport ? { type: 'sse' } : { transport: 'sse' }),\n };\n};\n\n/**\n * Installs the Intlayer MCP server configuration for a specific platform.\n * Every platform is configured at the project level (Claude Code included,\n * through `.mcp.json`), so nothing outside the project is modified.\n */\nexport const installMCP = async (\n projectRoot: string,\n platform: Platform,\n transport: MCPTransport\n): Promise<string> => {\n const configPath = getMCPConfigPath(projectRoot, platform);\n const serversKey = platform === 'VSCode' ? 'servers' : 'mcpServers';\n\n // Ensure the configuration directory exists\n await fs.mkdir(path.dirname(configPath), { recursive: true });\n\n let config: MCPConfigFile = {};\n try {\n const content = await fs.readFile(configPath, 'utf-8');\n config = JSON.parse(content) as MCPConfigFile;\n } catch {\n // File doesn't exist or is invalid JSON, start fresh\n }\n\n const servers = (config[serversKey] ?? {}) as Record<string, MCPServerConfig>;\n\n config[serversKey] = {\n ...servers,\n intlayer: getMCPServerConfig(platform, transport),\n };\n\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');\n\n return `MCP server configuration updated in ${configPath}`;\n};\n\n/** Matches `@intlayer/mcp`, optionally followed by a version or dist-tag. */\nconst MCP_PACKAGE_ARGUMENT_PATTERN = /^@intlayer\\/mcp(@.+)?$/;\n\n/**\n * Points the stdio Intlayer MCP entries of every platform config of the\n * project at the given dist-tag (`npx -y @intlayer/mcp@latest`), so agents\n * start the upgraded server. Returns the config files that were rewritten.\n */\nexport const upgradeMCPConfigs = async (\n projectRoot: string,\n distTag: string = 'latest'\n): Promise<string[]> => {\n const packageSpecifier = getMCPPackageSpecifier(distTag);\n const configPaths = [\n ...new Set(\n (Object.keys(PLATFORMS_METADATA) as Platform[]).map((platform) =>\n getMCPConfigPath(projectRoot, platform)\n )\n ),\n ];\n const updatedConfigPaths: string[] = [];\n\n for (const configPath of configPaths) {\n let config: MCPConfigFile;\n\n try {\n config = JSON.parse(await fs.readFile(configPath, 'utf-8'));\n } catch {\n continue;\n }\n\n let isUpdated = false;\n\n for (const serversKey of ['servers', 'mcpServers']) {\n const servers = config[serversKey] as\n | Record<string, MCPServerConfig>\n | undefined;\n\n for (const server of Object.values(servers ?? {})) {\n server.args = server.args?.map((argument) => {\n if (\n !MCP_PACKAGE_ARGUMENT_PATTERN.test(argument) ||\n argument === packageSpecifier\n ) {\n return argument;\n }\n\n isUpdated = true;\n return packageSpecifier;\n });\n }\n }\n\n if (isUpdated) {\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');\n updatedConfigPaths.push(configPath);\n }\n }\n\n return updatedConfigPaths;\n};\n"],"mappings":";;;;;;AAOA,MAAa,iBAAiC,CAAC,SAAS,KAAK;AAE7D,MAAM,sBAAsB;;AAG5B,MAAM,mBAAmB;;;;;AAMzB,MAAM,0BAA0B,UAAkB,aAChD,GAAG,iBAAiB,GAAG;;AAGzB,MAAM,kCAAkC;;AAexC,MAAM,4BAAwC,CAAC,UAAU,QAAQ;;AAGjE,MAAM,oBAAoB,aAAqB,aAA+B;CAC5E,IAAI,aAAa,UACf,OAAO,KAAK,KAAK,aAAa,+BAA+B;CAI/D,MAAM,cAAc,KAAK,QAAQ,mBAAmB,SAAS,EAAE,OAAO,GAAG;CAEzE,OAAO,KAAK,KAAK,aAAa,aAAa,mBAAmB;AAChE;;AAGA,MAAM,sBACJ,UACA,cACoB;CACpB,MAAM,mBAAmB,0BAA0B,SAAS,QAAQ;CAEpE,IAAI,cAAc,SAChB,OAAO;EACL,SAAS;EACT,MAAM,CAAC,MAAM,uBAAuB,CAAC;EACrC,GAAI,mBAAmB,EAAE,MAAM,QAAQ,IAAI,CAAC;CAC9C;CAGF,OAAO;EACL,KAAK;EACL,GAAI,mBAAmB,EAAE,MAAM,MAAM,IAAI,EAAE,WAAW,MAAM;CAC9D;AACF;;;;;;AAOA,MAAa,aAAa,OACxB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AAMA,SAAG,UAAU,YAAY,KAAK,UAAU,QAAQ,MAAM,CAAC,GAAG,OAAO;GACvE,mBAAmB,KAAK,UAAU;EACpC;CACF;CAEA,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  import { readAsset } from "../_virtual/_utils_asset.mjs";
2
2
  import { v } from "@intlayer/config/logger";
3
- import { existsSync, promises } from "node:fs";
4
3
  import path from "node:path";
4
+ import { existsSync, promises } from "node:fs";
5
5
  import { getMarkdownMetadata } from "@intlayer/core/markdown";
6
6
 
7
7
  // src/installSkills/index.ts
@@ -1,6 +1,6 @@
1
1
  import { getAppLogger } from "@intlayer/config/logger";
2
- import { readFileSync } from "node:fs";
3
2
  import { join } from "node:path";
3
+ import { readFileSync } from "node:fs";
4
4
  import { log } from "@intlayer/config/built";
5
5
  import { simpleGit } from "simple-git";
6
6
 
@@ -1,5 +1,5 @@
1
- import { join } from "node:path";
2
1
  import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
3
  import { getProjectRequire } from "@intlayer/config/utils";
4
4
  import { bundleFile } from "@intlayer/config/file";
5
5
  import { builtinModules, createRequire } from "node:module";
@@ -4,8 +4,8 @@ import { getIntlayerBundle } from "./getIntlayerBundle.mjs";
4
4
  import { loadMarkdownContentDeclaration } from "./loadMarkdownContentDeclaration.mjs";
5
5
  import { loadYamlContentDeclaration } from "./loadYamlContentDeclaration.mjs";
6
6
  import { logTypeScriptErrors } from "./logTypeScriptErrors.mjs";
7
- import { dirname, extname, join, relative } from "node:path";
8
7
  import { readFile, writeFile } from "node:fs/promises";
8
+ import { dirname, extname, join, relative } from "node:path";
9
9
  import { cacheDisk, getPackageJsonPath, getProjectRequire, parallelize } from "@intlayer/config/utils";
10
10
  import { loadExternalFile } from "@intlayer/config/file";
11
11
 
@@ -1,6 +1,6 @@
1
1
  import { loadContentDeclarations } from "./loadContentDeclaration.mjs";
2
- import { relative, resolve } from "node:path";
3
2
  import { mkdir } from "node:fs/promises";
3
+ import { relative, resolve } from "node:path";
4
4
 
5
5
  // src/loadDictionaries/loadLocalDictionaries.ts
6
6
  const loadLocalDictionaries = async (contentDeclarationsPaths, configuration) => {
@@ -1,6 +1,6 @@
1
1
  import { colorize, getPrefix, spinnerFrames, v, x } from "@intlayer/config/logger";
2
- import { extractErrorMessage } from "@intlayer/config/utils";
3
2
  import * as ANSIColors from "@intlayer/config/colors";
3
+ import { extractErrorMessage } from "@intlayer/config/utils";
4
4
  import { log } from "@intlayer/config/built";
5
5
 
6
6
  // src/loadDictionaries/log.ts
@@ -9,11 +9,11 @@ import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
9
9
  import { runOnce } from "./utils/runOnce.mjs";
10
10
  import { isCachedConfigurationUpToDate, writeConfiguration } from "./writeConfiguration/index.mjs";
11
11
  import { colorize, getAppLogger } from "@intlayer/config/logger";
12
- import { join } from "node:path";
13
12
  import { stat } from "node:fs/promises";
14
- import { cacheDisk } from "@intlayer/config/utils";
13
+ import { join } from "node:path";
15
14
  import * as ANSIColors from "@intlayer/config/colors";
16
15
  import packageJson from "@intlayer/config/package.json" with { type: "json" };
16
+ import { cacheDisk } from "@intlayer/config/utils";
17
17
 
18
18
  // src/prepareIntlayer.ts
19
19
  const DEFAULT_PREPARE_INTLAYER_OPTIONS = {
@@ -1,19 +1,19 @@
1
1
  import { analyzeBundleContent } from "./analyzeBundleContent.mjs";
2
2
  import { mutateScore, scoreRecord, toScorePercent } from "./calculateScore.mjs";
3
- import { findMatchingLocale, getLanguageCode, isRightToLeftLocale, isSameLanguage, isSameLocale, isValidLocaleCode, isValidOpenGraphLocale, looksLikeLocaleCode, normalizeLocaleCode, toOpenGraphLocale } from "./detection/localeCode.mjs";
4
- import { getFirstPathSegment, getSiteDomain, isAbsoluteUrl, normalizeHostname, normalizeUrl, parseUrl, toAbsoluteScanUrl } from "./detection/url.mjs";
5
- import { detectRoutingStrategy, getUrlLocale } from "./detection/detectRoutingStrategy.mjs";
6
- import { classifyInternalLinks } from "./detection/classifyInternalLinks.mjs";
7
3
  import { checkBundleContent, checkCanonical, checkHreflang, checkHreflangReciprocity, checkHtmlDir, checkHtmlLang, checkInternalLinks, checkLocaleConsistency, checkOgLocale, checkRobots, checkSitemap, checkXDefault, formatBundleAnalysis, formatSize } from "./checks.mjs";
4
+ import { technologySignatures } from "./detection/technologySignatures.mjs";
5
+ import { getFirstPathSegment, getSiteDomain, isAbsoluteUrl, normalizeHostname, normalizeUrl, parseUrl, toAbsoluteScanUrl } from "./detection/url.mjs";
6
+ import { detectTechnologies, getTechnologyGlobalNames } from "./detection/detectTechnologies.mjs";
8
7
  import { fetchText } from "./fetchText.mjs";
9
8
  import { byteLength, extractAnchors, extractCanonicalHref, extractHreflangs, extractHtmlDir, extractHtmlLang, extractMetaDescription, extractOgImage, extractOgLocale, extractOgLocaleAlternates, extractResourceUrls, extractScriptUrls, extractTitle, extractVisibleTextStrings, hasCanonical } from "./parseHtml.mjs";
9
+ import { findMatchingLocale, getLanguageCode, isRightToLeftLocale, isSameLanguage, isSameLocale, isValidLocaleCode, isValidOpenGraphLocale, looksLikeLocaleCode, normalizeLocaleCode, toOpenGraphLocale } from "./detection/localeCode.mjs";
10
+ import { detectRoutingStrategy, getUrlLocale } from "./detection/detectRoutingStrategy.mjs";
11
+ import { classifyInternalLinks } from "./detection/classifyInternalLinks.mjs";
10
12
  import { isPathAllowedByRobots, parseRobots } from "./robots.mjs";
11
- import { technologySignatures } from "./detection/technologySignatures.mjs";
12
- import { detectTechnologies, getTechnologyGlobalNames } from "./detection/detectTechnologies.mjs";
13
13
  import { runScanChecks } from "./runScanChecks.mjs";
14
14
  import { scanWebsite } from "./scanWebsite.mjs";
15
+ import { collectSitemapEntries, discoverSitemapUrls, getDefaultSitemapUrls, parseSitemap } from "./sitemap.mjs";
15
16
  import { getCheckDetailLines, splitCheckDetails } from "./detection/checkDetails.mjs";
16
17
  import { getLocalizedPages, isBaseLocalePage } from "./detection/localizedPages.mjs";
17
- import { collectSitemapEntries, discoverSitemapUrls, getDefaultSitemapUrls, parseSitemap } from "./sitemap.mjs";
18
18
 
19
19
  export { analyzeBundleContent, byteLength, checkBundleContent, checkCanonical, checkHreflang, checkHreflangReciprocity, checkHtmlDir, checkHtmlLang, checkInternalLinks, checkLocaleConsistency, checkOgLocale, checkRobots, checkSitemap, checkXDefault, classifyInternalLinks, collectSitemapEntries, detectRoutingStrategy, detectTechnologies, discoverSitemapUrls, extractAnchors, extractCanonicalHref, extractHreflangs, extractHtmlDir, extractHtmlLang, extractMetaDescription, extractOgImage, extractOgLocale, extractOgLocaleAlternates, extractResourceUrls, extractScriptUrls, extractTitle, extractVisibleTextStrings, fetchText, findMatchingLocale, formatBundleAnalysis, formatSize, getCheckDetailLines, getDefaultSitemapUrls, getFirstPathSegment, getLanguageCode, getLocalizedPages, getSiteDomain, getTechnologyGlobalNames, getUrlLocale, hasCanonical, isAbsoluteUrl, isBaseLocalePage, isPathAllowedByRobots, isRightToLeftLocale, isSameLanguage, isSameLocale, isValidLocaleCode, isValidOpenGraphLocale, looksLikeLocaleCode, mutateScore, normalizeHostname, normalizeLocaleCode, normalizeUrl, parseRobots, parseSitemap, parseUrl, runScanChecks, scanWebsite, scoreRecord, splitCheckDetails, technologySignatures, toAbsoluteScanUrl, toOpenGraphLocale, toScorePercent };
@@ -1,8 +1,8 @@
1
1
  import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
2
2
  import { extractKeyAndLocaleFromPath } from "./extractKeyAndLocaleFromPath.mjs";
3
3
  import { buildFilePathPatternContext } from "./filePathPatternHelpers.mjs";
4
- import { dirname, isAbsolute, resolve } from "node:path";
5
4
  import { mkdir, readFile } from "node:fs/promises";
5
+ import { dirname, isAbsolute, resolve } from "node:path";
6
6
  import { parseFilePathPattern } from "@intlayer/config/utils";
7
7
  import fg from "fast-glob";
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { isDirectoryExcluded } from "./isDirectoryExcluded.mjs";
2
- import { TRAVERSE_PATTERN } from "@intlayer/config/defaultValues";
3
2
  import { isAbsolute, relative, resolve } from "node:path";
4
3
  import { normalizePath } from "@intlayer/config/utils";
4
+ import { TRAVERSE_PATTERN } from "@intlayer/config/defaultValues";
5
5
  import fg from "fast-glob";
6
6
 
7
7
  // src/utils/buildComponentFilesList.ts
@@ -1,8 +1,8 @@
1
1
  import { colorize, getAppLogger } from "@intlayer/config/logger";
2
- import { rmSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
2
  import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
5
4
  import * as ANSIColors from "@intlayer/config/colors";
5
+ import { rmSync } from "node:fs";
6
6
 
7
7
  // src/utils/contentWatcherLock.ts
8
8
  /**
@@ -1,5 +1,5 @@
1
- import { existsSync, readFileSync, readdirSync } from "node:fs";
2
1
  import { basename, extname, join } from "node:path";
2
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
3
3
 
4
4
  // src/utils/readDictionariesFromDisk.ts
5
5
  /**
@@ -1,6 +1,6 @@
1
- import { rmSync } from "node:fs";
2
- import { dirname } from "node:path";
3
1
  import { mkdir, readFile, rmdir, stat, unlink, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { rmSync } from "node:fs";
4
4
  import packageJson from "@intlayer/core/package.json" with { type: "json" };
5
5
 
6
6
  // src/utils/runOnce.ts
@@ -1,6 +1,6 @@
1
- import { rmSync } from "node:fs";
2
- import { dirname } from "node:path";
3
1
  import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { rmSync } from "node:fs";
4
4
 
5
5
  // src/utils/withFileLock.ts
6
6
  const DEFAULT_OPTIONS = {
@@ -9,13 +9,13 @@ import { isDirectoryExcluded } from "./utils/isDirectoryExcluded.mjs";
9
9
  import { parseContentDeclarationFileName } from "./utils/parseContentDeclarationFileName.mjs";
10
10
  import { createBatchDebounce } from "./utils/createBatchDebounce.mjs";
11
11
  import { colorize, getAppLogger } from "@intlayer/config/logger";
12
- import { existsSync, watch as watch$1 } from "node:fs";
13
- import { basename, dirname, extname, resolve } from "node:path";
14
12
  import { readFile } from "node:fs/promises";
15
- import { clearAllCache, clearDiskCacheMemory, clearModuleCache, normalizePath } from "@intlayer/config/utils";
13
+ import { basename, dirname, extname, resolve } from "node:path";
16
14
  import * as ANSIColor from "@intlayer/config/colors";
17
- import { getConfiguration, getConfigurationAndFilePath } from "@intlayer/config/node";
15
+ import { clearAllCache, clearDiskCacheMemory, clearModuleCache, normalizePath } from "@intlayer/config/utils";
16
+ import { existsSync, watch as watch$1 } from "node:fs";
18
17
  import { transpileTSToCJS } from "@intlayer/config/file";
18
+ import { getConfiguration, getConfigurationAndFilePath } from "@intlayer/config/node";
19
19
 
20
20
  // src/watcher.ts
21
21
  const pendingUnlinks = /* @__PURE__ */ new Map();
@@ -1,8 +1,8 @@
1
1
  import { writeFileIfChanged } from "../writeFileIfChanged.mjs";
2
2
  import { generateConfigurationContent } from "./generateConfigurationContent.mjs";
3
- import { mkdirSync, watch } from "node:fs";
4
- import { join } from "node:path";
5
3
  import { mkdir, readFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { mkdirSync, watch } from "node:fs";
6
6
 
7
7
  // src/writeConfiguration/index.ts
8
8
  const isCachedConfigurationUpToDate = async (configuration) => {
@@ -1,6 +1,6 @@
1
1
  import { colorizePath, x } from "@intlayer/config/logger";
2
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
2
  import { dirname, join } from "node:path";
3
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
4
  import { deepTransformNode } from "@intlayer/core/interpreter";
5
5
  import * as NodeTypes from "@intlayer/types/nodeType";
6
6
 
@@ -1,15 +1,14 @@
1
- import { detectFormatCommand } from "../detectFormatCommand.mjs";
1
+ import { runFormatCommand } from "../detectFormatCommand.mjs";
2
2
  import { readDictionariesFromDisk } from "../utils/readDictionariesFromDisk.mjs";
3
3
  import { formatContentDeclaration } from "./renderContentDeclaration.mjs";
4
4
  import { transformJSONFile } from "./transformJSONFile.mjs";
5
5
  import { writeJSFile } from "./writeJSFile.mjs";
6
6
  import { writeMarkdownFile } from "./writeMarkdownFile.mjs";
7
7
  import { writeYamlFile } from "./writeYamlFile.mjs";
8
+ import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
9
+ import { basename, dirname, extname, join, resolve } from "node:path";
8
10
  import { COMPILER_NO_METADATA } from "@intlayer/config/defaultValues";
9
11
  import { existsSync } from "node:fs";
10
- import { basename, dirname, extname, join, resolve } from "node:path";
11
- import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
12
- import { execSync } from "node:child_process";
13
12
  import { isDeepStrictEqual } from "node:util";
14
13
 
15
14
  // src/writeContentDeclaration/writeContentDeclaration.ts
@@ -91,15 +90,7 @@ const writeFileWithDirectories = async (absoluteFilePath, dictionary, configurat
91
90
  } catch {}
92
91
  throw error;
93
92
  }
94
- const formatCommand = detectFormatCommand(configuration);
95
- if (formatCommand) try {
96
- execSync(formatCommand.replace("{{file}}", absoluteFilePath), {
97
- stdio: "inherit",
98
- cwd: configuration.system.baseDir
99
- });
100
- } catch (error) {
101
- console.error(error);
102
- }
93
+ runFormatCommand(absoluteFilePath, configuration);
103
94
  return;
104
95
  }
105
96
  if (!(/* @__PURE__ */ new Set([
@@ -1 +1 @@
1
- {"version":3,"file":"writeContentDeclaration.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport { COMPILER_NO_METADATA } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { detectFormatCommand } from '../detectFormatCommand';\nimport { readDictionariesFromDisk } from '../utils/readDictionariesFromDisk';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { formatContentDeclaration } from './renderContentDeclaration';\nimport { transformJSONFile } from './transformJSONFile';\nimport { writeJSFile } from './writeJSFile';\nimport { writeMarkdownFile } from './writeMarkdownFile';\nimport { writeYamlFile } from './writeYamlFile';\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { system, compiler } = configuration;\n const { baseDir } = system;\n\n const noMetadata = compiler?.noMetadata ?? COMPILER_NO_METADATA;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = readDictionariesFromDisk<\n Record<string, Dictionary[]>\n >(configuration.system.unmergedDictionariesDir);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n { configuration, localeList }\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.system.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(configuration.system.baseDir, dictionary.filePath);\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n noMetadata?: boolean\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n\n if (extension === '.md' || extension === '.mdx') {\n await writeMarkdownFile(absoluteFilePath, dictionary, configuration);\n return;\n }\n\n if (extension === '.yaml' || extension === '.yml') {\n await writeYamlFile(absoluteFilePath, dictionary, configuration);\n return;\n }\n\n // Handle JSON, JSONC, and JSON5 via the AST transformer\n if (['.json', '.jsonc', '.json5'].includes(extension)) {\n let fileContent = '{}';\n\n if (existsSync(absoluteFilePath)) {\n try {\n fileContent = await readFile(absoluteFilePath, 'utf-8');\n } catch {\n // ignore read errors, start with empty object\n }\n }\n\n const transformedContent = transformJSONFile(\n fileContent,\n dictionary,\n noMetadata\n );\n\n // We use standard writeFile because transformedContent is already a string\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(absoluteFilePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${absoluteFilePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, transformedContent, 'utf-8');\n await rename(tempPath, absoluteFilePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', absoluteFilePath), {\n stdio: 'inherit',\n cwd: configuration.system.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n\n return;\n }\n\n const knownJsExtensions = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n ]);\n\n if (!knownJsExtensions.has(extension)) {\n // Unknown extension (e.g. .po managed by a plugin) — skip; the plugin\n // owns this file format and writeJSFile / prettier would corrupt it.\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration, noMetadata);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.system.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,MAAM,iBAAiB,EACrB,qBAAqB,wBACvB;AAEA,MAAa,0BAA0B,OACrC,YACA,eACA,YACwD;CACxD,MAAM,EAAE,QAAQ,aAAa;CAC7B,MAAM,EAAE,YAAY;CAEpB,MAAM,aAAa,UAAU,cAAc;CAC3C,MAAM,EAAE,qBAAqB,eAAe;EAC1C,GAAG;EACH,GAAG;CACL;CAEA,MAAM,4BAA4B,KAAK,SAAS,mBAAmB;CASnE,MAAM,qBAP6B,yBAEjC,cAAc,OAAO,uBAC+B,CAAC,CACrD,WAAW,IAGkC,EAAE,MAC9C,OAAO,GAAG,YAAY,WAAW,OACpC;CAEA,MAAM,8BAA8B,MAAM,yBACxC,YACA;EAAE;EAAe;CAAW,CAC9B;CAEA,IAAI,oBAAoB,UAAU;EAEhC,MAAM,gBAAgB,kBAAkB,oBAAoB,UAAU;EAEtE,MAAM,WAAW,QACf,cAAc,OAAO,SACrB,mBAAmB,QACrB;EAGA,IAAI,eACF,OAAO;GACL,QAAQ;GACR,MAAM;EACR;EAGF,MAAM,yBACJ,UACA,6BACA,eACA,UACF;EA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;EAC3B,IAAI;GACF,MAAM,UAAU,UAAU,oBAAoB,OAAO;GACrD,MAAM,OAAO,UAAU,gBAAgB;EACzC,SAAS,OAAO;GACd,IAAI;IACF,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;GACpC,QAAQ,CAER;GACA,MAAM;EACR;EAEA,MAAM,gBAAgB,oBAAoB,aAAa;EAEvD,IAAI,eACF,IAAI;GACF,SAAS,cAAc,QAAQ,YAAY,gBAAgB,GAAG;IAC5D,OAAO;IACP,KAAK,cAAc,OAAO;GAC5B,CAAC;EACH,SAAS,OAAO;GACd,QAAQ,MAAM,KAAK;EACrB;EAGF;CACF;CAWA,IAAI,kBAAC,IATyB,IAAI;EAChC;EACA;EACA;EACA;EACA;EACA;CACF,CAEqB,EAAC,CAAC,IAAI,SAAS,GAGlC;CAGF,MAAM,YAAY,kBAAkB,YAAY,eAAe,UAAU;CAIzE,IAAI;EACF,MAAM,eAAe,KACnB,cAAc,OAAO,UACrB,wBACF;EACA,MAAM,GAAG,cAAc,EAAE,WAAW,KAAK,CAAC;CAC5C,QAAQ,CAAC;AACX"}
1
+ {"version":3,"file":"writeContentDeclaration.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport { COMPILER_NO_METADATA } from '@intlayer/config/defaultValues';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { runFormatCommand } from '../detectFormatCommand';\nimport { readDictionariesFromDisk } from '../utils/readDictionariesFromDisk';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { formatContentDeclaration } from './renderContentDeclaration';\nimport { transformJSONFile } from './transformJSONFile';\nimport { writeJSFile } from './writeJSFile';\nimport { writeMarkdownFile } from './writeMarkdownFile';\nimport { writeYamlFile } from './writeYamlFile';\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { system, compiler } = configuration;\n const { baseDir } = system;\n\n const noMetadata = compiler?.noMetadata ?? COMPILER_NO_METADATA;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = readDictionariesFromDisk<\n Record<string, Dictionary[]>\n >(configuration.system.unmergedDictionariesDir);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n { configuration, localeList }\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.system.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(configuration.system.baseDir, dictionary.filePath);\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration,\n noMetadata\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n noMetadata?: boolean\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n\n if (extension === '.md' || extension === '.mdx') {\n await writeMarkdownFile(absoluteFilePath, dictionary, configuration);\n return;\n }\n\n if (extension === '.yaml' || extension === '.yml') {\n await writeYamlFile(absoluteFilePath, dictionary, configuration);\n return;\n }\n\n // Handle JSON, JSONC, and JSON5 via the AST transformer\n if (['.json', '.jsonc', '.json5'].includes(extension)) {\n let fileContent = '{}';\n\n if (existsSync(absoluteFilePath)) {\n try {\n fileContent = await readFile(absoluteFilePath, 'utf-8');\n } catch {\n // ignore read errors, start with empty object\n }\n }\n\n const transformedContent = transformJSONFile(\n fileContent,\n dictionary,\n noMetadata\n );\n\n // We use standard writeFile because transformedContent is already a string\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(absoluteFilePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${absoluteFilePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, transformedContent, 'utf-8');\n await rename(tempPath, absoluteFilePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n\n runFormatCommand(absoluteFilePath, configuration);\n\n return;\n }\n\n const knownJsExtensions = new Set([\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n ]);\n\n if (!knownJsExtensions.has(extension)) {\n // Unknown extension (e.g. .po managed by a plugin) — skip; the plugin\n // owns this file format and writeJSFile / prettier would corrupt it.\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration, noMetadata);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.system.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAM,iBAAiB,EACrB,qBAAqB,wBACvB;AAEA,MAAa,0BAA0B,OACrC,YACA,eACA,YACwD;CACxD,MAAM,EAAE,QAAQ,aAAa;CAC7B,MAAM,EAAE,YAAY;CAEpB,MAAM,aAAa,UAAU,cAAc;CAC3C,MAAM,EAAE,qBAAqB,eAAe;EAC1C,GAAG;EACH,GAAG;CACL;CAEA,MAAM,4BAA4B,KAAK,SAAS,mBAAmB;CASnE,MAAM,qBAP6B,yBAEjC,cAAc,OAAO,uBAC+B,CAAC,CACrD,WAAW,IAGkC,EAAE,MAC9C,OAAO,GAAG,YAAY,WAAW,OACpC;CAEA,MAAM,8BAA8B,MAAM,yBACxC,YACA;EAAE;EAAe;CAAW,CAC9B;CAEA,IAAI,oBAAoB,UAAU;EAEhC,MAAM,gBAAgB,kBAAkB,oBAAoB,UAAU;EAEtE,MAAM,WAAW,QACf,cAAc,OAAO,SACrB,mBAAmB,QACrB;EAGA,IAAI,eACF,OAAO;GACL,QAAQ;GACR,MAAM;EACR;EAGF,MAAM,yBACJ,UACA,6BACA,eACA,UACF;EAEA,OAAO;GAAE,QAAQ;GAAW,MAAM;EAAS;CAC7C;CAEA,IAAI,WAAW,UAAU;EACvB,MAAM,WAAW,QAAQ,cAAc,OAAO,SAAS,WAAW,QAAQ;EAE1E,MAAM,yBACJ,UACA,6BACA,eACA,UACF;EAEA,OAAO;GAAE,QAAQ;GAAW,MAAM;EAAS;CAC7C;CAGA,MAAM,yBAAyB,KAC7B,2BACA,GAA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B,IAAI;EAChC;EACA;EACA;EACA;EACA;EACA;CACF,CAEqB,EAAC,CAAC,IAAI,SAAS,GAGlC;CAGF,MAAM,YAAY,kBAAkB,YAAY,eAAe,UAAU;CAIzE,IAAI;EACF,MAAM,eAAe,KACnB,cAAc,OAAO,UACrB,wBACF;EACA,MAAM,GAAG,cAAc,EAAE,WAAW,KAAK,CAAC;CAC5C,QAAQ,CAAC;AACX"}
@@ -1,12 +1,11 @@
1
- import { detectFormatCommand } from "../detectFormatCommand.mjs";
1
+ import { runFormatCommand } from "../detectFormatCommand.mjs";
2
2
  import { getContentDeclarationFileTemplate } from "../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
3
3
  import { getFormatFromExtension } from "../utils/getFormatFromExtension.mjs";
4
4
  import { transformJSFile } from "./transformJSFile.mjs";
5
5
  import { getAppLogger, logger } from "@intlayer/config/logger";
6
- import { existsSync } from "node:fs";
7
- import { basename, extname, join } from "node:path";
8
6
  import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
9
- import { execSync } from "node:child_process";
7
+ import { basename, extname, join } from "node:path";
8
+ import { existsSync } from "node:fs";
10
9
 
11
10
  // src/writeContentDeclaration/writeJSFile.ts
12
11
  /**
@@ -76,15 +75,7 @@ const writeJSFile = async (filePath, dictionary, configuration, noMetadata) => {
76
75
  logger(`Failed to write updated file: ${filePath}`, { level: "error" });
77
76
  throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);
78
77
  }
79
- const formatCommand = detectFormatCommand(configuration);
80
- if (formatCommand) try {
81
- execSync(formatCommand.replace("{{file}}", filePath), {
82
- stdio: "inherit",
83
- cwd: configuration.system.baseDir
84
- });
85
- } catch (error) {
86
- console.error(error);
87
- }
78
+ runFormatCommand(filePath, configuration);
88
79
  };
89
80
 
90
81
  export { writeJSFile };
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { detectFormatCommand } from '../detectFormatCommand';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n noMetadata?: boolean\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: noMetadata ? undefined : mergedDictionary.id,\n locale: noMetadata ? undefined : mergedDictionary.locale,\n filled: noMetadata ? undefined : mergedDictionary.filled,\n fill: noMetadata ? undefined : mergedDictionary.fill,\n description: noMetadata ? undefined : mergedDictionary.description,\n title: noMetadata ? undefined : mergedDictionary.title,\n tags: noMetadata ? undefined : mergedDictionary.tags,\n version: noMetadata ? undefined : mergedDictionary.version,\n priority: noMetadata ? undefined : mergedDictionary.priority,\n importMode: noMetadata ? undefined : mergedDictionary.importMode,\n }).filter(([, value]) => value !== undefined)\n ),\n noMetadata\n );\n\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(filePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${filePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, template, 'utf-8');\n await rename(tempPath, filePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n }\n\n let fileContent = await readFile(filePath, 'utf-8');\n\n if (fileContent === '') {\n const format = getFormatFromExtension(extname(filePath) as Extension);\n\n fileContent = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n {},\n noMetadata\n );\n }\n\n const finalCode = await transformJSFile(\n fileContent,\n dictionary,\n dictionary.locale as any,\n noMetadata\n );\n\n // Write the modified code back to the file\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(filePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${filePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, finalCode, 'utf-8');\n await rename(tempPath, filePath);\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.system.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAa,cAAc,OACzB,UACA,YACA,eACA,eACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;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;EACtB,MAAM,SAAS,uBAAuB,QAAQ,QAAQ,CAAc;EAEpE,cAAc,MAAM,kCAClB,iBAAiB,KACjB,QACA,CAAC,GACD,UACF;CACF;CAEA,MAAM,YAAY,MAAM,gBACtB,aACA,YACA,WAAW,QACX,UACF;CAGA,MAAM,UAAU,cAAc,QAAQ;CACtC,IAAI,SACF,MAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;CAG1C,MAAM,eAAe,GAAG,SAAS,QAAQ,EAAE,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;CAChG,MAAM,WAAW,UACb,KAAK,SAAS,YAAY,IAC1B,GAAG,SAAS,GAAG;CACnB,IAAI;EACF,MAAM,UAAU,UAAU,WAAW,OAAO;EAC5C,MAAM,OAAO,UAAU,QAAQ;EAC/B,OAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;EACb,CAAC;CACH,SAAS,OAAO;EACd,IAAI;GACF,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;EACpC,QAAQ,CAER;EACA,MAAM,MAAM;EACZ,OAAO,iCAAiC,YAAY,EAClD,OAAO,QACT,CAAC;EACD,MAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,SAAS;CAC5E;CAEA,MAAM,gBAAgB,oBAAoB,aAAa;CAEvD,IAAI,eACF,IAAI;EACF,SAAS,cAAc,QAAQ,YAAY,QAAQ,GAAG;GACpD,OAAO;GACP,KAAK,cAAc,OAAO;EAC5B,CAAC;CACH,SAAS,OAAO;EACd,QAAQ,MAAM,KAAK;CACrB;AAEJ"}
1
+ {"version":3,"file":"writeJSFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { runFormatCommand } from '../detectFormatCommand';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n noMetadata?: boolean\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n id: noMetadata ? undefined : mergedDictionary.id,\n locale: noMetadata ? undefined : mergedDictionary.locale,\n filled: noMetadata ? undefined : mergedDictionary.filled,\n fill: noMetadata ? undefined : mergedDictionary.fill,\n description: noMetadata ? undefined : mergedDictionary.description,\n title: noMetadata ? undefined : mergedDictionary.title,\n tags: noMetadata ? undefined : mergedDictionary.tags,\n version: noMetadata ? undefined : mergedDictionary.version,\n priority: noMetadata ? undefined : mergedDictionary.priority,\n importMode: noMetadata ? undefined : mergedDictionary.importMode,\n }).filter(([, value]) => value !== undefined)\n ),\n noMetadata\n );\n\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(filePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${filePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, template, 'utf-8');\n await rename(tempPath, filePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n }\n\n let fileContent = await readFile(filePath, 'utf-8');\n\n if (fileContent === '') {\n const format = getFormatFromExtension(extname(filePath) as Extension);\n\n fileContent = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n {},\n noMetadata\n );\n }\n\n const finalCode = await transformJSFile(\n fileContent,\n dictionary,\n dictionary.locale as any,\n noMetadata\n );\n\n // Write the modified code back to the file\n const tempDir = configuration.system?.tempDir;\n if (tempDir) {\n await mkdir(tempDir, { recursive: true });\n }\n\n const tempFileName = `${basename(filePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${filePath}.${tempFileName}`;\n try {\n await writeFile(tempPath, finalCode, 'utf-8');\n await rename(tempPath, filePath);\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // Ignore\n }\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n runFormatCommand(filePath, configuration);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,eACA,eACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;CACL;CAEA,MAAM,YAAY,aAAa,aAAa;CAG5C,IAAI,CAAC,WAAW,QAAQ,GAAG;EACzB,MAAM,gBAAgB,QAAQ,QAAQ;EAEtC,MAAM,SAAS,uBAAuB,aAAa;EAEnD,UAAU,oCAAoC,EAC5C,WAAW,KACb,CAAC;EACD,MAAM,WAAW,MAAM,kCACrB,iBAAiB,KACjB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WAAW,KAAK,CAAC;CAG1C,MAAM,eAAe,GAAG,SAAS,QAAQ,EAAE,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;CAChG,MAAM,WAAW,UACb,KAAK,SAAS,YAAY,IAC1B,GAAG,SAAS,GAAG;CACnB,IAAI;EACF,MAAM,UAAU,UAAU,WAAW,OAAO;EAC5C,MAAM,OAAO,UAAU,QAAQ;EAC/B,OAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;EACb,CAAC;CACH,SAAS,OAAO;EACd,IAAI;GACF,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;EACpC,QAAQ,CAER;EACA,MAAM,MAAM;EACZ,OAAO,iCAAiC,YAAY,EAClD,OAAO,QACT,CAAC;EACD,MAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,SAAS;CAC5E;CAEA,iBAAiB,UAAU,aAAa;AAC1C"}
@@ -1,8 +1,7 @@
1
- import { detectFormatCommand } from "../detectFormatCommand.mjs";
1
+ import { runFormatCommand } from "../detectFormatCommand.mjs";
2
2
  import { renderMarkdownContentDeclaration } from "./renderContentDeclaration.mjs";
3
- import { basename, dirname, join } from "node:path";
4
3
  import { mkdir, rename, rm, writeFile } from "node:fs/promises";
5
- import { execSync } from "node:child_process";
4
+ import { basename, dirname, join } from "node:path";
6
5
 
7
6
  // src/writeContentDeclaration/writeMarkdownFile.ts
8
7
  const writeMarkdownFile = async (absoluteFilePath, dictionary, configuration) => {
@@ -22,15 +21,7 @@ const writeMarkdownFile = async (absoluteFilePath, dictionary, configuration) =>
22
21
  } catch {}
23
22
  throw error;
24
23
  }
25
- const formatCommand = detectFormatCommand(configuration);
26
- if (formatCommand) try {
27
- execSync(formatCommand.replace("{{file}}", absoluteFilePath), {
28
- stdio: "inherit",
29
- cwd: configuration.system.baseDir
30
- });
31
- } catch (error) {
32
- console.error(error);
33
- }
24
+ runFormatCommand(absoluteFilePath, configuration);
34
25
  };
35
26
 
36
27
  export { writeMarkdownFile };
@@ -1 +1 @@
1
- {"version":3,"file":"writeMarkdownFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeMarkdownFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { mkdir, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { detectFormatCommand } from '../detectFormatCommand';\nimport { renderMarkdownContentDeclaration } from './renderContentDeclaration';\n\nexport const writeMarkdownFile = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const fileContent = renderMarkdownContentDeclaration(dictionary);\n\n const dir = dirname(absoluteFilePath);\n await mkdir(dir, { recursive: true });\n\n const tempDir = configuration.system?.tempDir;\n if (tempDir) await mkdir(tempDir, { recursive: true });\n\n const tempFileName = `${basename(absoluteFilePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${absoluteFilePath}.${tempFileName}`;\n\n try {\n await writeFile(tempPath, fileContent, 'utf-8');\n await rename(tempPath, absoluteFilePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // ignore\n }\n throw error;\n }\n\n const formatCommand = detectFormatCommand(configuration);\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', absoluteFilePath), {\n stdio: 'inherit',\n cwd: configuration.system.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;AAQA,MAAa,oBAAoB,OAC/B,kBACA,YACA,kBACkB;CAClB,MAAM,cAAc,iCAAiC,UAAU;CAE/D,MAAM,MAAM,QAAQ,gBAAgB;CACpC,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CAEpC,MAAM,UAAU,cAAc,QAAQ;CACtC,IAAI,SAAS,MAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;CAErD,MAAM,eAAe,GAAG,SAAS,gBAAgB,EAAE,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;CACxG,MAAM,WAAW,UACb,KAAK,SAAS,YAAY,IAC1B,GAAG,iBAAiB,GAAG;CAE3B,IAAI;EACF,MAAM,UAAU,UAAU,aAAa,OAAO;EAC9C,MAAM,OAAO,UAAU,gBAAgB;CACzC,SAAS,OAAO;EACd,IAAI;GACF,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;EACpC,QAAQ,CAER;EACA,MAAM;CACR;CAEA,MAAM,gBAAgB,oBAAoB,aAAa;CACvD,IAAI,eACF,IAAI;EACF,SAAS,cAAc,QAAQ,YAAY,gBAAgB,GAAG;GAC5D,OAAO;GACP,KAAK,cAAc,OAAO;EAC5B,CAAC;CACH,SAAS,OAAO;EACd,QAAQ,MAAM,KAAK;CACrB;AAEJ"}
1
+ {"version":3,"file":"writeMarkdownFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeMarkdownFile.ts"],"sourcesContent":["import { mkdir, rename, rm, writeFile } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { runFormatCommand } from '../detectFormatCommand';\nimport { renderMarkdownContentDeclaration } from './renderContentDeclaration';\n\nexport const writeMarkdownFile = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const fileContent = renderMarkdownContentDeclaration(dictionary);\n\n const dir = dirname(absoluteFilePath);\n await mkdir(dir, { recursive: true });\n\n const tempDir = configuration.system?.tempDir;\n if (tempDir) await mkdir(tempDir, { recursive: true });\n\n const tempFileName = `${basename(absoluteFilePath)}.${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`;\n const tempPath = tempDir\n ? join(tempDir, tempFileName)\n : `${absoluteFilePath}.${tempFileName}`;\n\n try {\n await writeFile(tempPath, fileContent, 'utf-8');\n await rename(tempPath, absoluteFilePath);\n } catch (error) {\n try {\n await rm(tempPath, { force: true });\n } catch {\n // ignore\n }\n throw error;\n }\n\n runFormatCommand(absoluteFilePath, configuration);\n};\n"],"mappings":";;;;;;AAOA,MAAa,oBAAoB,OAC/B,kBACA,YACA,kBACkB;CAClB,MAAM,cAAc,iCAAiC,UAAU;CAE/D,MAAM,MAAM,QAAQ,gBAAgB;CACpC,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CAEpC,MAAM,UAAU,cAAc,QAAQ;CACtC,IAAI,SAAS,MAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;CAErD,MAAM,eAAe,GAAG,SAAS,gBAAgB,EAAE,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;CACxG,MAAM,WAAW,UACb,KAAK,SAAS,YAAY,IAC1B,GAAG,iBAAiB,GAAG;CAE3B,IAAI;EACF,MAAM,UAAU,UAAU,aAAa,OAAO;EAC9C,MAAM,OAAO,UAAU,gBAAgB;CACzC,SAAS,OAAO;EACd,IAAI;GACF,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;EACpC,QAAQ,CAER;EACA,MAAM;CACR;CAEA,iBAAiB,kBAAkB,aAAa;AAClD"}
@@ -1,8 +1,7 @@
1
- import { detectFormatCommand } from "../detectFormatCommand.mjs";
1
+ import { runFormatCommand } from "../detectFormatCommand.mjs";
2
2
  import { renderYamlContentDeclaration } from "./renderContentDeclaration.mjs";
3
- import { basename, dirname, join } from "node:path";
4
3
  import { mkdir, rename, rm, writeFile } from "node:fs/promises";
5
- import { execSync } from "node:child_process";
4
+ import { basename, dirname, join } from "node:path";
6
5
 
7
6
  // src/writeContentDeclaration/writeYamlFile.ts
8
7
  const writeYamlFile = async (absoluteFilePath, dictionary, configuration) => {
@@ -22,15 +21,7 @@ const writeYamlFile = async (absoluteFilePath, dictionary, configuration) => {
22
21
  } catch {}
23
22
  throw error;
24
23
  }
25
- const formatCommand = detectFormatCommand(configuration);
26
- if (formatCommand) try {
27
- execSync(formatCommand.replace("{{file}}", absoluteFilePath), {
28
- stdio: "inherit",
29
- cwd: configuration.system.baseDir
30
- });
31
- } catch (error) {
32
- console.error(error);
33
- }
24
+ runFormatCommand(absoluteFilePath, configuration);
34
25
  };
35
26
 
36
27
  export { writeYamlFile };