lynx-intlayer
Version:
A Lynx plugin for seamless internationalization (i18n) and localization (l10n) of your mobile app.
1 lines • 4.28 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/plugin/pluginIntlayerLynx.ts"],"sourcesContent":["import {\n checkDictionaryChanges,\n prepareIntlayer,\n watch,\n} from '@intlayer/chokidar';\nimport { ESMxCJSRequire, getConfiguration, logger } from '@intlayer/config';\nimport type { RsbuildPlugin } from '@rsbuild/core';\nimport { join, relative } from 'path';\n\n/**\n * A Lynx plugin to integrate Intlayer into the Lynx build process.\n *\n * - Loads the Intlayer configuration and injects environment variables.\n * - If enabled, starts a file watcher for dictionary changes.\n * - On build, prepares the Intlayer configuration.\n * - Optionally checks for dictionary changes before compiling (hot reload).\n *\n * Usage in your lynx.config.ts:\n *\n * import { defineConfig } from '@lynx-js/rspeedy'\n * import { pluginIntlayerLynx } from '@intlayer/lynx-plugin'\n *\n * export default defineConfig({\n * plugins: [\n * pluginIntlayerLynx({\n * hotReload: true, // optional\n * }),\n * ],\n * // ...other configuration\n * })\n */\nexport const pluginIntlayerLynx = (): RsbuildPlugin => {\n return {\n name: 'plugin-intlayer-lynx',\n\n async setup(api) {\n // Load the Intlayer configuration and format env variables for Lynx.\n const intlayerConfig = getConfiguration();\n\n await prepareIntlayer(intlayerConfig);\n\n // Compute the relative paths for alias configuration.\n const { mainDir, configDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n const unmergedDictionariesPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n\n const configurationPath = join(configDir, 'configuration.json');\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n\n // If file watching is enabled in Intlayer's config, start it.\n if (intlayerConfig.content.watch) {\n watch(intlayerConfig);\n }\n\n // Merge Intlayer-specific environment variables and alias configuration.\n api.modifyRsbuildConfig(async (config, { mergeRsbuildConfig }) => {\n return mergeRsbuildConfig(config, {\n source: {\n alias: {\n '@intlayer/dictionaries-entry': relativeDictionariesPath,\n '@intlayer/unmerged-dictionaries-entry':\n relativeUnmergedDictionariesPath,\n '@intlayer/config/built': relativeConfigurationPath,\n react: ESMxCJSRequire.resolve('@lynx-js/react'),\n },\n },\n });\n });\n\n // Optionally, before compile check for dictionary changes if hot reload is enabled.\n if (intlayerConfig.editor.hotReload) {\n api.onBeforeEnvironmentCompile(async () => {\n try {\n await checkDictionaryChanges();\n } catch (error) {\n logger(`Error checking dictionary changes: ${error}`, {\n level: 'error',\n });\n }\n });\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAIO;AACP,oBAAyD;AAEzD,kBAA+B;AAwBxB,MAAM,qBAAqB,MAAqB;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,MAAM,KAAK;AAEf,YAAM,qBAAiB,gCAAiB;AAExC,gBAAM,iCAAgB,cAAc;AAGpC,YAAM,EAAE,SAAS,WAAW,QAAQ,IAAI,eAAe;AAEvD,YAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,YAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAEnE,YAAM,+BAA2B;AAAA,QAC/B;AAAA,QACA;AAAA,MACF;AACA,YAAM,uCAAmC;AAAA,QACvC;AAAA,QACA;AAAA,MACF;AAEA,YAAM,wBAAoB,kBAAK,WAAW,oBAAoB;AAC9D,YAAM,gCAA4B,sBAAS,SAAS,iBAAiB;AAGrE,UAAI,eAAe,QAAQ,OAAO;AAChC,mCAAM,cAAc;AAAA,MACtB;AAGA,UAAI,oBAAoB,OAAO,QAAQ,EAAE,mBAAmB,MAAM;AAChE,eAAO,mBAAmB,QAAQ;AAAA,UAChC,QAAQ;AAAA,YACN,OAAO;AAAA,cACL,gCAAgC;AAAA,cAChC,yCACE;AAAA,cACF,0BAA0B;AAAA,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