@fluenti/cli 0.4.0-rc.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./extract-cache-BioSaoFo.cjs`),t=require(`./tsx-extractor-B0vFXziu.cjs`),n=require(`./compile-kXClO6q4.cjs`);let r=require(`@fluenti/core/internal`),i=require(`node:fs`),a=require(`node:path`),o=require(`fast-glob`);o=e.l(o);let s=require(`node:crypto`),c=require(`@fluenti/core/config`);function l(e){return e}function u(t,n){if(!(0,i.existsSync)(t))return{};let r=(0,i.readFileSync)(t,`utf-8`);return n===`json`?e.a(r):e.r(r)}function d(e){let t={};for(let[n,r]of Object.entries(e))r.obsolete||(t[n]=r.translation??r.message??n);return t}async function f(t,o){let s=await(0,c.loadConfig)(void 0,t),l=(0,r.resolveLocaleCodes)(s.locales),f=s.format===`json`?`.json`:`.po`,p=(0,a.resolve)(t,s.compileOutDir);(0,i.mkdirSync)(p,{recursive:!0});let m=s.plugins?.length?(0,r.createPluginRunner)(s.plugins):void 0,h={};for(let e of l)h[e]=u((0,a.resolve)(t,s.catalogDir,`${e}${f}`),s.format);let g=n.t(h);for(let e of l)if(m){let t={locale:e,messages:d(h[e]),outDir:p,config:s};await m.runBeforeCompile(t)}if(o?.parallel&&l.length>1){let t=await e.n(l.map(e=>({locale:e,catalog:h[e],allIds:g,sourceLocale:s.sourceLocale})));for(let e of t)(0,i.writeFileSync)((0,a.resolve)(p,`${e.locale}.js`),e.code,`utf-8`)}else for(let e of l){let{code:t}=n.n(h[e],e,g,s.sourceLocale);(0,i.writeFileSync)((0,a.resolve)(p,`${e}.js`),t,`utf-8`)}let _=n.r(l,s.compileOutDir);(0,i.writeFileSync)((0,a.resolve)(p,`index.js`),_,`utf-8`);let v=n.i(g,h,s.sourceLocale);(0,i.writeFileSync)((0,a.resolve)(p,`messages.d.ts`),v,`utf-8`);for(let e of l)if(m){let t={locale:e,messages:d(h[e]),outDir:p,config:s};await m.runAfterCompile(t)}}function p(e){return(0,s.createHash)(`md5`).update(e).digest(`hex`).slice(0,8)}function m(t,n){if(!(0,i.existsSync)(t))return{};let r=(0,i.readFileSync)(t,`utf-8`);return n===`json`?e.a(r):e.r(r)}function h(t,n,r){let o=r===`json`?e.o(n):e.i(n);try{(0,i.mkdirSync)((0,a.dirname)(t),{recursive:!0}),(0,i.writeFileSync)(t,o,`utf-8`)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`Failed to write catalog "${t}": ${n}`)}}async function g(e,n){if((0,a.extname)(e)===`.vue`)try{let{extractFromVue:t}=await Promise.resolve().then(()=>require(`./vue-extractor.cjs`));return t(n,e)}catch{return[]}return t.t(n,e)}async function _(t,n){let s=await(0,c.loadConfig)(void 0,t),l=(0,r.resolveLocaleCodes)(s.locales),u=await(0,o.default)(s.include,{cwd:t,ignore:s.exclude??[]}),d=[],f=n?.useCache===!1?null:new e.t((0,a.resolve)(t,s.catalogDir),p(t));for(let e of u){let n=(0,a.resolve)(t,e);if(f){let e=f.get(n);if(e){d.push(...e);continue}}let r=await g(n,(0,i.readFileSync)(n,`utf-8`));d.push(...r),f&&f.set(n,r)}f&&(f.prune(new Set(u.map(e=>(0,a.resolve)(t,e)))),f.save());let _=s.plugins?.length?(0,r.createPluginRunner)(s.plugins):void 0;if(_){let e=new Map;for(let t of d)e.set(t.id,t);let t={messages:e,sourceLocale:s.sourceLocale,targetLocales:l.filter(e=>e!==s.sourceLocale),config:s};await _.runAfterExtract(t)}let v=s.format===`json`?`.json`:`.po`,y=n?.clean??!1,b=n?.stripFuzzy??!1;for(let n of l){let r=(0,a.resolve)(t,s.catalogDir,`${n}${v}`),{catalog:i}=e.s(m(r,s.format),d,{stripFuzzy:b});h(r,y?Object.fromEntries(Object.entries(i).filter(([,e])=>!e.obsolete)):i,s.format)}}exports.collectAllIds=n.t,exports.compileCatalog=n.n,exports.compileIndex=n.r,exports.defineConfig=l,exports.extractFromTsx=t.t,Object.defineProperty(exports,`hashMessage`,{enumerable:!0,get:function(){return r.hashMessage}}),Object.defineProperty(exports,`loadConfig`,{enumerable:!0,get:function(){return c.loadConfig}}),exports.readJsonCatalog=e.a,exports.readPoCatalog=e.r,exports.runCompile=f,exports.runExtract=_,exports.updateCatalog=e.s,exports.writeJsonCatalog=e.o,exports.writePoCatalog=e.i;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./extract-cache-BioSaoFo.cjs`),t=require(`./tsx-extractor-B0vFXziu.cjs`),n=require(`./compile-kXClO6q4.cjs`);let r=require(`@fluenti/core/internal`),i=require(`node:fs`),a=require(`node:path`),o=require(`fast-glob`);o=e.l(o);let s=require(`node:crypto`),c=require(`@fluenti/core/config`);function l(e){return e}function u(t,n){if(!(0,i.existsSync)(t))return{};let r=(0,i.readFileSync)(t,`utf-8`);return n===`json`?e.a(r):e.r(r)}function d(e){let t={};for(let[n,r]of Object.entries(e))r.obsolete||(t[n]=r.translation??r.message??n);return t}async function f(t,o){let s=await(0,c.loadConfig)(void 0,t),l=(0,r.resolveLocaleCodes)(s.locales),f=s.format===`json`?`.json`:`.po`,p=(0,a.resolve)(t,s.compileOutDir);(0,i.mkdirSync)(p,{recursive:!0});let m=s.plugins?.length?(0,r.createPluginRunner)(s.plugins):void 0,h={};for(let e of l)h[e]=u((0,a.resolve)(t,s.catalogDir,`${e}${f}`),s.format);let g=n.t(h);for(let e of l)if(m){let t={locale:e,messages:d(h[e]),outDir:p,config:s};await m.runBeforeCompile(t)}if(o?.parallel&&l.length>1){let t=await e.n(l.map(e=>({locale:e,catalog:h[e],allIds:g,sourceLocale:s.sourceLocale})));for(let e of t)(0,i.writeFileSync)((0,a.resolve)(p,`${e.locale}.js`),e.code,`utf-8`)}else for(let e of l){let{code:t}=n.n(h[e],e,g,s.sourceLocale);(0,i.writeFileSync)((0,a.resolve)(p,`${e}.js`),t,`utf-8`)}let _=n.r(l,s.compileOutDir);(0,i.writeFileSync)((0,a.resolve)(p,`index.js`),_,`utf-8`);let v=n.i(g,h,s.sourceLocale);(0,i.writeFileSync)((0,a.resolve)(p,`messages.d.ts`),v,`utf-8`);for(let e of l)if(m){let t={locale:e,messages:d(h[e]),outDir:p,config:s};await m.runAfterCompile(t)}}function p(e){return(0,s.createHash)(`md5`).update(e).digest(`hex`).slice(0,8)}function m(t,n){if(!(0,i.existsSync)(t))return{};let r=(0,i.readFileSync)(t,`utf-8`);return n===`json`?e.a(r):e.r(r)}function h(t,n,r){let o=r===`json`?e.o(n):e.i(n);try{(0,i.mkdirSync)((0,a.dirname)(t),{recursive:!0}),(0,i.writeFileSync)(t,o,`utf-8`)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`Failed to write catalog "${t}": ${n}`)}}async function g(e,n){if((0,a.extname)(e)===`.vue`)try{let{extractFromVue:t}=await Promise.resolve().then(()=>require(`./vue-extractor.cjs`));return t(n,e)}catch{return[]}return t.t(n,e)}async function _(t,n){let s=await(0,c.loadConfig)(void 0,t),l=(0,r.resolveLocaleCodes)(s.locales),u=await(0,o.default)(s.include,{cwd:t,ignore:s.exclude??[],absolute:!1}),d=[],f=n?.useCache===!1?null:new e.t((0,a.resolve)(t,s.catalogDir),p(t));for(let e of u){let n=(0,a.resolve)(t,e);if(f){let e=f.get(n);if(e){d.push(...e);continue}}let r=await g(n,(0,i.readFileSync)(n,`utf-8`));d.push(...r),f&&f.set(n,r)}f&&(f.prune(new Set(u.map(e=>(0,a.resolve)(t,e)))),f.save());let _=s.plugins?.length?(0,r.createPluginRunner)(s.plugins):void 0;if(_){let e=new Map;for(let t of d)e.set(t.id,t);let t={messages:e,sourceLocale:s.sourceLocale,targetLocales:l.filter(e=>e!==s.sourceLocale),config:s};await _.runAfterExtract(t)}let v=s.format===`json`?`.json`:`.po`,y=n?.clean??!1,b=n?.stripFuzzy??!1;for(let n of l){let r=(0,a.resolve)(t,s.catalogDir,`${n}${v}`),{catalog:i}=e.s(m(r,s.format),d,{stripFuzzy:b});h(r,y?Object.fromEntries(Object.entries(i).filter(([,e])=>!e.obsolete)):i,s.format)}}exports.collectAllIds=n.t,exports.compileCatalog=n.n,exports.compileIndex=n.r,exports.defineConfig=l,exports.extractFromTsx=t.t,Object.defineProperty(exports,`hashMessage`,{enumerable:!0,get:function(){return r.hashMessage}}),Object.defineProperty(exports,`loadConfig`,{enumerable:!0,get:function(){return c.loadConfig}}),exports.readJsonCatalog=e.a,exports.readPoCatalog=e.r,exports.runCompile=f,exports.runExtract=_,exports.updateCatalog=e.s,exports.writeJsonCatalog=e.o,exports.writePoCatalog=e.i;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/internal'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginCompileContext } from '@fluenti/core/internal'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/internal'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginExtractContext } from '@fluenti/core/internal'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [] })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n\n writeCatalog(catalogPath, finalCatalog, config.format)\n }\n}\n"],"mappings":"oXAoBA,SAAgB,EAAa,EAAkE,CAC7F,OAAO,ECVT,SAAS,EAAY,EAAkB,EAAoC,CACzE,GAAI,EAAA,EAAA,EAAA,YAAY,EAAS,CAAE,MAAO,EAAE,CACpC,IAAM,GAAA,EAAA,EAAA,cAAuB,EAAU,QAAQ,CAC/C,OAAO,IAAW,OAAS,EAAA,EAAgB,EAAQ,CAAG,EAAA,EAAc,EAAQ,CAI9E,SAAS,EAAkB,EAA8C,CACvE,IAAM,EAAmC,EAAE,CAC3C,IAAK,GAAM,CAAC,EAAI,KAAU,OAAO,QAAQ,EAAQ,CAC3C,EAAM,WAEV,EAAS,GADI,EAAM,aAAe,EAAM,SAAW,GAGrD,OAAO,EAYT,eAAsB,EAAW,EAAa,EAA4C,CACxF,IAAM,EAAS,MAAA,EAAA,EAAA,YAAiB,IAAA,GAAW,EAAI,CACzC,GAAA,EAAA,EAAA,oBAAiC,EAAO,QAAQ,CAChD,EAAM,EAAO,SAAW,OAAS,QAAU,MAE3C,GAAA,EAAA,EAAA,SAAiB,EAAK,EAAO,cAAc,EACjD,EAAA,EAAA,WAAU,EAAQ,CAAE,UAAW,GAAM,C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CAAC,CAMxE,EAAa,EAJQ,EACjB,OAAO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,EAAG,KAAW,CAAC,EAAM,SAAS,CAAC,CAClF,EAEoC,EAAO,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/internal'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginCompileContext } from '@fluenti/core/internal'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/internal'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginExtractContext } from '@fluenti/core/internal'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [], absolute: false })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n\n writeCatalog(catalogPath, finalCatalog, config.format)\n }\n}\n"],"mappings":"oXAoBA,SAAgB,EAAa,EA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,IAAI,IAAI,EAAM,IAAK,IAAA,EAAA,EAAA,SAAc,EAAK,EAAE,CAAC,CAAC,CAAC,CACvD,EAAM,MAAM,EAId,IAAM,EAAe,EAAO,SAAS,QAAA,EAAA,EAAA,oBACd,EAAO,QAAQ,CAClC,IAAA,GAEJ,GAAI,EAAc,CAChB,IAAM,EAAa,IAAI,IACvB,IAAK,IAAM,KAAO,EAChB,EAAW,IAAI,EAAI,GAAI,EAAI,CAE7B,IAAM,EAAuC,CAC3C,SAAU,EACV,aAAc,EAAO,aACrB,cAAe,EAAY,OAAQ,GAAM,IAAM,EAAO,aAAa,CACnE,SACD,CACD,MAAM,EAAa,gBAAgB,EAAe,CAGpD,IAAM,EAAM,EAAO,SAAW,OAAS,QAAU,MAC3C,EAAQ,GAAS,OAAS,GAC1B,EAAa,GAAS,YAAc,GAE1C,IAAK,IAAM,KAAU,EAAa,CAChC,IAAM,GAAA,EAAA,EAAA,SAAsB,EAAK,EAAO,WAAY,GAAG,IAAS,IAAM,CAEhE,CAAE,WAAY,EAAA,EADH,EAAY,EAAa,EAAO,OAAO,CACZ,EAAa,CAAE,aAAY,CAAC,CAMxE,EAAa,EAJQ,EACjB,OAAO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,EAAG,KAAW,CAAC,EAAM,SAAS,CAAC,CAClF,EAEoC,EAAO,OAAO"}
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,8 @@ async function M(e, t) {
|
|
|
94
94
|
async function N(e, t) {
|
|
95
95
|
let n = await u(void 0, e), r = h(n.locales), i = await C(n.include, {
|
|
96
96
|
cwd: e,
|
|
97
|
-
ignore: n.exclude ?? []
|
|
97
|
+
ignore: n.exclude ?? [],
|
|
98
|
+
absolute: !1
|
|
98
99
|
}), a = [], s = t?.useCache === !1 ? null : new f(S(e, n.catalogDir), k(e));
|
|
99
100
|
for (let t of i) {
|
|
100
101
|
let n = S(e, t);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/internal'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginCompileContext } from '@fluenti/core/internal'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/internal'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginExtractContext } from '@fluenti/core/internal'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [] })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n\n writeCatalog(catalogPath, finalCatalog, config.format)\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,EAAa,GAAkE;AAC7F,QAAO;;;;ACVT,SAAS,EAAY,GAAkB,GAAoC;AACzE,KAAI,CAAC,EAAW,EAAS,CAAE,QAAO,EAAE;CACpC,IAAM,IAAU,EAAa,GAAU,QAAQ;AAC/C,QAA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AAM,EAEhE,EAAE,eAAY,EADH,EAAY,GAAa,EAAO,OAAO,EACZ,GAAa,EAAE,eAAY,CAAC;AAMxE,IAAa,GAJQ,IACjB,OAAO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,GAAG,OAAW,CAAC,EAAM,SAAS,CAAC,GAClF,GAEoC,EAAO,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/internal'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginCompileContext } from '@fluenti/core/internal'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/internal'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginExtractContext } from '@fluenti/core/internal'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [], absolute: false })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n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,MAAM,EAAO,aAAa;GACnE;GACD;AACD,QAAM,EAAa,gBAAgB,EAAe;;CAGpD,IAAM,IAAM,EAAO,WAAW,SAAS,UAAU,OAC3C,IAAQ,GAAS,SAAS,IAC1B,IAAa,GAAS,cAAc;AAE1C,MAAK,IAAM,KAAU,GAAa;EAChC,IAAM,IAAc,EAAQ,GAAK,EAAO,YAAY,GAAG,IAAS,IAAM,EAEhE,EAAE,eAAY,EADH,EAAY,GAAa,EAAO,OAAO,EACZ,GAAa,EAAE,eAAY,CAAC;AAMxE,IAAa,GAJQ,IACjB,OAAO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,GAAG,OAAW,CAAC,EAAM,SAAS,CAAC,GAClF,GAEoC,EAAO,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluenti/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fluenti CLI — message extraction from Vue SFC & TSX, PO/JSON catalog compilation",
|
|
6
6
|
"homepage": "https://fluenti.dev",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"fast-glob": "^3",
|
|
73
73
|
"gettext-parser": "^9",
|
|
74
74
|
"jiti": "^2",
|
|
75
|
-
"@fluenti/core": "0.
|
|
75
|
+
"@fluenti/core": "0.5.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@vue/compiler-sfc": "^3.5"
|