@wp-blocks/make-pot 1.6.4 → 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.
- package/lib/const.js +1 -1
- package/lib/const.js.map +1 -1
- package/lib/fs/glob.js +1 -1
- package/lib/fs/glob.js.map +2 -2
- package/lib/parser/exec.js +3 -3
- package/lib/parser/exec.js.map +2 -2
- package/lib/parser/process.js +1 -1
- package/lib/parser/process.js.map +2 -2
- package/lib/parser/progress.js +1 -1
- package/lib/parser/progress.js.map +2 -2
- package/lib/parser/taskRunner.js +2 -2
- package/lib/parser/taskRunner.js.map +2 -2
- package/lib/parser/tree.js +2 -2
- package/lib/parser/tree.js.map +2 -2
- package/lib/utils/common.js +2 -2
- package/lib/utils/common.js.map +2 -2
- package/package.json +3 -2
package/lib/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=Object.create;var _=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},n=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!u.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?r(l(t)):{},n(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var T={};f(T,{DEFAULT_EXCLUDED_PATH:()=>F,IsoCodeRegex:()=>H,allowedFormats:()=>D,allowedFunctions:()=>E,defaultLocale:()=>A,fileRegex:()=>k,i18nFunctions:()=>L,modulePath:()=>P,pkgJsonHeaders:()=>j,pluginHeaders:()=>b,themeHeaders:()=>w});module.exports=h(T);var d=o(require("node:path")),x=o(require("./assets/package-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),g=o(require("./assets/wp-theme-i18n.js"));const j=x.default,b=a.default,w=g.default,F=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","
|
|
1
|
+
"use strict";var r=Object.create;var _=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},n=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!u.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?r(l(t)):{},n(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var T={};f(T,{DEFAULT_EXCLUDED_PATH:()=>F,IsoCodeRegex:()=>H,allowedFormats:()=>D,allowedFunctions:()=>E,defaultLocale:()=>A,fileRegex:()=>k,i18nFunctions:()=>L,modulePath:()=>P,pkgJsonHeaders:()=>j,pluginHeaders:()=>b,themeHeaders:()=>w});module.exports=h(T);var d=o(require("node:path")),x=o(require("./assets/package-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),g=o(require("./assets/wp-theme-i18n.js"));const j=x.default,b=a.default,w=g.default,F=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**/*.test.*","tests"],H=/-([a-z]{2}_[A-Z]{2})\.po$/,k=/#:\s*(.*?)(?::\d+)?$/,A="en_US",D=["php","js","jsx","ts","tsx","mjs","cjs"],E=new Set(["__","_x","_n","_nx"]),L={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]},P=d.default.resolve(__dirname,"..");0&&(module.exports={DEFAULT_EXCLUDED_PATH,IsoCodeRegex,allowedFormats,allowedFunctions,defaultLocale,fileRegex,i18nFunctions,modulePath,pkgJsonHeaders,pluginHeaders,themeHeaders});
|
package/lib/const.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/const.ts"],
|
|
4
|
-
"sourcesContent": ["import path from \"node:path\";\nimport packagei18n from \"./assets/package-i18n.js\";\nimport wpPlugini18n from \"./assets/wp-plugin-i18n.js\";\nimport wpThemei18n from \"./assets/wp-theme-i18n.js\";\n\n/**\n * Theme Json metadata headers\n *\n */\nexport const pkgJsonHeaders = packagei18n;\n/**\n * The Plugin metadata headers\n * @link https://codex.wordpress.org/File_Header\n */\nexport const pluginHeaders = wpPlugini18n;\n/**\n * The Theme metadata headers\n * @link https://developer.wordpress.org/plugins/plugin-basics/header-requirements/\n */\nexport const themeHeaders = wpThemei18n;\n\n/**\n * The default list of paths to exclude from the pot file.\n * @link https://www.npmjs.com/package/glob#glob-primer\n */\nexport const DEFAULT_EXCLUDED_PATH = [\n\t\".git\",\n\t\"node_modules\",\n\t\"vendor\",\n\t\"build\",\n\t\"dist\",\n\t\"uploads\",\n\t\"Gruntfile.js\",\n\t\"webpack.config.js\",\n\t\"**/*.min.js\",\n\t\"tsconfig.js\",\n\t\"
|
|
4
|
+
"sourcesContent": ["import path from \"node:path\";\nimport packagei18n from \"./assets/package-i18n.js\";\nimport wpPlugini18n from \"./assets/wp-plugin-i18n.js\";\nimport wpThemei18n from \"./assets/wp-theme-i18n.js\";\n\n/**\n * Theme Json metadata headers\n *\n */\nexport const pkgJsonHeaders = packagei18n;\n/**\n * The Plugin metadata headers\n * @link https://codex.wordpress.org/File_Header\n */\nexport const pluginHeaders = wpPlugini18n;\n/**\n * The Theme metadata headers\n * @link https://developer.wordpress.org/plugins/plugin-basics/header-requirements/\n */\nexport const themeHeaders = wpThemei18n;\n\n/**\n * The default list of paths to exclude from the pot file.\n * @link https://www.npmjs.com/package/glob#glob-primer\n */\nexport const DEFAULT_EXCLUDED_PATH = [\n\t\".git\",\n\t\"node_modules\",\n\t\"vendor\",\n\t\"build\",\n\t\"dist\",\n\t\"uploads\",\n\t\"Gruntfile.js\",\n\t\"webpack.config.js\",\n\t\"**/*.min.js\",\n\t\"tsconfig.js\",\n\t\"**/*.test.*\",\n\t\"tests\",\n];\n\n/**\n * The regex used to find the locale in the source code\n */\nexport const IsoCodeRegex = /-([a-z]{2}_[A-Z]{2})\\.po$/;\n\n/**\n * The regex used to find the filename in the source code\n */\nexport const fileRegex = /#:\\s*(.*?)(?::\\d+)?$/;\n\nexport const defaultLocale = \"en_US\";\n\n/**\n * The files that are allowed to be parsed using tree sitter\n *\n * Json and text files are parsed in a different way\n */\nexport const allowedFormats = [\"php\", \"js\", \"jsx\", \"ts\", \"tsx\", \"mjs\", \"cjs\"];\n\n/**\n * The functions that are allowed to be \"converted\" using babel during the make-json process\n */\nexport const allowedFunctions = new Set([\"__\", \"_x\", \"_n\", \"_nx\"]);\n\n/**\n * The default functions to use for i18n.\n */\nexport const i18nFunctions = {\n\t__: [\"msgid\", \"text_domain\"],\n\tesc_attr__: [\"msgid\", \"text_domain\"],\n\tesc_html__: [\"msgid\", \"text_domain\"],\n\tesc_xml__: [\"msgid\", \"text_domain\"],\n\t_e: [\"msgid\", \"text_domain\"],\n\tesc_attr_e: [\"msgid\", \"text_domain\"],\n\tesc_html_e: [\"msgid\", \"text_domain\"],\n\tesc_xml_e: [\"msgid\", \"text_domain\"],\n\t_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_ex: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_attr_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_html_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_xml_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_n: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t_nx: [\"msgid\", \"msgid_plural\", \"number\", \"msgctxt\", \"text_domain\"],\n\t_n_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n\t_nx_noop: [\"msgid\", \"msgid_plural\", \"msgctxt\", \"text_domain\"],\n\n\t// Compat.\n\t_: [\"msgid\", \"text_domain\"],\n\n\t// Deprecated.\n\t_c: [\"msgid\", \"text_domain\"],\n\t_nc: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n};\n\n/**\n * @var modulePath The path to the module folder containing this file\n */\nexport const modulePath = path.resolve(__dirname, \"..\");\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,0BAAwB;AACxB,4BAAyB;AACzB,2BAAwB;AAMjB,MAAM,iBAAiB,oBAAAA;AAKvB,MAAM,gBAAgB,sBAAAC;AAKtB,MAAM,eAAe,qBAAAC;AAMrB,MAAM,wBAAwB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,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iB,CAAC,SAAS,gBAAgB,aAAa;AACzD;AAKO,MAAM,aAAa,iBAAAC,QAAK,QAAQ,WAAW,IAAI;",
|
|
6
6
|
"names": ["packagei18n", "wpPlugini18n", "wpThemei18n", "path"]
|
|
7
7
|
}
|
package/lib/fs/glob.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
package/lib/fs/glob.js.map
CHANGED
|
@@ -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\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
|
|
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;
|
|
4
|
+
"sourcesContent": ["import path from 'node:path'\r\nimport { Glob, type Path } from 'glob'\r\nimport { 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,GAA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
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
Audit strings...`),(0,h.audit)(t,e)),t.options?.json)return(0,
|
|
3
|
-
${
|
|
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});
|
package/lib/parser/exec.js.map
CHANGED
|
@@ -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
|
|
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,
|
|
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
|
}
|
package/lib/parser/process.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,
|
|
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
|
}
|
package/lib/parser/progress.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAUrC,SAAS,aAAa,OAAa,aAAgC;
|
|
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
|
}
|
package/lib/parser/taskRunner.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
\u{1F389} Done!`),console.log(`\u{1F4DD} Found ${Object.values(
|
|
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: 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.
|
|
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,
|
|
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
|
}
|
package/lib/parser/tree.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var L=Object.create;var
|
|
2
|
-
|
|
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});
|
package/lib/parser/tree.js.map
CHANGED
|
@@ -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;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;
|
|
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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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/utils/common.js
CHANGED
|
@@ -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})},
|
|
2
|
-
# This file is distributed under the ${e} license.`}function v(t){return t.replace(/\\/g,"/")}function f(t,...e){const n={},o=
|
|
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}
|
package/lib/utils/common.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/common.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from \"node:fs\";\r\nimport { cpus, totalmem } from \"node:os\";\r\nimport path from \"node:path\";\r\nimport { modulePath } from \"../const.js\";\r\nimport type { Patterns } from \"../types.js\";\r\n\r\n/**\r\n * A function that removes comment markup from a given string.\r\n *\r\n * @param {string} input - The input string with comment markup.\r\n * @return {string} - The input string without comment markup.\r\n */\r\nexport function getCommentBlock(input: string): string {\r\n\tconst commentBlock = input.match(/\\/\\*\\*?[\\s\\S]*?\\*\\//);\r\n\treturn commentBlock !== null ? commentBlock[0] : input;\r\n}\r\n\r\n/**\r\n * A function that starts to capture the text after the first letter.\r\n *\r\n * @param {string} input - The input string with comment markup.\r\n * @return {string} - The input string without comment markup.\r\n */\r\nexport function removeCommentMarkup(input: string): string[] | null {\r\n\treturn input.match(/[a-zA-Z].*/gm);\r\n}\r\n\r\n/**\r\n * Removes the markup from a comment string.\r\n *\r\n * @param {string} comment - The comment string to remove markup from.\r\n * @return {string} The comment text without the markers.\r\n */\r\nexport function stripTranslationMarkup(comment: string): string {\r\n\tconst commentPattern =\r\n\t\t/\\/\\*\\*?\\s*(?:translators:)\\s*([\\s\\S]*?)\\s*\\*\\/|\\/\\/\\s*(?:translators:)\\s*(.*)$/i;\r\n\tconst matches = comment.match(commentPattern);\r\n\treturn matches ? matches[1] : comment;\r\n}\r\n\r\n/**\r\n * Splits a string into an array of strings based on the presence of a comma.\r\n *\r\n * @param {string} string - The string to be split.\r\n * @return {string[]} An array of strings after splitting the input string.\r\n */\r\nexport function stringstring(string: string | string[] | undefined): string[] {\r\n\tif (typeof string === \"string\") {\r\n\t\tif (string.includes(\",\")) {\r\n\t\t\treturn string.split(\",\");\r\n\t\t}\r\n\t\treturn [string];\r\n\t}\r\n\treturn [];\r\n}\r\n\r\n/**\r\n * Determines if a pattern represents a file, a directory, or a glob pattern.\r\n * @param pattern - The pattern string to evaluate.\r\n * @returns 'file', 'directory', or 'glob'.\r\n */\r\nexport function detectPatternType(\r\n\tpattern: string,\r\n): \"file\" | \"directory\" | \"glob\" {\r\n\tconst containsFileExtension = pattern.includes(\".\");\r\n\tconst containsDirectorySeparator = pattern.includes(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,qBAA+B;AAC/B,uBAAiB;AACjB,mBAA2B;AASpB,SAAS,gBAAgB,OAAuB;AACtD,QAAM,eAAe,MAAM,MAAM,qBAAqB;AACtD,SAAO,iBAAiB,OAAO,aAAa,CAAC,IAAI;AAClD;AAQO,SAAS,oBAAoB,OAAgC;AACnE,SAAO,MAAM,MAAM,cAAc;AAClC;AAQO,SAAS,uBAAuB,SAAyB;AAC/D,QAAM,iBACL;AACD,QAAM,UAAU,QAAQ,MAAM,cAAc;AAC5C,SAAO,UAAU,QAAQ,CAAC,IAAI;AAC/B;AAQO,SAAS,aAAa,QAAiD;AAC7E,MAAI,OAAO,WAAW,UAAU;AAC/B,QAAI,OAAO,SAAS,GAAG,GAAG;AACzB,aAAO,OAAO,MAAM,GAAG;AAAA,IACxB;AACA,WAAO,CAAC,MAAM;AAAA,EACf;AACA,SAAO,CAAC;AACT;AAOO,SAAS,kBACf,SACgC;AAChC,QAAM,wBAAwB,QAAQ,SAAS,GAAG;AAClD,QAAM,6BAA6B,QAAQ,SAAS,
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs\";\r\nimport { cpus, totalmem } from \"node:os\";\r\nimport path from \"node:path\";\r\nimport { modulePath } from \"../const.js\";\r\nimport type { Patterns } from \"../types.js\";\r\n\r\n/**\r\n * A function that removes comment markup from a given string.\r\n *\r\n * @param {string} input - The input string with comment markup.\r\n * @return {string} - The input string without comment markup.\r\n */\r\nexport function getCommentBlock(input: string): string {\r\n\tconst commentBlock = input.match(/\\/\\*\\*?[\\s\\S]*?\\*\\//);\r\n\treturn commentBlock !== null ? commentBlock[0] : input;\r\n}\r\n\r\n/**\r\n * A function that starts to capture the text after the first letter.\r\n *\r\n * @param {string} input - The input string with comment markup.\r\n * @return {string} - The input string without comment markup.\r\n */\r\nexport function removeCommentMarkup(input: string): string[] | null {\r\n\treturn input.match(/[a-zA-Z].*/gm);\r\n}\r\n\r\n/**\r\n * Removes the markup from a comment string.\r\n *\r\n * @param {string} comment - The comment string to remove markup from.\r\n * @return {string} The comment text without the markers.\r\n */\r\nexport function stripTranslationMarkup(comment: string): string {\r\n\tconst commentPattern =\r\n\t\t/\\/\\*\\*?\\s*(?:translators:)\\s*([\\s\\S]*?)\\s*\\*\\/|\\/\\/\\s*(?:translators:)\\s*(.*)$/i;\r\n\tconst matches = comment.match(commentPattern);\r\n\treturn matches ? matches[1] : comment;\r\n}\r\n\r\n/**\r\n * Splits a string into an array of strings based on the presence of a comma.\r\n *\r\n * @param {string} string - The string to be split.\r\n * @return {string[]} An array of strings after splitting the input string.\r\n */\r\nexport function stringstring(string: string | string[] | undefined): string[] {\r\n\tif (typeof string === \"string\") {\r\n\t\tif (string.includes(\",\")) {\r\n\t\t\treturn string.split(\",\");\r\n\t\t}\r\n\t\treturn [string];\r\n\t}\r\n\treturn [];\r\n}\r\n\r\n/**\r\n * Determines if a pattern represents a file, a directory, or a glob pattern.\r\n * @param pattern - The pattern string to evaluate.\r\n * @returns 'file', 'directory', or 'glob'.\r\n */\r\nexport function detectPatternType(\r\n\tpattern: string,\r\n): \"file\" | \"directory\" | \"glob\" {\r\n\tconst containsFileExtension = pattern.includes(\".\");\r\n\tconst containsDirectorySeparator = pattern.includes(\"/\");\r\n\r\n\tif (pattern.includes(\"*\")) {\r\n\t\treturn \"glob\";\r\n\t}\r\n\tif (!containsFileExtension && !containsDirectorySeparator) {\r\n\t\treturn \"directory\";\r\n\t}\r\n\tif (containsFileExtension && !containsDirectorySeparator) {\r\n\t\treturn \"file\";\r\n\t}\r\n\treturn \"glob\";\r\n}\r\n\r\n/**\r\n * Gets the file extension from a filename.\r\n * @param filename - The name of the file to extract the extension from.\r\n * @returns The file extension, or 'blade.php' for Blade templates.\r\n */\r\nexport function getFileExtension(filename: string): string {\r\n\tif (filename.endsWith(\".blade.php\")) {\r\n\t\treturn \"blade.php\";\r\n\t}\r\n\treturn filename.split(\".\").pop() || \"\";\r\n}\r\n\r\n/**\r\n * Generates a copyright comment for the specified slug and license.\r\n *\r\n * @param slug - The slug to include in the copyright comment\r\n * @param [license='GPL v2 or later'] - The license to use in the copyright comment\r\n * @return The generated copyright comment\r\n */\r\nexport function getCopyright(\r\n\tslug: string,\r\n\tlicense = \"GPL v2 or later\",\r\n): string {\r\n\treturn (\r\n\t\t`# Copyright (C) ${new Date().getFullYear()} ${slug}\\n` +\r\n\t\t`# This file is distributed under the ${license} license.`\r\n\t);\r\n}\r\n\r\n/**\r\n * Reverse slashes in a path, and replace backward slashes with forward slashes\r\n *\r\n * @param filePath - The path to be reversed.\r\n * @return {string} The reversed path.\r\n */\r\nexport function reverseSlashes(filePath: string): string {\r\n\t// Replace backward slashes with forward slashes\r\n\treturn filePath.replace(/\\\\/g, \"/\");\r\n}\r\n\r\n/**\r\n * The makepot package.json file data\r\n * @arguments {string[]} fields - The fields to extract\r\n * @return {Record<string, unknown>} - The package.json data\r\n */\r\nexport function getPkgJsonData(\r\n\tlocation?: string,\r\n\t...fields: string[]\r\n): Record<string, unknown> {\r\n\tconst requested: Record<string, unknown> = {};\r\n\t// read the package.json file the is in the root directory\r\n\tconst pkgJsonPath = path.join(location || process.cwd(), \"package.json\");\r\n\t// read the package.json file or return an empty object\r\n\tconst pkgJson: Record<string, unknown> = fs.existsSync(pkgJsonPath)\r\n\t\t? require(pkgJsonPath)\r\n\t\t: {};\r\n\t// extract the requested fields from the package.json\r\n\tfor (const field of fields) {\r\n\t\tif (pkgJson[field]) {\r\n\t\t\trequested[field] = pkgJson[field];\r\n\t\t}\r\n\t}\r\n\treturn requested;\r\n}\r\n\r\n/**\r\n * Print the module header with the current version and name\r\n */\r\nexport function printModuleInfo() {\r\n\tconst { version, name } = getPkgJsonData(modulePath, \"name\", \"version\");\r\n\t/* print the version */\r\n\tconsole.log(`${name} version: ${version}`);\r\n}\r\n\r\n/**\r\n * Output to the console the time elapsed in milliseconds between two dates\r\n * @param scriptName the name of the script\r\n * @param timeStart the start time\r\n * @param timeEnd the end time\r\n */\r\nexport function printTimeElapsed(\r\n\tscriptName: \"Make-Pot\" | \"Make-Json\",\r\n\ttimeStart: Date,\r\n\ttimeEnd: Date = new Date(),\r\n) {\r\n\tconsole.log(\r\n\t\t`\\n\uD83D\uDE80 ${scriptName}: Task completed! ${scriptName.split(\"-\")[1]} file created in ${timeEnd.getTime() - timeStart.getTime()\r\n\t\t}ms`,\r\n\t);\r\n}\r\n\r\n/**\r\n/**\r\n* Prints the memory usage and cpu usage of the system\r\n */\r\nexport function printStats() {\r\n\tconsole.log(\r\n\t\t\"Memory usage:\",\r\n\t\t(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2),\r\n\t\t\"MB (Free:\",\r\n\t\t(totalmem() / 1024 / 1024 / 1024).toFixed(2),\r\n\t\t\"GB)\\nCpu User:\",\r\n\t\t(process.cpuUsage().user / 1000000).toFixed(2),\r\n\t\t\"ms Cpu System:\",\r\n\t\t(process.cpuUsage().system / 1000000).toFixed(2),\r\n\t\t\"ms of\",\r\n\t\tcpus().length,\r\n\t\t\"cores\",\r\n\t);\r\n}\r\n\r\n/**\r\n * Returns the output path recap\r\n *\r\n * @param {string} cwd - The current working directory\r\n * @param {Patterns} patterns - The patterns to be used for the extraction process\r\n * @return {string} - The output path recap\r\n */\r\nexport function outputPathRecap(cwd: string, patterns: Patterns): string {\r\n\treturn `\\nScript Path: ${cwd}\\nfor ${patterns.include.join()}\\nignoring patterns: ${patterns.exclude.join()}\\n`;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,qBAA+B;AAC/B,uBAAiB;AACjB,mBAA2B;AASpB,SAAS,gBAAgB,OAAuB;AACtD,QAAM,eAAe,MAAM,MAAM,qBAAqB;AACtD,SAAO,iBAAiB,OAAO,aAAa,CAAC,IAAI;AAClD;AAQO,SAAS,oBAAoB,OAAgC;AACnE,SAAO,MAAM,MAAM,cAAc;AAClC;AAQO,SAAS,uBAAuB,SAAyB;AAC/D,QAAM,iBACL;AACD,QAAM,UAAU,QAAQ,MAAM,cAAc;AAC5C,SAAO,UAAU,QAAQ,CAAC,IAAI;AAC/B;AAQO,SAAS,aAAa,QAAiD;AAC7E,MAAI,OAAO,WAAW,UAAU;AAC/B,QAAI,OAAO,SAAS,GAAG,GAAG;AACzB,aAAO,OAAO,MAAM,GAAG;AAAA,IACxB;AACA,WAAO,CAAC,MAAM;AAAA,EACf;AACA,SAAO,CAAC;AACT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G,EAAE,CAAC,CAAC,oBAAoB,QAAQ,QAAQ,IAAI,UAAU,QAAQ,CACzH;AAAA,EACD;AACD;AAMO,SAAS,aAAa;AAC5B,UAAQ;AAAA,IACP;AAAA,KACC,QAAQ,YAAY,EAAE,WAAW,OAAO,MAAM,QAAQ,CAAC;AAAA,IACxD;AAAA,SACC,yBAAS,IAAI,OAAO,OAAO,MAAM,QAAQ,CAAC;AAAA,IAC3C;AAAA,KACC,QAAQ,SAAS,EAAE,OAAO,KAAS,QAAQ,CAAC;AAAA,IAC7C;AAAA,KACC,QAAQ,SAAS,EAAE,SAAS,KAAS,QAAQ,CAAC;AAAA,IAC/C;AAAA,QACA,qBAAK,EAAE;AAAA,IACP;AAAA,EACD;AACD;AASO,SAAS,gBAAgB,KAAa,UAA4B;AACxE,SAAO;AAAA,eAAkB,GAAG;AAAA,MAAS,SAAS,QAAQ,KAAK,CAAC;AAAA,qBAAwB,SAAS,QAAQ,KAAK,CAAC;AAAA;AAC5G;",
|
|
6
6
|
"names": ["path", "fs"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-blocks/make-pot",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://wp-blocks.github.io/make-pot/",
|
|
6
6
|
"description": "A Node.js script for generating a POT file from source code",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/wp-blocks/makePot.git"
|
|
25
|
+
"url": "git+https://github.com/wp-blocks/makePot.git"
|
|
26
26
|
},
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/wp-blocks/makePot/issues"
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"lint": "npx @biomejs/biome check --write src",
|
|
53
53
|
"type-check": "npx tsc --noEmit",
|
|
54
54
|
"update-pkg": "npm upgrade -S",
|
|
55
|
+
"publish-check": "npm run build && npx publint",
|
|
55
56
|
"rm": "rmdir /s /q lib",
|
|
56
57
|
"test:build": "npx esbuild ./src/**/* ./src/*.ts --format=cjs --sourcemap --outdir=lib --platform=node",
|
|
57
58
|
"test": "npm run test:build && node --test",
|