@wp-blocks/make-pot 1.5.0 → 1.6.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 +5 -4
- package/lib/cli/getArgs.js +1 -1
- package/lib/cli/getJsonArgs.js +1 -1
- package/lib/cli/parseCli.js +1 -1
- package/lib/cli.js +1 -1
- package/lib/const.js +1 -1
- package/lib/extractors/auditStrings.js +5 -0
- package/lib/extractors/css.js +1 -1
- package/lib/extractors/headers.js +12 -4
- package/lib/extractors/json.js +1 -1
- package/lib/extractors/packageJson.js +1 -0
- package/lib/extractors/php.js +2 -2
- package/lib/extractors/schema.js +4 -4
- package/lib/extractors/text.js +1 -1
- package/lib/fs/fs.js +2 -1
- package/lib/index.js +1 -1
- package/lib/jsonCommand.js +1 -1
- package/lib/makeJson.js +1 -1
- package/lib/makePot.js +1 -1
- package/lib/parser/exec.js +3 -7
- package/lib/parser/makeJson.js +1 -1
- package/lib/parser/makePot.js +1 -1
- package/lib/parser/process.js +1 -1
- package/lib/parser/progress.js +1 -1
- package/lib/parser/taskRunner.js +2 -1
- package/lib/parser/tree.js +1 -1
- package/lib/potCommand.js +1 -1
- package/lib/utils/common.js +8 -3
- package/lib/utils/extractors.js +1 -0
- package/lib/utils/output.js +1 -0
- package/package.json +15 -12
- package/tests/audit.test.js +50 -0
- package/tests/compare-json.test.js +81 -0
- package/tests/extract-headers.test.js +54 -0
- package/tests/extract.test.js +1 -1
- package/tests/jsonParse.test.js +167 -0
- package/tests/parse-headers.test.js +75 -0
- package/lib/extractors/utils.js +0 -1
- package/tests/getFiles.test.no.js +0 -85
- package/tests/jsonParse.no.js +0 -49
- package/tests/wpcliCompare.no.js +0 -32
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npm install -g @wp-blocks/make-pot
|
|
|
32
32
|
```bash
|
|
33
33
|
# without installation
|
|
34
34
|
npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
35
|
-
npx @wp-blocks/make-pot
|
|
35
|
+
npx -p @wp-blocks/make-pot makejson [sourceDirectory] [destination] [options]
|
|
36
36
|
|
|
37
37
|
# installed
|
|
38
38
|
npx makepot [sourceDirectory] [destination] [options]
|
|
@@ -65,7 +65,7 @@ npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,
|
|
|
65
65
|
- `--skip-block-json`: Skips block.json files during processing.
|
|
66
66
|
- `--skip-theme-json`: Skips theme.json files during processing.
|
|
67
67
|
- `--skip-audit`: Skips auditing of strings.
|
|
68
|
-
- `--headers <headers>`: Specifies additional headers for the `.pot` file.
|
|
68
|
+
- `--headers <headers>`: Specifies additional headers for the `.pot` file. Accepts an array of strings (--headers=email:erik@ck.it,domain:my-block) or multiple values (--headers=email:erik@ck.it --headers=domain:my-block)
|
|
69
69
|
- `--file-comment <comment>`: Specifies the file comment for the `.pot` file.
|
|
70
70
|
- `--package-name <name>`: Specifies the package name.
|
|
71
71
|
- `--location`: Includes location information in the `.pot` file.
|
|
@@ -158,6 +158,7 @@ Unlike traditional PO/MO files, JavaScript translations use JSON. This format is
|
|
|
158
158
|
- `--allowedFormats`: The allowed formats of the translation file (e.g. `js` or `tsx`).
|
|
159
159
|
- `--purge`: if enabled, removes the existing translation file. Otherwise, the old translation file will be merged with the new.
|
|
160
160
|
- `--prettyPrint`: Pretty prints the translation file.
|
|
161
|
+
- `--stripUnused`: strips unused translations from the translation file (default: true).
|
|
161
162
|
- `--debug`: Enables debug mode.
|
|
162
163
|
|
|
163
164
|
## How to Generate Json translations
|
|
@@ -170,8 +171,8 @@ translate the pot file into your language and then run `makejson`:
|
|
|
170
171
|
|
|
171
172
|
```bash
|
|
172
173
|
npx makejson
|
|
173
|
-
# OR
|
|
174
|
-
npx @wp-blocks/make-pot
|
|
174
|
+
# OR if you don't want to install the module
|
|
175
|
+
npx -p @wp-blocks/make-pot makejson,
|
|
175
176
|
```
|
|
176
177
|
It Will create a file for each po file in the `languages` directory with the md5 hash with the name of the file.
|
|
177
178
|
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.
|
package/lib/cli/getArgs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var o=Object.defineProperty;var
|
|
1
|
+
"use strict";var l=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0})},n=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!f.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(r=b(t,s))||r.enumerable});return e};var a=(e,t,i)=>(i=e!=null?l(u(e)):{},n(t||!e||!e.__esModule?o(i,"default",{value:e,enumerable:!0}):i,e)),m=e=>n(o({},"__esModule",{value:!0}),e);var S={};y(S,{getArgs:()=>h});module.exports=m(S);var p=a(require("node:process")),k=a(require("yargs")),d=require("yargs/helpers"),c=require("./parseCli.js");function h(e={}){const t=k.default((0,d.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("sourceDirectory",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({slug:{describe:"Plugin or theme slug",type:"string"},domain:{describe:"Text domain to look for in the source code",type:"string"},"skip-js":{describe:"Skip JavaScript files",type:"boolean"},"skip-php":{describe:"Skip PHP files",type:"boolean"},"skip-blade":{describe:"Skip Blade files",type:"boolean"},"skip-block-json":{describe:"Skip block.json files",type:"boolean"},"skip-theme-json":{describe:"Skip theme.json files",type:"boolean"},"skip-audit":{describe:"Skip auditing of strings",type:"boolean",default:!1},headers:{describe:"Additional Headers",type:"array",default:[]},"file-comment":{describe:"File comment",type:"string"},"package-name":{describe:"Package name",type:"string"},location:{describe:"Include location information",type:"boolean"},"ignore-domain":{describe:"Ignore text domain",type:"boolean"},mergePaths:{describe:"Merge with existing POT file(s)",type:"string"},subtractPaths:{describe:"Subtract strings from existing POT file(s)",type:"string"},subtractAndMerge:{describe:"Subtract and merge strings from existing POT file(s)",type:"boolean"},include:{describe:"Include specific files",type:"string",default:"**"},exclude:{describe:"Exclude specific files",type:"string"},silent:{describe:"No output to stdout",type:"boolean",default:!1},json:{describe:"Output the json gettext data",type:"boolean"},output:{describe:"Output the gettext data",type:"boolean"},charset:{describe:"Charset",type:"string",default:"latin1"},debug:{describe:"Debug mode",type:"boolean",default:!1}}).parseSync();return(0,c.parseCliArgs)({...e,...t})}0&&(module.exports={getArgs});
|
package/lib/cli/getJsonArgs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.create;var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var s in t)o(e,s,{get:t[s],enumerable:!0})},a=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!g.call(e,r)&&r!==s&&o(e,r,{get:()=>t[r],enumerable:!(i=c(t,r))||i.enumerable});return e};var n=(e,t,s)=>(s=e!=null?u(y(e)):{},a(t||!e||!e.__esModule?o(s,"default",{value:e,enumerable:!0}):s,e)),m=e=>a(o({},"__esModule",{value:!0}),e);var S={};b(S,{getJsonArgs:()=>J});module.exports=m(S);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},stripUnused:{describe:"Strip unused translations in js files",type:"boolean",default:!0}}).parseSync();return(0,l.parseJsonArgs)({...e,...t})}0&&(module.exports={getJsonArgs});
|
package/lib/cli/parseCli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.create;var u=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var v=(t,n)=>{for(var e in n)u(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of T(n))!j.call(t,s)&&s!==e&&u(t,s,{get:()=>n[s],enumerable:!(o=J(n,s))||o.enumerable});return t};var d=(t,n,e)=>(e=t!=null?w(_(t)):{},g(n||!t||!t.__esModule?u(e,"default",{value:t,enumerable:!0}):e,t)),O=t=>g(u({},"__esModule",{value:!0}),t);var $={};v($,{parseCliArgs:()=>C,parseJsonArgs:()=>N});module.exports=O($);var c=d(require("node:fs")),i=d(require("node:path")),f=d(require("node:process")),y=require("../const.js"),k=require("../fs/fs"),a=require("../utils/common.js");function S(t="/",n="default"){const e=t;try{return(0,c.accessSync)(i.join(e,`${n}.php`),c.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${e} does not contain a ${n}.php file`)}try{return(0,c.accessSync)(i.join(e,"style.css"),c.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${e} does not contain a style.css file`)}return"generic"}function C(t){const n=t._[0]?.toString(),e=t._[1]?.toString()||"languages",o=n??".",s=e.startsWith("/")?e.slice(1):e,r=f.cwd(),p=t.slug&&typeof t.slug=="string"?t.slug:i.basename(i.resolve(r,o)),m=i.relative(r,o),b=i.relative(r,s);if(!t?.domain)t.domain=S(i.resolve(m),p);else switch(t.domain){case"plugin":case"theme":case"block":case"theme-block":break;default:console.error(`Invalid domain: ${t.domain}. Valid domains are: plugin, theme, block, theme-block, generic`),t.domain="generic"}const l={};for(const P of t.headers){const[A,D]=P.split(":");l[A.trim()]=D.trim()}const h={slug:p,debug:!!t.debug,domain:t.domain,paths:{cwd:m,out:b},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:t.silent===!0,json:!!t.json,location:!!t?.location,headers:l,theme:!!t?.theme,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,charset:(0,k.getEncodingCharset)(t?.charset),skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit}},patterns:{mergePaths:(0,a.stringstring)(t.mergePaths),subtractPaths:(0,a.stringstring)(t.subtractPaths),subtractAndMerge:!!t.subtractAndMerge,include:(0,a.stringstring)(t.include),exclude:[...(0,a.stringstring)(t.exclude),...y.DEFAULT_EXCLUDED_PATH]}};return h.paths.root=t.root?String(t.root):void 0,h}function N(t){const n=t._[0]||"build",e=t._[1]||"languages",o=f.cwd(),s=i.basename(i.resolve(o));let r;return t.scriptName&&(r=t.scriptName.split(",").map(p=>p.trim()),r.length===1&&(r=r[0])),{timeStart:Date.now(),slug:s,source:n,destination:e,scriptName:r,allowedFormats:t.allowedFormats,purge:!!t.purge,stripUnused:!!t.stripUnused,prettyPrint:!!t.prettyPrint,debug:!!t.debug,paths:{cwd:o,out:i.join(o,e)}}}0&&(module.exports={parseCliArgs,parseJsonArgs});
|
package/lib/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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,
|
|
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,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/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.create;var _=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var m in e)_(t,m,{get:e[m],enumerable:!0})},n=(t,e,m,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!u.call(t,s)&&s!==m&&_(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var o=(t,e,m)=>(m=t!=null?r(l(t)):{},n(e||!t||!t.__esModule?_(m,"default",{value:t,enumerable:!0}):m,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var T={};f(T,{DEFAULT_EXCLUDED_PATH:()=>F,IsoCodeRegex:()=>H,allowedFormats:()=>D,allowedFunctions:()=>E,defaultLocale:()=>A,fileRegex:()=>k,i18nFunctions:()=>L,modulePath:()=>P,pkgJsonHeaders:()=>j,pluginHeaders:()=>b,themeHeaders:()=>w});module.exports=h(T);var d=o(require("node:path")),x=o(require("./assets/package-i18n.js")),a=o(require("./assets/wp-plugin-i18n.js")),g=o(require("./assets/wp-theme-i18n.js"));const j=x.default,b=a.default,w=g.default,F=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],H=/-([a-z]{2}_[A-Z]{2})\.po$/,k=/#:\s*(.*?)(?::\d+)?$/,A="en_US",D=["php","js","jsx","ts","tsx","mjs","cjs"],E=new Set(["__","_x","_n","_nx"]),L={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]},P=d.default.resolve(__dirname,"..");0&&(module.exports={DEFAULT_EXCLUDED_PATH,IsoCodeRegex,allowedFormats,allowedFunctions,defaultLocale,fileRegex,i18nFunctions,modulePath,pkgJsonHeaders,pluginHeaders,themeHeaders});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var S=(t,s)=>{for(var e in s)c(t,e,{get:s[e],enumerable:!0})},g=(t,s,e,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of R(s))!P.call(t,r)&&r!==e&&c(t,r,{get:()=>s[r],enumerable:!(o=f(s,r))||o.enumerable});return t};var _=(t,s,e)=>(e=t!=null?p(E(t)):{},g(s||!t||!t.__esModule?c(e,"default",{value:t,enumerable:!0}):e,t)),D=t=>g(c({},"__esModule",{value:!0}),t);var $={};S($,{audit:()=>T,default:()=>L});module.exports=D($);var u=require("node:fs"),d=_(require("node:path"));function T(t,s){const e=new m(t.domain);if(e.auditStrings(s.blocks),console.log(`
|
|
2
|
+
Audit Complete!`),e.getResults().length===0){console.log("No issues found! \u{1F389}");try{(0,u.unlinkSync)(d.default.join(t.paths.cwd,"audit.log"))}catch{}}else{console.log(`Found ${e.getResults().length} issues!`);const o=e.getResults().join(`
|
|
3
|
+
`);console.log(o),(0,u.writeFileSync)(d.default.join(t.paths.cwd,"audit.log"),o)}}class m{SPRINTF_PLACEHOLDER_REGEX=/%(?:\d+\$)?[+-]?(?:[ 0]|\'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;UNORDERED_SPRINTF_PLACEHOLDER_REGEX=/%(?!(\d+)\$)[+-]?(?:[ 0]|\'.)?-?\d*(?:\.\d+)?[bcdeEfFgGhHosuxX]/g;projectType;results=[];constructor(s){this.projectType=s}getFileHeaders(s){return{plugin:["Plugin Name:","Plugin URI:","Description:","Author:","Author URI:","Version:","Text Domain:","Domain Path:","Network:","Requires at least:","Requires PHP:"],theme:["Theme Name:","Theme URI:","Author:","Author URI:","Description:","Version:","License:","License URI:","Text Domain:","Domain Path:","Tags:","Requires at least:","Requires PHP:"]}[s]||[]}auditStrings(s){for(const e of s){const o=e.comments?.reference||[],r=o.length>0?`(${o[0]})`:"";if(!e.msgid)continue;if((!e.comments?.extracted||e.comments.extracted.length===0)&&(e.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX)||[]).length>=1){const n=`The string "${e.msgid}" contains placeholders but has no "translators:" comment to clarify their meaning. ${r}`;this.results.push(n)}if(e.comments?.extracted&&e.comments.extracted.length>0){let n=e.comments.extracted;n=n.filter(i=>{for(const h of this.getFileHeaders(this.projectType))if(i.startsWith(h))return!1;return!0});const a=[];n=n.filter(i=>a.includes(i)?!1:(a.push(i),!0));const l=n.length;if(l>1){const i=`The string "${e.msgid}" has ${l} different translator comments. ${r}
|
|
4
|
+
${n.join(`
|
|
5
|
+
`)}`;this.results.push(i)}}if(e.msgid.trim().replace(/^(['"])(.*)\1$/s,"$2").replace(this.SPRINTF_PLACEHOLDER_REGEX,"")===""){const n=`Found string without translatable content. ${r}`;this.results.push(n)}if((e.msgid.match(this.UNORDERED_SPRINTF_PLACEHOLDER_REGEX)||[]).length>=2){const n=`Multiple placeholders should be ordered. ${r}`;this.results.push(n)}if(e.msgid_plural){const n=e.msgid.match(this.SPRINTF_PLACEHOLDER_REGEX)||[],a=e.msgid_plural.match(this.SPRINTF_PLACEHOLDER_REGEX)||[];if(n.length<a.length){const l=`Missing singular placeholder, needed for some languages. See https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#plurals ${r}`;this.results.push(l)}else{const l=[...n].sort(),i=[...a].sort();if(JSON.stringify(l)!==JSON.stringify(i)){const h=`Mismatched placeholders for singular and plural string. ${r}`;this.results.push(h)}}}}}getResults(){return this.results}}var L=m;0&&(module.exports={audit});
|
package/lib/extractors/css.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var y=Object.create;var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!M.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(r=T(t,n))||r.enumerable});return e};var $=(e,t,o)=>(o=e!=null?y(I(e)):{},d(t||!e||!e.__esModule?c(o,"default",{value:e,enumerable:!0}):o,e)),w=e=>d(c({},"__esModule",{value:!0}),e);var L={};O(L,{extractMainFileData:()=>v,generateHeader:()=>U,getAuthorFromPackage:()=>P,translationsHeaders:()=>E});module.exports=w(L);var f=$(require("node:path")),g=require("gettext-merger"),p=require("../const.js"),k=require("../fs/fs.js"),u=require("../utils/common.js"),m=require("../utils/extractors.js"),b=require("./css.js"),A=require("./php.js");function R(e,t){const r=[{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(n=>!e[n.key]||e[n.key]===n.placeholder||n.key==="version"&&e[n.key]==="0.0.1");if(r.length>0){console.error(`
|
|
2
2
|
! Missing required information for POT file header:
|
|
3
|
-
`);for(const n of
|
|
3
|
+
`);for(const n of r)console.error(` - ${n.name} is missing or has a default value (eg. version: 0.0.1")`);return console.error(`
|
|
4
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
|
-
|
|
5
|
+
For more information check the documentation at https://github.com/wp-blocks/makePot`),r.some(n=>n.key==="email")&&console.error(`
|
|
6
|
+
|
|
7
|
+
Wordpress didn't require an email field in the headers object but it's required in order to generate a valid pot file.`,`
|
|
8
|
+
Please add the email field to the package.json file (author field eg. author: "AUTHOR <EMAIL>")`,`
|
|
9
|
+
or inject those information using the --headers flag to the "makePot" command (eg. --headers=email:erik@ck.it).`,`
|
|
10
|
+
For more information check the documentation at https://github.com/wp-blocks/makePot`),r&&t&&console.error(`
|
|
11
|
+
Debug information:`,`
|
|
12
|
+
Missing fields:`,r,`
|
|
13
|
+
Header data:`,e),console.error(`
|
|
14
|
+
`),!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(/<([^>]+)>/),r=o?o[1].trim():void 0,n=e.match(/\(([^)]+)\)/),s=n?n[1].trim():void 0;let i=e.trim();return o&&(i=i.replace(o[0],"").trim()),n&&(i=i.replace(n[0],"").trim()),{name:i,email:r,website:s}}if(typeof e=="object")return{name:e.name,email:e.email,website:e.website}}function P(e){const t=["author","authors","contributors","maintainers"];for(const o of t)if(e[o]){let r;if(typeof e[o]=="string")r=h(e[o]);else if(typeof e[o]=="object"){for(const n of e[o])if(n&&(r=h(n),r))break}if(r?.name!=="AUTHOR"||r?.email!=="AUTHOR EMAIL")return r}return{name:"AUTHOR",email:"AUTHOR EMAIL"}}function x(e){const t=(0,u.getPkgJsonData)(e.paths?.cwd,"name","version","author","authors","contributors","maintainers"),o=P(t),r=f.default.basename(e.paths?.cwd||process.cwd())?.toLowerCase().replace(" ","-"),n=e?.headers?.author||o?.name,s=e?.headers?.email||o?.email,i=`${n} <${s}>`,l=e.slug||r||e.headers?.name?.toString().replace(/ /g,"-")||(e.domain==="theme"?"THEME NAME":"PLUGIN NAME"),a=`https://wordpress.org/support/${e.domain==="theme"?"themes":"plugins"}/${l}`;return{...e.headers,name:e.headers?.name||l,author:n,authorString:i,slug:l,email:s,bugs:a,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||t.version||"0.0.1",language:"en",xDomain:e.headers?.textDomain||l}}async function U(e){const t=x(e),{name:o,version:r}=(0,u.getPkgJsonData)(p.modulePath,"name","version");return R(t,e.debug)?{"Project-Id-Version":`${t.name} ${t.version}`,"Report-Msgid-Bugs-To":t.bugs,"MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","content-type":`text/plain; charset=${(0,k.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} ${r}`,Language:`${t.language}`,"X-Domain":t.xDomain}:(process.exit(1),null)}function v(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,A.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,b.extractCssThemeData)(e):console.log("No main file detected."),t}function E(e){const{domain:t,headers:o}=e,{name:r,description:n,author:s,authorUri:i,url:l}=o,a=t==="plugin"?`${e.slug}.php`:"style.css";return new g.SetOfBlocks([(0,m.buildBlock)(`Name of the ${t}`,r,[a]),(0,m.buildBlock)(`Url of the ${t}`,l,[a]),(0,m.buildBlock)(`Description of the ${t}`,n,[a]),(0,m.buildBlock)(`Author of the ${t}`,s,[a]),(0,m.buildBlock)(`Author URI of the ${t}`,i,[a])])}0&&(module.exports={extractMainFileData,generateHeader,getAuthorFromPackage,translationsHeaders});
|
package/lib/extractors/json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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 @@
|
|
|
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});
|
package/lib/extractors/php.js
CHANGED
|
@@ -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=(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")),
|
|
2
|
-
`),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r?.[1]&&r[2]){const l=(0,
|
|
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});
|
package/lib/extractors/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
[i] Loading schema from ${e}`);const
|
|
3
|
-
Failed to load schema from ${e}. Error: ${
|
|
4
|
-
Failed to load schema from ${e}. Using fallback. Error: ${
|
|
1
|
+
"use strict";var A=Object.create;var y=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var F=(n,e)=>{for(var s in e)y(n,s,{get:e[s],enumerable:!0})},j=(n,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of v(e))!B.call(n,r)&&r!==s&&y(n,r,{get:()=>e[r],enumerable:!(i=u(e,r))||i.enumerable});return n};var w=(n,e,s)=>(s=n!=null?A(C(n)):{},j(e||!n||!n.__esModule?y(s,"default",{value:n,enumerable:!0}):s,n)),O=n=>j(y({},"__esModule",{value:!0}),n);var T={};F(T,{JsonSchemaExtractor:()=>c});module.exports=O(T);var $=w(require("../assets/block-i18n.js")),R=w(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=R;static blockJsonSource="http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json";static blockJsonFallback=$;static async loadSchema(e,s){if(c.schemaCache[e])return c.schemaCache[e];try{console.log(`
|
|
2
|
+
[i] Loading schema from ${e}`);const i=await fetch(e,{responseType:"json",accept:"application/json",headers:{"Access-Control-Allow-Origin":"*"}}).then(r=>r.json()).catch(r=>{throw new Error(`
|
|
3
|
+
Failed to load schema from ${e}. Error: ${r.message}`)});return i?(console.log("Schema loaded successfully"),c.schemaCache[e]=i,i):s}catch(i){return console.error(`
|
|
4
|
+
Failed to load schema from ${e}. Using fallback. Error: ${i.message}`),c.schemaCache[e]=s,s}}static async parse(e,s,i){const r=await c.loadSchema(s.url,s.fallback);try{const l=JSON.parse(e);if(!l){console.error("Could not parse JSON.");return}return c.extractFromJsonSchema(l,r,i)}catch(l){console.error(`Error parsing JSON: ${l.message}`);return}}static extractFromJsonSchema(e,s,i={filename:void 0,addReferences:!1}){const{filename:r="block.json",addReferences:l=!1}=i,g=[];function h(t,a,p=[]){if(!(!t||!a)&&typeof t=="object"&&!Array.isArray(t)&&typeof a=="object"&&!Array.isArray(a))for(const o of Object.keys(a))o in t&&(typeof t[o]=="string"?k(t[o],a[o],r,l):Array.isArray(t[o])&&Array.isArray(a[o])?I(t[o],a[o],[...p,o],r,l):typeof t[o]=="object"&&typeof a[o]=="object"&&h(t[o],a[o],[...p,o]))}function I(t,a,p,o,m){if(a.length>0){const d=a[0];for(const f of t)if(typeof f=="string")k(f,d,o,m);else if(typeof f=="object")if(typeof d=="object")h(f,d,p);else for(const b of Object.keys(f))typeof f[b]=="string"&&k(f[b],d,o,m)}}function k(t,a,p,o){if(!t)return;const m={msgid:a,msgctxt:t};o&&(m.comments={reference:[p]}),g.push(m)}return h(e,s),g}}0&&(module.exports={JsonSchemaExtractor});
|
package/lib/extractors/text.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var n in t)s(r,n,{get:t[n],enumerable:!0})},f=(r,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of g(t))!m.call(r,e)&&e!==n&&s(r,e,{get:()=>t[e],enumerable:!(o=a(t,e))||o.enumerable});return r};var p=r=>f(s({},"__esModule",{value:!0}),r);var d={};l(d,{extractFileData:()=>u});module.exports=p(d);var c=require("../utils/common.js");function u(r,t=":"){const n={},o=(0,c.removeCommentMarkup)(r)??[];for(const e of o){const i=e.split(t);i.length!==2&&Object.values(n).length>0&&i[1]||(n[i[0]?.trim()]=i[1].trim())}return n}0&&(module.exports={extractFileData});
|
package/lib/fs/fs.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
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
|
|
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 S={};w(S,{getCharset:()=>d,getEncodingCharset:()=>h,getOutputPath:()=>$,readFileAsync:()=>O,writeFile:()=>C});module.exports=y(S);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 j(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 C(t,e){const n=j(e);if(E(i.default.dirname(n))){const o=d(e.options?.charset);console.log(`
|
|
2
|
+
Pot 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 O(t){return(0,f.readFile)(t,"utf-8")}0&&(module.exports={getCharset,getEncodingCharset,getOutputPath,readFileAsync,writeFile});
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var F=Object.create;var a=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var A=(o,r)=>{for(var e in r)a(o,e,{get:r[e],enumerable:!0})},k=(o,r,e,x)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of c(r))!u.call(o,t)&&t!==e&&a(o,t,{get:()=>r[t],enumerable:!(x=J(r,t))||x.enumerable});return o};var p=(o,r,e)=>(e=o!=null?F(l(o)):{},k(r||!o||!o.__esModule?a(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>k(a({},"__esModule",{value:!0}),o);var M={};A(M,{MakeJsonCommand:()=>d.MakeJsonCommand,StringAuditor:()=>f.default,doTree:()=>g.doTree,extractMainFileData:()=>m.extractMainFileData,generateHeader:()=>m.generateHeader,getAuthorFromPackage:()=>m.getAuthorFromPackage,makeJson:()=>i.default,makePot:()=>n.default,makePotCommand:()=>s.makePot,parseJsonFile:()=>P.parseJsonFile});module.exports=C(M);var f=p(require("./extractors/auditStrings.js")),i=p(require("./jsonCommand.js")),n=p(require("./potCommand.js")),d=require("./parser/makeJson"),s=require("./parser/makePot.js"),g=require("./parser/tree.js"),P=require("./extractors/json.js"),m=require("./extractors/headers.js");0&&(module.exports={MakeJsonCommand,StringAuditor,doTree,extractMainFileData,generateHeader,getAuthorFromPackage,makeJson,makePot,makePotCommand,parseJsonFile});
|
package/lib/jsonCommand.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=Object.create;var
|
|
1
|
+
"use strict";var p=Object.create;var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var J=(e,o)=>{for(var n in o)m(e,n,{get:o[n],enumerable:!0})},a=(e,o,n,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of k(o))!d.call(e,r)&&r!==n&&m(e,r,{get:()=>o[r],enumerable:!(t=f(o,r))||t.enumerable});return e};var M=(e,o,n)=>(n=e!=null?p(l(e)):{},a(o||!e||!e.__esModule?m(n,"default",{value:e,enumerable:!0}):n,e)),u=e=>a(m({},"__esModule",{value:!0}),e);var g={};J(g,{default:()=>c});module.exports=u(g);var i=M(require("./parser/makeJson.js")),s=require("./utils/common.js");function c(e){const o=new i.default(e);if(Object.keys(e).length>0){(0,s.printModuleInfo)();const n=new Date;o.exec().then(t=>{e.debug&&console.log(t),(0,s.printTimeElapsed)("Make-Json",n)}).catch(t=>{console.error(`\u{1FAE4} make-json - Error: ${t}`)})}}
|
package/lib/makeJson.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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);
|
|
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.js"),g=c(require("./jsonCommand.js"));const d=(0,t.getJsonArgs)();(0,g.default)(d);
|
package/lib/makePot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var i=Object.create;var
|
|
2
|
+
"use strict";var i=Object.create;var e=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var d=(r,m,o,t)=>{if(m&&typeof m=="object"||typeof m=="function")for(let s of a(m))!A.call(r,s)&&s!==o&&e(r,s,{get:()=>m[s],enumerable:!(t=n(m,s))||t.enumerable});return r};var y=(r,m,o)=>(o=r!=null?i(f(r)):{},d(m||!r||!r.__esModule?e(o,"default",{value:r,enumerable:!0}):o,r));var p=require("./cli/getArgs.js"),g=y(require("./potCommand.js"));(0,g.default)((0,p.getArgs)());
|
package/lib/parser/exec.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
|
|
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});
|
|
1
|
+
"use strict";var w=Object.create;var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var k=(t,o)=>{for(var e in o)s(t,e,{get:o[e],enumerable:!0})},c=(t,o,e,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of S(o))!$.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(i=x(o,n))||i.enumerable});return t};var A=(t,o,e)=>(e=t!=null?w(v(t)):{},c(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t)),B=t=>c(s({},"__esModule",{value:!0}),t);var H={};k(H,{exec:()=>G});module.exports=B(H);var m=A(require("node:path")),f=require("gettext-parser"),h=require("../extractors/auditStrings.js"),p=require("../extractors/headers.js"),a=require("../fs/fs.js"),r=require("../utils/common.js"),u=require("../utils/output"),d=require("./patterns.js"),g=require("./process.js"),y=require("./progress.js"),T=require("./taskRunner.js");async function G(t){t.options?.silent||(console.log("\u{1F4DD} Starting makePot for",t?.slug),(0,r.printStats)());const o=await(0,p.generateHeader)(t);let e=(0,p.translationsHeaders)(t);t.options?.silent||(0,r.outputPathRecap)(m.default.resolve(t.paths.cwd),t.patterns);const i=(0,y.initProgress)(t,0);i.start(3,1,{filename:`Resolving files in ${m.default.resolve(t.paths.cwd)}`});const n=(0,d.getPatterns)(t),l=await(0,g.processFiles)(n,t);if(i.update(2,{filename:`Found ${l.length} files... `}),e=await(0,T.taskRunner)(l,e,t,i),t.options?.skip.audit||(console.log(`
|
|
2
|
+
Audit strings...`),(0,h.audit)(t,e)),t.options?.json)return(0,u.outputJson)(t,o,e);const C={charset:(0,a.getEncodingCharset)(t.options?.charset),headers:o,translations:e.toJson()},P=f.po.compile(C).toString((0,a.getCharset)(t.options?.charset));return`${t.options?.fileComment||(0,r.getCopyright)(t.headers?.name||t.slug,t.headers?.license??"GPL v2 or later")}
|
|
3
|
+
${P}`}0&&(module.exports={exec});
|
package/lib/parser/makeJson.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.create;var m=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var D=(o,t)=>{for(var e in t)m(o,e,{get:t[e],enumerable:!0})},v=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!M.call(o,n)&&n!==e&&m(o,n,{get:()=>t[n],enumerable:!(s=b(t,n))||s.enumerable});return o};var g=(o,t,e)=>(e=o!=null?N($(o)):{},v(t||!o||!o.__esModule?m(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>v(m({},"__esModule",{value:!0}),o);var G={};D(G,{MakeJsonCommand:()=>F,default:()=>I});module.exports=C(G);var S=g(require("node:crypto")),c=g(require("node:fs")),a=g(require("node:path")),x=require("@babel/core"),k=require("gettext-parser"),h=require("glob"),p=require("../const.js"),J=require("../utils/common.js"),T=require("./tree");class F{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;stripUnused;constructor(t){if(this.sourceDir=a.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.stripUnused=t.stripUnused,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 exec(){const t=await(0,h.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,h.glob)("**/*.js",{cwd:this.source,nodir:!0}),console.log(`Found script: ${this.scriptName} in ${this.source} folder`)),typeof this.scriptName=="string"){const n=this.addPot(s,this.scriptName);n.data?e[n.filename]=n.data:console.log(`\u274C Translation strings not found in Script ${this.scriptName} in ${s} po file`)}else if(Array.isArray(this.scriptName))for(const n of this.scriptName){const i=this.addPot(s,n);i.data?e[i.filename]=i.data:console.log(`\u274C Translation strings not found in Script ${n} in ${s} po file`)}for(const[s,n]of Object.entries(e)){let i;if(this.purge)c.existsSync(a.default.join(this.destination,s))&&(console.log(`Removing ${a.default.join(this.destination,s)} as the purge option is enabled`),c.unlinkSync(a.default.join(this.destination,s))),i=JSON.stringify(n,null,this?.prettyPrint?2:0);else{const l=c.readFileSync(a.default.join(this.source,s),"utf8");i=JSON.stringify({...n,...JSON.parse(l)},null,this?.prettyPrint?2:0)}const r=a.default.join(this.destination,s);c.writeFileSync(r,i),console.log(`\u2705 JSON file written to ${r} with ${s}`)}return e}processFile(t,e,s="utf8"){const n=a.default.join(this.destination,t),i=c.readFileSync(n,s),r=this.parsePoFile(i);if(this.stripUnused){const l=this.parseScript(e),d=this.compareStrings(l.blocks,r);if(!d)return null;r.translations=d.translations}return this.convertToJed(r.headers,r.translations,e,this.extractIsoCode(n))}parsePoFile(t){return k.po.parse(t)}convertToJed(t,e,s,n){const i=(0,J.getPkgJsonData)(p.modulePath,"name","version"),r="messages",l=`${i.name}/${i.version}`,d={[r]:{"":{domain:r,lang:n||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const f of Object.keys(e)){const y=e[f];for(const u of Object.keys(y)){const P=y[u];if(u==="")continue;const j=f&&f!==""?`${f}${u}`:u;d[r][j]=P.msgstr}}return{"translation-revision-date":new Date().toISOString(),generator:l,source:a.default.join(this.sourceDir,s).replace(/\\/g,"/"),domain:r,locale_data:d}}extractIsoCode(t){const e=t.match(p.IsoCodeRegex);return e?e[1]:void 0}md5(t){return S.default.createHash("md5").update(t).digest("hex")}generateFilename(t,e){const s=this.md5(t);return e.replace(".po",`-${s}.json`)}addPot(t,e){return{filename:this.generateFilename(a.default.join(this.source,e).replace(/\\/g,"/"),t),data:this.processFile(t,e)}}compareStrings(t,e){const s={charset:e.charset,headers:{...e.headers},translations:{"":{}}};e.translations[""][""]&&(s.translations[""][""]={...e.translations[""][""]});const n=new Set(t.map(i=>i.msgid));for(const i in e.translations)if(i==="")for(const r in e.translations[i])r!==""&&n.has(r)&&(s.translations[i]||(s.translations[i]={}),s.translations[i][r]={...e.translations[i][r]});return Object.keys(s.translations[""]).length<=1?null:s}parseScript(t){const e=c.readFileSync(a.default.join(this.source,t),"utf8"),s=(0,x.transformSync)(e,{configFile:!1,presets:["@babel/preset-env"],compact:!1,comments:!0,sourceMaps:!1,plugins:[({types:n})=>({visitor:{CallExpression(i){const r=i.node.callee;if(n.isSequenceExpression(r)&&n.isMemberExpression(r.expressions[1])){const l=r.expressions[1].property;n.isIdentifier(l)&&p.allowedFunctions.has(l.name)&&(i.node.callee=n.identifier(l.name))}}}})]}).code;return(0,T.doTree)(s,t)}}var I=F;0&&(module.exports={MakeJsonCommand});
|
package/lib/parser/makePot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},u=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of f(e))!h.call(t,a)&&a!==o&&i(t,a,{get:()=>e[a],enumerable:!(r=s(e,a))||r.enumerable});return t};var x=t=>u(i({},"__esModule",{value:!0}),t);var y={};d(y,{makePot:()=>k});module.exports=x(y);var m=require("../extractors/headers.js"),c=require("../extractors/packageJson.js"),n=require("../fs/fs.js"),p=require("./exec.js");async function k(t){const e=(0,c.extractPackageJson)(t),o=(0,m.extractMainFileData)(t);return t.headers={...t?.options?.headers,...e,...o},await(0,p.exec)(t).then(r=>((0,n.writeFile)(r,t),r)).catch(r=>(console.error(r),""))}0&&(module.exports={makePot});
|
package/lib/parser/process.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.create;var m=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of j(t))!S.call(e,s)&&s!==o&&m(e,s,{get:()=>t[s],enumerable:!(i=b(t,s))||i.enumerable});return e};var x=(e,t,o)=>(o=e!=null?P(O(e)):{},d(t||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),g=e=>d(m({},"__esModule",{value:!0}),e);var A={};w(A,{processFiles:()=>v});module.exports=g(A);var r=x(require("node:path")),h=require("../const.js"),u=require("../extractors/json.js"),c=require("../fs/fs.js"),k=require("../fs/glob.js"),y=require("./tree.js");async function v(e,t,o){const i=[];let s=0;const f=(0,k.getFiles)(t,e);o&&(o.setTotal(Object.values(f).length),o.update(0,{filename:`Found ${Object.values(f).length} files`}));for await(const l of f){s++;const n=r.default.basename(l),F=r.default.extname(l).replace(/^./,""),p=r.default.resolve(t.paths.cwd,l);n==="theme.json"||n==="block.json"?i.push((0,c.readFileAsync)(p).then(a=>(0,u.parseJsonCallback)(a,t.paths.cwd,n))):h.allowedFormats.includes(F)&&i.push((0,c.readFileAsync)(p).then(a=>(0,y.doTree)(a,l))),o&&(o.update(s,{filename:n}),o.render())}return i}0&&(module.exports={processFiles});
|
package/lib/parser/progress.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var
|
|
1
|
+
"use strict";var l=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},o=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of u(r))!m.call(e,s)&&s!==t&&a(e,s,{get:()=>r[s],enumerable:!(n=g(r,s))||n.enumerable});return e};var c=(e,r,t)=>(t=e!=null?l(f(e)):{},o(r||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),B=e=>o(a({},"__esModule",{value:!0}),e);var A={};p(A,{initProgress:()=>y});module.exports=B(A);var i=c(require("cli-progress"));function y(e,r){return new i.default.SingleBar({clearOnComplete:!0,etaBuffer:1e3,hideCursor:!0,format:" {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}"},i.default.Presets.shades_classic)}0&&(module.exports={initProgress});
|
package/lib/parser/taskRunner.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var B=(o,e)=>{for(var s in e)a(o,s,{get:e[s],enumerable:!0})},i=(o,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of u(e))!k.call(o,t)&&t!==s&&a(o,t,{get:()=>e[t],enumerable:!(n=g(e,t))||n.enumerable});return o};var p=(o,e,s)=>(s=o!=null?m(h(o)):{},i(e||!o||!o.__esModule?a(s,"default",{value:o,enumerable:!0}):s,o)),S=o=>i(a({},"__esModule",{value:!0}),o);var d={};B(d,{taskRunner:()=>O});module.exports=S(d);var y=p(require("node:os")),c=p(require("node:path"));async function O(o,e,s,n){const t=[];return await Promise.allSettled(o).then(l=>l.map(r=>r.status==="fulfilled"&&r.value).filter(Boolean)).then(l=>{if(s.options?.silent!==!0)for(const r of l)r.blocks.length>0?(e.addArray(r.blocks),t.push(`\u2705 ${r.path} [${r.blocks.map(f=>f.msgid).join(", ")}]`)):t.push(`\u274C ${r.path} has no strings`)}).catch(l=>new Error(l)),n.stop(),console.log(`
|
|
2
|
+
\u{1F389} Done!`),console.log(`\u{1F4DD} Found ${Object.values(e.blocks).length} translation strings in ${c.default.resolve(s.paths.cwd)}.`),console.log(t.join(y.EOL)),e}0&&(module.exports={taskRunner});
|
package/lib/parser/tree.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var O=Object.create;var
|
|
1
|
+
"use strict";var O=Object.create;var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var n in e)m(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of K(e))!F.call(t,s)&&s!==n&&m(t,s,{get:()=>e[s],enumerable:!(o=P(e,s))||o.enumerable});return t};var j=(t,e,n)=>(n=t!=null?O(L(t)):{},b(e||!t||!t.__esModule?m(n,"default",{value:t,enumerable:!0}):n,t)),E=t=>b(m({},"__esModule",{value:!0}),t);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"),g=require("../utils/common.js");function I(t){let e=t,n=0;for(;e&&n<6;){if(e?.previousSibling?.type==="comment"&&e?.previousSibling?.text.toLowerCase().includes("translators"))return e?.previousSibling?.text?(0,g.stripTranslationMarkup)(e.previousSibling.text):void 0;n++,e=e.parent}}function U(t,e){const n=new k.default,o=(0,w.getParser)(e);if(!o)return new a.SetOfBlocks([],e);n.setLanguage(o);const s=n.parse(t),x=new a.SetOfBlocks([],e),v=e.split(".").pop()?.toLowerCase()!=="php"?"call_expression":"function_call_expression",N=["name","string","string_value","variable_name","binary_expression","member_expression","subscript_expression","shell_command_expression","function_call_expression","encapsed_string"];function _(r){if(r?.children.length)for(const l of r.children)_(l);if(r?.type===v){const l=r.firstChild?.text??null;if(l===null||!Object.keys(y.i18nFunctions).includes(l))return;const p=r.lastChild;if(p===null||p.childCount===0||p.type!=="arguments")return;const[q,C]=r.children,c={},h=y.i18nFunctions[l],$=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 ${e}`);continue}const T=h[f];c[T]=d,f+=1}const S=I(p),B=new a.Block({msgctxt:c.msgctxt,msgid:c.msgid??"",msgid_plural:c.msgid_plural,msgstr:c.msgid_plural?["",""]:[""],comments:{translator:S?[S]:void 0,reference:[`${(0,g.reverseSlashes)(e)}:${r.startPosition.row+1}`]}});x.add(B)}}return _(s.rootNode),x}0&&(module.exports={doTree});
|
package/lib/potCommand.js
CHANGED
|
@@ -1 +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.
|
|
1
|
+
"use strict";var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of s(t))!c.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(p=f(t,r))||p.enumerable});return e};var k=e=>d(n({},"__esModule",{value:!0}),e);var h={};l(h,{default:()=>a});module.exports=k(h);var i=require("./parser/makePot.js"),m=require("./utils/common.js");function a(e){if(Object.keys(e).length>0){(0,m.printModuleInfo)();const t=new Date;(0,i.makePot)(e).then(()=>{(0,m.printTimeElapsed)("Make-Pot",t)}).catch(o=>{console.error(`\u{1FAE4} Make-pot - ${o}`)})}}
|
package/lib/utils/common.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
# This file is distributed under the ${
|
|
3
|
-
|
|
1
|
+
"use strict";var f=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},a=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!k.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=d(e,r))||o.enumerable});return t};var p=(t,e,n)=>(n=t!=null?f(h(t)):{},a(e||!t||!t.__esModule?s(n,"default",{value:t,enumerable:!0}):n,t)),$=t=>a(s({},"__esModule",{value:!0}),t);var b={};y(b,{detectPatternType:()=>M,getCommentBlock:()=>P,getCopyright:()=>T,getPkgJsonData:()=>m,outputPathRecap:()=>U,printModuleInfo:()=>w,printStats:()=>j,printTimeElapsed:()=>D,removeCommentMarkup:()=>S,reverseSlashes:()=>v,stringstring:()=>F,stripTranslationMarkup:()=>C});module.exports=$(b);var g=p(require("node:fs")),i=require("node:os"),u=p(require("node:path")),l=require("../const.js");function P(t){const e=t.match(/\/\*\*?[\s\S]*?\*\//);return e!==null?e[0]:t}function S(t){return t.match(/[a-zA-Z].*/gm)}function C(t){const e=/\/\*\*?\s*(?:translators:)\s*([\s\S]*?)\s*\*\/|\/\/\s*(?:translators:)\s*(.*)$/i,n=t.match(e);return n?n[1]:t}function F(t){return typeof t=="string"?t.includes(",")?t.split(","):[t]:[]}function M(t){const e=t.includes("."),n=t.includes(u.default.sep);return t.includes("*")?"glob":!e&&!n?"directory":e&&!n?"file":"glob"}function T(t,e="GPL v2 or later"){return`# Copyright (C) ${new Date().getFullYear()} ${t}
|
|
2
|
+
# This file is distributed under the ${e} license.`}function v(t){return t.replace(/\\/g,"/")}function m(t,...e){const n={},o=u.default.join(t||process.cwd(),"package.json"),r=g.default.existsSync(o)?require(o):{};for(const c of e)r[c]&&(n[c]=r[c]);return n}function w(){const{version:t,name:e}=m(l.modulePath,"name","version");console.log(`${e} version: ${t}`)}function D(t,e,n=new Date){console.log(`
|
|
3
|
+
\u{1F680} ${t}: Task completed! ${t.split("-")[1]} file created in ${n.getTime()-e.getTime()}ms`)}function j(){console.log("Memory usage:",(process.memoryUsage().heapUsed/1024/1024).toFixed(2),"MB (Free:",((0,i.totalmem)()/1024/1024/1024).toFixed(2),`GB)
|
|
4
|
+
Cpu User:`,(process.cpuUsage().user/1e6).toFixed(2),"ms Cpu System:",(process.cpuUsage().system/1e6).toFixed(2),"ms of",(0,i.cpus)().length,"cores")}function U(t,e){return`
|
|
5
|
+
Script Path: ${t}
|
|
6
|
+
for ${e.include.join()}
|
|
7
|
+
ignoring patterns: ${e.exclude.join()}
|
|
8
|
+
`}0&&(module.exports={detectPatternType,getCommentBlock,getCopyright,getPkgJsonData,outputPathRecap,printModuleInfo,printStats,printTimeElapsed,removeCommentMarkup,reverseSlashes,stringstring,stripTranslationMarkup});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var l=(n,t)=>{for(var s in t)c(n,s,{get:t[s],enumerable:!0})},u=(n,t,s,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!g.call(n,o)&&o!==s&&c(n,o,{get:()=>t[o],enumerable:!(e=m(t,o))||e.enumerable});return n};var k=n=>u(c({},"__esModule",{value:!0}),n);var x={};l(x,{buildBlock:()=>f,getKeyByValue:()=>B,yieldParsedData:()=>a});module.exports=k(x);var r=require("gettext-merger");function B(n,t){return Object.keys(n).find(s=>n[s]===t)??void 0}const f=(n,t,s=void 0)=>{const e=new r.Block([]);return e.msgctxt=void 0,e.msgid=t,e.msgid_plural="",e.msgstr=[],e.comments={},n&&(e.comments.extracted=[n]),s?.length&&(e.comments.reference=s),e};function a(n,t,s){const e=new r.SetOfBlocks([],s);if(n.length===0)return e;e.path=s;for(const o of n){const i=f(o.msgid,o.msgctxt,o.comments?.reference);i&&e.blocks.push(i)}return e}0&&(module.exports={buildBlock,getKeyByValue,yieldParsedData});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var l=(t,n)=>{for(var r in n)i(t,r,{get:n[r],enumerable:!0})},g=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of c(n))!u.call(t,s)&&s!==r&&i(t,s,{get:()=>n[s],enumerable:!(o=m(n,s))||o.enumerable});return t};var a=(t,n,r)=>(r=t!=null?p(f(t)):{},g(n||!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),y=t=>g(i({},"__esModule",{value:!0}),t);var d={};l(d,{outputJson:()=>S});module.exports=y(d);var e=a(require("tannin"));function S(t,n,r){const o={[t.slug]:{"":n??{},...r.toJson()}};return new e.default(o).toString()}0&&(module.exports={outputJson});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-blocks/make-pot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://wp-blocks.github.io/make-pot/",
|
|
6
6
|
"description": "A Node.js script for generating a POT file from source code",
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"John Hooks <bitmachina@outlook.com> (https://johnhooks.io/)"
|
|
10
10
|
],
|
|
11
11
|
"type": "commonjs",
|
|
12
|
-
"main": "lib/
|
|
12
|
+
"main": "lib/index.js",
|
|
13
13
|
"bin": {
|
|
14
|
-
"default": "lib/cli.js",
|
|
15
|
-
"make-pot": "lib/makePot.js",
|
|
16
|
-
"makepot": "lib/makePot.js",
|
|
17
|
-
"make-json": "lib/makeJson.js",
|
|
18
|
-
"makejson": "lib/makeJson.js"
|
|
14
|
+
"default": "./lib/cli.js",
|
|
15
|
+
"make-pot": "./lib/makePot.js",
|
|
16
|
+
"makepot": "./lib/makePot.js",
|
|
17
|
+
"make-json": "./lib/makeJson.js",
|
|
18
|
+
"makejson": "./lib/makeJson.js"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=16.0.0"
|
|
@@ -48,25 +48,28 @@
|
|
|
48
48
|
"scripts": {
|
|
49
49
|
"postinstall": "npm rebuild tree-sitter tree-sitter-typescript tree-sitter-php tree-sitter-javascript --force",
|
|
50
50
|
"build": "npx esbuild ./src/**/* --format=cjs --minify --outdir=lib --platform=node",
|
|
51
|
-
"build:ci": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --platform=node",
|
|
52
51
|
"watch": "tsc --watch",
|
|
53
|
-
"lint": "npx @biomejs/biome check --
|
|
52
|
+
"lint": "npx @biomejs/biome check --write src",
|
|
54
53
|
"rm": "rmdir /s /q lib",
|
|
55
|
-
"test": "
|
|
56
|
-
"test
|
|
54
|
+
"test:build": "npx esbuild ./src/**/* --format=cjs --sourcemap --outdir=lib --platform=node",
|
|
55
|
+
"test": "npm run test:build && node --test",
|
|
56
|
+
"build:build-ci": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --external:@babel/preset-typescript --platform=node",
|
|
57
|
+
"test:ci": "npm run build:build-ci && npm run test",
|
|
57
58
|
"test:watch": "node --test --watch",
|
|
58
59
|
"test:coverage": "node --test --experimental-test-coverage"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
62
|
+
"@babel/core": "^7.27.1",
|
|
63
|
+
"@babel/preset-env": "^7.27.2",
|
|
61
64
|
"cli-progress": "^3.12.0",
|
|
62
65
|
"gettext-merger": "^1.2.1",
|
|
63
66
|
"gettext-parser": "^4.0.4",
|
|
64
67
|
"glob": "^11.0.2",
|
|
68
|
+
"tannin": "^1.2.0",
|
|
65
69
|
"tree-sitter": "^0.20.6",
|
|
66
70
|
"tree-sitter-javascript": "^0.20.4",
|
|
67
71
|
"tree-sitter-php": "^0.20.0",
|
|
68
72
|
"tree-sitter-typescript": "^0.20.5",
|
|
69
|
-
"tannin": "^1.2.0",
|
|
70
73
|
"yargs": "^17.7.1"
|
|
71
74
|
},
|
|
72
75
|
"devDependencies": {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { describe, it, beforeEach, before } = require("node:test");
|
|
2
|
+
const assert = require("node:assert");
|
|
3
|
+
const { StringAuditor } = require("../lib");
|
|
4
|
+
|
|
5
|
+
describe("Audit", () => {
|
|
6
|
+
it("should not find any errors", () => {
|
|
7
|
+
/** @type {Block[]} */
|
|
8
|
+
const translations = [
|
|
9
|
+
{
|
|
10
|
+
comments: {
|
|
11
|
+
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
12
|
+
translator: undefined,
|
|
13
|
+
},
|
|
14
|
+
msgctxt: undefined,
|
|
15
|
+
msgid: "Simple Block",
|
|
16
|
+
msgid_plural: undefined,
|
|
17
|
+
msgstr: [""],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const SA = new StringAuditor("plugin");
|
|
22
|
+
SA.auditStrings(translations);
|
|
23
|
+
|
|
24
|
+
assert.deepStrictEqual(SA.results, []);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should find an error", () => {
|
|
28
|
+
/** @type {Block[]} */
|
|
29
|
+
const translations = [
|
|
30
|
+
{
|
|
31
|
+
comments: {
|
|
32
|
+
reference: ["tests/fixtures/block/javascript.js:7"],
|
|
33
|
+
translator: undefined,
|
|
34
|
+
},
|
|
35
|
+
msgctxt: undefined,
|
|
36
|
+
msgid: "translation with multiple %s %S %s %s %d and no comments",
|
|
37
|
+
msgid_plural: undefined,
|
|
38
|
+
msgstr: [""],
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const SA = new StringAuditor("plugin");
|
|
43
|
+
SA.auditStrings(translations);
|
|
44
|
+
|
|
45
|
+
assert.deepStrictEqual(SA.results, [
|
|
46
|
+
'The string "translation with multiple %s %S %s %s %d and no comments" contains placeholders but has no "translators:" comment to clarify their meaning. (tests/fixtures/block/javascript.js:7)',
|
|
47
|
+
"Multiple placeholders should be ordered. (tests/fixtures/block/javascript.js:7)",
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { join, resolve } = require("node:path");
|
|
5
|
+
|
|
6
|
+
describe("MakeJson", () => {
|
|
7
|
+
describe("should return the used translations", () => {
|
|
8
|
+
it("compare js translations with pot file", async () => {
|
|
9
|
+
const { MakeJsonCommand } = await require("../lib");
|
|
10
|
+
// the current working directory
|
|
11
|
+
const path = "tests/fixtures/makejson";
|
|
12
|
+
const cwd = join(process.cwd(), path);
|
|
13
|
+
const makeJson = new MakeJsonCommand({
|
|
14
|
+
source: "",
|
|
15
|
+
destination: "",
|
|
16
|
+
paths: {
|
|
17
|
+
cwd: cwd,
|
|
18
|
+
source: cwd,
|
|
19
|
+
destination: cwd,
|
|
20
|
+
},
|
|
21
|
+
stripUnused: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const result = await makeJson.processFile(
|
|
25
|
+
"tests/fixtures/makejson/live-search-block-it_IT.po",
|
|
26
|
+
"tests/fixtures/makejson/script.js",
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
result["translation-revision-date"] = undefined;
|
|
30
|
+
|
|
31
|
+
assert.deepStrictEqual(result.locale_data.messages, {
|
|
32
|
+
"": {
|
|
33
|
+
domain: "messages",
|
|
34
|
+
lang: "it_IT",
|
|
35
|
+
plural_forms: "nplurals=2; plural=(n != 1);",
|
|
36
|
+
},
|
|
37
|
+
Search: ["Cerca"],
|
|
38
|
+
"Type to search…": ["Digita per cercare…"],
|
|
39
|
+
"Please add %s more characters": [
|
|
40
|
+
"Aggiungere %s altri caratteri",
|
|
41
|
+
"Aggiungere %s caratteri in più",
|
|
42
|
+
],
|
|
43
|
+
"Sorry, no results found": ["Spiacente, nessun risultato trovato"],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("compare js translations with pot file", async () => {
|
|
48
|
+
const { MakeJsonCommand } = await require("../lib");
|
|
49
|
+
// the current working directory
|
|
50
|
+
const path = "tests/fixtures/makejson-2";
|
|
51
|
+
const cwd = join(process.cwd(), path);
|
|
52
|
+
const makeJson = new MakeJsonCommand({
|
|
53
|
+
source: "",
|
|
54
|
+
destination: "",
|
|
55
|
+
paths: {
|
|
56
|
+
cwd: cwd,
|
|
57
|
+
source: cwd,
|
|
58
|
+
destination: cwd,
|
|
59
|
+
},
|
|
60
|
+
stripUnused: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const result = await makeJson.processFile(
|
|
64
|
+
"tests/fixtures/makejson-2/plugin2-it_IT.po",
|
|
65
|
+
"tests/fixtures/makejson-2/unminified.js",
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
result["translation-revision-date"] = undefined;
|
|
69
|
+
|
|
70
|
+
assert.deepStrictEqual(result.locale_data.messages, {
|
|
71
|
+
"": {
|
|
72
|
+
domain: "messages",
|
|
73
|
+
lang: "it_IT",
|
|
74
|
+
plural_forms: "nplurals=2; plural=(n != 1);",
|
|
75
|
+
},
|
|
76
|
+
"Grid view": ["Vista a griglia"],
|
|
77
|
+
"List view": ["Visualizzazione elenco"],
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const { describe, it } = require("node:test");
|
|
2
|
+
const { join } = require("node:path");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { extractMainFileData } = require("../lib");
|
|
5
|
+
|
|
6
|
+
describe("should parse plugin main file", () => {
|
|
7
|
+
describe("should parse plugin.php", () => {
|
|
8
|
+
it("correctly extracts plugin headers", async () => {
|
|
9
|
+
const fileParsed = extractMainFileData({
|
|
10
|
+
domain: "plugin",
|
|
11
|
+
paths: {
|
|
12
|
+
cwd: join(process.cwd(), "tests/fixtures/plugin"),
|
|
13
|
+
},
|
|
14
|
+
slug: "plugin",
|
|
15
|
+
});
|
|
16
|
+
assert.deepStrictEqual(fileParsed, {
|
|
17
|
+
author: "Erik yo",
|
|
18
|
+
authorUri: "https://codekraft.it",
|
|
19
|
+
description:
|
|
20
|
+
"An example plugin to demo how to do internationalization in a WordPress plugin.",
|
|
21
|
+
domainPath: "/languages",
|
|
22
|
+
license: "GPL3+",
|
|
23
|
+
licenseUri: "http://www.gnu.org/licenses/gpl-3.0.html",
|
|
24
|
+
name: "plugin",
|
|
25
|
+
textDomain: "i18n-example",
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("should parse theme main file", () => {
|
|
33
|
+
describe("should parse style.css", () => {
|
|
34
|
+
it("correctly extracts theme headers", async () => {
|
|
35
|
+
const fileParsed = extractMainFileData({
|
|
36
|
+
domain: "theme",
|
|
37
|
+
paths: {
|
|
38
|
+
cwd: join(process.cwd(), "tests/fixtures/theme"),
|
|
39
|
+
},
|
|
40
|
+
slug: "fabled-sunset",
|
|
41
|
+
});
|
|
42
|
+
assert.deepStrictEqual(fileParsed, {
|
|
43
|
+
name: "Theme name",
|
|
44
|
+
description: "Custom theme description...",
|
|
45
|
+
version: "1.0.0",
|
|
46
|
+
author: "Author Name",
|
|
47
|
+
tags: "block-patterns, full-site-editing",
|
|
48
|
+
textDomain: "fabled-sunset",
|
|
49
|
+
domainPath: "/assets/lang",
|
|
50
|
+
license: "GNU General Public License v2.0 or later",
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
package/tests/extract.test.js
CHANGED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { parseJsonFile } = require("../lib");
|
|
5
|
+
|
|
6
|
+
describe("should parse json", () => {
|
|
7
|
+
describe("should parse block.json", () => {
|
|
8
|
+
it("block.json", async () => {
|
|
9
|
+
const expected = [
|
|
10
|
+
{
|
|
11
|
+
msgid: "block title",
|
|
12
|
+
msgctxt: "my block title",
|
|
13
|
+
comments: {
|
|
14
|
+
reference: ["block.json"],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
msgid: "block description",
|
|
19
|
+
msgctxt: "my block description",
|
|
20
|
+
comments: {
|
|
21
|
+
reference: ["block.json"],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
msgid: "block keyword",
|
|
26
|
+
msgctxt: "my block keyword",
|
|
27
|
+
comments: {
|
|
28
|
+
reference: ["block.json"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
msgid: "block keyword",
|
|
33
|
+
msgctxt: "my block keyword 2",
|
|
34
|
+
comments: {
|
|
35
|
+
reference: ["block.json"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
msgid: "block keyword",
|
|
40
|
+
msgctxt: "my block keyword 3",
|
|
41
|
+
comments: {
|
|
42
|
+
reference: ["block.json"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const result = await parseJsonFile({
|
|
48
|
+
fileContent: fs.readFileSync("tests/fixtures/block/block.json", "utf8"),
|
|
49
|
+
filename: "block.json",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
assert.deepStrictEqual(result, expected);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("should parse theme.json", () => {
|
|
57
|
+
it("theme.json", async () => {
|
|
58
|
+
const expected = [
|
|
59
|
+
{
|
|
60
|
+
msgid: "Font size name",
|
|
61
|
+
msgctxt: "Extra small",
|
|
62
|
+
comments: {
|
|
63
|
+
reference: ["block.json"],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
msgid: "Font size name",
|
|
68
|
+
msgctxt: "Small",
|
|
69
|
+
comments: {
|
|
70
|
+
reference: ["block.json"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
msgid: "Font size name",
|
|
75
|
+
msgctxt: "Medium",
|
|
76
|
+
comments: {
|
|
77
|
+
reference: ["block.json"],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
msgid: "Font size name",
|
|
82
|
+
msgctxt: "Large",
|
|
83
|
+
comments: {
|
|
84
|
+
reference: ["block.json"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
msgid: "Font size name",
|
|
89
|
+
msgctxt: "Extra large",
|
|
90
|
+
comments: {
|
|
91
|
+
reference: ["block.json"],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
msgid: "Font family name",
|
|
96
|
+
msgctxt: "System Fonts",
|
|
97
|
+
comments: {
|
|
98
|
+
reference: ["block.json"],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
msgid: "Color name",
|
|
103
|
+
msgctxt: "Base",
|
|
104
|
+
comments: {
|
|
105
|
+
reference: ["block.json"],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
msgid: "Color name",
|
|
110
|
+
msgctxt: "Contrast",
|
|
111
|
+
comments: {
|
|
112
|
+
reference: ["block.json"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
msgid: "Color name",
|
|
117
|
+
msgctxt: "Accent",
|
|
118
|
+
comments: {
|
|
119
|
+
reference: ["block.json"],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
msgid: "Color name",
|
|
124
|
+
msgctxt: "Accent Two",
|
|
125
|
+
comments: {
|
|
126
|
+
reference: ["block.json"],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
msgid: "Color name",
|
|
131
|
+
msgctxt: "Accent Three",
|
|
132
|
+
comments: {
|
|
133
|
+
reference: ["block.json"],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
msgid: "Gradient name",
|
|
138
|
+
msgctxt: "Accent Two to Contrast",
|
|
139
|
+
comments: {
|
|
140
|
+
reference: ["block.json"],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
msgid: "Template part name",
|
|
145
|
+
msgctxt: "Header",
|
|
146
|
+
comments: {
|
|
147
|
+
reference: ["block.json"],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
msgid: "Template part name",
|
|
152
|
+
msgctxt: "Footer",
|
|
153
|
+
comments: {
|
|
154
|
+
reference: ["block.json"],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const result = await parseJsonFile({
|
|
160
|
+
fileContent: fs.readFileSync("tests/fixtures/fse/theme.json", "utf8"),
|
|
161
|
+
filename: "theme.json",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
assert.deepStrictEqual(result, expected);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { generateHeader, getAuthorFromPackage } = require("../lib");
|
|
5
|
+
const { join } = require("node:path");
|
|
6
|
+
|
|
7
|
+
describe("Header generation", () => {
|
|
8
|
+
describe("Should generate a valid header", () => {
|
|
9
|
+
it("from user full data", async () => {
|
|
10
|
+
const expected = {};
|
|
11
|
+
const author = await getAuthorFromPackage({
|
|
12
|
+
authors: ["John Doe <1dHsK@example.com> (http://example.com)"],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
assert.deepStrictEqual(author, {
|
|
16
|
+
name: "John Doe",
|
|
17
|
+
email: "1dHsK@example.com",
|
|
18
|
+
website: "http://example.com",
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("from user data", async () => {
|
|
23
|
+
const expected = {};
|
|
24
|
+
const author = await getAuthorFromPackage({
|
|
25
|
+
authors: ["erik"],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
assert.deepStrictEqual(author, {
|
|
29
|
+
name: "erik",
|
|
30
|
+
email: undefined,
|
|
31
|
+
website: undefined,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("from package.json data", async () => {
|
|
36
|
+
const expected = {
|
|
37
|
+
"Project-Id-Version": "My Plugin Name 1.0.0",
|
|
38
|
+
"Report-Msgid-Bugs-To": "https://wordpress.org/support/plugins/plugin",
|
|
39
|
+
"MIME-Version": "1.0",
|
|
40
|
+
"Content-Transfer-Encoding": "8bit",
|
|
41
|
+
"content-type": "text/plain; charset=iso-8859-1",
|
|
42
|
+
"plural-forms": "nplurals=2; plural=(n!=1);",
|
|
43
|
+
"POT-Creation-Date": undefined, // because the date is going to change every test
|
|
44
|
+
"PO-Revision-Date": undefined, // because the date is going to change every test
|
|
45
|
+
"Last-Translator": "John Doe <bbb@ccc.ddd>",
|
|
46
|
+
"Language-Team": "John Doe <bbb@ccc.ddd>",
|
|
47
|
+
"X-Generator": undefined, // because the version changes
|
|
48
|
+
Language: "en",
|
|
49
|
+
"X-Domain": "plugin",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = await generateHeader({
|
|
53
|
+
headers: {
|
|
54
|
+
name: "My Plugin Name",
|
|
55
|
+
author: "John Doe",
|
|
56
|
+
version: "1.0.0",
|
|
57
|
+
license: "MIT",
|
|
58
|
+
homepage: "https://example.com",
|
|
59
|
+
repository: "https://github.com/example/my-block",
|
|
60
|
+
domain: "my-plugin-text-domain",
|
|
61
|
+
},
|
|
62
|
+
paths: {
|
|
63
|
+
cwd: join(process.cwd(), "tests/fixtures/plugin"),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// remove the date "POT-Creation-Date"
|
|
68
|
+
result["POT-Creation-Date"] = undefined;
|
|
69
|
+
result["PO-Revision-Date"] = undefined;
|
|
70
|
+
result["X-Generator"] = undefined;
|
|
71
|
+
|
|
72
|
+
assert.deepStrictEqual(result, expected);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
package/lib/extractors/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const { sep } = require("node:path");
|
|
2
|
-
const { describe, it } = require("node:test");
|
|
3
|
-
const assert = require("node:assert");
|
|
4
|
-
const { parseCliArgs } = require("../lib/cli/parseCli.js");
|
|
5
|
-
const { getFiles } = require("../lib/fs/glob.js");
|
|
6
|
-
|
|
7
|
-
describe("getFiles", () => {
|
|
8
|
-
const DEFAULTS = parseCliArgs({
|
|
9
|
-
domain: "plugin",
|
|
10
|
-
slug: "plugin-slug",
|
|
11
|
-
paths: { cwd: "tests/fixtures/", out: "tests/fixtures/" },
|
|
12
|
-
options: {
|
|
13
|
-
silent: true,
|
|
14
|
-
},
|
|
15
|
-
$0: "makepot",
|
|
16
|
-
_: [0, 1],
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should retrieve a all files", async () => {
|
|
20
|
-
const args = { ...DEFAULTS, domain: "theme" };
|
|
21
|
-
const pattern = { include: ["./src/**"], exclude: [] };
|
|
22
|
-
|
|
23
|
-
const files = getFiles(args, pattern);
|
|
24
|
-
const collected = [];
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
assert.equal(!!file, true);
|
|
27
|
-
collected.push(file);
|
|
28
|
-
}
|
|
29
|
-
assert.deepStrictEqual(collected.length, 28);
|
|
30
|
-
assert.strictEqual(
|
|
31
|
-
collected.find((e) => e.includes("const.ts")),
|
|
32
|
-
"src\\const.ts",
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("Should retrieve a list of txt files based on the provided plugin pattern", async () => {
|
|
37
|
-
const args = {
|
|
38
|
-
...DEFAULTS,
|
|
39
|
-
};
|
|
40
|
-
const pattern = {
|
|
41
|
-
include: ["**/*.txt"],
|
|
42
|
-
exclude: ["node_modules", "dist"],
|
|
43
|
-
};
|
|
44
|
-
const expectedFiles = [
|
|
45
|
-
`tests${sep}fixtures${sep}file1.txt`,
|
|
46
|
-
`tests${sep}fixtures${sep}sourcedir${sep}file2.txt`,
|
|
47
|
-
`tests${sep}fixtures${sep}block${sep}readme.txt`,
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const files = getFiles(args, pattern);
|
|
51
|
-
const collected = [];
|
|
52
|
-
for (const file of files) {
|
|
53
|
-
assert.equal(!!file, true);
|
|
54
|
-
collected.push(file);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
assert.deepStrictEqual(collected, expectedFiles);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should retrieve a list of theme.json files based on the provided theme pattern", async () => {
|
|
61
|
-
const args = {
|
|
62
|
-
...DEFAULTS,
|
|
63
|
-
};
|
|
64
|
-
const pattern = {
|
|
65
|
-
include: ["tests/fixtures/sourcedir/**/*.json"],
|
|
66
|
-
exclude: [],
|
|
67
|
-
};
|
|
68
|
-
const expectedFiles = [
|
|
69
|
-
`tests${sep}fixtures${sep}sourcedir${sep}theme.json`,
|
|
70
|
-
`tests${sep}fixtures${sep}sourcedir${sep}package.json`,
|
|
71
|
-
`tests${sep}fixtures${sep}sourcedir${sep}node_modules${sep}module${sep}block.json`,
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
const files = getFiles(args, pattern);
|
|
75
|
-
const collected = [];
|
|
76
|
-
for (const file of files) {
|
|
77
|
-
assert.equal(!!file, true);
|
|
78
|
-
collected.push(file);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const fileFound = collected.filter((file) => expectedFiles.includes(file));
|
|
82
|
-
|
|
83
|
-
assert.deepStrictEqual(fileFound.length, 3);
|
|
84
|
-
});
|
|
85
|
-
});
|
package/tests/jsonParse.no.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const { describe, it } = require("node:test");
|
|
3
|
-
const assert = require("node:assert");
|
|
4
|
-
const { parseJsonFile } = require("../lib/extractors/json.js");
|
|
5
|
-
|
|
6
|
-
describe("should parse json", () => {
|
|
7
|
-
it("theme.json", async () => {
|
|
8
|
-
const expected = {
|
|
9
|
-
"block style label": {
|
|
10
|
-
label: {
|
|
11
|
-
comments: {
|
|
12
|
-
reference: "block/block.json",
|
|
13
|
-
},
|
|
14
|
-
msgctxt: "block style label",
|
|
15
|
-
msgid: "label",
|
|
16
|
-
msgstr: [],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
"block description": {
|
|
20
|
-
description: {
|
|
21
|
-
comments: {
|
|
22
|
-
reference: "block/block.json",
|
|
23
|
-
},
|
|
24
|
-
msgctxt: "block description",
|
|
25
|
-
msgid: "description",
|
|
26
|
-
msgstr: [],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
"block keyword": {
|
|
30
|
-
undefined: {
|
|
31
|
-
comments: {
|
|
32
|
-
reference: "block/block.json",
|
|
33
|
-
},
|
|
34
|
-
msgctxt: "block keyword",
|
|
35
|
-
msgid: undefined,
|
|
36
|
-
msgstr: [],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const result = await parseJsonFile({
|
|
42
|
-
fileContent: fs.readFileSync("tests/fixtures/block/block.json", "utf8"),
|
|
43
|
-
filename: "block.json",
|
|
44
|
-
filepath: "block/block.json",
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
assert.strictEqual(result, expected);
|
|
48
|
-
});
|
|
49
|
-
});
|
package/tests/wpcliCompare.no.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
const { describe, it } = require("node:test");
|
|
4
|
-
const assert = require("node:assert");
|
|
5
|
-
|
|
6
|
-
const { makePot } = require("../lib/");
|
|
7
|
-
const { getArgs } = require("../lib/cli/getArgs.js");
|
|
8
|
-
|
|
9
|
-
describe("doTree is like wpcli", () => {
|
|
10
|
-
it("Should emit a pot file for theme like the wp-cli makepot", async () => {
|
|
11
|
-
const filePath = path.join(process.cwd(), "./tests/fixtures/theme/");
|
|
12
|
-
const potPath = path.join(process.cwd(), "./tests/fixtures/theme.pot");
|
|
13
|
-
const potContent = fs.readFileSync(potPath, "utf8");
|
|
14
|
-
const args = getArgs({
|
|
15
|
-
_: [filePath],
|
|
16
|
-
});
|
|
17
|
-
const fileParsed = await makePot(args);
|
|
18
|
-
assert.deepEqual(fileParsed, potContent);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should emit a pot file for plugin like the wp-cli makepot", async () => {
|
|
22
|
-
const filePath = path.join(process.cwd(), "./tests/fixtures/vinyl/");
|
|
23
|
-
const potPath = path.join(process.cwd(), "./tests/fixtures/vinyl.pot");
|
|
24
|
-
const potContent = fs.readFileSync(potPath, "utf8");
|
|
25
|
-
|
|
26
|
-
const args = getArgs({
|
|
27
|
-
_: [filePath],
|
|
28
|
-
});
|
|
29
|
-
const fileParsed = await makePot(args);
|
|
30
|
-
assert.deepEqual(fileParsed, potContent);
|
|
31
|
-
});
|
|
32
|
-
});
|