@wp-blocks/make-pot 1.6.2 → 1.6.3

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 (46) hide show
  1. package/README.md +2 -1
  2. package/biome.json +6 -3
  3. package/lib/assets/block-i18n.js.map +7 -1
  4. package/lib/assets/package-i18n.js.map +7 -1
  5. package/lib/assets/theme-i18n.js.map +7 -1
  6. package/lib/assets/wp-plugin-i18n.js.map +7 -1
  7. package/lib/assets/wp-theme-i18n.js.map +7 -1
  8. package/lib/cli/getArgs.js +1 -1
  9. package/lib/cli/getArgs.js.map +7 -1
  10. package/lib/cli/getJsonArgs.js.map +7 -1
  11. package/lib/cli/parseCli.js +1 -1
  12. package/lib/cli/parseCli.js.map +7 -1
  13. package/lib/cli.js.map +7 -1
  14. package/lib/const.js.map +7 -1
  15. package/lib/extractors/auditStrings.js +1 -1
  16. package/lib/extractors/auditStrings.js.map +7 -1
  17. package/lib/extractors/css.js.map +7 -1
  18. package/lib/extractors/headers.js.map +7 -1
  19. package/lib/extractors/json.js.map +7 -1
  20. package/lib/extractors/packageJson.js.map +7 -1
  21. package/lib/extractors/php.js.map +7 -1
  22. package/lib/extractors/schema.js.map +7 -1
  23. package/lib/extractors/text.js.map +7 -1
  24. package/lib/fs/fs.js.map +7 -1
  25. package/lib/fs/glob.js.map +7 -1
  26. package/lib/index.js.map +7 -1
  27. package/lib/jsonCommand.js.map +7 -1
  28. package/lib/makeJson.js.map +7 -1
  29. package/lib/makePot.js.map +7 -1
  30. package/lib/parser/exec.js.map +7 -1
  31. package/lib/parser/makeJson.js.map +7 -1
  32. package/lib/parser/makePot.js.map +7 -1
  33. package/lib/parser/patterns.js.map +7 -1
  34. package/lib/parser/process.js +1 -1
  35. package/lib/parser/process.js.map +7 -1
  36. package/lib/parser/progress.js.map +7 -1
  37. package/lib/parser/taskRunner.js.map +7 -1
  38. package/lib/parser/tree.js +1 -1
  39. package/lib/parser/tree.js.map +7 -1
  40. package/lib/potCommand.js.map +7 -1
  41. package/lib/types.js.map +7 -1
  42. package/lib/utils/common.js.map +7 -1
  43. package/lib/utils/extractors.js.map +7 -1
  44. package/lib/utils/output.js.map +7 -1
  45. package/package.json +5 -5
  46. package/tests/tree.test.js +37 -0
package/README.md CHANGED
@@ -58,7 +58,7 @@ npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,
58
58
  - `--version`: Displays the version number of `make-pot`.
59
59
  - `-h`, `--help`: Displays help information.
60
60
  - `--slug <slug>`: Specifies the plugin or theme slug.
61
- - `--domain <domain>`: Specifies the text domain to look for in the source code.
61
+ - `--domain <domain>`: Specifies the text domain to look for in the source code, you can choose "plugin", "theme", "block", "theme-block", "generic".
62
62
  - `--skip-js`: Skips JavaScript files during processing.
63
63
  - `--skip-php`: Skips PHP files during processing.
64
64
  - `--skip-blade`: Skips Blade files during processing.
@@ -78,6 +78,7 @@ npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,
78
78
  - `--silent`: Suppresses output to stdout.
79
79
  - `--json`: Outputs the JSON gettext data.
80
80
  - `--charset`: Defines the encoding charset of the pot file, you can choose "iso-8859-1" and "uft-8" (defaults to iso-8859-1)
81
+ - `--translation-domains`: Restrict to specific translation domains.
81
82
  - `--output`: Outputs the gettext data.
82
83
 
83
84
  ### Example usage
package/biome.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
3
- "organizeImports": {
4
- "enabled": true
2
+ "$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
3
+ "formatter": {
4
+ "enabled": false
5
5
  },
6
6
  "linter": {
7
7
  "enabled": true,
8
8
  "rules": {
9
9
  "recommended": true
10
10
  }
11
+ },
12
+ "assist": {
13
+ "enabled": false
11
14
  }
12
15
  }
@@ -1 +1,7 @@
1
- {"version":3,"file":"block-i18n.js","sourceRoot":"","sources":["../../src/assets/block-i18n.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,mBAAmB;IAChC,QAAQ,EAAE,CAAC,eAAe,CAAC;IAC3B,MAAM,EAAE;QACP;YACC,KAAK,EAAE,mBAAmB;SAC1B;KACD;IACD,UAAU,EAAE;QACX;YACC,KAAK,EAAE,uBAAuB;YAC9B,WAAW,EAAE,6BAA6B;YAC1C,QAAQ,EAAE,CAAC,yBAAyB,CAAC;SACrC;KACD;CACD,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/block-i18n.ts"],
4
+ "sourcesContent": ["export default {\n\ttitle: \"block title\",\n\tdescription: \"block description\",\n\tkeywords: [\"block keyword\"],\n\tstyles: [\n\t\t{\n\t\t\tlabel: \"block style label\",\n\t\t},\n\t],\n\tvariations: [\n\t\t{\n\t\t\ttitle: \"block variation title\",\n\t\t\tdescription: \"block variation description\",\n\t\t\tkeywords: [\"block variation keyword\"],\n\t\t},\n\t],\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,qBAAQ;AAAA,EACd,OAAO;AAAA,EACP,aAAa;AAAA,EACb,UAAU,CAAC,eAAe;AAAA,EAC1B,QAAQ;AAAA,IACP;AAAA,MACC,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EACA,YAAY;AAAA,IACX;AAAA,MACC,OAAO;AAAA,MACP,aAAa;AAAA,MACb,UAAU,CAAC,yBAAyB;AAAA,IACrC;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"package-i18n.js","sourceRoot":"","sources":["../../src/assets/package-i18n.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,WAAW;IACzB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;CACxB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/package-i18n.ts"],
4
+ "sourcesContent": ["export default {\n\tname: \"name\",\n\turl: \"url\",\n\tdescription: \"description\",\n\tauthor: \"author\",\n\tauthors: \"authors\",\n\tauthorEmail: \"authorEmail\",\n\tversion: \"version\",\n\tbugs: \"bugs\",\n\t\"bugs.url\": \"bugsUrl\",\n\t\"bugs.email\": \"bugsEmail\",\n\tlicense: \"license\",\n\trepository: \"repository\",\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,uBAAQ;AAAA,EACd,MAAM;AAAA,EACN,KAAK;AAAA,EACL,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,aAAa;AAAA,EACb,SAAS;AAAA,EACT,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,SAAS;AAAA,EACT,YAAY;AACb;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"theme-i18n.js","sourceRoot":"","sources":["../../src/assets/theme-i18n.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,KAAK,EAAE,sBAAsB;IAC7B,QAAQ,EAAE;QACT,UAAU,EAAE;YACX,SAAS,EAAE;gBACV;oBACC,IAAI,EAAE,gBAAgB;iBACtB;aACD;YACD,YAAY,EAAE;gBACb;oBACC,IAAI,EAAE,kBAAkB;iBACxB;aACD;SACD;QACD,KAAK,EAAE;YACN,OAAO,EAAE;gBACR;oBACC,IAAI,EAAE,YAAY;iBAClB;aACD;YACD,SAAS,EAAE;gBACV;oBACC,IAAI,EAAE,eAAe;iBACrB;aACD;YACD,OAAO,EAAE;gBACR;oBACC,IAAI,EAAE,cAAc;iBACpB;aACD;SACD;QACD,OAAO,EAAE;YACR,YAAY,EAAE;gBACb;oBACC,IAAI,EAAE,iBAAiB;iBACvB;aACD;SACD;QACD,MAAM,EAAE;YACP,GAAG,EAAE;gBACJ,UAAU,EAAE;oBACX,SAAS,EAAE;wBACV;4BACC,IAAI,EAAE,gBAAgB;yBACtB;qBACD;oBACD,YAAY,EAAE;wBACb;4BACC,IAAI,EAAE,kBAAkB;yBACxB;qBACD;iBACD;gBACD,KAAK,EAAE;oBACN,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,YAAY;yBAClB;qBACD;oBACD,SAAS,EAAE;wBACV;4BACC,IAAI,EAAE,eAAe;yBACrB;qBACD;iBACD;gBACD,OAAO,EAAE;oBACR,YAAY,EAAE;wBACb;4BACC,IAAI,EAAE,iBAAiB;yBACvB;qBACD;iBACD;aACD;SACD;KACD;IACD,eAAe,EAAE;QAChB;YACC,KAAK,EAAE,sBAAsB;SAC7B;KACD;IACD,aAAa,EAAE;QACd;YACC,KAAK,EAAE,oBAAoB;SAC3B;KACD;CACD,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/theme-i18n.ts"],
4
+ "sourcesContent": ["export default {\n\ttitle: \"Style variation name\",\n\tsettings: {\n\t\ttypography: {\n\t\t\tfontSizes: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Font size name\",\n\t\t\t\t},\n\t\t\t],\n\t\t\tfontFamilies: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Font family name\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tcolor: {\n\t\t\tpalette: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Color name\",\n\t\t\t\t},\n\t\t\t],\n\t\t\tgradients: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Gradient name\",\n\t\t\t\t},\n\t\t\t],\n\t\t\tduotone: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Duotone name\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tspacing: {\n\t\t\tspacingSizes: [\n\t\t\t\t{\n\t\t\t\t\tname: \"Space size name\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tblocks: {\n\t\t\t\"*\": {\n\t\t\t\ttypography: {\n\t\t\t\t\tfontSizes: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"Font size name\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tfontFamilies: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"Font family name\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tcolor: {\n\t\t\t\t\tpalette: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"Color name\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tgradients: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"Gradient name\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tspacing: {\n\t\t\t\t\tspacingSizes: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"Space size name\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n\tcustomTemplates: [\n\t\t{\n\t\t\ttitle: \"Custom template name\",\n\t\t},\n\t],\n\ttemplateParts: [\n\t\t{\n\t\t\ttitle: \"Template part name\",\n\t\t},\n\t],\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,qBAAQ;AAAA,EACd,OAAO;AAAA,EACP,UAAU;AAAA,IACT,YAAY;AAAA,MACX,WAAW;AAAA,QACV;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,MACA,cAAc;AAAA,QACb;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,IACA,OAAO;AAAA,MACN,SAAS;AAAA,QACR;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,MACA,WAAW;AAAA,QACV;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,MACA,SAAS;AAAA,QACR;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,IACA,SAAS;AAAA,MACR,cAAc;AAAA,QACb;AAAA,UACC,MAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,IACA,QAAQ;AAAA,MACP,KAAK;AAAA,QACJ,YAAY;AAAA,UACX,WAAW;AAAA,YACV;AAAA,cACC,MAAM;AAAA,YACP;AAAA,UACD;AAAA,UACA,cAAc;AAAA,YACb;AAAA,cACC,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,QACA,OAAO;AAAA,UACN,SAAS;AAAA,YACR;AAAA,cACC,MAAM;AAAA,YACP;AAAA,UACD;AAAA,UACA,WAAW;AAAA,YACV;AAAA,cACC,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,QACA,SAAS;AAAA,UACR,cAAc;AAAA,YACb;AAAA,cACC,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA,iBAAiB;AAAA,IAChB;AAAA,MACC,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EACA,eAAe;AAAA,IACd;AAAA,MACC,OAAO;AAAA,IACR;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"wp-plugin-i18n.js","sourceRoot":"","sources":["../../src/assets/wp-plugin-i18n.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,aAAa;IACnB,GAAG,EAAE,YAAY;IACjB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,YAAY;IACvB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;CACzB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/wp-plugin-i18n.ts"],
4
+ "sourcesContent": ["export default {\n\tname: \"Plugin Name\",\n\tslug: \"Plugin Slug\",\n\turl: \"Plugin URI\",\n\tdescription: \"Description\",\n\tversion: \"Version\",\n\tauthor: \"Author\",\n\tauthorUri: \"Author URI\",\n\ttags: \"Tags\",\n\tlicense: \"License\",\n\tlicenseUri: \"License URI\",\n\tupdateUri: \"Update URI\",\n\tdomainPath: \"Domain Path\",\n\ttextDomain: \"Text Domain\",\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,yBAAQ;AAAA,EACd,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,aAAa;AAAA,EACb,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,MAAM;AAAA,EACN,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACb;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"wp-theme-i18n.js","sourceRoot":"","sources":["../../src/assets/wp-theme-i18n.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,IAAI,EAAE,YAAY;IAClB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,YAAY;IACvB,WAAW,EAAE,aAAa;IAC1B,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;CACzB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/assets/wp-theme-i18n.ts"],
4
+ "sourcesContent": ["export default {\n\tname: \"Theme Name\",\n\tauthor: \"Author\",\n\tauthorUri: \"Author URI\",\n\tdescription: \"Description\",\n\turl: \"Theme URI\",\n\ttags: \"Tags\",\n\tversion: \"Version\",\n\tlicense: \"License\",\n\tlicenseUri: \"License URI\",\n\tdomainPath: \"Domain Path\",\n\ttextDomain: \"Text Domain\",\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,wBAAQ;AAAA,EACd,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,aAAa;AAAA,EACb,KAAK;AAAA,EACL,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AACb;",
6
+ "names": []
7
+ }
@@ -1 +1 @@
1
- "use strict";var l=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0})},n=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!f.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(r=b(t,s))||r.enumerable});return e};var a=(e,t,i)=>(i=e!=null?l(u(e)):{},n(t||!e||!e.__esModule?o(i,"default",{value:e,enumerable:!0}):i,e)),m=e=>n(o({},"__esModule",{value:!0}),e);var S={};y(S,{getArgs:()=>h});module.exports=m(S);var p=a(require("node:process")),k=a(require("yargs")),d=require("yargs/helpers"),c=require("./parseCli.js");function h(e={}){const t=k.default((0,d.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("sourceDirectory",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({slug:{describe:"Plugin or theme slug",type:"string"},domain:{describe:"Text domain to look for in the source code",type:"string"},"skip-js":{describe:"Skip JavaScript files",type:"boolean"},"skip-php":{describe:"Skip PHP files",type:"boolean"},"skip-blade":{describe:"Skip Blade files",type:"boolean"},"skip-block-json":{describe:"Skip block.json files",type:"boolean"},"skip-theme-json":{describe:"Skip theme.json files",type:"boolean"},"skip-audit":{describe:"Skip auditing of strings",type:"boolean",default:!1},headers:{describe:"Additional Headers",type:"array",default:[]},"file-comment":{describe:"File comment",type:"string"},"package-name":{describe:"Package name",type:"string"},location:{describe:"Include location information",type:"boolean"},"ignore-domain":{describe:"Ignore text domain",type:"boolean"},mergePaths:{describe:"Merge with existing POT file(s)",type:"string"},subtractPaths:{describe:"Subtract strings from existing POT file(s)",type:"string"},subtractAndMerge:{describe:"Subtract and merge strings from existing POT file(s)",type:"boolean"},include:{describe:"Include specific files",type:"string",default:"**"},exclude:{describe:"Exclude specific files",type:"string"},silent:{describe:"No output to stdout",type:"boolean",default:!1},json:{describe:"Output the json gettext data",type:"boolean"},output:{describe:"Output the gettext data",type:"boolean"},charset:{describe:"Charset",type:"string",default:"latin1"},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,c.parseCliArgs)({...e,...t})}0&&(module.exports={getArgs});
1
+ "use strict";var d=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0})},n=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!m.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(r=b(t,s))||r.enumerable});return e};var a=(e,t,i)=>(i=e!=null?d(u(e)):{},n(t||!e||!e.__esModule?o(i,"default",{value:e,enumerable:!0}):i,e)),y=e=>n(o({},"__esModule",{value:!0}),e);var S={};f(S,{getArgs:()=>k});module.exports=y(S);var c=a(require("node:process")),h=a(require("yargs")),l=require("yargs/helpers"),p=require("./parseCli.js");function k(e={}){const t=h.default((0,l.hideBin)(c.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("sourceDirectory",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({slug:{describe:"Plugin or theme slug",type:"string"},domain:{describe:"Text domain to look for in the source code. Valid domains are: plugin, theme, block, theme-block, generic.",choices:["plugin","theme","block","theme-block","generic"],type:"string"},"skip-js":{describe:"Skip JavaScript files",type:"boolean"},"skip-php":{describe:"Skip PHP files",type:"boolean"},"skip-blade":{describe:"Skip Blade files",type:"boolean"},"skip-block-json":{describe:"Skip block.json files",type:"boolean"},"skip-theme-json":{describe:"Skip theme.json files",type:"boolean"},"skip-audit":{describe:"Skip auditing of strings",type:"boolean",default:!1},headers:{describe:"Additional Headers",type:"array",default:[]},"file-comment":{describe:"File comment",type:"string"},"package-name":{describe:"Package name",type:"string"},location:{describe:"Include location information",type:"boolean"},"ignore-domain":{describe:"Ignore text domain",type:"boolean"},mergePaths:{describe:"Merge with existing POT file(s)",type:"string"},subtractPaths:{describe:"Subtract strings from existing POT file(s)",type:"string"},subtractAndMerge:{describe:"Subtract and merge strings from existing POT file(s)",type:"boolean"},include:{describe:"Include specific files",type:"string",default:"**"},exclude:{describe:"Exclude specific files",type:"string"},silent:{describe:"No output to stdout",type:"boolean",default:!1},json:{describe:"Output the json gettext data",type:"boolean"},output:{describe:"Output the gettext data",type:"boolean"},charset:{describe:"Charset",type:"string",default:"latin1"},"translation-domains":{describe:"Restrict to specific translation domains",type:"array"},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,p.parseCliArgs)({...e,...t})}0&&(module.exports={getArgs});
@@ -1 +1,7 @@
1
- {"version":3,"file":"getArgs.js","sourceRoot":"","sources":["../../src/cli/getArgs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0BAoHC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AAC,CAAC;AAC/C,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/cli/getArgs.ts"],
4
+ "sourcesContent": ["import process from \"node:process\";\r\nimport * as yargs from \"yargs\";\r\nimport { hideBin } from \"yargs/helpers\";\r\nimport type { Args, MakeJsonArgs } from \"../types.js\";\r\nimport { parseCliArgs } from \"./parseCli.js\";\r\n\r\n/**\r\n * Retrieves and returns the command line arguments and options.\r\n *\r\n * @return The parsed command line arguments and options.\r\n */\r\nexport function getArgs(userArgs = {}): Args | MakeJsonArgs {\r\n\tconst args = yargs\r\n\t\t.default(hideBin(process.argv))\r\n\t\t.help(\"h\")\r\n\t\t.alias(\"help\", \"help\")\r\n\t\t.usage(\"Usage: $0 <source> [destination] [options]\")\r\n\t\t.positional(\"sourceDirectory\", {\r\n\t\t\tdescribe: \"Source directory\",\r\n\t\t\ttype: \"string\",\r\n\t\t})\r\n\t\t.positional(\"destination\", {\r\n\t\t\tdescribe: \"Destination directory\",\r\n\t\t\ttype: \"string\",\r\n\t\t})\r\n\t\t.options({\r\n\t\t\tslug: {\r\n\t\t\t\tdescribe: \"Plugin or theme slug\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\tdomain: {\r\n\t\t\t\tdescribe: \"Text domain to look for in the source code. Valid domains are: plugin, theme, block, theme-block, generic.\",\r\n\t\t\t\tchoices: [\"plugin\", \"theme\", \"block\", \"theme-block\", \"generic\"],\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\t\"skip-js\": {\r\n\t\t\t\tdescribe: \"Skip JavaScript files\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"skip-php\": {\r\n\t\t\t\tdescribe: \"Skip PHP files\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"skip-blade\": {\r\n\t\t\t\tdescribe: \"Skip Blade files\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"skip-block-json\": {\r\n\t\t\t\tdescribe: \"Skip block.json files\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"skip-theme-json\": {\r\n\t\t\t\tdescribe: \"Skip theme.json files\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"skip-audit\": {\r\n\t\t\t\tdescribe: \"Skip auditing of strings\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t\tdefault: false,\r\n\t\t\t},\r\n\t\t\theaders: {\r\n\t\t\t\tdescribe: \"Additional Headers\",\r\n\t\t\t\ttype: \"array\",\r\n\t\t\t\tdefault: [],\r\n\t\t\t},\r\n\t\t\t\"file-comment\": {\r\n\t\t\t\tdescribe: \"File comment\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\t\"package-name\": {\r\n\t\t\t\tdescribe: \"Package name\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\tlocation: {\r\n\t\t\t\tdescribe: \"Include location information\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\t\"ignore-domain\": {\r\n\t\t\t\tdescribe: \"Ignore text domain\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\tmergePaths: {\r\n\t\t\t\tdescribe: \"Merge with existing POT file(s)\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\tsubtractPaths: {\r\n\t\t\t\tdescribe: \"Subtract strings from existing POT file(s)\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\tsubtractAndMerge: {\r\n\t\t\t\tdescribe: \"Subtract and merge strings from existing POT file(s)\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\tinclude: {\r\n\t\t\t\tdescribe: \"Include specific files\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t\tdefault: \"**\",\r\n\t\t\t},\r\n\t\t\texclude: {\r\n\t\t\t\tdescribe: \"Exclude specific files\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t},\r\n\t\t\tsilent: {\r\n\t\t\t\tdescribe: \"No output to stdout\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t\tdefault: false,\r\n\t\t\t},\r\n\t\t\tjson: {\r\n\t\t\t\tdescribe: \"Output the json gettext data\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\toutput: {\r\n\t\t\t\tdescribe: \"Output the gettext data\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t},\r\n\t\t\tcharset: {\r\n\t\t\t\tdescribe: \"Charset\",\r\n\t\t\t\ttype: \"string\",\r\n\t\t\t\tdefault: \"latin1\",\r\n\t\t\t},\r\n\t\t\t\"translation-domains\": {\r\n\t\t\t\tdescribe: \"Restrict to specific translation domains\",\r\n\t\t\t\ttype: \"array\",\r\n\t\t\t},\r\n\t\t\tdebug: {\r\n\t\t\t\tdescribe: \"Debug mode\",\r\n\t\t\t\ttype: \"boolean\",\r\n\t\t\t\tdefault: false,\r\n\t\t\t},\r\n\t\t})\r\n\t\t.parseSync();\r\n\treturn parseCliArgs({ ...userArgs, ...args });\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAoB;AACpB,YAAuB;AACvB,qBAAwB;AAExB,sBAA6B;AAOtB,SAAS,QAAQ,WAAW,CAAC,GAAwB;AAC3D,QAAM,OAAO,MACX,YAAQ,wBAAQ,oBAAAA,QAAQ,IAAI,CAAC,EAC7B,KAAK,GAAG,EACR,MAAM,QAAQ,MAAM,EACpB,MAAM,4CAA4C,EAClD,WAAW,mBAAmB;AAAA,IAC9B,UAAU;AAAA,IACV,MAAM;AAAA,EACP,CAAC,EACA,WAAW,eAAe;AAAA,IAC1B,UAAU;AAAA,IACV,MAAM;AAAA,EACP,CAAC,EACA,QAAQ;AAAA,IACR,MAAM;AA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Q;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,MAAM;AAAA,MACL,UAAU;AAAA,MACV,MAAM;AAAA,IACP;AAAA,IACA,QAAQ;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACR,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,uBAAuB;AAAA,MACtB,UAAU;AAAA,MACV,MAAM;AAAA,IACP;AAAA,IACA,OAAO;AAAA,MACN,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,EACD,CAAC,EACA,UAAU;AACZ,aAAO,8BAAa,EAAE,GAAG,UAAU,GAAG,KAAK,CAAC;AAC7C;",
6
+ "names": ["process"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"getJsonArgs.js","sourceRoot":"","sources":["../../src/cli/getJsonArgs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,kCA+CC;AA3DD,gEAAmC;AACnC,6CAA+B;AAC/B,2CAAwC;AAExC,+CAA8C;AAE9C;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,cAAc,GAAG,EAAE;IAC9C,MAAM,IAAI,GAAG,KAAK;SAChB,OAAO,CAAC,IAAA,iBAAO,EAAC,sBAAO,CAAC,IAAI,CAAC,CAAC;SAC9B,IAAI,CAAC,GAAG,CAAC;SACT,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;SACrB,KAAK,CAAC,4CAA4C,CAAC;SACnD,UAAU,CAAC,QAAQ,EAAE;QACrB,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,UAAU,CAAC,aAAa,EAAE;QAC1B,QAAQ,EAAE,uBAAuB;QACjC,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,OAAO,CAAC;QACR,UAAU,EAAE;YACX,QAAQ,EAAE,yCAAyC;YACnD,IAAI,EAAE,QAAQ;SACd;QACD,cAAc,EAAE;YACf,QAAQ,EAAE,yCAAyC;YACnD,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,CAAC,IAAI,CAAC;SACf;QACD,KAAK,EAAE;YACN,QAAQ,EAAE,uBAAuB;YACjC,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI;SACb;QACD,WAAW,EAAE;YACZ,QAAQ,EAAE,mBAAmB;YAC7B,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;SACd;QACD,KAAK,EAAE;YACN,QAAQ,EAAE,YAAY;YACtB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;SACd;QACD,WAAW,EAAE;YACZ,QAAQ,EAAE,uCAAuC;YACjD,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI;SACb;KACD,CAAC;SACD,SAAS,EAAE,CAAC;IACd,OAAO,IAAA,2BAAa,EAAC,EAAE,GAAG,cAAc,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/cli/getJsonArgs.ts"],
4
+ "sourcesContent": ["import process from \"node:process\";\nimport * as yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport type { MakeJsonArgs } from \"../types.js\";\nimport { parseJsonArgs } from \"./parseCli.js\";\n\n/**\n * Parses the command line arguments for the JSON command.\n *\n * @param additionalArgs - Additional arguments to be parsed.\n * @returns The parsed command line arguments.\n */\nexport function getJsonArgs(additionalArgs = {}): MakeJsonArgs {\n\tconst args = yargs\n\t\t.default(hideBin(process.argv))\n\t\t.help(\"h\")\n\t\t.alias(\"help\", \"help\")\n\t\t.usage(\"Usage: $0 <source> [destination] [options]\")\n\t\t.positional(\"source\", {\n\t\t\tdescribe: \"Source directory\",\n\t\t\ttype: \"string\",\n\t\t})\n\t\t.positional(\"destination\", {\n\t\t\tdescribe: \"Destination directory\",\n\t\t\ttype: \"string\",\n\t\t})\n\t\t.options({\n\t\t\tscriptName: {\n\t\t\t\tdescribe: \"The name of the script to be translated\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tallowedFormats: {\n\t\t\t\tdescribe: \"which extensions to use for translation\",\n\t\t\t\ttype: \"array\",\n\t\t\t\tdefault: [\"js\"],\n\t\t\t},\n\t\t\tpurge: {\n\t\t\t\tdescribe: \"Remove old JSON files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefault: true,\n\t\t\t},\n\t\t\tprettyPrint: {\n\t\t\t\tdescribe: \"Pretty print JSON\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\tdebug: {\n\t\t\t\tdescribe: \"Debug mode\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\tstripUnused: {\n\t\t\t\tdescribe: \"Strip unused translations in js files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefault: true,\n\t\t\t},\n\t\t})\n\t\t.parseSync();\n\treturn parseJsonArgs({ ...additionalArgs, ...args });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAoB;AACpB,YAAuB;AACvB,qBAAwB;AAExB,sBAA8B;AAQvB,SAAS,YAAY,iBAAiB,CAAC,GAAiB;AAC9D,QAAM,OAAO,MACX,YAAQ,wBAAQ,oBAAAA,QAAQ,IAAI,CAAC,EAC7B,KAAK,GAAG,EACR,MAAM,QAAQ,MAAM,EACpB,MAAM,4CAA4C,EAClD,WAAW,UAAU;AAAA,IACrB,UAAU;AAAA,IACV,MAAM;AAAA,EACP,CAAC,EACA,WAAW,eAAe;AAAA,IAC1B,UAAU;AAAA,IACV,MAAM;AAAA,EACP,CAAC,EACA,QAAQ;AAAA,IACR,YAAY;AAAA,MACX,UAAU;AAAA,MACV,MAAM;AAAA,IACP;AAAA,IACA,gBAAgB;AAAA,MACf,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS,CAAC,IAAI;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACN,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,aAAa;AAAA,MACZ,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,OAAO;AAAA,MACN,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,aAAa;AAAA,MACZ,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,EACD,CAAC,EACA,UAAU;AACZ,aAAO,+BAAc,EAAE,GAAG,gBAAgB,GAAG,KAAK,CAAC;AACpD;",
6
+ "names": ["process"]
7
+ }
@@ -1 +1 @@
1
- "use strict";var w=Object.create;var u=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var v=(t,n)=>{for(var e in n)u(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of T(n))!j.call(t,s)&&s!==e&&u(t,s,{get:()=>n[s],enumerable:!(o=J(n,s))||o.enumerable});return t};var d=(t,n,e)=>(e=t!=null?w(_(t)):{},g(n||!t||!t.__esModule?u(e,"default",{value:t,enumerable:!0}):e,t)),O=t=>g(u({},"__esModule",{value:!0}),t);var $={};v($,{parseCliArgs:()=>C,parseJsonArgs:()=>N});module.exports=O($);var c=d(require("node:fs")),i=d(require("node:path")),f=d(require("node:process")),y=require("../const.js"),k=require("../fs/fs"),a=require("../utils/common.js");function S(t="/",n="default"){const e=t;try{return(0,c.accessSync)(i.join(e,`${n}.php`),c.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${e} does not contain a ${n}.php file`)}try{return(0,c.accessSync)(i.join(e,"style.css"),c.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${e} does not contain a style.css file`)}return"generic"}function C(t){const n=t._[0]?.toString(),e=t._[1]?.toString()||"languages",o=n??".",s=e.startsWith("/")?e.slice(1):e,r=f.cwd(),p=t.slug&&typeof t.slug=="string"?t.slug:i.basename(i.resolve(r,o)),m=i.relative(r,o),b=i.relative(r,s);if(!t?.domain)t.domain=S(i.resolve(m),p);else switch(t.domain){case"plugin":case"theme":case"block":case"theme-block":break;default:console.error(`Invalid domain: ${t.domain}. Valid domains are: plugin, theme, block, theme-block, generic`),t.domain="generic"}const l={};for(const P of t.headers){const[A,D]=P.split(":");l[A.trim()]=D.trim()}const h={slug:p,debug:!!t.debug,domain:t.domain,paths:{cwd:m,out:b},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,headers:l,theme:!!t?.theme,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,charset:(0,k.getEncodingCharset)(t?.charset),skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit}},patterns:{mergePaths:(0,a.stringstring)(t.mergePaths),subtractPaths:(0,a.stringstring)(t.subtractPaths),subtractAndMerge:!!t.subtractAndMerge,include:(0,a.stringstring)(t.include),exclude:[...(0,a.stringstring)(t.exclude),...y.DEFAULT_EXCLUDED_PATH]}};return h.paths.root=t.root?String(t.root):void 0,h}function N(t){const n=t._[0]||"build",e=t._[1]||"languages",o=f.cwd(),s=i.basename(i.resolve(o));let r;return t.scriptName&&(r=t.scriptName.split(",").map(p=>p.trim()),r.length===1&&(r=r[0])),{timeStart:Date.now(),slug:s,source:n,destination:e,scriptName:r,allowedFormats:t.allowedFormats,purge:!!t.purge,stripUnused:!!t.stripUnused,prettyPrint:!!t.prettyPrint,debug:!!t.debug,paths:{cwd:o,out:i.join(o,e)}}}0&&(module.exports={parseCliArgs,parseJsonArgs});
1
+ "use strict";var w=Object.create;var m=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var j=(t,n)=>{for(var e in n)m(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of S(n))!T.call(t,s)&&s!==e&&m(t,s,{get:()=>n[s],enumerable:!(o=_(n,s))||o.enumerable});return t};var u=(t,n,e)=>(e=t!=null?w(J(t)):{},g(n||!t||!t.__esModule?m(e,"default",{value:t,enumerable:!0}):e,t)),v=t=>g(m({},"__esModule",{value:!0}),t);var $={};j($,{parseCliArgs:()=>C,parseJsonArgs:()=>N});module.exports=v($);var a=u(require("node:fs")),i=u(require("node:path")),f=u(require("node:process")),y=require("../const.js"),k=require("../fs/fs"),c=require("../utils/common.js");function O(t="/",n="default"){const e=t;try{return(0,a.accessSync)(i.join(e,`${n}.php`),a.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${e} does not contain a ${n}.php file`)}try{return(0,a.accessSync)(i.join(e,"style.css"),a.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${e} does not contain a style.css file`)}return"generic"}function C(t){const n=t._[0]?.toString(),e=t._[1]?.toString()||"languages",o=n??".",s=e.startsWith("/")?e.slice(1):e,r=f.cwd(),p=t.slug&&typeof t.slug=="string"?t.slug:i.basename(i.resolve(r,o)),l=i.relative(r,o),b=i.relative(r,s);if(!t?.domain)t.domain=O(i.resolve(l),p);else switch(t.domain){case"plugin":case"theme":case"block":case"theme-block":break;default:console.error(`Invalid domain: ${t.domain}. Valid domains are: plugin, theme, block, theme-block, generic`),t.domain="generic"}const d={};for(const D of t.headers){const[P,A]=D.split(":");d[P.trim()]=A.trim()}const h={slug:p,debug:!!t.debug,domain:t.domain,paths:{cwd:l,out:b},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,headers:d,theme:!!t?.theme,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,charset:(0,k.getEncodingCharset)(t?.charset),skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit},translationDomains:t.translationDomains?Array.isArray(t.translationDomains)?t.translationDomains.map(String):[String(t.translationDomains)]:void 0},patterns:{mergePaths:(0,c.stringstring)(t.mergePaths),subtractPaths:(0,c.stringstring)(t.subtractPaths),subtractAndMerge:!!t.subtractAndMerge,include:(0,c.stringstring)(t.include),exclude:[...(0,c.stringstring)(t.exclude),...y.DEFAULT_EXCLUDED_PATH]}};return h.paths.root=t.root?String(t.root):void 0,h}function N(t){const n=t._[0]||"build",e=t._[1]||"languages",o=f.cwd(),s=i.basename(i.resolve(o));let r;return t.scriptName&&(r=t.scriptName.split(",").map(p=>p.trim()),r.length===1&&(r=r[0])),{timeStart:Date.now(),slug:s,source:n,destination:e,scriptName:r,allowedFormats:t.allowedFormats,purge:!!t.purge,stripUnused:!!t.stripUnused,prettyPrint:!!t.prettyPrint,debug:!!t.debug,paths:{cwd:o,out:i.join(o,e)}}}0&&(module.exports={parseCliArgs,parseJsonArgs});
@@ -1 +1,7 @@
1
- {"version":3,"file":"parseCli.js","sourceRoot":"","sources":["../../src/cli/parseCli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,oCA4FC;AAMD,sCAiCC;AA9LD,mDAAyC;AACzC,gDAAkC;AAClC,sDAAwC;AAExC,0CAAoD;AACpD,iCAA8C;AAE9C,kDAAkD;AAElD;;;;GAIG;AACH,SAAS,eAAe,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,GAAG,SAAS;IAC3D,MAAM,uBAAuB,GAAG,WAAW,CAAC;IAE5C;;OAEG;IACH,IAAI,CAAC;QACJ,IAAA,oBAAU,EACT,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE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C,cAA0B;QAC/C,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK;QACnB,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;QAC/B,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;QAC/B,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK;QACnB,KAAK,EAAE;YACN,GAAG,EAAE,uBAAuB;YAC5B,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC;SACnD;KACD,CAAC;AACH,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/cli/parseCli.ts"],
4
+ "sourcesContent": ["import fs, { accessSync } from \"node:fs\";\r\nimport * as path from \"node:path\";\r\nimport * as process from \"node:process\";\r\nimport type * as yargs from \"yargs\";\r\nimport { DEFAULT_EXCLUDED_PATH } from \"../const.js\";\r\nimport { getEncodingCharset } from \"../fs/fs\";\r\nimport type { Args, DomainType, MakeJsonArgs, PotHeaders } from \"../types.js\";\r\nimport { stringstring } from \"../utils/common.js\";\r\n\r\n/**\r\n * This function checks if the current working directory is a theme or plugin\r\n * @param currentPath The current working directory\r\n * @param slug The slug of the theme or plugin\r\n */\r\nfunction isThemeOrPlugin(currentPath = \"/\", slug = \"default\"): DomainType {\r\n\tconst currentWorkingDirectory = currentPath;\r\n\r\n\t/**\r\n\t * Checks if the current working directory contains a plugin file\r\n\t */\r\n\ttry {\r\n\t\taccessSync(\r\n\t\t\tpath.join(currentWorkingDirectory, `${slug}.php`),\r\n\t\t\tfs.constants.R_OK,\r\n\t\t);\r\n\t\treturn \"plugin\";\r\n\t} catch (_err) {\r\n\t\t// do nothing\r\n\t\tconsole.log(\r\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a ${slug}.php file`,\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the current working directory contains a style.css file and is a theme\r\n\t */\r\n\ttry {\r\n\t\taccessSync(\r\n\t\t\tpath.join(currentWorkingDirectory, \"style.css\"),\r\n\t\t\tfs.constants.R_OK,\r\n\t\t);\r\n\t\treturn \"theme\";\r\n\t} catch (_err) {\r\n\t\t// do nothing\r\n\t\tconsole.log(\r\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a style.css file`,\r\n\t\t);\r\n\t}\r\n\r\n\t// If none of the above conditions are met, return \"generic\"\r\n\treturn \"generic\";\r\n}\r\n\r\n/**\r\n * Parses the command line arguments and returns an object with the parsed values.\r\n *\r\n * @param {{_: string[]}} args - The command line arguments to be parsed.\r\n * @return {object} - An object with the parsed values from the command line arguments.\r\n */\r\nexport function parseCliArgs(\r\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\r\n): Args {\r\n\t// Get the input and output paths\r\n\tconst pos1: string | undefined = args._[0]?.toString();\r\n\tconst pos2: string = args._[1]?.toString() || \"languages\";\r\n\r\n\tconst inputPath: string | undefined = pos1 ?? \".\";\r\n\t// remove \"/\" if the output path starts with it\r\n\tconst outputPath: string = pos2.startsWith(\"/\") ? pos2.slice(1) : pos2;\r\n\r\n\t// Store the current working directory\r\n\tconst currentWorkingDirectory = process.cwd();\r\n\r\n\t// Get the slug or use the basename of the current working directory\r\n\t// the slug is the plugin or theme slug. Defaults to the source directory\u2019s basename\r\n\tconst slug =\r\n\t\targs.slug && typeof args.slug === \"string\"\r\n\t\t\t? args.slug\r\n\t\t\t: path.basename(path.resolve(currentWorkingDirectory, inputPath));\r\n\r\n\t// Get the relative paths\r\n\tconst cwd = path.relative(currentWorkingDirectory, inputPath);\r\n\tconst out = path.relative(currentWorkingDirectory, outputPath);\r\n\r\n\t/** get the domain to look for (plugin, theme, etc) */\r\n\tif (!(args?.domain as DomainType)) {\r\n\t\targs.domain = isThemeOrPlugin(path.resolve(cwd), slug);\r\n\t} else {\r\n\t\tswitch (args.domain) {\r\n\t\t\tcase \"plugin\":\r\n\t\t\tcase \"theme\":\r\n\t\t\tcase \"block\":\r\n\t\t\tcase \"theme-block\":\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t`Invalid domain: ${args.domain}. Valid domains are: plugin, theme, block, theme-block, generic`,\r\n\t\t\t\t);\r\n\t\t\t\t// fallback to generic if the domain is invalid\r\n\t\t\t\targs.domain = \"generic\";\r\n\t\t}\r\n\t}\r\n\r\n\t// Collect the headers passed via cli\r\n\tconst headers = {};\r\n\tfor (const header of args.headers) {\r\n\t\tconst [key, value] = header.split(\":\") as Record<PotHeaders, string>;\r\n\t\theaders[key.trim()] = value.trim();\r\n\t}\r\n\r\n\tconst parsedArgs: Args = {\r\n\t\tslug: slug,\r\n\t\tdebug: !!args.debug,\r\n\t\tdomain: args.domain as DomainType,\r\n\t\tpaths: { cwd: cwd, out: out },\r\n\t\toptions: {\r\n\t\t\tignoreDomain: !!args?.ignoreDomain,\r\n\t\t\tpackageName: String(args.packageName),\r\n\t\t\tsilent: args.silent === true, // default is false\r\n\t\t\tjson: !!args.json,\r\n\t\t\tlocation: !!args?.location,\r\n\t\t\theaders: headers as Record<PotHeaders, string>,\r\n\t\t\ttheme: !!args?.theme,\r\n\t\t\toutput: !!args?.output,\r\n\t\t\tfileComment: args.fileComment ? String(args.fileComment) : undefined,\r\n\t\t\tcharset: getEncodingCharset(args?.charset as string | undefined),\r\n\t\t\tskip: {\r\n\t\t\t\tjs: !!args.skipJs,\r\n\t\t\t\tphp: !!args.skipPhp,\r\n\t\t\t\tblade: !!args.skipBlade,\r\n\t\t\t\tblockJson: !!args.skipBlockJson,\r\n\t\t\t\tthemeJson: !!args.skipThemeJson,\r\n\t\t\t\taudit: !!args.skipAudit,\r\n\t\t\t},\r\n\t\t\ttranslationDomains: args.translationDomains\r\n\t\t\t\t? Array.isArray(args.translationDomains)\r\n\t\t\t\t\t? args.translationDomains.map(String)\r\n\t\t\t\t\t: [String(args.translationDomains)]\r\n\t\t\t\t: undefined,\r\n\t\t},\r\n\t\t// Patterns\r\n\t\tpatterns: {\r\n\t\t\tmergePaths: stringstring(args.mergePaths as string),\r\n\t\t\tsubtractPaths: stringstring(args.subtractPaths as string),\r\n\t\t\tsubtractAndMerge: !!args.subtractAndMerge,\r\n\t\t\tinclude: stringstring(args.include as string),\r\n\t\t\texclude: [\r\n\t\t\t\t...stringstring(args.exclude as string),\r\n\t\t\t\t...DEFAULT_EXCLUDED_PATH,\r\n\t\t\t],\r\n\t\t},\r\n\t};\r\n\r\n\tparsedArgs.paths.root = args.root ? String(args.root) : undefined;\r\n\r\n\treturn parsedArgs;\r\n}\r\n\r\n/**\r\n * Parses the command line arguments for the JSON command.\r\n * @param args - The command line arguments to be parsed.\r\n */\r\nexport function parseJsonArgs(\r\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\r\n): MakeJsonArgs {\r\n\t// Get the input and output paths\r\n\tconst inputPath: string = (args._[0] as string) || \"build\";\r\n\tconst outputPath: string = (args._[1] as string) || \"languages\";\r\n\tconst currentWorkingDirectory = process.cwd();\r\n\tconst slug = path.basename(path.resolve(currentWorkingDirectory));\r\n\r\n\tlet scriptName: string;\r\n\tif (args.scriptName) {\r\n\t\tscriptName = args.scriptName.split(\",\").map((s) => s.trim());\r\n\t\tif (scriptName.length === 1) {\r\n\t\t\tscriptName = scriptName[0];\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\ttimeStart: Date.now(),\r\n\t\tslug,\r\n\t\tsource: inputPath,\r\n\t\tdestination: outputPath,\r\n\t\tscriptName,\r\n\t\tallowedFormats: args.allowedFormats as string[],\r\n\t\tpurge: !!args.purge,\r\n\t\tstripUnused: !!args.stripUnused,\r\n\t\tprettyPrint: !!args.prettyPrint,\r\n\t\tdebug: !!args.debug,\r\n\t\tpaths: {\r\n\t\t\tcwd: currentWorkingDirectory,\r\n\t\t\tout: path.join(currentWorkingDirectory, outputPath),\r\n\t\t},\r\n\t};\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAA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"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gEAAmC;AACnC,6CAA+B;AAC/B,2CAAwC;AACxC,iDAA2C;AAC3C,yDAAmD;AACnD,sEAA+C;AAC/C,oEAA6C;AAG7C,qBAAqB;AACrB,2BAA2B;AAC3B,MAAM,CAAC,GAAG,KAAK;KACb,OAAO,CAAC,IAAA,iBAAO,EAAC,sBAAO,CAAC,IAAI,CAAC,CAAC;KAC9B,OAAO,CAAC;IACR,QAAQ,EAAE;QACT,QAAQ,EAAE,gBAAgB;QAC1B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACd;CACD,CAAC;KACD,SAAS,EAA2B,CAAC;AAEvC,sBAAsB;AACtB,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjB,IAAA,uBAAc,EAAC,IAAA,oBAAO,GAAU,CAAC,CAAC;AACnC,CAAC;KAAM,CAAC;IACP,IAAA,wBAAe,EAAC,IAAA,4BAAW,GAAkB,CAAC,CAAC;AAChD,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\n\nimport process from \"node:process\";\nimport * as yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { getArgs } from \"./cli/getArgs.js\";\nimport { getJsonArgs } from \"./cli/getJsonArgs.js\";\nimport makeJsonCommand from \"./jsonCommand.js\";\nimport makepotCommand from \"./potCommand.js\";\nimport type { Args, MakeJsonArgs } from \"./types.js\";\n\n/** Main execution */\n// Get the selected command\nconst r = yargs\n\t.default(hideBin(process.argv))\n\t.options({\n\t\tmakejson: {\n\t\t\tdescribe: \"Make JSON file\",\n\t\t\ttype: \"boolean\",\n\t\t\tdefault: false,\n\t\t},\n\t})\n\t.parseSync() as { makejson: boolean };\n\n// Execute the command\nif (!r.makejson) {\n\tmakepotCommand(getArgs() as Args);\n} else {\n\tmakeJsonCommand(getJsonArgs() as MakeJsonArgs);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,0BAAoB;AACpB,YAAuB;AACvB,qBAAwB;AACxB,qBAAwB;AACxB,yBAA4B;AAC5B,yBAA4B;AAC5B,wBAA2B;AAK3B,MAAM,IAAI,MACR,YAAQ,wBAAQ,oBAAAA,QAAQ,IAAI,CAAC,EAC7B,QAAQ;AAAA,EACR,UAAU;AAAA,IACT,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS;AAAA,EACV;AACD,CAAC,EACA,UAAU;AAGZ,IAAI,CAAC,EAAE,UAAU;AAChB,wBAAAC,aAAe,wBAAQ,CAAS;AACjC,OAAO;AACN,yBAAAC,aAAgB,gCAAY,CAAiB;AAC9C;",
6
+ "names": ["process", "makepotCommand", "makeJsonCommand"]
7
+ }
package/lib/const.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,+EAAmD;AACnD,mFAAsD;AACtD,iFAAoD;AAEpD;;;GAGG;AACU,QAAA,cAAc,GAAG,yBAAW,CAAC;AAC1C;;;GAGG;AACU,QAAA,aAAa,GAAG,2BAAY,CAAC;AAC1C;;;GAGG;AACU,QAAA,YAAY,GAAG,0BAAW,CAAC;AAExC;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACpC,MAAM;IACN,cAAc;IACd,QAAQ;IACR,OAAO;IACP,MAAM;IACN,SAAS;IACT,cAAc;IACd,mBAAmB;IACnB,aAAa;IACb,aAAa;IACb,YAAY;IACZ,OAAO;CACP,CAAC;AAEF;;GAEG;AACU,QAAA,YAAY,GAAG,2BAA2B,CAAC;AAExD;;GAEG;AACU,QAAA,SAAS,GAAG,sBAAsB,CAAC;AAEnC,QAAA,aAAa,GAAG,OAAO,CAAC;AAErC;;;;GAIG;AACU,QAAA,cAAc,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI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OAAO,EAAE,aAAa,CAAC;IAE3B,cAAc;IACd,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;IAC5B,GAAG,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,CAAC;IACvD,UAAU,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,CAAC;IAC9D,eAAe,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,aAAa,CAAC;CACzD,CAAC;AAEF;;GAEG;AACU,QAAA,UAAU,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC"}
1
+ {
2
+ "version": 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\"**.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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,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EACrD,KAAK,CAAC,SAAS,gBAAgB,UAAU,WAAW,aAAa;AAAA,EACjE,SAAS,CAAC,SAAS,gBAAgB,aAAa;AAAA,EAChD,UAAU,CAAC,SAAS,gBAAgB,WAAW,aAAa;AAAA;AAAA,EAG5D,GAAG,CAAC,SAAS,aAAa;AAAA;AAAA,EAG1B,IAAI,CAAC,SAAS,aAAa;AAAA,EAC3B,KAAK,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EACtD,YAAY,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EAC7D,iBAAiB,CAAC,SAAS,gBAAgB,aAAa;AACzD;AAKO,MAAM,aAAa,iBAAAC,QAAK,QAAQ,WAAW,IAAI;",
6
+ "names": ["packagei18n", "wpPlugini18n", "wpThemei18n", "path"]
7
+ }
@@ -1,5 +1,5 @@
1
1
  "use strict";var p=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var S=(t,s)=>{for(var e in s)c(t,e,{get:s[e],enumerable:!0})},g=(t,s,e,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of R(s))!P.call(t,r)&&r!==e&&c(t,r,{get:()=>s[r],enumerable:!(o=f(s,r))||o.enumerable});return t};var _=(t,s,e)=>(e=t!=null?p(E(t)):{},g(s||!t||!t.__esModule?c(e,"default",{value:t,enumerable:!0}):e,t)),D=t=>g(c({},"__esModule",{value:!0}),t);var $={};S($,{audit:()=>T,default:()=>L});module.exports=D($);var u=require("node:fs"),d=_(require("node:path"));function T(t,s){const e=new m(t.domain);if(e.auditStrings(s.blocks),console.log(`
2
2
  Audit Complete!`),e.getResults().length===0){console.log("No issues found! \u{1F389}");try{(0,u.unlinkSync)(d.default.join(t.paths.cwd,"audit.log"))}catch{}}else{console.log(`Found ${e.getResults().length} issues!`);const o=e.getResults().join(`
3
- `);console.log(o),(0,u.writeFileSync)(d.default.join(t.paths.cwd,"audit.log"),o)}}class m{SPRINTF_PLACEHOLDER_REGEX=/%(?:\d+\$)?[+-]?(?:[ 0]|\'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;UNORDERED_SPRINTF_PLACEHOLDER_REGEX=/%(?!(\d+)\$)[+-]?(?:[ 0]|\'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;projectType;results=[];constructor(s){this.projectType=s}getFileHeaders(s){return{plugin:["Plugin Name:","Plugin URI:","Description:","Author:","Author URI:","Version:","Text Domain:","Domain Path:","Network:","Requires at least:","Requires PHP:"],theme:["Theme Name:","Theme URI:","Author:","Author URI:","Description:","Version:","License:","License URI:","Text Domain:","Domain Path:","Tags:","Requires at least:","Requires PHP:"]}[s]||[]}auditStrings(s){for(const e of s){const o=e.comments?.reference||[],r=o.length>0?`(${o[0]})`:"";if(!e.msgid)continue;if((!e.comments?.extracted||e.comments.extracted.length===0)&&(e.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX)||[]).length>=1){const n=`The string "${e.msgid}" contains placeholders but has no "translators:" comment to clarify their meaning. ${r}`;this.results.push(n)}if(e.comments?.extracted&&e.comments.extracted.length>0){let n=e.comments.extracted;n=n.filter(i=>{for(const h of this.getFileHeaders(this.projectType))if(i.startsWith(h))return!1;return!0});const a=[];n=n.filter(i=>a.includes(i)?!1:(a.push(i),!0));const l=n.length;if(l>1){const i=`The string "${e.msgid}" has ${l} different translator comments. ${r}
3
+ `);console.log(o),(0,u.writeFileSync)(d.default.join(t.paths.cwd,"audit.log"),o)}}class m{SPRINTF_PLACEHOLDER_REGEX=/%(?:\d+\$)?[+-]?(?:[ 0]|'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;UNORDERED_SPRINTF_PLACEHOLDER_REGEX=/%(?!(\d+)\$)[+-]?(?:[ 0]|'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;projectType;results=[];constructor(s){this.projectType=s}getFileHeaders(s){return{plugin:["Plugin Name:","Plugin URI:","Description:","Author:","Author URI:","Version:","Text Domain:","Domain Path:","Network:","Requires at least:","Requires PHP:"],theme:["Theme Name:","Theme URI:","Author:","Author URI:","Description:","Version:","License:","License URI:","Text Domain:","Domain Path:","Tags:","Requires at least:","Requires PHP:"]}[s]||[]}auditStrings(s){for(const e of s){const o=e.comments?.reference||[],r=o.length>0?`(${o[0]})`:"";if(!e.msgid)continue;if((!e.comments?.extracted||e.comments.extracted.length===0)&&(e.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX)||[]).length>=1){const n=`The string "${e.msgid}" contains placeholders but has no "translators:" comment to clarify their meaning. ${r}`;this.results.push(n)}if(e.comments?.extracted&&e.comments.extracted.length>0){let n=e.comments.extracted;n=n.filter(i=>{for(const h of this.getFileHeaders(this.projectType))if(i.startsWith(h))return!1;return!0});const a=[];n=n.filter(i=>a.includes(i)?!1:(a.push(i),!0));const l=n.length;if(l>1){const i=`The string "${e.msgid}" has ${l} different translator comments. ${r}
4
4
  ${n.join(`
5
5
  `)}`;this.results.push(i)}}if(e.msgid.trim().replace(/^(['"])(.*)\1$/s,"$2").replace(this.SPRINTF_PLACEHOLDER_REGEX,"")===""){const n=`Found string without translatable content. ${r}`;this.results.push(n)}if((e.msgid.match(this.UNORDERED_SPRINTF_PLACEHOLDER_REGEX)||[]).length>=2){const n=`Multiple placeholders should be ordered. ${r}`;this.results.push(n)}if(e.msgid_plural){const n=e.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX)||[],a=e.msgid_plural.match(this.SPRINTF_PLACEHOLDER_REGEX)||[];if(n.length<a.length){const l=`Missing singular placeholder, needed for some languages. See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plurals ${r}`;this.results.push(l)}else{const l=[...n].sort(),i=[...a].sort();if(JSON.stringify(l)!==JSON.stringify(i)){const h=`Mismatched placeholders for singular and plural string. ${r}`;this.results.push(h)}}}}}getResults(){return this.results}}var L=m;0&&(module.exports={audit});
@@ -1 +1,7 @@
1
- {"version":3,"file":"auditStrings.js","sourceRoot":"","sources":["../../src/extractors/auditStrings.ts"],"names":[],"mappings":";;;;;AAKA,sBAsBC;AA3BD,qCAAoD;AACpD,0DAA6B;AAI7B,SAAgB,KAAK,CAAC,IAAU,EAAE,iBAA8B;IAC/D,4BAA4B;IAC5B,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,CAAC,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE/C,qDAAqD;IACrD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,0DAA0D;QAC1D,IAAI,CAAC;YACJ,IAAA,oBAAU,EAAC,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,QAAQ;QACT,CAAC;IACF,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,UAAU,CAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,wCAAwC;QACxC,IAAA,uBAAa,EAAC,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,aAAa;IACD,yBAAyB,GACzC,iEAAiE,CAAC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BAAkB,CAAC,MAAM,EAAE,CAAC;oBAC3D,6DAA6D;oBAC7D,MAAM,OAAO,GAAG,0KAA0K,QAAQ,EAAE,CAAC;oBACrM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;qBAAM,CAAC;oBACP,oEAAoE;oBACpE,MAAM,wBAAwB,GAAG,CAAC,GAAG,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC;oBAChE,MAAM,wBAAwB,GAAG,CAAC,GAAG,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC;oBAEhE,sEAAsE;oBACtE,IACC,IAAI,CAAC,SAAS,CAAC,wBAAwB,CAAC;wBACxC,IAAI,CAAC,SAAS,CAAC,wBAAwB,CAAC,EACvC,CAAC;wBACF,MAAM,OAAO,GAAG,2DAA2D,QAAQ,EAAE,CAAC;wBACtF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBAC5B,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;OAGG;IACI,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD;AAED,kBAAe,aAAa,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/auditStrings.ts"],
4
+ "sourcesContent": ["import { unlinkSync, writeFileSync } from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport type { Block, SetOfBlocks } from \"gettext-merger\";\r\nimport type { Args } from \"../types.js\";\r\n\r\nexport function audit(args: Args, translationsUnion: SetOfBlocks) {\r\n\t/** Run the audit process */\r\n\tconst auditor = new StringAuditor(args.domain);\r\n\tauditor.auditStrings(translationsUnion.blocks);\r\n\r\n\t/** Get and print the results of the audit process */\r\n\tconsole.log(\"\\nAudit Complete!\");\r\n\tif (auditor.getResults().length === 0) {\r\n\t\tconsole.log(\"No issues found! \uD83C\uDF89\");\r\n\t\t//if there are no errors, we can remove the audit.log file\r\n\t\ttry {\r\n\t\t\tunlinkSync(path.join(args.paths.cwd, \"audit.log\"));\r\n\t\t} catch (error) {\r\n\t\t\t//ignore\r\n\t\t}\r\n\t} else {\r\n\t\tconsole.log(`Found ${auditor.getResults().length} issues!`);\r\n\t\tconst results = auditor.getResults().join(\"\\n\");\r\n\t\tconsole.log(results);\r\n\t\t/** Write the audit results to a file */\r\n\t\twriteFileSync(path.join(args.paths.cwd, \"audit.log\"), results);\r\n\t}\r\n}\r\n\r\n/**\r\n * Class to audit gettext strings\r\n *\r\n * Example usage:\r\n * const auditor = new StringAuditor('plugin');\r\n * auditor.auditStrings(translationBlocks);\r\n */\r\nclass StringAuditor {\r\n\tprivate readonly SPRINTF_PLACEHOLDER_REGEX =\r\n\t\t/%(?:\\d+\\$)?[+-]?(?:[ 0]|'.)?-?\\d*(?:\\.\\d+)?[bcdeEfFgGhHosuxX]/g;\r\n\tprivate readonly UNORDERED_SPRINTF_PLACEHOLDER_REGEX =\r\n\t\t/%(?!(\\d+)\\$)[+-]?(?:[ 0]|'.)?-?\\d*(?:\\.\\d+)?[bcdeEfFgGhHosuxX]/g;\r\n\tprivate projectType: string;\r\n\r\n\t/**\r\n\t * The results of the audit process\r\n\t */\r\n\tpublic results: string[] = [];\r\n\r\n\tconstructor(projectType: string) {\r\n\t\tthis.projectType = projectType;\r\n\t}\r\n\r\n\tprivate getFileHeaders(projectType: string): string[] {\r\n\t\t// Implement based on your requirements\r\n\t\t// This would be the equivalent of the PHP get_file_headers method\r\n\t\tconst headers: Record<string, string[]> = {\r\n\t\t\tplugin: [\r\n\t\t\t\t\"Plugin Name:\",\r\n\t\t\t\t\"Plugin URI:\",\r\n\t\t\t\t\"Description:\",\r\n\t\t\t\t\"Author:\",\r\n\t\t\t\t\"Author URI:\",\r\n\t\t\t\t\"Version:\",\r\n\t\t\t\t\"Text Domain:\",\r\n\t\t\t\t\"Domain Path:\",\r\n\t\t\t\t\"Network:\",\r\n\t\t\t\t\"Requires at least:\",\r\n\t\t\t\t\"Requires PHP:\",\r\n\t\t\t],\r\n\t\t\ttheme: [\r\n\t\t\t\t\"Theme Name:\",\r\n\t\t\t\t\"Theme URI:\",\r\n\t\t\t\t\"Author:\",\r\n\t\t\t\t\"Author URI:\",\r\n\t\t\t\t\"Description:\",\r\n\t\t\t\t\"Version:\",\r\n\t\t\t\t\"License:\",\r\n\t\t\t\t\"License URI:\",\r\n\t\t\t\t\"Text Domain:\",\r\n\t\t\t\t\"Domain Path:\",\r\n\t\t\t\t\"Tags:\",\r\n\t\t\t\t\"Requires at least:\",\r\n\t\t\t\t\"Requires PHP:\",\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\treturn headers[projectType] || [];\r\n\t}\r\n\r\n\tauditStrings(translations: Block[]): void {\r\n\t\tfor (const translation of translations) {\r\n\t\t\tconst references = translation.comments?.reference || [];\r\n\r\n\t\t\t// File headers don't have any file references\r\n\t\t\tconst location = references.length > 0 ? `(${references[0]})` : \"\";\r\n\r\n\t\t\t// Check 0: Flag strings without msgid is the header so it's not a translation and should be ignored\r\n\t\t\tif (!translation.msgid) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Check 1: Flag strings with placeholders that should have translator comments\r\n\t\t\tif (\r\n\t\t\t\t(!translation.comments?.extracted ||\r\n\t\t\t\t\ttranslation.comments.extracted.length === 0) &&\r\n\t\t\t\t(translation.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX) || [])\r\n\t\t\t\t\t.length >= 1\r\n\t\t\t) {\r\n\t\t\t\tconst message = `The string \"${translation.msgid}\" contains placeholders but has no \"translators:\" comment to clarify their meaning. ${location}`;\r\n\t\t\t\tthis.results.push(message);\r\n\t\t\t}\r\n\r\n\t\t\t// Check 2: Flag strings with different translator comments\r\n\t\t\tif (\r\n\t\t\t\ttranslation.comments?.extracted &&\r\n\t\t\t\ttranslation.comments.extracted.length > 0\r\n\t\t\t) {\r\n\t\t\t\tlet comments = translation.comments.extracted;\r\n\r\n\t\t\t\t// Remove plugin header information from comments\r\n\t\t\t\tcomments = comments.filter((comment) => {\r\n\t\t\t\t\tfor (const fileHeader of this.getFileHeaders(this.projectType)) {\r\n\t\t\t\t\t\tif (comment.startsWith(fileHeader)) {\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tconst uniqueComments: string[] = [];\r\n\r\n\t\t\t\t// Remove duplicate comments\r\n\t\t\t\tcomments = comments.filter((comment) => {\r\n\t\t\t\t\tif (uniqueComments.includes(comment)) {\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tuniqueComments.push(comment);\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tconst commentsCount = comments.length;\r\n\r\n\t\t\t\tif (commentsCount > 1) {\r\n\t\t\t\t\tconst message = `The string \"${translation.msgid}\" has ${commentsCount} different translator comments. ${location}\\n${comments.join(\"\\n\")}`;\r\n\t\t\t\t\tthis.results.push(message);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Extract non-placeholder content from the string\r\n\t\t\tconst nonPlaceholderContent = translation.msgid\r\n\t\t\t\t.trim()\r\n\t\t\t\t.replace(/^(['\"])(.*)\\1$/s, \"$2\")\r\n\t\t\t\t.replace(this.SPRINTF_PLACEHOLDER_REGEX, \"\");\r\n\r\n\t\t\t// Check 3: Flag empty strings without any translatable content\r\n\t\t\tif (nonPlaceholderContent === \"\") {\r\n\t\t\t\tconst message = `Found string without translatable content. ${location}`;\r\n\t\t\t\tthis.results.push(message);\r\n\t\t\t}\r\n\r\n\t\t\t// Check 4: Flag strings with multiple unordered placeholders (%s %s %s vs. %1$s %2$s %3$s)\r\n\t\t\tconst unorderedMatches =\r\n\t\t\t\ttranslation.msgid.match(this.UNORDERED_SPRINTF_PLACEHOLDER_REGEX) || [];\r\n\t\t\tconst unorderedMatchesCount = unorderedMatches.length;\r\n\r\n\t\t\tif (unorderedMatchesCount >= 2) {\r\n\t\t\t\tconst message = `Multiple placeholders should be ordered. ${location}`;\r\n\t\t\t\tthis.results.push(message);\r\n\t\t\t}\r\n\r\n\t\t\tif (translation.msgid_plural) {\r\n\t\t\t\tconst singlePlaceholders =\r\n\t\t\t\t\ttranslation.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX) || [];\r\n\t\t\t\tconst pluralPlaceholders =\r\n\t\t\t\t\ttranslation.msgid_plural.match(this.SPRINTF_PLACEHOLDER_REGEX) || [];\r\n\r\n\t\t\t\t// See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plurals\r\n\t\t\t\tif (singlePlaceholders.length < pluralPlaceholders.length) {\r\n\t\t\t\t\t// Check 5: Flag things like _n('One comment', '%s Comments')\r\n\t\t\t\t\tconst message = `Missing singular placeholder, needed for some languages. See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plurals ${location}`;\r\n\t\t\t\t\tthis.results.push(message);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Reordering is fine, but mismatched placeholders is probably wrong\r\n\t\t\t\t\tconst sortedSinglePlaceholders = [...singlePlaceholders].sort();\r\n\t\t\t\t\tconst sortedPluralPlaceholders = [...pluralPlaceholders].sort();\r\n\r\n\t\t\t\t\t// Check 6: Flag things like _n('%s Comment (%d)', '%s Comments (%s)')\r\n\t\t\t\t\tif (\r\n\t\t\t\t\t\tJSON.stringify(sortedSinglePlaceholders) !==\r\n\t\t\t\t\t\tJSON.stringify(sortedPluralPlaceholders)\r\n\t\t\t\t\t) {\r\n\t\t\t\t\t\tconst message = `Mismatched placeholders for singular and plural string. ${location}`;\r\n\t\t\t\t\t\tthis.results.push(message);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Get the results of the audit process\r\n\t * @returns An array of messages\r\n\t */\r\n\tpublic getResults(): string[] {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CAAC;QACP,OAAO,CAAC,GAAG,CAAC,iCAAiC,YAAY,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/css.ts"],
4
+ "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { themeHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getCommentBlock } from \"../utils/common.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\nimport { extractFileData } from \"./text.js\";\n\n/**\n * Extracts the theme data from the style.css file.\n * @param args - The command line arguments.\n * @param filename - The name of the style.css file.\n */\nexport function extractCssThemeData(\n\targs: Args,\n\tfilename = \"style.css\",\n): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst styleCssFile = path.join(args.paths.cwd, filename);\n\n\tif (fs.existsSync(styleCssFile)) {\n\t\tconst fileContent = fs.readFileSync(styleCssFile, \"utf8\");\n\t\tconst commentBlock = getCommentBlock(fileContent);\n\t\tfileData = extractFileData(commentBlock);\n\n\t\tif (\"Theme Name\" in fileData) {\n\t\t\tconsole.log(`\uD83D\uDD35 Theme stylesheet detected. (${styleCssFile})`);\n\t\t\targs.domain = \"theme\";\n\n\t\t\tconst themeInfo: Record<string, string> = {};\n\n\t\t\t// Loop through the theme headers and extract the values with the required format\n\t\t\tfor (const keyValueMatch of Object.entries(fileData)) {\n\t\t\t\t// Check if the line matches the expected format\n\t\t\t\tif (keyValueMatch?.[0] && keyValueMatch[1]) {\n\t\t\t\t\t// filter the retrieved headers\n\t\t\t\t\tconst header = getKeyByValue(themeHeaders, keyValueMatch[0].trim());\n\t\t\t\t\tif (header === undefined) continue;\n\t\t\t\t\tthemeInfo[header] = keyValueMatch[1].trim();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn themeInfo;\n\t\t}\n\t} else {\n\t\tconsole.log(`Theme stylesheet not found in ${styleCssFile}`);\n\t}\n\treturn {};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA6B;AAE7B,oBAAgC;AAChC,wBAA8B;AAC9B,kBAAgC;AAOzB,SAAS,oBACf,MACA,WAAW,aACc;AACzB,MAAI,WAAmC,CAAC;AACxC,QAAM,eAAe,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,QAAQ;AAEvD,MAAI,eAAAC,QAAG,WAAW,YAAY,GAAG;AAChC,UAAM,cAAc,eAAAA,QAAG,aAAa,cAAc,MAAM;AACxD,UAAM,mBAAe,+BAAgB,WAAW;AAChD,mBAAW,6BAAgB,YAAY;AAEvC,QAAI,gBAAgB,UAAU;AAC7B,cAAQ,IAAI,yCAAkC,YAAY,GAAG;AAC7D,WAAK,SAAS;AAEd,YAAM,YAAoC,CAAC;AAG3C,iBAAW,iBAAiB,OAAO,QAAQ,QAAQ,GAAG;AAErD,YAAI,gBAAgB,CAAC,KAAK,cAAc,CAAC,GAAG;AAE3C,gBAAM,aAAS,iCAAc,2BAAc,cAAc,CAAC,EAAE,KAAK,CAAC;AAClE,cAAI,WAAW,OAAW;AAC1B,oBAAU,MAAM,IAAI,cAAc,CAAC,EAAE,KAAK;AAAA,QAC3C;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD,OAAO;AACN,YAAQ,IAAI,iCAAiC,YAAY,EAAE;AAAA,EAC5D;AACA,SAAO,CAAC;AACT;",
6
+ "names": ["path", "fs"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/extractors/headers.ts"],"names":[],"mappings":";;;;;AAmIA,oDAyCC;AAsED,wCA8BC;AAQD,kDAWC;AAQD,kDAgBC;AA3TD,0DAA6B;AAC7B,mDAA6C;AAG7C,0CAAyC;AACzC,uCAAiD;AAEjD,kDAAoD;AACpD,0DAAoD;AACpD,qCAA+C;AAC/C,qCAAg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,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,OAErD,CAAC;IAEF,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;IAExE,OAAO,IAAI,4BAAW,CAAC;QACtB,IAAA,0BAAU,EAAC,eAAe,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAA,0BAAU,EAAC,cAAc,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAA,0BAAU,EAAC,sBAAsB,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAA,0BAAU,EAAC,iBAAiB,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAA,0BAAU,EAAC,qBAAqB,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,CAAC;KAChE,CAAC,CAAC;AACJ,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/headers.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\r\nimport { SetOfBlocks } from \"gettext-merger\";\r\nimport { boolean } from \"yargs\";\r\nimport type PackageI18n from \"../assets/package-i18n.js\";\r\nimport { modulePath } from \"../const.js\";\r\nimport { getEncodingCharset } from \"../fs/fs.js\";\r\nimport type { Args, I18nHeaders, PotHeaders } from \"../types.js\";\r\nimport { getPkgJsonData } from \"../utils/common.js\";\r\nimport { buildBlock } from \"../utils/extractors.js\";\r\nimport { extractCssThemeData } from \"./css.js\";\r\nimport { extractPhpPluginData } from \"./php.js\";\r\n\r\n/**\r\n * Checks if required fields are missing and logs a clear error message\r\n * @param {object} headerData - The header data to validate\r\n * @param {boolean} debug - Debug mode flag\r\n * @returns {boolean} - true if all required fields are present, false otherwise\r\n */\r\nfunction validateRequiredFields(\r\n\theaderData: I18nHeaders,\r\n\tdebug: boolean,\r\n): boolean {\r\n\tconst requiredFields = [\r\n\t\t{ key: \"slug\", name: \"Plugin/Theme slug\", placeholder: \"PLUGIN NAME\" },\r\n\t\t{ key: \"author\", name: \"Author name\", placeholder: \"AUTHOR\" },\r\n\t\t{ key: \"version\", name: \"Version\", placeholder: \"\" },\r\n\t\t{ key: \"email\", name: \"Author email\", placeholder: \"AUTHOR EMAIL\" },\r\n\t\t{ key: \"xDomain\", name: \"Text domain\", placeholder: \"PLUGIN TEXTDOMAIN\" },\r\n\t];\r\n\r\n\tconst missingFields = requiredFields.filter(\r\n\t\t(field) =>\r\n\t\t\t!headerData[field.key] ||\r\n\t\t\theaderData[field.key] === field.placeholder ||\r\n\t\t\t(field.key === \"version\" && headerData[field.key] === \"0.0.1\"),\r\n\t);\r\n\r\n\tif (missingFields.length > 0) {\r\n\t\tconsole.error(\"\\n! Missing required information for POT file header:\\n\");\r\n\r\n\t\tfor (const field of missingFields) {\r\n\t\t\tconsole.error(\r\n\t\t\t\t` - ${field.name} is missing or has a default value (eg. version: 0.0.1\")`,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tconsole.error(\r\n\t\t\t\"\\nPlease provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.\",\r\n\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t);\r\n\r\n\t\tif (missingFields.some((field) => field.key === \"email\")) {\r\n\t\t\tconsole.error(\r\n\t\t\t\t\"\\n\\nWordpress didn't require an email field in the headers object but it's required in order to generate a valid pot file.\",\r\n\t\t\t\t'\\nPlease add the email field to the package.json file (author field eg. author: \"AUTHOR <EMAIL>\")',\r\n\t\t\t\t'\\nor inject those information using the --headers flag to the \"makePot\" command (eg. --headers=email:erik@ck.it).',\r\n\t\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif (missingFields && debug) {\r\n\t\t\tconsole.error(\r\n\t\t\t\t\"\\nDebug information:\",\r\n\t\t\t\t\"\\nMissing fields:\",\r\n\t\t\t\tmissingFields,\r\n\t\t\t\t\"\\nHeader data:\",\r\n\t\t\t\theaderData,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tconsole.error(\"\\n\");\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\treturn true;\r\n}\r\n\r\n/**\r\n * Extract author data from package.json author field and return an array of strings\r\n * the original field is a string and it's longer form is \"Your Name <email@example.com> (https://example.com)\"\r\n *\r\n * @returns an object with name, email, and website\r\n * @param authorData\r\n */\r\nfunction extractAuthorData(authorData: string | object): {\r\n\tname: string;\r\n\temail?: string;\r\n\twebsite?: string;\r\n} {\r\n\t// Default result with placeholder values\r\n\tconst defaultResult = { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n\r\n\t// Return default if no author data\r\n\tif (!authorData) {\r\n\t\treturn defaultResult;\r\n\t}\r\n\r\n\t// Handle string format: \"Barney Rubble <barney@npmjs.com> (http://barnyrubble.npmjs.com/)\"\r\n\tif (typeof authorData === \"string\") {\r\n\t\t// Try to extract email with regex\r\n\t\tconst emailMatch = authorData.match(/<([^>]+)>/);\r\n\t\tconst email = emailMatch ? emailMatch[1].trim() : undefined;\r\n\r\n\t\t// Try to extract website with regex\r\n\t\tconst websiteMatch = authorData.match(/\\(([^)]+)\\)/);\r\n\t\tconst website = websiteMatch ? websiteMatch[1].trim() : undefined;\r\n\r\n\t\t// Extract name by removing email and website parts if present\r\n\t\tlet name = authorData.trim();\r\n\t\tif (emailMatch) name = name.replace(emailMatch[0], \"\").trim();\r\n\t\tif (websiteMatch) name = name.replace(websiteMatch[0], \"\").trim();\r\n\r\n\t\treturn { name, email, website };\r\n\t}\r\n\tif (typeof authorData === \"object\") {\r\n\t\t// Handle object format: { name: \"Barney Rubble\", email: \"barney@npmjs.com\", website: \"http://barnyrubble.npmjs.com/\" }\r\n\t\treturn {\r\n\t\t\tname: authorData.name,\r\n\t\t\temail: authorData.email,\r\n\t\t\twebsite: authorData.website,\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Gets author data by checking multiple possible locations in package.json\r\n *\r\n * @param pkgJsonData The package.json data object\r\n * @returns Author data with name, email and website\r\n */\r\nexport function getAuthorFromPackage(pkgJsonData: PackageI18n): {\r\n\tname: string;\r\n\temail?: string;\r\n\twebsite?: string;\r\n} {\r\n\t// Check multiple possible locations for author information\r\n\tconst locations = [\r\n\t\t\"author\", // Standard author field\r\n\t\t\"authors\", // Some packages use authors (plural)\r\n\t\t\"contributors\", // Try contributors if no author\r\n\t\t\"maintainers\", // Try maintainers as last resort\r\n\t];\r\n\r\n\t// Try each location in order\r\n\tfor (const location of locations) {\r\n\t\tif (pkgJsonData[location]) {\r\n\t\t\tlet authorData: {\r\n\t\t\t\tname: string;\r\n\t\t\t\temail?: string;\r\n\t\t\t\twebsite?: string;\r\n\t\t\t};\r\n\t\t\tif (typeof pkgJsonData[location] === \"string\") {\r\n\t\t\t\tauthorData = extractAuthorData(pkgJsonData[location]);\r\n\t\t\t} else if (typeof pkgJsonData[location] === \"object\") {\r\n\t\t\t\tfor (const author of pkgJsonData[location]) {\r\n\t\t\t\t\tif (!author) continue;\r\n\t\t\t\t\tauthorData = extractAuthorData(author);\r\n\t\t\t\t\tif (authorData) break;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tauthorData?.name !== \"AUTHOR\" ||\r\n\t\t\t\tauthorData?.email !== \"AUTHOR EMAIL\"\r\n\t\t\t) {\r\n\t\t\t\treturn authorData;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// If no valid author data found in any location\r\n\treturn { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n}\r\n\r\n/**\r\n * This function consolidates the user headers data into a single object\r\n *\r\n * @param args the command line arguments\r\n * @return {Record<string, string>} the consolidated headers data object\r\n */\r\nfunction consolidateUserHeaderData(args: Args): I18nHeaders {\r\n\tconst pkgJsonData = getPkgJsonData(\r\n\t\targs.paths?.cwd,\r\n\t\t\"name\",\r\n\t\t\"version\",\r\n\t\t\"author\",\r\n\t\t\"authors\",\r\n\t\t\"contributors\",\r\n\t\t\"maintainers\",\r\n\t) as Record<[keyof PackageI18n], string>;\r\n\t// get author data from package.json\r\n\tconst pkgAuthor = getAuthorFromPackage(pkgJsonData);\r\n\r\n\t// get the current directory name as slug\r\n\tconst currentDir = path\r\n\t\t.basename(args.paths?.cwd || process.cwd())\r\n\t\t?.toLowerCase()\r\n\t\t.replace(\" \", \"-\");\r\n\r\n\t// Use command line author name if provided, fallback to package.json\r\n\tconst authorName = args?.headers?.author || pkgAuthor?.name;\r\n\tconst email = args?.headers?.email || pkgAuthor?.email;\r\n\t// this is the author with email address in this format: author <email>\r\n\tconst authorString = `${authorName} <${email}>`;\r\n\tconst slug =\r\n\t\targs.slug ||\r\n\t\tcurrentDir ||\r\n\t\targs.headers?.name?.toString().replace(/ /g, \"-\") ||\r\n\t\t(args.domain === \"theme\" ? \"THEME NAME\" : \"PLUGIN NAME\");\r\n\r\n\tconst bugs = `https://wordpress.org/support/${args.domain === \"theme\" ? \"themes\" : \"plugins\"}/${slug}`;\r\n\r\n\treturn {\r\n\t\t...args.headers,\r\n\t\tname: args.headers?.name || slug,\r\n\t\tauthor: authorName,\r\n\t\tauthorString: authorString, // this is the author with email address in this format: author <email>\r\n\t\tslug,\r\n\t\temail,\r\n\t\tbugs,\r\n\t\tlicense: args.headers?.license || \"gpl-2.0 or later\",\r\n\t\tversion: args.headers?.version || pkgJsonData.version || \"0.0.1\",\r\n\t\tlanguage: \"en\",\r\n\t\txDomain: args.headers?.textDomain || slug,\r\n\t};\r\n}\r\n\r\n/**\r\n * Generates a POT header for a given set of arguments.\r\n * https://developer.wordpress.org/cli/commands/i18n/make-pot/\r\n * 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 in the following manner:\r\n * `\r\n * Copyright (C) 2018 Example Plugin Author\r\n * This file is distributed under the same license as the Example Plugin package.\r\n * `\r\n * If a plugin or theme specifies a license in their main plugin file or stylesheet,\r\n * the comment looks like this: Copyright (C) 2018 Example Plugin Author This file is distributed under the GPLv2.\r\n *\r\n * @param args - The argument object containing the headers and their values.\r\n * @return The generated POT header.\r\n */\r\nexport async function generateHeader(\r\n\targs: Args,\r\n): Promise<Record<string, string> | null> {\r\n\t// Consolidate the user headers data into a single object\r\n\tconst headerData = consolidateUserHeaderData(args);\r\n\r\n\t// the makepot module name and version\r\n\tconst { name, version } = getPkgJsonData(modulePath, \"name\", \"version\");\r\n\r\n\t// Validate required fields - exit early if validation fails\r\n\tif (!validateRequiredFields(headerData, args.debug)) {\r\n\t\tprocess.exit(1); // Exit with error code\r\n\t\treturn null; // This is never reached but helps with TypeScript\r\n\t}\r\n\r\n\treturn {\r\n\t\t\"Project-Id-Version\": `${headerData.name} ${headerData.version}`,\r\n\t\t\"Report-Msgid-Bugs-To\": headerData.bugs,\r\n\t\t\"MIME-Version\": \"1.0\",\r\n\t\t\"Content-Transfer-Encoding\": \"8bit\",\r\n\t\t\"content-type\": `text/plain; charset=${getEncodingCharset(args.options?.charset)}`,\r\n\t\t\"plural-forms\": \"nplurals=2; plural=(n!=1);\",\r\n\t\t\"POT-Creation-Date\": `${new Date().toISOString()}`,\r\n\t\t\"PO-Revision-Date\": `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,\r\n\t\t\"Last-Translator\": headerData.authorString,\r\n\t\t\"Language-Team\": headerData.authorString,\r\n\t\t\"X-Generator\": `${name} ${version}`,\r\n\t\tLanguage: `${headerData.language}`,\r\n\t\t\"X-Domain\": headerData.xDomain,\r\n\t};\r\n}\r\n\r\n/**\r\n * Extracts main file data based on the given arguments.\r\n *\r\n * @param {Args} args - The arguments for extracting the main file data.\r\n * @return {Record<string, string>} The extracted main file data.\r\n */\r\nexport function extractMainFileData(args: Args): Record<string, string> {\r\n\tlet extractedData = {};\r\n\tif ([\"plugin\", \"block\", \"generic\"].includes(args.domain)) {\r\n\t\textractedData = extractPhpPluginData(args);\r\n\t} else if ([\"theme\", \"theme-block\"].includes(args.domain)) {\r\n\t\textractedData = extractCssThemeData(args);\r\n\t} else {\r\n\t\tconsole.log(\"No main file detected.\");\r\n\t}\r\n\r\n\treturn extractedData;\r\n}\r\n\r\n/**\r\n * Generate translation strings based on the given type and headers.\r\n *\r\n * @return {Record<string, string>} the generated translation strings\r\n * @param args\r\n */\r\nexport function translationsHeaders(args: Args): SetOfBlocks {\r\n\tconst { domain, headers } = args as Args;\r\n\tconst { name, description, author, authorUri, url } = headers as {\r\n\t\t[key in PotHeaders]: string;\r\n\t};\r\n\r\n\t// the main file is the plugin main php file or the css file\r\n\tconst fakePath = domain === \"plugin\" ? `${args.slug}.php` : \"style.css\";\r\n\r\n\treturn new SetOfBlocks([\r\n\t\tbuildBlock(`Name of the ${domain}`, name, [fakePath]),\r\n\t\tbuildBlock(`Url of the ${domain}`, url, [fakePath]),\r\n\t\tbuildBlock(`Description of the ${domain}`, description, [fakePath]),\r\n\t\tbuildBlock(`Author of the ${domain}`, author, [fakePath]),\r\n\t\tbuildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]),\r\n\t]);\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,4BAA4B;AAG5B,mBAA2B;AAC3B,gBAAmC;AAEnC,oBAA+B;AAC/B,wBAA2B;AAC3B,iBAAoC;AACpC,iBAAqC;AAQrC,SAAS,uBACR,YACA,OACU;AACV,QAAM,iBAAiB;AAAA,IACtB,EAAE,KAAK,QAAQ,MAAM,qBAAqB,aAAa,cAAc;AAAA,IACrE,EAAE,KAAK,UAAU,MAAM,eAAe,aAAa,SAAS;AAAA,IAC5D,EAAE,KAAK,WAAW,MAAM,WAAW,aAAa,GAAG;AAAA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C;IAC/C,MAAM,MAAM,GAA0C;QACrD,GAAG,EAAE,OAAO;YACX,CAAC,CAAC,+BAAmB,CAAC,eAAe;YACrC,CAAC,CAAC,+BAAmB,CAAC,eAAe;QACtC,QAAQ,EAAE,OAAO;YAChB,CAAC,CAAE,+BAAmB,CAAC,iBAAgC;YACvD,CAAC,CAAE,+BAAmB,CAAC,iBAAgC;KACxD,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACrD,OAAO;IACR,CAAC;IAED,4CAA4C;IAC5C,MAAM,gBAAgB,GAAG,MAAM,+BAAmB,CAAC,KAAK,CACvD,IAAI,CAAC,WAAW,EAChB,MAAM,EACN;QACC,IAAI,EAAE,IAAI,CAAC,QAAQ;QACnB,aAAa,EAAE,IAAI;KACnB,CACD,CAAC;IAEF,OAAO,gBAAgB,IAAI,EAAE,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,iBAAiB,CACtC,WAAmB,EACnB,QAAgB,EAChB,QAAqC;IAErC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;QAChC,WAAW,EAAE,WAAW;QACxB,QAAQ,EAAE,QAAQ;KAClB,CAAC,CAAC;IAEH,OAAO,IAAA,+BAAe,EAAC,IAAI,EAAE,QAAQ,EAAE,mBAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvE,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/json.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\nimport type { Block, SetOfBlocks } from \"gettext-merger\";\nimport type { I18nSchema } from \"../types.js\";\nimport { yieldParsedData } from \"../utils/extractors.js\";\nimport { JsonSchemaExtractor } from \"./schema.js\";\n\n/**\n * Parses a JSON file and returns an array of parsed data.\n *\n * @param {Object} opts - The arguments for parsing the JSON file.\n * @param {string} opts.filepath - The filepath of the JSON file to parse.\n * @param {Object} [opts.stats] - Optional statistics object.\n * @param {number} opts.stats.index - The index of the progress bar.\n * @return {Promise<TranslationStrings>} A promise that resolves to an object containing the parsed data.\n */\nexport async function parseJsonFile(opts: {\n\tfileContent: string;\n\tfilename: \"block.json\" | \"theme.json\";\n}): Promise<Block[]> {\n\tconst isTheme = opts.filename === \"theme.json\";\n\tconst schema: { url: string; fallback: I18nSchema } = {\n\t\turl: isTheme\n\t\t\t? JsonSchemaExtractor.themeJsonSource\n\t\t\t: JsonSchemaExtractor.blockJsonSource,\n\t\tfallback: isTheme\n\t\t\t? (JsonSchemaExtractor.themeJsonFallback as I18nSchema)\n\t\t\t: (JsonSchemaExtractor.blockJsonFallback as I18nSchema),\n\t};\n\n\tif (!schema.url || !schema.fallback) {\n\t\tconsole.error(\"Schema URL or fallback not provided\");\n\t\treturn;\n\t}\n\n\t// Get the JSON translations from the schema\n\tconst jsonTranslations = await JsonSchemaExtractor.parse(\n\t\topts.fileContent,\n\t\tschema,\n\t\t{\n\t\t\tfile: opts.filename,\n\t\t\taddReferences: true,\n\t\t},\n\t);\n\n\treturn jsonTranslations ?? [];\n}\n\n/**\n * Parses the JSON content of a file based on the filename and file content.\n *\n * @param {string} fileContent - The content of the file to parse.\n * @param {string} filePath - The path of the file being parsed.\n * @param {'block.json' | 'theme.json'} filename - The type of JSON file being parsed.\n * @return {Promise<TranslationStrings>} The parsed translation strings.\n */\nexport async function parseJsonCallback(\n\tfileContent: string,\n\tfilePath: string,\n\tfilename: \"block.json\" | \"theme.json\",\n): Promise<SetOfBlocks> {\n\tconst data = await parseJsonFile({\n\t\tfileContent: fileContent,\n\t\tfilename: filename,\n\t});\n\n\treturn yieldParsedData(data, filename, path.join(filePath, filename));\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,wBAAgC;AAChC,oBAAoC;AAWpC,eAAsB,cAAc,MAGf;AACpB,QAAM,UAAU,KAAK,aAAa;AAClC,QAAM,SAAgD;AAAA,IACrD,KAAK,UACF,kCAAoB,kBACpB,kCAAoB;AAAA,IACvB,UAAU,UACN,kCAAoB,oBACpB,kCAAoB;AAAA,EACzB;AAEA,MAAI,CAAC,OAAO,OAAO,CAAC,OAAO,UAAU;AACpC,YAAQ,MAAM,qCAAqC;AACnD;AAAA,EACD;AAGA,QAAM,mBAAmB,MAAM,kCAAoB;AAAA,IAClD,KAAK;AAAA,IACL;AAAA,IACA;AAAA,MACC,MAAM,KAAK;AAAA,MACX,eAAe;AAAA,IAChB;AAAA,EACD;AAEA,SAAO,oBAAoB,CAAC;AAC7B;AAUA,eAAsB,kBACrB,aACA,UACA,UACuB;AACvB,QAAM,OAAO,MAAM,cAAc;AAAA,IAChC;AAAA,IACA;AAAA,EACD,CAAC;AAED,aAAO,mCAAgB,MAAM,UAAU,iBAAAA,QAAK,KAAK,UAAU,QAAQ,CAAC;AACrE;",
6
+ "names": ["path"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"packageJson.js","sourceRoot":"","sources":["../../src/extractors/packageJson.ts"],"names":[],"mappings":";;;;;AAaA,gDAqBC;AAlCD,sDAAyB;AACzB,0DAA6B;AAC7B,0CAA6C;AAG7C;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,IAAU;IAC5C,MAAM,MAAM,GAAG,yBAAc,CAAC;IAC9B,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,6BAA6B;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG;QACrC,CAAC,CAAC,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC;QAC3C,CAAC,CAAC,cAAc,CAAC;IAElB;;OAEG;IACH,IAAI,iBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACpC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;QACzE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACzC,0CAA0C;YAC1C,IAAI,KAAK,IAAI,WAAW,EAAE,CAAC;gBAC1B,WAAW,CAAC,KAAK,CAAC,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,EAAY,CAAC;YACxD,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,WAAW,CAAC;AACpB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/packageJson.ts"],
4
+ "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pkgJsonHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Extracts package data from the given arguments and returns a record\n * containing the specified fields from the package.json file.\n *\n * @param {Args} args - The arguments for extracting package data.\n *\n * @return {Record<string, string>} - A record containing the extracted package data.\n */\nexport function extractPackageJson(args: Args): Record<string, string> {\n\tconst fields = pkgJsonHeaders;\n\tconst pkgJsonMeta: Record<string, string> = {};\n\t// read the package.json file\n\tconst packageJsonPath = args.paths.cwd\n\t\t? path.join(args.paths.cwd, \"package.json\")\n\t\t: \"package.json\";\n\n\t/**\n\t * check if the package.json extract the fields from the package.json file\n\t */\n\tif (fs.existsSync(packageJsonPath)) {\n\t\tconst packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\"));\n\t\tfor (const field of Object.keys(fields)) {\n\t\t\t// if the field exists in the package.json\n\t\t\tif (field in packageJson) {\n\t\t\t\tpkgJsonMeta[field] = `${packageJson[field]}` as string;\n\t\t\t}\n\t\t}\n\t}\n\treturn pkgJsonMeta;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;A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C,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,4BAA4B,aAAa,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,UAAkB;IAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAEvD,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEvC,MAAM,UAAU,GAA2B,EAAE,CAAC;QAE9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAE7D,IAAI,CAAC,aAAa,EAAE,CAAC;gBACpB,SAAS;YACV,CAAC;YAED,gDAAgD;YAChD,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5C,+BAA+B;gBAC/B,MAAM,MAAM,GAAG,IAAA,6BAAa,EAAC,wBAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBACrE,IAAI,MAAM,KAAK,SAAS;oBAAE,SAAS;gBACnC,UAAU,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9C,CAAC;QACF,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/php.ts"],
4
+ "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pluginHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\n\nexport function extractPhpPluginData(args: Args): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst folderPhpFile = path.join(args.paths.cwd, `${args.slug}.php`);\n\n\tif (fs.existsSync(folderPhpFile)) {\n\t\tconst fileContent = fs.readFileSync(folderPhpFile, \"utf8\");\n\t\tfileData = parsePHPFile(fileContent);\n\n\t\tconsole.log(`\uD83D\uDD35 Plugin file detected. (${folderPhpFile})`);\n\n\t\t// Set the domain\n\t\targs.domain = \"plugin\";\n\n\t\treturn fileData;\n\t}\n\n\tconsole.log(\"Plugin file not found.\");\n\tconsole.log(`Missing Plugin filename: ${folderPhpFile}`);\n\n\treturn {};\n}\n\n/**\n * Parses a PHP file and extracts the plugin information from the comment block.\n *\n * @param {string} phpContent - The content of the PHP file.\n * @return {Record<string, string>} - A record containing the plugin information.\n */\nexport function parsePHPFile(phpContent: string): Record<string, string> {\n\tconst match = phpContent.match(/\\/\\*\\*([\\s\\S]*?)\\*\\//);\n\n\tif (match?.[1] && match) {\n\t\tconst commentBlock = match[1];\n\t\tconst lines = commentBlock.split(\"\\n\");\n\n\t\tconst pluginInfo: Record<string, string> = {};\n\n\t\tfor (const line of lines) {\n\t\t\tconst keyValueMatch = line.match(/^\\s*\\*\\s*([^:]+):\\s*(.*)/);\n\n\t\t\tif (!keyValueMatch) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if the line matches the expected format\n\t\t\tif (keyValueMatch?.[1] && keyValueMatch[2]) {\n\t\t\t\t// filter the retrieved headers\n\t\t\t\tconst header = getKeyByValue(pluginHeaders, keyValueMatch[1].trim());\n\t\t\t\tif (header === undefined) continue;\n\t\t\t\tpluginInfo[header] = keyValueMatch[2].trim();\n\t\t\t}\n\t\t}\n\n\t\treturn pluginInfo;\n\t}\n\treturn {};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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E,CAAC;YAEX,IAAI,aAAa,EAAE,CAAC;gBACnB,WAAW,CAAC,QAAQ,GAAG;oBACtB,SAAS,EAAE,CAAC,QAAQ,CAAC;iBACrB,CAAC;YACH,CAAC;YAED,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAChC,CAAC;QAED,iCAAiC;QACjC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEtB,OAAO,YAAY,CAAC;IACrB,CAAC;;AAhQF,kDAiQC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/schema.ts"],
4
+ "sourcesContent": ["import type { Block } from \"gettext-merger\";\r\nimport type BlockI18n from \"../assets/block-i18n.js\";\r\nimport * as blocki18n from \"../assets/block-i18n.js\";\r\nimport type ThemeI18n from \"../assets/theme-i18n.js\";\r\nimport * as themei18n from \"../assets/theme-i18n.js\";\r\nimport type { I18nSchema } from \"../types.js\";\r\n\r\n/**\r\n * Extracts strings from JSON files using the I18n schema.\r\n */\r\nexport class JsonSchemaExtractor {\r\n\tprivate static schemaCache: { [url: string]: I18nSchema } = {};\r\n\r\n\t/** Theme */\r\n\tstatic themeJsonSource =\r\n\t\t\"http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json\";\r\n\tstatic themeJsonFallback = themei18n as ThemeI18n;\r\n\t/** Block */\r\n\tstatic blockJsonSource =\r\n\t\t\"http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json\";\r\n\tstatic blockJsonFallback = blocki18n as BlockI18n;\r\n\r\n\t/**\r\n\t * Load the schema from the specified URL, with a fallback URL if needed.\r\n\t *\r\n\t * @param {string} url - The URL to load the schema from.\r\n\t * @param {I18nSchema} fallback - The fallback schema to use if the main URL fails.\r\n\t * @return {Promise<I18nSchema>} The loaded schema.\r\n\t */\r\n\tprivate static async loadSchema(\r\n\t\turl: string,\r\n\t\tfallback: I18nSchema,\r\n\t): Promise<I18nSchema> {\r\n\t\tif (JsonSchemaExtractor.schemaCache[url]) {\r\n\t\t\treturn JsonSchemaExtractor.schemaCache[url];\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tconsole.log(`\\n[i] Loading schema from ${url}`);\r\n\t\t\tconst response = await fetch(url, {\r\n\t\t\t\tresponseType: \"json\",\r\n\t\t\t\taccept: \"application/json\",\r\n\t\t\t\theaders: {\r\n\t\t\t\t\t\"Access-Control-Allow-Origin\": \"*\",\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t\t\t.then((response) => response.json())\r\n\t\t\t\t.catch((error: Error) => {\r\n\t\t\t\t\tthrow new Error(\r\n\t\t\t\t\t\t`\\nFailed to load schema from ${url}. Error: ${error.message}`,\r\n\t\t\t\t\t);\r\n\t\t\t\t});\r\n\r\n\t\t\t// Verify if the response is valid\r\n\t\t\tif (!response) {\r\n\t\t\t\treturn fallback;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.log(\"Schema loaded successfully\");\r\n\t\t\tJsonSchemaExtractor.schemaCache[url] = response;\r\n\t\t\treturn response;\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(\r\n\t\t\t\t`\\nFailed to load schema from ${url}. Using fallback. Error: ${error.message}`,\r\n\t\t\t);\r\n\t\t\tJsonSchemaExtractor.schemaCache[url] = fallback;\r\n\t\t\treturn fallback;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Parses a string and extracts translations using the specified schema.\r\n\t *\r\n\t * @param {string} text - the input string to be parsed\r\n\t * @param {object} schema - the schema to use for parsing the input string\r\n\t * @param {string} schema.url - the URL of the schema to use for parsing the input string\r\n\t * @param {object} schema.schemaFallback - the fallback schema to use if the main schema fails\r\n\t * @param {object} options - the options for parsing the input string\r\n\t * @param {string} options.file - the name of the file being parsed\r\n\t * @param {boolean} options.addReferences - whether to add references to the extracted strings\r\n\t *\r\n\t * @return {Promise<I18nSchema | undefined>} a promise that resolves with the extracted schema\r\n\t */\r\n\tpublic static async parse(\r\n\t\ttext: string,\r\n\t\tschema: {\r\n\t\t\turl: string;\r\n\t\t\tfallback: I18nSchema;\r\n\t\t},\r\n\t\toptions: {\r\n\t\t\tfile: \"block.json\" | \"theme.json\";\r\n\t\t\taddReferences: boolean;\r\n\t\t},\r\n\t): Promise<Block[] | undefined> {\r\n\t\tconst parsedSchema = await JsonSchemaExtractor.loadSchema(\r\n\t\t\tschema.url,\r\n\t\t\tschema.fallback,\r\n\t\t);\r\n\r\n\t\ttry {\r\n\t\t\tconst json = JSON.parse(text) as Record<string, unknown>;\r\n\t\t\tif (!json) {\r\n\t\t\t\tconsole.error(\"Could not parse JSON.\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\treturn JsonSchemaExtractor.extractFromJsonSchema(\r\n\t\t\t\tjson,\r\n\t\t\t\tparsedSchema,\r\n\t\t\t\toptions,\r\n\t\t\t);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(`Error parsing JSON: ${error.message}`);\r\n\t\t\treturn;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts translatable strings from a JSON file by comparing it with a schema\r\n\t *\r\n\t * @param {Object} json - The JSON object to extract strings from\r\n\t * @param {Object} schema - The schema that defines which fields contain translatable strings\r\n\t * @param {Object} options - Options for extraction\r\n\t * @param {string} options.filename - The name of the file being extracted (for references)\r\n\t * @param {boolean} options.addReferences - Whether to add file references in comments\r\n\t * @return {Array} - An array of objects with translatable strings in gettext format\r\n\t */\r\n\tprivate static extractFromJsonSchema(\r\n\t\tjson: Record<string, unknown>,\r\n\t\tschema: I18nSchema,\r\n\t\toptions: { filename?: string; addReferences?: boolean } = {\r\n\t\t\tfilename: undefined,\r\n\t\t\taddReferences: false,\r\n\t\t},\r\n\t): Block[] | undefined {\r\n\t\tconst { filename = \"block.json\", addReferences = false } = options;\r\n\t\tconst translations = [];\r\n\r\n\t\t/**\r\n\t\t * Recursive function to extract translatable strings\r\n\t\t * @param {*} currentJson - The current node in the JSON\r\n\t\t * @param {*} currentSchema - The current node in the schema\r\n\t\t * @param {Array} path - The current path in the JSON\r\n\t\t */\r\n\t\tfunction extract(currentJson, currentSchema, path = []) {\r\n\t\t\t// If either is null or undefined, there's nothing to do\r\n\t\t\tif (!currentJson || !currentSchema) return;\r\n\r\n\t\t\t// Handles the case where both are objects\r\n\t\t\tif (\r\n\t\t\t\ttypeof currentJson === \"object\" &&\r\n\t\t\t\t!Array.isArray(currentJson) &&\r\n\t\t\t\ttypeof currentSchema === \"object\" &&\r\n\t\t\t\t!Array.isArray(currentSchema)\r\n\t\t\t) {\r\n\t\t\t\t// Iterate over the schema keys\r\n\t\t\t\tfor (const key of Object.keys(currentSchema)) {\r\n\t\t\t\t\tif (key in currentJson) {\r\n\t\t\t\t\t\t// If the key exists in the JSON, check the type\r\n\t\t\t\t\t\tif (typeof currentJson[key] === \"string\") {\r\n\t\t\t\t\t\t\t// It's a string - add it to translations\r\n\t\t\t\t\t\t\taddTranslation(\r\n\t\t\t\t\t\t\t\tcurrentJson[key],\r\n\t\t\t\t\t\t\t\tcurrentSchema[key],\r\n\t\t\t\t\t\t\t\tfilename,\r\n\t\t\t\t\t\t\t\taddReferences,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t} else if (\r\n\t\t\t\t\t\t\tArray.isArray(currentJson[key]) &&\r\n\t\t\t\t\t\t\tArray.isArray(currentSchema[key])\r\n\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t// It's an array - handle each element\r\n\t\t\t\t\t\t\thandleArrays(\r\n\t\t\t\t\t\t\t\tcurrentJson[key],\r\n\t\t\t\t\t\t\t\tcurrentSchema[key],\r\n\t\t\t\t\t\t\t\t[...path, key],\r\n\t\t\t\t\t\t\t\tfilename,\r\n\t\t\t\t\t\t\t\taddReferences,\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t} else if (\r\n\t\t\t\t\t\t\ttypeof currentJson[key] === \"object\" &&\r\n\t\t\t\t\t\t\ttypeof currentSchema[key] === \"object\"\r\n\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t// It's an object - recurse\r\n\t\t\t\t\t\t\textract(currentJson[key], currentSchema[key], [...path, key]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Handles arrays in JSON and schema\r\n\t\t * @param {Array} jsonArray - The JSON array\r\n\t\t * @param {Array} schemaArray - The schema array\r\n\t\t * @param {Array} path - The current path\r\n\t\t * @param {string} filename - The name of the file\r\n\t\t * @param {boolean} addReferences - whenever to add references\r\n\t\t */\r\n\t\tfunction handleArrays(\r\n\t\t\tjsonArray,\r\n\t\t\tschemaArray,\r\n\t\t\tpath,\r\n\t\t\tfilename,\r\n\t\t\taddReferences,\r\n\t\t) {\r\n\t\t\t// If the schema has at least one element, use it as a template\r\n\t\t\tif (schemaArray.length > 0) {\r\n\t\t\t\tconst schemaTemplate = schemaArray[0];\r\n\r\n\t\t\t\t// For each element in the JSON array\r\n\t\t\t\tfor (const jsonItem of jsonArray) {\r\n\t\t\t\t\tif (typeof jsonItem === \"string\") {\r\n\t\t\t\t\t\t// If the JSON element is a string, add it directly\r\n\t\t\t\t\t\taddTranslation(jsonItem, schemaTemplate, filename, addReferences);\r\n\t\t\t\t\t} else if (typeof jsonItem === \"object\") {\r\n\t\t\t\t\t\t// If it's an object, recurse\r\n\t\t\t\t\t\tif (typeof schemaTemplate === \"object\") {\r\n\t\t\t\t\t\t\textract(jsonItem, schemaTemplate, path);\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t// Edge case: handles cases like keywords: [\"string1\", \"string2\"]\r\n\t\t\t\t\t\t\t// when the schema has keywords: [\"keyword context\"]\r\n\t\t\t\t\t\t\tfor (const key of Object.keys(jsonItem)) {\r\n\t\t\t\t\t\t\t\tif (typeof jsonItem[key] === \"string\") {\r\n\t\t\t\t\t\t\t\t\taddTranslation(\r\n\t\t\t\t\t\t\t\t\t\tjsonItem[key],\r\n\t\t\t\t\t\t\t\t\t\tschemaTemplate,\r\n\t\t\t\t\t\t\t\t\t\tfilename,\r\n\t\t\t\t\t\t\t\t\t\taddReferences,\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Adds a translation to the translations array\r\n\t\t * @param {string} msgctxt - The context of the text to be translated\r\n\t\t * @param {string} msgid - The text to be translated\r\n\t\t * @param {string} filename - The name of the file for references\r\n\t\t * @param {boolean} addReferences - Whether to add references\r\n\t\t */\r\n\t\tfunction addTranslation(msgctxt, msgid, filename, addReferences) {\r\n\t\t\tif (!msgctxt) return; // Do not add empty strings\r\n\r\n\t\t\tconst translation = {\r\n\t\t\t\tmsgid,\r\n\t\t\t\tmsgctxt,\r\n\t\t\t} as Block;\r\n\r\n\t\t\tif (addReferences) {\r\n\t\t\t\ttranslation.comments = {\r\n\t\t\t\t\treference: [filename],\r\n\t\t\t\t};\r\n\t\t\t}\r\n\r\n\t\t\ttranslations.push(translation);\r\n\t\t}\r\n\r\n\t\t// Start extraction from the root\r\n\t\textract(json, schema);\r\n\r\n\t\treturn translations;\r\n\t}\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAA2B;AAE3B,gBAA2B;AAMpB,MAAM,oBAAoB;AAAA,EAChC,OAAe,cAA6C,CAAC;AAAA;AAAA,EAG7D,OAAO,kBACN;AAAA,EACD,OAAO,oBAAoB;AAAA;AAAA,EAE3B,OAAO,kBACN;AAAA,EACD,OAAO,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS3B,aAAqB,WACpB,KACA,UACsB;AACtB,QAAI,oBAAoB,YAAY,GAAG,GAAG;AACzC,aAAO,oBAAoB,YAAY,GAAG;AA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O,mBAAmB,UAAU;AACvC,sBAAQ,UAAU,gBAAgB,IAAI;AAAA,YACvC,OAAO;AAGN,yBAAW,OAAO,OAAO,KAAK,QAAQ,GAAG;AACxC,oBAAI,OAAO,SAAS,GAAG,MAAM,UAAU;AACtC;AAAA,oBACC,SAAS,GAAG;AAAA,oBACZ;AAAA,oBACAD;AAAA,oBACAC;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AASA,aAAS,eAAe,SAAS,OAAOD,WAAUC,gBAAe;AAChE,UAAI,CAAC,QAAS;AAEd,YAAM,cAAc;AAAA,QACnB;AAAA,QACA;AAAA,MACD;AAEA,UAAIA,gBAAe;AAClB,oBAAY,WAAW;AAAA,UACtB,WAAW,CAACD,SAAQ;AAAA,QACrB;AAAA,MACD;AAEA,mBAAa,KAAK,WAAW;AAAA,IAC9B;AAGA,YAAQ,MAAM,MAAM;AAEpB,WAAO;AAAA,EACR;AACD;",
6
+ "names": ["response", "filename", "addReferences"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/extractors/text.ts"],"names":[],"mappings":";;AASA,0CAqBC;AA9BD,kDAAyD;AAEzD;;;;;;GAMG;AACH,SAAgB,eAAe,CAC9B,WAAmB,EACnB,SAAS,GAAG,GAAG;IAEf,MAAM,IAAI,GAA2B,EAAE,CAAC;IAExC,qCAAqC;IACrC,MAAM,IAAI,GAAG,IAAA,+BAAmB,EAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IACpD,mEAAmE;IACnE,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACpC;;qCAE0B;QAC1B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,SAAS;QACV,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/text.ts"],
4
+ "sourcesContent": ["import { removeCommentMarkup } from \"../utils/common.js\";\n\n/**\n * Extracts file data from the given file content.\n *\n * @param {string} fileContent - The content of the file.\n * @param {string} separator - The separator used in the file.\n * @return {Record<string, string>} An object containing the extracted file data.\n */\nexport function extractFileData(\n\tfileContent: string,\n\tseparator = \":\",\n): Record<string, string> {\n\tconst data: Record<string, string> = {};\n\n\t// split by lines and trim every line\n\tconst text = removeCommentMarkup(fileContent) ?? [];\n\t// split each line by break line and trim each part and add to data\n\tfor (const line of text) {\n\t\tconst parts = line.split(separator);\n\t\t/* Check if the parser has already collected the data from the previous line\n\t\t\t and the current line is empty.\n\t\t\t If so, skip this line */\n\t\tif (parts.length !== 2 && Object.values(data).length > 0 && parts[1]) {\n\t\t\tcontinue;\n\t\t}\n\t\tdata[parts[0]?.trim()] = parts[1].trim();\n\t}\n\n\treturn data;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAS7B,SAAS,gBACf,aACA,YAAY,KACa;AACzB,QAAM,OAA+B,CAAC;AAGtC,QAAM,WAAO,mCAAoB,WAAW,KAAK,CAAC;AAElD,aAAW,QAAQ,MAAM;AACxB,UAAM,QAAQ,KAAK,MAAM,SAAS;AAIlC,QAAI,MAAM,WAAW,KAAK,OAAO,OAAO,IAAI,EAAE,SAAS,KAAK,MAAM,CAAC,GAAG;AACrE;AAAA,IACD;AACA,SAAK,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,MAAM,CAA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E7C,iBAAiB;QACjB,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAA,uBAAa,EAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;YACxD,QAAQ,EAAE,eAAe;SACzB,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,uCAAuC,CAAC,CAAC;IACpE,CAAC;AACF,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,aAAa,CAAC,IAAY;IAC/C,OAAO,IAAA,mBAAQ,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAChC,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/fs/fs.ts"],
4
+ "sourcesContent": ["import fs, { writeFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Ensures that a folder exists at the specified path.\n *\n * @param {string | undefined} folderPath - The path of the folder to ensure existence for.\n * @return {string} - The path of the folder, or '.' if folderPath is undefined.\n */\nfunction ensureFolderExists(folderPath: string | undefined): string {\n\tif (folderPath === undefined) {\n\t\treturn \".\";\n\t}\n\ttry {\n\t\t// Check if the folder exists\n\t\tfs.accessSync(\n\t\t\tpath.resolve(folderPath),\n\t\t\tfs.constants.R_OK | fs.constants.W_OK,\n\t\t);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// The Folder does not exist, so create it\n\t\t\tfs.mkdirSync(folderPath, { recursive: true });\n\t\t\tconsole.log(`Folder created: ${folderPath}`);\n\t\t\treturn folderPath;\n\t\t}\n\t}\n\treturn folderPath;\n}\n\n/**\n * Gets the charset of the .pot file\n *\n * @param charset the charset of the .pot file\n * @return the charset of the .pot file\n */\nexport function getCharset(charset: string | undefined): BufferEncoding {\n\tif (!charset) {\n\t\treturn \"latin1\";\n\t}\n\t// we need to check if the charset is valid otherwise we return latin1 that is a common alias for ISO-8859-1 and the default charset for pot files\n\tswitch (charset.toLowerCase()) {\n\t\tcase \"utf-8\":\n\t\tcase \"utf8\":\n\t\t\treturn \"utf-8\";\n\t\tdefault:\n\t\t\treturn \"latin1\";\n\t}\n}\n\nexport function getEncodingCharset(charset: string | undefined): string {\n\tif (!charset) {\n\t\treturn \"iso-8859-1\";\n\t}\n\t// we need to check if the charset is valid otherwise we return utf-8 that is a common alias for ISO-8859-1 and the default charset for pot files\n\tswitch (charset.toLowerCase()) {\n\t\tcase \"utf-8\":\n\t\tcase \"utf8\":\n\t\t\treturn \"utf-8\";\n\t\tdefault:\n\t\t\treturn \"iso-8859-1\";\n\t}\n}\n\n/**\n * The output path for the pot file.\n * @param args - the command line arguments\n */\nfunction getOutputFilePath(args: Args): string {\n\tconst { out, headers, options } = args.paths;\n\tlet i18nFolder = out ?? headers?.domainPath ?? \"languages\";\n\n\t// Remove leading and trailing slashes\n\ti18nFolder = i18nFolder.replace(/^\\/+|\\/+$/g, \"\");\n\n\tconst extension = options?.json ? \"json\" : \"pot\";\n\n\treturn path.join(process.cwd(), i18nFolder, `${args.slug}.${extension}`);\n}\n\n/**\n * Writes the .pot file to disk\n *\n * @param fileContent the content of the .pot file\n * @param args the command line arguments passed to the program\n */\nexport function writeFile(fileContent: string, args: Args): void {\n\tconst dest = getOutputFilePath(args);\n\n\tif (ensureFolderExists(path.dirname(dest))) {\n\t\t// get the encoding charset\n\t\tconst encodingCharset = getCharset(args.options?.charset);\n\t\tconsole.log(`\\nPot File created at ${dest}`);\n\n\t\t// write the file\n\t\tconst potBuffer = Buffer.from(fileContent);\n\t\twriteFileSync(dest, potBuffer.toString(encodingCharset), {\n\t\t\tencoding: encodingCharset,\n\t\t});\n\t} else {\n\t\tconsole.log(`Folder ${dest} does not exist and cannot be created`);\n\t}\n}\n\n/**\n * The async version of fs.readFile method\n * @param path the path of the file to read\n * @return the content of the file as a string\n */\nexport async function readFileAsync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+ {
2
+ "version": 3,
3
+ "sources": ["../../src/fs/glob.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\r\nimport { Glob, type Path } from \"glob\";\r\nimport { minimatch } from \"minimatch\";\r\n// @ts-expect-error\r\nimport * as javascript from \"tree-sitter-javascript\";\r\n// @ts-expect-error\r\nimport * as php from \"tree-sitter-php\";\r\n// @ts-expect-error\r\nimport * as ts from \"tree-sitter-typescript\";\r\nimport type { Args, Patterns } from \"../types.js\";\r\nimport { detectPatternType, getFileExtension } from \"../utils/common.js\";\r\n\r\n/**\r\n * Return the parser based on the file extension\r\n *\r\n * @param file - Path to the file\r\n * @return {Parser|null} - the parser to be used with the file or null if no parser is found\r\n */\r\nexport function getParser(\r\n\tfile: string,\r\n): string | { name: string; language: unknown } | null {\r\n\tconst ext = getFileExtension(file);\r\n\tswitch (ext) {\r\n\t\tcase \"ts\":\r\n\t\t\treturn ts.typescript;\r\n\t\tcase \"tsx\":\r\n\t\t\treturn ts.tsx;\r\n\t\tcase \"js\":\r\n\t\tcase \"jsx\":\r\n\t\tcase \"mjs\":\r\n\t\tcase \"cjs\":\r\n\t\t\treturn javascript;\r\n\t\tcase \"php\":\r\n\t\t\treturn php.php;\r\n\t\tcase \"blade.php\":\r\n\t\t\treturn php.php_only;\r\n\t\tdefault:\r\n\t\t\treturn null;\r\n\t}\r\n}\r\n\r\n// Build the ignore function for Glob\r\nexport const ignoreFunc = (\r\n\tfilePath: Path,\r\n\texcludedPatterns: string[],\r\n): boolean => {\r\n\treturn excludedPatterns.some((exclude) => {\r\n\t\tconst type = detectPatternType(exclude);\r\n\t\t// return true to ignore\r\n\t\tswitch (type) {\r\n\t\t\tcase \"file\":\r\n\t\t\t\treturn filePath.isNamed(exclude);\r\n\t\t\tcase \"directory\":\r\n\t\t\t\treturn filePath.relative().includes(exclude);\r\n\t\t\tdefault:\r\n\t\t\t\t// Handle glob patterns using minimatch\r\n\t\t\t\treturn minimatch(filePath.relative(), exclude);\r\n\t\t}\r\n\t}) as boolean;\r\n};\r\n\r\n/**\r\n * Retrieves a list of files based on the provided arguments and patterns.\r\n *\r\n * @param {Args} args - The argument object containing the source directory and other options.\r\n * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns.\r\n * @return A promise that resolves to an array of file paths.\r\n */\r\nexport function getFiles(args: Args, pattern: Patterns) {\r\n\t// Execute the glob search with the built patterns\r\n\treturn new Glob(pattern.include, {\r\n\t\tignore: {\r\n\t\t\tignored: (p: Path) => ignoreFunc(p, pattern.exclude),\r\n\t\t},\r\n\t\tnodir: true,\r\n\t\tcwd: args.paths.cwd,\r\n\t\troot: args.paths.root ? path.resolve(args.paths.root) : undefined,\r\n\t});\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,kBAAgC;AAChC,uBAA0B;AAE1B,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;AAGO,MAAM,aAAa,CACzB,UACA,qBACa;AACb,SAAO,iBAAiB,KAAK,CAAC,YAAY;AACzC,UAAM,WAAO,iCAAkB,OAAO;AAEtC,YAAQ,MAAM;AAAA,MACb,KAAK;AACJ,eAAO,SAAS,QAAQ,OAAO;AAAA,MAChC,KAAK;AACJ,eAAO,SAAS,SAAS,EAAE,SAAS,OAAO;AAAA,MAC5C;AAEC,mBAAO,4BAAU,SAAS,SAAS,GAAG,OAAO;AAAA,IAC/C;AAAA,EACD,CAAC;AACF;AASO,SAAS,SAAS,MAAY,SAAmB;AAEvD,SAAO,IAAI,iBAAK,QAAQ,SAAS;AAAA,IAChC,QAAQ;AAAA,MACP,SAAS,CAAC,MAAY,WAAW,GAAG,QAAQ,OAAO;AAAA,IACpD;AAAA,IACA,OAAO;AAAA,IACP,KAAK,KAAK,MAAM;AAAA,IAChB,MAAM,KAAK,MAAM,OAAO,iBAAAA,QAAK,QAAQ,KAAK,MAAM,IAAI,IAAI;AAAA,EACzD,CAAC;AACF;",
6
+ "names": ["path"]
7
+ }
package/lib/index.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mFAAyD;AAc7B,wBAdrB,yBAAa,CAcqB;AAbzC,sEAAwC;AAa/B,mBAbF,wBAAQ,CAaE;AAZjB,oEAAsC;AAYnB,kBAZZ,uBAAO,CAYY;AAV1B,8CAAoD;AAA3C,2GAAA,eAAe,OAAA;AACxB,kDAAgE;AAAvD,4GAAA,OAAO,OAAkB;AAClC,4CAA0C;AAAjC,iGAAA,MAAM,OAAA;AACf,gDAAqD;AAA5C,wGAAA,aAAa,OAAA;AACtB,sDAIiC;AAHhC,iHAAA,mBAAmB,OAAA;AACnB,4GAAA,cAAc,OAAA;AACd,kHAAA,oBAAoB,OAAA"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import StringAuditor from \"./extractors/auditStrings.js\";\nimport makeJson from \"./jsonCommand.js\";\nimport makePot from \"./potCommand.js\";\n\nexport { MakeJsonCommand } from \"./parser/makeJson\";\nexport { makePot as makePotCommand } from \"./parser/makePot.js\";\nexport { doTree } from \"./parser/tree.js\";\nexport { parseJsonFile } from \"./extractors/json.js\";\nexport {\n\textractMainFileData,\n\tgenerateHeader,\n\tgetAuthorFromPackage,\n} from \"./extractors/headers.js\";\n\nexport { makeJson, makePot, StringAuditor };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,2CAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,qCAAAC;AAAA,EAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,0BAA0B;AAC1B,yBAAqB;AACrB,wBAAoB;AAEpB,sBAAgC;AAChC,qBAA0C;AAC1C,kBAAuB;AACvB,kBAA8B;AAC9B,qBAIO;",
6
+ "names": ["StringAuditor", "makeJson", "makePot"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"jsonCommand.js","sourceRoot":"","sources":["../src/jsonCommand.ts"],"names":[],"mappings":";;;;;AAIA,kCAoBC;AAxBD,uEAAmD;AAEnD,iDAAsE;AAEtE,SAAwB,eAAe,CAAC,IAAkB;IACzD,MAAM,QAAQ,GAAG,IAAI,qBAAe,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,IAAA,2BAAe,GAAE,CAAC;QAClB,4BAA4B;QAC5B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,QAAQ;aACN,IAAI,EAAE;aACN,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;YACD,yBAAyB;YACzB,IAAA,4BAAgB,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC;AACF,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/jsonCommand.ts"],
4
+ "sourcesContent": ["import MakeJsonCommand from \"./parser/makeJson.js\";\nimport type { MakeJsonArgs } from \"./types.js\";\nimport { printModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function makeJsonCommand(args: MakeJsonArgs) {\n\tconst makeJson = new MakeJsonCommand(args);\n\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\tmakeJson\n\t\t\t.exec()\n\t\t\t.then((result) => {\n\t\t\t\tif (args.debug) {\n\t\t\t\t\tconsole.log(result);\n\t\t\t\t}\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Json\", timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 make-json - Error: ${error}`);\n\t\t\t});\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAE5B,oBAAkD;AAEnC,SAAR,gBAAiC,MAAoB;AAC3D,QAAM,WAAW,IAAI,gBAAAA,QAAgB,IAAI;AAEzC,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,uCAAgB;AAEhB,UAAM,YAAY,oBAAI,KAAK;AAC3B,aACE,KAAK,EACL,KAAK,CAAC,WAAW;AACjB,UAAI,KAAK,OAAO;AACf,gBAAQ,IAAI,MAAM;AAAA,MACnB;AAEA,0CAAiB,aAAa,SAAS;AAAA,IACxC,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,gCAAyB,KAAK,EAAE;AAAA,IAC/C,CAAC;AAAA,EACH;AACD;",
6
+ "names": ["MakeJsonCommand"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"makeJson.js","sourceRoot":"","sources":["../src/makeJson.ts"],"names":[],"mappings":";;;;;;AAEA,yDAAmD;AACnD,sEAAwC;AAExC,MAAM,IAAI,GAAG,IAAA,4BAAW,GAAE,CAAC;AAE3B,IAAA,wBAAQ,EAAC,IAAI,CAAC,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/makeJson.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\n\nimport { getJsonArgs } from \"./cli/getJsonArgs.js\";\nimport makeJson from \"./jsonCommand.js\";\n\nconst args = getJsonArgs();\n\nmakeJson(args);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,yBAA4B;AAC5B,yBAAqB;AAErB,MAAM,WAAO,gCAAY;AAAA,IAEzB,mBAAAA,SAAS,IAAI;",
6
+ "names": ["makeJson"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"makePot.js","sourceRoot":"","sources":["../src/makePot.ts"],"names":[],"mappings":";;;;;;AAEA,iDAA2C;AAC3C,oEAA6C;AAG7C,qBAAqB;AACrB,IAAA,uBAAc,EAAC,IAAA,oBAAO,GAAU,CAAC,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/makePot.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\n\nimport { getArgs } from \"./cli/getArgs.js\";\nimport makepotCommand from \"./potCommand.js\";\nimport type { Args } from \"./types.js\";\n\n/** Main execution */\nmakepotCommand(getArgs() as Args);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,qBAAwB;AACxB,wBAA2B;AAAA,IAI3B,kBAAAA,aAAe,wBAAQ,CAAS;",
6
+ "names": ["makepotCommand"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/parser/exec.ts"],"names":[],"mappings":";;;;;AAoBA,oBA0EC;AA9FD,0DAA6B;AAE7B,mDAA8D;AAC9D,mEAAsD;AACtD,yDAA+E;AAC/E,uCAA6D;AAE7D,kDAA+E;AAC/E,4CAA6C;AAC7C,+CAA4C;AAC5C,6CAA4C;AAC5C,+CAA6C;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AC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,IAAA,uBAAK,EAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IAChC,CAAC;IAED,6DAA6D;IAC7D,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;QACxB,OAAO,IAAA,mBAAU,EAAC,IAAI,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC;IAED,iCAAiC;IACjC,MAAM,mBAAmB,GAAwB;QAChD,OAAO,EAAE,IAAA,0BAAkB,EAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;QAClD,OAAO,EAAE,SAA6C;QACtD,YAAY,EAAE,iBAAiB,CAAC,MAAM,EAAE;KACxC,CAAC;IAEF,gDAAgD;IAChD,MAAM,kBAAkB,GAAG,mBAAE;SAC3B,OAAO,CAAC,mBAAmB,CAAC;SAC5B,QAAQ,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAE9C,gEAAgE;IAChE,MAAM,gBAAgB,GACrB,IAAI,CAAC,OAAO,EAAE,WAAW;QACzB,IAAA,wBAAY,EACX,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,EAC9B,IAAI,CAAC,OAAO,EAAE,OAAkB,IAAI,iBAAiB,CACtD,CAAC;IACH,OAAO,GAAG,gBAAgB,KAAK,kBAAkB,EAAE,CAAC;AACrD,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/exec.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport { type GetTextTranslations, po } from \"gettext-parser\";\nimport { audit } from \"../extractors/auditStrings.js\";\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\nimport { getCharset, getEncodingCharset } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { getCopyright, outputPathRecap, printStats } from \"../utils/common.js\";\nimport { outputJson } from \"../utils/output\";\nimport { getPatterns } from \"./patterns.js\";\nimport { processFiles } from \"./process.js\";\nimport { initProgress } from \"./progress.js\";\nimport { taskRunner } from \"./taskRunner.js\";\n\n/**\n * Runs the parser and generates the pot file or the json file based on the command line arguments\n *\n * @param {Args} args - The command line arguments\n * @return {Promise<string>} - A promise that resolves with the generated pot file\n */\nexport async function exec(args: Args): Promise<string> {\n\tif (!args.options?.silent) {\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\n\t\tprintStats();\n\t}\n\n\t/** The pot file header contains the data about the plugin or theme */\n\tconst potHeader = await generateHeader(args);\n\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\n\tlet translationsUnion = translationsHeaders(args);\n\n\tif (!args.options?.silent)\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\n\n\t/**\n\t * The progress bar that is used to show the progress of the extraction process.\n\t */\n\tconst progressBar: SingleBar = initProgress(args, 0);\n\tprogressBar.start(3, 1, {\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\n\t});\n\n\t/**\n\t * Extract the strings from the files\n\t */\n\tconst patterns = getPatterns(args);\n\tconst files = await processFiles(patterns, args);\n\n\tprogressBar.update(2, {\n\t\tfilename: `Found ${files.length} files... `,\n\t});\n\n\ttranslationsUnion = await taskRunner(\n\t\tfiles,\n\t\ttranslationsUnion,\n\t\targs,\n\t\tprogressBar,\n\t);\n\n\t/**\n\t * Audit Strings: Strings are validated and reported to the user if they are not compliant.\n\t * --skip-audit flag turns this off\n\t **/\n\tif (!args.options?.skip.audit) {\n\t\tconsole.log(\"\\nAudit strings...\");\n\t\taudit(args, translationsUnion);\n\t}\n\n\t/** generate the json file based on the --json flag passed */\n\tif (args.options?.json) {\n\t\treturn outputJson(args, potHeader, translationsUnion);\n\t}\n\n\t/** Generate the pot file json */\n\tconst getTextTranslations: GetTextTranslations = {\n\t\tcharset: getEncodingCharset(args.options?.charset),\n\t\theaders: potHeader as { [headerName: string]: string },\n\t\ttranslations: translationsUnion.toJson(),\n\t};\n\n\t/** And then compile the pot file to a string */\n\tconst pluginTranslations = po\n\t\t.compile(getTextTranslations)\n\t\t.toString(getCharset(args.options?.charset));\n\n\t/** Return the pot file as a string, prefixed with the header */\n\tconst copyrightComment =\n\t\targs.options?.fileComment ||\n\t\tgetCopyright(\n\t\t\targs.headers?.name || args.slug,\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\n\t\t);\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,0BAAsB;AACtB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAA0D;AAC1D,oBAA2B;AAC3B,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAQ3B,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,uCAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AACnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,QAAQ,UAAM,6BAAa,UAAU,IAAI;AAE/C,cAAY,OAAO,GAAG;AAAA,IACrB,UAAU,SAAS,MAAM,MAAM;AAAA,EAChC,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAMA,MAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC9B,YAAQ,IAAI,oBAAoB;AAChC,mCAAM,MAAM,iBAAiB;AAAA,EAC9B;AAGA,MAAI,KAAK,SAAS,MAAM;AACvB,eAAO,0BAAW,MAAM,WAAW,iBAAiB;AAAA,EACrD;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK,SAAS,QAAQ,KAAK;AAAA,IAC1B,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
6
+ "names": ["path"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"makeJson.js","sourceRoot":"","sources":["../../src/parser/makeJson.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAiC;AACjC,4CAA8B;AAC9B,0DAA6B;AAC7B,sCAA4C;AAE5C,mDAIwB;AACxB,+BAA4B;AAC5B,0CAAyE;AAEzE,kDAAoD;AACpD,iCAAgC;AAEhC,MAAa,eAAe;IAC3B;;;;OAIG;IACc,MAAM,CAAS;IAChC;;;;OAIG;IACc,WAAW,CAAS;IACrC;;;OAGG;IACc,cAAc,CAAW;IAC1C;;;OAGG;IACc,KAAK,CAAU;IAChC;;;OAGG;IACc,WAAW,CAAU;IACtC;;;OAGG;IACK,KAAK,CAAU;IACvB;;;OAGG;IACK,UAA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AAA,aAAM,EAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;CACD;AA5bD,0CA4bC;AAED,kBAAe,eAAe,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/makeJson.ts"],
4
+ "sourcesContent": ["import crypto from \"node:crypto\";\r\nimport * as fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { transformSync } from \"@babel/core\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport {\r\n\ttype GetTextTranslation,\r\n\ttype GetTextTranslations,\r\n\tpo,\r\n} from \"gettext-parser\";\r\nimport { glob } from \"glob\";\r\nimport { IsoCodeRegex, allowedFunctions, modulePath } from \"../const.js\";\r\nimport type { JedData, MakeJson, MakeJsonArgs } from \"../types.js\";\r\nimport { getPkgJsonData } from \"../utils/common.js\";\r\nimport { doTree } from \"./tree\";\r\n\r\nexport class MakeJsonCommand {\r\n\t/**\r\n\t * The source file path.\r\n\t * Should be the \"build\" directory containing .js files\r\n\t * @private\r\n\t */\r\n\tprivate readonly source: string;\r\n\t/**\r\n\t * The destination file path.\r\n\t * Should be the \"languages\" directory containing .po files\r\n\t * @private\r\n\t */\r\n\tprivate readonly destination: string;\r\n\t/**\r\n\t * The allowed file extensions.\r\n\t * @private\r\n\t */\r\n\tprivate readonly allowedFormats: string[];\r\n\t/**\r\n\t * Remove old POT files.\r\n\t * @private\r\n\t */\r\n\tprivate readonly purge: boolean;\r\n\t/**\r\n\t * Pretty print JSON.\r\n\t * @private\r\n\t */\r\n\tprivate readonly prettyPrint: boolean;\r\n\t/**\r\n\t * Enable debug mode.\r\n\t * @private\r\n\t */\r\n\tprivate debug: boolean;\r\n\t/**\r\n\t * The script to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate scriptName: string | string[] | undefined;\r\n\t/**\r\n\t * The paths to be translated.\r\n\t * @private\r\n\t */\r\n\tprivate paths: object | undefined;\r\n\t/**\r\n\t * The source directory.\r\n\t * @private\r\n\t */\r\n\tprivate readonly sourceDir: string;\r\n\t/**\r\n\t * Whenever to strip unused translations from js files\r\n\t * @private\r\n\t */\r\n\tprivate stripUnused: boolean;\r\n\r\n\t/**\r\n\t * The constructor.\r\n\t * @param args - The arguments to the command.\r\n\t */\r\n\tpublic constructor(args: MakeJsonArgs) {\r\n\t\tthis.sourceDir = path.relative(args.paths.cwd, args.source ?? \"\");\r\n\t\tif (!fs.existsSync(this.sourceDir)) {\r\n\t\t\tconsole.error(\"Source directory not found\", args);\r\n\t\t\tthrow new Error(`Source directory ${this.sourceDir} not found`);\r\n\t\t}\r\n\r\n\t\tthis.stripUnused = args.stripUnused;\r\n\t\tthis.scriptName = args.scriptName;\r\n\t\tthis.source = args.source;\r\n\t\tthis.destination = args.destination;\r\n\t\tthis.allowedFormats = args.allowedFormats ?? [\r\n\t\t\t\".ts\",\r\n\t\t\t\".tsx\",\r\n\t\t\t\".js\",\r\n\t\t\t\".jsx\",\r\n\t\t\t\".mjs\",\r\n\t\t\t\".cjs\",\r\n\t\t];\r\n\t\tthis.purge = args.purge;\r\n\t\tthis.prettyPrint = args.prettyPrint;\r\n\t\tthis.debug = args.debug;\r\n\t\tthis.paths = args.paths;\r\n\t}\r\n\r\n\t/**\r\n\t * The main function. Parses the PO files and generates the JSON files.\r\n\t */\r\n\tpublic async exec(): Promise<Record<string, MakeJson>> {\r\n\t\t// get all the files in the source directory\r\n\t\tconst files = await glob(\"**/*.po\", { cwd: this.destination, nodir: true });\r\n\r\n\t\tconsole.log(\"Found po files\", files, \"in\", this.destination, \"folder\");\r\n\r\n\t\t// get all the po files\r\n\t\tconst output: Record<string, MakeJson> = {};\r\n\t\tfor (const file of files) {\r\n\t\t\tif (!this.scriptName) {\r\n\t\t\t\tthis.scriptName = await glob(\"**/*.js\", {\r\n\t\t\t\t\tcwd: this.source,\r\n\t\t\t\t\tnodir: true,\r\n\t\t\t\t});\r\n\t\t\t\tconsole.log(\r\n\t\t\t\t\t`Found script: ${this.scriptName} in ${this.source} folder`,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof this.scriptName === \"string\") {\r\n\t\t\t\tthis.scriptName = [this.scriptName];\r\n\t\t\t}\r\n\r\n\t\t\tfor (const script of this.scriptName) {\r\n\t\t\t\tconst pot = this.addPot(file, script);\r\n\t\t\t\tif (pot.data) {\r\n\t\t\t\t\toutput[pot.filename] = pot.data;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`\u274C Translation strings not found in Script ${script} in ${file} po file`,\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// write the json files\r\n\t\tfor (const [filename, content] of Object.entries(output)) {\r\n\t\t\tlet contentString: string;\r\n\t\t\tif (this.purge) {\r\n\t\t\t\tif (fs.existsSync(path.join(this.destination, filename))) {\r\n\t\t\t\t\tconsole.log(\r\n\t\t\t\t\t\t`Removing ${path.join(this.destination, filename)} as the purge option is enabled`,\r\n\t\t\t\t\t);\r\n\t\t\t\t\tfs.unlinkSync(path.join(this.destination, filename));\r\n\t\t\t\t}\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\tcontent,\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tconst oldJedContent = fs.readFileSync(\r\n\t\t\t\t\tpath.join(this.source, filename),\r\n\t\t\t\t\t\"utf8\",\r\n\t\t\t\t);\r\n\r\n\t\t\t\tcontentString = JSON.stringify(\r\n\t\t\t\t\t{ ...content, ...JSON.parse(oldJedContent) },\r\n\t\t\t\t\tnull,\r\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconst destinationPath = path.join(this.destination, filename);\r\n\t\t\tfs.writeFileSync(destinationPath, contentString);\r\n\t\t\tconsole.log(\r\n\t\t\t\t`\u2705 JSON file written to ${destinationPath} with ${filename}`,\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\t// return the output\r\n\t\treturn output;\r\n\t}\r\n\r\n\t/**\r\n\t * Process a PO file and return the JSON data.\r\n\t * @param file - The path to the PO file.\r\n\t * @param script - The script to be translated.\r\n\t * @param encoding - The encoding of the PO file.\r\n\t */\r\n\tpublic processFile(\r\n\t\tfile: string,\r\n\t\tscript: string,\r\n\t\tencoding: BufferEncoding = \"utf8\",\r\n\t): MakeJson | null {\r\n\t\t// Get the file path\r\n\t\tconst filePath = path.join(this.destination, file);\r\n\r\n\t\t// Read the source file\r\n\t\tconst content = fs.readFileSync(filePath, encoding) as string;\r\n\r\n\t\t// Parse the source file\r\n\t\tconst poContent = this.parsePoFile(content);\r\n\r\n\t\tif (this.stripUnused) {\r\n\t\t\t// get the strings used in the script\r\n\t\t\tconst scriptContent = this.parseScript(script);\r\n\r\n\t\t\tif (!scriptContent) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// compare the strings used in the script with the strings in the po file\r\n\t\t\tconst stringsNotInPoFile = this.compareStrings(\r\n\t\t\t\tscriptContent.blocks,\r\n\t\t\t\tpoContent,\r\n\t\t\t);\r\n\r\n\t\t\tif (!stringsNotInPoFile) {\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\t// replace the po file strings with the strings used in the script\r\n\t\t\tpoContent.translations = stringsNotInPoFile.translations;\r\n\t\t}\r\n\r\n\t\t// Convert to Jed json dataset\r\n\t\treturn this.convertToJed(\r\n\t\t\tpoContent.headers,\r\n\t\t\tpoContent.translations,\r\n\t\t\tscript,\r\n\t\t\tthis.extractIsoCode(filePath), // extract the ISO code from the po filename\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a PO file and returns the header and translations.\r\n\t * @param content - The content of the PO file.\r\n\t * @private\r\n\t *\r\n\t * @returns An object containing the header and translations.\r\n\t */\r\n\tprivate parsePoFile(content: string): GetTextTranslations {\r\n\t\treturn po.parse(content);\r\n\t}\r\n\r\n\t/**\r\n\t * Converts PO data to Jed data.\r\n\t * @param header - The header of the PO file.\r\n\t * @param translations - The translations of the PO file.\r\n\t * @param source - The source of the PO file.\r\n\t * @param languageIsoCode - The ISO code of the language.\r\n\t * @private\r\n\t *\r\n\t * @return An object containing the Jed data.\r\n\t */\r\n\tprivate convertToJed(\r\n\t\theader: Record<string, string>,\r\n\t\ttranslations: {\r\n\t\t\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n\t\t},\r\n\t\tsource: string,\r\n\t\tlanguageIsoCode?: string,\r\n\t): MakeJson {\r\n\t\tconst packageJson = getPkgJsonData(modulePath, \"name\", \"version\") as {\r\n\t\t\tname: string;\r\n\t\t\tversion: string;\r\n\t\t};\r\n\r\n\t\t// Domain name to use for the Jed format\r\n\t\tconst domain: string = \"messages\";\r\n\r\n\t\tconst generator = `${packageJson.name}/${packageJson.version}`;\r\n\r\n\t\t// Initialize the Jed-compatible structure\r\n\t\tconst jedData: JedData = {\r\n\t\t\t[domain]: {\r\n\t\t\t\t\"\": {\r\n\t\t\t\t\tdomain,\r\n\t\t\t\t\tlang: languageIsoCode || header.Language || \"en\",\r\n\t\t\t\t\tplural_forms:\r\n\t\t\t\t\t\theader[\"Plural-Forms\"] || \"nplurals=2; plural=(n != 1);\",\r\n\t\t\t\t},\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\t// Process all translations\r\n\t\tfor (const msgctxt of Object.keys(translations)) {\r\n\t\t\tconst contextTranslations = translations[msgctxt];\r\n\r\n\t\t\tfor (const msgid of Object.keys(contextTranslations)) {\r\n\t\t\t\tconst translation = contextTranslations[msgid];\r\n\r\n\t\t\t\t// Skip empty msgid (header) as we've already handled it\r\n\t\t\t\tif (msgid === \"\") continue;\r\n\r\n\t\t\t\t// Construct the key using context if available\r\n\t\t\t\tconst key =\r\n\t\t\t\t\tmsgctxt && msgctxt !== \"\" ? `${msgctxt}\\u0004${msgid}` : msgid;\r\n\r\n\t\t\t\t// Add the translation to the Jed data structure\r\n\t\t\t\tjedData[domain][key] = translation.msgstr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst makeJson: {\r\n\t\t\tdomain: string;\r\n\t\t\tgenerator: string;\r\n\t\t\t\"translation-revision-date\": string;\r\n\t\t\tsource: string;\r\n\t\t\tlocale_data: JedData;\r\n\t\t} = {\r\n\t\t\t\"translation-revision-date\": new Date().toISOString(),\r\n\t\t\tgenerator: generator,\r\n\t\t\tsource: path.join(this.sourceDir, source).replace(/\\\\/g, \"/\"),\r\n\t\t\tdomain,\r\n\t\t\tlocale_data: jedData,\r\n\t\t};\r\n\r\n\t\treturn makeJson as MakeJson;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the ISO code from the filename.\r\n\t * @param filename The filename to extract the ISO code from.\r\n\t * @private\r\n\t *\r\n\t * @returns The ISO code if found, otherwise null.\r\n\t */\r\n\tprivate extractIsoCode(filename: string): string | undefined {\r\n\t\tconst match = filename.match(IsoCodeRegex);\r\n\t\treturn match ? match[1] : undefined;\r\n\t}\r\n\r\n\t/**\r\n\t * Takes a string and returns its md5 hash.\r\n\t * @param text\r\n\t * @private\r\n\t */\r\n\tprivate md5(text: string): string {\r\n\t\treturn crypto.createHash(\"md5\").update(text).digest(\"hex\");\r\n\t}\r\n\r\n\t/**\r\n\t * Generates the filename for the json file.\r\n\t * @param script\r\n\t * @param file\r\n\t * @private\r\n\t */\r\n\tprivate generateFilename(script: string, file: string): string {\r\n\t\tconst scriptName = this.md5(script);\r\n\t\t//build the filename for the json file using the po files\r\n\t\treturn file.replace(\".po\", `-${scriptName}.json`);\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a script to the output object.\r\n\t * @private\r\n\t *\r\n\t * @param potFile - The pot file to parse.\r\n\t * @param script - The script to add.\r\n\t * @return {Record<string, JedData>} - The output object.\r\n\t * */\r\n\tprivate addPot(\r\n\t\tpotFile: string,\r\n\t\tscript: string,\r\n\t): { filename: string; data: MakeJson | null } {\r\n\t\tconst filename = this.generateFilename(\r\n\t\t\tpath.join(this.source, script).replace(/\\\\/g, \"/\"),\r\n\t\t\tpotFile,\r\n\t\t);\r\n\t\t// the processed file is added to the output object\r\n\t\treturn {\r\n\t\t\tfilename,\r\n\t\t\tdata: this.processFile(potFile, script),\r\n\t\t};\r\n\t}\r\n\r\n\t/**\r\n\t * Compares the strings used in the script with the strings in the po file.\r\n\t * @param jsArray - The strings used in the script.\r\n\t * @param poObject - The content of the po file.\r\n\t * @private\r\n\t */\r\n\tprivate compareStrings(\r\n\t\tjsArray: SetOfBlocks[\"blocks\"],\r\n\t\tpoObject: GetTextTranslations,\r\n\t): GetTextTranslations | null {\r\n\t\t// The copy of the po file with only the strings used in the script\r\n\t\tconst filteredPo = {\r\n\t\t\tcharset: poObject.charset,\r\n\t\t\theaders: { ...poObject.headers },\r\n\t\t\ttranslations: { \"\": {} },\r\n\t\t} as GetTextTranslations;\r\n\r\n\t\t// copy the original header\r\n\t\tif (poObject.translations[\"\"][\"\"]) {\r\n\t\t\tfilteredPo.translations[\"\"][\"\"] = { ...poObject.translations[\"\"][\"\"] };\r\n\t\t}\r\n\r\n\t\t// Create a set of message ids from the JS file\r\n\t\tconst jsMessageIds = new Set(jsArray.map((item) => item.msgid));\r\n\r\n\t\t// Iterate over the po file and keep only the strings used in the script\r\n\t\tfor (const domain in poObject.translations) {\r\n\t\t\tif (domain !== \"\") continue; // handle only the main domain\r\n\r\n\t\t\tfor (const msgid in poObject.translations[domain]) {\r\n\t\t\t\tif (msgid === \"\") continue; // Skip the header\r\n\r\n\t\t\t\tif (jsMessageIds.has(msgid)) {\r\n\t\t\t\t\t// ok the msgid is used\r\n\t\t\t\t\tif (!filteredPo.translations[domain]) {\r\n\t\t\t\t\t\tfilteredPo.translations[domain] = {};\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfilteredPo.translations[domain][msgid] = {\r\n\t\t\t\t\t\t...poObject.translations[domain][msgid],\r\n\t\t\t\t\t};\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// check if the po file is empty, 1 means that the header is the only string available\r\n\t\t// TODO: if the json file is empty, we should delete it?\r\n\t\tif (Object.keys(filteredPo.translations[\"\"]).length <= 1) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\treturn filteredPo;\r\n\t}\r\n\r\n\tprivate parseScript(script: string): SetOfBlocks | undefined {\r\n\t\tconst fileContent = fs.readFileSync(path.join(this.source, script), \"utf8\");\r\n\t\tconst transformedScript = transformSync(fileContent, {\r\n\t\t\tconfigFile: false,\r\n\t\t\tpresets: [\"@babel/preset-env\"],\r\n\t\t\tcompact: false,\r\n\t\t\tcomments: true,\r\n\t\t\tsourceMaps: false,\r\n\t\t\tplugins: [\r\n\t\t\t\t({ types: t }) => ({\r\n\t\t\t\t\tvisitor: {\r\n\t\t\t\t\t\tCallExpression(path) {\r\n\t\t\t\t\t\t\tconst callee = path.node.callee;\r\n\r\n\t\t\t\t\t\t\t// Check for pattern like: (fn)(\"...\")\r\n\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\tt.isSequenceExpression(callee) &&\r\n\t\t\t\t\t\t\t\tt.isMemberExpression(callee.expressions[1])\r\n\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\tconst property = callee.expressions[1].property;\r\n\r\n\t\t\t\t\t\t\t\tif (\r\n\t\t\t\t\t\t\t\t\tt.isIdentifier(property) &&\r\n\t\t\t\t\t\t\t\t\tallowedFunctions.has(property.name)\r\n\t\t\t\t\t\t\t\t) {\r\n\t\t\t\t\t\t\t\t\t// Replace with direct function call: __(\"...\"), _n(...), etc.\r\n\t\t\t\t\t\t\t\t\tpath.node.callee = t.identifier(property.name);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t},\r\n\t\t\t\t\t},\r\n\t\t\t\t}),\r\n\t\t\t],\r\n\t\t}).code as string;\r\n\r\n\t\tre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AAA,IACD;AAIA,QAAI,OAAO,KAAK,WAAW,aAAa,EAAE,CAAC,EAAE,UAAU,GAAG;AACzD,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,YAAY,QAAyC;AAC5D,UAAM,cAAc,GAAG,aAAa,iBAAAA,QAAK,KAAK,KAAK,QAAQ,MAAM,GAAG,MAAM;AAC1E,UAAM,wBAAoB,2BAAc,aAAa;AAAA,MACpD,YAAY;AAAA,MACZ,SAAS,CAAC,mBAAmB;AAAA,MAC7B,SAAS;AAAA,MACT,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,SAAS;AAAA,QACR,CAAC,EAAE,OAAO,EAAE,OAAO;AAAA,UAClB,SAAS;AAAA,YACR,eAAeA,OAAM;AACpB,oBAAM,SAASA,MAAK,KAAK;AAGzB,kBACC,EAAE,qBAAqB,MAAM,KAC7B,EAAE,mBAAmB,OAAO,YAAY,CAAC,CAAC,GACzC;AACD,sBAAM,WAAW,OAAO,YAAY,CAAC,EAAE;AAEvC,oBACC,EAAE,aAAa,QAAQ,KACvB,8BAAiB,IAAI,SAAS,IAAI,GACjC;AAED,kBAAAA,MAAK,KAAK,SAAS,EAAE,WAAW,SAAS,IAAI;AAAA,gBAC9C;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC,EAAE;AAEH,eAAO,oBAAO,mBAAmB,QAAQ,KAAK,KAAK;AAAA,EACpD;AACD;AAEA,IAAO,mBAAQ;",
6
+ "names": ["path", "crypto"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"makePot.js","sourceRoot":"","sources":["../../src/parser/makePot.ts"],"names":[],"mappings":";;AAYA,0BA0BC;AAtCD,yDAA+D;AAC/D,iEAAkE;AAClE,uCAAwC;AAExC,uCAAiC;AAEjC;;;;;GAKG;AACI,KAAK,UAAU,OAAO,CAAC,IAAU;IACvC,iDAAiD;IACjD,MAAM,OAAO,GAAG,IAAA,mCAAkB,EAAC,IAAI,CAAC,CAAC;IAEzC,yDAAyD;IACzD,MAAM,QAAQ,GAAG,IAAA,gCAAmB,EAAC,IAAI,CAAC,CAAC;IAE3C,qEAAqE;IACrE,IAAI,CAAC,OAAO,GAAG;QACd,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO;QACzB,GAAG,OAAO;QACV,GAAG,QAAQ;KACQ,CAAC;IAErB,4BAA4B;IAC5B,OAAO,MAAM,IAAA,cAAI,EAAC,IAAI,CAAC;SACrB,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1B,IAAA,iBAAS,EAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QAElC,OAAO,gBAAgB,CAAC;IACzB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAErB,OAAO,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/makePot.ts"],
4
+ "sourcesContent": ["import { extractMainFileData } from \"../extractors/headers.js\";\nimport { extractPackageJson } from \"../extractors/packageJson.js\";\nimport { writeFile } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { exec } from \"./exec.js\";\n\n/**\n * Generates a pot file for localization.\n *\n * @param args - the command line arguments\n * @return {string} - a promise that resolves when the pot file is generated\n */\nexport async function makePot(args: Args): Promise<string> {\n\t/** Collect metadata from the get package json */\n\tconst pkgData = extractPackageJson(args);\n\n\t/** Get metadata from the main file (theme and plugin) */\n\tconst metadata = extractMainFileData(args);\n\n\t/** Merge the metadata to get a single object with all the headers */\n\targs.headers = {\n\t\t...args?.options?.headers,\n\t\t...pkgData,\n\t\t...metadata,\n\t} as Args[\"headers\"];\n\n\t/** Generate the pot file */\n\treturn await exec(args)\n\t\t.then((jsonTranslations) => {\n\t\t\twriteFile(jsonTranslations, args);\n\n\t\t\treturn jsonTranslations;\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\n\t\t\treturn \"\";\n\t\t});\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AACpC,yBAAmC;AACnC,gBAA0B;AAE1B,kBAAqB;AAQrB,eAAsB,QAAQ,MAA6B;AAE1D,QAAM,cAAU,uCAAmB,IAAI;AAGvC,QAAM,eAAW,oCAAoB,IAAI;AAGzC,OAAK,UAAU;AAAA,IACd,GAAG,MAAM,SAAS;AAAA,IAClB,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AAGA,SAAO,UAAM,kBAAK,IAAI,EACpB,KAAK,CAAC,qBAAqB;AAC3B,6BAAU,kBAAkB,IAAI;AAEhC,WAAO;AAAA,EACR,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,YAAQ,MAAM,KAAK;AAEnB,WAAO;AAAA,EACR,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/parser/patterns.ts"],"names":[],"mappings":";;AAOA,kCAiCC;AAtCD;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAU;IACrC,MAAM,OAAO,GAAG;QACf,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE;QACpC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE;QACpC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU;QACpC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;QAC1C,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB;KACpC,CAAC;IAEd,8DAA8D;IAC9D,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,4BAA4B;QAC5B,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACxC,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAClC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;QACpD,CAAC;QAED,4BAA4B;QAC5B,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YAC1B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACjC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACpC,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACjC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/patterns.ts"],
4
+ "sourcesContent": ["import type { Args, Patterns } from \"../types.js\";\r\n\r\n/**\r\n * Returns the patterns based on the given arguments.\r\n *\r\n * @param args - The arguments for the extract process.\r\n */\r\nexport function getPatterns(args: Args) {\r\n\tconst pattern = {\r\n\t\tinclude: args.patterns.include || [],\r\n\t\texclude: args.patterns.exclude || [],\r\n\t\tmergePaths: args.patterns.mergePaths,\r\n\t\tsubtractPaths: args.patterns.subtractPaths,\r\n\t\tsubtractAndMerge: args.patterns.subtractAndMerge,\r\n\t} as Patterns;\r\n\r\n\t// Additional logic to handle different file types and formats\r\n\tif (args.options) {\r\n\t\t// js typescript mjs cjs etc\r\n\t\tif (args.options.skip.blade) {\r\n\t\t\tpattern.exclude.push(\"**/*.blade.php\");\r\n\t\t} else if (args.options.skip.php) {\r\n\t\t\tpattern.exclude.push(\"**/*.php\", \"**/*.blade.php\");\r\n\t\t}\r\n\r\n\t\t// js typescript mjs cjs etc\r\n\t\tif (args.options.skip.js) {\r\n\t\t\tpattern.exclude.push(\"**/*.{js,jsx,ts,tsx,mjs,cjs}\");\r\n\t\t}\r\n\r\n\t\tif (args.options.skip.blockJson) {\r\n\t\t\tpattern.exclude.push(\"block.json\");\r\n\t\t}\r\n\r\n\t\tif (args.options.skip.themeJson) {\r\n\t\t\tpattern.exclude.push(\"theme.json\");\r\n\t\t}\r\n\t}\r\n\r\n\treturn pattern;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,YAAY,MAAY;AACvC,QAAM,UAAU;AAAA,IACf,SAAS,KAAK,SAAS,WAAW,CAAC;AAAA,IACnC,SAAS,KAAK,SAAS,WAAW,CAAC;AAAA,IACnC,YAAY,KAAK,SAAS;AAAA,IAC1B,eAAe,KAAK,SAAS;AAAA,IAC7B,kBAAkB,KAAK,SAAS;AAAA,EACjC;AAGA,MAAI,KAAK,SAAS;AAEjB,QAAI,KAAK,QAAQ,KAAK,OAAO;AAC5B,cAAQ,QAAQ,KAAK,gBAAgB;AAAA,IACtC,WAAW,KAAK,QAAQ,KAAK,KAAK;AACjC,cAAQ,QAAQ,KAAK,YAAY,gBAAgB;AAAA,IAClD;AAGA,QAAI,KAAK,QAAQ,KAAK,IAAI;AACzB,cAAQ,QAAQ,KAAK,8BAA8B;AAAA,IACpD;AAEA,QAAI,KAAK,QAAQ,KAAK,WAAW;AAChC,cAAQ,QAAQ,KAAK,YAAY;AAAA,IAClC;AAEA,QAAI,KAAK,QAAQ,KAAK,WAAW;AAChC,cAAQ,QAAQ,KAAK,YAAY;AAAA,IAClC;AAAA,EACD;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1 +1 @@
1
- "use strict";var F=Object.create;var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var o in t)f(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of S(t))!w.call(e,s)&&s!==o&&f(e,s,{get:()=>t[s],enumerable:!(i=O(t,s))||i.enumerable});return e};var g=(e,t,o)=>(o=e!=null?F(j(e)):{},d(t||!e||!e.__esModule?f(o,"default",{value:e,enumerable:!0}):o,e)),v=e=>d(f({},"__esModule",{value:!0}),e);var T={};x(T,{processFiles:()=>A});module.exports=v(T);var r=g(require("node:path")),u=require("../const.js"),h=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),P=require("./tree.js");async function A(e,t,o){const i=[];let s=0;const c=(0,k.getFiles)(t,e);o&&(o.setTotal(Object.values(c).length),o.update(0,{filename:`Found ${Object.values(c).length} files`}));for await(const l of c){s++;const n=r.default.basename(l),b=r.default.extname(l).replace(/^./,""),p=r.default.resolve(t.paths.cwd,l);if(n==="theme.json"||n==="block.json")i.push((0,a.readFileAsync)(p).then(m=>(0,h.parseJsonCallback)(m,t.paths.cwd,n)));else if(u.allowedFormats.includes(b)){const m=(0,a.readFileAsync)(p).then(y=>(0,P.doTree)(y,l,t.debug));m&&i.push(m)}o&&(o.update(s,{filename:n}),o.render())}return i}0&&(module.exports={processFiles});
1
+ "use strict";var F=Object.create;var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)f(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!w.call(t,s)&&s!==o&&f(t,s,{get:()=>e[s],enumerable:!(i=O(e,s))||i.enumerable});return t};var v=(t,e,o)=>(o=t!=null?F(j(t)):{},d(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),A=t=>d(f({},"__esModule",{value:!0}),t);var g={};x(g,{processFiles:()=>T});module.exports=A(g);var r=v(require("node:path")),u=require("../const.js"),h=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),P=require("./tree.js");async function T(t,e,o){const i=[];let s=0;const c=(0,k.getFiles)(e,t);o&&(o.setTotal(Object.values(c).length),o.update(0,{filename:`Found ${Object.values(c).length} files`}));for await(const l of c){s++;const n=r.default.basename(l),b=r.default.extname(l).replace(/^./,""),p=r.default.resolve(e.paths.cwd,l);if(n==="theme.json"||n==="block.json")i.push((0,a.readFileAsync)(p).then(m=>(0,h.parseJsonCallback)(m,e.paths.cwd,n)));else if(u.allowedFormats.includes(b)){const m=(0,a.readFileAsync)(p).then(y=>(0,P.doTree)(y,l,e.debug,e));m&&i.push(m)}o&&(o.update(s,{filename:n}),o.render())}return i}0&&(module.exports={processFiles});
@@ -1 +1,7 @@
1
- {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/parser/process.ts"],"names":[],"mappings":";;;;;AAkBA,oCA8CC;AAhED,0DAA6B;AAG7B,0CAA6C;AAC7C,mDAA0D;AAC1D,uCAA4C;AAC5C,2CAAyC;AAEzC,uCAAmC;AAEnC;;;;;;;GAOG;AACI,KAAK,UAAU,YAAY,CACjC,QAAkB,EAClB,IAAU,EACV,WAAuB;IAEvB,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAE5B,MAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEvC,IAAI,WAAW,EAAE,CAAC;QACjB,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QAClD,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE;YACrB,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,QA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C;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/process.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport { allowedFormats } from \"../const.js\";\r\nimport { parseJsonCallback } from \"../extractors/json.js\";\r\nimport { readFileAsync } from \"../fs/fs.js\";\r\nimport { getFiles } from \"../fs/glob.js\";\r\nimport type { Args, Patterns } from \"../types.js\";\r\nimport { doTree } from \"./tree.js\";\r\n\r\n/**\r\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\r\n *\r\n * @param patterns\r\n * @param {Args} args - The arguments for processing the files.\r\n * @param progressBar - The progress bar element.\r\n * @return {Promise<SetOfBlocks[]>} - An array of promises that resolve to TranslationStrings.\r\n */\r\nexport async function processFiles(\r\n\tpatterns: Patterns,\r\n\targs: Args,\r\n\tprogressBar?: SingleBar,\r\n): Promise<Promise<SetOfBlocks>[]> {\r\n\tconst tasks: Promise<SetOfBlocks>[] = [];\r\n\tlet processedFilesCount = 0;\r\n\r\n\tconst files = getFiles(args, patterns);\r\n\r\n\tif (progressBar) {\r\n\t\tprogressBar.setTotal(Object.values(files).length);\r\n\t\tprogressBar.update(0, {\r\n\t\t\tfilename: `Found ${Object.values(files).length} files`,\r\n\t\t});\r\n\t}\r\n\r\n\t// loop through the files and parse them\r\n\tfor await (const file of files) {\r\n\t\tprocessedFilesCount++;\r\n\t\tconst filename = path.basename(file);\r\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\r\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\r\n\r\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\r\n\t\t\ttasks.push(\r\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\r\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t} else if (allowedFormats.includes(ext)) {\r\n\t\t\tconst fileTree = readFileAsync(fileRealPath).then((content) =>\r\n\t\t\t\tdoTree(content, file, args.debug, args),\r\n\t\t\t);\r\n\t\t\tif (fileTree) {\r\n\t\t\t\ttasks.push(fileTree as Promise<SetOfBlocks>);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (progressBar) {\r\n\t\t\tprogressBar.update(processedFilesCount, { filename: filename });\r\n\t\t\tprogressBar.render();\r\n\t\t}\r\n\t}\r\n\r\n\treturn tasks;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,mBAA+B;AAC/B,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AAUvB,eAAsB,aACrB,UACA,MACA,aACkC;AAClC,QAAM,QAAgC,CAAC;AACvC,MAAI,sBAAsB;AAE1B,QAAM,YAAQ,sBAAS,MAAM,QAAQ;AAErC,MAAI,aAAa;AAChB,gBAAY,SAAS,OAAO,OAAO,KAAK,EAAE,MAAM;AAChD,gBAAY,OAAO,GAAG;AAAA,MACrB,UAAU,SAAS,OAAO,OAAO,KAAK,EAAE,MAAM;AAAA,IAC/C,CAAC;AAAA,EACF;AAGA,mBAAiB,QAAQ,OAAO;AAC/B;AACA,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC,YAAM,eAAW,yBAAc,YAAY,EAAE;AAAA,QAAK,CAAC,gBAClD,oBAAO,SAAS,MAAM,KAAK,OAAO,IAAI;AAAA,MACvC;AACA,UAAI,UAAU;AACb,cAAM,KAAK,QAAgC;AAAA,MAC5C;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,qBAAqB,EAAE,SAAmB,CAAC;AAC9D,kBAAY,OAAO;AAAA,IACpB;AAAA,EACD;AAEA,SAAO;AACR;",
6
+ "names": ["path"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/parser/progress.ts"],"names":[],"mappings":";;;;;AAUA,oCAYC;AAtBD,gEAA2D;AAG3D;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,IAAU,EAAE,UAAkB;IAC1D,0BAA0B;IAC1B,OAAO,IAAI,sBAAW,CAAC,SAAS,CAC/B;QACC,eAAe,EAAE,IAAI;QACrB,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,MAAM,EACL,mEAAmE;KACpE,EACD,sBAAW,CAAC,OAAO,CAAC,cAAc,CAClC,CAAC;AACH,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/progress.ts"],
4
+ "sourcesContent": ["import cliProgress, { type SingleBar } from \"cli-progress\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Initializes a progress bar and returns the progress bar element.\n *\n * @param {Args} args - The argument object containing the source directory and other options.\n * @param {number} filesCount - An array of file names.\n * @return {cliProgress.SingleBar} The progress bar element.\n */\nexport function initProgress(args: Args, filesCount: number): SingleBar {\n\t// Set up the progress bar\n\treturn new cliProgress.SingleBar(\n\t\t{\n\t\t\tclearOnComplete: true,\n\t\t\tetaBuffer: 1000,\n\t\t\thideCursor: true,\n\t\t\tformat:\n\t\t\t\t\" {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}\",\n\t\t},\n\t\tcliProgress.Presets.shades_classic,\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAUrC,SAAS,aAAa,MAAY,YAA+B;AAEvE,SAAO,IAAI,oBAAAA,QAAY;AAAA,IACtB;AAAA,MACC,iBAAiB;AAAA,MACjB,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,QACC;AAAA,IACF;AAAA,IACA,oBAAAA,QAAY,QAAQ;AAAA,EACrB;AACD;",
6
+ "names": ["cliProgress"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"taskRunner.js","sourceRoot":"","sources":["../../src/parser/taskRunner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,gCA+CC;AA7DD,4CAA8B;AAC9B,0DAA6B;AAK7B;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAC/B,KAA6B,EAC7B,WAAwB,EACxB,IAAU,EACV,WAAsB;IAEtB,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;SAC7B,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACjB;;WAEG;QACH,OAAO,OAAO;aACZ,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC,KAAK,CAAC;aAC3D,MAAM,CAAC,OAAO,CAAkB,CAAC,CAAC,iBAAiB;IACtD,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;QACtB,sBAAsB;QACtB,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;YACnC,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;gBACnC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC9B;;uBAEG;oBACH,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACpC,qBAAqB;oBACrB,QAAQ,CAAC,IAAI,CACZ,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACpE,CAAC;gBACH,CAAC;;oBAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,iBAAiB,CAAC,CAAC;YACzD,CAAC;QACF,CAAC;IACF,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACd,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEJ,WAAW,CAAC,IAAI,EAAE,CAAC;IAEnB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,OAAO,CAAC,GAAG,CACV,YAAY,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,2BAA2B,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAC9G,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEnC,OAAO,WAAW,CAAC;AACpB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/taskRunner.ts"],
4
+ "sourcesContent": ["import * as os from \"node:os\";\nimport path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport type { SetOfBlocks } from \"gettext-merger\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Task runner for the extraction process.\n *\n * @param tasks - The tasks to run\n * @param destination - The destination\n * @param args - The command line arguments\n * @param progressBar\n */\nexport async function taskRunner(\n\ttasks: Promise<SetOfBlocks>[],\n\tdestination: SetOfBlocks,\n\targs: Args,\n\tprogressBar: SingleBar,\n) {\n\tconst messages = [];\n\tawait Promise.allSettled(tasks)\n\t\t.then((strings) => {\n\t\t\t/**\n\t\t\t * Return the strings that are not rejected (they are fulfilled)\n\t\t\t */\n\t\t\treturn strings\n\t\t\t\t.map((block) => block.status === \"fulfilled\" && block.value)\n\t\t\t\t.filter(Boolean) as SetOfBlocks[]; // remove nullish\n\t\t})\n\t\t.then((consolidated) => {\n\t\t\t/** Log the results */\n\t\t\tif (args.options?.silent !== true) {\n\t\t\t\tfor (const result of consolidated) {\n\t\t\t\t\tif (result.blocks.length > 0) {\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Add the strings to the destination set\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdestination.addArray(result.blocks);\n\t\t\t\t\t\t/* Log the results */\n\t\t\t\t\t\tmessages.push(\n\t\t\t\t\t\t\t`\u2705 ${result.path} [${result.blocks.map((b) => b.msgid).join(\", \")}]`,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else messages.push(`\u274C ${result.path} has no strings`);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.catch((err) => {\n\t\t\treturn new Error(err);\n\t\t});\n\n\tprogressBar.stop();\n\n\tconsole.log(\"\\n\uD83C\uDF89 Done!\");\n\tconsole.log(\n\t\t`\uD83D\uDCDD Found ${Object.values(destination.blocks).length} translation strings in ${path.resolve(args.paths.cwd)}.`,\n\t);\n\n\tconsole.log(messages.join(os.EOL));\n\n\treturn destination;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AACD,QAAM,WAAW,CAAC;AAClB,QAAM,QAAQ,WAAW,KAAK,EAC5B,KAAK,CAAC,YAAY;AAIlB,WAAO,QACL,IAAI,CAAC,UAAU,MAAM,WAAW,eAAe,MAAM,KAAK,EAC1D,OAAO,OAAO;AAAA,EACjB,CAAC,EACA,KAAK,CAAC,iBAAiB;AAEvB,QAAI,KAAK,SAAS,WAAW,MAAM;AAClC,iBAAW,UAAU,cAAc;AAClC,YAAI,OAAO,OAAO,SAAS,GAAG;AAI7B,sBAAY,SAAS,OAAO,MAAM;AAElC,mBAAS;AAAA,YACR,UAAK,OAAO,IAAI,KAAK,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;AAAA,UAClE;AAAA,QACD,MAAO,UAAS,KAAK,UAAK,OAAO,IAAI,iBAAiB;AAAA,MACvD;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,UAAQ,IAAI,mBAAY;AACxB,UAAQ;AAAA,IACP,mBAAY,OAAO,OAAO,YAAY,MAAM,EAAE,MAAM,2BAA2B,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC5G;AAEA,UAAQ,IAAI,SAAS,KAAK,GAAG,GAAG,CAAC;AAEjC,SAAO;AACR;",
6
+ "names": ["path"]
7
+ }
@@ -1 +1 @@
1
- "use strict";var C=Object.create;var f=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0})},S=(t,e,n,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!z.call(t,i)&&i!==n&&f(t,i,{get:()=>e[i],enumerable:!(c=F(e,i))||c.enumerable});return t};var M=(t,e,n)=>(n=t!=null?C(O(t)):{},S(e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n,t)),j=t=>S(f({},"__esModule",{value:!0}),t);var U={};K(U,{doTree:()=>I});module.exports=j(U);var b=M(require("tree-sitter")),y=require("../const.js"),u=require("gettext-merger"),$=require("../fs/glob.js"),g=require("../utils/common.js");function E(t){let e=t,n=0;for(;e&&n<6;){if(e?.previousSibling?.type==="comment"&&e?.previousSibling?.text.toLowerCase().includes("translators"))return e?.previousSibling?.text?(0,g.stripTranslationMarkup)(e.previousSibling.text):void 0;n++,e=e.parent}}function I(t,e,n){const c=new b.default,i=(0,$.getParser)(e);if(!i)return new u.SetOfBlocks([],e);c.setLanguage(i);const x=new u.SetOfBlocks([],e),k=e.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",v=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function _(s){if(s?.children.length)for(const r of s.children)_(r);if(s?.type===k){const r=s.firstChild?.text??null;if(r===null||!Object.keys(y.i18nFunctions).includes(r))return;const l=s.lastChild;if(l===null||l.childCount===0||l.type!=="arguments")return;const[V,N]=s.children,a={},h=y.i18nFunctions[r],B=N.children.slice(1,-1);let m=0;for(const d of B){let o=d,p=o.text;if(d.type==="argument"){if(d.children.length===0)continue;o=d.children[0]}if(o?.type===",")continue;if(o?.type&&v.includes(o.type))p=p.slice(1,-1);else{n&&console.warn(`Unexpected node type ${o?.type} identified as ${h[m]} with value ${p} in ${e} at ${o.startPosition.row+1} pos ${o.startPosition.column+1}`);continue}const T=h[m];a[T]=p,m+=1}const w=E(l),P=new u.Block({msgctxt:a.msgctxt,msgid:a.msgid??"",msgid_plural:a.msgid_plural,msgstr:a.msgid_plural?["",""]:[""],comments:{translator:w?[w]:void 0,reference:[`${(0,g.reverseSlashes)(e)}:${s.startPosition.row+1}`]}});x.add(P)}}try{if(t){const s=Buffer.byteLength(t,"utf8");let r=1024*32;s>=r&&(r=s+32),s>=1024*1024*2&&console.warn(`File size warning: ${e} exceeds 2 MB.`);const l=c.parse(t,void 0,{bufferSize:r});l&&_(l.rootNode)}}catch(s){console.error(`Failed to parse ${e}: ${s}`)}return x}0&&(module.exports={doTree});
1
+ "use strict";var C=Object.create;var m=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var K=(e,t)=>{for(var s in t)m(e,s,{get:t[s],enumerable:!0})},$=(e,t,s,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of L(t))!z.call(e,o)&&o!==s&&m(e,o,{get:()=>t[o],enumerable:!(c=F(t,o))||c.enumerable});return e};var M=(e,t,s)=>(s=e!=null?C(O(e)):{},$(t||!e||!e.__esModule?m(s,"default",{value:e,enumerable:!0}):s,e)),j=e=>$(m({},"__esModule",{value:!0}),e);var I={};K(I,{doTree:()=>E});module.exports=j(I);var k=M(require("tree-sitter")),y=require("../const.js"),d=require("gettext-merger"),v=require("../fs/glob.js"),f=require("../utils/common.js");function D(e){let t=e,s=0;for(;t&&s<6;){if(t?.previousSibling?.type==="comment"&&t?.previousSibling?.text.toLowerCase().includes("translators"))return t?.previousSibling?.text?(0,f.stripTranslationMarkup)(t.previousSibling.text):void 0;s++,t=t.parent}}function E(e,t,s,c){const o=new k.default,x=(0,v.getParser)(t);if(!x)return new d.SetOfBlocks([],t);o.setLanguage(x);const _=new d.SetOfBlocks([],t),N=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",B=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function b(n){if(n?.children.length)for(const r of n.children)b(r);if(n?.type===N){const r=n.firstChild?.text??null;if(r===null||!Object.keys(y.i18nFunctions).includes(r))return;const l=n.lastChild;if(l===null||l.childCount===0||l.type!=="arguments")return;const[U,P]=n.children,a={text_domain:"default"},h=y.i18nFunctions[r],T=P.children.slice(1,-1);let g=0;for(const p of T){let i=p,u=i.text;if(p.type==="argument"){if(p.children.length===0)continue;i=p.children[0]}if(i?.type===",")continue;const w=h[g];if(i?.type&&B.includes(i.type))u=u.slice(1,-1);else if(w==="number")u=i.text;else{console.error(`Unexpected node type ${i?.type} identified as ${h[g]} with value ${u} in ${t} at ${i.startPosition.row+1} pos ${i.startPosition.column+1}`);return}a[w]=u,g+=1}if(Array.isArray(c?.options?.translationDomains)&&!c.options.translationDomains.includes(a.text_domain))return;const S=D(l),A=new d.Block({msgctxt:a.msgctxt,msgid:a.msgid??"",msgid_plural:a.msgid_plural,msgstr:a.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,f.reverseSlashes)(t)}:${n.startPosition.row+1}`]}});_.add(A)}}try{if(e){const n=Buffer.byteLength(e,"utf8");let r=1024*32;n>=r&&(r=n+32),n>=1024*1024*2&&console.warn(`File size warning: ${t} exceeds 2 MB.`);const l=o.parse(e,void 0,{bufferSize:r});l&&b(l.rootNode)}}catch(n){console.error(`Failed to parse ${t}: ${n}`)}return _}0&&(module.exports={doTree});
@@ -1 +1,7 @@
1
- {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/parser/tree.ts"],"names":[],"mappings":";;;;;AAwCA,wBA8JC;AAtMD,8DAAsD;AACtD,0CAA4C;AAE5C,mDAAoD;AACpD,2CAA0C;AAC1C,kDAA4E;AAE5E;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAgB;IACxC,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,mDAAmD;IACnD,OAAO,WAAW,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACjC,IACC,WAAW,EAAE,eAAe,EAAE,IAAI,KAAK,SAAS;YAChD,WAAW,EAAE,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EACvE,CAAC;YACF,OAAO,WAAW,EAAE,eAAe,EAAE,IAAI;gBACxC,CAAC,CAAC,IAAA,kCAAsB,EAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC;gBAC1D,CAAC,CAAC,SAAS,CAAC;QACd,CAAC;QACD,KAAK,EAAE,CAAC;QACR,WAAW,GAAG,WAAW,CA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AE;qBAC3D;iBACD;aACQ,CAAC,CAAC;YAEZ,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IAED,iBAAiB;IACjB,IAAI,CAAC;QACJ,IAAI,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,IAAI,EAAE,CAAC;gBACV,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,mBAAmB,QAAQ,KAAK,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,kCAAkC;IAClC,OAAO,mBAAmB,CAAC;AAC5B,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/parser/tree.ts"],
4
+ "sourcesContent": ["import Parser, { type SyntaxNode } from \"tree-sitter\";\r\nimport { i18nFunctions } from \"../const.js\";\r\n\r\nimport { Block, SetOfBlocks } from \"gettext-merger\";\r\nimport { getParser } from \"../fs/glob.js\";\r\nimport { reverseSlashes, stripTranslationMarkup } from \"../utils/common.js\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Collect comments from the AST node and its preceding siblings.\r\n *\r\n * @param {SyntaxNode} node - The AST node.\r\n * @return {string[]} An array of collected comments.\r\n */\r\nfunction collectComments(node: SyntaxNode): string | undefined {\r\n\tlet currentNode = node;\r\n\tlet depth = 0;\r\n\r\n\t// Check the node's preceding siblings for comments\r\n\twhile (currentNode && depth < 6) {\r\n\t\tif (\r\n\t\t\tcurrentNode?.previousSibling?.type === \"comment\" &&\r\n\t\t\tcurrentNode?.previousSibling?.text.toLowerCase().includes(\"translators\")\r\n\t\t) {\r\n\t\t\treturn currentNode?.previousSibling?.text\r\n\t\t\t\t? stripTranslationMarkup(currentNode.previousSibling.text)\r\n\t\t\t\t: undefined;\r\n\t\t}\r\n\t\tdepth++;\r\n\t\tcurrentNode = currentNode.parent as SyntaxNode;\r\n\t}\r\n}\r\n\r\n/**\r\n * Parses the source code using the specified language parser and extracts the strings from the file.\r\n *\r\n * @param {string} sourceCode - The source code to be parsed.\r\n * @param {string} filepath - The path to the file being parsed.\r\n * @param {boolean} debugEnabled - Whether debug mode is enabled.\r\n * @param {Args} args - The command line arguments, optional.\r\n * @return {SetOfBlocks} An array of translation strings.\r\n */\r\nexport function doTree(\r\n\tsourceCode: string,\r\n\tfilepath: string,\r\n\tdebugEnabled?: boolean,\r\n\targs?: Args,\r\n): SetOfBlocks {\r\n\t// set up the parser\r\n\tconst parser = new Parser();\r\n\tconst parserExt = getParser(filepath);\r\n\t// if no parser is found return empty\r\n\tif (!parserExt) return new SetOfBlocks([], filepath);\r\n\t// set the parser language\r\n\tparser.setLanguage(parserExt);\r\n\r\n\t// set up the translation object\r\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\r\n\r\n\tconst typeToMatch =\r\n\t\tfilepath.split(\".\").pop()?.toLowerCase() !== \"php\"\r\n\t\t\t? \"call_expression\"\r\n\t\t\t: \"function_call_expression\";\r\n\r\n\tconst stringType = [\r\n\t\t\"name\",\r\n\t\t\"string\",\r\n\t\t\"string_value\",\r\n\t\t\"variable_name\",\r\n\t\t\"binary_expression\",\r\n\t\t\"member_expression\",\r\n\t\t\"subscript_expression\",\r\n\t\t\"shell_command_expression\",\r\n\t\t\"function_call_expression\",\r\n\t\t\"encapsed_string\",\r\n\t];\r\n\r\n\t/**\r\n\t * Traverse the tree \uD83C\uDF33\r\n\t *\r\n\t * @param {SyntaxNode} node The node to traverse through\r\n\t */\r\n\tfunction traverse(node: SyntaxNode): void {\r\n\t\t// Walk the tree\r\n\t\tif (node?.children.length)\r\n\t\t\tfor (const child of node.children) {\r\n\t\t\t\ttraverse(child);\r\n\t\t\t}\r\n\r\n\t\t// Check if the node matches\r\n\t\tif (node?.type === typeToMatch) {\r\n\t\t\t// The function name is the first child\r\n\t\t\tconst functionName = node.firstChild?.text ?? null;\r\n\t\t\tif (\r\n\t\t\t\tfunctionName === null ||\r\n\t\t\t\t!Object.keys(i18nFunctions).includes(functionName)\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// The arguments are the last child\r\n\t\t\tconst argsNode = node.lastChild;\r\n\t\t\tif (\r\n\t\t\t\targsNode === null ||\r\n\t\t\t\targsNode.childCount === 0 ||\r\n\t\t\t\targsNode.type !== \"arguments\"\r\n\t\t\t) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the whole gettext translation string\r\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n\t\t\tconst [_fn, raw] = node.children;\r\n\t\t\tconst translation: Partial<{\r\n\t\t\t\tmsgctxt: string;\r\n\t\t\t\tmsgid: string;\r\n\t\t\t\tmsgid_plural: string;\r\n\t\t\t\tnumber: string;\r\n\t\t\t\tmsgstr: string;\r\n\t\t\t\ttext_domain: string;\r\n\t\t\t}> = {\r\n\t\t\t\t// WordPress default text domain is 'default'\r\n\t\t\t\ttext_domain: 'default',\r\n\t\t\t};\r\n\r\n\t\t\tconst translationKeys =\r\n\t\t\t\ti18nFunctions[functionName as keyof typeof i18nFunctions];\r\n\r\n\t\t\tconst children = raw.children.slice(1, -1);\r\n\t\t\tlet translationKeyIndex = 0;\r\n\r\n\t\t\t// Get the translation from the arguments (the quoted strings)\r\n\t\t\tfor (const child of children) {\r\n\t\t\t\tlet node = child;\r\n\t\t\t\tlet nodeValue: string | string[] = node.text;\r\n\r\n\t\t\t\t// unwrap the argument node, which is used in PHP.\r\n\t\t\t\tif (child.type === \"argument\") {\r\n\t\t\t\t\tif (child.children.length === 0) continue;\r\n\t\t\t\t\tnode = child.children[0];\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (node?.type === \",\") {\r\n\t\t\t\t\t// skip the comma between arguments\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the translation key (eg. msgid)\r\n\t\t\t\tconst currentKey = translationKeys[\r\n\t\t\t\t\ttranslationKeyIndex\r\n\t\t\t\t] as keyof typeof translation;\r\n\r\n\t\t\t\tif (node?.type && stringType.includes(node.type)) {\r\n\t\t\t\t\t// unquote the strings\r\n\t\t\t\t\tnodeValue = nodeValue.slice(1, -1);\r\n\t\t\t\t} else if (currentKey === 'number'){\r\n\t\t\t\t\t// `number` accepts any value, this will not be provided in the POT file\r\n\t\t\t\t\tnodeValue = node.text;\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// Whenever we get an unexpected node type this string is not translatable and should be skipped\r\n\t\t\t\t\tconsole.error(\r\n\t\t\t\t\t\t`Unexpected node type ${node?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node.startPosition.row + 1} pos ${node.startPosition.column + 1}`,\r\n\t\t\t\t\t);\r\n\t\t\t\t\treturn; // Parse error, skip this translation.\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// the value of that key\r\n\t\t\t\ttranslation[currentKey] = nodeValue;\r\n\r\n\t\t\t\t// increment the index of the translation key\r\n\t\t\t\ttranslationKeyIndex += 1;\r\n\t\t\t}\r\n\r\n\t\t\tif (Array.isArray(args?.options?.translationDomains) && !args.options.translationDomains.includes(translation.text_domain as string)) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst comments = collectComments(argsNode);\r\n\r\n\t\t\t// Get the translation data\r\n\t\t\tconst block = new Block({\r\n\t\t\t\tmsgctxt: translation.msgctxt,\r\n\t\t\t\tmsgid: translation.msgid ?? \"\",\r\n\t\t\t\tmsgid_plural: translation.msgid_plural,\r\n\t\t\t\tmsgstr: translation.msgid_plural ? [\"\", \"\"] : [\"\"],\r\n\t\t\t\tcomments: {\r\n\t\t\t\t\ttranslator: comments ? [comments] : undefined,\r\n\t\t\t\t\treference: [\r\n\t\t\t\t\t\t`${reverseSlashes(filepath)}:${node.startPosition.row + 1}`,\r\n\t\t\t\t\t],\r\n\t\t\t\t},\r\n\t\t\t} as Block);\r\n\r\n\t\t\tgettextTranslations.add(block);\r\n\t\t}\r\n\t}\r\n\r\n\ttry {\r\n\t\tif (sourceCode) {\r\n\t\t\tconst fileSize = Buffer.byteLength(sourceCode, \"utf8\");\r\n\t\t\tlet bufferSize = 1024 * 32; // 32 KB default buffer size\r\n\r\n\t\t\tif (fileSize >= bufferSize) {\r\n\t\t\t\tbufferSize = fileSize + 32; // dynamic buffer size with 32 bytes of padding\r\n\t\t\t}\r\n\r\n\t\t\tif (fileSize >= 1024 * 1024 * 2) {\r\n\t\t\t\tconsole.warn(`File size warning: ${filepath} exceeds 2 MB.`);\r\n\t\t\t}\r\n\r\n\t\t\t// parse the file\r\n\t\t\tconst tree = parser.parse(sourceCode, undefined, { bufferSize });\r\n\t\t\tif (tree) {\r\n\t\t\t\ttraverse(tree.rootNode);\r\n\t\t\t}\r\n\t\t}\r\n\t} catch (e) {\r\n\t\tconsole.error(`Failed to parse ${filepath}: ${e}`);\r\n\t}\r\n\r\n\t// Return both matches and entries\r\n\treturn gettextTranslations;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAA8B;AAE9B,4BAAmC;AACnC,kBAA0B;AAC1B,oBAAuD;AASvD,SAAS,gBAAgB,MAAsC;AAC9D,MAAI,cAAc;AAClB,MAAI,QAAQ;AAGZ,SAAO,eAAe,QAAQ,GAAG;AAChC,QACC,aAAa,iBAAiB,SAAS,aACvC,aAAa,iBAAiB,KAAK,YAAY,EAAE,SAAS,aAAa,GACtE;AACD,aAAO,aAAa,iBAAiB,WAClC,sCAAuB,YAAY,gBAAgB,IAAI,IACvD;AAAA,IACJ;AACA;AACA,kBAAc,YAAY;AAAA,EAC3B;AACD;AAWO,SAAS,OACf,YACA,UACA,cACA,MACc;AAEd,Q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,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
+ "names": ["Parser", "node"]
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"potCommand.js","sourceRoot":"","sources":["../src/potCommand.ts"],"names":[],"mappings":";;AAKA,6BAeC;AApBD,oDAA8C;AAG9C,iDAAsE;AAEtE,SAAwB,UAAU,CAAC,IAAU;IAC5C,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,IAAA,2BAAe,GAAE,CAAC;QAClB,4BAA4B;QAC5B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,wBAAwB;QACxB,IAAA,oBAAO,EAAC,IAAI,CAAC;aACX,IAAI,CAAC,GAAG,EAAE;YACV,yBAAyB;YACzB,IAAA,4BAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACzC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;AACF,CAAC"}
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
package/lib/types.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/types.ts"],
4
+ "sourcesContent": ["import type { GetTextTranslation } from \"gettext-parser\";\r\nimport type { pkgJsonHeaders, pluginHeaders, themeHeaders } from \"./const.js\";\r\n\r\nexport type ThemeHeadersType = typeof themeHeaders;\r\nexport type PluginHeadersType = typeof pluginHeaders;\r\nexport type PkgHeadersType = typeof pkgJsonHeaders;\r\n\r\n/**\r\n * The args headers Object types\r\n */\r\nexport type PotHeaders =\r\n\t| keyof PkgHeadersType\r\n\t| keyof PluginHeadersType\r\n\t| keyof ThemeHeadersType\r\n\t| \"license\"\r\n\t| \"email\"\r\n\t| \"language\"\r\n\t| \"domain\"\r\n\t| \"bugs\";\r\n\r\n// type is the value of the themeHeader Object\r\nexport type DomainType =\r\n\t| \"plugin\"\r\n\t| \"theme\"\r\n\t| \"block\"\r\n\t| \"theme-block\"\r\n\t| \"generic\";\r\n\r\n/**\r\n * The patterns to use when extracting strings from files.\r\n *\r\n * @param {string} mergePaths - Comma-separated list of POT files whose contents should be merged with the extracted strings.\r\n * If left empty, defaults to the destination POT file. POT file headers will be ignored.\r\n * @param {string} subtractPaths - Comma-separated list of POT files whose contents should act as some sort of denylist\r\n * for string extraction. Any string which is found on that denylist will not be extracted. This can be useful when\r\n * you want to create multiple POT files from the same source directory with slightly different content and no duplicate\r\n * strings between them.\r\n * @param {boolean} subtractAndMerge - Whether source code references and comments from the generated POT file should be\r\n * instead added to the POT file used for subtraction. Warning: this modifies the files passed to `subtractPaths`!\r\n * @param {string} include - Comma-separated list of files and paths that should be used for string extraction.\r\n * If provided, only these files and folders will be taken into account for string extraction.\r\n * For example, `--include=\"src,my-file.php` will ignore anything besides `my-file.php` and files in the `src`\r\n * directory. Simple glob patterns can be used, i.e. `--include=foo-*.php` includes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * @param {string} exclude - Comma-separated list of files and paths that should be skipped for string extraction.\r\n * For example, `--exclude=.github,myfile.php` would ignore any strings found within `myfile.php` or the `.github`\r\n * folder. Simple glob patterns can be used, i.e. `--exclude=foo-*.php` excludes any PHP file with the `foo-`\r\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\r\n * The following files and folders are always excluded: node_modules, .git, .svn, .CVS, .hg, vendor, *.min.js.\r\n */\r\nexport interface Patterns {\r\n\tmergePaths?: string[];\r\n\tsubtractPaths?: string[];\r\n\tsubtractAndMerge?: boolean;\r\n\tinclude: string[];\r\n\texclude: string[];\r\n}\r\n\r\n/**\r\n * Create a POT file for a WordPress project.\r\n *\r\n * Scans PHP, Blade-PHP, and JavaScript files for translatable strings, as well as theme stylesheets and plugin files\r\n * if the source directory is detected as either a plugin or theme.\r\n *\r\n * @param {string} sourceDirectory - Directory to scan for string extraction.\r\n * @param {string} destination - Name of the resulting POT file.\r\n * @param {string | undefined} slug - Plugin or theme slug. Defaults to the source directory's basename.\r\n * @param {'plugin' | 'theme' | 'block' | 'theme-block' | 'generic'} domain - Text domain to look for in the source code,\r\n * unless the `ignoreDomain` option is used. By default, the \"Text Domain\" header of the plugin or theme is used.\r\n * If none is provided, it falls back to the project slug.\r\n * @param {boolean} ignoreDomain - Ignore the text domain completely and extract strings with any text domain.\r\n * @param {{}} headers - Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.\r\n * @param {boolean} location - Whether to write `#: filename:line` lines. Defaults to true, use `--no-location`\r\n * to skip the removal. Note that disabling this option makes it harder for technically skilled translators\r\n * to understand each message\u2019s context.\r\n * @param {boolean} skipJs - Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.\r\n * @param {boolean} skipPhp - Skips PHP string extraction.\r\n * @param {boolean} skipBlade - Skips Blade-PHP string extraction.\r\n * @param {boolean} skipBlockJson - Skips string extraction from block.json files.\r\n * @param {boolean} skipThemeJson - Skips string extraction from theme.json files.\r\n * @param {boolean} skipAudit - Skips string audit where it tries to find possible mistakes in translatable strings.\r\n * Useful when running in an automated environment.\r\n * @param {string} fileComment - String that should be added as a comment to the top of the resulting POT file.\r\n * By default, a copyright comment is added for WordPress plugins and themes.\r\n * @param {string} packageName - Name to use for the package name in the resulting POT file's `Project-Id-Version` header.\r\n * Overrides the plugin or theme name, if applicable.\r\n * @param {boolean} silent - Whether to hide progress information.\r\n */\r\nexport interface Args {\r\n\tslug: string;\r\n\tdebug: boolean;\r\n\tdomain: DomainType;\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout: string;\r\n\t\troot?: string;\r\n\t};\r\n\toptions?: {\r\n\t\tignoreDomain?: boolean;\r\n\t\tsilent?: boolean;\r\n\t\tjson?: boolean;\r\n\t\tlocation?: boolean;\r\n\t\tpackageName?: string;\r\n\t\theaders: { [key in PotHeaders]: string };\r\n\t\toutput?: boolean;\r\n\t\tfileComment?: string;\r\n\t\tcharset?: string;\r\n\t\tskip: {\r\n\t\t\tjs?: boolean;\r\n\t\t\tphp?: boolean;\r\n\t\t\tblade?: boolean;\r\n\t\t\tblockJson?: boolean;\r\n\t\t\tthemeJson?: boolean;\r\n\t\t\taudit?: boolean;\r\n\t\t};\r\n\t\ttranslationDomains?: string[];\r\n\t};\r\n\theaders?: { [key in PotHeaders]: string };\r\n\tpatterns: Patterns;\r\n}\r\n\r\n/**\r\n * The arguments for the `makeJson` command.\r\n * \t@param {string} source the source directory\r\n * \t@param {string | null} destination the destination directory (defaults to source)\r\n * \t@param {string[] | null} allowedFormats the allowed files\r\n * \t@param {boolean} purge remove old json files (otherwise the content will be merged)\r\n * \t@param {boolean} prettyPrint?: pretty print json\r\n * \t@param {boolean} debug: enable debug mode\r\n */\r\nexport interface MakeJsonArgs {\r\n\ttimeStart: number;\r\n\tprettyPrint: boolean;\r\n\tdebug: boolean;\r\n\tdestination: string;\r\n\tscriptName?: string;\r\n\tpurge: boolean;\r\n\tstripUnused: boolean;\r\n\tsource: string;\r\n\tslug: string;\r\n\tallowedFormats?: string[];\r\n\tpaths: {\r\n\t\tcwd: string;\r\n\t\tout?: string;\r\n\t\troot?: string;\r\n\t};\r\n}\r\n\r\nexport interface I18nSchema {\r\n\t[key: string]: string | string[] | I18nSchema | I18nSchema[];\r\n}\r\n\r\n/**\r\n * Translation string metadata.\r\n * Gettext format: https://www.gnu.org/savannah-checkouts/gnu/gettext/FAQ.html\r\n *\r\n * @property {string} msgctxt - context for this translation, if not present the default context applies\r\n * @property {string} msgid - string to be translated\r\n * @property {string} msgid_plural the plural form of the original string (might not be present)\r\n * @property {string[]} msgstr an array of translations\r\n * @property {{}} comments an object with the following properties: translator, reference, extracted, flag, previous.\r\n */\r\nexport interface TranslationStrings {\r\n\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\r\n}\r\n\r\n/** The header of the JED file. */\r\nexport interface JedHeader {\r\n\tdomain: string;\r\n\tlang: string;\r\n\tplural_forms: string;\r\n\t[key: string]: string;\r\n}\r\n\r\n/**\r\n * The JSON data returned by the `makeJson` command.\r\n * @param {string} domain\r\n * @param {Record<string, string | string[] | JedHeader>} locale_data\r\n */\r\nexport interface JedData {\r\n\t[domain: string]: {\r\n\t\t[key: string]: string | string[] | JedHeader;\r\n\t};\r\n}\r\n\r\nexport interface MakeJson {\r\n\tdomain: string;\r\n\tgenerator: string;\r\n\t\"translation-revision-date\": string;\r\n\tsource: string;\r\n\tlocale_data: JedData;\r\n}\r\n\r\n/**\r\n * The header data of the current plugin / theme as returned by the `extractHeaders` command.\r\n */\r\nexport interface I18nHeaders {\r\n\tname: string;\r\n\tauthorString: string;\r\n\tbugs: string;\r\n\tlicense: string;\r\n\tauthor?: string;\r\n\txDomain: string;\r\n\tlanguage: string;\r\n\tversion: string;\r\n\tslug: string;\r\n\temail: string | undefined;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":";;;;;AAYA,0CAGC;AAQD,kDAEC;AAQD,wDAKC;AAQD,oCAQC;AAOD,8CAgBC;AAOD,4CAKC;AASD,oCAQC;AAQD,wCAGC;AAOD,wCAkBC;AAKD,0CAIC;AAQD,4CAUC;AAMD,gCAcC;AASD,0CAEC;AAxMD,sDAAyB;AACzB,qCAAyC;AACzC,0DAA6B;AAC7B,0CAAyC;AAGzC;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC5C,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxD,OAAO,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,KA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
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(path.sep);\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 ${\r\n\t\t\ttimeEnd.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;AAOO,SAAS,kBACf,SACgC;AAChC,QAAM,wBAAwB,QAAQ,SAAS,GAAG;AAClD,QAAM,6BAA6B,QAAQ,SAAS,iBAAAA,QAAK,GAAG;AAE5D,MAAI,QAAQ,SAAS,GAAG,GAAG;AAC1B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,yBAAyB,CAAC,4BAA4B;AAC1D,WAAO;AAAA,EACR;AACA,MAAI,yBAAyB,CAAC,4BAA4B;AACzD,WAAO;AA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M,EAAE,CAAC;QACtB,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC;IACrC,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAlBW,QAAA,UAAU,cAkBrB;AAEF;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC9B,MAAe,EACf,QAAqC,EACrC,QAAgB;IAEhB,MAAM,mBAAmB,GAAgB,IAAI,4BAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAEvE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,mBAAmB,CAAC;IAC5B,CAAC;IAED,kCAAkC;IAClC,mBAAmB,CAAC,IAAI,GAAG,QAAQ,CAAC;IAEpC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,IAAA,kBAAU,EACvB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,OAAiB,EACtB,IAAI,CAAC,QAAQ,EAAE,SAAS,CACxB,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACX,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACF,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC5B,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/extractors.ts"],
4
+ "sourcesContent": ["import { Block, SetOfBlocks } from \"gettext-merger\";\n\n/**\n * Returns the key of an object based on its value\n *\n * @param object the object that contains the key\n * @param value the key that we want to get\n * @return {Record<string, string>} the filtered keys\n */\nexport function getKeyByValue(\n\tobject: Record<string, unknown>,\n\tvalue: string,\n): string | undefined {\n\treturn Object.keys(object).find((key) => object[key] === value) ?? undefined;\n}\n\n/**\n * Returns a gettext translation object\n *\n * @param label the label of the translation\n * @param string the string of the translation\n * @param filePath the file path of the translation\n */\nexport const buildBlock = (\n\tlabel: string,\n\tstring: string,\n\tfilePath: string[] | undefined = undefined,\n): Block => {\n\tconst block = new Block([]);\n\tblock.msgctxt = undefined;\n\tblock.msgid = string;\n\tblock.msgid_plural = \"\";\n\tblock.msgstr = [];\n\tblock.comments = {};\n\tif (label) {\n\t\tblock.comments.extracted = [label];\n\t}\n\tif (filePath?.length) {\n\t\tblock.comments.reference = filePath;\n\t}\n\treturn block;\n};\n\n/**\n * Extracts strings from parsed JSON data.\n *\n * @param {Record<string, any> | Parser.SyntaxNode} parsed - The parsed JSON data or syntax node.\n * @param {string | Parser} filename - The filename or parser.\n * @param filepath - the path to the file being parsed\n * @return {SetOfBlocks} An array of translation strings.\n */\nexport function yieldParsedData(\n\tparsed: Block[],\n\tfilename: \"block.json\" | \"theme.json\",\n\tfilepath: string,\n): SetOfBlocks {\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\n\n\tif (parsed.length === 0) {\n\t\treturn gettextTranslations;\n\t}\n\n\t// set the path of the translation\n\tgettextTranslations.path = filepath;\n\n\tfor (const item of parsed) {\n\t\tconst block = buildBlock(\n\t\t\titem.msgid,\n\t\t\titem.msgctxt as string,\n\t\t\titem.comments?.reference,\n\t\t);\n\n\t\tif (block) {\n\t\t\tgettextTranslations.blocks.push(block);\n\t\t}\n\t}\n\n\treturn gettextTranslations;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC;AAS5B,SAAS,cACf,QACA,OACqB;AACrB,SAAO,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,QAAQ,OAAO,GAAG,MAAM,KAAK,KAAK;AACpE;AASO,MAAM,aAAa,CACzB,OACA,QACA,WAAiC,WACtB;AACX,QAAM,QAAQ,IAAI,4BAAM,CAAC,CAAC;AAC1B,QAAM,UAAU;AAChB,QAAM,QAAQ;AACd,QAAM,eAAe;AACrB,QAAM,SAAS,CAAC;AAChB,QAAM,WAAW,CAAC;AAClB,MAAI,OAAO;AACV,UAAM,SAAS,YAAY,CAAC,KAAK;AAAA,EAClC;AACA,MAAI,UAAU,QAAQ;AACrB,UAAM,SAAS,YAAY;AAAA,EAC5B;AACA,SAAO;AACR;AAUO,SAAS,gBACf,QACA,UACA,UACc;AACd,QAAM,sBAAmC,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAErE,MAAI,OAAO,WAAW,GAAG;AACxB,WAAO;AAAA,EACR;AAGA,sBAAoB,OAAO;AAE3B,aAAW,QAAQ,QAAQ;AAC1B,UAAM,QAAQ;AAAA,MACb,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,UAAU;AAAA,IAChB;AAEA,QAAI,OAAO;AACV,0BAAoB,OAAO,KAAK,KAAK;AAAA,IACtC;AAAA,EACD;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1 +1,7 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":";;;;;AAYA,gCAgBC;AA3BD,oDAA4B;AAG5B;;;;;;;GAOG;AACH,SAAgB,UAAU,CACzB,IAAU,EACV,SAAwC,EACxC,iBAA8B;IAE9B,MAAM,OAAO,GAET;QACH,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACZ,EAAE,EAAE,SAAS,IAAI,EAAE;YACnB,GAAI,iBAAiB,CAAC,MAAM,EAAwC;SACpE;KACD,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/output.ts"],
4
+ "sourcesContent": ["import type { SetOfBlocks } from \"gettext-merger\";\r\nimport Tannin from \"tannin\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Outputs the pot file in json format based on the command line arguments --json option\r\n *\r\n * @param {Args} args - The command line arguments\r\n * @param {Record<string, string>} potHeader - The pot file header\r\n * @param {SetOfBlocks} translationsUnion - The translations union\r\n * @return {string} - The output pot file\r\n */\r\nexport function outputJson(\r\n\targs: Args,\r\n\tpotHeader: Record<string, string> | null,\r\n\ttranslationsUnion: SetOfBlocks,\r\n) {\r\n\tconst jedData: {\r\n\t\t[p: string]: { [p: string]: [string, string] };\r\n\t} = {\r\n\t\t[args.slug]: {\r\n\t\t\t\"\": potHeader ?? {},\r\n\t\t\t...(translationsUnion.toJson() as { [p: string]: [string, string] }),\r\n\t\t},\r\n\t};\r\n\tconst i18n = new Tannin(jedData);\r\n\r\n\treturn i18n.toString();\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAmB;AAWZ,SAAS,WACf,MACA,WACA,mBACC;AACD,QAAM,UAEF;AAAA,IACH,CAAC,KAAK,IAAI,GAAG;AAAA,MACZ,IAAI,aAAa,CAAC;AAAA,MAClB,GAAI,kBAAkB,OAAO;AAAA,IAC9B;AAAA,EACD;AACA,QAAM,OAAO,IAAI,cAAAA,QAAO,OAAO;AAE/B,SAAO,KAAK,SAAS;AACtB;",
6
+ "names": ["Tannin"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-blocks/make-pot",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
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",
@@ -64,7 +64,7 @@
64
64
  "cli-progress": "^3.12.0",
65
65
  "gettext-merger": "^1.2.1",
66
66
  "gettext-parser": "^4.0.4",
67
- "glob": "^11.0.2",
67
+ "glob": "^11.0.3",
68
68
  "tannin": "^1.2.0",
69
69
  "tree-sitter": "^0.21.1",
70
70
  "tree-sitter-javascript": "^0.23.1",
@@ -73,12 +73,12 @@
73
73
  "yargs": "^17.7.1"
74
74
  },
75
75
  "devDependencies": {
76
- "@biomejs/biome": "1.9.4",
76
+ "@biomejs/biome": "2.2.4",
77
77
  "@types/cli-progress": "^3.11.6",
78
78
  "@types/gettext-parser": "^4.0.4",
79
79
  "@types/node": "^22.15.17",
80
80
  "@types/yargs": "^17.0.33",
81
- "esbuild": "0.25.4",
82
- "typescript": "^5.8.3"
81
+ "esbuild": "0.25.9",
82
+ "typescript": "^5.9.2"
83
83
  }
84
84
  }
@@ -177,3 +177,40 @@ describe("doTree large file", () => {
177
177
  assert.strictEqual(r.filter((block) => block.comments).length, 19);
178
178
  });
179
179
  });
180
+
181
+ describe("doTree php filtered by translation domain", async () => {
182
+ it("should extract translations filtered by translation domain", () => {
183
+ const content = `<?php
184
+
185
+ __( 'hello, world' );
186
+ __( 'hello, foo', 'foo-plugin' );
187
+ __( 'hello, bar', 'bar-plugin' );
188
+ `;
189
+
190
+ const filename = "filename.php";
191
+
192
+ for (const translationDomain of ['default', 'foo-plugin', 'bar-plugin']) {
193
+ const r = doTree(content, filename, undefined, { options: { translationDomains: [translationDomain] } }).blocks;
194
+ assert.strictEqual(r.map((block) => block).length, 1);
195
+ }
196
+ });
197
+ });
198
+
199
+ describe("doTree php _n, _nx", async () => {
200
+ it("should extract translations and comments from code content", () => {
201
+ const content = `<?php
202
+
203
+ // translators: %d a number of years
204
+ _n( '%d year ago', '%d years go', 1, 'foo-plugin' );
205
+
206
+ // translators: %d a number of years
207
+ _nx( '%d year ago', '%d years go', 1, 'context', 'foo-plugin' );
208
+ `;
209
+
210
+ const filename = "filename.php";
211
+
212
+ const r = doTree(content, filename).blocks;
213
+
214
+ assert.strictEqual(r.filter((block) => block.msgctxt === 'context').length, 1);
215
+ });
216
+ });