@wp-blocks/make-pot 1.6.3 → 1.6.5

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 (41) hide show
  1. package/biome.json +1 -1
  2. package/lib/cli/parseCli.js +1 -1
  3. package/lib/cli/parseCli.js.map +2 -2
  4. package/lib/const.js +1 -1
  5. package/lib/const.js.map +1 -1
  6. package/lib/extractors/auditStrings.js +4 -3
  7. package/lib/extractors/auditStrings.js.map +2 -2
  8. package/lib/extractors/headers.js +7 -6
  9. package/lib/extractors/headers.js.map +3 -3
  10. package/lib/extractors/json.js +1 -1
  11. package/lib/extractors/json.js.map +2 -2
  12. package/lib/extractors/schema.js +3 -4
  13. package/lib/extractors/schema.js.map +2 -2
  14. package/lib/fs/fs.js +2 -2
  15. package/lib/fs/fs.js.map +2 -2
  16. package/lib/fs/glob.js +1 -1
  17. package/lib/fs/glob.js.map +2 -2
  18. package/lib/parser/exec.js +3 -3
  19. package/lib/parser/exec.js.map +2 -2
  20. package/lib/parser/makeJson.js +1 -1
  21. package/lib/parser/makeJson.js.map +2 -2
  22. package/lib/parser/makePot.js.map +1 -1
  23. package/lib/parser/process.js +1 -1
  24. package/lib/parser/process.js.map +2 -2
  25. package/lib/parser/progress.js +1 -1
  26. package/lib/parser/progress.js.map +2 -2
  27. package/lib/parser/taskRunner.js +2 -2
  28. package/lib/parser/taskRunner.js.map +2 -2
  29. package/lib/parser/tree.js +2 -1
  30. package/lib/parser/tree.js.map +2 -2
  31. package/lib/types.js.map +1 -1
  32. package/lib/utils/common.js +2 -2
  33. package/lib/utils/common.js.map +2 -2
  34. package/lib/utils/extractors.js +1 -1
  35. package/lib/utils/extractors.js.map +2 -2
  36. package/lib/utils/output.js +1 -1
  37. package/lib/utils/output.js.map +2 -2
  38. package/package.json +16 -12
  39. package/tests/extract-headers.test.js +69 -1
  40. package/tests/generate-header.test.js +27 -0
  41. package/tests/tree.test.js +74 -1
package/lib/fs/glob.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.create;var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},p=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!j.call(t,n)&&n!==r&&s(t,n,{get:()=>e[n],enumerable:!(i=g(e,n))||i.enumerable});return t};var o=(t,e,r)=>(r=t!=null?f(x(t)):{},p(e||!t||!t.__esModule?s(r,"default",{value:t,enumerable:!0}):r,t)),P=t=>p(s({},"__esModule",{value:!0}),t);var A={};w(A,{getFiles:()=>F,getParser:()=>v,ignoreFunc:()=>d});module.exports=P(A);var u=o(require("node:path")),l=require("glob"),h=require("minimatch"),b=o(require("tree-sitter-javascript")),c=o(require("tree-sitter-php")),m=o(require("tree-sitter-typescript")),a=require("../utils/common.js");function v(t){switch((0,a.getFileExtension)(t)){case"ts":return m.typescript;case"tsx":return m.tsx;case"js":case"jsx":case"mjs":case"cjs":return b;case"php":return c.php;case"blade.php":return c.php_only;default:return null}}const d=(t,e)=>e.some(r=>{switch((0,a.detectPatternType)(r)){case"file":return t.isNamed(r);case"directory":return t.relative().includes(r);default:return(0,h.minimatch)(t.relative(),r)}});function F(t,e){return new l.Glob(e.include,{ignore:{ignored:r=>d(r,e.exclude)},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?u.default.resolve(t.paths.root):void 0})}0&&(module.exports={getFiles,getParser,ignoreFunc});
1
+ "use strict";var y=Object.create;var c=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},u=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of P(e))!w.call(t,n)&&n!==r&&c(t,n,{get:()=>e[n],enumerable:!(s=x(e,n))||s.enumerable});return t};var p=(t,e,r)=>(r=t!=null?y(j(t)):{},u(e||!t||!t.__esModule?c(r,"default",{value:t,enumerable:!0}):r,t)),b=t=>u(c({},"__esModule",{value:!0}),t);var F={};v(F,{classifyExcludes:()=>h,getFiles:()=>E,getParser:()=>A});module.exports=b(F);var d=p(require("node:path")),f=require("glob"),g=require("minimatch"),k=p(require("tree-sitter-javascript")),m=p(require("tree-sitter-php")),l=p(require("tree-sitter-typescript")),i=require("../utils/common.js");function A(t){switch((0,i.getFileExtension)(t)){case"ts":return l.typescript;case"tsx":return l.tsx;case"js":case"jsx":case"mjs":case"cjs":return k;case"php":return m.php;case"blade.php":return m.php_only;default:return null}}function h(t){const e=[],r=[];for(const s of t)(0,i.detectPatternType)(s)==="directory"?e.push(s):r.push(s);return{dirs:e,filePatterns:r}}async function E(t,e){const{dirs:r,filePatterns:s}=h(e.exclude);return new f.Glob(e.include,{ignore:{childrenIgnored:a=>r.some(o=>a.isNamed(o)),ignored:a=>s.some(o=>(0,i.detectPatternType)(o)==="file"?a.isNamed(o):(0,g.minimatch)(a.relative(),o))},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?d.default.resolve(t.paths.root):void 0}).walk()}0&&(module.exports={classifyExcludes,getFiles,getParser});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/fs/glob.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\r\nimport { Glob, type Path } from \"glob\";\r\nimport { minimatch } from \"minimatch\";\r\n// @ts-expect-error\r\nimport * as javascript from \"tree-sitter-javascript\";\r\n// @ts-expect-error\r\nimport * as php from \"tree-sitter-php\";\r\n// @ts-expect-error\r\nimport * as ts from \"tree-sitter-typescript\";\r\nimport type { Args, Patterns } from \"../types.js\";\r\nimport { detectPatternType, getFileExtension } from \"../utils/common.js\";\r\n\r\n/**\r\n * Return the parser based on the file extension\r\n *\r\n * @param file - Path to the file\r\n * @return {Parser|null} - the parser to be used with the file or null if no parser is found\r\n */\r\nexport function getParser(\r\n\tfile: string,\r\n): string | { name: string; language: unknown } | null {\r\n\tconst ext = getFileExtension(file);\r\n\tswitch (ext) {\r\n\t\tcase \"ts\":\r\n\t\t\treturn ts.typescript;\r\n\t\tcase \"tsx\":\r\n\t\t\treturn ts.tsx;\r\n\t\tcase \"js\":\r\n\t\tcase \"jsx\":\r\n\t\tcase \"mjs\":\r\n\t\tcase \"cjs\":\r\n\t\t\treturn javascript;\r\n\t\tcase \"php\":\r\n\t\t\treturn php.php;\r\n\t\tcase \"blade.php\":\r\n\t\t\treturn php.php_only;\r\n\t\tdefault:\r\n\t\t\treturn null;\r\n\t}\r\n}\r\n\r\n// Build the ignore function for Glob\r\nexport const ignoreFunc = (\r\n\tfilePath: Path,\r\n\texcludedPatterns: string[],\r\n): boolean => {\r\n\treturn excludedPatterns.some((exclude) => {\r\n\t\tconst type = detectPatternType(exclude);\r\n\t\t// return true to ignore\r\n\t\tswitch (type) {\r\n\t\t\tcase \"file\":\r\n\t\t\t\treturn filePath.isNamed(exclude);\r\n\t\t\tcase \"directory\":\r\n\t\t\t\treturn filePath.relative().includes(exclude);\r\n\t\t\tdefault:\r\n\t\t\t\t// Handle glob patterns using minimatch\r\n\t\t\t\treturn minimatch(filePath.relative(), exclude);\r\n\t\t}\r\n\t}) as boolean;\r\n};\r\n\r\n/**\r\n * Retrieves a list of files based on the provided arguments and patterns.\r\n *\r\n * @param {Args} args - The argument object containing the source directory and other options.\r\n * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns.\r\n * @return A promise that resolves to an array of file paths.\r\n */\r\nexport function getFiles(args: Args, pattern: Patterns) {\r\n\t// Execute the glob search with the built patterns\r\n\treturn new Glob(pattern.include, {\r\n\t\tignore: {\r\n\t\t\tignored: (p: Path) => ignoreFunc(p, pattern.exclude),\r\n\t\t},\r\n\t\tnodir: true,\r\n\t\tcwd: args.paths.cwd,\r\n\t\troot: args.paths.root ? path.resolve(args.paths.root) : undefined,\r\n\t});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import { minimatch } from 'minimatch'\r\nimport * as javascript from 'tree-sitter-javascript'\r\n// @ts-expect-error\r\nimport * as php from 'tree-sitter-php'\r\n// @ts-expect-error\r\nimport * as ts from 'tree-sitter-typescript'\r\nimport type { Args, Patterns } from '../types.js'\r\nimport { detectPatternType, getFileExtension } from '../utils/common.js'\r\n\r\n/**\r\n * Return the parser based on the file extension\r\n *\r\n * @param file - Path to the file\r\n * @return {Parser|null} - the parser to be used with the file or null if no parser is found\r\n */\r\nexport function getParser(\r\n\tfile: string,\r\n): string | { name: string; language: unknown } | null {\r\n\tconst ext = getFileExtension(file);\r\n\tswitch (ext) {\r\n\t\tcase \"ts\":\r\n\t\t\treturn ts.typescript;\r\n\t\tcase \"tsx\":\r\n\t\t\treturn ts.tsx;\r\n\t\tcase \"js\":\r\n\t\tcase \"jsx\":\r\n\t\tcase \"mjs\":\r\n\t\tcase \"cjs\":\r\n\t\t\treturn javascript;\r\n\t\tcase \"php\":\r\n\t\t\treturn php.php;\r\n\t\tcase \"blade.php\":\r\n\t\t\treturn php.php_only;\r\n\t\tdefault:\r\n\t\t\treturn null;\r\n\t}\r\n}\r\n\r\n/**\r\n * Classify exclude patterns into directory names (for tree pruning)\r\n * and file/glob patterns (for per-file filtering).\r\n */\r\nexport function classifyExcludes(excludedPatterns: string[]) {\r\n\tconst dirs: string[] = [];\r\n\tconst filePatterns: string[] = [];\r\n\tfor (const exclude of excludedPatterns) {\r\n\t\tconst type = detectPatternType(exclude);\r\n\t\tif (type === \"directory\") {\r\n\t\t\tdirs.push(exclude);\r\n\t\t} else {\r\n\t\t\tfilePatterns.push(exclude);\r\n\t\t}\r\n\t}\r\n\treturn { dirs, filePatterns };\r\n}\r\n\r\n/**\r\n * Retrieves a list of files based on the provided arguments and patterns.\r\n *\r\n * @param {Args} args - The argument object containing the source directory and other options.\r\n * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns.\r\n * @return A promise that resolves to an array of file paths.\r\n */\r\nexport async function getFiles(args: Args, pattern: Patterns): Promise<string[]> {\r\n\tconst { dirs, filePatterns } = classifyExcludes(pattern.exclude);\r\n\r\n\tconst g = new Glob(pattern.include, {\r\n\t\tignore: {\r\n\t\t\t// Prune entire directory subtrees \u2014 glob won't enter these dirs at all\r\n\t\t\tchildrenIgnored: (p: Path) => dirs.some((d) => p.isNamed(d)),\r\n\t\t\t// Filter individual files by name or glob pattern\r\n\t\t\tignored: (p: Path) =>\r\n\t\t\t\tfilePatterns.some((fp) => {\r\n\t\t\t\t\tconst type = detectPatternType(fp);\r\n\t\t\t\t\tif (type === \"file\") {\r\n\t\t\t\t\t\treturn p.isNamed(fp);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn minimatch(p.relative(), fp);\r\n\t\t\t\t}),\r\n\t\t},\r\n\t\tnodir: true,\r\n\t\tcwd: args.paths.cwd,\r\n\t\troot: args.paths.root ? path.resolve(args.paths.root) : undefined,\r\n\t});\r\n\r\n\treturn g.walk();\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,kBAAgC;AAChC,uBAA0B;AAC1B,iBAA4B;AAE5B,UAAqB;AAErB,SAAoB;AAEpB,oBAAoD;AAQ7C,SAAS,UACf,MACsD;AACtD,QAAM,UAAM,gCAAiB,IAAI;AACjC,UAAQ,KAAK;AAAA,IACZ,KAAK;AACJ,aAAO,GAAG;AAAA,IACX,KAAK;AACJ,aAAO,GAAG;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO,IAAI;AAAA,IACZ,KAAK;AACJ,aAAO,IAAI;AAAA,IACZ;AACC,aAAO;AAAA,EACT;AACD;AAMO,SAAS,iBAAiB,kBAA4B;AAC5D,QAAM,OAAiB,CAAC;AACxB,QAAM,eAAyB,CAAC;AAChC,aAAW,WAAW,kBAAkB;AACvC,UAAM,WAAO,iCAAkB,OAAO;AACtC,QAAI,SAAS,aAAa;AACzB,WAAK,KAAK,OAAO;AAAA,IAClB,OAAO;AACN,mBAAa,KAAK,OAAO;AAAA,IAC1B;AAAA,EACD;AACA,SAAO,EAAE,MAAM,aAAa;AAC7B;AASA,eAAsB,SAAS,MAAY,SAAsC;AAChF,QAAM,EAAE,MAAM,aAAa,IAAI,iBAAiB,QAAQ,OAAO;AAE/D,QAAM,IAAI,IAAI,iBAAK,QAAQ,SAAS;AAAA,IACnC,QAAQ;AAAA;AAAA,MAEP,iBAAiB,CAAC,MAAY,KAAK,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,MAE3D,SAAS,CAAC,MACT,aAAa,KAAK,CAAC,OAAO;AACzB,cAAM,WAAO,iCAAkB,EAAE;AACjC,YAAI,SAAS,QAAQ;AACpB,iBAAO,EAAE,QAAQ,EAAE;AAAA,QACpB;AACA,mBAAO,4BAAU,EAAE,SAAS,GAAG,EAAE;AAAA,MAClC,CAAC;AAAA,IACH;AAAA,IACA,OAAO;AAAA,IACP,KAAK,KAAK,MAAM;AAAA,IAChB,MAAM,KAAK,MAAM,OAAO,iBAAAA,QAAK,QAAQ,KAAK,MAAM,IAAI,IAAI;AAAA,EACzD,CAAC;AAED,SAAO,EAAE,KAAK;AACf;",
6
6
  "names": ["path"]
7
7
  }
@@ -1,3 +1,3 @@
1
- "use strict";var w=Object.create;var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var k=(t,o)=>{for(var e in o)s(t,e,{get:o[e],enumerable:!0})},c=(t,o,e,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of S(o))!$.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(i=x(o,n))||i.enumerable});return t};var A=(t,o,e)=>(e=t!=null?w(v(t)):{},c(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t)),B=t=>c(s({},"__esModule",{value:!0}),t);var H={};k(H,{exec:()=>G});module.exports=B(H);var m=A(require("node:path")),f=require("gettext-parser"),h=require("../extractors/auditStrings.js"),p=require("../extractors/headers.js"),a=require("../fs/fs.js"),r=require("../utils/common.js"),u=require("../utils/output"),d=require("./patterns.js"),g=require("./process.js"),y=require("./progress.js"),T=require("./taskRunner.js");async function G(t){t.options?.silent||(console.log("\u{1F4DD} Starting makePot for",t?.slug),(0,r.printStats)());const o=await(0,p.generateHeader)(t);let e=(0,p.translationsHeaders)(t);t.options?.silent||(0,r.outputPathRecap)(m.default.resolve(t.paths.cwd),t.patterns);const i=(0,y.initProgress)(t,0);i.start(3,1,{filename:`Resolving files in ${m.default.resolve(t.paths.cwd)}`});const n=(0,d.getPatterns)(t),l=await(0,g.processFiles)(n,t);if(i.update(2,{filename:`Found ${l.length} files... `}),e=await(0,T.taskRunner)(l,e,t,i),t.options?.skip.audit||(console.log(`
2
- Audit strings...`),(0,h.audit)(t,e)),t.options?.json)return(0,u.outputJson)(t,o,e);const C={charset:(0,a.getEncodingCharset)(t.options?.charset),headers:o,translations:e.toJson()},P=f.po.compile(C).toString((0,a.getCharset)(t.options?.charset));return`${t.options?.fileComment||(0,r.getCopyright)(t.headers?.name||t.slug,t.headers?.license??"GPL v2 or later")}
3
- ${P}`}0&&(module.exports={exec});
1
+ "use strict";var x=Object.create;var r=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var B=(t,o)=>{for(var e in o)r(t,e,{get:o[e],enumerable:!0})},c=(t,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of $(o))!A.call(t,i)&&i!==e&&r(t,i,{get:()=>o[i],enumerable:!(n=S(o,i))||n.enumerable});return t};var G=(t,o,e)=>(e=t!=null?x(v(t)):{},c(o||!t||!t.__esModule?r(e,"default",{value:t,enumerable:!0}):e,t)),H=t=>c(r({},"__esModule",{value:!0}),t);var j={};B(j,{exec:()=>R});module.exports=H(j);var m=G(require("node:path")),f=require("gettext-parser"),h=require("../extractors/auditStrings.js"),p=require("../extractors/headers.js"),a=require("../fs/fs.js"),s=require("../utils/common.js"),d=require("../utils/output"),u=require("./patterns.js"),g=require("./process.js"),y=require("./progress.js"),C=require("./taskRunner.js");async function R(t){t.options?.silent||(console.log("\u{1F4DD} Starting makePot for",t?.slug),(0,s.printStats)());const o=await(0,p.generateHeader)(t);let e=(0,p.translationsHeaders)(t);t.options?.silent||(0,s.outputPathRecap)(m.default.resolve(t.paths.cwd),t.patterns);const n=(0,y.initProgress)(t,0);n.start(3,1,{filename:`Resolving files in ${m.default.resolve(t.paths.cwd)}`});const i=(0,u.getPatterns)(t),{tasks:l,processedCount:P,skippedCount:T}=await(0,g.processFiles)(i,t,n);if(n.start(l.length,0,{filename:`Processing ${P} files (${T} skipped)... `}),e=await(0,C.taskRunner)(l,e,t,n),t.options?.skip.audit||(console.log(`
2
+ Audit strings...`),(0,h.audit)(t,e)),t.options?.json)return(0,d.outputJson)(t,o,e);const k={charset:(0,a.getEncodingCharset)(t.options?.charset),headers:o,translations:e.toJson()},w=f.po.compile(k).toString((0,a.getCharset)(t.options?.charset));return`${t.options?.fileComment||(0,s.getCopyright)(t.headers?.name||t.slug,t.headers?.license??"GPL v2 or later")}
3
+ ${w}`}0&&(module.exports={exec});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/exec.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport { type GetTextTranslations, po } from \"gettext-parser\";\nimport { audit } from \"../extractors/auditStrings.js\";\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\nimport { getCharset, getEncodingCharset } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { getCopyright, outputPathRecap, printStats } from \"../utils/common.js\";\nimport { outputJson } from \"../utils/output\";\nimport { getPatterns } from \"./patterns.js\";\nimport { processFiles } from \"./process.js\";\nimport { initProgress } from \"./progress.js\";\nimport { taskRunner } from \"./taskRunner.js\";\n\n/**\n * Runs the parser and generates the pot file or the json file based on the command line arguments\n *\n * @param {Args} args - The command line arguments\n * @return {Promise<string>} - A promise that resolves with the generated pot file\n */\nexport async function exec(args: Args): Promise<string> {\n\tif (!args.options?.silent) {\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\n\t\tprintStats();\n\t}\n\n\t/** The pot file header contains the data about the plugin or theme */\n\tconst potHeader = await generateHeader(args);\n\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\n\tlet translationsUnion = translationsHeaders(args);\n\n\tif (!args.options?.silent)\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\n\n\t/**\n\t * The progress bar that is used to show the progress of the extraction process.\n\t */\n\tconst progressBar: SingleBar = initProgress(args, 0);\n\tprogressBar.start(3, 1, {\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\n\t});\n\n\t/**\n\t * Extract the strings from the files\n\t */\n\tconst patterns = getPatterns(args);\n\tconst files = await processFiles(patterns, args);\n\n\tprogressBar.update(2, {\n\t\tfilename: `Found ${files.length} files... `,\n\t});\n\n\ttranslationsUnion = await taskRunner(\n\t\tfiles,\n\t\ttranslationsUnion,\n\t\targs,\n\t\tprogressBar,\n\t);\n\n\t/**\n\t * Audit Strings: Strings are validated and reported to the user if they are not compliant.\n\t * --skip-audit flag turns this off\n\t **/\n\tif (!args.options?.skip.audit) {\n\t\tconsole.log(\"\\nAudit strings...\");\n\t\taudit(args, translationsUnion);\n\t}\n\n\t/** generate the json file based on the --json flag passed */\n\tif (args.options?.json) {\n\t\treturn outputJson(args, potHeader, translationsUnion);\n\t}\n\n\t/** Generate the pot file json */\n\tconst getTextTranslations: GetTextTranslations = {\n\t\tcharset: getEncodingCharset(args.options?.charset),\n\t\theaders: potHeader as { [headerName: string]: string },\n\t\ttranslations: translationsUnion.toJson(),\n\t};\n\n\t/** And then compile the pot file to a string */\n\tconst pluginTranslations = po\n\t\t.compile(getTextTranslations)\n\t\t.toString(getCharset(args.options?.charset));\n\n\t/** Return the pot file as a string, prefixed with the header */\n\tconst copyrightComment =\n\t\targs.options?.fileComment ||\n\t\tgetCopyright(\n\t\t\targs.headers?.name || args.slug,\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\n\t\t);\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,0BAAsB;AACtB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAA0D;AAC1D,oBAA2B;AAC3B,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAQ3B,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,uCAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AACnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,QAAQ,UAAM,6BAAa,UAAU,IAAI;AAE/C,cAAY,OAAO,GAAG;AAAA,IACrB,UAAU,SAAS,MAAM,MAAM;AAAA,EAChC,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAMA,MAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC9B,YAAQ,IAAI,oBAAoB;AAChC,mCAAM,MAAM,iBAAiB;AAAA,EAC9B;AAGA,MAAI,KAAK,SAAS,MAAM;AACvB,eAAO,0BAAW,MAAM,WAAW,iBAAiB;AAAA,EACrD;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK,SAAS,QAAQ,KAAK;AAAA,IAC1B,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
4
+ "sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport { type GetTextTranslations, po } from \"gettext-parser\";\r\nimport { audit } from \"../extractors/auditStrings.js\";\r\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\r\nimport { getCharset, getEncodingCharset } from \"../fs/fs.js\";\r\nimport type { Args } from \"../types.js\";\r\nimport { getCopyright, outputPathRecap, printStats } from \"../utils/common.js\";\r\nimport { outputJson } from \"../utils/output\";\r\nimport { getPatterns } from \"./patterns.js\";\r\nimport { processFiles } from \"./process.js\";\r\nimport { initProgress } from \"./progress.js\";\r\nimport { taskRunner } from \"./taskRunner.js\";\r\n\r\n/**\r\n * Runs the parser and generates the pot file or the json file based on the command line arguments\r\n *\r\n * @param {Args} args - The command line arguments\r\n * @return {Promise<string>} - A promise that resolves with the generated pot file\r\n */\r\nexport async function exec(args: Args): Promise<string> {\r\n\tif (!args.options?.silent) {\r\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\r\n\t\tprintStats();\r\n\t}\r\n\r\n\t/** The pot file header contains the data about the plugin or theme */\r\n\tconst potHeader = await generateHeader(args);\r\n\r\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\r\n\tlet translationsUnion = translationsHeaders(args);\r\n\r\n\tif (!args.options?.silent)\r\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\r\n\r\n\t/**\r\n\t * The progress bar that is used to show the progress of the extraction process.\r\n\t */\r\n\tconst progressBar: SingleBar = initProgress(args, 0);\r\n\tprogressBar.start(3, 1, {\r\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\r\n\t});\r\n\r\n\t/**\r\n\t * Extract the strings from the files\r\n\t */\r\n\tconst patterns = getPatterns(args);\r\n\tconst { tasks, processedCount, skippedCount } = await processFiles(patterns, args, progressBar);\r\n\r\n\tprogressBar.start(tasks.length, 0, {\r\n\t\tfilename: `Processing ${processedCount} files (${skippedCount} skipped)... `,\r\n\t});\r\n\r\n\ttranslationsUnion = await taskRunner(\r\n\t\ttasks,\r\n\t\ttranslationsUnion,\r\n\t\targs,\r\n\t\tprogressBar,\r\n\t);\r\n\r\n\t/**\r\n\t * Audit Strings: Strings are validated and reported to the user if they are not compliant.\r\n\t * --skip-audit flag turns this off\r\n\t **/\r\n\tif (!args.options?.skip.audit) {\r\n\t\tconsole.log(\"\\nAudit strings...\");\r\n\t\taudit(args, translationsUnion);\r\n\t}\r\n\r\n\t/** generate the JSON file based on the --json flag passed */\r\n\tif (args.options?.json) {\r\n\t\treturn outputJson(args, potHeader, translationsUnion);\r\n\t}\r\n\r\n\t/** Generate the pot file JSON */\r\n\tconst getTextTranslations: GetTextTranslations = {\r\n\t\tcharset: getEncodingCharset(args.options?.charset),\r\n\t\theaders: potHeader as { [headerName: string]: string },\r\n\t\ttranslations: translationsUnion.toJson(),\r\n\t};\r\n\r\n\t/** And then compile the pot file to a string */\r\n\tconst pluginTranslations = po\r\n\t\t.compile(getTextTranslations)\r\n\t\t.toString(getCharset(args.options?.charset));\r\n\r\n\t/** Return the pot file as a string, prefixed with the header */\r\n\tconst copyrightComment =\r\n\t\targs.options?.fileComment ||\r\n\t\tgetCopyright(\r\n\t\t\targs.headers?.name || args.slug,\r\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\r\n\t\t);\r\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,0BAAsB;AACtB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAA0D;AAC1D,oBAA2B;AAC3B,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAQ3B,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,uCAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AACnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,EAAE,OAAO,gBAAgB,aAAa,IAAI,UAAM,6BAAa,UAAU,MAAM,WAAW;AAE9F,cAAY,MAAM,MAAM,QAAQ,GAAG;AAAA,IAClC,UAAU,cAAc,cAAc,WAAW,YAAY;AAAA,EAC9D,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAMA,MAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC9B,YAAQ,IAAI,oBAAoB;AAChC,mCAAM,MAAM,iBAAiB;AAAA,EAC9B;AAGA,MAAI,KAAK,SAAS,MAAM;AACvB,eAAO,0BAAW,MAAM,WAAW,iBAAiB;AAAA,EACrD;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK,SAAS,QAAQ,KAAK;AAAA,IAC1B,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
6
6
  "names": ["path"]
7
7
  }
@@ -1 +1 @@
1
- "use strict";var P=Object.create;var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var D=(o,t)=>{for(var e in t)g(o,e,{get:t[e],enumerable:!0})},v=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of N(t))!$.call(o,i)&&i!==e&&g(o,i,{get:()=>t[i],enumerable:!(s=w(t,i))||s.enumerable});return o};var m=(o,t,e)=>(e=o!=null?P(M(o)):{},v(t||!o||!o.__esModule?g(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>v(g({},"__esModule",{value:!0}),o);var G={};D(G,{MakeJsonCommand:()=>F,default:()=>I});module.exports=C(G);var S=m(require("node:crypto")),c=m(require("node:fs")),a=m(require("node:path")),x=require("@babel/core"),k=require("gettext-parser"),h=require("glob"),d=require("../const.js"),J=require("../utils/common.js"),T=require("./tree");class F{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;stripUnused;constructor(t){if(this.sourceDir=a.default.relative(t.paths.cwd,t.source??""),!c.existsSync(this.sourceDir))throw console.error("Source directory not found",t),new Error(`Source directory ${this.sourceDir} not found`);this.stripUnused=t.stripUnused,this.scriptName=t.scriptName,this.source=t.source,this.destination=t.destination,this.allowedFormats=t.allowedFormats??[".ts",".tsx",".js",".jsx",".mjs",".cjs"],this.purge=t.purge,this.prettyPrint=t.prettyPrint,this.debug=t.debug,this.paths=t.paths}async exec(){const t=await(0,h.glob)("**/*.po",{cwd:this.destination,nodir:!0});console.log("Found po files",t,"in",this.destination,"folder");const e={};for(const s of t){this.scriptName||(this.scriptName=await(0,h.glob)("**/*.js",{cwd:this.source,nodir:!0}),console.log(`Found script: ${this.scriptName} in ${this.source} folder`)),typeof this.scriptName=="string"&&(this.scriptName=[this.scriptName]);for(const i of this.scriptName){const n=this.addPot(s,i);n.data?e[n.filename]=n.data:console.log(`\u274C Translation strings not found in Script ${i} in ${s} po file`)}}for(const[s,i]of Object.entries(e)){let n;if(this.purge)c.existsSync(a.default.join(this.destination,s))&&(console.log(`Removing ${a.default.join(this.destination,s)} as the purge option is enabled`),c.unlinkSync(a.default.join(this.destination,s))),n=JSON.stringify(i,null,this?.prettyPrint?2:0);else{const l=c.readFileSync(a.default.join(this.source,s),"utf8");n=JSON.stringify({...i,...JSON.parse(l)},null,this?.prettyPrint?2:0)}const r=a.default.join(this.destination,s);c.writeFileSync(r,n),console.log(`\u2705 JSON file written to ${r} with ${s}`)}return e}processFile(t,e,s="utf8"){const i=a.default.join(this.destination,t),n=c.readFileSync(i,s),r=this.parsePoFile(n);if(this.stripUnused){const l=this.parseScript(e);if(!l)return null;const p=this.compareStrings(l.blocks,r);if(!p)return null;r.translations=p.translations}return this.convertToJed(r.headers,r.translations,e,this.extractIsoCode(i))}parsePoFile(t){return k.po.parse(t)}convertToJed(t,e,s,i){const n=(0,J.getPkgJsonData)(d.modulePath,"name","version"),r="messages",l=`${n.name}/${n.version}`,p={[r]:{"":{domain:r,lang:i||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const u of Object.keys(e)){const y=e[u];for(const f of Object.keys(y)){const b=y[f];if(f==="")continue;const j=u&&u!==""?`${u}${f}`:f;p[r][j]=b.msgstr}}return{"translation-revision-date":new Date().toISOString(),generator:l,source:a.default.join(this.sourceDir,s).replace(/\\/g,"/"),domain:r,locale_data:p}}extractIsoCode(t){const e=t.match(d.IsoCodeRegex);return e?e[1]:void 0}md5(t){return S.default.createHash("md5").update(t).digest("hex")}generateFilename(t,e){const s=this.md5(t);return e.replace(".po",`-${s}.json`)}addPot(t,e){return{filename:this.generateFilename(a.default.join(this.source,e).replace(/\\/g,"/"),t),data:this.processFile(t,e)}}compareStrings(t,e){const s={charset:e.charset,headers:{...e.headers},translations:{"":{}}};e.translations[""][""]&&(s.translations[""][""]={...e.translations[""][""]});const i=new Set(t.map(n=>n.msgid));for(const n in e.translations)if(n==="")for(const r in e.translations[n])r!==""&&i.has(r)&&(s.translations[n]||(s.translations[n]={}),s.translations[n][r]={...e.translations[n][r]});return Object.keys(s.translations[""]).length<=1?null:s}parseScript(t){const e=c.readFileSync(a.default.join(this.source,t),"utf8"),s=(0,x.transformSync)(e,{configFile:!1,presets:["@babel/preset-env"],compact:!1,comments:!0,sourceMaps:!1,plugins:[({types:i})=>({visitor:{CallExpression(n){const r=n.node.callee;if(i.isSequenceExpression(r)&&i.isMemberExpression(r.expressions[1])){const l=r.expressions[1].property;i.isIdentifier(l)&&d.allowedFunctions.has(l.name)&&(n.node.callee=i.identifier(l.name))}}}})]}).code;return(0,T.doTree)(s,t,this.debug)}}var I=F;0&&(module.exports={MakeJsonCommand});
1
+ "use strict";var j=Object.create;var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var D=(o,t)=>{for(var e in t)g(o,e,{get:t[e],enumerable:!0})},x=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of M(t))!$.call(o,i)&&i!==e&&g(o,i,{get:()=>t[i],enumerable:!(s=w(t,i))||s.enumerable});return o};var h=(o,t,e)=>(e=o!=null?j(E(o)):{},x(t||!o||!o.__esModule?g(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>x(g({},"__esModule",{value:!0}),o);var I={};D(I,{MakeJsonCommand:()=>T,default:()=>B});module.exports=C(I);var v=h(require("node:crypto")),d=h(require("node:fs")),a=h(require("node:path")),S=require("@babel/core"),b=require("gettext-parser"),y=require("glob"),u=require("../const.js"),k=require("../utils/common.js"),J=require("./tree");class T{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;stripUnused;constructor(t){if(this.sourceDir=a.default.relative(t.paths.cwd,t.source??""),!d.existsSync(this.sourceDir))throw console.error("Source directory not found",t),new Error(`Source directory ${this.sourceDir} not found`);this.stripUnused=t.stripUnused,this.scriptName=t.scriptName,this.source=t.source,this.destination=t.destination,this.allowedFormats=t.allowedFormats??[".ts",".tsx",".js",".jsx",".mjs",".cjs"],this.purge=t.purge,this.prettyPrint=t.prettyPrint,this.debug=t.debug,this.paths=t.paths}async exec(){const t=await(0,y.glob)("**/*.po",{cwd:this.destination,nodir:!0});console.log("Found po files",t,"in",this.destination,"folder");const e={};for(const s of t){this.scriptName||(this.scriptName=await(0,y.glob)("**/*.js",{cwd:this.source,nodir:!0}),console.log(`Found script: ${this.scriptName} in ${this.source} folder`)),typeof this.scriptName=="string"&&(this.scriptName=[this.scriptName]);for(const i of this.scriptName){const n=this.addPot(s,i);n.data?e[n.filename]=n.data:console.log(`\u274C Translation strings not found in Script ${i} in ${s} po file`)}}for(const[s,i]of Object.entries(e)){let n;if(this.purge)d.existsSync(a.default.join(this.destination,s))&&(console.log(`Removing ${a.default.join(this.destination,s)} as the purge option is enabled`),d.unlinkSync(a.default.join(this.destination,s))),n=JSON.stringify(i,null,this?.prettyPrint?2:0);else{const c=d.readFileSync(a.default.join(this.source,s),"utf8");n=JSON.stringify({...i,...JSON.parse(c)},null,this?.prettyPrint?2:0)}const r=a.default.join(this.destination,s);d.writeFileSync(r,n),console.log(`\u2705 JSON file written to ${r} with ${s}`)}return e}processFile(t,e,s="utf8"){const i=a.default.join(this.destination,t),n=d.readFileSync(i,s),r=this.parsePoFile(n);if(this.stripUnused){const c=this.parseScript(e);if(!c)return null;const l=this.compareStrings(c.blocks,r);if(!l)return null;r.translations=l.translations}return this.convertToJed(r.headers,r.translations,e,this.extractIsoCode(i))}parsePoFile(t){return b.po.parse(t)}convertToJed(t,e,s,i){const n=(0,k.getPkgJsonData)(u.modulePath,"name","version"),r="messages",c=`${n.name}/${n.version}`,l={[r]:{"":{domain:r,lang:i||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const p of Object.keys(e)){const f=e[p];for(const m of Object.keys(f)){const F=f[m];if(m==="")continue;const N=p&&p!==""?`${p}${m}`:m;l[r][N]=F.msgstr}}return{"translation-revision-date":new Date().toISOString(),generator:c,source:a.default.join(this.sourceDir,s).replace(/\\/g,"/"),domain:r,locale_data:l}}extractIsoCode(t){const e=t.match(u.IsoCodeRegex);return e?e[1]:void 0}md5(t){return v.default.createHash("md5").update(t).digest("hex")}generateFilename(t,e){const s=this.md5(t);return e.replace(".po",`-${s}.json`)}addPot(t,e){return{filename:this.generateFilename(a.default.join(this.source,e).replace(/\\/g,"/"),t),data:this.processFile(t,e)}}compareStrings(t,e){const s={charset:e.charset,headers:{...e.headers},translations:{"":{}}};e.translations[""][""]&&(s.translations[""][""]={...e.translations[""][""]});const i=new Set(t.map(n=>n.msgid));for(const n in e.translations)if(n==="")for(const r in e.translations[n])r!==""&&i.has(r)&&(s.translations[n]||(s.translations[n]={}),s.translations[n][r]={...e.translations[n][r]});return Object.keys(s.translations[""]).length<=1?null:s}parseScript(t){const e=d.readFileSync(a.default.join(this.source,t),"utf8"),s=(0,S.transformSync)(e,{configFile:!1,presets:["@babel/preset-env"],compact:!1,comments:!0,sourceMaps:!1,plugins:[({types:i})=>({visitor:{CallExpression(n){const r=n.node.callee;if(i.isSequenceExpression(r)){const l=r.expressions[1];if(i.isMemberExpression(l)){const p=l.property;if(i.isIdentifier(p)){const f=p;u.allowedFunctions.has(f.name)&&(n.node.callee=i.identifier(f.name))}}}}}})]})?.code??"";return(0,J.doTree)(s,t,this.debug)}}var B=T;0&&(module.exports={MakeJsonCommand});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/makeJson.ts"],
4
- "sourcesContent": ["import crypto from \"node:crypto\";\r\nimport * as fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { transformSync } from \"@babel/core\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport {\r\n\ttype GetTextTranslation,\r\n\ttype GetTextTranslations,\r\n\tpo,\r\n} from \"gettext-parser\";\r\nimport { glob } from \"glob\";\r\nimport { IsoCodeRegex, allowedFunctions, modulePath } from \"../const.js\";\r\nimport type { JedData, MakeJson, MakeJsonArgs } from \"../types.js\";\r\nimport { getPkgJsonData } from \"../utils/common.js\";\r\nimport { doTree } from \"./tree\";\r\n\r\nexport class MakeJsonCommand {\r\n\t/**\r\n\t * The source file path.\r\n\t * Should be the \"build\" directory containing .js files\r\n\t * @private\r\n\t */\r\n\tprivate readonly source: string;\r\n\t/**\r\n\t * The destination file path.\r\n\t * Should be the \"languages\" directory containing .po files\r\n\t * @private\r\n\t */\r\n\tprivate readonly destination: string;\r\n\t/**\r\n\t * The allowed file extensions.\r\n\t * @private\r\n\t */\r\n\tprivate readonly allowedFormats: string[];\r\n\t/**\r\n\t * Remove old POT files.\r\n\t * @private\r\n\t */\r\n\tprivate readonly purge: boolean;\r\n\t/**\r\n\t * Pretty print JSON.\r\n\t * @private\r\n\t */\r\n\tprivate readonly prettyPrint: boolean;\r\n\t/**\r\n\t * Enable debug mode.\r\n\t * @private\r\n\t */\r\n\tprivate debug: boolean;\r\n\t/**\r\n\t * The script to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate scriptName: string | string[] | undefined;\r\n\t/**\r\n\t * The paths to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate paths: object | undefined;\r\n\t/**\r\n\t * The source directory.\r\n\t * @private\r\n\t */\r\n\tprivate readonly sourceDir: string;\r\n\t/**\r\n\t * Whenever to strip unused translations from js files\r\n\t * @private\r\n\t */\r\n\tprivate stripUnused: boolean;\r\n\r\n\t/**\r\n\t * The constructor.\r\n\t * @param args - The arguments to the command.\r\n\t */\r\n\tpublic constructor(args: MakeJsonArgs) {\r\n\t\tthis.sourceDir = path.relative(args.paths.cwd, args.source ?? \"\");\r\n\t\tif (!fs.existsSync(this.sourceDir)) {\r\n\t\t\tconsole.error(\"Source directory not found\", args);\r\n\t\t\tthrow new Error(`Source directory ${this.sourceDir} not found`);\r\n\t\t}\r\n\r\n\t\tthis.stripUnused = args.stripUnused;\r\n\t\tthis.scriptName = args.scriptName;\r\n\t\tthis.source = args.source;\r\n\t\tthis.destination = args.destination;\r\n\t\tthis.allowedFormats = args.allowedFormats ?? [\r\n\t\t\t\".ts\",\r\n\t\t\t\".tsx\",\r\n\t\t\t\".js\",\r\n\t\t\t\".jsx\",\r\n\t\t\t\".mjs\",\r\n\t\t\t\".cjs\",\r\n\t\t];\r\n\t\tthis.purge = args.purge;\r\n\t\tthis.prettyPrint = args.prettyPrint;\r\n\t\tthis.debug = args.debug;\r\n\t\tthis.paths = args.paths;\r\n\t}\r\n\r\n\t/**\r\n\t * The main function. Parses the PO files and generates the JSON files.\r\n\t */\r\n\tpublic async exec(): Promise<Record<string, MakeJson>> {\r\n\t\t// get all the files in the source directory\r\n\t\tconst files = await glob(\"**/*.po\", { cwd: this.destination, nodir: true });\r\n\r\n\t\tconsole.log(\"Found po files\", files, \"in\", this.destination, \"folder\");\r\n\r\n\t\t// get all the po files\r\n\t\tconst output: Record<string, MakeJson> = {};\r\n\t\tfor (const file of files) {\r\n\t\t\tif (!this.scriptName) {\r\n\t\t\t\tthis.scriptName = await glob(\"**/*.js\", {\r\n\t\t\t\t\tcwd: this.source,\r\n\t\t\t\t\tnodir: true,\r\n\t\t\t\t});\r\n\t\t\t\tconsole.log(\r\n\t\t\t\t\t`Found script: ${this.scriptName} in ${this.source} folder`,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof this.scriptName === \"string\") {\r\n\t\t\t\tthis.scriptName = [this.scriptName];\r\n\t\t\t}\r\n\r\n\t\t\tfor (const script of this.scriptName) {\r\n\t\t\t\tconst pot = this.addPot(file, script);\r\n\t\t\t\tif (pot.data) {\r\n\t\t\t\t\toutput[pot.filename] = pot.data;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`\u274C Translation strings not found in Script ${script} in ${file} po file`,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// write the json files\r\n\t\tfor (const [filename, content] of Object.entries(output)) {\r\n\t\t\tlet contentString: string;\r\n\t\t\tif (this.purge) {\r\n\t\t\t\tif (fs.existsSync(path.join(this.destination, filename))) {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`Removing ${path.join(this.destination, filename)} as the purge option is enabled`,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tfs.unlinkSync(path.join(this.destination, filename));\r\n\t\t\t\t}\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\tcontent,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tconst oldJedContent = fs.readFileSync(\r\n\t\t\t\t\tpath.join(this.source, filename),\r\n\t\t\t\t\t\"utf8\",\r\n\t\t\t\t);\r\n\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\t{ ...content, ...JSON.parse(oldJedContent) },\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst destinationPath = path.join(this.destination, filename);\r\n\t\t\tfs.writeFileSync(destinationPath, contentString);\r\n\t\t\tconsole.log(\r\n\t\t\t\t`\u2705 JSON file written to ${destinationPath} with ${filename}`,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\t// return the output\r\n\t\treturn output;\r\n\t}\r\n\r\n\t/**\r\n\t * Process a PO file and return the JSON data.\r\n\t * @param file - The path to the PO file.\r\n\t * @param script - The script to be translated.\r\n\t * @param encoding - The encoding of the PO file.\r\n\t */\r\n\tpublic processFile(\r\n\t\tfile: string,\r\n\t\tscript: string,\r\n\t\tencoding: BufferEncoding = \"utf8\",\r\n\t): MakeJson | null {\r\n\t\t// Get the file path\r\n\t\tconst filePath = path.join(this.destination, file);\r\n\r\n\t\t// Read the source file\r\n\t\tconst content = fs.readFileSync(filePath, encoding) as string;\r\n\r\n\t\t// Parse the source file\r\n\t\tconst poContent = this.parsePoFile(content);\r\n\r\n\t\tif (this.stripUnused) {\r\n\t\t\t// get the strings used in the script\r\n\t\t\tconst scriptContent = this.parseScript(script);\r\n\r\n\t\t\tif (!scriptContent) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// compare the strings used in the script with the strings in the po file\r\n\t\t\tconst stringsNotInPoFile = this.compareStrings(\r\n\t\t\t\tscriptContent.blocks,\r\n\t\t\t\tpoContent,\r\n\t\t\t);\r\n\r\n\t\t\tif (!stringsNotInPoFile) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// replace the po file strings with the strings used in the script\r\n\t\t\tpoContent.translations = stringsNotInPoFile.translations;\r\n\t\t}\r\n\r\n\t\t// Convert to Jed json dataset\r\n\t\treturn this.convertToJed(\r\n\t\t\tpoContent.headers,\r\n\t\t\tpoContent.translations,\r\n\t\t\tscript,\r\n\t\t\tthis.extractIsoCode(filePath), // extract the ISO code from the po filename\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a PO file and returns the header and translations.\r\n\t * @param content - The content of the PO file.\r\n\t * @private\r\n\t *\r\n\t * @returns An object containing the header and translations.\r\n\t */\r\n\tprivate parsePoFile(content: string): GetTextTranslations {\r\n\t\treturn po.parse(content);\r\n\t}\r\n\r\n\t/**\r\n\t * Converts PO data to Jed data.\r\n\t * @param header - The header of the PO file.\r\n\t * @param translations - The translations of the PO file.\r\n\t * @param source - The source of the PO file.\r\n\t * @param languageIsoCode - The ISO code of the language.\r\n\t * @private\r\n\t *\r\n\t * @return An object containing the Jed data.\r\n\t */\r\n\tprivate convertToJed(\r\n\t\theader: Record<string, string>,\r\n\t\ttranslations: {\r\n\t\t\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n\t\t},\r\n\t\tsource: string,\r\n\t\tlanguageIsoCode?: string,\r\n\t): MakeJson {\r\n\t\tconst packageJson = getPkgJsonData(modulePath, \"name\", \"version\") as {\r\n\t\t\tname: string;\r\n\t\t\tversion: string;\r\n\t\t};\r\n\r\n\t\t// Domain name to use for the Jed format\r\n\t\tconst domain: string = \"messages\";\r\n\r\n\t\tconst generator = `${packageJson.name}/${packageJson.version}`;\r\n\r\n\t\t// Initialize the Jed-compatible structure\r\n\t\tconst jedData: JedData = {\r\n\t\t\t[domain]: {\r\n\t\t\t\t\"\": {\r\n\t\t\t\t\tdomain,\r\n\t\t\t\t\tlang: languageIsoCode || header.Language || \"en\",\r\n\t\t\t\t\tplural_forms:\r\n\t\t\t\t\t\theader[\"Plural-Forms\"] || \"nplurals=2; plural=(n != 1);\",\r\n\t\t\t\t},\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\t// Process all translations\r\n\t\tfor (const msgctxt of Object.keys(translations)) {\r\n\t\t\tconst contextTranslations = translations[msgctxt];\r\n\r\n\t\t\tfor (const msgid of Object.keys(contextTranslations)) {\r\n\t\t\t\tconst translation = contextTranslations[msgid];\r\n\r\n\t\t\t\t// Skip empty msgid (header) as we've already handled it\r\n\t\t\t\tif (msgid === \"\") continue;\r\n\r\n\t\t\t\t// Construct the key using context if available\r\n\t\t\t\tconst key =\r\n\t\t\t\t\tmsgctxt && msgctxt !== \"\" ? `${msgctxt}\\u0004${msgid}` : msgid;\r\n\r\n\t\t\t\t// Add the translation to the Jed data structure\r\n\t\t\t\tjedData[domain][key] = translation.msgstr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst makeJson: {\r\n\t\t\tdomain: string;\r\n\t\t\tgenerator: string;\r\n\t\t\t\"translation-revision-date\": string;\r\n\t\t\tsource: string;\r\n\t\t\tlocale_data: JedData;\r\n\t\t} = {\r\n\t\t\t\"translation-revision-date\": new Date().toISOString(),\r\n\t\t\tgenerator: generator,\r\n\t\t\tsource: path.join(this.sourceDir, source).replace(/\\\\/g, \"/\"),\r\n\t\t\tdomain,\r\n\t\t\tlocale_data: jedData,\r\n\t\t};\r\n\r\n\t\treturn makeJson as MakeJson;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the ISO code from the filename.\r\n\t * @param filename The filename to extract the ISO code from.\r\n\t * @private\r\n\t *\r\n\t * @returns The ISO code if found, otherwise null.\r\n\t */\r\n\tprivate extractIsoCode(filename: string): string | undefined {\r\n\t\tconst match = filename.match(IsoCodeRegex);\r\n\t\treturn match ? match[1] : undefined;\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a string and returns its md5 hash.\r\n\t * @param text\r\n\t * @private\r\n\t */\r\n\tprivate md5(text: string): string {\r\n\t\treturn crypto.createHash(\"md5\").update(text).digest(\"hex\");\r\n\t}\r\n\r\n\t/**\r\n\t * Generates the filename for the json file.\r\n\t * @param script\r\n\t * @param file\r\n\t * @private\r\n\t */\r\n\tprivate generateFilename(script: string, file: string): string {\r\n\t\tconst scriptName = this.md5(script);\r\n\t\t//build the filename for the json file using the po files\r\n\t\treturn file.replace(\".po\", `-${scriptName}.json`);\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a script to the output object.\r\n\t * @private\r\n\t *\r\n\t * @param potFile - The pot file to parse.\r\n\t * @param script - The script to add.\r\n\t * @return {Record<string, JedData>} - The output object.\r\n\t * */\r\n\tprivate addPot(\r\n\t\tpotFile: string,\r\n\t\tscript: string,\r\n\t): { filename: string; data: MakeJson | null } {\r\n\t\tconst filename = this.generateFilename(\r\n\t\t\tpath.join(this.source, script).replace(/\\\\/g, \"/\"),\r\n\t\t\tpotFile,\r\n\t\t);\r\n\t\t// the processed file is added to the output object\r\n\t\treturn {\r\n\t\t\tfilename,\r\n\t\t\tdata: this.processFile(potFile, script),\r\n\t\t};\r\n\t}\r\n\r\n\t/**\r\n\t * Compares the strings used in the script with the strings in the po file.\r\n\t * @param jsArray - The strings used in the script.\r\n\t * @param poObject - The content of the po file.\r\n\t * @private\r\n\t */\r\n\tprivate compareStrings(\r\n\t\tjsArray: SetOfBlocks[\"blocks\"],\r\n\t\tpoObject: GetTextTranslations,\r\n\t): GetTextTranslations | null {\r\n\t\t// The copy of the po file with only the strings used in the script\r\n\t\tconst filteredPo = {\r\n\t\t\tcharset: poObject.charset,\r\n\t\t\theaders: { ...poObject.headers },\r\n\t\t\ttranslations: { \"\": {} },\r\n\t\t} as GetTextTranslations;\r\n\r\n\t\t// copy the original header\r\n\t\tif (poObject.translations[\"\"][\"\"]) {\r\n\t\t\tfilteredPo.translations[\"\"][\"\"] = { ...poObject.translations[\"\"][\"\"] };\r\n\t\t}\r\n\r\n\t\t// Create a set of message ids from the JS file\r\n\t\tconst jsMessageIds = new Set(jsArray.map((item) => item.msgid));\r\n\r\n\t\t// Iterate over the po file and keep only the strings used in the script\r\n\t\tfor (const domain in poObject.translations) {\r\n\t\t\tif (domain !== \"\") continue; // handle only the main domain\r\n\r\n\t\t\tfor (const msgid in poObject.translations[domain]) {\r\n\t\t\t\tif (msgid === \"\") continue; // Skip the header\r\n\r\n\t\t\t\tif (jsMessageIds.has(msgid)) {\r\n\t\t\t\t\t// ok the msgid is used\r\n\t\t\t\t\tif (!filteredPo.translations[domain]) {\r\n\t\t\t\t\t\tfilteredPo.translations[domain] = {};\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfilteredPo.translations[domain][msgid] = {\r\n\t\t\t\t\t\t...poObject.translations[domain][msgid],\r\n\t\t\t\t\t};\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// check if the po file is empty, 1 means that the header is the only string available\r\n\t\t// TODO: if the json file is empty, we should delete it?\r\n\t\tif (Object.keys(filteredPo.translations[\"\"]).length <= 1) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\treturn filteredPo;\r\n\t}\r\n\r\n\tprivate parseScript(script: string): SetOfBlocks | undefined {\r\n\t\tconst fileContent = fs.readFileSync(path.join(this.source, script), \"utf8\");\r\n\t\tconst transformedScript = transformSync(fileContent, {\r\n\t\t\tconfigFile: false,\r\n\t\t\tpresets: [\"@babel/preset-env\"],\r\n\t\t\tcompact: false,\r\n\t\t\tcomments: true,\r\n\t\t\tsourceMaps: false,\r\n\t\t\tplugins: [\r\n\t\t\t\t({ types: t }) => ({\r\n\t\t\t\t\tvisitor: {\r\n\t\t\t\t\t\tCallExpression(path) {\r\n\t\t\t\t\t\t\tconst callee = path.node.callee;\r\n\r\n\t\t\t\t\t\t\t// Check for pattern like: (fn)(\"...\")\r\n\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\tt.isSequenceExpression(callee) &&\r\n\t\t\t\t\t\t\t\tt.isMemberExpression(callee.expressions[1])\r\n\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\tconst property = callee.expressions[1].property;\r\n\r\n\t\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\t\tt.isIdentifier(property) &&\r\n\t\t\t\t\t\t\t\t\tallowedFunctions.has(property.name)\r\n\t\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\t\t// Replace with direct function call: __(\"...\"), _n(...), etc.\r\n\t\t\t\t\t\t\t\t\tpath.node.callee = t.identifier(property.name);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t},\r\n\t\t\t\t\t},\r\n\t\t\t\t}),\r\n\t\t\t],\r\n\t\t}).code as string;\r\n\r\n\t\treturn doTree(transformedScript, script, this.debug);\r\n\t}\r\n}\r\n\r\nexport default MakeJsonCommand;\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AACnB,SAAoB;AACpB,uBAAiB;AACjB,kBAA8B;AAE9B,4BAIO;AACP,kBAAqB;AACrB,mBAA2D;AAE3D,oBAA+B;AAC/B,kBAAuB;AAEhB,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKT;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMD,YAAY,MAAoB;AACtC,SAAK,YAAY,iBAAAA,QAAK,SAAS,KAAK,MAAM,KAAK,KAAK,UAAU,EAAE;AAChE,QAAI,CAAC,GAAG,WAAW,KAAK,SAAS,GAAG;AACnC,cAAQ,MAAM,8BAA8B,IAAI;AAChD,YAAM,IAAI,MAAM,oBAAoB,KAAK,SAAS,YAAY;AAAA,IAC/D;AAEA,SAAK,cAAc,KAAK;AACxB,SAAK,aAAa,KAAK;AACvB,SAAK,SAAS,KAAK;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B,cAAI,CAAC,WAAW,aAAa,MAAM,GAAG;AACrC,uBAAW,aAAa,MAAM,IAAI,CAAC;AAAA,UACpC;AACA,qBAAW,aAAa,MAAM,EAAE,KAAK,IAAI;AAAA,YACxC,GAAG,SAAS,aAAa,MAAM,EAAE,KAAK;AAAA,UACvC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAIA,QAAI,OAAO,KAAK,WAAW,aAAa,EAAE,CAAC,EAAE,UAAU,GAAG;AACzD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,YAAY,QAAyC;AAC5D,UAAM,cAAc,GAAG,aAAa,iBAAAA,QAAK,KAAK,KAAK,QAAQ,MAAM,GAAG,MAAM;AAC1E,UAAM,wBAAoB,2BAAc,aAAa;AAAA,MACpD,YAAY;AAAA,MACZ,SAAS,CAAC,mBAAmB;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,SAAS;AAAA,QACR,CAAC,EAAE,OAAO,EAAE,OAAO;AAAA,UAClB,SAAS;AAAA,YACR,eAAeA,OAAM;AACpB,oBAAM,SAASA,MAAK,KAAK;AAGzB,kBACC,EAAE,qBAAqB,MAAM,KAC7B,EAAE,mBAAmB,OAAO,YAAY,CAAC,CAAC,GACzC;AACD,sBAAM,WAAW,OAAO,YAAY,CAAC,EAAE;AAEvC,oBACC,EAAE,aAAa,QAAQ,KACvB,8BAAiB,IAAI,SAAS,IAAI,GACjC;AAED,kBAAAA,MAAK,KAAK,SAAS,EAAE,WAAW,SAAS,IAAI;AAAA,gBAC9C;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC,EAAE;AAEH,eAAO,oBAAO,mBAAmB,QAAQ,KAAK,KAAK;AAAA,EACpD;AACD;AAEA,IAAO,mBAAQ;",
4
+ "sourcesContent": ["import crypto from \"node:crypto\";\r\nimport * as fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { type NodePath, transformSync, type types as BabelTypes } from \"@babel/core\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport {\r\n\ttype GetTextTranslation,\r\n\ttype GetTextTranslations,\r\n\tpo,\r\n} from \"gettext-parser\";\r\nimport { glob } from \"glob\";\r\nimport { IsoCodeRegex, allowedFunctions, modulePath } from \"../const.js\";\r\nimport type { JedData, MakeJson, MakeJsonArgs } from \"../types.js\";\r\nimport { getPkgJsonData } from \"../utils/common.js\";\r\nimport { doTree } from \"./tree\";\r\n\r\nexport class MakeJsonCommand {\r\n\t/**\r\n\t * The source file path.\r\n\t * Should be the \"build\" directory containing .js files\r\n\t * @private\r\n\t */\r\n\tprivate readonly source: string;\r\n\t/**\r\n\t * The destination file path.\r\n\t * Should be the \"languages\" directory containing .po files\r\n\t * @private\r\n\t */\r\n\tprivate readonly destination: string;\r\n\t/**\r\n\t * The allowed file extensions.\r\n\t * @private\r\n\t */\r\n\tprivate readonly allowedFormats: string[];\r\n\t/**\r\n\t * Remove old POT files.\r\n\t * @private\r\n\t */\r\n\tprivate readonly purge: boolean;\r\n\t/**\r\n\t * Pretty print JSON.\r\n\t * @private\r\n\t */\r\n\tprivate readonly prettyPrint: boolean;\r\n\t/**\r\n\t * Enable debug mode.\r\n\t * @private\r\n\t */\r\n\tprivate debug: boolean;\r\n\t/**\r\n\t * The script to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate scriptName: string | string[] | undefined;\r\n\t/**\r\n\t * The paths to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate paths: object | undefined;\r\n\t/**\r\n\t * The source directory.\r\n\t * @private\r\n\t */\r\n\tprivate readonly sourceDir: string;\r\n\t/**\r\n\t * Whenever to strip unused translations from js files\r\n\t * @private\r\n\t */\r\n\tprivate stripUnused: boolean;\r\n\r\n\t/**\r\n\t * The constructor.\r\n\t * @param args - The arguments to the command.\r\n\t */\r\n\tpublic constructor(args: MakeJsonArgs) {\r\n\t\tthis.sourceDir = path.relative(args.paths.cwd, args.source ?? \"\");\r\n\t\tif (!fs.existsSync(this.sourceDir)) {\r\n\t\t\tconsole.error(\"Source directory not found\", args);\r\n\t\t\tthrow new Error(`Source directory ${this.sourceDir} not found`);\r\n\t\t}\r\n\r\n\t\tthis.stripUnused = args.stripUnused;\r\n\t\tthis.scriptName = args.scriptName;\r\n\t\tthis.source = args.source;\r\n\t\tthis.destination = args.destination;\r\n\t\tthis.allowedFormats = args.allowedFormats ?? [\r\n\t\t\t\".ts\",\r\n\t\t\t\".tsx\",\r\n\t\t\t\".js\",\r\n\t\t\t\".jsx\",\r\n\t\t\t\".mjs\",\r\n\t\t\t\".cjs\",\r\n\t\t];\r\n\t\tthis.purge = args.purge;\r\n\t\tthis.prettyPrint = args.prettyPrint;\r\n\t\tthis.debug = args.debug;\r\n\t\tthis.paths = args.paths;\r\n\t}\r\n\r\n\t/**\r\n\t * The main function. Parses the PO files and generates the JSON files.\r\n\t */\r\n\tpublic async exec(): Promise<Record<string, MakeJson>> {\r\n\t\t// get all the files in the source directory\r\n\t\tconst files = await glob(\"**/*.po\", { cwd: this.destination, nodir: true });\r\n\r\n\t\tconsole.log(\"Found po files\", files, \"in\", this.destination, \"folder\");\r\n\r\n\t\t// get all the po files\r\n\t\tconst output: Record<string, MakeJson> = {};\r\n\t\tfor (const file of files) {\r\n\t\t\tif (!this.scriptName) {\r\n\t\t\t\tthis.scriptName = await glob(\"**/*.js\", {\r\n\t\t\t\t\tcwd: this.source,\r\n\t\t\t\t\tnodir: true,\r\n\t\t\t\t});\r\n\t\t\t\tconsole.log(\r\n\t\t\t\t\t`Found script: ${this.scriptName} in ${this.source} folder`,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof this.scriptName === \"string\") {\r\n\t\t\t\tthis.scriptName = [this.scriptName];\r\n\t\t\t}\r\n\r\n\t\t\tfor (const script of this.scriptName) {\r\n\t\t\t\tconst pot = this.addPot(file, script);\r\n\t\t\t\tif (pot.data) {\r\n\t\t\t\t\toutput[pot.filename] = pot.data;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`\u274C Translation strings not found in Script ${script} in ${file} po file`,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// write the json files\r\n\t\tfor (const [filename, content] of Object.entries(output)) {\r\n\t\t\tlet contentString: string;\r\n\t\t\tif (this.purge) {\r\n\t\t\t\tif (fs.existsSync(path.join(this.destination, filename))) {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`Removing ${path.join(this.destination, filename)} as the purge option is enabled`,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tfs.unlinkSync(path.join(this.destination, filename));\r\n\t\t\t\t}\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\tcontent,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tconst oldJedContent = fs.readFileSync(\r\n\t\t\t\t\tpath.join(this.source, filename),\r\n\t\t\t\t\t\"utf8\",\r\n\t\t\t\t);\r\n\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\t{ ...content, ...JSON.parse(oldJedContent) },\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst destinationPath = path.join(this.destination, filename);\r\n\t\t\tfs.writeFileSync(destinationPath, contentString);\r\n\t\t\tconsole.log(\r\n\t\t\t\t`\u2705 JSON file written to ${destinationPath} with ${filename}`,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\t// return the output\r\n\t\treturn output;\r\n\t}\r\n\r\n\t/**\r\n\t * Process a PO file and return the JSON data.\r\n\t * @param file - The path to the PO file.\r\n\t * @param script - The script to be translated.\r\n\t * @param encoding - The encoding of the PO file.\r\n\t */\r\n\tpublic processFile(\r\n\t\tfile: string,\r\n\t\tscript: string,\r\n\t\tencoding: BufferEncoding = \"utf8\",\r\n\t): MakeJson | null {\r\n\t\t// Get the file path\r\n\t\tconst filePath = path.join(this.destination, file);\r\n\r\n\t\t// Read the source file\r\n\t\tconst content = fs.readFileSync(filePath, encoding) as string;\r\n\r\n\t\t// Parse the source file\r\n\t\tconst poContent = this.parsePoFile(content);\r\n\r\n\t\tif (this.stripUnused) {\r\n\t\t\t// get the strings used in the script\r\n\t\t\tconst scriptContent = this.parseScript(script);\r\n\r\n\t\t\tif (!scriptContent) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// compare the strings used in the script with the strings in the po file\r\n\t\t\tconst stringsNotInPoFile = this.compareStrings(\r\n\t\t\t\tscriptContent.blocks,\r\n\t\t\t\tpoContent,\r\n\t\t\t);\r\n\r\n\t\t\tif (!stringsNotInPoFile) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// replace the po file strings with the strings used in the script\r\n\t\t\tpoContent.translations = stringsNotInPoFile.translations;\r\n\t\t}\r\n\r\n\t\t// Convert to Jed json dataset\r\n\t\treturn this.convertToJed(\r\n\t\t\tpoContent.headers,\r\n\t\t\tpoContent.translations,\r\n\t\t\tscript,\r\n\t\t\tthis.extractIsoCode(filePath), // extract the ISO code from the po filename\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a PO file and returns the header and translations.\r\n\t * @param content - The content of the PO file.\r\n\t * @private\r\n\t *\r\n\t * @returns An object containing the header and translations.\r\n\t */\r\n\tprivate parsePoFile(content: string): GetTextTranslations {\r\n\t\treturn po.parse(content);\r\n\t}\r\n\r\n\t/**\r\n\t * Converts PO data to Jed data.\r\n\t * @param header - The header of the PO file.\r\n\t * @param translations - The translations of the PO file.\r\n\t * @param source - The source of the PO file.\r\n\t * @param languageIsoCode - The ISO code of the language.\r\n\t * @private\r\n\t *\r\n\t * @return An object containing the Jed data.\r\n\t */\r\n\tprivate convertToJed(\r\n\t\theader: Record<string, string>,\r\n\t\ttranslations: {\r\n\t\t\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n\t\t},\r\n\t\tsource: string,\r\n\t\tlanguageIsoCode?: string,\r\n\t): MakeJson {\r\n\t\tconst packageJson = getPkgJsonData(modulePath, \"name\", \"version\") as {\r\n\t\t\tname: string;\r\n\t\t\tversion: string;\r\n\t\t};\r\n\r\n\t\t// Domain name to use for the Jed format\r\n\t\tconst domain: string = \"messages\";\r\n\r\n\t\tconst generator = `${packageJson.name}/${packageJson.version}`;\r\n\r\n\t\t// Initialize the Jed-compatible structure\r\n\t\tconst jedData: JedData = {\r\n\t\t\t[domain]: {\r\n\t\t\t\t\"\": {\r\n\t\t\t\t\tdomain,\r\n\t\t\t\t\tlang: languageIsoCode || header.Language || \"en\",\r\n\t\t\t\t\tplural_forms:\r\n\t\t\t\t\t\theader[\"Plural-Forms\"] || \"nplurals=2; plural=(n != 1);\",\r\n\t\t\t\t},\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\t// Process all translations\r\n\t\tfor (const msgctxt of Object.keys(translations)) {\r\n\t\t\tconst contextTranslations = translations[msgctxt];\r\n\r\n\t\t\tfor (const msgid of Object.keys(contextTranslations)) {\r\n\t\t\t\tconst translation = contextTranslations[msgid];\r\n\r\n\t\t\t\t// Skip empty msgid (header) as we've already handled it\r\n\t\t\t\tif (msgid === \"\") continue;\r\n\r\n\t\t\t\t// Construct the key using context if available\r\n\t\t\t\tconst key =\r\n\t\t\t\t\tmsgctxt && msgctxt !== \"\" ? `${msgctxt}\\u0004${msgid}` : msgid;\r\n\r\n\t\t\t\t// Add the translation to the Jed data structure\r\n\t\t\t\tjedData[domain][key] = translation.msgstr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst makeJson: {\r\n\t\t\tdomain: string;\r\n\t\t\tgenerator: string;\r\n\t\t\t\"translation-revision-date\": string;\r\n\t\t\tsource: string;\r\n\t\t\tlocale_data: JedData;\r\n\t\t} = {\r\n\t\t\t\"translation-revision-date\": new Date().toISOString(),\r\n\t\t\tgenerator: generator,\r\n\t\t\tsource: path.join(this.sourceDir, source).replace(/\\\\/g, \"/\"),\r\n\t\t\tdomain,\r\n\t\t\tlocale_data: jedData,\r\n\t\t};\r\n\r\n\t\treturn makeJson as MakeJson;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the ISO code from the filename.\r\n\t * @param filename The filename to extract the ISO code from.\r\n\t * @private\r\n\t *\r\n\t * @returns The ISO code if found, otherwise null.\r\n\t */\r\n\tprivate extractIsoCode(filename: string): string | undefined {\r\n\t\tconst match = filename.match(IsoCodeRegex);\r\n\t\treturn match ? match[1] : undefined;\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a string and returns its md5 hash.\r\n\t * @param text\r\n\t * @private\r\n\t */\r\n\tprivate md5(text: string): string {\r\n\t\treturn crypto.createHash(\"md5\").update(text).digest(\"hex\");\r\n\t}\r\n\r\n\t/**\r\n\t * Generates the filename for the json file.\r\n\t * @param script\r\n\t * @param file\r\n\t * @private\r\n\t */\r\n\tprivate generateFilename(script: string, file: string): string {\r\n\t\tconst scriptName = this.md5(script);\r\n\t\t//build the filename for the json file using the po files\r\n\t\treturn file.replace(\".po\", `-${scriptName}.json`);\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a script to the output object.\r\n\t * @private\r\n\t *\r\n\t * @param potFile - The pot file to parse.\r\n\t * @param script - The script to add.\r\n\t * @return {Record<string, JedData>} - The output object.\r\n\t * */\r\n\tprivate addPot(\r\n\t\tpotFile: string,\r\n\t\tscript: string,\r\n\t): { filename: string; data: MakeJson | null } {\r\n\t\tconst filename = this.generateFilename(\r\n\t\t\tpath.join(this.source, script).replace(/\\\\/g, \"/\"),\r\n\t\t\tpotFile,\r\n\t\t);\r\n\t\t// the processed file is added to the output object\r\n\t\treturn {\r\n\t\t\tfilename,\r\n\t\t\tdata: this.processFile(potFile, script),\r\n\t\t};\r\n\t}\r\n\r\n\t/**\r\n\t * Compares the strings used in the script with the strings in the po file.\r\n\t * @param jsArray - The strings used in the script.\r\n\t * @param poObject - The content of the po file.\r\n\t * @private\r\n\t */\r\n\tprivate compareStrings(\r\n\t\tjsArray: SetOfBlocks[\"blocks\"],\r\n\t\tpoObject: GetTextTranslations,\r\n\t): GetTextTranslations | null {\r\n\t\t// The copy of the po file with only the strings used in the script\r\n\t\tconst filteredPo = {\r\n\t\t\tcharset: poObject.charset,\r\n\t\t\theaders: { ...poObject.headers },\r\n\t\t\ttranslations: { \"\": {} },\r\n\t\t} as GetTextTranslations;\r\n\r\n\t\t// copy the original header\r\n\t\tif (poObject.translations[\"\"][\"\"]) {\r\n\t\t\tfilteredPo.translations[\"\"][\"\"] = { ...poObject.translations[\"\"][\"\"] };\r\n\t\t}\r\n\r\n\t\t// Create a set of message ids from the JS file\r\n\t\tconst jsMessageIds = new Set(jsArray.map((item) => item.msgid));\r\n\r\n\t\t// Iterate over the po file and keep only the strings used in the script\r\n\t\tfor (const domain in poObject.translations) {\r\n\t\t\tif (domain !== \"\") continue; // handle only the main domain\r\n\r\n\t\t\tfor (const msgid in poObject.translations[domain]) {\r\n\t\t\t\tif (msgid === \"\") continue; // Skip the header\r\n\r\n\t\t\t\tif (jsMessageIds.has(msgid)) {\r\n\t\t\t\t\t// ok the msgid is used\r\n\t\t\t\t\tif (!filteredPo.translations[domain]) {\r\n\t\t\t\t\t\tfilteredPo.translations[domain] = {};\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfilteredPo.translations[domain][msgid] = {\r\n\t\t\t\t\t\t...poObject.translations[domain][msgid],\r\n\t\t\t\t\t};\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// check if the po file is empty, 1 means that the header is the only string available\r\n\t\t// TODO: if the json file is empty, we should delete it?\r\n\t\tif (Object.keys(filteredPo.translations[\"\"]).length <= 1) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\treturn filteredPo;\r\n\t}\r\n\r\n\tprivate parseScript(script: string): SetOfBlocks | undefined {\r\n\t\tconst fileContent = fs.readFileSync(path.join(this.source, script), \"utf8\");\r\n\t\tconst transformedScript = transformSync(fileContent, {\r\n\t\t\tconfigFile: false,\r\n\t\t\tpresets: [\"@babel/preset-env\"],\r\n\t\t\tcompact: false,\r\n\t\t\tcomments: true,\r\n\t\t\tsourceMaps: false,\r\n\t\t\tplugins: [\r\n\t\t\t\t({ types: t }) => ({\r\n\t\t\t\t\tvisitor: {\r\n\t\t\t\t\t\tCallExpression(path: NodePath<BabelTypes.CallExpression>) {\r\n\t\t\t\t\t\t\tconst callee = path.node.callee;\r\n\r\n\t\t\t\t\t\t\t// Check for pattern like: (fn)(\"...\")\r\n\t\t\t\t\t\t\tif (t.isSequenceExpression(callee)) {\r\n\t\t\t\t\t\t\t\tconst seqExpr = callee as BabelTypes.SequenceExpression;\r\n\t\t\t\t\t\t\t\tconst secondExpression = seqExpr.expressions[1];\r\n\r\n\t\t\t\t\t\t\t\tif (t.isMemberExpression(secondExpression)) {\r\n\t\t\t\t\t\t\t\t\tconst memberExpr = secondExpression as BabelTypes.MemberExpression;\r\n\t\t\t\t\t\t\t\t\tconst property = memberExpr.property;\r\n\r\n\t\t\t\t\t\t\t\t\tif (t.isIdentifier(property)) {\r\n\t\t\t\t\t\t\t\t\t\t// Cast to Identifier\r\n\t\t\t\t\t\t\t\t\t\tconst identifier = property as BabelTypes.Identifier;\r\n\r\n\t\t\t\t\t\t\t\t\t\tif (allowedFunctions.has(identifier.name)) {\r\n\t\t\t\t\t\t\t\t\t\t\t// Replace with direct function call: __(\"...\"), _n(...), etc.\r\n\t\t\t\t\t\t\t\t\t\t\tpath.node.callee = t.identifier(identifier.name);\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t},\r\n\t\t\t\t\t},\r\n\t\t\t\t}),\r\n\t\t\t],\r\n\t\t})?.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AAA,QACD;AAAA,MACD;AAAA,IACD;AAIA,QAAI,OAAO,KAAK,WAAW,aAAa,EAAE,CAAC,EAAE,UAAU,GAAG;AACzD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,YAAY,QAAyC;AAC5D,UAAM,cAAc,GAAG,aAAa,iBAAAA,QAAK,KAAK,KAAK,QAAQ,MAAM,GAAG,MAAM;AAC1E,UAAM,wBAAoB,2BAAc,aAAa;AAAA,MACpD,YAAY;AAAA,MACZ,SAAS,CAAC,mBAAmB;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,SAAS;AAAA,QACR,CAAC,EAAE,OAAO,EAAE,OAAO;AAAA,UAClB,SAAS;AAAA,YACR,eAAeA,OAA2C;AACzD,oBAAM,SAASA,MAAK,KAAK;AAGzB,kBAAI,EAAE,qBAAqB,MAAM,GAAG;AACnC,sBAAM,UAAU;AAChB,sBAAM,mBAAmB,QAAQ,YAAY,CAAC;AAE9C,oBAAI,EAAE,mBAAmB,gBAAgB,GAAG;AAC3C,wBAAM,aAAa;AACnB,wBAAM,WAAW,WAAW;AAE5B,sBAAI,EAAE,aAAa,QAAQ,GAAG;AAE7B,0BAAM,aAAa;AAEnB,wBAAI,8BAAiB,IAAI,WAAW,IAAI,GAAG;AAE1C,sBAAAA,MAAK,KAAK,SAAS,EAAE,WAAW,WAAW,IAAI;AAAA,oBAChD;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC,GAAG,QAAQ;AAEZ,eAAO,oBAAO,mBAAmB,QAAQ,KAAK,KAAK;AAAA,EACpD;AACD;AAEA,IAAO,mBAAQ;",
6
6
  "names": ["path", "crypto"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/makePot.ts"],
4
- "sourcesContent": ["import { extractMainFileData } from \"../extractors/headers.js\";\nimport { extractPackageJson } from \"../extractors/packageJson.js\";\nimport { writeFile } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { exec } from \"./exec.js\";\n\n/**\n * Generates a pot file for localization.\n *\n * @param args - the command line arguments\n * @return {string} - a promise that resolves when the pot file is generated\n */\nexport async function makePot(args: Args): Promise<string> {\n\t/** Collect metadata from the get package json */\n\tconst pkgData = extractPackageJson(args);\n\n\t/** Get metadata from the main file (theme and plugin) */\n\tconst metadata = extractMainFileData(args);\n\n\t/** Merge the metadata to get a single object with all the headers */\n\targs.headers = {\n\t\t...args?.options?.headers,\n\t\t...pkgData,\n\t\t...metadata,\n\t} as Args[\"headers\"];\n\n\t/** Generate the pot file */\n\treturn await exec(args)\n\t\t.then((jsonTranslations) => {\n\t\t\twriteFile(jsonTranslations, args);\n\n\t\t\treturn jsonTranslations;\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\n\t\t\treturn \"\";\n\t\t});\n}\n"],
4
+ "sourcesContent": ["import { extractMainFileData } from \"../extractors/headers.js\";\nimport { extractPackageJson } from \"../extractors/packageJson.js\";\nimport { writeFile } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { exec } from \"./exec.js\";\n\n/**\n * Generates a pot file for localization.\n *\n * @param args - the command line arguments\n * @return {string} - a promise that resolves when the pot file is generated\n */\nexport async function makePot(args: Args): Promise<string> {\n\t/** Collect metadata from the get-go package JSON */\n\tconst pkgData = extractPackageJson(args);\n\n\t/** Get metadata from the main file (theme and plugin) */\n\tconst metadata = extractMainFileData(args);\n\n\t/** Merge the metadata to get a single object with all the headers */\n\targs.headers = {\n\t\t...args?.options?.headers,\n\t\t...pkgData,\n\t\t...metadata,\n\t} as Args[\"headers\"];\n\n\t/** Generate the pot file */\n\treturn await exec(args)\n\t\t.then((jsonTranslations) => {\n\t\t\twriteFile(jsonTranslations, args);\n\n\t\t\treturn jsonTranslations;\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\n\t\t\treturn \"\";\n\t\t});\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AACpC,yBAAmC;AACnC,gBAA0B;AAE1B,kBAAqB;AAQrB,eAAsB,QAAQ,MAA6B;AAE1D,QAAM,cAAU,uCAAmB,IAAI;AAGvC,QAAM,eAAW,oCAAoB,IAAI;AAGzC,OAAK,UAAU;AAAA,IACd,GAAG,MAAM,SAAS;AAAA,IAClB,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AAGA,SAAO,UAAM,kBAAK,IAAI,EACpB,KAAK,CAAC,qBAAqB;AAC3B,6BAAU,kBAAkB,IAAI;AAEhC,WAAO;AAAA,EACR,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,YAAQ,MAAM,KAAK;AAEnB,WAAO;AAAA,EACR,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- "use strict";var F=Object.create;var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)f(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!w.call(t,s)&&s!==o&&f(t,s,{get:()=>e[s],enumerable:!(i=O(e,s))||i.enumerable});return t};var v=(t,e,o)=>(o=t!=null?F(j(t)):{},d(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),A=t=>d(f({},"__esModule",{value:!0}),t);var g={};x(g,{processFiles:()=>T});module.exports=A(g);var r=v(require("node:path")),u=require("../const.js"),h=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),P=require("./tree.js");async function T(t,e,o){const i=[];let s=0;const c=(0,k.getFiles)(e,t);o&&(o.setTotal(Object.values(c).length),o.update(0,{filename:`Found ${Object.values(c).length} files`}));for await(const l of c){s++;const n=r.default.basename(l),b=r.default.extname(l).replace(/^./,""),p=r.default.resolve(e.paths.cwd,l);if(n==="theme.json"||n==="block.json")i.push((0,a.readFileAsync)(p).then(m=>(0,h.parseJsonCallback)(m,e.paths.cwd,n)));else if(u.allowedFormats.includes(b)){const m=(0,a.readFileAsync)(p).then(y=>(0,P.doTree)(y,l,e.debug,e));m&&i.push(m)}o&&(o.update(s,{filename:n}),o.render())}return i}0&&(module.exports={processFiles});
1
+ "use strict";var x=Object.create;var f=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var o in e)f(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!O.call(t,s)&&s!==o&&f(t,s,{get:()=>e[s],enumerable:!(i=C(e,s))||i.enumerable});return t};var g=(t,e,o)=>(o=t!=null?x(w(t)):{},d(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),j=t=>d(f({},"__esModule",{value:!0}),t);var R={};$(R,{processFiles:()=>A});module.exports=j(R);var r=g(require("node:path")),h=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),P=require("./tree.js"),b=require("../const");async function A(t,e,o){const i=[];let s=0,l=0;const p=await(0,k.getFiles)(e,t);o&&(o.setTotal(p.length),o.update(0,{filename:`Found ${p.length} files`}));for(const n of p){const c=r.default.basename(n),S=r.default.extname(n).replace(/^./,""),u=r.default.resolve(e.paths.cwd,n);if(c==="theme.json"||c==="block.json")s++,i.push((0,a.readFileAsync)(u).then(m=>(0,h.parseJsonCallback)(m,e.paths.cwd,c)));else if(b.allowedFormats.includes(S)){s++;const m=(0,a.readFileAsync)(u).then(y=>(0,P.doTree)(y,n,e.debug,e));m&&i.push(m)}else l++;o&&o.update(s+l,{filename:`${r.default.basename(n)} (Processed: ${s} | Skipped: ${l})`})}return{tasks:i,processedCount:s,skippedCount:l}}0&&(module.exports={processFiles});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/process.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport { allowedFormats } from \"../const.js\";\r\nimport { parseJsonCallback } from \"../extractors/json.js\";\r\nimport { readFileAsync } from \"../fs/fs.js\";\r\nimport { getFiles } from \"../fs/glob.js\";\r\nimport type { Args, Patterns } from \"../types.js\";\r\nimport { doTree } from \"./tree.js\";\r\n\r\n/**\r\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\r\n *\r\n * @param patterns\r\n * @param {Args} args - The arguments for processing the files.\r\n * @param progressBar - The progress bar element.\r\n * @return {Promise<SetOfBlocks[]>} - An array of promises that resolve to TranslationStrings.\r\n */\r\nexport async function processFiles(\r\n\tpatterns: Patterns,\r\n\targs: Args,\r\n\tprogressBar?: SingleBar,\r\n): Promise<Promise<SetOfBlocks>[]> {\r\n\tconst tasks: Promise<SetOfBlocks>[] = [];\r\n\tlet processedFilesCount = 0;\r\n\r\n\tconst files = getFiles(args, patterns);\r\n\r\n\tif (progressBar) {\r\n\t\tprogressBar.setTotal(Object.values(files).length);\r\n\t\tprogressBar.update(0, {\r\n\t\t\tfilename: `Found ${Object.values(files).length} files`,\r\n\t\t});\r\n\t}\r\n\r\n\t// loop through the files and parse them\r\n\tfor await (const file of files) {\r\n\t\tprocessedFilesCount++;\r\n\t\tconst filename = path.basename(file);\r\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\r\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\r\n\r\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\r\n\t\t\ttasks.push(\r\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\r\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t} else if (allowedFormats.includes(ext)) {\r\n\t\t\tconst fileTree = readFileAsync(fileRealPath).then((content) =>\r\n\t\t\t\tdoTree(content, file, args.debug, args),\r\n\t\t\t);\r\n\t\t\tif (fileTree) {\r\n\t\t\t\ttasks.push(fileTree as Promise<SetOfBlocks>);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (progressBar) {\r\n\t\t\tprogressBar.update(processedFilesCount, { filename: filename });\r\n\t\t\tprogressBar.render();\r\n\t\t}\r\n\t}\r\n\r\n\treturn tasks;\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,mBAA+B;AAC/B,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AAUvB,eAAsB,aACrB,UACA,MACA,aACkC;AAClC,QAAM,QAAgC,CAAC;AACvC,MAAI,sBAAsB;AAE1B,QAAM,YAAQ,sBAAS,MAAM,QAAQ;AAErC,MAAI,aAAa;AAChB,gBAAY,SAAS,OAAO,OAAO,KAAK,EAAE,MAAM;AAChD,gBAAY,OAAO,GAAG;AAAA,MACrB,UAAU,SAAS,OAAO,OAAO,KAAK,EAAE,MAAM;AAAA,IAC/C,CAAC;AAAA,EACF;AAGA,mBAAiB,QAAQ,OAAO;AAC/B;AACA,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC,YAAM,eAAW,yBAAc,YAAY,EAAE;AAAA,QAAK,CAAC,gBAClD,oBAAO,SAAS,MAAM,KAAK,OAAO,IAAI;AAAA,MACvC;AACA,UAAI,UAAU;AACb,cAAM,KAAK,QAAgC;AAAA,MAC5C;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,qBAAqB,EAAE,SAAmB,CAAC;AAC9D,kBAAY,OAAO;AAAA,IACpB;AAAA,EACD;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import path from 'node:path'\r\nimport type { SingleBar } from 'cli-progress'\r\nimport type { SetOfBlocks } from 'gettext-merger'\r\nimport { parseJsonCallback } from '../extractors/json.js'\r\nimport { readFileAsync } from '../fs/fs.js'\r\nimport { getFiles } from '../fs/glob.js'\r\nimport type { Args, Patterns } from '../types.js'\r\nimport { doTree } from './tree.js'\r\nimport { allowedFormats } from '../const'\r\n\r\n/**\r\n * The result of processing files.\r\n */\r\nexport interface ProcessResult {\r\n\ttasks: Promise<SetOfBlocks>[];\r\n\tprocessedCount: number;\r\n\tskippedCount: number;\r\n}\r\n\r\n/**\r\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\r\n *\r\n * @param patterns\r\n * @param {Args} args - The arguments for processing the files.\r\n * @param progressBar - The progress bar element.\r\n * @return {Promise<ProcessResult>} - The tasks and file counts.\r\n */\r\nexport async function processFiles(\r\n\tpatterns: Patterns,\r\n\targs: Args,\r\n\tprogressBar?: SingleBar,\r\n): Promise<ProcessResult> {\r\n\tconst tasks: Promise<SetOfBlocks>[] = [];\r\n\tlet processedCount = 0;\r\n\tlet skippedCount = 0;\r\n\r\n\tconst files = await getFiles(args, patterns);\r\n\r\n\tif (progressBar) {\r\n\t\tprogressBar.setTotal(files.length);\r\n\t\tprogressBar.update(0, {\r\n\t\t\tfilename: `Found ${files.length} files`,\r\n\t\t});\r\n\t}\r\n\r\n\t// Loop through the array\r\n\tfor (const file of files) {\r\n\t\tconst filename = path.basename(file);\r\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\r\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\r\n\r\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\r\n\t\t\tprocessedCount++;\r\n\t\t\ttasks.push(\r\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\r\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t} else if (allowedFormats.includes(ext)) {\r\n\t\t\tprocessedCount++;\r\n\t\t\tconst fileTree = readFileAsync(fileRealPath).then((content) =>\r\n\t\t\t\tdoTree(content, file, args.debug, args),\r\n\t\t\t);\r\n\t\t\tif (fileTree) {\r\n\t\t\t\ttasks.push(fileTree as Promise<SetOfBlocks>);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tskippedCount++;\r\n\t\t}\r\n\r\n\t\tif (progressBar) {\r\n\t\t\tprogressBar.update(processedCount + skippedCount, {\r\n\t\t\t\tfilename: `${path.basename(file)} (Processed: ${processedCount} | Skipped: ${skippedCount})`,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\treturn { tasks, processedCount, skippedCount };\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AACvB,mBAA+B;AAmB/B,eAAsB,aACrB,UACA,MACA,aACyB;AACzB,QAAM,QAAgC,CAAC;AACvC,MAAI,iBAAiB;AACrB,MAAI,eAAe;AAEnB,QAAM,QAAQ,UAAM,sBAAS,MAAM,QAAQ;AAE3C,MAAI,aAAa;AAChB,gBAAY,SAAS,MAAM,MAAM;AACjC,gBAAY,OAAO,GAAG;AAAA,MACrB,UAAU,SAAS,MAAM,MAAM;AAAA,IAChC,CAAC;AAAA,EACF;AAGA,aAAW,QAAQ,OAAO;AACzB,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D;AACA,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC;AACA,YAAM,eAAW,yBAAc,YAAY,EAAE;AAAA,QAAK,CAAC,gBAClD,oBAAO,SAAS,MAAM,KAAK,OAAO,IAAI;AAAA,MACvC;AACA,UAAI,UAAU;AACb,cAAM,KAAK,QAAgC;AAAA,MAC5C;AAAA,IACD,OAAO;AACN;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,iBAAiB,cAAc;AAAA,QACjD,UAAU,GAAG,iBAAAA,QAAK,SAAS,IAAI,CAAC,gBAAgB,cAAc,eAAe,YAAY;AAAA,MAC1F,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO,EAAE,OAAO,gBAAgB,aAAa;AAC9C;",
6
6
  "names": ["path"]
7
7
  }
@@ -1 +1 @@
1
- "use strict";var l=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},o=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of u(r))!m.call(e,s)&&s!==t&&a(e,s,{get:()=>r[s],enumerable:!(n=g(r,s))||n.enumerable});return e};var c=(e,r,t)=>(t=e!=null?l(f(e)):{},o(r||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),B=e=>o(a({},"__esModule",{value:!0}),e);var A={};p(A,{initProgress:()=>y});module.exports=B(A);var i=c(require("cli-progress"));function y(e,r){return new i.default.SingleBar({clearOnComplete:!0,etaBuffer:1e3,hideCursor:!0,format:" {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}"},i.default.Presets.shades_classic)}0&&(module.exports={initProgress});
1
+ "use strict";var f=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var $=(e,r)=>{for(var s in r)i(e,s,{get:r[s],enumerable:!0})},a=(e,r,s,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of E(r))!I.call(e,t)&&t!==s&&i(e,t,{get:()=>r[t],enumerable:!(n=m(r,t))||n.enumerable});return e};var d=(e,r,s)=>(s=e!=null?f(p(e)):{},a(r||!e||!e.__esModule?i(s,"default",{value:e,enumerable:!0}):s,e)),A=e=>a(i({},"__esModule",{value:!0}),e);var h={};$(h,{initProgress:()=>_});module.exports=A(h);var o=d(require("cli-progress"));function _(e,r){return new o.default.SingleBar({clearOnComplete:!0,etaBuffer:1e3,hideCursor:!0,format:(n,t,l)=>{const g=n.barCompleteString?.substring(0,Math.round(t.progress*(n.barsize??40)))??"",u=n.barIncompleteString?.substring(0,(n.barsize??40)-g.length)??"",c=Math.round(t.progress*100),b=(l.filename||"").substring(0,40).padEnd(40);return` ${g}${u} ${c}% | ETA: ${t.eta}s | ${b} | ${t.value}/${t.total}`}},o.default.Presets.shades_classic)}0&&(module.exports={initProgress});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/progress.ts"],
4
- "sourcesContent": ["import cliProgress, { type SingleBar } from \"cli-progress\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Initializes a progress bar and returns the progress bar element.\n *\n * @param {Args} args - The argument object containing the source directory and other options.\n * @param {number} filesCount - An array of file names.\n * @return {cliProgress.SingleBar} The progress bar element.\n */\nexport function initProgress(args: Args, filesCount: number): SingleBar {\n\t// Set up the progress bar\n\treturn new cliProgress.SingleBar(\n\t\t{\n\t\t\tclearOnComplete: true,\n\t\t\tetaBuffer: 1000,\n\t\t\thideCursor: true,\n\t\t\tformat:\n\t\t\t\t\" {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}\",\n\t\t},\n\t\tcliProgress.Presets.shades_classic,\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAUrC,SAAS,aAAa,MAAY,YAA+B;AAEvE,SAAO,IAAI,oBAAAA,QAAY;AAAA,IACtB;AAAA,MACC,iBAAiB;AAAA,MACjB,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,QACC;AAAA,IACF;AAAA,IACA,oBAAAA,QAAY,QAAQ;AAAA,EACrB;AACD;",
4
+ "sourcesContent": ["import cliProgress, { type SingleBar } from \"cli-progress\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Initializes a progress bar and returns the progress bar element.\r\n *\r\n * @param {Args} _args - The argument object containing the source directory and other options.\r\n * @param {number} _filesCount - An array of file names.\r\n * @return {cliProgress.SingleBar} The progress bar element.\r\n */\r\nexport function initProgress(_args: Args, _filesCount: number): SingleBar {\r\n\tconst FILENAME_WIDTH = 40;\r\n\t// Set up the progress bar\r\n\treturn new cliProgress.SingleBar(\r\n\t\t{\r\n\t\t\tclearOnComplete: true,\r\n\t\t\tetaBuffer: 1000,\r\n\t\t\thideCursor: true,\r\n\t\t\tformat: (options, params, payload) => {\r\n\t\t\t\tconst bar = options.barCompleteString?.substring(0, Math.round(params.progress * (options.barsize ?? 40))) ?? \"\";\r\n\t\t\t\tconst emptyBar = options.barIncompleteString?.substring(0, (options.barsize ?? 40) - bar.length) ?? \"\";\r\n\t\t\t\tconst pct = Math.round(params.progress * 100);\r\n\t\t\t\tconst filename = (payload.filename || \"\").substring(0, FILENAME_WIDTH).padEnd(FILENAME_WIDTH);\r\n\t\t\t\treturn ` ${bar}${emptyBar} ${pct}% | ETA: ${params.eta}s | ${filename} | ${params.value}/${params.total}`;\r\n\t\t\t},\r\n\t\t},\r\n\t\tcliProgress.Presets.shades_classic,\r\n\t);\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAUrC,SAAS,aAAa,OAAa,aAAgC;AACzE,QAAM,iBAAiB;AAEvB,SAAO,IAAI,oBAAAA,QAAY;AAAA,IACtB;AAAA,MACC,iBAAiB;AAAA,MACjB,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,QAAQ,CAAC,SAAS,QAAQ,YAAY;AACrC,cAAM,MAAM,QAAQ,mBAAmB,UAAU,GAAG,KAAK,MAAM,OAAO,YAAY,QAAQ,WAAW,GAAG,CAAC,KAAK;AAC9G,cAAM,WAAW,QAAQ,qBAAqB,UAAU,IAAI,QAAQ,WAAW,MAAM,IAAI,MAAM,KAAK;AACpG,cAAM,MAAM,KAAK,MAAM,OAAO,WAAW,GAAG;AAC5C,cAAM,YAAY,QAAQ,YAAY,IAAI,UAAU,GAAG,cAAc,EAAE,OAAO,cAAc;AAC5F,eAAO,IAAI,GAAG,GAAG,QAAQ,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,QAAQ,MAAM,OAAO,KAAK,IAAI,OAAO,KAAK;AAAA,MACxG;AAAA,IACD;AAAA,IACA,oBAAAA,QAAY,QAAQ;AAAA,EACrB;AACD;",
6
6
  "names": ["cliProgress"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var B=(o,e)=>{for(var s in e)a(o,s,{get:e[s],enumerable:!0})},i=(o,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of u(e))!k.call(o,t)&&t!==s&&a(o,t,{get:()=>e[t],enumerable:!(n=g(e,t))||n.enumerable});return o};var p=(o,e,s)=>(s=o!=null?m(h(o)):{},i(e||!o||!o.__esModule?a(s,"default",{value:o,enumerable:!0}):s,o)),S=o=>i(a({},"__esModule",{value:!0}),o);var d={};B(d,{taskRunner:()=>O});module.exports=S(d);var y=p(require("node:os")),c=p(require("node:path"));async function O(o,e,s,n){const t=[];return await Promise.allSettled(o).then(l=>l.map(r=>r.status==="fulfilled"&&r.value).filter(Boolean)).then(l=>{if(s.options?.silent!==!0)for(const r of l)r.blocks.length>0?(e.addArray(r.blocks),t.push(`\u2705 ${r.path} [${r.blocks.map(f=>f.msgid).join(", ")}]`)):t.push(`\u274C ${r.path} has no strings`)}).catch(l=>new Error(l)),n.stop(),console.log(`
2
- \u{1F389} Done!`),console.log(`\u{1F4DD} Found ${Object.values(e.blocks).length} translation strings in ${c.default.resolve(s.paths.cwd)}.`),console.log(t.join(y.EOL)),e}0&&(module.exports={taskRunner});
1
+ "use strict";var g=Object.create;var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!d.call(t,n)&&n!==s&&i(t,n,{get:()=>e[n],enumerable:!(l=u(e,n))||l.enumerable});return t};var p=(t,e,s)=>(s=t!=null?g(S(t)):{},m(e||!t||!t.__esModule?i(s,"default",{value:t,enumerable:!0}):s,t)),O=t=>m(i({},"__esModule",{value:!0}),t);var B={};y(B,{taskRunner:()=>b});module.exports=O(B);var $=p(require("node:os")),a=p(require("node:path"));async function b(t,e,s,l){const n=[],f=t.map(r=>r.then(o=>(l.increment({filename:o.path?a.default.basename(o.path):""}),o)).catch(o=>{throw l.increment({filename:"error"}),o}));return await Promise.allSettled(f).then(r=>r.map(o=>o.status==="fulfilled"&&o.value).filter(Boolean)).then(r=>{for(const o of r)if(o.blocks.length>0){e.addArray(o.blocks);const c=o.blocks.map(h=>h.msgid);s.options?.silent!==!0&&n.push(`\u2705 ${o.path} - ${c.length} strings found [${c.join(", ")}]`)}else s.options?.silent!==!0&&n.push(`\u274C ${o.path} - has no strings`)}).catch(r=>new Error(r)),l.stop(),console.log(`
2
+ \u{1F389} Done!`),console.log(`\u{1F4DD} Found ${Object.values(e.blocks).length} translation strings in ${a.default.resolve(s.paths.cwd)}.`),console.log(n.join($.EOL)),e}0&&(module.exports={taskRunner});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/taskRunner.ts"],
4
- "sourcesContent": ["import * as os from \"node:os\";\nimport path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport type { SetOfBlocks } from \"gettext-merger\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Task runner for the extraction process.\n *\n * @param tasks - The tasks to run\n * @param destination - The destination\n * @param args - The command line arguments\n * @param progressBar\n */\nexport async function taskRunner(\n\ttasks: Promise<SetOfBlocks>[],\n\tdestination: SetOfBlocks,\n\targs: Args,\n\tprogressBar: SingleBar,\n) {\n\tconst messages = [];\n\tawait Promise.allSettled(tasks)\n\t\t.then((strings) => {\n\t\t\t/**\n\t\t\t * Return the strings that are not rejected (they are fulfilled)\n\t\t\t */\n\t\t\treturn strings\n\t\t\t\t.map((block) => block.status === \"fulfilled\" && block.value)\n\t\t\t\t.filter(Boolean) as SetOfBlocks[]; // remove nullish\n\t\t})\n\t\t.then((consolidated) => {\n\t\t\t/** Log the results */\n\t\t\tif (args.options?.silent !== true) {\n\t\t\t\tfor (const result of consolidated) {\n\t\t\t\t\tif (result.blocks.length > 0) {\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Add the strings to the destination set\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdestination.addArray(result.blocks);\n\t\t\t\t\t\t/* Log the results */\n\t\t\t\t\t\tmessages.push(\n\t\t\t\t\t\t\t`\u2705 ${result.path} [${result.blocks.map((b) => b.msgid).join(\", \")}]`,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else messages.push(`\u274C ${result.path} has no strings`);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.catch((err) => {\n\t\t\treturn new Error(err);\n\t\t});\n\n\tprogressBar.stop();\n\n\tconsole.log(\"\\n\uD83C\uDF89 Done!\");\n\tconsole.log(\n\t\t`\uD83D\uDCDD Found ${Object.values(destination.blocks).length} translation strings in ${path.resolve(args.paths.cwd)}.`,\n\t);\n\n\tconsole.log(messages.join(os.EOL));\n\n\treturn destination;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AACD,QAAM,WAAW,CAAC;AAClB,QAAM,QAAQ,WAAW,KAAK,EAC5B,KAAK,CAAC,YAAY;AAIlB,WAAO,QACL,IAAI,CAAC,UAAU,MAAM,WAAW,eAAe,MAAM,KAAK,EAC1D,OAAO,OAAO;AAAA,EACjB,CAAC,EACA,KAAK,CAAC,iBAAiB;AAEvB,QAAI,KAAK,SAAS,WAAW,MAAM;AAClC,iBAAW,UAAU,cAAc;AAClC,YAAI,OAAO,OAAO,SAAS,GAAG;AAI7B,sBAAY,SAAS,OAAO,MAAM;AAElC,mBAAS;AAAA,YACR,UAAK,OAAO,IAAI,KAAK,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;AAAA,UAClE;AAAA,QACD,MAAO,UAAS,KAAK,UAAK,OAAO,IAAI,iBAAiB;AAAA,MACvD;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,UAAQ,IAAI,mBAAY;AACxB,UAAQ;AAAA,IACP,mBAAY,OAAO,OAAO,YAAY,MAAM,EAAE,MAAM,2BAA2B,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC5G;AAEA,UAAQ,IAAI,SAAS,KAAK,GAAG,GAAG,CAAC;AAEjC,SAAO;AACR;",
4
+ "sourcesContent": ["import * as os from \"node:os\";\r\nimport path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Task runner for the extraction process.\r\n *\r\n * @param tasks - The tasks to run\r\n * @param destination - The destination\r\n * @param args - The command line arguments\r\n * @param progressBar\r\n */\r\nexport async function taskRunner(\r\n\ttasks: Promise<SetOfBlocks>[],\r\n\tdestination: SetOfBlocks,\r\n\targs: Args,\r\n\tprogressBar: SingleBar,\r\n) {\r\n\tconst messages: string[] = [];\r\n\t// Create a new array of promises that update the bar when they finish.\r\n\tconst tasksWithProgress = tasks.map((task) =>\r\n\t\ttask.then((result) => {\r\n\t\t\tprogressBar.increment({\r\n\t\t\t\tfilename: result.path ? path.basename(result.path) : \"\",\r\n\t\t\t});\r\n\t\t\treturn result;\r\n\t\t}).catch((err) => {\r\n\t\t\tprogressBar.increment({ filename: \"error\" });\r\n\t\t\tthrow err;\r\n\t\t})\r\n\t);\r\n\tawait Promise.allSettled(tasksWithProgress)\r\n\t\t.then((strings) => {\r\n\t\t\t/**\r\n\t\t\t * Return the strings that are not rejected (they are fulfilled)\r\n\t\t\t */\r\n\t\t\treturn strings\r\n\t\t\t\t.map((block) => block.status === \"fulfilled\" && block.value)\r\n\t\t\t\t.filter(Boolean) as SetOfBlocks[]; // remove nullish\r\n\t\t})\r\n\t\t.then((consolidated) => {\r\n\t\t\t/** Log the results */\r\n\t\t\tfor (const result of consolidated) {\r\n\t\t\t\tif (result.blocks.length > 0) {\r\n\t\t\t\t\t/**\r\n\t\t\t\t\t * Add the strings to the destination set\r\n\t\t\t\t\t */\r\n\t\t\t\t\tdestination.addArray(result.blocks);\r\n\t\t\t\t\tconst strings = result.blocks.map((b) => b.msgid);\r\n\r\n\t\t\t\t\t/* Log the results */\r\n\t\t\t\t\tif (args.options?.silent !== true) {\r\n\t\t\t\t\t\tmessages.push(\r\n\t\t\t\t\t\t\t`\u2705 ${result.path} - ${strings.length} strings found [${strings.join(\", \")}]`,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t} else if (args.options?.silent !== true) {\r\n\t\t\t\t\tmessages.push(`\u274C ${result.path} - has no strings`);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t})\r\n\t\t.catch((err) => {\r\n\t\t\treturn new Error(err);\r\n\t\t});\r\n\r\n\tprogressBar.stop();\r\n\r\n\tconsole.log(\"\\n\uD83C\uDF89 Done!\");\r\n\tconsole.log(\r\n\t\t`\uD83D\uDCDD Found ${Object.values(destination.blocks).length} translation strings in ${path.resolve(args.paths.cwd)}.`,\r\n\t);\r\n\r\n\tconsole.log(messages.join(os.EOL));\r\n\r\n\treturn destination;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AACD,QAAM,WAAqB,CAAC;AAE5B,QAAM,oBAAoB,MAAM;AAAA,IAAI,CAAC,SACpC,KAAK,KAAK,CAAC,WAAW;AACrB,kBAAY,UAAU;AAAA,QACrB,UAAU,OAAO,OAAO,iBAAAA,QAAK,SAAS,OAAO,IAAI,IAAI;AAAA,MACtD,CAAC;AACD,aAAO;AAAA,IACR,CAAC,EAAE,MAAM,CAAC,QAAQ;AACjB,kBAAY,UAAU,EAAE,UAAU,QAAQ,CAAC;AAC3C,YAAM;AAAA,IACP,CAAC;AAAA,EACF;AACA,QAAM,QAAQ,WAAW,iBAAiB,EACxC,KAAK,CAAC,YAAY;AAIlB,WAAO,QACL,IAAI,CAAC,UAAU,MAAM,WAAW,eAAe,MAAM,KAAK,EAC1D,OAAO,OAAO;AAAA,EACjB,CAAC,EACA,KAAK,CAAC,iBAAiB;AAEvB,eAAW,UAAU,cAAc;AAClC,UAAI,OAAO,OAAO,SAAS,GAAG;AAI7B,oBAAY,SAAS,OAAO,MAAM;AAClC,cAAM,UAAU,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK;AAGhD,YAAI,KAAK,SAAS,WAAW,MAAM;AAClC,mBAAS;AAAA,YACR,UAAK,OAAO,IAAI,MAAM,QAAQ,MAAM,mBAAmB,QAAQ,KAAK,IAAI,CAAC;AAAA,UAC1E;AAAA,QACD;AAAA,MACD,WAAW,KAAK,SAAS,WAAW,MAAM;AACzC,iBAAS,KAAK,UAAK,OAAO,IAAI,mBAAmB;AAAA,MAClD;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,UAAQ,IAAI,mBAAY;AACxB,UAAQ;AAAA,IACP,mBAAY,OAAO,OAAO,YAAY,MAAM,EAAE,MAAM,2BAA2B,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC5G;AAEA,UAAQ,IAAI,SAAS,KAAK,GAAG,GAAG,CAAC;AAEjC,SAAO;AACR;",
6
6
  "names": ["path"]
7
7
  }
@@ -1 +1,2 @@
1
- "use strict";var C=Object.create;var m=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var K=(e,t)=>{for(var s in t)m(e,s,{get:t[s],enumerable:!0})},$=(e,t,s,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of L(t))!z.call(e,o)&&o!==s&&m(e,o,{get:()=>t[o],enumerable:!(c=F(t,o))||c.enumerable});return e};var M=(e,t,s)=>(s=e!=null?C(O(e)):{},$(t||!e||!e.__esModule?m(s,"default",{value:e,enumerable:!0}):s,e)),j=e=>$(m({},"__esModule",{value:!0}),e);var I={};K(I,{doTree:()=>E});module.exports=j(I);var k=M(require("tree-sitter")),y=require("../const.js"),d=require("gettext-merger"),v=require("../fs/glob.js"),f=require("../utils/common.js");function D(e){let t=e,s=0;for(;t&&s<6;){if(t?.previousSibling?.type==="comment"&&t?.previousSibling?.text.toLowerCase().includes("translators"))return t?.previousSibling?.text?(0,f.stripTranslationMarkup)(t.previousSibling.text):void 0;s++,t=t.parent}}function E(e,t,s,c){const o=new k.default,x=(0,v.getParser)(t);if(!x)return new d.SetOfBlocks([],t);o.setLanguage(x);const _=new d.SetOfBlocks([],t),N=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",B=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function b(n){if(n?.children.length)for(const r of n.children)b(r);if(n?.type===N){const r=n.firstChild?.text??null;if(r===null||!Object.keys(y.i18nFunctions).includes(r))return;const l=n.lastChild;if(l===null||l.childCount===0||l.type!=="arguments")return;const[U,P]=n.children,a={text_domain:"default"},h=y.i18nFunctions[r],T=P.children.slice(1,-1);let g=0;for(const p of T){let i=p,u=i.text;if(p.type==="argument"){if(p.children.length===0)continue;i=p.children[0]}if(i?.type===",")continue;const w=h[g];if(i?.type&&B.includes(i.type))u=u.slice(1,-1);else if(w==="number")u=i.text;else{console.error(`Unexpected node type ${i?.type} identified as ${h[g]} with value ${u} in ${t} at ${i.startPosition.row+1} pos ${i.startPosition.column+1}`);return}a[w]=u,g+=1}if(Array.isArray(c?.options?.translationDomains)&&!c.options.translationDomains.includes(a.text_domain))return;const S=D(l),A=new d.Block({msgctxt:a.msgctxt,msgid:a.msgid??"",msgid_plural:a.msgid_plural,msgstr:a.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,f.reverseSlashes)(t)}:${n.startPosition.row+1}`]}});_.add(A)}}try{if(e){const n=Buffer.byteLength(e,"utf8");let r=1024*32;n>=r&&(r=n+32),n>=1024*1024*2&&console.warn(`File size warning: ${t} exceeds 2 MB.`);const l=o.parse(e,void 0,{bufferSize:r});l&&b(l.rootNode)}}catch(n){console.error(`Failed to parse ${t}: ${n}`)}return _}0&&(module.exports={doTree});
1
+ "use strict";var L=Object.create;var g=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of O(t))!z.call(e,o)&&o!==n&&g(e,o,{get:()=>t[o],enumerable:!(s=M(t,o))||s.enumerable});return e};var K=(e,t,n)=>(n=e!=null?L(j(e)):{},N(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),V=e=>N(g({},"__esModule",{value:!0}),e);var R={};D(R,{doTree:()=>I});module.exports=V(R);var F=K(require("tree-sitter")),h=require("../const.js"),f=require("gettext-merger"),B=require("../fs/glob.js"),x=require("../utils/common.js");function q(e){let t=e,n=0;for(;t&&n<6;){if(t.previousSibling?.type==="comment"&&t.previousSibling.text.toLowerCase().includes("translators"))return(0,x.stripTranslationMarkup)(t.previousSibling.text);n++,t=t.parent}}const y={n:`
2
+ `,r:"\r",t:" ",f:"\f",v:"\v",0:"\0","\\":"\\",'"':'"',"'":"'",$:"$",e:"\x1B"};function E(e){if(e.type==="encapsed_string")return e.children.map(t=>{if(t.type==="escape_sequence"){const n=t.text.slice(1);return n in y?y[n]:t.text}return t.type==="string_content"||t.type==="variable_name"?t.text:""}).join("");if(e.type==="string"){const t=e.text;if(t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')){const n=t.startsWith('"');let s=t.slice(1,-1);return n?s=s.replace(/\\(.)/g,(o,u)=>u in y?y[u]:o):s=s.replace(/\\'/g,"'").replace(/\\\\/g,"\\"),s}}return e.text}function I(e,t,n,s){const o=new F.default,u=(0,B.getParser)(t);if(!u)return new f.SetOfBlocks([],t);o.setLanguage(u);const S=new f.SetOfBlocks([],t),P=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",T=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function v(i){if(i?.children.length)for(const a of i.children)v(a);if(i?.type===P){const a=i.firstChild?.text??null;if(a===null||!Object.keys(h.i18nFunctions).includes(a))return;const l=i.childForFieldName("arguments");if(l===null||l.childCount===0||l.type!=="arguments"||!l)return;const c={text_domain:"default"},_=h.i18nFunctions[a],W=l.children;let m=0;for(const p of W){let r=p;if(r.type==="("||r.type===")"||r.type===","||r.type==="["||r.type==="]"||r.type==="comment")continue;if(p.type==="argument"){if(p.children.length===0)continue;const C=p.childForFieldName("name");let w=!1;for(const d of p.children)if(d.id!==C?.id&&!(d.type==="comment"||d.type===":")){r=d,w=!0;break}if(!w)continue}if(m>=_.length)break;const k=_[m];let b=E(r);if(k==="number")b=r.text;else if(!r?.type||!T.includes(r.type)){n&&console.error(`Unexpected node type ${r?.type} identified as ${_[m]} with value ${b} in ${t} at ${r.startPosition.row+1} pos ${r.startPosition.column+1}`);return}c[k]=b,m+=1}if(Array.isArray(s?.options?.translationDomains)&&c.text_domain&&!s.options.translationDomains.includes(c.text_domain))return;const $=q(i),A=new f.Block({msgctxt:c.msgctxt,msgid:c.msgid??"",msgid_plural:c.msgid_plural,msgstr:c.msgid_plural?["",""]:[""],comments:{translator:$?[$]:void 0,reference:[`${(0,x.reverseSlashes)(t)}:${i.startPosition.row+1}`]}});S.add(A)}}try{if(e){const i=Buffer.byteLength(e,"utf8");let a=1024*32;i>=a&&(a=i+32),i>=1024*1024*2&&console.warn(`File size warning: ${t} exceeds 2 MB.`);const l=o.parse(e,void 0,{bufferSize:a});l&&v(l.rootNode)}}catch(i){console.error(`Failed to parse ${t}: ${i}`)}return S}0&&(module.exports={doTree});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/tree.ts"],
4
- "sourcesContent": ["import Parser, { type SyntaxNode } from \"tree-sitter\";\r\nimport { i18nFunctions } from \"../const.js\";\r\n\r\nimport { Block, SetOfBlocks } from \"gettext-merger\";\r\nimport { getParser } from \"../fs/glob.js\";\r\nimport { reverseSlashes, stripTranslationMarkup } from \"../utils/common.js\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Collect comments from the AST node and its preceding siblings.\r\n *\r\n * @param {SyntaxNode} node - The AST node.\r\n * @return {string[]} An array of collected comments.\r\n */\r\nfunction collectComments(node: SyntaxNode): string | undefined {\r\n\tlet currentNode = node;\r\n\tlet depth = 0;\r\n\r\n\t// Check the node's preceding siblings for comments\r\n\twhile (currentNode && depth < 6) {\r\n\t\tif (\r\n\t\t\tcurrentNode?.previousSibling?.type === \"comment\" &&\r\n\t\t\tcurrentNode?.previousSibling?.text.toLowerCase().includes(\"translators\")\r\n\t\t) {\r\n\t\t\treturn currentNode?.previousSibling?.text\r\n\t\t\t\t? stripTranslationMarkup(currentNode.previousSibling.text)\r\n\t\t\t\t: undefined;\r\n\t\t}\r\n\t\tdepth++;\r\n\t\tcurrentNode = currentNode.parent as SyntaxNode;\r\n\t}\r\n}\r\n\r\n/**\r\n * Parses the source code using the specified language parser and extracts the strings from the file.\r\n *\r\n * @param {string} sourceCode - The source code to be parsed.\r\n * @param {string} filepath - The path to the file being parsed.\r\n * @param {boolean} debugEnabled - Whether debug mode is enabled.\r\n * @param {Args} args - The command line arguments, optional.\r\n * @return {SetOfBlocks} An array of translation strings.\r\n */\r\nexport function doTree(\r\n\tsourceCode: string,\r\n\tfilepath: string,\r\n\tdebugEnabled?: boolean,\r\n\targs?: Args,\r\n): SetOfBlocks {\r\n\t// set up the parser\r\n\tconst parser = new Parser();\r\n\tconst parserExt = getParser(filepath);\r\n\t// if no parser is found return empty\r\n\tif (!parserExt) return new SetOfBlocks([], filepath);\r\n\t// set the parser language\r\n\tparser.setLanguage(parserExt);\r\n\r\n\t// set up the translation object\r\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\r\n\r\n\tconst typeToMatch =\r\n\t\tfilepath.split(\".\").pop()?.toLowerCase() !== \"php\"\r\n\t\t\t? \"call_expression\"\r\n\t\t\t: \"function_call_expression\";\r\n\r\n\tconst stringType = [\r\n\t\t\"name\",\r\n\t\t\"string\",\r\n\t\t\"string_value\",\r\n\t\t\"variable_name\",\r\n\t\t\"binary_expression\",\r\n\t\t\"member_expression\",\r\n\t\t\"subscript_expression\",\r\n\t\t\"shell_command_expression\",\r\n\t\t\"function_call_expression\",\r\n\t\t\"encapsed_string\",\r\n\t];\r\n\r\n\t/**\r\n\t * Traverse the tree \uD83C\uDF33\r\n\t *\r\n\t * @param {SyntaxNode} node The node to traverse through\r\n\t */\r\n\tfunction traverse(node: SyntaxNode): void {\r\n\t\t// Walk the tree\r\n\t\tif (node?.children.length)\r\n\t\t\tfor (const child of node.children) {\r\n\t\t\t\ttraverse(child);\r\n\t\t\t}\r\n\r\n\t\t// Check if the node matches\r\n\t\tif (node?.type === typeToMatch) {\r\n\t\t\t// The function name is the first child\r\n\t\t\tconst functionName = node.firstChild?.text ?? null;\r\n\t\t\tif (\r\n\t\t\t\tfunctionName === null ||\r\n\t\t\t\t!Object.keys(i18nFunctions).includes(functionName)\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// The arguments are the last child\r\n\t\t\tconst argsNode = node.lastChild;\r\n\t\t\tif (\r\n\t\t\t\targsNode === null ||\r\n\t\t\t\targsNode.childCount === 0 ||\r\n\t\t\t\targsNode.type !== \"arguments\"\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the whole gettext translation string\r\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n\t\t\tconst [_fn, raw] = node.children;\r\n\t\t\tconst translation: Partial<{\r\n\t\t\t\tmsgctxt: string;\r\n\t\t\t\tmsgid: string;\r\n\t\t\t\tmsgid_plural: string;\r\n\t\t\t\tnumber: string;\r\n\t\t\t\tmsgstr: string;\r\n\t\t\t\ttext_domain: string;\r\n\t\t\t}> = {\r\n\t\t\t\t// WordPress default text domain is 'default'\r\n\t\t\t\ttext_domain: 'default',\r\n\t\t\t};\r\n\r\n\t\t\tconst translationKeys =\r\n\t\t\t\ti18nFunctions[functionName as keyof typeof i18nFunctions];\r\n\r\n\t\t\tconst children = raw.children.slice(1, -1);\r\n\t\t\tlet translationKeyIndex = 0;\r\n\r\n\t\t\t// Get the translation from the arguments (the quoted strings)\r\n\t\t\tfor (const child of children) {\r\n\t\t\t\tlet node = child;\r\n\t\t\t\tlet nodeValue: string | string[] = node.text;\r\n\r\n\t\t\t\t// unwrap the argument node, which is used in PHP.\r\n\t\t\t\tif (child.type === \"argument\") {\r\n\t\t\t\t\tif (child.children.length === 0) continue;\r\n\t\t\t\t\tnode = child.children[0];\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (node?.type === \",\") {\r\n\t\t\t\t\t// skip the comma between arguments\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the translation key (eg. msgid)\r\n\t\t\t\tconst currentKey = translationKeys[\r\n\t\t\t\t\ttranslationKeyIndex\r\n\t\t\t\t] as keyof typeof translation;\r\n\r\n\t\t\t\tif (node?.type && stringType.includes(node.type)) {\r\n\t\t\t\t\t// unquote the strings\r\n\t\t\t\t\tnodeValue = nodeValue.slice(1, -1);\r\n\t\t\t\t} else if (currentKey === 'number'){\r\n\t\t\t\t\t// `number` accepts any value, this will not be provided in the POT file\r\n\t\t\t\t\tnodeValue = node.text;\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Whenever we get an unexpected node type this string is not translatable and should be skipped\r\n\t\t\t\t\tconsole.error(\r\n\t\t\t\t\t\t`Unexpected node type ${node?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node.startPosition.row + 1} pos ${node.startPosition.column + 1}`,\r\n\t\t\t\t\t);\r\n\t\t\t\t\treturn; // Parse error, skip this translation.\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the value of that key\r\n\t\t\t\ttranslation[currentKey] = nodeValue;\r\n\r\n\t\t\t\t// increment the index of the translation key\r\n\t\t\t\ttranslationKeyIndex += 1;\r\n\t\t\t}\r\n\r\n\t\t\tif (Array.isArray(args?.options?.translationDomains) && !args.options.translationDomains.includes(translation.text_domain as string)) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst comments = collectComments(argsNode);\r\n\r\n\t\t\t// Get the translation data\r\n\t\t\tconst block = new Block({\r\n\t\t\t\tmsgctxt: translation.msgctxt,\r\n\t\t\t\tmsgid: translation.msgid ?? \"\",\r\n\t\t\t\tmsgid_plural: translation.msgid_plural,\r\n\t\t\t\tmsgstr: translation.msgid_plural ? [\"\", \"\"] : [\"\"],\r\n\t\t\t\tcomments: {\r\n\t\t\t\t\ttranslator: comments ? [comments] : undefined,\r\n\t\t\t\t\treference: [\r\n\t\t\t\t\t\t`${reverseSlashes(filepath)}:${node.startPosition.row + 1}`,\r\n\t\t\t\t\t],\r\n\t\t\t\t},\r\n\t\t\t} as Block);\r\n\r\n\t\t\tgettextTranslations.add(block);\r\n\t\t}\r\n\t}\r\n\r\n\ttry {\r\n\t\tif (sourceCode) {\r\n\t\t\tconst fileSize = Buffer.byteLength(sourceCode, \"utf8\");\r\n\t\t\tlet bufferSize = 1024 * 32; // 32 KB default buffer size\r\n\r\n\t\t\tif (fileSize >= bufferSize) {\r\n\t\t\t\tbufferSize = fileSize + 32; // dynamic buffer size with 32 bytes of padding\r\n\t\t\t}\r\n\r\n\t\t\tif (fileSize >= 1024 * 1024 * 2) {\r\n\t\t\t\tconsole.warn(`File size warning: ${filepath} exceeds 2 MB.`);\r\n\t\t\t}\r\n\r\n\t\t\t// parse the file\r\n\t\t\tconst tree = parser.parse(sourceCode, undefined, { bufferSize });\r\n\t\t\tif (tree) {\r\n\t\t\t\ttraverse(tree.rootNode);\r\n\t\t\t}\r\n\t\t}\r\n\t} catch (e) {\r\n\t\tconsole.error(`Failed to parse ${filepath}: ${e}`);\r\n\t}\r\n\r\n\t// Return both matches and entries\r\n\treturn gettextTranslations;\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAA8B;AAE9B,4BAAmC;AACnC,kBAA0B;AAC1B,oBAAuD;AASvD,SAAS,gBAAgB,MAAsC;AAC9D,MAAI,cAAc;AAClB,MAAI,QAAQ;AAGZ,SAAO,eAAe,QAAQ,GAAG;AAChC,QACC,aAAa,iBAAiB,SAAS,aACvC,aAAa,iBAAiB,KAAK,YAAY,EAAE,SAAS,aAAa,GACtE;AACD,aAAO,aAAa,iBAAiB,WAClC,sCAAuB,YAAY,gBAAgB,IAAI,IACvD;AAAA,IACJ;AACA;AACA,kBAAc,YAAY;AAAA,EAC3B;AACD;AAWO,SAAS,OACf,YACA,UACA,cACA,MACc;AAEd,QAAM,SAAS,IAAI,mBAAAA,QAAO;AAC1B,QAAM,gBAAY,uBAAU,QAAQ;AAEpC,MAAI,CAAC,UAAW,QAAO,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAEnD,SAAO,YAAY,SAAS;AAG5B,QAAM,sBAAmC,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAErE,QAAM,cACL,SAAS,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY,MAAM,QAC1C,oBACA;AAEJ,QAAM,aAAa;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA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AA,QACD;AAGA,oBAAY,UAAU,IAAI;AAG1B,+BAAuB;AAAA,MACxB;AAEA,UAAI,MAAM,QAAQ,MAAM,SAAS,kBAAkB,KAAK,CAAC,KAAK,QAAQ,mBAAmB,SAAS,YAAY,WAAqB,GAAG;AACrI;AAAA,MACD;AAEA,YAAM,WAAW,gBAAgB,QAAQ;AAGzC,YAAM,QAAQ,IAAI,4BAAM;AAAA,QACvB,SAAS,YAAY;AAAA,QACrB,OAAO,YAAY,SAAS;AAAA,QAC5B,cAAc,YAAY;AAAA,QAC1B,QAAQ,YAAY,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;AAAA,QACjD,UAAU;AAAA,UACT,YAAY,WAAW,CAAC,QAAQ,IAAI;AAAA,UACpC,WAAW;AAAA,YACV,OAAG,8BAAe,QAAQ,CAAC,IAAI,KAAK,cAAc,MAAM,CAAC;AAAA,UAC1D;AAAA,QACD;AAAA,MACD,CAAU;AAEV,0BAAoB,IAAI,KAAK;AAAA,IAC9B;AAAA,EACD;AAEA,MAAI;AACH,QAAI,YAAY;AACf,YAAM,WAAW,OAAO,WAAW,YAAY,MAAM;AACrD,UAAI,aAAa,OAAO;AAExB,UAAI,YAAY,YAAY;AAC3B,qBAAa,WAAW;AAAA,MACzB;AAEA,UAAI,YAAY,OAAO,OAAO,GAAG;AAChC,gBAAQ,KAAK,sBAAsB,QAAQ,gBAAgB;AAAA,MAC5D;AAGA,YAAM,OAAO,OAAO,MAAM,YAAY,QAAW,EAAE,WAAW,CAAC;AAC/D,UAAI,MAAM;AACT,iBAAS,KAAK,QAAQ;AAAA,MACvB;AAAA,IACD;AAAA,EACD,SAAS,GAAG;AACX,YAAQ,MAAM,mBAAmB,QAAQ,KAAK,CAAC,EAAE;AAAA,EAClD;AAGA,SAAO;AACR;",
4
+ "sourcesContent": ["import Parser, { type SyntaxNode } from \"tree-sitter\";\r\nimport { i18nFunctions } from \"../const.js\";\r\nimport { Block, SetOfBlocks } from \"gettext-merger\";\r\nimport { getParser } from \"../fs/glob.js\";\r\nimport { reverseSlashes, stripTranslationMarkup } from \"../utils/common.js\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Collect comments from the AST node and its preceding siblings.\r\n *\r\n * @param {SyntaxNode} node - The AST node.\r\n * @return {string | undefined} The collected comment or undefined.\r\n */\r\nfunction collectComments(node: SyntaxNode): string | undefined {\r\n\tlet currentNode: SyntaxNode | null = node;\r\n\tlet depth = 0;\r\n\r\n\t// Check the node's preceding siblings for comments\r\n\twhile (currentNode && depth < 6) {\r\n\t\tif (\r\n\t\t\tcurrentNode.previousSibling?.type === \"comment\" &&\r\n\t\t\tcurrentNode.previousSibling.text.toLowerCase().includes(\"translators\")\r\n\t\t) {\r\n\t\t\treturn stripTranslationMarkup(currentNode.previousSibling.text);\r\n\t\t}\r\n\t\tdepth++;\r\n\t\tcurrentNode = currentNode.parent;\r\n\t}\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Map of escape characters to their resolved values.\r\n * Used by both PHP (encapsed_string) and JS (string) handlers.\r\n */\r\nconst escapeMap: Record<string, string> = {\r\n\t'n': '\\n',\r\n\t'r': '\\r',\r\n\t't': '\\t',\r\n\t'f': '\\f',\r\n\t'v': '\\v',\r\n\t'0': '\\0',\r\n\t'\\\\': '\\\\',\r\n\t'\"': '\"',\r\n\t\"'\": \"'\",\r\n\t'$': '$',\r\n\t'e': '\\x1b',\r\n};\r\n\r\n/**\r\n * Resolves the actual string value from a tree-sitter node,\r\n * handling escape sequences in double-quoted strings.\r\n *\r\n * @param {SyntaxNode} node - The AST node.\r\n * @return {string} The collected comment or undefined.\r\n */\r\nfunction resolveStringValue(node: SyntaxNode): string {\r\n\t// Handle double-quoted strings (PHP encapsed_string)\r\n\tif (node.type === 'encapsed_string') {\r\n\t\treturn node.children\r\n\t\t\t.map((child) => {\r\n\t\t\t\tif (child.type === 'escape_sequence') {\r\n\t\t\t\t\t// child.text is e.g. \"\\\\n\" \u2014 the char after the backslash is the key\r\n\t\t\t\t\tconst ch = child.text.slice(1);\r\n\t\t\t\t\treturn ch in escapeMap ? escapeMap[ch] : child.text;\r\n\t\t\t\t}\r\n\t\t\t\t// Return literal content\r\n\t\t\t\tif (child.type === 'string_content') {\r\n\t\t\t\t\treturn child.text;\r\n\t\t\t\t}\r\n\t\t\t\t// Handle variables if they appear (preserve them as text)\r\n\t\t\t\tif (child.type === 'variable_name') {\r\n\t\t\t\t\treturn child.text;\r\n\t\t\t\t}\r\n\t\t\t\treturn '';\r\n\t\t\t})\r\n\t\t\t.join('');\r\n\t}\r\n\r\n\t// Handle single-quoted strings (PHP string) or JS strings\r\n\tif (node.type === 'string') {\r\n\t\tconst text = node.text;\r\n\t\t// Strip surrounding quotes if present\r\n\t\tif ((text.startsWith(\"'\") && text.endsWith(\"'\")) ||\r\n\t\t\t(text.startsWith('\"') && text.endsWith('\"'))) {\r\n\t\t\tconst isDouble = text.startsWith('\"');\r\n\t\t\tlet inner = text.slice(1, -1);\r\n\t\t\tif (isDouble) {\r\n\t\t\t\t// Unescape common escape sequences for double-quoted strings\r\n\t\t\t\tinner = inner.replace(/\\\\(.)/g, (_match, ch) =>\r\n\t\t\t\t\tch in escapeMap ? escapeMap[ch] : _match\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\t// Single-quoted: only unescape \\\\ and \\'\r\n\t\t\t\tinner = inner.replace(/\\\\'/g, \"'\").replace(/\\\\\\\\/g, \"\\\\\");\r\n\t\t\t}\r\n\t\t\treturn inner;\r\n\t\t}\r\n\t}\r\n\r\n\t// Fallback for other node types (identifiers, etc.)\r\n\treturn node.text;\r\n}\r\n\r\n/**\r\n * Parses the source code using the specified language parser and extracts the strings from the file.\r\n *\r\n * @param {string} sourceCode - The source code to be parsed.\r\n * @param {string} filepath - The path to the file being parsed.\r\n * @param {boolean} debugEnabled - Whether debug mode is enabled.\r\n * @param {Args} args - The command line arguments, optional.\r\n * @return {SetOfBlocks} An array of translation strings.\r\n */\r\nexport function doTree(\r\n\tsourceCode: string,\r\n\tfilepath: string,\r\n\tdebugEnabled?: boolean,\r\n\targs?: Args,\r\n): SetOfBlocks {\r\n\t// set up the parser\r\n\tconst parser = new Parser();\r\n\tconst parserExt = getParser(filepath);\r\n\r\n\t// if no parser is found return empty\r\n\tif (!parserExt) return new SetOfBlocks([], filepath);\r\n\r\n\t// set the parser language\r\n\tparser.setLanguage(parserExt);\r\n\r\n\t// set up the translation object\r\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\r\n\r\n\tconst typeToMatch =\r\n\t\tfilepath.split(\".\").pop()?.toLowerCase() !== \"php\"\r\n\t\t\t? \"call_expression\"\r\n\t\t\t: \"function_call_expression\";\r\n\r\n\tconst stringType = [\r\n\t\t\"name\",\r\n\t\t\"string\",\r\n\t\t\"string_value\",\r\n\t\t\"variable_name\",\r\n\t\t\"binary_expression\",\r\n\t\t\"member_expression\",\r\n\t\t\"subscript_expression\",\r\n\t\t\"shell_command_expression\",\r\n\t\t\"function_call_expression\",\r\n\t\t\"encapsed_string\",\r\n\t];\r\n\r\n\t/**\r\n\t * Traverse the tree \uD83C\uDF33\r\n\t *\r\n\t * @param {SyntaxNode} node The node to traverse through\r\n\t */\r\n\tfunction traverse(node: SyntaxNode): void {\r\n\t\t// Walk the tree\r\n\t\tif (node?.children.length) {\r\n\t\t\tfor (const child of node.children) {\r\n\t\t\t\ttraverse(child);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Check if the node matches\r\n\t\tif (node?.type === typeToMatch) {\r\n\t\t\t// The function name is the first child\r\n\t\t\tconst functionName = node.firstChild?.text ?? null;\r\n\t\t\tif (\r\n\t\t\t\tfunctionName === null ||\r\n\t\t\t\t!Object.keys(i18nFunctions).includes(functionName)\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// The arguments are the last child\r\n\t\t\tconst argsNode = node.childForFieldName(\"arguments\");\r\n\t\t\tif (\r\n\t\t\t\targsNode === null ||\r\n\t\t\t\targsNode.childCount === 0 ||\r\n\t\t\t\targsNode.type !== \"arguments\"\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// Safety check: verify we actually have an arguments node\r\n\t\t\tif (!argsNode) return;\r\n\r\n\t\t\tconst translation: Partial<{\r\n\t\t\t\tmsgctxt: string;\r\n\t\t\t\tmsgid: string;\r\n\t\t\t\tmsgid_plural: string;\r\n\t\t\t\tnumber: string;\r\n\t\t\t\tmsgstr: string;\r\n\t\t\t\ttext_domain: string;\r\n\t\t\t}> = {\r\n\t\t\t\t// WordPress default text domain is 'default'\r\n\t\t\t\ttext_domain: 'default',\r\n\t\t\t};\r\n\r\n\t\t\tconst translationKeys =\r\n\t\t\t\ti18nFunctions[functionName as keyof typeof i18nFunctions];\r\n\r\n\t\t\t// Slice the children to skip the opening and closing parentheses/brackets or process them directly\r\n\t\t\t// We iterate over all children and handle them based on type\r\n\t\t\tconst children = argsNode.children;\r\n\t\t\tlet translationKeyIndex = 0;\r\n\r\n\t\t\t// Get the translation from the arguments\r\n\t\t\tfor (const child of children) {\r\n\t\t\t\tlet node = child;\r\n\r\n\t\t\t\t// Skip parentheses and commas\r\n\t\t\t\tif (\r\n\t\t\t\t\tnode.type === \"(\" ||\r\n\t\t\t\t\tnode.type === \")\" ||\r\n\t\t\t\t\tnode.type === \",\" ||\r\n\t\t\t\t\tnode.type === \"[\" ||\r\n\t\t\t\t\tnode.type === \"]\"\r\n\t\t\t\t) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Skip comments\r\n\t\t\t\tif (node.type === \"comment\") {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// unwrap the argument node, which is used in PHP.\r\n\t\t\t\tif (child.type === \"argument\") {\r\n\t\t\t\t\tif (child.children.length === 0) continue;\r\n\r\n\t\t\t\t\t// Check if this is a named argument\r\n\t\t\t\t\tconst nameNode = child.childForFieldName(\"name\");\r\n\r\n\t\t\t\t\t// Iterate over children to find the value\r\n\t\t\t\t\t// The value is the child that is NOT the name node, not a comment, and not punctuation.\r\n\t\t\t\t\tlet foundValue = false;\r\n\t\t\t\t\tfor (const argChild of child.children) {\r\n\t\t\t\t\t\tif (argChild.id === nameNode?.id) {\r\n\t\t\t\t\t\t\tcontinue; // Skip the name label\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (argChild.type === \"comment\" || argChild.type === \":\") {\r\n\t\t\t\t\t\t\tcontinue; // Skip comments and colon\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t// Found the value!\r\n\t\t\t\t\t\tnode = argChild;\r\n\t\t\t\t\t\tfoundValue = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If we didn't find a value (e.g. only comments?), skip this argument\r\n\t\t\t\t\tif (!foundValue) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Stop if we have more arguments than keys defined\r\n\t\t\t\tif (translationKeyIndex >= translationKeys.length) {\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the translation key (eg. msgid)\r\n\t\t\t\tconst currentKey = translationKeys[\r\n\t\t\t\t\ttranslationKeyIndex\r\n\t\t\t\t] as keyof typeof translation;\r\n\r\n\t\t\t\t// Resolve the value using our new function (handles quotes and escapes)\r\n\t\t\t\tlet nodeValue: string = resolveStringValue(node);\r\n\r\n\t\t\t\tif (currentKey === 'number') {\r\n\t\t\t\t\t// `number` accepts any value, this will not be provided in the POT file\r\n\t\t\t\t\tnodeValue = node.text;\r\n\t\t\t\t} else if (!node?.type || !stringType.includes(node.type)) {\r\n\t\t\t\t\t// Whenever we get an unexpected node type this string is not translatable and should be skipped\r\n\t\t\t\t\tif (debugEnabled) {\r\n\t\t\t\t\t\tconsole.error(\r\n\t\t\t\t\t\t\t`Unexpected node type ${node?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node.startPosition.row + 1} pos ${node.startPosition.column + 1}`,\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn; // Parse error, skip this translation.\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the value of that key\r\n\t\t\t\ttranslation[currentKey] = nodeValue;\r\n\r\n\t\t\t\t// increment the index of the translation key\r\n\t\t\t\ttranslationKeyIndex += 1;\r\n\t\t\t}\r\n\r\n\t\t\t// Check if domain matches the requested domain filter\r\n\t\t\tif (\r\n\t\t\t\tArray.isArray(args?.options?.translationDomains) &&\r\n\t\t\t\ttranslation.text_domain &&\r\n\t\t\t\t!args.options.translationDomains.includes(translation.text_domain)\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst comments = collectComments(node); // Pass the CallExpression node, collectComments walks up\r\n\r\n\t\t\t// Get the translation data\r\n\t\t\tconst block = new Block({\r\n\t\t\t\tmsgctxt: translation.msgctxt,\r\n\t\t\t\tmsgid: translation.msgid ?? \"\",\r\n\t\t\t\tmsgid_plural: translation.msgid_plural,\r\n\t\t\t\tmsgstr: translation.msgid_plural ? [\"\", \"\"] : [\"\"],\r\n\t\t\t\tcomments: {\r\n\t\t\t\t\ttranslator: comments ? [comments] : undefined,\r\n\t\t\t\t\treference: [\r\n\t\t\t\t\t\t`${reverseSlashes(filepath)}:${node.startPosition.row + 1}`,\r\n\t\t\t\t\t],\r\n\t\t\t\t},\r\n\t\t\t} as Block);\r\n\r\n\t\t\tgettextTranslations.add(block);\r\n\t\t}\r\n\t}\r\n\r\n\ttry {\r\n\t\tif (sourceCode) {\r\n\t\t\tconst fileSize = Buffer.byteLength(sourceCode, \"utf8\");\r\n\t\t\tlet bufferSize = 1024 * 32; // 32 KB default buffer size\r\n\r\n\t\t\tif (fileSize >= bufferSize) {\r\n\t\t\t\tbufferSize = fileSize + 32; // dynamic buffer size with 32 bytes of padding\r\n\t\t\t}\r\n\r\n\t\t\tif (fileSize >= 1024 * 1024 * 2) {\r\n\t\t\t\tconsole.warn(`File size warning: ${filepath} exceeds 2 MB.`);\r\n\t\t\t}\r\n\r\n\t\t\t// parse the file\r\n\t\t\tconst tree = parser.parse(sourceCode, undefined, { bufferSize });\r\n\t\t\tif (tree) {\r\n\t\t\t\ttraverse(tree.rootNode);\r\n\t\t\t}\r\n\t\t}\r\n\t} catch (e) {\r\n\t\tconsole.error(`Failed to parse ${filepath}: ${e}`);\r\n\t}\r\n\r\n\t// Return both matches and entries\r\n\treturn gettextTranslations;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAA8B;AAC9B,4BAAmC;AACnC,kBAA0B;AAC1B,oBAAuD;AASvD,SAAS,gBAAgB,MAAsC;AAC9D,MAAI,cAAiC;AACrC,MAAI,QAAQ;AAGZ,SAAO,eAAe,QAAQ,GAAG;AAChC,QACC,YAAY,iBAAiB,SAAS,aACtC,YAAY,gBAAgB,KAAK,YAAY,EAAE,SAAS,aAAa,GACpE;AACD,iBAAO,sCAAuB,YAAY,gBAAgB,IAAI;AAAA,IAC/D;AACA;AACA,kBAAc,YAAY;AAAA,EAC3B;AACA,SAAO;AACR;AAMA,MAAM,YAAoC;AAAA,EACzC,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AASA,SAAS,mBAAmB,MAA0B;AAErD,MAAI,KAAK,SAAS,mBAAmB;AACpC,WAAO,KAAK,SACV,IAAI,CAAC,UAAU;AACf,UAAI,MAAM,SAAS,mBAAmB;AAErC,cAAM,KAAK,MAAM,KAAK,MAAM,CAAC;AAC7B,eAAO,MAA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AAA,MAC5D;AAGA,YAAM,OAAO,OAAO,MAAM,YAAY,QAAW,EAAE,WAAW,CAAC;AAC/D,UAAI,MAAM;AACT,iBAAS,KAAK,QAAQ;AAAA,MACvB;AAAA,IACD;AAAA,EACD,SAAS,GAAG;AACX,YAAQ,MAAM,mBAAmB,QAAQ,KAAK,CAAC,EAAE;AAAA,EAClD;AAGA,SAAO;AACR;",
6
6
  "names": ["Parser", "node"]
7
7
  }
package/lib/types.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.ts"],
4
- "sourcesContent": ["import type { GetTextTranslation } from \"gettext-parser\";\r\nimport type { pkgJsonHeaders, pluginHeaders, themeHeaders } from \"./const.js\";\r\n\r\nexport type ThemeHeadersType = typeof themeHeaders;\r\nexport type PluginHeadersType = typeof pluginHeaders;\r\nexport type PkgHeadersType = typeof pkgJsonHeaders;\r\n\r\n/**\r\n * The args headers Object types\r\n */\r\nexport type PotHeaders =\r\n\t| keyof PkgHeadersType\r\n\t| keyof PluginHeadersType\r\n\t| keyof ThemeHeadersType\r\n\t| \"license\"\r\n\t| \"email\"\r\n\t| \"language\"\r\n\t| \"domain\"\r\n\t| \"bugs\";\r\n\r\n// type is the value of the themeHeader Object\r\nexport type DomainType =\r\n\t| \"plugin\"\r\n\t| \"theme\"\r\n\t| \"block\"\r\n\t| \"theme-block\"\r\n\t| \"generic\";\r\n\r\n/**\r\n * The patterns to use when extracting strings from files.\r\n *\r\n * @param {string} mergePaths - Comma-separated list of POT files whose contents should be merged with the extracted strings.\r\n * If left empty, defaults to the destination POT file. POT file headers will be ignored.\r\n * @param {string} subtractPaths - Comma-separated list of POT files whose contents should act as some sort of denylist\r\n * for string extraction. Any string which is found on that denylist will not be extracted. This can be useful when\r\n * you want to create multiple POT files from the same source directory with slightly different content and no duplicate\r\n * strings between them.\r\n * @param {boolean} subtractAndMerge - Whether source code references and comments from the generated POT file should be\r\n * instead added to the POT file used for subtraction. Warning: this modifies the files passed to `subtractPaths`!\r\n * @param {string} include - Comma-separated list of files and paths that should be used for string extraction.\r\n * If provided, only these files and folders will be taken into account for string extraction.\r\n * For example, `--include=\"src,my-file.php` will ignore anything besides `my-file.php` and files in the `src`\r\n * directory. Simple glob patterns can be used, i.e. `--include=foo-*.php` includes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * @param {string} exclude - Comma-separated list of files and paths that should be skipped for string extraction.\r\n * For example, `--exclude=.github,myfile.php` would ignore any strings found within `myfile.php` or the `.github`\r\n * folder. Simple glob patterns can be used, i.e. `--exclude=foo-*.php` excludes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * The following files and folders are always excluded: node_modules, .git, .svn, .CVS, .hg, vendor, *.min.js.\r\n */\r\nexport interface Patterns {\r\n\tmergePaths?: string[];\r\n\tsubtractPaths?: string[];\r\n\tsubtractAndMerge?: boolean;\r\n\tinclude: string[];\r\n\texclude: string[];\r\n}\r\n\r\n/**\r\n * Create a POT file for a WordPress project.\r\n *\r\n * Scans PHP, Blade-PHP, and JavaScript files for translatable strings, as well as theme stylesheets and plugin files\r\n * if the source directory is detected as either a plugin or theme.\r\n *\r\n * @param {string} sourceDirectory - Directory to scan for string extraction.\r\n * @param {string} destination - Name of the resulting POT file.\r\n * @param {string | undefined} slug - Plugin or theme slug. Defaults to the source directory's basename.\r\n * @param {'plugin' | 'theme' | 'block' | 'theme-block' | 'generic'} domain - Text domain to look for in the source code,\r\n * unless the `ignoreDomain` option is used. By default, the \"Text Domain\" header of the plugin or theme is used.\r\n * If none is provided, it falls back to the project slug.\r\n * @param {boolean} ignoreDomain - Ignore the text domain completely and extract strings with any text domain.\r\n * @param {{}} headers - Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.\r\n * @param {boolean} location - Whether to write `#: filename:line` lines. Defaults to true, use `--no-location`\r\n * to skip the removal. Note that disabling this option makes it harder for technically skilled translators\r\n * to understand each message\u2019s context.\r\n * @param {boolean} skipJs - Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.\r\n * @param {boolean} skipPhp - Skips PHP string extraction.\r\n * @param {boolean} skipBlade - Skips Blade-PHP string extraction.\r\n * @param {boolean} skipBlockJson - Skips string extraction from block.json files.\r\n * @param {boolean} skipThemeJson - Skips string extraction from theme.json files.\r\n * @param {boolean} skipAudit - Skips string audit where it tries to find possible mistakes in translatable strings.\r\n * Useful when running in an automated environment.\r\n * @param {string} fileComment - String that should be added as a comment to the top of the resulting POT file.\r\n * By default, a copyright comment is added for WordPress plugins and themes.\r\n * @param {string} packageName - Name to use for the package name in the resulting POT file's `Project-Id-Version` header.\r\n * Overrides the plugin or theme name, if applicable.\r\n * @param {boolean} silent - Whether to hide progress information.\r\n */\r\nexport interface Args {\r\n\tslug: string;\r\n\tdebug: boolean;\r\n\tdomain: DomainType;\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout: string;\r\n\t\troot?: string;\r\n\t};\r\n\toptions?: {\r\n\t\tignoreDomain?: boolean;\r\n\t\tsilent?: boolean;\r\n\t\tjson?: boolean;\r\n\t\tlocation?: boolean;\r\n\t\tpackageName?: string;\r\n\t\theaders: { [key in PotHeaders]: string };\r\n\t\toutput?: boolean;\r\n\t\tfileComment?: string;\r\n\t\tcharset?: string;\r\n\t\tskip: {\r\n\t\t\tjs?: boolean;\r\n\t\t\tphp?: boolean;\r\n\t\t\tblade?: boolean;\r\n\t\t\tblockJson?: boolean;\r\n\t\t\tthemeJson?: boolean;\r\n\t\t\taudit?: boolean;\r\n\t\t};\r\n\t\ttranslationDomains?: string[];\r\n\t};\r\n\theaders?: { [key in PotHeaders]: string };\r\n\tpatterns: Patterns;\r\n}\r\n\r\n/**\r\n * The arguments for the `makeJson` command.\r\n * \t@param {string} source the source directory\r\n * \t@param {string | null} destination the destination directory (defaults to source)\r\n * \t@param {string[] | null} allowedFormats the allowed files\r\n * \t@param {boolean} purge remove old json files (otherwise the content will be merged)\r\n * \t@param {boolean} prettyPrint?: pretty print json\r\n * \t@param {boolean} debug: enable debug mode\r\n */\r\nexport interface MakeJsonArgs {\r\n\ttimeStart: number;\r\n\tprettyPrint: boolean;\r\n\tdebug: boolean;\r\n\tdestination: string;\r\n\tscriptName?: string;\r\n\tpurge: boolean;\r\n\tstripUnused: boolean;\r\n\tsource: string;\r\n\tslug: string;\r\n\tallowedFormats?: string[];\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout?: string;\r\n\t\troot?: string;\r\n\t};\r\n}\r\n\r\nexport interface I18nSchema {\r\n\t[key: string]: string | string[] | I18nSchema | I18nSchema[];\r\n}\r\n\r\n/**\r\n * Translation string metadata.\r\n * Gettext format: https://www.gnu.org/savannah-checkouts/gnu/gettext/FAQ.html\r\n *\r\n * @property {string} msgctxt - context for this translation, if not present the default context applies\r\n * @property {string} msgid - string to be translated\r\n * @property {string} msgid_plural the plural form of the original string (might not be present)\r\n * @property {string[]} msgstr an array of translations\r\n * @property {{}} comments an object with the following properties: translator, reference, extracted, flag, previous.\r\n */\r\nexport interface TranslationStrings {\r\n\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n}\r\n\r\n/** The header of the JED file. */\r\nexport interface JedHeader {\r\n\tdomain: string;\r\n\tlang: string;\r\n\tplural_forms: string;\r\n\t[key: string]: string;\r\n}\r\n\r\n/**\r\n * The JSON data returned by the `makeJson` command.\r\n * @param {string} domain\r\n * @param {Record<string, string | string[] | JedHeader>} locale_data\r\n */\r\nexport interface JedData {\r\n\t[domain: string]: {\r\n\t\t[key: string]: string | string[] | JedHeader;\r\n\t};\r\n}\r\n\r\nexport interface MakeJson {\r\n\tdomain: string;\r\n\tgenerator: string;\r\n\t\"translation-revision-date\": string;\r\n\tsource: string;\r\n\tlocale_data: JedData;\r\n}\r\n\r\n/**\r\n * The header data of the current plugin / theme as returned by the `extractHeaders` command.\r\n */\r\nexport interface I18nHeaders {\r\n\tname: string;\r\n\tauthorString: string;\r\n\tbugs: string;\r\n\tlicense: string;\r\n\tauthor?: string;\r\n\txDomain: string;\r\n\tlanguage: string;\r\n\tversion: string;\r\n\tslug: string;\r\n\temail: string | undefined;\r\n}\r\n"],
4
+ "sourcesContent": ["import type { GetTextTranslation } from \"gettext-parser\";\r\nimport type { pkgJsonHeaders, pluginHeaders, themeHeaders } from \"./const.js\";\r\n\r\nexport type ThemeHeadersType = typeof themeHeaders;\r\nexport type PluginHeadersType = typeof pluginHeaders;\r\nexport type PkgHeadersType = typeof pkgJsonHeaders;\r\n\r\n/**\r\n * The args headers Object types\r\n */\r\nexport type PotHeaders =\r\n\t| keyof PkgHeadersType\r\n\t| keyof PluginHeadersType\r\n\t| keyof ThemeHeadersType\r\n\t| \"license\"\r\n\t| \"email\"\r\n\t| \"language\"\r\n\t| \"domain\"\r\n\t| \"bugs\";\r\n\r\n// type is the value of the themeHeader Object\r\nexport type DomainType =\r\n\t| \"plugin\"\r\n\t| \"theme\"\r\n\t| \"block\"\r\n\t| \"theme-block\"\r\n\t| \"generic\";\r\n\r\n/**\r\n * The patterns to use when extracting strings from files.\r\n *\r\n * @param {string} mergePaths - Comma-separated list of POT files whose contents should be merged with the extracted strings.\r\n * If left empty, defaults to the destination POT file. POT file headers will be ignored.\r\n * @param {string} subtractPaths - Comma-separated list of POT files whose contents should act as some sort of denylist\r\n * for string extraction. Any string which is found on that denylist will not be extracted. This can be useful when\r\n * you want to create multiple POT files from the same source directory with slightly different content and no duplicate\r\n * strings between them.\r\n * @param {boolean} subtractAndMerge - Whether source code references and comments from the generated POT file should be\r\n * instead added to the POT file used for subtraction. Warning: this modifies the files passed to `subtractPaths`!\r\n * @param {string} include - Comma-separated list of files and paths that should be used for string extraction.\r\n * If provided, only these files and folders will be taken into account for string extraction.\r\n * For example, `--include=\"src,my-file.php` will ignore anything besides `my-file.php` and files in the `src`\r\n * directory. Simple glob patterns can be used, i.e. `--include=foo-*.php` includes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * @param {string} exclude - Comma-separated list of files and paths that should be skipped for string extraction.\r\n * For example, `--exclude=.github,myfile.php` would ignore any strings found within `myfile.php` or the `.github`\r\n * folder. Simple glob patterns can be used, i.e. `--exclude=foo-*.php` excludes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * The following files and folders are always excluded: node_modules, .git, .svn, .CVS, .hg, vendor, *.min.js.\r\n */\r\nexport interface Patterns {\r\n\tmergePaths?: string[];\r\n\tsubtractPaths?: string[];\r\n\tsubtractAndMerge?: boolean;\r\n\tinclude: string[];\r\n\texclude: string[];\r\n}\r\n\r\n/**\r\n * Create a POT file for a WordPress project.\r\n *\r\n * Scans PHP, Blade-PHP, and JavaScript files for translatable strings, as well as theme stylesheets and plugin files\r\n * if the source directory is detected as either a plugin or theme.\r\n *\r\n * @param {string} sourceDirectory - Directory to scan for string extraction.\r\n * @param {string} destination - Name of the resulting POT file.\r\n * @param {string | undefined} slug - Plugin or theme slug. Defaults to the source directory's basename.\r\n * @param {'plugin' | 'theme' | 'block' | 'theme-block' | 'generic'} domain - Text domain to look for in the source code,\r\n * unless the `ignoreDomain` option is used. By default, the \"Text Domain\" header of the plugin or theme is used.\r\n * If none is provided, it falls back to the project slug.\r\n * @param {boolean} ignoreDomain - Ignore the text domain completely and extract strings with any text domain.\r\n * @param {{}} headers - Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.\r\n * @param {boolean} location - Whether to write `#: filename:line` lines. Defaults to true, use `--no-location`\r\n * to skip the removal. Note that disabling this option makes it harder for technically skilled translators\r\n * to understand each message\u2019s context.\r\n * @param {boolean} skipJs - Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.\r\n * @param {boolean} skipPhp - Skips PHP string extraction.\r\n * @param {boolean} skipBlade - Skips Blade-PHP string extraction.\r\n * @param {boolean} skipBlockJson - Skips string extraction from block.json files.\r\n * @param {boolean} skipThemeJson - Skips string extraction from theme.json files.\r\n * @param {boolean} skipAudit - Skips string audit where it tries to find possible mistakes in translatable strings.\r\n * Useful when running in an automated environment.\r\n * @param {string} fileComment - String that should be added as a comment to the top of the resulting POT file.\r\n * By default, a copyright comment is added for WordPress plugins and themes.\r\n * @param {string} packageName - Name to use for the package name in the resulting POT file's `Project-Id-Version` header.\r\n * Overrides the plugin or theme name, if applicable.\r\n * @param {boolean} silent - Whether to hide progress information.\r\n */\r\nexport interface Args {\r\n\tslug: string;\r\n\tdebug: boolean;\r\n\tdomain: DomainType;\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout: string;\r\n\t\troot?: string;\r\n\t};\r\n\toptions?: {\r\n\t\tignoreDomain?: boolean;\r\n\t\tsilent?: boolean;\r\n\t\tjson?: boolean;\r\n\t\tlocation?: boolean;\r\n\t\tpackageName?: string;\r\n\t\theaders: { [key in PotHeaders]: string };\r\n\t\toutput?: boolean;\r\n\t\ttheme?: boolean;\r\n\t\tfileComment?: string;\r\n\t\tcharset?: string;\r\n\t\tskip: {\r\n\t\t\tjs?: boolean;\r\n\t\t\tphp?: boolean;\r\n\t\t\tblade?: boolean;\r\n\t\t\tblockJson?: boolean;\r\n\t\t\tthemeJson?: boolean;\r\n\t\t\taudit?: boolean;\r\n\t\t};\r\n\t\ttranslationDomains?: string[];\r\n\t};\r\n\theaders?: { [key in PotHeaders]: string };\r\n\tpatterns: Patterns;\r\n}\r\n\r\n/**\r\n * The arguments for the `makeJson` command.\r\n * \t@param {string} source the source directory\r\n * \t@param {string | null} destination the destination directory (defaults to source)\r\n * \t@param {string[] | null} allowedFormats the allowed files\r\n * \t@param {boolean} purge remove old json files (otherwise the content will be merged)\r\n * \t@param {boolean} prettyPrint?: pretty print json\r\n * \t@param {boolean} debug: enable debug mode\r\n */\r\nexport interface MakeJsonArgs {\r\n\ttimeStart: number;\r\n\tprettyPrint: boolean;\r\n\tdebug: boolean;\r\n\tdestination: string;\r\n\tscriptName?: string;\r\n\tpurge: boolean;\r\n\tstripUnused: boolean;\r\n\tsource: string;\r\n\tslug: string;\r\n\tallowedFormats?: string[];\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout?: string;\r\n\t\troot?: string;\r\n\t};\r\n}\r\n\r\nexport interface I18nSchema {\r\n\t[key: string]: string | string[] | I18nSchema | I18nSchema[];\r\n}\r\n\r\n/**\r\n * Translation string metadata.\r\n * Gettext format: https://www.gnu.org/savannah-checkouts/gnu/gettext/FAQ.html\r\n *\r\n * @property {string} msgctxt - context for this translation, if not present the default context applies\r\n * @property {string} msgid - string to be translated\r\n * @property {string} msgid_plural the plural form of the original string (might not be present)\r\n * @property {string[]} msgstr an array of translations\r\n * @property {{}} comments an object with the following properties: translator, reference, extracted, flag, previous.\r\n */\r\nexport interface TranslationStrings {\r\n\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n}\r\n\r\n/** The header of the JED file. */\r\nexport interface JedHeader {\r\n\tdomain: string;\r\n\tlang: string;\r\n\tplural_forms: string;\r\n\t[key: string]: string;\r\n}\r\n\r\n/**\r\n * The JSON data returned by the `makeJson` command.\r\n * @param {string} domain\r\n * @param {Record<string, string | string[] | JedHeader>} locale_data\r\n */\r\nexport interface JedData {\r\n\t[domain: string]: {\r\n\t\t[key: string]: string | string[] | JedHeader;\r\n\t};\r\n}\r\n\r\nexport interface MakeJson {\r\n\tdomain: string;\r\n\tgenerator: string;\r\n\t\"translation-revision-date\": string;\r\n\tsource: string;\r\n\tlocale_data: JedData;\r\n}\r\n\r\n/**\r\n * The header data of the current plugin / theme as returned by the `extractHeaders` command.\r\n */\r\nexport interface I18nHeaders {\r\n\tname: string;\r\n\tauthorString: string;\r\n\tbugs: string;\r\n\tlicense: string;\r\n\tauthor?: string;\r\n\txDomain: string;\r\n\tlanguage: string;\r\n\tversion: string;\r\n\tslug: string;\r\n\temail: string | undefined;\r\n}\r\n\r\nexport interface AuthorData {\r\n\tname: string;\r\n\temail?: string;\r\n\twebsite?: string;\r\n}\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
- "use strict";var m=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},p=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!k.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=d(e,r))||o.enumerable});return t};var a=(t,e,n)=>(n=t!=null?m(h(t)):{},p(e||!t||!t.__esModule?s(n,"default",{value:t,enumerable:!0}):n,t)),$=t=>p(s({},"__esModule",{value:!0}),t);var B={};y(B,{detectPatternType:()=>M,getCommentBlock:()=>P,getCopyright:()=>b,getFileExtension:()=>T,getPkgJsonData:()=>f,outputPathRecap:()=>U,printModuleInfo:()=>w,printStats:()=>j,printTimeElapsed:()=>D,removeCommentMarkup:()=>F,reverseSlashes:()=>v,stringstring:()=>C,stripTranslationMarkup:()=>S});module.exports=$(B);var g=a(require("node:fs")),i=require("node:os"),u=a(require("node:path")),l=require("../const.js");function P(t){const e=t.match(/\/\*\*?[\s\S]*?\*\//);return e!==null?e[0]:t}function F(t){return t.match(/[a-zA-Z].*/gm)}function S(t){const e=/\/\*\*?\s*(?:translators:)\s*([\s\S]*?)\s*\*\/|\/\/\s*(?:translators:)\s*(.*)$/i,n=t.match(e);return n?n[1]:t}function C(t){return typeof t=="string"?t.includes(",")?t.split(","):[t]:[]}function M(t){const e=t.includes("."),n=t.includes(u.default.sep);return t.includes("*")?"glob":!e&&!n?"directory":e&&!n?"file":"glob"}function T(t){return t.endsWith(".blade.php")?"blade.php":t.split(".").pop()||""}function b(t,e="GPL v2 or later"){return`# Copyright (C) ${new Date().getFullYear()} ${t}
2
- # This file is distributed under the ${e} license.`}function v(t){return t.replace(/\\/g,"/")}function f(t,...e){const n={},o=u.default.join(t||process.cwd(),"package.json"),r=g.default.existsSync(o)?require(o):{};for(const c of e)r[c]&&(n[c]=r[c]);return n}function w(){const{version:t,name:e}=f(l.modulePath,"name","version");console.log(`${e} version: ${t}`)}function D(t,e,n=new Date){console.log(`
1
+ "use strict";var m=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},u=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!k.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=d(e,r))||o.enumerable});return t};var p=(t,e,n)=>(n=t!=null?m(h(t)):{},u(e||!t||!t.__esModule?s(n,"default",{value:t,enumerable:!0}):n,t)),$=t=>u(s({},"__esModule",{value:!0}),t);var B={};y(B,{detectPatternType:()=>M,getCommentBlock:()=>P,getCopyright:()=>b,getFileExtension:()=>T,getPkgJsonData:()=>f,outputPathRecap:()=>U,printModuleInfo:()=>w,printStats:()=>j,printTimeElapsed:()=>D,removeCommentMarkup:()=>F,reverseSlashes:()=>v,stringstring:()=>C,stripTranslationMarkup:()=>S});module.exports=$(B);var a=p(require("node:fs")),i=require("node:os"),g=p(require("node:path")),l=require("../const.js");function P(t){const e=t.match(/\/\*\*?[\s\S]*?\*\//);return e!==null?e[0]:t}function F(t){return t.match(/[a-zA-Z].*/gm)}function S(t){const e=/\/\*\*?\s*(?:translators:)\s*([\s\S]*?)\s*\*\/|\/\/\s*(?:translators:)\s*(.*)$/i,n=t.match(e);return n?n[1]:t}function C(t){return typeof t=="string"?t.includes(",")?t.split(","):[t]:[]}function M(t){const e=t.includes("."),n=t.includes("/");return t.includes("*")?"glob":!e&&!n?"directory":e&&!n?"file":"glob"}function T(t){return t.endsWith(".blade.php")?"blade.php":t.split(".").pop()||""}function b(t,e="GPL v2 or later"){return`# Copyright (C) ${new Date().getFullYear()} ${t}
2
+ # This file is distributed under the ${e} license.`}function v(t){return t.replace(/\\/g,"/")}function f(t,...e){const n={},o=g.default.join(t||process.cwd(),"package.json"),r=a.default.existsSync(o)?require(o):{};for(const c of e)r[c]&&(n[c]=r[c]);return n}function w(){const{version:t,name:e}=f(l.modulePath,"name","version");console.log(`${e} version: ${t}`)}function D(t,e,n=new Date){console.log(`
3
3
  \u{1F680} ${t}: Task completed! ${t.split("-")[1]} file created in ${n.getTime()-e.getTime()}ms`)}function j(){console.log("Memory usage:",(process.memoryUsage().heapUsed/1024/1024).toFixed(2),"MB (Free:",((0,i.totalmem)()/1024/1024/1024).toFixed(2),`GB)
4
4
  Cpu User:`,(process.cpuUsage().user/1e6).toFixed(2),"ms Cpu System:",(process.cpuUsage().system/1e6).toFixed(2),"ms of",(0,i.cpus)().length,"cores")}function U(t,e){return`
5
5
  Script Path: ${t}