@wp-blocks/make-pot 1.6.4 → 1.6.6

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 (55) hide show
  1. package/README.md +2 -2
  2. package/lib/assets/block-i18n.js +41 -1
  3. package/lib/assets/package-i18n.js +38 -1
  4. package/lib/assets/theme-i18n.js +110 -1
  5. package/lib/assets/wp-plugin-i18n.js +39 -1
  6. package/lib/assets/wp-theme-i18n.js +37 -1
  7. package/lib/cli/getArgs.js +156 -1
  8. package/lib/cli/getArgs.js.map +2 -2
  9. package/lib/cli/getJsonArgs.js +82 -1
  10. package/lib/cli/parseCli.js +179 -1
  11. package/lib/cli.js +43 -1
  12. package/lib/const.js +111 -1
  13. package/lib/const.js.map +1 -1
  14. package/lib/extractors/auditStrings.js +177 -6
  15. package/lib/extractors/auditStrings.js.map +2 -2
  16. package/lib/extractors/css.js +69 -1
  17. package/lib/extractors/headers.js +253 -15
  18. package/lib/extractors/headers.js.map +2 -2
  19. package/lib/extractors/json.js +70 -1
  20. package/lib/extractors/packageJson.js +55 -1
  21. package/lib/extractors/php.js +79 -2
  22. package/lib/extractors/php.js.map +2 -2
  23. package/lib/extractors/schema.js +217 -3
  24. package/lib/extractors/text.js +41 -1
  25. package/lib/fs/fs.js +114 -2
  26. package/lib/fs/glob.js +103 -1
  27. package/lib/fs/glob.js.map +2 -2
  28. package/lib/index.js +64 -1
  29. package/lib/jsonCommand.js +51 -1
  30. package/lib/makeJson.js +28 -1
  31. package/lib/makePot.js +27 -1
  32. package/lib/parser/exec.js +94 -3
  33. package/lib/parser/exec.js.map +2 -2
  34. package/lib/parser/makeJson.js +393 -1
  35. package/lib/parser/makePot.js +48 -1
  36. package/lib/parser/patterns.js +54 -1
  37. package/lib/parser/process.js +85 -1
  38. package/lib/parser/process.js.map +2 -2
  39. package/lib/parser/progress.js +57 -1
  40. package/lib/parser/progress.js.map +2 -2
  41. package/lib/parser/taskRunner.js +65 -2
  42. package/lib/parser/taskRunner.js.map +2 -2
  43. package/lib/parser/tree.js +228 -2
  44. package/lib/parser/tree.js.map +2 -2
  45. package/lib/potCommand.js +36 -1
  46. package/lib/potCommand.js.map +2 -2
  47. package/lib/types.js +17 -1
  48. package/lib/types.js.map +1 -1
  49. package/lib/utils/common.js +161 -8
  50. package/lib/utils/common.js.map +2 -2
  51. package/lib/utils/extractors.js +69 -1
  52. package/lib/utils/output.js +59 -1
  53. package/lib/utils/output.js.map +3 -3
  54. package/package.json +3 -3
  55. package/tests/parse-php.test.js +47 -0
@@ -1 +1,57 @@
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";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var progress_exports = {};
30
+ __export(progress_exports, {
31
+ initProgress: () => initProgress
32
+ });
33
+ module.exports = __toCommonJS(progress_exports);
34
+ var import_cli_progress = __toESM(require("cli-progress"));
35
+ function initProgress(_args, _filesCount) {
36
+ const FILENAME_WIDTH = 40;
37
+ return new import_cli_progress.default.SingleBar(
38
+ {
39
+ clearOnComplete: true,
40
+ etaBuffer: 1e3,
41
+ hideCursor: true,
42
+ format: (options, params, payload) => {
43
+ const bar = options.barCompleteString?.substring(0, Math.round(params.progress * (options.barsize ?? 40))) ?? "";
44
+ const emptyBar = options.barIncompleteString?.substring(0, (options.barsize ?? 40) - bar.length) ?? "";
45
+ const pct = Math.round(params.progress * 100);
46
+ const filename = (payload.filename || "").substring(0, FILENAME_WIDTH).padEnd(FILENAME_WIDTH);
47
+ return ` ${bar}${emptyBar} ${pct}% | ETA: ${params.eta}s | ${filename} | ${params.value}/${params.total}`;
48
+ }
49
+ },
50
+ import_cli_progress.default.Presets.shades_classic
51
+ );
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ initProgress
56
+ });
57
+ //# sourceMappingURL=progress.js.map
@@ -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,OAAa,aAAgC;AAEzE,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,65 @@
1
- "use strict";var u=Object.create;var i=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var d=(t,s)=>{for(var o in s)i(t,o,{get:s[o],enumerable:!0})},c=(t,s,o,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let e of k(s))!S.call(t,e)&&e!==o&&i(t,e,{get:()=>s[e],enumerable:!(l=h(s,e))||l.enumerable});return t};var p=(t,s,o)=>(o=t!=null?u(y(t)):{},c(s||!t||!t.__esModule?i(o,"default",{value:t,enumerable:!0}):o,t)),B=t=>c(i({},"__esModule",{value:!0}),t);var b={};d(b,{taskRunner:()=>$});module.exports=B(b);var O=p(require("node:os")),f=p(require("node:path"));async function $(t,s,o,l){const e=[],m=t.map(n=>n.finally(()=>{l.increment()}));return await Promise.allSettled(m).then(n=>n.map(r=>r.status==="fulfilled"&&r.value).filter(Boolean)).then(n=>{for(const r of n)if(r.blocks.length>0){s.addArray(r.blocks);const a=r.blocks.map(g=>g.msgid);o.options?.silent!==!0&&e.push(`\u2705 ${r.path} - ${a.length} strings found [${a.join(", ")}]`)}else o.options?.silent!==!0&&e.push(`\u274C ${r.path} - has no strings`)}).catch(n=>new Error(n)),l.stop(),console.log(`
2
- \u{1F389} Done!`),console.log(`\u{1F4DD} Found ${Object.values(s.blocks).length} translation strings in ${f.default.resolve(o.paths.cwd)}.`),console.log(e.join(O.EOL)),s}0&&(module.exports={taskRunner});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var taskRunner_exports = {};
30
+ __export(taskRunner_exports, {
31
+ taskRunner: () => taskRunner
32
+ });
33
+ module.exports = __toCommonJS(taskRunner_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ async function taskRunner(tasks, destination, args, progressBar) {
36
+ const tasksWithProgress = tasks.map(
37
+ (task) => task.then((result) => {
38
+ progressBar.increment({
39
+ filename: result.path ? import_node_path.default.basename(result.path) : ""
40
+ });
41
+ return result;
42
+ }).catch((err) => {
43
+ progressBar.increment({ filename: "error" });
44
+ throw err;
45
+ })
46
+ );
47
+ await Promise.allSettled(tasksWithProgress).then((strings) => {
48
+ return strings.map((block) => block.status === "fulfilled" && block.value).filter(Boolean);
49
+ }).then((consolidated) => {
50
+ for (const result of consolidated) {
51
+ if (result.blocks.length > 0) {
52
+ destination.addArray(result.blocks);
53
+ }
54
+ }
55
+ }).catch((err) => {
56
+ return new Error(err);
57
+ });
58
+ progressBar.stop();
59
+ return destination;
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ taskRunner
64
+ });
65
+ //# sourceMappingURL=taskRunner.js.map
@@ -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: string[] = [];\n\t// Create a new array of promises that update the bar when they finish.\n\tconst tasksWithProgress = tasks.map((task) =>\n\t\ttask.finally(() => {\n\t\t\tprogressBar.increment();\n\t\t})\n\t);\n\tawait Promise.allSettled(tasksWithProgress)\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\tfor (const result of consolidated) {\n\t\t\t\tif (result.blocks.length > 0) {\n\t\t\t\t\t/**\n\t\t\t\t\t * Add the strings to the destination set\n\t\t\t\t\t */\n\t\t\t\t\tdestination.addArray(result.blocks);\n\t\t\t\t\tconst strings = result.blocks.map((b) => b.msgid);\n\n\t\t\t\t\t/* Log the results */\n\t\t\t\t\tif (args.options?.silent !== true) {\n\t\t\t\t\t\tmessages.push(\n\t\t\t\t\t\t\t`\u2705 ${result.path} - ${strings.length} strings found [${strings.join(\", \")}]`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (args.options?.silent !== true) {\n\t\t\t\t\tmessages.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,WAAqB,CAAC;AAE5B,QAAM,oBAAoB,MAAM;AAAA,IAAI,CAAC,SACpC,KAAK,QAAQ,MAAM;AAClB,kBAAY,UAAU;AAAA,IACvB,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;",
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\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}\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\treturn destination;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AAED,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;AAAA,MACnC;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,SAAO;AACR;",
6
6
  "names": ["path"]
7
7
  }
@@ -1,2 +1,228 @@
1
- "use strict";var L=Object.create;var d=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of W(e))!z.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(l=O(e,o))||l.enumerable});return t};var M=(t,e,r)=>(r=t!=null?L(j(t)):{},k(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),V=t=>k(d({},"__esModule",{value:!0}),t);var I={};K(I,{doTree:()=>E});module.exports=V(I);var N=M(require("tree-sitter")),_=require("../const.js"),f=require("gettext-merger"),F=require("../fs/glob.js"),g=require("../utils/common.js");function D(t){let e=t,r=0;for(;e&&r<6;){if(e.previousSibling?.type==="comment"&&e.previousSibling.text.toLowerCase().includes("translators"))return(0,g.stripTranslationMarkup)(e.previousSibling.text);r++,e=e.parent}}function q(t){if(t.type==="encapsed_string")return t.children.map(e=>{if(e.type==="escape_sequence")switch(e.text){case"\\n":return`
2
- `;case"\\r":return"\r";case"\\t":return" ";case"\\\\":return"\\";case'\\"':return'"';case"\\$":return"$";case"\\e":return"\x1B";case"\\f":return"\f";case"\\v":return"\v";default:return e.text}return e.type==="string_content"||e.type==="variable_name"?e.text:""}).join("");if(t.type==="string"){const e=t.text;if(e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/\\'/g,"'").replace(/\\\\/g,"\\")}return t.text}function E(t,e,r,l){const o=new N.default,b=(0,F.getParser)(e);if(!b)return new f.SetOfBlocks([],e);o.setLanguage(b);const h=new f.SetOfBlocks([],e),B=e.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",P=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function S(s){if(s?.children.length)for(const i of s.children)S(i);if(s?.type===B){const i=s.firstChild?.text??null;if(i===null||!Object.keys(_.i18nFunctions).includes(i))return;const a=s.childForFieldName("arguments");if(a===null||a.childCount===0||a.type!=="arguments"||!a)return;const c={text_domain:"default"},y=_.i18nFunctions[i],T=a.children;let p=0;for(const u of T){let n=u;if(n.type==="("||n.type===")"||n.type===","||n.type==="["||n.type==="]"||n.type==="comment")continue;if(u.type==="argument"){if(u.children.length===0)continue;const C=u.childForFieldName("name");let $=!1;for(const m of u.children)if(m.id!==C?.id&&!(m.type==="comment"||m.type===":")){n=m,$=!0;break}if(!$)continue}if(p>=y.length)break;const w=y[p];let x=q(n);if(w==="number")x=n.text;else if(!n?.type||!P.includes(n.type)){r&&console.error(`Unexpected node type ${n?.type} identified as ${y[p]} with value ${x} in ${e} at ${n.startPosition.row+1} pos ${n.startPosition.column+1}`);return}c[w]=x,p+=1}if(Array.isArray(l?.options?.translationDomains)&&c.text_domain&&!l.options.translationDomains.includes(c.text_domain))return;const v=D(s),A=new f.Block({msgctxt:c.msgctxt,msgid:c.msgid??"",msgid_plural:c.msgid_plural,msgstr:c.msgid_plural?["",""]:[""],comments:{translator:v?[v]:void 0,reference:[`${(0,g.reverseSlashes)(e)}:${s.startPosition.row+1}`]}});h.add(A)}}try{if(t){const s=Buffer.byteLength(t,"utf8");let i=1024*32;s>=i&&(i=s+32),s>=1024*1024*2&&console.warn(`File size warning: ${e} exceeds 2 MB.`);const a=o.parse(t,void 0,{bufferSize:i});a&&S(a.rootNode)}}catch(s){console.error(`Failed to parse ${e}: ${s}`)}return h}0&&(module.exports={doTree});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var tree_exports = {};
30
+ __export(tree_exports, {
31
+ doTree: () => doTree
32
+ });
33
+ module.exports = __toCommonJS(tree_exports);
34
+ var import_tree_sitter = __toESM(require("tree-sitter"));
35
+ var import_const = require("../const.js");
36
+ var import_gettext_merger = require("gettext-merger");
37
+ var import_glob = require("../fs/glob.js");
38
+ var import_common = require("../utils/common.js");
39
+ function collectComments(node) {
40
+ let currentNode = node;
41
+ let depth = 0;
42
+ while (currentNode && depth < 6) {
43
+ if (currentNode.previousSibling?.type === "comment" && currentNode.previousSibling.text.toLowerCase().includes("translators")) {
44
+ return (0, import_common.stripTranslationMarkup)(currentNode.previousSibling.text);
45
+ }
46
+ depth++;
47
+ currentNode = currentNode.parent;
48
+ }
49
+ return void 0;
50
+ }
51
+ const escapeMap = {
52
+ "n": "\n",
53
+ "r": "\r",
54
+ "t": " ",
55
+ "f": "\f",
56
+ "v": "\v",
57
+ "0": "\0",
58
+ "\\": "\\",
59
+ '"': '"',
60
+ "'": "'",
61
+ "$": "$",
62
+ "e": "\x1B"
63
+ };
64
+ function resolveStringValue(node) {
65
+ if (node.type === "encapsed_string") {
66
+ return node.children.map((child) => {
67
+ if (child.type === "escape_sequence") {
68
+ const ch = child.text.slice(1);
69
+ return ch in escapeMap ? escapeMap[ch] : child.text;
70
+ }
71
+ if (child.type === "string_content") {
72
+ return child.text;
73
+ }
74
+ if (child.type === "variable_name") {
75
+ return child.text;
76
+ }
77
+ return "";
78
+ }).join("");
79
+ }
80
+ if (node.type === "string") {
81
+ const text = node.text;
82
+ if (text.startsWith("'") && text.endsWith("'") || text.startsWith('"') && text.endsWith('"')) {
83
+ const isDouble = text.startsWith('"');
84
+ let inner = text.slice(1, -1);
85
+ if (isDouble) {
86
+ inner = inner.replace(
87
+ /\\(.)/g,
88
+ (_match, ch) => ch in escapeMap ? escapeMap[ch] : _match
89
+ );
90
+ } else {
91
+ inner = inner.replace(/\\'/g, "'").replace(/\\\\/g, "\\");
92
+ }
93
+ return inner;
94
+ }
95
+ }
96
+ return node.text;
97
+ }
98
+ function doTree(sourceCode, filepath, debugEnabled, args) {
99
+ const parser = new import_tree_sitter.default();
100
+ const parserExt = (0, import_glob.getParser)(filepath);
101
+ if (!parserExt) return new import_gettext_merger.SetOfBlocks([], filepath);
102
+ parser.setLanguage(parserExt);
103
+ const gettextTranslations = new import_gettext_merger.SetOfBlocks([], filepath);
104
+ const typeToMatch = filepath.split(".").pop()?.toLowerCase() !== "php" ? "call_expression" : "function_call_expression";
105
+ const stringType = [
106
+ "name",
107
+ "string",
108
+ "string_value",
109
+ "variable_name",
110
+ "binary_expression",
111
+ "member_expression",
112
+ "subscript_expression",
113
+ "shell_command_expression",
114
+ "function_call_expression",
115
+ "encapsed_string"
116
+ ];
117
+ function traverse(node) {
118
+ if (node?.children.length) {
119
+ for (const child of node.children) {
120
+ traverse(child);
121
+ }
122
+ }
123
+ if (node?.type === typeToMatch) {
124
+ const functionName = node.firstChild?.text ?? null;
125
+ if (functionName === null || !Object.keys(import_const.i18nFunctions).includes(functionName)) {
126
+ return;
127
+ }
128
+ const argsNode = node.childForFieldName("arguments");
129
+ if (argsNode === null || argsNode.childCount === 0 || argsNode.type !== "arguments") {
130
+ return;
131
+ }
132
+ if (!argsNode) return;
133
+ const translation = {
134
+ // WordPress default text domain is 'default'
135
+ text_domain: "default"
136
+ };
137
+ const translationKeys = import_const.i18nFunctions[functionName];
138
+ const children = argsNode.children;
139
+ let translationKeyIndex = 0;
140
+ for (const child of children) {
141
+ let node2 = child;
142
+ if (node2.type === "(" || node2.type === ")" || node2.type === "," || node2.type === "[" || node2.type === "]") {
143
+ continue;
144
+ }
145
+ if (node2.type === "comment") {
146
+ continue;
147
+ }
148
+ if (child.type === "argument") {
149
+ if (child.children.length === 0) continue;
150
+ const nameNode = child.childForFieldName("name");
151
+ let foundValue = false;
152
+ for (const argChild of child.children) {
153
+ if (argChild.id === nameNode?.id) {
154
+ continue;
155
+ }
156
+ if (argChild.type === "comment" || argChild.type === ":") {
157
+ continue;
158
+ }
159
+ node2 = argChild;
160
+ foundValue = true;
161
+ break;
162
+ }
163
+ if (!foundValue) {
164
+ continue;
165
+ }
166
+ }
167
+ if (translationKeyIndex >= translationKeys.length) {
168
+ break;
169
+ }
170
+ const currentKey = translationKeys[translationKeyIndex];
171
+ let nodeValue = resolveStringValue(node2);
172
+ if (currentKey === "number") {
173
+ nodeValue = node2.text;
174
+ } else if (!node2?.type || !stringType.includes(node2.type)) {
175
+ if (debugEnabled) {
176
+ console.error(
177
+ `Unexpected node type ${node2?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node2.startPosition.row + 1} pos ${node2.startPosition.column + 1}`
178
+ );
179
+ }
180
+ return;
181
+ }
182
+ translation[currentKey] = nodeValue;
183
+ translationKeyIndex += 1;
184
+ }
185
+ if (Array.isArray(args?.options?.translationDomains) && translation.text_domain && !args.options.translationDomains.includes(translation.text_domain)) {
186
+ return;
187
+ }
188
+ const comments = collectComments(node);
189
+ const block = new import_gettext_merger.Block({
190
+ msgctxt: translation.msgctxt,
191
+ msgid: translation.msgid ?? "",
192
+ msgid_plural: translation.msgid_plural,
193
+ msgstr: translation.msgid_plural ? ["", ""] : [""],
194
+ comments: {
195
+ translator: comments ? [comments] : void 0,
196
+ reference: [
197
+ `${(0, import_common.reverseSlashes)(filepath)}:${node.startPosition.row + 1}`
198
+ ]
199
+ }
200
+ });
201
+ gettextTranslations.add(block);
202
+ }
203
+ }
204
+ try {
205
+ if (sourceCode) {
206
+ const fileSize = Buffer.byteLength(sourceCode, "utf8");
207
+ let bufferSize = 1024 * 32;
208
+ if (fileSize >= bufferSize) {
209
+ bufferSize = fileSize + 32;
210
+ }
211
+ if (fileSize >= 1024 * 1024 * 2) {
212
+ console.warn(`File size warning: ${filepath} exceeds 2 MB.`);
213
+ }
214
+ const tree = parser.parse(sourceCode, void 0, { bufferSize });
215
+ if (tree) {
216
+ traverse(tree.rootNode);
217
+ }
218
+ }
219
+ } catch (e) {
220
+ console.error(`Failed to parse ${filepath}: ${e}`);
221
+ }
222
+ return gettextTranslations;
223
+ }
224
+ // Annotate the CommonJS export names for ESM import in node:
225
+ 0 && (module.exports = {
226
+ doTree
227
+ });
228
+ //# sourceMappingURL=tree.js.map
@@ -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\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 * 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// Unescape common sequences\r\n\t\t\t\t\tswitch (child.text) {\r\n\t\t\t\t\t\tcase '\\\\n': return '\\n';\r\n\t\t\t\t\t\tcase '\\\\r': return '\\r';\r\n\t\t\t\t\t\tcase '\\\\t': return '\\t';\r\n\t\t\t\t\t\tcase '\\\\\\\\': return '\\\\';\r\n\t\t\t\t\t\tcase '\\\\\"': return '\"';\r\n\t\t\t\t\t\tcase '\\\\$': return '$';\r\n\t\t\t\t\t\tcase '\\\\e': return '\\x1b';\r\n\t\t\t\t\t\tcase '\\\\f': return '\\f';\r\n\t\t\t\t\t\tcase '\\\\v': return '\\v';\r\n\t\t\t\t\t\tdefault: return child.text;\r\n\t\t\t\t\t}\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\t// Remove quotes and unescape escaped quotes\r\n\t\t\treturn text.slice(1, -1).replace(/\\\\'/g, \"'\").replace(/\\\\\\\\/g, \"\\\\\");\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;AAC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E,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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UAAU,IAAI;AAG1B,+BAAuB;AAAA,MACxB;AAGA,UACC,MAAM,QAAQ,MAAM,SAAS,kBAAkB,KAC/C,YAAY,eACZ,CAAC,KAAK,QAAQ,mBAAmB,SAAS,YAAY,WAAW,GAChE;AACD;AAAA,MACD;AAEA,YAAM,WAAW,gBAAgB,IAAI;AAGrC,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;",
6
6
  "names": ["Parser", "node"]
7
7
  }
package/lib/potCommand.js CHANGED
@@ -1 +1,36 @@
1
- "use strict";var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of s(t))!c.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(p=f(t,r))||p.enumerable});return e};var k=e=>d(n({},"__esModule",{value:!0}),e);var h={};l(h,{default:()=>a});module.exports=k(h);var i=require("./parser/makePot.js"),m=require("./utils/common.js");function a(e){if(Object.keys(e).length>0){(0,m.printModuleInfo)();const t=new Date;(0,i.makePot)(e).then(()=>{(0,m.printTimeElapsed)("Make-Pot",t)}).catch(o=>{console.error(`\u{1FAE4} Make-pot - ${o}`)})}}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var potCommand_exports = {};
20
+ __export(potCommand_exports, {
21
+ default: () => potCommand
22
+ });
23
+ module.exports = __toCommonJS(potCommand_exports);
24
+ var import_makePot = require("./parser/makePot.js");
25
+ var import_common = require("./utils/common.js");
26
+ function potCommand(args) {
27
+ if (Object.keys(args).length > 0) {
28
+ (0, import_common.printModuleInfo)();
29
+ (0, import_makePot.makePot)(args).then(() => {
30
+ (0, import_common.printTimeElapsed)("Make-Pot", args.timeStart);
31
+ }).catch((error) => {
32
+ console.error(`\u{1FAE4} Make-pot - ${error}`);
33
+ });
34
+ }
35
+ }
36
+ //# sourceMappingURL=potCommand.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/potCommand.ts"],
4
- "sourcesContent": ["import { makePot } from \"./parser/makePot.js\";\n\nimport type { Args } from \"./types.js\";\nimport { printModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function potCommand(args: Args) {\n\tif (Object.keys(args).length > 0) {\n\t\tprintModuleInfo();\n\t\t/* capture the start time */\n\t\tconst timeStart = new Date();\n\t\t/** make the pot file */\n\t\tmakePot(args)\n\t\t\t.then(() => {\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Pot\", timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 Make-pot - ${error}`);\n\t\t\t});\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAGxB,oBAAkD;AAEnC,SAAR,WAA4B,MAAY;AAC9C,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,uCAAgB;AAEhB,UAAM,YAAY,oBAAI,KAAK;AAE3B,gCAAQ,IAAI,EACV,KAAK,MAAM;AAEX,0CAAiB,YAAY,SAAS;AAAA,IACvC,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,wBAAiB,KAAK,EAAE;AAAA,IACvC,CAAC;AAAA,EACH;AACD;",
4
+ "sourcesContent": ["import { makePot } from \"./parser/makePot.js\";\n\nimport type { Args } from \"./types.js\";\nimport { printModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function potCommand(args: Args) {\n\tif (Object.keys(args).length > 0) {\n\t\tprintModuleInfo();\n\t\t/** make the pot file */\n\t\tmakePot(args)\n\t\t\t.then(() => {\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Pot\", args.timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 Make-pot - ${error}`);\n\t\t\t});\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAGxB,oBAAkD;AAEnC,SAAR,WAA4B,MAAY;AAC9C,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,uCAAgB;AAEhB,gCAAQ,IAAI,EACV,KAAK,MAAM;AAEX,0CAAiB,YAAY,KAAK,SAAS;AAAA,IAC5C,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,wBAAiB,KAAK,EAAE;AAAA,IACvC,CAAC;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
package/lib/types.js CHANGED
@@ -1 +1,17 @@
1
- "use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(t,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of i(e))!g.call(t,n)&&n!==a&&s(t,n,{get:()=>e[n],enumerable:!(r=o(e,n))||r.enumerable});return t};var l=t=>p(s({},"__esModule",{value:!0}),t);var d={};module.exports=l(d);
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
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\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"],
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\ttimeStart?: Date;\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
  }