@wp-blocks/make-pot 1.3.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 @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:
@@ -27,7 +53,7 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
27
53
  - `sourceDirectory` (optional): Specifies the source directory of your plugin or theme. If not provided, the `.pot` file root will be the source directory.
28
54
  - `destination` (optional): Specifies the destination directory where the `.pot` file will be generated. If not provided, the `.pot` file will be created in the source directory.
29
55
 
30
- #### Options:
56
+ #### Make Pot Options:
31
57
 
32
58
  - `--version`: Displays the version number of `make-pot`.
33
59
  - `-h`, `--help`: Displays help information.
@@ -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.
@@ -63,6 +129,100 @@ To do so, create a `build:makepot` action in your `package.json` with the follow
63
129
  "build:makepot": "npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]"
64
130
  }
65
131
  ```
132
+ ---
133
+
134
+ # Make JSON
135
+
136
+ ### Why JSON Translation for WordPress JavaScript?
137
+
138
+ #### Overview
139
+ WordPress 5.0 introduced Gutenberg, a JavaScript-heavy editor. This shifted much of the internationalization (I18N) work from the server to the client side. While functions like `wp_localize_script()` were used before, Gutenberg required a more robust solution.
140
+
141
+ #### JavaScript Localization Functions
142
+ WordPress 5.0 introduced the `wp-i18n` JavaScript package, offering localization functions (`__()`, `_x()`, `_n()`, `_nx()`, `sprintf()`) similar to their PHP counterparts, enabling seamless I18N in JavaScript.
143
+
144
+ #### Loading Translations
145
+ To fully internationalize a plugin or theme, you must load translations using `wp_set_script_translations()`, which requires:
146
+ 1. Script handle (e.g., `my-plugin-script`)
147
+ 2. Text domain (e.g., `my-plugin`)
148
+ 3. Optional: Path to translation files (if not hosted on WordPress.org)
149
+
150
+ #### JSON Translation Files
151
+ Unlike traditional PO/MO files, JavaScript translations use JSON. This format is easily readable in JavaScript and compatible with the Jed JavaScript gettext library, used by the `wp-i18n` package. WordPress.org generates these JSON files automatically, but custom ones can be created if needed.
152
+
153
+ ## JSON Utility args
154
+
155
+ - `source`: (positional) the source directory of your plugin or theme translations (e.g. `languages`).
156
+ - `destination`: (positional and optional) The destination directory where the `.json` file will be generated. If not provided, the `.json` file will be created in the source directory.
157
+ - `--scriptName`: The name of the script that needs this translation file.
158
+ - `--allowedFormats`: The allowed formats of the translation file (e.g. `js` or `tsx`).
159
+ - `--purge`: if enabled, removes the existing translation file. Otherwise, the old translation file will be merged with the new.
160
+ - `--prettyPrint`: Pretty prints the translation file.
161
+ - `--debug`: Enables debug mode.
162
+
163
+ ## How to Generate Json translations
164
+
165
+ #### Build the json translations file
166
+
167
+ First, build the translation pot file using `makepot` (no matter with this module or not) and then translate it into the different languages.
168
+
169
+ translate the pot file into your language and then run `makejson`:
170
+
171
+ ```bash
172
+ npx makejson
173
+ # OR
174
+ npx @wp-blocks/make-pot --makejson,
175
+ ```
176
+ It Will create a file for each po file in the `languages` directory with the md5 hash with the name of the file.
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.
178
+ This is crucial because the md5 hash has to be the same as the path of the script file.
179
+
180
+ ## Register the javascript block translations
181
+
182
+ ```php
183
+ <?php
184
+ /**
185
+ * Loads the plugin text domain for translation.
186
+ */
187
+ function my_i18n() {
188
+ load_plugin_textdomain( 'my-text-domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
189
+ }
190
+ add_action( 'init', 'my_i18n' );
191
+
192
+ /**
193
+ * Registers the block using the metadata loaded from the `block.json` file.
194
+ */
195
+ add_action('init', function () {
196
+ register_block_type( dirname( plugin_basename( __FILE__ ) ) . '/build', [
197
+ "script" => "my-vendor-script",
198
+ "viewScript" => "my-frontend-script",
199
+ "editorScript" => "my-editor-script",
200
+ ]);
201
+ });
202
+
203
+ /**
204
+ * Registers the block using the metadata loaded from the `block.json` file.
205
+ */
206
+ function my_register_block_type() {
207
+
208
+ $fe_assets = include dirname( __FILE__ ) . '/build/my-frontend-script.asset.php';
209
+
210
+ wp_register_script(
211
+ 'my-frontend-script',
212
+ VSGE_MB_PLUGIN_URL . 'build/frontend.js',
213
+ $fe_assets['dependencies'],
214
+ $fe_assets['version']
215
+ );
216
+
217
+ // 1 - the name of the hook used to register the script
218
+ // 2 - the text domaim of the block
219
+ // 3 - the path to the translations directory
220
+ wp_set_script_translations( 'my-frontend-script', 'my-text-domain', plugin_dir_url(__FILE__) . '/languages' );
221
+
222
+ ...
223
+ }
224
+ add_action( 'init', 'my_register_block_type' );
225
+ ```
66
226
 
67
227
  ### Credits
68
228
 
@@ -70,6 +230,10 @@ This module is heavily inspired by the original `makepot` command from [WP-CLI](
70
230
  Special thanks to the maintainers in particular [Swissspidy](https://github.com/swissspidy) which
71
231
  has been very helpful with suggestions and tips on how to rebuild `make-pot`.
72
232
 
233
+ #### Useful links
234
+ - https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
235
+ - https://pascalbirchler.com/internationalization-in-wordpress-5-0/
236
+
73
237
  Feel free to contribute or report issues on [GitHub](https://github.com/example/example).
74
238
 
75
239
  This tool is licensed under the [GNU General Public License v3](LICENSE).
@@ -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"};
@@ -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 m=(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)),f=e=>n(o({},"__esModule",{value:!0}),e);var S={};m(S,{getArgs:()=>h});module.exports=f(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"},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 @@
1
+ "use strict";var c=Object.create;var s=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)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 g(t))!y.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(i=f(t,o))||i.enumerable});return e};var n=(e,t,r)=>(r=e!=null?c(u(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")),d=require("yargs/helpers"),l=require("./parseCli");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});
@@ -1 +1 @@
1
- "use strict";var y=Object.create;var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},a=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!D.call(t,s)&&s!==n&&p(t,s,{get:()=>e[s],enumerable:!(i=g(e,s))||i.enumerable});return t};var u=(t,e,n)=>(n=t!=null?y(A(t)):{},a(e||!t||!t.__esModule?p(n,"default",{value:t,enumerable:!0}):n,t)),_=t=>a(p({},"__esModule",{value:!0}),t);var j={};P(j,{parseCliArgs:()=>T});module.exports=_(j);var r=u(require("node:fs")),o=u(require("node:path")),b=u(require("node:process")),d=require("../const.js"),c=require("../utils/common.js");function w(t="/",e="default"){const n=t;try{return(0,r.accessSync)(o.join(n,`${e}.php`),r.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${n} does not contain a ${e}.php file`)}try{return(0,r.accessSync)(o.join(n,"style.css"),r.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${n} does not contain a style.css file`)}return n.includes(`wp-content${o.sep}themes`)?"theme":n.includes(`wp-content${o.sep}plugins`)?"plugin":"generic"}function T(t){const e=typeof t._[0]=="string"?t._[0]:".",n=typeof t._[1]=="string"?t._[1]:".",i=b.cwd(),s=t.slug&&typeof t.slug=="string"?t.slug:o.basename(o.resolve(i,e)),l=o.relative(i,e),f=o.relative(i,n),h=t?.domain??w(o.resolve(l),s),m={slug:s,domain:h,paths:{cwd:l,out:f},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:!!t.silent,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 m.paths.root=t.root?String(t.root):void 0,m}0&&(module.exports={parseCliArgs});
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});
package/lib/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var 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,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of A(r))!J.call(o,s)&&s!==e&&n(o,s,{get:()=>r[s],enumerable:!(a=l(r,s))||a.enumerable});return o};var m=(o,r,e)=>(e=o!=null?d(y(o)):{},b(r||!o||!o.__esModule?n(e,"default",{value:o,enumerable:!0}):e,o));var t=m(require("node:process")),c=m(require("yargs")),i=require("yargs/helpers"),p=require("./cli/getArgs.js"),f=require("./cli/getJsonArgs"),g=m(require("./jsonCommand")),k=m(require("./potCommand"));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/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,b=Object.prototype.hasOwnProperty;var f=(t,m)=>{for(var s in m)_(t,s,{get:m[s],enumerable:!0})},n=(t,m,s,o)=>{if(m&&typeof m=="object"||typeof m=="function")for(let e of l(m))!b.call(t,e)&&e!==s&&_(t,e,{get:()=>m[e],enumerable:!(o=p(m,e))||o.enumerable});return t};var i=(t,m,s)=>(s=t!=null?c(u(t)):{},n(m||!t||!t.__esModule?_(s,"default",{value:t,enumerable:!0}):s,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var T={};f(T,{DEFAULT_EXCLUDED_PATH:()=>E,allowedFiles:()=>F,blockJson:()=>k,i18nFunctions:()=>J,pkgJsonHeaders:()=>w,pluginHeaders:()=>H,themeHeaders:()=>D,themeJson:()=>j});module.exports=h(T);var d=i(require("./assets/block-i18n.js")),x=i(require("./assets/package-i18n.js")),g=i(require("./assets/theme-i18n.js")),a=i(require("./assets/wp-plugin-i18n.js")),r=i(require("./assets/wp-theme-i18n.js"));const j=g.default,k=d.default,w=x.default,H=a.default,D=r.default,E=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],F=["php","js","jsx","ts","tsx","mjs","cjs"],J={__:["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,allowedFiles,blockJson,i18nFunctions,pkgJsonHeaders,pluginHeaders,themeHeaders,themeJson});
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 +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 u=Object.create;var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},l=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!j.call(e,r)&&r!==o&&i(e,r,{get:()=>t[r],enumerable:!(n=x(t,r))||n.enumerable});return e};var a=(e,t,o)=>(o=e!=null?u(T(e)):{},l(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),B=e=>l(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 n=m.default.readFileSync(o,"utf8"),r=(0,p.getCommentBlock)(n);if(t=(0,y.extractFileData)(r),"Theme Name"in t){console.log(`\u{1F535} Theme stylesheet detected. ${o}`),e.domain="theme";const c={};for(const s of Object.entries(t))if(s?.[0]&&s[1]){const f=(0,g.getKeyByValue)(d.themeHeaders,s[0].trim());if(f===void 0)continue;c[f]=s[1].trim()}return c}}else console.log(`Theme stylesheet not found in ${o}`);return{}}0&&(module.exports={extractCssThemeData});
@@ -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 m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of b(t))!y.call(e,r)&&r!==o&&m(e,r,{get:()=>t[r],enumerable:!(n=T(t,r))||n.enumerable});return e};var H=e=>P(m({},"__esModule",{value:!0}),e);var R={};I(R,{extractMainFileData:()=>x,generateHeader:()=>U,translationsHeaders:()=>E});module.exports=H(R);var d=require("gettext-merger"),f=require("../fs/fs"),u=require("../utils/common"),g=require("./css.js"),p=require("./php.js"),l=require("./utils.js");function M(e){const o=[{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:"domain",name:"Text domain",placeholder:"PLUGIN TEXTDOMAIN"}].filter(n=>!e[n.key]||e[n.key]===n.placeholder||n.key==="version"&&e[n.key]==="0.0.1");if(o.length>0){console.error(`
2
+ ! Missing required information for POT file header:
3
+ `);for(const n of o)console.error(` - ${n.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 h(e){const t={name:"AUTHOR",email:"AUTHOR EMAIL"};if(!e)return t;if(typeof e=="string"){const o=e.match(/<([^>]+)>/),n=o?o[1].trim():void 0,r=e.match(/\(([^)]+)\)/),a=r?r[1].trim():void 0;let i=e.trim();return o&&(i=i.replace(o[0],"").trim()),r&&(i=i.replace(r[0],"").trim()),{name:i,email:n,website:a}}if(typeof e=="object")return{name:e.name,email:e.email,website:e.website}}function O(e){const t=["author","authors","contributors","maintainers"];for(const o of t)if(e[o]){let n;if(typeof e[o]=="string")n=h(e[o]);else if(typeof e[o]=="object"){for(const r of e[o])if(r&&(n=h(r),n))break}if(n?.name!=="AUTHOR"||n?.email!=="AUTHOR EMAIL")return n}return{name:"AUTHOR",email:"AUTHOR EMAIL"}}function $(e){const{author:t,textDomain:o}=e.headers,n=(0,u.getPkgJsonData)("name","version","author","authors","contributors","maintainers"),r=`https://wordpress.org/support/${e.domain==="theme"?"themes":"plugins"}/${e.slug}`,a=O(n),i=e.headers?.author||a?.name,c=a?.email,s=`${t} <${c}>`,A=process.cwd().split("/").pop()?.toLowerCase().replace(" ","-"),k=e.slug||A||(e.domain==="theme"?"THEME NAME":"PLUGIN NAME");return{...e.headers,author:i,authorString:s,slug:k,email:c,bugs:r,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||n.version||"0.0.1",language:"en",domain:e.headers?.textDomain||e.headers?.slug||"PLUGIN TEXTDOMAIN",xDomain:o}}async function U(e){const t=$(e),{name:o,version:n}=(0,u.getPkgJsonData)("name","version");if(!M(t))return process.exit(1),null;const r={"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,f.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":`${o} ${n}`,Language:`${t.language}`};return t.xDomain&&(r["X-Domain"]=t.xDomain),r}function x(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,p.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,g.extractCssThemeData)(e):console.log("No main file detected."),t}function E(e){const{domain:t,headers:o}=e,{name:n,description:r,author:a,authorUri:i,url:c}=o,s=t==="plugin"?`${e.slug}.php`:"style.css";return new d.SetOfBlocks([(0,l.gentranslation)(`Name of the ${t}`,n,s),(0,l.gentranslation)(`Url of the ${t}`,c,s),(0,l.gentranslation)(`Description of the ${t}`,r,s),(0,l.gentranslation)(`Author of the ${t}`,a,s),(0,l.gentranslation)(`Author URI of the ${t}`,i,s)])}0&&(module.exports={extractMainFileData,generateHeader,translationsHeaders});
@@ -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 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,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of j(n))!d.call(e,s)&&s!==t&&c(e,s,{get:()=>n[s],enumerable:!(o=u(n,s))||o.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 C={};b(C,{extractPackageJson:()=>F,getJsonComment:()=>x,parseJsonCallback:()=>w,parseJsonFile:()=>h});module.exports=S(C);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 F(e){const n=a.pkgJsonHeaders,t={},o=e.paths.cwd?f.default.join(e.paths.cwd,"package.json"):"package.json";if(m.default.existsSync(o)){const s=JSON.parse(m.default.readFileSync(o,"utf8"));for(const i of Object.keys(n))i in s&&(t[i]=s[i])}return t}async function w(e,n,t){const o=await h({fileContent:e,filename:t,filepath:n});return(0,p.yieldParsedData)(o,t,f.default.join(n,t))}0&&(module.exports={extractPackageJson,getJsonComment,parseJsonCallback,parseJsonFile});
@@ -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")),p=require("../const.js"),u=require("./utils.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]){const i=n[1].split(`
2
+ `),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r?.[1]&&r[2]){const l=(0,u.getKeyByValue)(p.pluginHeaders,r[1].trim());if(l===void 0)continue;o[l]=r[2].trim()}}return o}return{}}0&&(module.exports={extractPhpPluginData,parsePHPFile});
@@ -1 +1,4 @@
1
- "use strict";var u=Object.create;var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var b=(a,t)=>{for(var e in t)n(a,e,{get:t[e],enumerable:!0})},h=(a,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!d.call(a,r)&&r!==e&&n(a,r,{get:()=>t[r],enumerable:!(s=p(t,r))||s.enumerable});return a};var o=(a,t,e)=>(e=a!=null?u(S(a)):{},h(t||!a||!a.__esModule?n(e,"default",{value:a,enumerable:!0}):e,a)),g=a=>h(n({},"__esModule",{value:!0}),a);var j={};b(j,{JsonSchemaExtractor:()=>y});module.exports=g(j);var l=o(require("axios")),I=o(require("../assets/block-i18n.js")),k=o(require("../assets/theme-i18n.js"));class y{static schemaCache={};static themeJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json";static themeJsonFallback=k;static blockJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json";static blockJsonFallback=I;static async loadSchema(t,e){if(this.schemaCache.url)return this.schemaCache.url;try{const s=await l.default.get(t);return this.schemaCache.url=s.data,s.data}catch{console.error(`Failed to load schema from ${t}. Using fallback.`);const r=e;return this.schemaCache.url=r,r}}static async fromString(t,e){const s=await this.loadSchema(e.schema,e.schemaFallback);if(!s){console.error("Failed to load schema.");return}const r=JSON.parse(t);if(r===null){console.error("Could not parse JSON.");return}return this.extractStringsUsingI18nSchema(s,r)}static extractStringsUsingI18nSchema(t,e){if(!t||!e)return{};if(Array.isArray(t)&&typeof e=="object"){const s={};for(const r in e){const c=this.extractStringsUsingI18nSchema(t[r],r);Object.assign(s,c)}return s}if(typeof t=="object"&&typeof e=="object"){const s="*",r={};for(const[c,m]of Object.entries(e))if(t[c])r[c]=t[c];else if(Object.prototype.hasOwnProperty.call(t,s)){const i=this.extractStringsUsingI18nSchema(t[s],m);i&&Object.assign(r,i)}return r}return{}}}0&&(module.exports={JsonSchemaExtractor});
1
+ "use strict";var p=Object.create;var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!u.call(t,s)&&s!==r&&i(t,s,{get:()=>e[s],enumerable:!(a=d(e,s))||a.enumerable});return t};var m=(t,e,r)=>(r=t!=null?p(g(t)):{},h(e||!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),b=t=>h(i({},"__esModule",{value:!0}),t);var j={};y(j,{JsonSchemaExtractor:()=>c});module.exports=b(j);var I=m(require("../assets/block-i18n.js")),S=m(require("../assets/theme-i18n.js"));class c{static schemaCache={};static themeJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json";static themeJsonFallback=S;static blockJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json";static blockJsonFallback=I;static async loadSchema(e,r){if(c.schemaCache[e])return c.schemaCache[e];try{console.log(`
2
+ [i] Loading schema from ${e}`);const a=await fetch(e,{responseType:"json",accept:"application/json",headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}}).then(s=>s.json()).catch(s=>{throw new Error(`
3
+ Failed to load schema from ${e}. Error: ${s.message}`)});return!a||!a?.data?r:(console.log("Schema loaded successfully"),c.schemaCache[e]=a.data,a.data)}catch(a){return console.error(`
4
+ Failed to load schema from ${e}. Using fallback. Error: ${a.message}`),c.schemaCache[e]=r,r}}static async fromString(e,r){const a=r.schema,s=r.schemaFallback;if(!a||!s){console.error("Schema URL or fallback not provided");return}const n=await c.loadSchema(a,s);try{const o=JSON.parse(e);if(o===null){console.error("Could not parse JSON.");return}return c.extractStringsUsingI18nSchema(n,o)}catch(o){console.error(`Error parsing JSON: ${o.message}`);return}}static extractStringsUsingI18nSchema(e,r){if(!e||!r)return{};if(Array.isArray(e)&&typeof r=="object"){const a={};for(const s in r){const n=c.extractStringsUsingI18nSchema(e[s],s);Object.assign(a,n)}return a}if(typeof e=="object"&&typeof r=="object"){const a="*",s={};for(const[n,o]of Object.entries(r))if(e[n])s[n]=e[n];else if(Object.prototype.hasOwnProperty.call(e,a)){const l=c.extractStringsUsingI18nSchema(e[a],o);l&&Object.assign(s,l)}return s}return{}}}0&&(module.exports={JsonSchemaExtractor});
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var x=(n,t)=>{for(var e in t)a(n,e,{get:t[e],enumerable:!0})},p=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!y.call(n,s)&&s!==e&&a(n,s,{get:()=>t[s],enumerable:!(r=k(t,s))||r.enumerable});return n};var B=n=>p(a({},"__esModule",{value:!0}),n);var j={};x(j,{gentranslation:()=>l,getKeyByValue:()=>O,yieldParsedData:()=>b});module.exports=B(j);var g=require("gettext-merger"),d=require("./json.js");function O(n,t){return Object.keys(n).find(e=>n[e]===t)??void 0}const l=(n,t,e)=>{const r=new g.Block([]);return r.msgctxt=void 0,r.msgid=t,r.msgid_plural="",r.msgstr=[],r.comments={extracted:[n],reference:[e]},r};function b(n,t,e){const r=new g.SetOfBlocks([],e);return n&&(r.path=e,Object.entries(n).forEach(([s,o])=>{function f(i,c=s){const u=l((0,d.getJsonComment)(s,t),c,e);r.add(u)}if(o)typeof o=="string"?f(o):Array.isArray(o)?o.forEach(i=>f(i)):Object.entries(o).forEach(([i,c])=>{typeof c=="string"&&f(c,i)});else return})),r}0&&(module.exports={gentranslation,getKeyByValue,yieldParsedData});
1
+ "use strict";var l=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var p=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!x.call(t,o)&&o!==r&&l(t,o,{get:()=>e[o],enumerable:!(n=k(e,o))||n.enumerable});return t};var O=t=>B(l({},"__esModule",{value:!0}),t);var v={};p(v,{gentranslation:()=>m,getKeyByValue:()=>b,yieldParsedData:()=>j});module.exports=O(v);var g=require("gettext-merger"),d=require("./json.js");function b(t,e){return Object.keys(t).find(r=>t[r]===e)??void 0}const m=(t,e,r)=>{const n=new g.Block([]);return n.msgctxt=void 0,n.msgid=e,n.msgid_plural="",n.msgstr=[],n.comments={extracted:[t],reference:[r]},n};function j(t,e,r){const n=new g.SetOfBlocks([],r);if(!t)return n;n.path=r;for(const[u,s]of Object.entries(t)){let i=function(c,f=u){const a=m((0,d.getJsonComment)(u,e),f,r);n.add(a)};var o=i;if(s)if(typeof s=="string")i(s);else if(Array.isArray(s))for(const c of s)i(c);else for(const[c,f]of Object.entries(s))typeof f=="string"&&i(f,c)}return n}0&&(module.exports={gentranslation,getKeyByValue,yieldParsedData});
package/lib/fs/fs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.create;var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var F=(r,n)=>{for(var e in n)s(r,e,{get:n[e],enumerable:!0})},u=(r,n,e,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of p(n))!y.call(r,t)&&t!==e&&s(r,t,{get:()=>n[t],enumerable:!(c=g(n,t))||c.enumerable});return r};var m=(r,n,e)=>(e=r!=null?d(a(r)):{},u(n||!r||!r.__esModule?s(e,"default",{value:r,enumerable:!0}):e,r)),E=r=>u(s({},"__esModule",{value:!0}),r);var N={};F(N,{readFileAsync:()=>S,writeFile:()=>x});module.exports=E(N);var i=m(require("node:fs")),f=require("node:fs/promises"),o=m(require("node:path"));function l(r){if(r===void 0)return".";try{i.default.accessSync(o.default.resolve(r),i.default.constants.R_OK|i.default.constants.W_OK)}catch(n){if(n.code==="ENOENT")return i.default.mkdirSync(r,{recursive:!0}),console.log(`Folder created: ${r}`),r}return r}function x(r,n){l(o.default.dirname(n))&&(0,i.writeFileSync)(n,r)}async function S(r){return(0,f.readFile)(r,"utf-8")}0&&(module.exports={readFileAsync,writeFile});
1
+ "use strict";var p=Object.create;var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},u=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!x.call(t,r)&&r!==n&&c(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var a=(t,e,n)=>(n=t!=null?p(F(t)):{},u(e||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),y=t=>u(c({},"__esModule",{value:!0}),t);var j={};w(j,{getCharset:()=>d,getEncodingCharset:()=>h,getOutputPath:()=>$,readFileAsync:()=>S,writeFile:()=>O});module.exports=y(j);var s=a(require("node:fs")),f=require("node:fs/promises"),i=a(require("node:path"));function E(t){if(t===void 0)return".";try{s.default.accessSync(i.default.resolve(t),s.default.constants.R_OK|s.default.constants.W_OK)}catch(e){if(e.code==="ENOENT")return s.default.mkdirSync(t,{recursive:!0}),console.log(`Folder created: ${t}`),t}return t}function d(t){if(!t)return"latin1";switch(t.toLowerCase()){case"utf-8":case"utf8":return"utf-8";default:return"latin1"}}function h(t){if(!t)return"iso-8859-1";switch(t.toLowerCase()){case"utf-8":case"utf8":return"utf-8";default:return"iso-8859-1"}}function $(t){return i.default.join(process.cwd(),t??"languages")}function C(t){const{out:e,headers:n,options:o}=t.paths;let r=e??n?.domainPath??"languages";r=r.replace(/^\/+|\/+$/g,"");const g=o?.json?"json":"pot";return i.default.join(process.cwd(),r,`${t.slug}.${g}`)}function O(t,e){const n=C(e);if(E(i.default.dirname(n))){const o=d(e.options?.charset);console.log(`File created at ${n}`);const r=Buffer.from(t);(0,s.writeFileSync)(n,r.toString(o),{encoding:o})}else console.log(`Folder ${n} does not exist and cannot be created`)}async function S(t){return(0,f.readFile)(t,"utf-8")}0&&(module.exports={getCharset,getEncodingCharset,getOutputPath,readFileAsync,writeFile});
package/lib/fs/glob.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";var f=Object.create;var n=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},p=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of h(e))!j.call(t,o)&&o!==r&&n(t,o,{get:()=>e[o],enumerable:!(i=g(e,o))||i.enumerable});return t};var s=(t,e,r)=>(r=t!=null?f(y(t)):{},p(e||!t||!t.__esModule?n(r,"default",{value:t,enumerable:!0}):r,t)),x=t=>p(n({},"__esModule",{value:!0}),t);var F={};w(F,{getFiles:()=>A,getParser:()=>b,ignoreFunc:()=>d});module.exports=x(F);var a=s(require("node:path")),u=require("glob"),m=require("minimatch"),v=s(require("tree-sitter-javascript")),P=s(require("tree-sitter-php")),c=s(require("tree-sitter-typescript")),l=require("../utils/common.js");function b(t){const e=t.split(".").pop();switch(e){case"ts":return c.typescript;case"tsx":return c.tsx;case"js":case"jsx":case"mjs":case"cjs":return v.default;case"php":return P.default;default:return e}}const d=(t,e)=>e.some(r=>{switch((0,l.detectPatternType)(r)){case"file":return t.isNamed(r);case"directory":return t.relative().includes(r);default:return(0,m.minimatch)(t.relative(),r)}});function A(t,e){return t.options?.silent||console.log("Searching in :"+a.default.resolve(t.paths.cwd),`
2
- for `+e.include.join(),`
3
- ignoring patterns: `+e.exclude.join()),new u.Glob(e.include,{ignore:{ignored:r=>d(r,e.exclude)},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?a.default.resolve(t.paths.root):void 0})}0&&(module.exports={getFiles,getParser,ignoreFunc});
1
+ "use strict";var d=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var e in r)o(t,e,{get:r[e],enumerable:!0})},i=(t,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of h(r))!w.call(t,s)&&s!==e&&o(t,s,{get:()=>r[s],enumerable:!(a=g(r,s))||a.enumerable});return t};var n=(t,r,e)=>(e=t!=null?d(y(t)):{},i(r||!t||!t.__esModule?o(e,"default",{value:t,enumerable:!0}):e,t)),j=t=>i(o({},"__esModule",{value:!0}),t);var F={};x(F,{getFiles:()=>A,getParser:()=>b,ignoreFunc:()=>f});module.exports=j(F);var c=n(require("node:path")),u=require("glob"),m=require("minimatch"),P=n(require("tree-sitter-javascript")),v=n(require("tree-sitter-php")),p=n(require("tree-sitter-typescript")),l=require("../utils/common.js");function b(t){switch(t.split(".").pop()){case"ts":return p.typescript;case"tsx":return p.tsx;case"js":case"jsx":case"mjs":case"cjs":return P.default;case"php":return v.default;default:return null}}const f=(t,r)=>r.some(e=>{switch((0,l.detectPatternType)(e)){case"file":return t.isNamed(e);case"directory":return t.relative().includes(e);default:return(0,m.minimatch)(t.relative(),e)}});function A(t,r){return new u.Glob(r.include,{ignore:{ignored:e=>f(e,r.exclude)},nodir:!0,cwd:t.paths.cwd,root:t.paths.root?c.default.resolve(t.paths.root):void 0})}0&&(module.exports={getFiles,getParser,ignoreFunc});
package/lib/index.js CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
- "use strict";var a=Object.create;var t=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var c=(r,o)=>{for(var e in o)t(r,e,{get:o[e],enumerable:!0})},f=(r,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of u(o))!b.call(r,m)&&m!==e&&t(r,m,{get:()=>o[m],enumerable:!(n=d(o,m))||n.enumerable});return r};var k=(r,o,e)=>(e=r!=null?a(x(r)):{},f(o||!r||!r.__esModule?t(e,"default",{value:r,enumerable:!0}):e,r)),v=r=>f(t({},"__esModule",{value:!0}),r);var P={};c(P,{doTree:()=>i.doTree,makePot:()=>g.makePot});module.exports=v(P);var p=require("./cli/getArgs.js"),s=k(require("./run.js")),g=require("./parser/makePot.js"),i=require("./parser/tree.js");const A=(0,p.getArgs)();(0,s.default)(A);0&&(module.exports={doTree,makePot});
1
+ "use strict";var k=Object.create;var t=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var J=(o,r)=>{for(var e in r)t(o,e,{get:r[e],enumerable:!0})},x=(o,r,e,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of n(r))!u.call(o,m)&&m!==e&&t(o,m,{get:()=>r[m],enumerable:!(a=l(r,m))||a.enumerable});return o};var d=(o,r,e)=>(e=o!=null?k(s(o)):{},x(r||!o||!o.__esModule?t(e,"default",{value:o,enumerable:!0}):e,o)),P=o=>x(t({},"__esModule",{value:!0}),o);var b={};J(b,{default:()=>T,doTree:()=>i.doTree,makeJson:()=>p.default,makePot:()=>f.default});module.exports=P(b);var p=d(require("./jsonCommand")),f=d(require("./potCommand")),i=require("./parser/tree.js"),T={makeJson:p.default,makePot:f.default};0&&(module.exports={doTree,makeJson,makePot});
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.create;var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var J=(o,e)=>{for(var n in e)r(o,n,{get:e[n],enumerable:!0})},s=(o,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of f(e))!l.call(o,m)&&m!==n&&r(o,m,{get:()=>e[m],enumerable:!(t=c(e,m))||t.enumerable});return o};var M=(o,e,n)=>(n=o!=null?p(d(o)):{},s(e||!o||!o.__esModule?r(n,"default",{value:o,enumerable:!0}):n,o)),u=o=>s(r({},"__esModule",{value:!0}),o);var g={};J(g,{default:()=>k});module.exports=u(g);var i=M(require("./parser/makeJson")),a=require("./utils/common");function k(o){const e=new i.default(o);if(Object.keys(o).length>0){(0,a.printMakePotModuleInfo)();const n=new Date;e.invoke().then(t=>{o.debug&&console.log(t),(0,a.printTimeElapsed)(n)}).catch(t=>{console.error(`\u{1FAE4} make-json - Error: ${t}`)})}}
package/lib/makeJson.js CHANGED
@@ -1 +1,2 @@
1
- "use strict";var k=Object.create;var h=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var P=(l,s,o,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let e of w(s))!R.call(l,e)&&e!==o&&h(l,e,{get:()=>s[e],enumerable:!(t=$(s,e))||t.enumerable});return l};var j=(l,s,o)=>(o=l!=null?k(v(l)):{},P(s||!l||!l.__esModule?h(o,"default",{value:l,enumerable:!0}):o,l));var a=j(require("node:fs")),g=j(require("node:path")),S=require("glob"),T=require("node:crypto"),y=require("gettext-parser");class M{json_options=0;async invoke(s,o){const t=g.default.resolve(s[0]);if(!t||!a.default.existsSync(t)||!a.default.statSync(t).isFile()&&!a.default.statSync(t).isDirectory())throw new Error("Source file or directory does not exist!");const e=a.default.statSync(t).isFile()?g.default.dirname(t):t,n=this.buildMap(mapPaths);if(n&&Object.keys(n).length===0)throw new Error("No valid keys found. No file was created.");if(!a.default.existsSync(e)&&!a.default.mkdirSync(e,{recursive:!0})&&!a.default.existsSync(e))throw new Error("Could not create destination directory!");let r=0;const c=a.default.statSync(t).isFile()?[t]:(0,S.glob)(g.default.join(t,"**/*.po"));for(const i of c)if(a.default.statSync(i).isFile()&&a.default.statSync(i)&&g.default.extname(i)===".po"){const u=this.makeJson(i,e,n);if(r+=u.length,purge){if(!this.removeJsStringsFromPoFile(i)){console.warn(`Could not update file ${g.default.basename(t)}`);continue}if(updateMoFiles){const p=g.default.basename(i,".po"),b=g.default.join(e,`${p}.mo`);Translations.fromPoFile(i).toMoFile(b)||console.warn(`! Could not create file ${b}`)}}}console.log(`Created ${r} ${r===1?"file":"files"}.`)}buildMap(s){const o={},t=s?s.filter(n=>!0):[];console.info(`Using ${t.length} map files: ${t.join(", ")}`,"make-json");const e=maps.map((n,r)=>[n,`inline object ${r}`]);for(const n of t){if(!a.default.existsSync(n)||a.default.statSync(n).isDirectory()){console.warn(`Map file ${n} does not exist`);continue}const r=JSON.parse(a.default.readFileSync(n,"utf8"));if(!r||typeof r!="object"){console.warn(`Map file ${n} invalid`);continue}e.push([r,n])}for(const n of e){let[r,c]=n;const i=Object.keys(r).length;r=Object.fromEntries(Object.entries(r).map(([u,d])=>[u,Array.isArray(d)?d.filter(p=>typeof p=="string"):[]])),console.log(`Dropped ${Object.keys(r).length-i} keys from ${c}`,"make-json"),o={...o,...r}}return o}makeJson(s,o,t){const e={},n=a.default.readFileSync(s,"utf8"),r=y.po.parse(n),c=[];let i=g.default.basename(s,".po");const u=r.headers.TextDomain||null;return u&&!i.startsWith(u)&&(i=`${u}-${i}`),r.forEach(d=>{const p=(d.getReferences()||[]).map(f=>{const m=f[0];return m.endsWith(".min.js")?m.slice(0,-7)+".js":m.endsWith(".js")?m:null}).filter(Boolean);Array.from(new Set(p)).forEach(f=>{if(!e[f]){e[f]=new Translations,e[f].setHeader("Language",r.getLanguage()||""),e[f].setHeader("PO-Revision-Date",r.getHeader("PO-Revision-Date")||"");const m=r.getPluralForms();if(m){const[F,x]=m;e[f].setPluralForms(F,x)}}e[f].append(d)})}),c.push(...this.buildJsonFiles(e,i,o)),c}referenceMap(s,o){return o===null?s:s.map(([n,r])=>{const c=n;return o[c]?o[c]:[]}).flat().map(n=>[n,0])}buildJsonFiles(s,o,t){const e=[];for(const n of Object.keys(s)){const r=s[n],c=(0,T.createHash)("md5").update(n).digest("hex"),i=g.default.join(t,`${o}-${c}.json`);if(!y.po.compile(r,i,{json:this.json_options,source:n})){warning(`Could not create file ${g.default.basename(i,".json")}`);continue}e.push(i)}return e}removeJsStringsFromPoFile(s){const{translations:o}=y.po.parse(s);return o.forEach(t=>{if(t.comments?.reference){for(const e of t.comments?.reference)e[0].endsWith(".js");delete o.translations[t.msgid]}}),y.po.compile(o,s)}}const C=new M;C.invoke(process.argv.slice(2),{}).catch(l=>console.error(l));
1
+ #!/usr/bin/env node
2
+ "use strict";var i=Object.create;var e=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var b=(o,r,n,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of f(r))!J.call(o,s)&&s!==n&&e(o,s,{get:()=>r[s],enumerable:!(m=a(r,s))||m.enumerable});return o};var c=(o,r,n)=>(n=o!=null?i(p(o)):{},b(r||!o||!o.__esModule?e(n,"default",{value:o,enumerable:!0}):n,o));var t=require("./cli/getJsonArgs"),g=c(require("./jsonCommand"));const d=(0,t.getJsonArgs)();(0,g.default)(d);
package/lib/makePot.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var i=Object.create;var p=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var d=(r,m,o,e)=>{if(m&&typeof m=="object"||typeof m=="function")for(let t of a(m))!A.call(r,t)&&t!==o&&p(r,t,{get:()=>m[t],enumerable:!(e=n(m,t))||e.enumerable});return r};var y=(r,m,o)=>(o=r!=null?i(f(r)):{},d(m||!r||!r.__esModule?p(o,"default",{value:r,enumerable:!0}):o,r));var s=require("./cli/getArgs.js"),g=y(require("./potCommand"));(0,g.default)((0,s.getArgs)());
@@ -1,3 +1,7 @@
1
- "use strict";var m=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var S=(o,t)=>{for(var n in t)m(o,n,{get:t[n],enumerable:!0})},U=(o,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of T(t))!F.call(o,s)&&s!==n&&m(o,s,{get:()=>t[s],enumerable:!(e=h(t,s))||e.enumerable});return o};var B=o=>U(m({},"__esModule",{value:!0}),o);var P={};S(P,{exec:()=>C});module.exports=B(P);var i=require("node:os"),a=require("gettext-parser"),p=require("../extractors/headers.js"),l=require("../utils/common.js"),c=require("./patterns.js"),f=require("./process.js"),u=require("./progress.js"),g=require("./taskRunner.js");async function C(o){o.options?.silent||(console.log("\u{1F4DD} Starting makePot for",o?.slug),console.log("Memory usage:",(process.memoryUsage().heapUsed/1024/1024).toFixed(2),"MB (Free:",((0,i.totalmem)()/1024/1024/1024).toFixed(2),`GB)
2
- Cpu User:`,(process.cpuUsage().user/1e6).toFixed(2),"ms Cpu System:",(process.cpuUsage().system/1e6).toFixed(2),"ms of",(0,i.cpus)().length,"cores")),o.options?.skip.audit&&(console.log("Audit strings..."),console.log("\u2705 Done"));const t=(0,p.generateHeader)(o),n=o.options?.fileComment||(0,l.getCopyright)(o.slug,o.headers?.license??"GPL v2 or later");let e=(0,p.translationsHeaders)(o);const s=(0,c.getPatterns)(o),r=(0,u.initProgress)(o,0)??void 0,d=await(0,f.processFiles)(s,o,r);if(e=await(0,g.taskRunner)(d,e,o,r),r&&r.stop(),o.options?.json)return JSON.stringify([t,e.toJson()],null,4);const y={charset:"iso-8859-1",headers:t,translations:e.toJson()},x=a.po.compile(y).toString("utf-8");return`${n}
3
- ${x}`}0&&(module.exports={exec});
1
+ "use strict";var C=Object.create;var s=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var A=(t,n)=>{for(var o in n)s(t,o,{get:n[o],enumerable:!0})},l=(t,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of w(n))!k.call(t,i)&&i!==o&&s(t,i,{get:()=>n[i],enumerable:!(e=j(n,i))||e.enumerable});return t};var m=(t,n,o)=>(o=t!=null?C($(t)):{},l(n||!t||!t.__esModule?s(o,"default",{value:t,enumerable:!0}):o,t)),B=t=>l(s({},"__esModule",{value:!0}),t);var H={};A(H,{exec:()=>G});module.exports=B(H);var c=m(require("node:path")),g=require("gettext-parser"),f=m(require("tannin")),r=require("../extractors/headers.js"),p=require("../fs/fs"),a=require("../utils/common.js"),d=require("./patterns.js"),u=require("./process.js"),h=require("./progress.js"),P=require("./taskRunner.js");function D(t,n){console.log(`
2
+ Script Path: ${t}
3
+ for ${n.include.join()}
4
+ ignoring patterns: ${n.exclude.join()}
5
+ `)}async function G(t){t.options?.silent||(console.log("\u{1F4DD} Starting makePot for",t?.slug),(0,a.printStats)()),t.options?.skip.audit&&(console.log(`
6
+ Audit strings...`),console.log("TODO"),console.log("\u2705 Done"));const n=await(0,r.generateHeader)(t);let o=(0,r.translationsHeaders)(t);const e=(0,d.getPatterns)(t);t.options?.silent||D(c.default.resolve(t.paths.cwd),e);const i=(0,h.initProgress)(t,0)??void 0,T=await(0,u.processFiles)(e,t,i);if(o=await(0,P.taskRunner)(T,o,t,i),t.options?.json){const x={[t.slug]:{"":n,...o.toJson()}};return new f.default(x).toString()}const y={charset:(0,p.getEncodingCharset)(t.options?.charset),headers:n,translations:o.toJson()},S=g.po.compile(y).toString((0,p.getCharset)(t.options?.charset));return`${t.options?.fileComment||(0,a.getCopyright)(t.slug,t.headers?.license??"GPL v2 or later")}
7
+ ${S}`}0&&(module.exports={exec});
@@ -0,0 +1 @@
1
+ "use strict";var b=Object.create;var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var P=(n,t)=>{for(var e in t)p(n,e,{get:t[e],enumerable:!0})},h=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of J(t))!N.call(n,i)&&i!==e&&p(n,i,{get:()=>t[i],enumerable:!(s=x(t,i))||s.enumerable});return n};var m=(n,t,e)=>(e=n!=null?b(w(n)):{},h(t||!n||!n.__esModule?p(e,"default",{value:n,enumerable:!0}):e,n)),S=n=>h(p({},"__esModule",{value:!0}),n);var T={};P(T,{MakeJsonCommand:()=>v,default:()=>D});module.exports=S(T);var f=m(require("node:crypto")),c=m(require("node:fs")),o=m(require("node:path")),y=require("gettext-parser"),g=require("glob"),u=require("../const");class v{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;constructor(t){if(this.sourceDir=o.default.relative(t.paths.cwd,t.source??""),!c.existsSync(this.sourceDir))throw console.error("Source directory not found",t),new Error(`Source directory ${this.sourceDir} not found`);this.scriptName=t.scriptName,this.source=t.source,this.destination=t.destination,this.allowedFormats=t.allowedFormats??[".ts",".tsx",".js",".jsx",".mjs",".cjs"],this.purge=t.purge,this.prettyPrint=t.prettyPrint,this.debug=t.debug,this.paths=t.paths}async invoke(){const t=await(0,g.glob)("**/*.po",{cwd:this.destination,nodir:!0});console.log("Found po files",t,"in",this.destination,"folder");const e={};for(const s of t)if(this.scriptName||(this.scriptName=await(0,g.glob)("*.js",{cwd:this.source,nodir:!0}),console.log("Found script:",this.scriptName,"in",this.source,"folder")),typeof this.scriptName=="string"){const i=this.addPot(s,this.scriptName);e[i.filename]=i.data}else if(Array.isArray(this.scriptName))for(const i of this.scriptName){const r=this.addPot(s,i);e[r.filename]=r.data}for(const[s,i]of Object.entries(e)){let r;if(this.purge)c.existsSync(o.default.join(this.destination,s))&&(console.log(`Removing ${o.default.join(this.destination,s)} as the purge option is enabled`),c.unlinkSync(o.default.join(this.destination,s))),r=JSON.stringify(i,null,this?.prettyPrint?2:0);else{const l=c.readFileSync(o.default.join(this.source,s),"utf8");r=JSON.stringify({...i,...JSON.parse(l)},null,this?.prettyPrint?2:0)}const a=o.default.join(this.destination,s);c.writeFileSync(a,r),console.log(`JSON file written to ${a} with ${s}`)}return e}processFile(t,e="utf8"){const s=c.readFileSync(t,e),i=this.extractIsoCode(t),r=this.parsePoFile(s);return this.convertToJed(r.headers,r.translations,i)}parsePoFile(t){return y.po.parse(t)}convertToJed(t,e,s){const i="messages",r={[i]:{"":{domain:i,lang:s||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const a of Object.keys(e)){const l=e[a];for(const d of Object.keys(l)){const F=l[d];if(d==="")continue;const j=a&&a!==""?`${a}${d}`:d;r[i][j]=F.msgstr}}return r}extractIsoCode(t){const e=t.match(u.IsoCodeRegex);return e?e[1]:void 0}getPluralForms(t){const e=t.match(/Plural-Forms:\s*(.*?)\n/);return e?e[1]:"nplurals=2; plural=(n != 1);"}getLanguage(t){const e=t.match(/Language:\s*(.*?)\n/);return e?e[1]:u.defaultLocale}isCompatibleFile(t){return this.allowedFormats?t.some(e=>this.allowedFormats.some(s=>e.endsWith(s))):!0}md5(t){return f.default.createHash("md5").update(t).digest("hex")}addPot(t,e){const s=this.md5(e);return{filename:t.replace(".po",`-${s}.json`),data:this.processFile(o.default.join(this.destination,t))}}}var D=v;0&&(module.exports={MakeJsonCommand});
@@ -1 +1 @@
1
- "use strict";var f=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var P=(t,o)=>{for(var e in o)s(t,e,{get:o[e],enumerable:!0})},a=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of l(o))!g.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(r=h(o,n))||r.enumerable});return t};var j=(t,o,e)=>(e=t!=null?f(d(t)):{},a(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t)),x=t=>a(s({},"__esModule",{value:!0}),t);var w={};P(w,{makePot:()=>k});module.exports=x(w);var i=j(require("node:path")),p=require("../extractors/headers.js"),m=require("../extractors/json.js"),c=require("../fs/fs.js"),u=require("./exec.js");function A(t){return i.default.join(process.cwd(),t.headers?.domainPath??t.paths.out??"languages",`${t?.slug}.${t.options?.json?"json":"pot"}`)}async function k(t){const o=(0,m.extractPackageJson)(t),e=(0,p.extractMainFileData)(t);t.headers={...t.headers,...o,...e};const r=await(0,u.exec)(t),n=A(t);return console.log(`Writing pot file to ${n}`),(0,c.writeFile)(r,n),r}0&&(module.exports={makePot});
1
+ "use strict";var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},x=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of f(t))!h.call(e,m)&&m!==o&&a(e,m,{get:()=>t[m],enumerable:!(r=s(t,m))||r.enumerable});return e};var k=e=>x(a({},"__esModule",{value:!0}),e);var y={};d(y,{makePot:()=>u});module.exports=k(y);var c=require("../extractors/headers.js"),i=require("../extractors/json.js"),n=require("../fs/fs.js"),p=require("./exec.js");async function u(e){const t=(0,i.extractPackageJson)(e),o=(0,c.extractMainFileData)(e);e.headers={...e.headers,...t,...o},(0,p.exec)(e).then(r=>((0,n.writeFile)(r,e),r)).catch(r=>(console.error(r),""))}0&&(module.exports={makePot});
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var s in t)p(e,s,{get:t[s],enumerable:!0})},h=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!o.call(e,n)&&n!==s&&p(e,n,{get:()=>t[n],enumerable:!(i=d(t,n))||i.enumerable});return e};var l=e=>h(p({},"__esModule",{value:!0}),e);var f={};c(f,{getPatterns:()=>r});module.exports=l(f);function r(e){const t={include:e.patterns.include||[],exclude:e.patterns.exclude||[],mergePaths:e.patterns.mergePaths,subtractPaths:e.patterns.subtractPaths,subtractAndMerge:e.patterns.subtractAndMerge};return(e.options?.skip.php!==void 0||e.options?.skip.blade!==void 0)&&(e.options?.skip.blade!==void 0?t.include.push("**/*.php"):t.include.push("**/*.php","!**/blade.php")),e.options?.skip.js!==void 0&&t.include.push("**/*.{js,jsx,ts,tsx,mjs,cjs}"),e.options?.skip.blockJson!==void 0&&t.include.push("block.json"),e.options?.skip.themeJson!==void 0&&t.include.push("theme.json"),t}0&&(module.exports={getPatterns});
1
+ "use strict";var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var p in e)n(t,p,{get:e[p],enumerable:!0})},l=(t,e,p,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!c.call(t,s)&&s!==p&&n(t,s,{get:()=>e[s],enumerable:!(o=i(e,s))||o.enumerable});return t};var d=t=>l(n({},"__esModule",{value:!0}),t);var a={};h(a,{getPatterns:()=>r});module.exports=d(a);function r(t){const e={include:t.patterns.include||[],exclude:t.patterns.exclude||[],mergePaths:t.patterns.mergePaths,subtractPaths:t.patterns.subtractPaths,subtractAndMerge:t.patterns.subtractAndMerge};return t.options&&(t.options.skip.blade?e.exclude.push("**/blade.php"):t.options.skip.php&&e.exclude.push("**/*.php","**/*.blade.php"),t.options.skip.js&&e.exclude.push("**/*.{js,jsx,ts,tsx,mjs,cjs}"),t.options.skip.blockJson&&e.exclude.push("block.json"),t.options.skip.themeJson&&e.exclude.push("theme.json")),e}0&&(module.exports={getPatterns});
@@ -1 +1 @@
1
- "use strict";var g=Object.create;var n=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var F=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},c=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!B.call(e,s)&&s!==o&&n(e,s,{get:()=>t[s],enumerable:!(r=S(t,s))||r.enumerable});return e};var b=(e,t,o)=>(o=e!=null?g(x(e)):{},c(t||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),j=e=>c(n({},"__esModule",{value:!0}),e);var O={};F(O,{processFiles:()=>A});module.exports=j(O);var l=b(require("node:path")),h=require("../const.js"),d=require("../extractors/json.js"),k=require("../fs/glob.js"),p=require("../fs/fs.js"),u=require("./tree.js");async function A(e,t,o){const r=[];let s=0;const y=(0,k.getFiles)(t,e);for await(const i of y){s++;const m=l.default.basename(i),P=l.default.extname(i).replace(/^./,""),a=l.default.resolve(t.paths.cwd,i);(m==="theme.json"||m==="block.json")&&r.push((0,p.readFileAsync)(a).then(f=>(0,d.parseJsonCallback)(f,t.paths.cwd,m))),h.allowedFiles.includes(P)&&r.push((0,p.readFileAsync)(a).then(f=>(0,u.doTree)(f,i))),o?.increment(1,{filename:m}),o?.setTotal(s)}return r}0&&(module.exports={processFiles});
1
+ "use strict";var S=Object.create;var m=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!w.call(e,s)&&s!==o&&m(e,s,{get:()=>t[s],enumerable:!(r=b(t,s))||r.enumerable});return e};var F=(e,t,o)=>(o=e!=null?S(j(e)):{},h(t||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),O=e=>h(m({},"__esModule",{value:!0}),e);var v={};x(v,{processFiles:()=>A});module.exports=O(v);var n=F(require("node:path")),d=require("../const.js"),u=require("../extractors/json.js"),a=require("../fs/fs.js"),k=require("../fs/glob.js"),y=require("./tree.js");async function A(e,t,o){const r=[];let s=0;const c=(0,k.getFiles)(t,e);for await(const i of c){s++;const l=n.default.basename(i),P=n.default.extname(i).replace(/^./,""),p=n.default.resolve(t.paths.cwd,i);l==="theme.json"||l==="block.json"?r.push((0,a.readFileAsync)(p).then(f=>(0,u.parseJsonCallback)(f,t.paths.cwd,l))):d.allowedFormats.includes(P)&&r.push((0,a.readFileAsync)(p).then(f=>(0,y.doTree)(f,i))),o&&(o.update(s,{filename:l}),o.setTotal(Object.values(c).length),o.render())}return r}0&&(module.exports={processFiles});
@@ -1 +1 @@
1
- "use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var g=(s,o)=>{for(var l in o)n(s,l,{get:o[l],enumerable:!0})},f=(s,o,l,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of i(o))!p.call(s,e)&&e!==l&&n(s,e,{get:()=>o[e],enumerable:!(r=c(o,e))||r.enumerable});return s};var m=s=>f(n({},"__esModule",{value:!0}),s);var h={};g(h,{taskRunner:()=>u});module.exports=m(h);async function u(s,o,l,r){return await Promise.allSettled(s).then(e=>e.map(t=>t.status==="fulfilled"&&t.value).filter(Boolean)).then(e=>{for(const t of e)t.blocks.length>0?(o.addArray(t.blocks),console.log(`\u2705 ${t.path} [`,t.blocks.map(a=>a.msgid).join(", "),"]")):console.log("\u274C ",`${t.path} has no strings`);r?.stop()}).catch(e=>{console.log("\u274C Failed!",e),process.exit(1)}),l.options?.silent||(console.log("\u{1F389} Done!"),console.log("\u{1F4DD} Found",Object.values(o.blocks).length,"translation strings in",l.paths.cwd)),o}0&&(module.exports={taskRunner});
1
+ "use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(t,o)=>{for(var s in o)n(t,s,{get:o[s],enumerable:!0})},g=(t,o,s,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of a(o))!p.call(t,e)&&e!==s&&n(t,e,{get:()=>o[e],enumerable:!(r=c(o,e))||r.enumerable});return t};var m=t=>g(n({},"__esModule",{value:!0}),t);var h={};f(h,{taskRunner:()=>u});module.exports=m(h);async function u(t,o,s,r){return await Promise.allSettled(t).then(e=>e.map(l=>l.status==="fulfilled"&&l.value).filter(Boolean)).then(e=>{if(r?.stop(),s.options?.silent!==!0)for(const l of e)l.blocks.length>0?(o.addArray(l.blocks),console.log(`\u2705 ${l.path} [${l.blocks.map(i=>i.msgid).join(", ")}]`)):console.log("\u274C ",`${l.path} has no strings`)}).catch(e=>{console.log("\u274C Failed!",e),process.exit(1)}),s.options?.silent||(console.log("\u{1F389} Done!"),console.log(`\u{1F4DD} Found ${Object.values(o.blocks).length} translation strings in ${s.paths.cwd}`)),o}0&&(module.exports={taskRunner});
@@ -1 +1 @@
1
- "use strict";var T=Object.create;var g=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var F=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},k=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!L.call(e,s)&&s!==n&&g(e,s,{get:()=>t[s],enumerable:!(c=O(t,s))||c.enumerable});return e};var M=(e,t,n)=>(n=e!=null?T(K(e)):{},k(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),j=e=>k(g({},"__esModule",{value:!0}),e);var V={};F(V,{doTree:()=>U});module.exports=j(V);var _=M(require("tree-sitter")),y=require("../const.js"),p=require("gettext-merger"),w=require("../fs/glob.js"),m=require("../utils/common.js");function I(e){let t=e,n=0;for(;t&&n<6;){if(t?.previousSibling?.type==="comment"&&t?.previousSibling?.text.toLowerCase().includes("translators"))return(0,m.stripTranslationMarkup)(t?.previousSibling.text);n++,t=t.parent}}function U(e,t){const n=new _.default;n.setLanguage((0,w.getParser)(t));const c=n.parse(e),s=new p.SetOfBlocks([],t),N=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",v=["string","encapsed_string","string_value"];function x(r){if(r?.children.length)for(const o of r.children)x(o);if(r?.type===N){const o=r.firstChild?.text??null;if(o===null||!Object.keys(y.i18nFunctions).includes(o))return;const a=r.lastChild;if(a===null||a.childCount===0||a.type!=="arguments")return;const[q,C]=r.children,i={},h=y.i18nFunctions[o],$=C.children.slice(1,-1);let f=0;for(const d of $){let l=d,u=l.text;if(d.type==="argument"){if(d.children.length===0)continue;l=d.children[0]}if(l?.type===",")continue;if(v.includes(l?.type))u=u.slice(1,-1);else{console.warn(`Unexpected node type: ${l?.type} is ${h[f]} for ${u} in ${t}`);continue}const B=h[f];i[B]=u,f+=1}const S=I(a),b=new p.Block({msgctxt:i.msgctxt,msgid:i.msgid??"",msgid_plural:i.msgid_plural,msgstr:i.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,m.reverseSlashes)(t)}:${r.startPosition.row+1}`]}});s.add(b)}}return x(c.rootNode),s}0&&(module.exports={doTree});
1
+ "use strict";var O=Object.create;var g=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},b=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!F.call(e,s)&&s!==n&&g(e,s,{get:()=>t[s],enumerable:!(o=P(t,s))||o.enumerable});return e};var j=(e,t,n)=>(n=e!=null?O(L(e)):{},b(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),E=e=>b(g({},"__esModule",{value:!0}),e);var V={};M(V,{doTree:()=>U});module.exports=E(V);var k=j(require("tree-sitter")),y=require("../const.js"),a=require("gettext-merger"),w=require("../fs/glob.js"),m=require("../utils/common.js");function I(e){let t=e,n=0;for(;t&&n<6;){if(t?.previousSibling?.type==="comment"&&t?.previousSibling?.text.toLowerCase().includes("translators"))return t?.previousSibling?.text?(0,m.stripTranslationMarkup)(t.previousSibling.text):void 0;n++,t=t.parent}}function U(e,t){const n=new k.default,o=(0,w.getParser)(t);if(!o)return new a.SetOfBlocks([],t);n.setLanguage(o);const s=n.parse(e),x=new a.SetOfBlocks([],t),v=t.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",N=["string","string_value","variable_name","binary_expression","member_expression","subscript_expression","function_call_expression","encapsed_string"];function _(r){if(r?.children.length)for(const c of r.children)_(c);if(r?.type===v){const c=r.firstChild?.text??null;if(c===null||!Object.keys(y.i18nFunctions).includes(c))return;const p=r.lastChild;if(p===null||p.childCount===0||p.type!=="arguments")return;const[q,C]=r.children,l={},h=y.i18nFunctions[c],$=C.children.slice(1,-1);let f=0;for(const u of $){let i=u,d=i.text;if(u.type==="argument"){if(u.children.length===0)continue;i=u.children[0]}if(i?.type===",")continue;if(i?.type&&N.includes(i.type))d=d.slice(1,-1);else{console.warn(`Unexpected node type: ${i?.type} is ${h[f]} for ${d} in ${t}`);continue}const T=h[f];l[T]=d,f+=1}const S=I(p),B=new a.Block({msgctxt:l.msgctxt,msgid:l.msgid??"",msgid_plural:l.msgid_plural,msgstr:l.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,m.reverseSlashes)(t)}:${r.startPosition.row+1}`]}});x.add(B)}}return _(s.rootNode),x}0&&(module.exports={doTree});
@@ -0,0 +1 @@
1
+ "use strict";var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of s(t))!c.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(p=f(t,r))||p.enumerable});return e};var k=e=>d(n({},"__esModule",{value:!0}),e);var h={};l(h,{default:()=>a});module.exports=k(h);var i=require("./parser/makePot.js"),m=require("./utils/common");function a(e){if(Object.keys(e).length>0){(0,m.printMakePotModuleInfo)();const t=new Date;(0,i.makePot)(e).then(()=>{(0,m.printTimeElapsed)(t)}).catch(o=>{console.error(`\u{1FAE4} Make-pot - ${o}`)})}}
package/lib/types.js CHANGED
@@ -1 +1 @@
1
- "use strict";var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var g=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of i(e))!p.call(t,n)&&n!==a&&r(t,n,{get:()=>e[n],enumerable:!(o=s(e,n))||o.enumerable});return t};var l=t=>g(r({},"__esModule",{value:!0}),t);var m={};module.exports=l(m);
1
+ "use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of i(e))!g.call(t,n)&&n!==o&&s(t,n,{get:()=>e[n],enumerable:!(r=a(e,n))||r.enumerable});return t};var l=t=>p(s({},"__esModule",{value:!0}),t);var d={};module.exports=l(d);