@wp-blocks/make-pot 1.4.0 → 1.5.1

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 (78) hide show
  1. package/README.md +79 -11
  2. package/lib/assets/block-i18n.js.map +7 -0
  3. package/lib/assets/package-i18n.js +1 -1
  4. package/lib/assets/package-i18n.js.map +7 -0
  5. package/lib/assets/theme-i18n.js.map +7 -0
  6. package/lib/assets/wp-plugin-i18n.js.map +7 -0
  7. package/lib/assets/wp-theme-i18n.js.map +7 -0
  8. package/lib/cli/getArgs.js +1 -1
  9. package/lib/cli/getArgs.js.map +7 -0
  10. package/lib/cli/getJsonArgs.js +1 -1
  11. package/lib/cli/getJsonArgs.js.map +7 -0
  12. package/lib/cli/parseCli.js +1 -1
  13. package/lib/cli/parseCli.js.map +7 -0
  14. package/lib/cli.js +2 -0
  15. package/lib/cli.js.map +7 -0
  16. package/lib/const.js +1 -1
  17. package/lib/const.js.map +7 -0
  18. package/lib/extractors/css.js +1 -1
  19. package/lib/extractors/css.js.map +7 -0
  20. package/lib/extractors/headers.js +6 -1
  21. package/lib/extractors/headers.js.map +7 -0
  22. package/lib/extractors/json.js +1 -1
  23. package/lib/extractors/json.js.map +7 -0
  24. package/lib/extractors/packageJson.js +1 -0
  25. package/lib/extractors/packageJson.js.map +7 -0
  26. package/lib/extractors/php.js +2 -2
  27. package/lib/extractors/php.js.map +7 -0
  28. package/lib/extractors/schema.js +4 -1
  29. package/lib/extractors/schema.js.map +7 -0
  30. package/lib/extractors/text.js +1 -1
  31. package/lib/extractors/text.js.map +7 -0
  32. package/lib/fs/fs.js +2 -1
  33. package/lib/fs/fs.js.map +7 -0
  34. package/lib/fs/glob.js +1 -3
  35. package/lib/fs/glob.js.map +7 -0
  36. package/lib/index.js +1 -2
  37. package/lib/index.js.map +7 -0
  38. package/lib/jsonCommand.js +1 -2
  39. package/lib/jsonCommand.js.map +7 -0
  40. package/lib/makeJson.js +2 -0
  41. package/lib/makeJson.js.map +7 -0
  42. package/lib/makePot.js +2 -0
  43. package/lib/makePot.js.map +7 -0
  44. package/lib/parser/exec.js +7 -3
  45. package/lib/parser/exec.js.map +7 -0
  46. package/lib/parser/makeJson.js +1 -3
  47. package/lib/parser/makeJson.js.map +7 -0
  48. package/lib/parser/makePot.js +1 -1
  49. package/lib/parser/makePot.js.map +7 -0
  50. package/lib/parser/patterns.js +1 -1
  51. package/lib/parser/patterns.js.map +7 -0
  52. package/lib/parser/process.js +1 -1
  53. package/lib/parser/process.js.map +7 -0
  54. package/lib/parser/progress.js +1 -1
  55. package/lib/parser/progress.js.map +7 -0
  56. package/lib/parser/taskRunner.js +2 -1
  57. package/lib/parser/taskRunner.js.map +7 -0
  58. package/lib/parser/tree.js +1 -1
  59. package/lib/parser/tree.js.map +7 -0
  60. package/lib/potCommand.js +1 -1
  61. package/lib/potCommand.js.map +7 -0
  62. package/lib/types.js +1 -1
  63. package/lib/types.js.map +7 -0
  64. package/lib/utils/common.js +4 -2
  65. package/lib/utils/common.js.map +7 -0
  66. package/lib/utils/extractors.js +1 -0
  67. package/lib/utils/extractors.js.map +7 -0
  68. package/package.json +22 -22
  69. package/tests/extract-headers.test.js +54 -0
  70. package/tests/extract.test.js +381 -381
  71. package/tests/jsonParse.test.js +167 -0
  72. package/tests/parse-headers.test.js +74 -0
  73. package/tests/tree.test.js +158 -158
  74. package/tsconfig.json +2 -0
  75. package/lib/extractors/utils.js +0 -1
  76. package/tests/getFiles.test.no.js +0 -85
  77. package/tests/jsonParse.no.js +0 -49
  78. package/tests/wpcliCompare.no.js +0 -32
package/README.md CHANGED
@@ -2,15 +2,26 @@
2
2
  [![](https://img.shields.io/npm/l/@wp-blocks/make-pot)](https://github.com/wp-blocks/make-pot?tab=GPL-3.0-1-ov-file#readme)
3
3
  [![](https://github.com/wp-blocks/make-pot/actions/workflows/node.js.yml/badge.svg)](https://github.com/wp-blocks/make-pot/actions/workflows/node.js.yml)
4
4
 
5
- ## Make Pot
5
+ ## Make POT
6
6
 
7
7
  `make-pot` is a Node.js module designed to generate the `.pot` file for your WordPress plugin or theme. This file serves as the basis for internationalization, allowing translators to localize your plugin or theme into different languages.
8
8
 
9
9
  Extract strings from your WordPress plugin or theme and generate a `.pot` file. Works with `js`, `jx`, `ts`, `tsx`, `cjs`, `mjs`, `php`, `blade`, `txt`, `json` with a custom schema for theme and block.json files.
10
10
 
11
- ### Installation
11
+ ## Make JSON
12
+ `make-json` is a Node.js module designed to convert `.po` files into JSON format for your WordPress plugin or theme. This conversion facilitates client-side translations and enables your JavaScript code to use the translated strings.
13
+
14
+ Transform your translation files into a JSON format compatible with WordPress i18n package. This module simplifies the process of making your WordPress plugin or theme fully translatable on the frontend.
15
+
16
+ ## Installation
17
+
18
+ You can install `make-pot` as a dependecy via npm:
19
+
20
+ ```
21
+ npm install -d @wp-blocks/make-pot
22
+ ```
12
23
 
13
- You can install `make-pot` globally via npm:
24
+ or globally
14
25
 
15
26
  ```
16
27
  npm install -g @wp-blocks/make-pot
@@ -19,7 +30,22 @@ npm install -g @wp-blocks/make-pot
19
30
  ### Usage
20
31
 
21
32
  ```bash
33
+ # without installation
22
34
  npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
35
+ npx -p @wp-blocks/make-pot makejson [sourceDirectory] [destination] [options]
36
+
37
+ # installed
38
+ npx makepot [sourceDirectory] [destination] [options]
39
+ npx makejson [sourceDirectory] [destination] [options]
40
+ ```
41
+
42
+ ## Make Pot
43
+
44
+ Example usage:
45
+
46
+ ```bash
47
+ # without installation
48
+ npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,tsx},inc/**/*,admin/**/*.{php}"
23
49
  ```
24
50
 
25
51
  #### Positional Arguments:
@@ -51,8 +77,48 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
51
77
  - `--exclude <files>`: Excludes specific files from processing.
52
78
  - `--silent`: Suppresses output to stdout.
53
79
  - `--json`: Outputs the JSON gettext data.
80
+ - `--charset`: Defines the encoding charset of the pot file, you can choose "iso-8859-1" and "uft-8" (defaults to iso-8859-1)
54
81
  - `--output`: Outputs the gettext data.
55
82
 
83
+ ### Example usage
84
+
85
+ First of all remember that the 'make-pot' help can be printed using the command `npx @wp-blocks/make-pot -h`, and the help for the json command can be printed using the command `npx make-json -h`. the commands are available after installing the module (`npm install @wp-blocks/make-pot`)
86
+
87
+ #### Using `make-pot` in your `package.json` (assiming you have already installed the makepot command)
88
+ ```bash
89
+ "scripts": {
90
+ "build": "npm run build:scripts && npm run build:makepot",
91
+ "build:scripts": "wp-scripts build",
92
+ "build:makepot": "npx makepot",
93
+ "build-2:makejson": "npx makejson",
94
+ }
95
+ ```
96
+ > Note: that it should be launched after creating the “.po” files with the localized translations (and then at a later time)
97
+
98
+ Both command does not need any arguments, they will parse the required data from the plugin file (the one in the root directory with the same name of the folder) or the theme.json/theme css file in the case of themes.
99
+ So what you should check before running the command is to have all the WordPress and Node.js required data/metadata in place, nothing else. Anyway, the command can be customized if you need, let's see some examples:
100
+
101
+ #### Using `make-pot` include and exclude files
102
+ We use glob module to include and exclude files. please check [glob](https://github.com/isaacs/node-glob)
103
+
104
+ ```bash
105
+ # Every file in includes, frontend and admin directories that is not in node_modules
106
+ npx @wp-blocks/make-pot --include='includes/**/*,frontend/**/*,admin/**/*' --exclude="**/node_modules/**"
107
+
108
+ # Every file that is a tsx, ts, js and not in node_modules
109
+ npx @wp-blocks/make-pot --include='**/*.{tsx,ts,js}' --exclude="**/node_modules/**"
110
+
111
+ # Merge the resulting pot file with another pot file
112
+ npx @wp-blocks/make-pot --mergePaths='path/to/other.pot'
113
+
114
+ # Remove the strings from the resulting pot file with another pot file
115
+ npx @wp-blocks/make-pot --subtractPaths='path/to/other.pot'
116
+ ```
117
+
118
+ #### Tip:
119
+ The include and exclude options works in a different way... the include option adds the files to the default list of files to be processed, while the exclude option replaces the original list and excludes the specified files/directories.
120
+ The mergePaths option will merge the resulting pot file with another pot file, while the subtractPaths option will subtract the strings from the resulting pot file with another pot file.
121
+
56
122
  ## As a build chain step
57
123
 
58
124
  The `make-pot` module can be used as a build step in your build chain.
@@ -65,7 +131,7 @@ To do so, create a `build:makepot` action in your `package.json` with the follow
65
131
  ```
66
132
  ---
67
133
 
68
- # JSON Translations
134
+ # Make JSON
69
135
 
70
136
  ### Why JSON Translation for WordPress JavaScript?
71
137
 
@@ -98,18 +164,20 @@ Unlike traditional PO/MO files, JavaScript translations use JSON. This format is
98
164
 
99
165
  #### Build the json translations file
100
166
 
101
- first build the translation pot file using `makepot` (no matter with this module or not) and then translate it into the different languages.
167
+ First, build the translation pot file using `makepot` (no matter with this module or not) and then translate it into the different languages.
102
168
 
103
- then run `makejson`:
169
+ translate the pot file into your language and then run `makejson`:
104
170
 
105
171
  ```bash
106
- npx @wp-blocks/make-pot makejson language --scriptName="build/frontend.js"
172
+ npx makejson
173
+ # OR if you don't want to install the module
174
+ npx -p @wp-blocks/make-pot makejson,
107
175
  ```
108
176
  It Will create a file for each po file in the `languages` directory with the md5 hash with the name of the file.
109
177
  In this case, the file will be named my-frontend-script-en_US-79431f0eb8deb8221f24df5112e15095.json because the md5 hash of "build/frontend.js" is 79431f0eb8deb8221f24df5112e15095.
110
178
  This is crucial because the md5 hash has to be the same as the path of the script file.
111
179
 
112
- #### Register the javascript block translations
180
+ ## Register the javascript block translations
113
181
 
114
182
  ```php
115
183
  <?php
@@ -117,7 +185,7 @@ This is crucial because the md5 hash has to be the same as the path of the scrip
117
185
  * Loads the plugin text domain for translation.
118
186
  */
119
187
  function my_i18n() {
120
- load_plugin_textdomain( 'my-text-domain', false, __DIR__ . '/languages' );
188
+ load_plugin_textdomain( 'my-text-domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
121
189
  }
122
190
  add_action( 'init', 'my_i18n' );
123
191
 
@@ -125,7 +193,7 @@ add_action( 'init', 'my_i18n' );
125
193
  * Registers the block using the metadata loaded from the `block.json` file.
126
194
  */
127
195
  add_action('init', function () {
128
- register_block_type(__DIR__ . '/build', [
196
+ register_block_type( dirname( plugin_basename( __FILE__ ) ) . '/build', [
129
197
  "script" => "my-vendor-script",
130
198
  "viewScript" => "my-frontend-script",
131
199
  "editorScript" => "my-editor-script",
@@ -137,7 +205,7 @@ add_action('init', function () {
137
205
  */
138
206
  function my_register_block_type() {
139
207
 
140
- $fe_assets = include __FILE__ . '/build/my-frontend-script.asset.php';
208
+ $fe_assets = include dirname( __FILE__ ) . '/build/my-frontend-script.asset.php';
141
209
 
142
210
  wp_register_script(
143
211
  'my-frontend-script',
@@ -0,0 +1,7 @@
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 @@
1
- "use strict";var u=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var n=(e,r)=>{for(var s in r)u(e,s,{get:r[s],enumerable:!0})},b=(e,r,s,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of l(r))!t.call(e,i)&&i!==s&&u(e,i,{get:()=>r[i],enumerable:!(o=a(r,i))||o.enumerable});return e};var g=e=>b(u({},"__esModule",{value:!0}),e);var p={};n(p,{default:()=>m});module.exports=g(p);var m={name:"name",url:"url",description:"description",author:"author",authorEmail:"authorEmail",version:"version",bugs:"bugs","bugs.url":"bugsUrl","bugs.email":"bugsEmail",license:"license",repository:"repository"};
1
+ "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var t=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var n=(s,r)=>{for(var e in r)o(s,e,{get:r[e],enumerable:!0})},b=(s,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of t(r))!l.call(s,u)&&u!==e&&o(s,u,{get:()=>r[u],enumerable:!(i=a(r,u))||i.enumerable});return s};var g=s=>b(o({},"__esModule",{value:!0}),s);var m={};n(m,{default:()=>h});module.exports=g(m);var h={name:"name",url:"url",description:"description",author:"author",authors:"authors",authorEmail:"authorEmail",version:"version",bugs:"bugs","bugs.url":"bugsUrl","bugs.email":"bugsEmail",license:"license",repository:"repository"};
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,7 @@
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,y=Object.prototype.hasOwnProperty;var f=(e,i)=>{for(var t in i)o(e,t,{get:i[t],enumerable:!0})},n=(e,i,t,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of g(i))!y.call(e,s)&&s!==t&&o(e,s,{get:()=>i[s],enumerable:!(r=b(i,s))||r.enumerable});return e};var a=(e,i,t)=>(t=e!=null?l(u(e)):{},n(i||!e||!e.__esModule?o(t,"default",{value:e,enumerable:!0}):t,e)),m=e=>n(o({},"__esModule",{value:!0}),e);var S={};f(S,{getArgs:()=>h});module.exports=m(S);var p=a(require("node:process")),k=a(require("yargs")),c=require("yargs/helpers"),d=require("./parseCli.js");function h(e={}){const i=k.default((0,c.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"},headers:{describe:"Headers",type:"string"},"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"},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"}}).parseSync();return(0,d.parseCliArgs)({...e,...i})}0&&(module.exports={getArgs});
1
+ "use strict";var l=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,y=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 b(t))!y.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(r=g(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={};f(S,{getArgs:()=>h});module.exports=m(S);var p=a(require("node:process")),k=a(require("yargs")),c=require("yargs/helpers"),d=require("./parseCli.js");function h(e={}){const t=k.default((0,c.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"},headers:{describe:"Headers",type:"string"},"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"}}).parseSync();return(0,d.parseCliArgs)({...e,...t})}0&&(module.exports={getArgs});
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/cli/getArgs.ts"],
4
+ "sourcesContent": ["import process from \"node:process\";\nimport * as yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport type { Args, MakeJsonArgs } from \"../types.js\";\nimport { parseCliArgs } from \"./parseCli.js\";\n\n/**\n * Retrieves and returns the command line arguments and options.\n *\n * @return The parsed command line arguments and options.\n */\nexport function getArgs(userArgs = {}): Args | 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(\"sourceDirectory\", {\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\tslug: {\n\t\t\t\tdescribe: \"Plugin or theme slug\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tdomain: {\n\t\t\t\tdescribe: \"Text domain to look for in the source code\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\t\"skip-js\": {\n\t\t\t\tdescribe: \"Skip JavaScript files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"skip-php\": {\n\t\t\t\tdescribe: \"Skip PHP files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"skip-blade\": {\n\t\t\t\tdescribe: \"Skip Blade files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"skip-block-json\": {\n\t\t\t\tdescribe: \"Skip block.json files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"skip-theme-json\": {\n\t\t\t\tdescribe: \"Skip theme.json files\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"skip-audit\": {\n\t\t\t\tdescribe: \"Skip auditing of strings\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\theaders: {\n\t\t\t\tdescribe: \"Headers\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\t\"file-comment\": {\n\t\t\t\tdescribe: \"File comment\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\t\"package-name\": {\n\t\t\t\tdescribe: \"Package name\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tlocation: {\n\t\t\t\tdescribe: \"Include location information\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\t\"ignore-domain\": {\n\t\t\t\tdescribe: \"Ignore text domain\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\tmergePaths: {\n\t\t\t\tdescribe: \"Merge with existing POT file(s)\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tsubtractPaths: {\n\t\t\t\tdescribe: \"Subtract strings from existing POT file(s)\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tsubtractAndMerge: {\n\t\t\t\tdescribe: \"Subtract and merge strings from existing POT file(s)\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\tinclude: {\n\t\t\t\tdescribe: \"Include specific files\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdefault: \"**\",\n\t\t\t},\n\t\t\texclude: {\n\t\t\t\tdescribe: \"Exclude specific files\",\n\t\t\t\ttype: \"string\",\n\t\t\t},\n\t\t\tsilent: {\n\t\t\t\tdescribe: \"No output to stdout\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\tjson: {\n\t\t\t\tdescribe: \"Output the json gettext data\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\toutput: {\n\t\t\t\tdescribe: \"Output the gettext data\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t},\n\t\t\tcharset: {\n\t\t\t\tdescribe: \"Charset\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdefault: \"latin1\",\n\t\t\t},\n\t\t})\n\t\t.parseSync();\n\treturn parseCliArgs({ ...userArgs, ...args });\n}\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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AAU;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,EACD,CAAC,EACA,UAAU;AACZ,aAAO,8BAAa,EAAE,GAAG,UAAU,GAAG,KAAK,CAAC;AAC7C;",
6
+ "names": ["process"]
7
+ }
@@ -1 +1 @@
1
- "use strict";var c=Object.create;var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})},a=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of u(t))!y.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(i=g(t,o))||i.enumerable});return e};var n=(e,t,r)=>(r=e!=null?c(f(e)):{},a(t||!e||!e.__esModule?s(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>a(s({},"__esModule",{value:!0}),e);var A={};m(A,{getJsonArgs:()=>J});module.exports=b(A);var p=n(require("node:process")),h=n(require("yargs")),l=require("yargs/helpers"),d=require("./parseCli");function J(e={}){const t=h.default((0,l.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("source",{describe:"Source directory",type:"string",default:"./languages"}).positional("destination",{describe:"Destination directory",type:"string"}).options({scriptName:{describe:"The name of the script to be translated",type:"string"},allowedFormats:{describe:"which extensions to use for translation",type:"array"},purge:{describe:"Remove old POT files",type:"boolean",default:!0},prettyPrint:{describe:"Pretty print JSON",type:"boolean",default:!1},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,d.parseJsonArgs)({...e,...t})}0&&(module.exports={getJsonArgs});
1
+ "use strict";var c=Object.create;var o=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})},a=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!y.call(e,s)&&s!==r&&o(e,s,{get:()=>t[s],enumerable:!(i=f(t,s))||i.enumerable});return e};var n=(e,t,r)=>(r=e!=null?c(u(e)):{},a(t||!e||!e.__esModule?o(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>a(o({},"__esModule",{value:!0}),e);var A={};m(A,{getJsonArgs:()=>J});module.exports=b(A);var p=n(require("node:process")),h=n(require("yargs")),d=require("yargs/helpers"),l=require("./parseCli.js");function J(e={}){const t=h.default((0,d.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("source",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({scriptName:{describe:"The name of the script to be translated",type:"string"},allowedFormats:{describe:"which extensions to use for translation",type:"array",default:["js"]},purge:{describe:"Remove old JSON files",type:"boolean",default:!0},prettyPrint:{describe:"Pretty print JSON",type:"boolean",default:!1},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,l.parseJsonArgs)({...e,...t})}0&&(module.exports={getJsonArgs});
@@ -0,0 +1,7 @@
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})\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,EACD,CAAC,EACA,UAAU;AACZ,aAAO,+BAAc,EAAE,GAAG,gBAAgB,GAAG,KAAK,CAAC;AACpD;",
6
+ "names": ["process"]
7
+ }
@@ -1 +1 @@
1
- "use strict";var h=Object.create;var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var D=(t,n)=>{for(var e in n)p(t,e,{get:n[e],enumerable:!0})},m=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of A(n))!_.call(t,s)&&s!==e&&p(t,s,{get:()=>n[s],enumerable:!(i=k(n,s))||i.enumerable});return t};var u=(t,n,e)=>(e=t!=null?h(P(t)):{},m(n||!t||!t.__esModule?p(e,"default",{value:t,enumerable:!0}):e,t)),b=t=>m(p({},"__esModule",{value:!0}),t);var j={};D(j,{parseCliArgs:()=>J,parseJsonArgs:()=>S});module.exports=b(j);var r=u(require("node:fs")),o=u(require("node:path")),g=u(require("node:process")),d=require("../const.js"),c=require("../utils/common.js");function w(t="/",n="default"){const e=t;try{return(0,r.accessSync)(o.join(e,`${n}.php`),r.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${e} does not contain a ${n}.php file`)}try{return(0,r.accessSync)(o.join(e,"style.css"),r.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${e} does not contain a style.css file`)}return e.includes(`wp-content${o.sep}themes`)?"theme":e.includes(`wp-content${o.sep}plugins`)?"plugin":"generic"}function J(t){const n=typeof t._[0]=="string"?t._[0].toString():".",e=typeof t._[1]=="string"?t._[1].toString():".",i=g.cwd(),s=t.slug&&typeof t.slug=="string"?t.slug:o.basename(o.resolve(i,n)),l=o.relative(i,n),y=o.relative(i,e),f=t?.domain??w(o.resolve(l),s),a={slug:s,domain:f,paths:{cwd:l,out:y},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit}},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)??d.DEFAULT_EXCLUDED_PATH}};return a.paths.root=t.root?String(t.root):void 0,a}function S(t){const n=typeof t._[0]=="string"?t._[0].toString():"",e=typeof t._[1]=="string"?t._[1].toString():n,i=g.cwd();return{slug:o.basename(o.resolve(i)),source:n,destination:e,scriptName:t.scriptName??"index.js",allowedFormats:t.allowedFormats,purge:!!t.purge,prettyPrint:!!t.prettyPrint,debug:!!t.debug}}0&&(module.exports={parseCliArgs,parseJsonArgs});
1
+ "use strict";var b=Object.create;var u=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var J=(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 P(n))!w.call(t,s)&&s!==e&&u(t,s,{get:()=>n[s],enumerable:!(o=A(n,s))||o.enumerable});return t};var l=(t,n,e)=>(e=t!=null?b(D(t)):{},g(n||!t||!t.__esModule?u(e,"default",{value:t,enumerable:!0}):e,t)),T=t=>g(u({},"__esModule",{value:!0}),t);var S={};J(S,{parseCliArgs:()=>j,parseJsonArgs:()=>O});module.exports=T(S);var c=l(require("node:fs")),i=l(require("node:path")),h=l(require("node:process")),f=require("../const.js"),y=require("../fs/fs"),a=require("../utils/common.js");function _(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 j(t){const n=t._[0]?.toString(),e=t._[1]?.toString()||"languages",o=n??".",s=e.startsWith("/")?e.slice(1):e,r=h.cwd(),p=t.slug&&typeof t.slug=="string"?t.slug:i.basename(i.resolve(r,o)),m=i.relative(r,o),k=i.relative(r,s);if(!t?.domain)t.domain=_(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 d={slug:p,domain:t.domain,paths:{cwd:m,out:k},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,charset:(0,y.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),...f.DEFAULT_EXCLUDED_PATH]}};return d.paths.root=t.root?String(t.root):void 0,d}function O(t){const n=t._[0]||"build",e=t._[1]||"languages",o=h.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,prettyPrint:!!t.prettyPrint,debug:!!t.debug,paths:{cwd:o,out:i.join(o,e)}}}0&&(module.exports={parseCliArgs,parseJsonArgs});
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/cli/parseCli.ts"],
4
+ "sourcesContent": ["import fs, { accessSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as process from \"node:process\";\nimport type * as yargs from \"yargs\";\nimport { DEFAULT_EXCLUDED_PATH } from \"../const.js\";\nimport { getEncodingCharset } from \"../fs/fs\";\nimport type { Args, DomainType, MakeJsonArgs } from \"../types.js\";\nimport { stringstring } from \"../utils/common.js\";\n\n/**\n * This function checks if the current working directory is a theme or plugin\n * @param currentPath The current working directory\n * @param slug The slug of the theme or plugin\n */\nfunction isThemeOrPlugin(currentPath = \"/\", slug = \"default\"): DomainType {\n\tconst currentWorkingDirectory = currentPath;\n\n\t/**\n\t * Checks if the current working directory contains a plugin file\n\t */\n\ttry {\n\t\taccessSync(\n\t\t\tpath.join(currentWorkingDirectory, `${slug}.php`),\n\t\t\tfs.constants.R_OK,\n\t\t);\n\t\treturn \"plugin\";\n\t} catch (err) {\n\t\t// do nothing\n\t\tconsole.log(\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a ${slug}.php file`,\n\t\t);\n\t}\n\n\t/**\n\t * Checks if the current working directory contains a style.css file and is a theme\n\t */\n\ttry {\n\t\taccessSync(\n\t\t\tpath.join(currentWorkingDirectory, \"style.css\"),\n\t\t\tfs.constants.R_OK,\n\t\t);\n\t\treturn \"theme\";\n\t} catch (err) {\n\t\t// do nothing\n\t\tconsole.log(\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a style.css file`,\n\t\t);\n\t}\n\n\t// If none of the above conditions are met, return \"generic\"\n\treturn \"generic\";\n}\n\n/**\n * Parses the command line arguments and returns an object with the parsed values.\n *\n * @param {{_: string[]}} args - The command line arguments to be parsed.\n * @return {object} - An object with the parsed values from the command line arguments.\n */\nexport function parseCliArgs(\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\n): Args {\n\t// Get the input and output paths\n\tconst pos1: string | undefined = args._[0]?.toString();\n\tconst pos2: string = args._[1]?.toString() || \"languages\";\n\n\tconst inputPath: string | undefined = pos1 ?? \".\";\n\t// remove \"/\" if the output path starts with it\n\tconst outputPath: string = pos2.startsWith(\"/\") ? pos2.slice(1) : pos2;\n\n\t// Store the current working directory\n\tconst currentWorkingDirectory = process.cwd();\n\n\t// Get the slug or use the basename of the current working directory\n\t// the slug is the plugin or theme slug. Defaults to the source directory\u2019s basename\n\tconst slug =\n\t\targs.slug && typeof args.slug === \"string\"\n\t\t\t? args.slug\n\t\t\t: path.basename(path.resolve(currentWorkingDirectory, inputPath));\n\n\t// Get the relative paths\n\tconst cwd = path.relative(currentWorkingDirectory, inputPath);\n\tconst out = path.relative(currentWorkingDirectory, outputPath);\n\n\t/** get the domain to look for (plugin, theme, etc) */\n\tif (!(args?.domain as DomainType)) {\n\t\targs.domain = isThemeOrPlugin(path.resolve(cwd), slug);\n\t} else {\n\t\tswitch (args.domain) {\n\t\t\tcase \"plugin\":\n\t\t\tcase \"theme\":\n\t\t\tcase \"block\":\n\t\t\tcase \"theme-block\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Invalid domain: ${args.domain}. Valid domains are: plugin, theme, block, theme-block, generic`,\n\t\t\t\t);\n\t\t\t\t// fallback to generic if the domain is invalid\n\t\t\t\targs.domain = \"generic\";\n\t\t}\n\t}\n\n\tconst parsedArgs: Args = {\n\t\tslug: slug,\n\t\tdomain: args.domain as DomainType,\n\t\tpaths: { cwd: cwd, out: out },\n\t\toptions: {\n\t\t\tignoreDomain: !!args?.ignoreDomain,\n\t\t\tpackageName: String(args.packageName),\n\t\t\tsilent: args.silent === true, // default is false\n\t\t\tjson: !!args.json,\n\t\t\tlocation: !!args?.location,\n\t\t\toutput: !!args?.output,\n\t\t\tfileComment: args.fileComment ? String(args.fileComment) : undefined,\n\t\t\tcharset: getEncodingCharset(args?.charset as string | undefined),\n\t\t\tskip: {\n\t\t\t\tjs: !!args.skipJs,\n\t\t\t\tphp: !!args.skipPhp,\n\t\t\t\tblade: !!args.skipBlade,\n\t\t\t\tblockJson: !!args.skipBlockJson,\n\t\t\t\tthemeJson: !!args.skipThemeJson,\n\t\t\t\taudit: !!args.skipAudit,\n\t\t\t},\n\t\t},\n\t\t// Patterns\n\t\tpatterns: {\n\t\t\tmergePaths: stringstring(args.mergePaths as string),\n\t\t\tsubtractPaths: stringstring(args.subtractPaths as string),\n\t\t\tsubtractAndMerge: !!args.subtractAndMerge,\n\t\t\tinclude: stringstring(args.include as string),\n\t\t\texclude: [\n\t\t\t\t...stringstring(args.exclude as string),\n\t\t\t\t...DEFAULT_EXCLUDED_PATH,\n\t\t\t],\n\t\t},\n\t};\n\n\tparsedArgs.paths.root = args.root ? String(args.root) : undefined;\n\n\treturn parsedArgs;\n}\n\n/**\n * Parses the command line arguments for the JSON command.\n * @param args - The command line arguments to be parsed.\n */\nexport function parseJsonArgs(\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\n): MakeJsonArgs {\n\t// Get the input and output paths\n\tconst inputPath: string = (args._[0] as string) || \"build\";\n\tconst outputPath: string = (args._[1] as string) || \"languages\";\n\tconst currentWorkingDirectory = process.cwd();\n\tconst slug = path.basename(path.resolve(currentWorkingDirectory));\n\n\tlet scriptName = undefined;\n\tif (args.scriptName) {\n\t\tscriptName = args.scriptName.split(\",\").map((s) => s.trim());\n\t\tif (scriptName.length === 1) {\n\t\t\tscriptName = scriptName[0];\n\t\t}\n\t}\n\n\treturn {\n\t\ttimeStart: Date.now(),\n\t\tslug,\n\t\tsource: inputPath,\n\t\tdestination: outputPath,\n\t\tscriptName,\n\t\tallowedFormats: args.allowedFormats as string[],\n\t\tpurge: !!args.purge,\n\t\tprettyPrint: !!args.prettyPrint,\n\t\tdebug: !!args.debug,\n\t\tpaths: {\n\t\t\tcwd: currentWorkingDirectory,\n\t\t\tout: path.join(currentWorkingDirectory, outputPath),\n\t\t},\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+B;AAC/B,WAAsB;AACtB,cAAyB;AAEzB,mBAAsC;AACtC,gBAAmC;AAEnC,oBAA6B;AAO7B,SAAS,gBAAgB,cAAc,KAAK,OAAO,WAAuB;AACzE,QAAM,0BAA0B;AAKhC,MAAI;AACH;AAAA,MACC,KAAK,KAAK,yBAAyB,GAAG,IAAI,MAAM;AAAA,MAChD,eAAAA,QAAG,UAAU;AAAA,IACd;AACA,WAAO;AAAA,EACR,SAAS,KAAK;AAEb,YAAQ;AAAA,MACP,iCAAiC,uBAAuB,uBAAuB,IAAI;AAAA,IACpF;AAAA,EACD;AAKA,MAAI;AACH;AAAA,MACC,KAAK,KAAK,yBAAyB,WAAW;AAAA,MAC9C,eAAAA,QAAG,UAAU;AAAA,IACd;AACA,WAAO;AAAA,EACR,SAAS,KAAK;AAEb,YAAQ;AAAA,MACP,iCAAiC,uBAAuB;AAAA,IACzD;AAAA,EACD;AAGA,SAAO;AACR;AAQO,SAAS,aACf,MACO;AAEP,QAAM,OAA2B,KAAK,EAAE,CAAC,GAAG,SAAS;AACrD,QAAM,OAAe,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK;AAE9C,QAAM,YAAgC,QAAQ;AAE9C,QAAM,aAAqB,KAAK,WAAW,GAAG,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d=Object.create;var n=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var b=(o,r,s,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of A(r))!J.call(o,e)&&e!==s&&n(o,e,{get:()=>r[e],enumerable:!(a=l(r,e))||a.enumerable});return o};var m=(o,r,s)=>(s=o!=null?d(y(o)):{},b(r||!o||!o.__esModule?n(s,"default",{value:o,enumerable:!0}):s,o));var t=m(require("node:process")),c=m(require("yargs")),i=require("yargs/helpers"),p=require("./cli/getArgs.js"),f=require("./cli/getJsonArgs.js"),g=m(require("./jsonCommand.js")),k=m(require("./potCommand.js"));const j=c.default((0,i.hideBin)(t.default.argv)).options({makejson:{describe:"Make JSON file",type:"boolean",default:!1}}).parseSync();j.makejson?(0,g.default)((0,f.getJsonArgs)()):(0,k.default)((0,p.getArgs)());
package/lib/cli.js.map ADDED
@@ -0,0 +1,7 @@
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 CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.create;var _=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},n=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of l(e))!f.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=p(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?c(u(t)):{},n(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var U={};b(U,{DEFAULT_EXCLUDED_PATH:()=>D,IsoCodeRegex:()=>E,allowedFormats:()=>L,blockJson:()=>k,defaultLocale:()=>J,fileRegex:()=>F,i18nFunctions:()=>T,pkgJsonHeaders:()=>w,pluginHeaders:()=>H,themeHeaders:()=>A,themeJson:()=>j});module.exports=h(U);var d=o(require("./assets/block-i18n.js")),x=o(require("./assets/package-i18n.js")),g=o(require("./assets/theme-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),r=o(require("./assets/wp-theme-i18n.js"));const j=g.default,k=d.default,w=x.default,H=a.default,A=r.default,D=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],E=/-([a-z]{2}_[A-Z]{2})\.po$/,F=/#:\s*(.*?)(?::\d+)?$/,J="en_US",L=["php","js","jsx","ts","tsx","mjs","cjs"],T={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]};0&&(module.exports={DEFAULT_EXCLUDED_PATH,IsoCodeRegex,allowedFormats,blockJson,defaultLocale,fileRegex,i18nFunctions,pkgJsonHeaders,pluginHeaders,themeHeaders,themeJson});
1
+ "use strict";var r=Object.create;var _=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},d=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!u.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?r(l(t)):{},d(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>d(_({},"__esModule",{value:!0}),t);var P={};f(P,{DEFAULT_EXCLUDED_PATH:()=>H,IsoCodeRegex:()=>k,allowedFormats:()=>E,defaultLocale:()=>D,fileRegex:()=>A,i18nFunctions:()=>F,modulePath:()=>L,pkgJsonHeaders:()=>j,pluginHeaders:()=>b,themeHeaders:()=>w});module.exports=h(P);var n=o(require("node:path")),x=o(require("./assets/package-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),g=o(require("./assets/wp-theme-i18n.js"));const j=x.default,b=a.default,w=g.default,H=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],k=/-([a-z]{2}_[A-Z]{2})\.po$/,A=/#:\s*(.*?)(?::\d+)?$/,D="en_US",E=["php","js","jsx","ts","tsx","mjs","cjs"],F={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]},L=n.default.resolve(__dirname,"..");0&&(module.exports={DEFAULT_EXCLUDED_PATH,IsoCodeRegex,allowedFormats,defaultLocale,fileRegex,i18nFunctions,modulePath,pkgJsonHeaders,pluginHeaders,themeHeaders});
@@ -0,0 +1,7 @@
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 default functions to use for i18n.\n */\nexport const i18nFunctions = {\n\t__: [\"msgid\", \"text_domain\"],\n\tesc_attr__: [\"msgid\", \"text_domain\"],\n\tesc_html__: [\"msgid\", \"text_domain\"],\n\tesc_xml__: [\"msgid\", \"text_domain\"],\n\t_e: [\"msgid\", \"text_domain\"],\n\tesc_attr_e: [\"msgid\", \"text_domain\"],\n\tesc_html_e: [\"msgid\", \"text_domain\"],\n\tesc_xml_e: [\"msgid\", \"text_domain\"],\n\t_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_ex: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_attr_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_html_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_xml_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_n: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t_nx: [\"msgid\", \"msgid_plural\", \"number\", \"msgctxt\", \"text_domain\"],\n\t_n_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n\t_nx_noop: [\"msgid\", \"msgid_plural\", \"msgctxt\", \"text_domain\"],\n\n\t// Compat.\n\t_: [\"msgid\", \"text_domain\"],\n\n\t// Deprecated.\n\t_c: [\"msgid\", \"text_domain\"],\n\t_nc: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n};\n\n/**\n * @var modulePath The path to the module folder containing this file\n */\nexport const modulePath = path.resolve(__dirname, \"..\");\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,0BAAwB;AACxB,4BAAyB;AACzB,2BAAwB;AAMjB,MAAM,iBAAiB,oBAAAA;AAKvB,MAAM,gBAAgB,sBAAAC;AAKtB,MAAM,eAAe,qBAAAC;AAMrB,MAAM,wBAAwB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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]
7
+ }
@@ -1 +1 @@
1
- "use strict";var u=Object.create;var i=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!j.call(e,s)&&s!==o&&i(e,s,{get:()=>t[s],enumerable:!(r=T(t,s))||r.enumerable});return e};var a=(e,t,o)=>(o=e!=null?u(C(e)):{},f(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),B=e=>f(i({},"__esModule",{value:!0}),e);var F={};k(F,{extractCssThemeData:()=>D});module.exports=B(F);var m=a(require("node:fs")),h=a(require("node:path")),d=require("../const.js"),p=require("../utils/common.js"),y=require("./text.js"),g=require("./utils.js");function D(e){let t={};const o=h.default.join(e.paths.cwd,"style.css");if(m.default.existsSync(o)){const r=m.default.readFileSync(o,"utf8"),s=(0,p.getCommentBlock)(r);if(t=(0,y.extractFileData)(s),"Theme Name"in t){console.log("Theme stylesheet detected."),console.log(`Theme stylesheet: ${o}`),e.domain="theme";const c={};for(const n of Object.entries(t))if(n&&n[0]&&n[1]){const l=(0,g.getKeyByValue)(d.themeHeaders,n[0].trim());if(l===void 0)continue;c[l]=n[1].trim()}return c}}else console.log(`Theme stylesheet not found in ${o}`);return{}}0&&(module.exports={extractCssThemeData});
1
+ "use strict";var x=Object.create;var i=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var B=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},l=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!k.call(e,n)&&n!==o&&i(e,n,{get:()=>t[n],enumerable:!(r=C(t,n))||r.enumerable});return e};var a=(e,t,o)=>(o=e!=null?x(j(e)):{},l(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),D=e=>l(i({},"__esModule",{value:!0}),e);var R={};B(R,{extractCssThemeData:()=>F});module.exports=D(R);var m=a(require("node:fs")),d=a(require("node:path")),h=require("../const.js"),p=require("../utils/common.js"),g=require("../utils/extractors.js"),y=require("./text.js");function F(e,t="style.css"){let o={};const r=d.default.join(e.paths.cwd,t);if(m.default.existsSync(r)){const n=m.default.readFileSync(r,"utf8"),u=(0,p.getCommentBlock)(n);if(o=(0,y.extractFileData)(u),"Theme Name"in o){console.log(`\u{1F535} Theme stylesheet detected. ${r}`),e.domain="theme";const c={};for(const s of Object.entries(o))if(s?.[0]&&s[1]){const f=(0,g.getKeyByValue)(h.themeHeaders,s[0].trim());if(f===void 0)continue;c[f]=s[1].trim()}return c}}else console.log(`Theme stylesheet not found in ${r}`);return{}}0&&(module.exports={extractCssThemeData});
@@ -0,0 +1,7 @@
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,wCAAiC,YAAY,EAAE;AAC3D,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,6 @@
1
- "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of D(t))!$.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(a=f(t,n))||a.enumerable});return e};var O=e=>P(c({},"__esModule",{value:!0}),e);var k={};A(k,{extractMainFileData:()=>I,generateHeader:()=>x,translationsHeaders:()=>M});module.exports=O(k);var d=require("gettext-merger"),g=require("../utils/common"),h=require("./css.js"),p=require("./php.js"),s=require("./utils.js");function x(e){const{author:t,textDomain:o}=e.headers,{name:a,version:n}=(0,g.getPkgJsonData)("name","version"),i="EMAIL",u="en",l=`${t} <${i}>`,r=o?`X-Domain: ${o}`:"",H={url:"https://wordpress.org/support/plugin/"+e.slug,email:i||"AUTHOR EMAIL"},m={...e.headers,author:e.headers?.author||"AUTHOR",slug:e.slug||"PLUGIN NAME",email:i,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||"1.0.0",language:u,domain:e.headers?.textDomain||e.headers?.slug||"PLUGIN DOMAIN"};return{"Project-Id-Version":`${m.slug} ${m.version}`,"Report-Msgid-Bugs-To":l,"MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=iso-8859-1","plural-forms":"nplurals=2; plural=(n!=1);","POT-Creation-Date":`${new Date().toISOString()}`,"PO-Revision-Date":`${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,"Last-Translator":l,"Language-Team":l,"X-Generator":`${a} ${n}`,Language:`${u}`,domain:r}}function I(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,p.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,h.extractCssThemeData)(e):console.log("No main file detected."),t}function M(e){const{domain:t,headers:o}=e,{name:a,description:n,author:i,authorUri:u,url:l}=o,r=t==="plugin"?`${e.slug}.php`:"style.css";return new d.SetOfBlocks([(0,s.gentranslation)(`Name of the ${t}`,a,r),(0,s.gentranslation)(`Url of the ${t}`,l,r),(0,s.gentranslation)(`Description of the ${t}`,n,r),(0,s.gentranslation)(`Author of the ${t}`,i,r),(0,s.gentranslation)(`Author URI of the ${t}`,u,r)])}0&&(module.exports={extractMainFileData,generateHeader,translationsHeaders});
1
+ "use strict";var P=Object.create;var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)c(e,n,{get:t[n],enumerable:!0})},h=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!M.call(e,r)&&r!==n&&c(e,r,{get:()=>t[r],enumerable:!(o=T(t,r))||o.enumerable});return e};var $=(e,t,n)=>(n=e!=null?P(H(e)):{},h(t||!e||!e.__esModule?c(n,"default",{value:e,enumerable:!0}):n,e)),w=e=>h(c({},"__esModule",{value:!0}),e);var L={};O(L,{extractMainFileData:()=>E,generateHeader:()=>U,getAuthorFromPackage:()=>y,translationsHeaders:()=>v});module.exports=w(L);var f=$(require("node:path")),g=require("gettext-merger"),p=require("../const.js"),A=require("../fs/fs.js"),u=require("../utils/common.js"),l=require("../utils/extractors.js"),k=require("./css.js"),b=require("./php.js");function x(e){const n=[{key:"slug",name:"Plugin/Theme slug",placeholder:"PLUGIN NAME"},{key:"author",name:"Author name",placeholder:"AUTHOR"},{key:"version",name:"Version",placeholder:""},{key:"email",name:"Author email",placeholder:"AUTHOR EMAIL"},{key:"xDomain",name:"Text domain",placeholder:"PLUGIN TEXTDOMAIN"}].filter(o=>!e[o.key]||e[o.key]===o.placeholder||o.key==="version"&&e[o.key]==="0.0.1");if(n.length>0){console.error(`
2
+ ! Missing required information for POT file header:
3
+ `);for(const o of n)console.error(` - ${o.name} is missing or has a default value (eg. version: 0.0.1, author: "AUTHOR <EMAIL>")`);return console.error(`
4
+ Please provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.`,`
5
+ For more information check the documentation at https://github.com/wp-blocks/makePot`),console.error(`
6
+ `),!1}return!0}function d(e){const t={name:"AUTHOR",email:"AUTHOR EMAIL"};if(!e)return t;if(typeof e=="string"){const n=e.match(/<([^>]+)>/),o=n?n[1].trim():void 0,r=e.match(/\(([^)]+)\)/),a=r?r[1].trim():void 0;let i=e.trim();return n&&(i=i.replace(n[0],"").trim()),r&&(i=i.replace(r[0],"").trim()),{name:i,email:o,website:a}}if(typeof e=="object")return{name:e.name,email:e.email,website:e.website}}function y(e){const t=["author","authors","contributors","maintainers"];for(const n of t)if(e[n]){let o;if(typeof e[n]=="string")o=d(e[n]);else if(typeof e[n]=="object"){for(const r of e[n])if(r&&(o=d(r),o))break}if(o?.name!=="AUTHOR"||o?.email!=="AUTHOR EMAIL")return o}return{name:"AUTHOR",email:"AUTHOR EMAIL"}}function R(e){const t=(0,u.getPkgJsonData)(e.paths?.cwd,"name","version","author","authors","contributors","maintainers"),n=`https://wordpress.org/support/${e.domain==="theme"?"themes":"plugins"}/${e.slug}`,o=y(t),r=e?.headers?.author||o?.name,a=o?.email,i=`${r} <${a}>`,m=f.default.basename(e.paths?.cwd||process.cwd())?.toLowerCase().replace(" ","-"),s=e.slug||m||(e.domain==="theme"?"THEME NAME":"PLUGIN NAME");return{...e.headers,author:r,authorString:i,slug:s,email:a,bugs:n,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||t.version||"0.0.1",language:"en",xDomain:e.headers?.textDomain||s}}async function U(e){const t=R(e),{name:n,version:o}=(0,u.getPkgJsonData)(p.modulePath,"name","version");return x(t)?{"Project-Id-Version":`${t.slug} ${t.version}`,"Report-Msgid-Bugs-To":t.authorString,"MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","content-type":`text/plain; charset=${(0,A.getEncodingCharset)(e.options?.charset)}`,"plural-forms":"nplurals=2; plural=(n!=1);","POT-Creation-Date":`${new Date().toISOString()}`,"PO-Revision-Date":`${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,"Last-Translator":t.authorString,"Language-Team":t.authorString,"X-Generator":`${n} ${o}`,Language:`${t.language}`,"X-Domain":t.xDomain}:(process.exit(1),null)}function E(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,b.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,k.extractCssThemeData)(e):console.log("No main file detected."),t}function v(e){const{domain:t,headers:n}=e,{name:o,description:r,author:a,authorUri:i,url:m}=n,s=t==="plugin"?`${e.slug}.php`:"style.css";return new g.SetOfBlocks([(0,l.buildBlock)(`Name of the ${t}`,o,[s]),(0,l.buildBlock)(`Url of the ${t}`,m,[s]),(0,l.buildBlock)(`Description of the ${t}`,r,[s]),(0,l.buildBlock)(`Author of the ${t}`,a,[s]),(0,l.buildBlock)(`Author URI of the ${t}`,i,[s])])}0&&(module.exports={extractMainFileData,generateHeader,getAuthorFromPackage,translationsHeaders});
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/extractors/headers.ts"],
4
+ "sourcesContent": ["import path from \"node:path\";\nimport { SetOfBlocks } from \"gettext-merger\";\nimport { boolean } from \"yargs\";\nimport type PackageI18n from \"../assets/package-i18n.js\";\nimport { modulePath } from \"../const.js\";\nimport { getEncodingCharset } from \"../fs/fs.js\";\nimport type { Args, I18nHeaders, PotHeaders } from \"../types.js\";\nimport { getPkgJsonData } from \"../utils/common.js\";\nimport { buildBlock } from \"../utils/extractors.js\";\nimport { extractCssThemeData } from \"./css.js\";\nimport { extractPhpPluginData } from \"./php.js\";\n\n/**\n * Checks if required fields are missing and logs a clear error message\n * @param {object} headerData - The header data to validate\n * @returns {boolean} - true if all required fields are present, false otherwise\n */\nfunction validateRequiredFields(headerData: I18nHeaders): boolean {\n\tconst requiredFields = [\n\t\t{ key: \"slug\", name: \"Plugin/Theme slug\", placeholder: \"PLUGIN NAME\" },\n\t\t{ key: \"author\", name: \"Author name\", placeholder: \"AUTHOR\" },\n\t\t{ key: \"version\", name: \"Version\", placeholder: \"\" },\n\t\t{ key: \"email\", name: \"Author email\", placeholder: \"AUTHOR EMAIL\" },\n\t\t{ key: \"xDomain\", name: \"Text domain\", placeholder: \"PLUGIN TEXTDOMAIN\" },\n\t];\n\n\tconst missingFields = requiredFields.filter(\n\t\t(field) =>\n\t\t\t!headerData[field.key] ||\n\t\t\theaderData[field.key] === field.placeholder ||\n\t\t\t(field.key === \"version\" && headerData[field.key] === \"0.0.1\"),\n\t);\n\n\tif (missingFields.length > 0) {\n\t\tconsole.error(\"\\n! Missing required information for POT file header:\\n\");\n\n\t\tfor (const field of missingFields) {\n\t\t\tconsole.error(\n\t\t\t\t` - ${field.name} is missing or has a default value (eg. version: 0.0.1, author: \"AUTHOR <EMAIL>\")`,\n\t\t\t);\n\t\t}\n\n\t\tconsole.error(\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.\",\n\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\n\t\t);\n\n\t\tconsole.error(\"\\n\");\n\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Extract author data from package.json author field and return an array of strings\n * the original field is a string and it's longer form is \"Your Name <email@example.com> (https://example.com)\"\n *\n * @returns an object with name, email, and website\n * @param authorData\n */\nfunction extractAuthorData(authorData: string | object): {\n\tname: string;\n\temail?: string;\n\twebsite?: string;\n} {\n\t// Default result with placeholder values\n\tconst defaultResult = { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\n\n\t// Return default if no author data\n\tif (!authorData) {\n\t\treturn defaultResult;\n\t}\n\n\t// Handle string format: \"Barney Rubble <barney@npmjs.com> (http://barnyrubble.npmjs.com/)\"\n\tif (typeof authorData === \"string\") {\n\t\t// Try to extract email with regex\n\t\tconst emailMatch = authorData.match(/<([^>]+)>/);\n\t\tconst email = emailMatch ? emailMatch[1].trim() : undefined;\n\n\t\t// Try to extract website with regex\n\t\tconst websiteMatch = authorData.match(/\\(([^)]+)\\)/);\n\t\tconst website = websiteMatch ? websiteMatch[1].trim() : undefined;\n\n\t\t// Extract name by removing email and website parts if present\n\t\tlet name = authorData.trim();\n\t\tif (emailMatch) name = name.replace(emailMatch[0], \"\").trim();\n\t\tif (websiteMatch) name = name.replace(websiteMatch[0], \"\").trim();\n\n\t\treturn { name, email, website };\n\t}\n\tif (typeof authorData === \"object\") {\n\t\t// Handle object format: { name: \"Barney Rubble\", email: \"barney@npmjs.com\", website: \"http://barnyrubble.npmjs.com/\" }\n\t\treturn {\n\t\t\tname: authorData.name,\n\t\t\temail: authorData.email,\n\t\t\twebsite: authorData.website,\n\t\t};\n\t}\n}\n\n/**\n * Gets author data by checking multiple possible locations in package.json\n *\n * @param pkgJsonData The package.json data object\n * @returns Author data with name, email and website\n */\nexport function getAuthorFromPackage(pkgJsonData: PackageI18n): {\n\tname: string;\n\temail?: string;\n\twebsite?: string;\n} {\n\t// Check multiple possible locations for author information\n\tconst locations = [\n\t\t\"author\", // Standard author field\n\t\t\"authors\", // Some packages use authors (plural)\n\t\t\"contributors\", // Try contributors if no author\n\t\t\"maintainers\", // Try maintainers as last resort\n\t];\n\n\t// Try each location in order\n\tfor (const location of locations) {\n\t\tif (pkgJsonData[location]) {\n\t\t\tlet authorData: {\n\t\t\t\tname: string;\n\t\t\t\temail?: string;\n\t\t\t\twebsite?: string;\n\t\t\t};\n\t\t\tif (typeof pkgJsonData[location] === \"string\") {\n\t\t\t\tauthorData = extractAuthorData(pkgJsonData[location]);\n\t\t\t} else if (typeof pkgJsonData[location] === \"object\") {\n\t\t\t\tfor (const author of pkgJsonData[location]) {\n\t\t\t\t\tif (!author) continue;\n\t\t\t\t\tauthorData = extractAuthorData(author);\n\t\t\t\t\tif (authorData) break;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tauthorData?.name !== \"AUTHOR\" ||\n\t\t\t\tauthorData?.email !== \"AUTHOR EMAIL\"\n\t\t\t) {\n\t\t\t\treturn authorData;\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no valid author data found in any location\n\treturn { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\n}\n\n/**\n * This function consolidates the user headers data into a single object\n *\n * @param args the command line arguments\n * @return {Record<string, string>} the consolidated headers data object\n */\nfunction consolidateUserHeaderData(args: Args): I18nHeaders {\n\tconst pkgJsonData = getPkgJsonData(\n\t\targs.paths?.cwd,\n\t\t\"name\",\n\t\t\"version\",\n\t\t\"author\",\n\t\t\"authors\",\n\t\t\"contributors\",\n\t\t\"maintainers\",\n\t) as Record<[keyof PackageI18n], string>;\n\n\tconst bugs = `https://wordpress.org/support/${args.domain === \"theme\" ? \"themes\" : \"plugins\"}/${args.slug}`;\n\n\t// get author data from package.json\n\tconst pkgAuthor = getAuthorFromPackage(pkgJsonData);\n\t// Use command line author name if provided, fallback to package.json\n\tconst authorName = args?.headers?.author || pkgAuthor?.name;\n\tconst email = pkgAuthor?.email;\n\t// this is the author with email address in this format: author <email>\n\tconst authorString = `${authorName} <${email}>`;\n\t// get the current directory name as slug\n\tconst currentDir = path\n\t\t.basename(args.paths?.cwd || process.cwd())\n\t\t?.toLowerCase()\n\t\t.replace(\" \", \"-\");\n\tconst slug =\n\t\targs.slug ||\n\t\tcurrentDir ||\n\t\t(args.domain === \"theme\" ? \"THEME NAME\" : \"PLUGIN NAME\");\n\n\treturn {\n\t\t...args.headers,\n\t\tauthor: authorName,\n\t\tauthorString: authorString, // this is the author with email address in this format: author <email>\n\t\tslug,\n\t\temail,\n\t\tbugs,\n\t\tlicense: args.headers?.license || \"gpl-2.0 or later\",\n\t\tversion: args.headers?.version || pkgJsonData.version || \"0.0.1\",\n\t\tlanguage: \"en\",\n\t\txDomain: args.headers?.textDomain || slug,\n\t};\n}\n\n/**\n * Generates a POT header for a given set of arguments.\n * https://developer.wordpress.org/cli/commands/i18n/make-pot/\n * String that should be added as a comment to the top of the resulting POT file.\n * By default, a copyright comment is added for WordPress plugins and themes in the following manner:\n * `\n * Copyright (C) 2018 Example Plugin Author\n * This file is distributed under the same license as the Example Plugin package.\n * `\n * If a plugin or theme specifies a license in their main plugin file or stylesheet,\n * the comment looks like this: Copyright (C) 2018 Example Plugin Author This file is distributed under the GPLv2.\n *\n * @param args - The argument object containing the headers and their values.\n * @return The generated POT header.\n */\nexport async function generateHeader(args: Args) {\n\t// Consolidate the user headers data into a single object\n\tconst headerData = consolidateUserHeaderData(args);\n\n\t// the makepot module name and version\n\tconst { name, version } = getPkgJsonData(modulePath, \"name\", \"version\");\n\n\t// Validate required fields - exit early if validation fails\n\tif (!validateRequiredFields(headerData)) {\n\t\tprocess.exit(1); // Exit with error code\n\t\treturn null; // This is never reached but helps with TypeScript\n\t}\n\n\tconst header = {\n\t\t\"Project-Id-Version\": `${headerData.slug} ${headerData.version}`,\n\t\t\"Report-Msgid-Bugs-To\": headerData.authorString,\n\t\t\"MIME-Version\": \"1.0\",\n\t\t\"Content-Transfer-Encoding\": \"8bit\",\n\t\t\"content-type\": `text/plain; charset=${getEncodingCharset(args.options?.charset)}`,\n\t\t\"plural-forms\": \"nplurals=2; plural=(n!=1);\",\n\t\t\"POT-Creation-Date\": `${new Date().toISOString()}`,\n\t\t\"PO-Revision-Date\": `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,\n\t\t\"Last-Translator\": headerData.authorString,\n\t\t\"Language-Team\": headerData.authorString,\n\t\t\"X-Generator\": `${name} ${version}`,\n\t\tLanguage: `${headerData.language}`,\n\t\t\"X-Domain\": headerData.xDomain,\n\t};\n\n\treturn header;\n}\n\n/**\n * Extracts main file data based on the given arguments.\n *\n * @param {Args} args - The arguments for extracting the main file data.\n * @return {Record<string, string>} The extracted main file data.\n */\nexport function extractMainFileData(args: Args): Record<string, string> {\n\tlet extractedData = {};\n\tif ([\"plugin\", \"block\", \"generic\"].includes(args.domain)) {\n\t\textractedData = extractPhpPluginData(args);\n\t} else if ([\"theme\", \"theme-block\"].includes(args.domain)) {\n\t\textractedData = extractCssThemeData(args);\n\t} else {\n\t\tconsole.log(\"No main file detected.\");\n\t}\n\n\treturn extractedData;\n}\n\n/**\n * Generate translation strings based on the given type and headers.\n *\n * @return {Record<string, string>} the generated translation strings\n * @param args\n */\nexport function translationsHeaders(args: Args): SetOfBlocks {\n\tconst { domain, headers } = args as Args;\n\tconst { name, description, author, authorUri, url } = headers as {\n\t\t[key in PotHeaders]: string;\n\t};\n\n\t// the main file is the plugin main php file or the css file\n\tconst fakePath = domain === \"plugin\" ? `${args.slug}.php` : \"style.css\";\n\n\treturn new SetOfBlocks([\n\t\tbuildBlock(`Name of the ${domain}`, name, [fakePath]),\n\t\tbuildBlock(`Url of the ${domain}`, url, [fakePath]),\n\t\tbuildBlock(`Description of the ${domain}`, description, [fakePath]),\n\t\tbuildBlock(`Author of the ${domain}`, author, [fakePath]),\n\t\tbuildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]),\n\t]);\n}\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;AAOrC,SAAS,uBAAuB,YAAkC;AACjE,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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AAAA,EACrC;AAEA,SAAO;AACR;AAQO,SAAS,oBAAoB,MAAyB;AAC5D,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAC5B,QAAM,EAAE,MAAM,aAAa,QAAQ,WAAW,IAAI,IAAI;AAKtD,QAAM,WAAW,WAAW,WAAW,GAAG,KAAK,IAAI,SAAS;AAE5D,SAAO,IAAI,kCAAY;AAAA,QACtB,8BAAW,eAAe,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC;AAAA,QACpD,8BAAW,cAAc,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC;AAAA,QAClD,8BAAW,sBAAsB,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC;AAAA,QAClE,8BAAW,iBAAiB,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC;AAAA,QACxD,8BAAW,qBAAqB,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC;AAAA,EAChE,CAAC;AACF;",
6
+ "names": ["path"]
7
+ }
@@ -1 +1 @@
1
- "use strict";var k=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var b=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},l=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of j(n))!d.call(e,o)&&o!==t&&c(e,o,{get:()=>n[o],enumerable:!(s=u(n,o))||s.enumerable});return e};var g=(e,n,t)=>(t=e!=null?k(J(e)):{},l(n||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>l(c({},"__esModule",{value:!0}),e);var F={};b(F,{extractPackageJson:()=>w,getJsonComment:()=>x,parseJsonCallback:()=>C,parseJsonFile:()=>h});module.exports=S(F);var m=g(require("node:fs")),f=g(require("node:path")),a=require("../const.js"),r=require("./schema.js"),p=require("./utils.js");async function h(e){return await r.JsonSchemaExtractor.fromString(e.fileContent,{file:e.filename,schema:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonSource:r.JsonSchemaExtractor.blockJsonSource,schemaFallback:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonFallback:r.JsonSchemaExtractor.blockJsonFallback,addReferences:!0})??{}}function y(e){switch(e){case"block.json":return a.blockJson;case"theme.json":return a.themeJson;default:return{}}}function x(e,n){const t=y(n);return e in Object.values(t)?t[e]:e}function w(e){const n=a.pkgJsonHeaders,t={},s=e.paths.cwd?f.default.join(e.paths.cwd,"package.json"):"package.json";if(m.default.existsSync(s)){const o=JSON.parse(m.default.readFileSync(s,"utf8"));for(const i of Object.keys(n))i in o&&(t[i]=o[i])}return t}async function C(e,n,t){const s=await h({fileContent:e,filename:t,filepath:n});return(0,p.yieldParsedData)(s,t,f.default.join(n,t))}0&&(module.exports={extractPackageJson,getJsonComment,parseJsonCallback,parseJsonFile});
1
+ "use strict";var f=Object.create;var s=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var u=(e,o)=>{for(var n in o)s(e,n,{get:o[n],enumerable:!0})},l=(e,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of h(o))!b.call(e,r)&&r!==n&&s(e,r,{get:()=>o[r],enumerable:!(a=k(o,r))||a.enumerable});return e};var S=(e,o,n)=>(n=e!=null?f(p(e)):{},l(o||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),j=e=>l(s({},"__esModule",{value:!0}),e);var J={};u(J,{parseJsonCallback:()=>d,parseJsonFile:()=>m});module.exports=j(J);var c=S(require("node:path")),i=require("../utils/extractors.js"),t=require("./schema.js");async function m(e){const o=e.filename==="theme.json",n={url:o?t.JsonSchemaExtractor.themeJsonSource:t.JsonSchemaExtractor.blockJsonSource,fallback:o?t.JsonSchemaExtractor.themeJsonFallback:t.JsonSchemaExtractor.blockJsonFallback};if(!n.url||!n.fallback){console.error("Schema URL or fallback not provided");return}return await t.JsonSchemaExtractor.parse(e.fileContent,n,{file:e.filename,addReferences:!0})??[]}async function d(e,o,n){const a=await m({fileContent:e,filename:n});return(0,i.yieldParsedData)(a,n,c.default.join(o,n))}0&&(module.exports={parseJsonCallback,parseJsonFile});
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1 @@
1
+ "use strict";var d=Object.create;var e=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var y=(s,t)=>{for(var o in t)e(s,o,{get:t[o],enumerable:!0})},i=(s,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of m(t))!j.call(s,n)&&n!==o&&e(s,n,{get:()=>t[n],enumerable:!(r=k(t,n))||r.enumerable});return s};var p=(s,t,o)=>(o=s!=null?d(J(s)):{},i(t||!s||!s.__esModule?e(o,"default",{value:s,enumerable:!0}):o,s)),h=s=>i(e({},"__esModule",{value:!0}),s);var u={};y(u,{extractPackageJson:()=>l});module.exports=h(u);var c=p(require("node:fs")),f=p(require("node:path")),g=require("../const.js");function l(s){const t=g.pkgJsonHeaders,o={},r=s.paths.cwd?f.default.join(s.paths.cwd,"package.json"):"package.json";if(c.default.existsSync(r)){const n=JSON.parse(c.default.readFileSync(r,"utf8"));for(const a of Object.keys(t))a in n&&(o[a]=`${n[a]}`)}return o}0&&(module.exports={extractPackageJson});
@@ -0,0 +1,7 @@
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;AACjB,mBAA+B;AAWxB,SAAS,mBAAmB,MAAoC;AACtE,QAAM,SAAS;AACf,QAAM,cAAsC,CAAC;AAE7C,QAAM,kBAAkB,KAAK,MAAM,MAChC,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,cAAc,IACxC;AAKH,MAAI,eAAAC,QAAG,WAAW,eAAe,GAAG;AACnC,UAAM,cAAc,KAAK,MAAM,eAAAA,QAAG,aAAa,iBAAiB,MAAM,CAAC;AACvE,eAAW,SAAS,OAAO,KAAK,MAAM,GAAG;AAExC,UAAI,SAAS,aAAa;AACzB,oBAAY,KAAK,IAAI,GAAG,YAAY,KAAK,CAAC;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
+ "names": ["path", "fs"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var h=Object.create;var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var e in t)s(n,e,{get:t[e],enumerable:!0})},f=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!R.call(n,o)&&o!==e&&s(n,o,{get:()=>t[o],enumerable:!(i=P(t,o))||i.enumerable});return n};var g=(n,t,e)=>(e=n!=null?h(x(n)):{},f(t||!n||!n.__esModule?s(e,"default",{value:n,enumerable:!0}):e,n)),B=n=>f(s({},"__esModule",{value:!0}),n);var S={};k(S,{extractPhpPluginData:()=>F,parsePHPFile:()=>a});module.exports=B(S);var l=g(require("node:fs")),m=g(require("node:path")),u=require("../const.js"),p=require("./utils.js");function F(n){let t={};const e=m.default.join(n.paths.cwd,`${n.slug}.php`);if(l.default.existsSync(e)){const i=l.default.readFileSync(e,"utf8");return t=a(i),console.log("Plugin file detected."),console.log(`Plugin file: ${e}`),n.domain="plugin",t}else console.log("Plugin file not found."),console.log(`Missing Plugin filename: ${e}`);return{}}function a(n){const t=n.match(/\/\*\*([\s\S]*?)\*\//);if(t&&t[1]){const i=t[1].split(`
2
- `),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r&&r[1]&&r[2]){const c=(0,p.getKeyByValue)(u.pluginHeaders,r[1].trim());if(c===void 0)continue;o[c]=r[2].trim()}}return o}return{}}0&&(module.exports={extractPhpPluginData,parsePHPFile});
1
+ "use strict";var h=Object.create;var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var k=(t,n)=>{for(var e in n)s(t,e,{get:n[e],enumerable:!0})},f=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of y(n))!R.call(t,o)&&o!==e&&s(t,o,{get:()=>n[o],enumerable:!(i=P(n,o))||i.enumerable});return t};var g=(t,n,e)=>(e=t!=null?h(x(t)):{},f(n||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t)),B=t=>f(s({},"__esModule",{value:!0}),t);var S={};k(S,{extractPhpPluginData:()=>F,parsePHPFile:()=>a});module.exports=B(S);var c=g(require("node:fs")),m=g(require("node:path")),u=require("../const.js"),p=require("../utils/extractors.js");function F(t){let n={};const e=m.default.join(t.paths.cwd,`${t.slug}.php`);if(c.default.existsSync(e)){const i=c.default.readFileSync(e,"utf8");return n=a(i),console.log(`\u{1F535} Plugin file detected. (${e})`),t.domain="plugin",n}return console.log("Plugin file not found."),console.log(`Missing Plugin filename: ${e}`),{}}function a(t){const n=t.match(/\/\*\*([\s\S]*?)\*\//);if(n?.[1]&&n){const i=n[1].split(`
2
+ `),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r&&r?.[1]&&r[2]){const l=(0,p.getKeyByValue)(u.pluginHeaders,r[1].trim());if(l===void 0)continue;o[l]=r[2].trim()}}return o}return{}}0&&(module.exports={extractPhpPluginData,parsePHPFile});
@@ -0,0 +1,7 @@
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;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA8B;AAE9B,wBAA8B;AAEvB,SAAS,qBAAqB,MAAoC;AACxE,MAAI,WAAmC,CAAC;AACxC,QAAM,gBAAgB,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,GAAG,KAAK,IAAI,MAAM;AAElE,MAAI,eAAAC,QAAG,WAAW,aAAa,GAAG;AACjC,UAAM,cAAc,eAAAA,QAAG,aAAa,eAAe,MAAM;AACzD,eAAW,aAAa,WAAW;AAEnC,YAAQ,IAAI,oCAA6B,aAAa,GAAG;AAGzD,SAAK,SAAS;AAEd,WAAO;AAAA,EACR;AAEA,UAAQ,IAAI,wBAAwB;AACpC,UAAQ,IAAI,4BAA4B,aAAa,EAAE;AAEvD,SAAO,CAAC;AACT;AAQO,SAAS,aAAa,YAA4C;AACxE,QAAM,QAAQ,WAAW,MAAM,sBAAsB;AAErD,MAAI,QAAQ,CAAC,KAAK,OAAO;AACxB,UAAM,eAAe,MAAM,CAAC;AAC5B,UAAM,QAAQ,aAAa,MAAM,IAAI;AAErC,UAAM,aAAqC,CAAC;AAE5C,eAAW,QAAQ,OAAO;AACzB,YAAM,gBAAgB,KAAK,MAAM,0BAA0B;AAE3D,UAAI,CAAC,eAAe;AACnB;AAAA,MACD;AAGA,UAAI,gBAAgB,CAAC,KAAK,cAAc,CAAC,GAAG;AAE3C,cAAM,aAAS,iCAAc,4BAAe,cAAc,CAAC,EAAE,KAAK,C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