@wp-blocks/make-pot 1.6.4 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +2 -2
  2. package/lib/assets/block-i18n.js +41 -1
  3. package/lib/assets/package-i18n.js +38 -1
  4. package/lib/assets/theme-i18n.js +110 -1
  5. package/lib/assets/wp-plugin-i18n.js +39 -1
  6. package/lib/assets/wp-theme-i18n.js +37 -1
  7. package/lib/cli/getArgs.js +156 -1
  8. package/lib/cli/getArgs.js.map +2 -2
  9. package/lib/cli/getJsonArgs.js +82 -1
  10. package/lib/cli/parseCli.js +179 -1
  11. package/lib/cli.js +43 -1
  12. package/lib/const.js +111 -1
  13. package/lib/const.js.map +1 -1
  14. package/lib/extractors/auditStrings.js +177 -6
  15. package/lib/extractors/auditStrings.js.map +2 -2
  16. package/lib/extractors/css.js +69 -1
  17. package/lib/extractors/headers.js +253 -15
  18. package/lib/extractors/headers.js.map +2 -2
  19. package/lib/extractors/json.js +70 -1
  20. package/lib/extractors/packageJson.js +55 -1
  21. package/lib/extractors/php.js +79 -2
  22. package/lib/extractors/php.js.map +2 -2
  23. package/lib/extractors/schema.js +217 -3
  24. package/lib/extractors/text.js +41 -1
  25. package/lib/fs/fs.js +114 -2
  26. package/lib/fs/glob.js +103 -1
  27. package/lib/fs/glob.js.map +2 -2
  28. package/lib/index.js +64 -1
  29. package/lib/jsonCommand.js +51 -1
  30. package/lib/makeJson.js +28 -1
  31. package/lib/makePot.js +27 -1
  32. package/lib/parser/exec.js +94 -3
  33. package/lib/parser/exec.js.map +2 -2
  34. package/lib/parser/makeJson.js +393 -1
  35. package/lib/parser/makePot.js +48 -1
  36. package/lib/parser/patterns.js +54 -1
  37. package/lib/parser/process.js +85 -1
  38. package/lib/parser/process.js.map +2 -2
  39. package/lib/parser/progress.js +57 -1
  40. package/lib/parser/progress.js.map +2 -2
  41. package/lib/parser/taskRunner.js +65 -2
  42. package/lib/parser/taskRunner.js.map +2 -2
  43. package/lib/parser/tree.js +228 -2
  44. package/lib/parser/tree.js.map +2 -2
  45. package/lib/potCommand.js +36 -1
  46. package/lib/potCommand.js.map +2 -2
  47. package/lib/types.js +17 -1
  48. package/lib/types.js.map +1 -1
  49. package/lib/utils/common.js +161 -8
  50. package/lib/utils/common.js.map +2 -2
  51. package/lib/utils/extractors.js +69 -1
  52. package/lib/utils/output.js +59 -1
  53. package/lib/utils/output.js.map +3 -3
  54. package/package.json +3 -3
  55. package/tests/parse-php.test.js +47 -0
@@ -1 +1,393 @@
1
- "use strict";var j=Object.create;var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var D=(o,t)=>{for(var e in t)g(o,e,{get:t[e],enumerable:!0})},x=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of M(t))!$.call(o,i)&&i!==e&&g(o,i,{get:()=>t[i],enumerable:!(s=w(t,i))||s.enumerable});return o};var h=(o,t,e)=>(e=o!=null?j(E(o)):{},x(t||!o||!o.__esModule?g(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>x(g({},"__esModule",{value:!0}),o);var I={};D(I,{MakeJsonCommand:()=>T,default:()=>B});module.exports=C(I);var v=h(require("node:crypto")),d=h(require("node:fs")),a=h(require("node:path")),S=require("@babel/core"),b=require("gettext-parser"),y=require("glob"),u=require("../const.js"),k=require("../utils/common.js"),J=require("./tree");class T{source;destination;allowedFormats;purge;prettyPrint;debug;scriptName;paths;sourceDir;stripUnused;constructor(t){if(this.sourceDir=a.default.relative(t.paths.cwd,t.source??""),!d.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,y.glob)("**/*.po",{cwd:this.destination,nodir:!0});console.log("Found po files",t,"in",this.destination,"folder");const e={};for(const s of t){this.scriptName||(this.scriptName=await(0,y.glob)("**/*.js",{cwd:this.source,nodir:!0}),console.log(`Found script: ${this.scriptName} in ${this.source} folder`)),typeof this.scriptName=="string"&&(this.scriptName=[this.scriptName]);for(const i of this.scriptName){const n=this.addPot(s,i);n.data?e[n.filename]=n.data:console.log(`\u274C Translation strings not found in Script ${i} in ${s} po file`)}}for(const[s,i]of Object.entries(e)){let n;if(this.purge)d.existsSync(a.default.join(this.destination,s))&&(console.log(`Removing ${a.default.join(this.destination,s)} as the purge option is enabled`),d.unlinkSync(a.default.join(this.destination,s))),n=JSON.stringify(i,null,this?.prettyPrint?2:0);else{const c=d.readFileSync(a.default.join(this.source,s),"utf8");n=JSON.stringify({...i,...JSON.parse(c)},null,this?.prettyPrint?2:0)}const r=a.default.join(this.destination,s);d.writeFileSync(r,n),console.log(`\u2705 JSON file written to ${r} with ${s}`)}return e}processFile(t,e,s="utf8"){const i=a.default.join(this.destination,t),n=d.readFileSync(i,s),r=this.parsePoFile(n);if(this.stripUnused){const c=this.parseScript(e);if(!c)return null;const l=this.compareStrings(c.blocks,r);if(!l)return null;r.translations=l.translations}return this.convertToJed(r.headers,r.translations,e,this.extractIsoCode(i))}parsePoFile(t){return b.po.parse(t)}convertToJed(t,e,s,i){const n=(0,k.getPkgJsonData)(u.modulePath,"name","version"),r="messages",c=`${n.name}/${n.version}`,l={[r]:{"":{domain:r,lang:i||t.Language||"en",plural_forms:t["Plural-Forms"]||"nplurals=2; plural=(n != 1);"}}};for(const p of Object.keys(e)){const f=e[p];for(const m of Object.keys(f)){const F=f[m];if(m==="")continue;const N=p&&p!==""?`${p}${m}`:m;l[r][N]=F.msgstr}}return{"translation-revision-date":new Date().toISOString(),generator:c,source:a.default.join(this.sourceDir,s).replace(/\\/g,"/"),domain:r,locale_data:l}}extractIsoCode(t){const e=t.match(u.IsoCodeRegex);return e?e[1]:void 0}md5(t){return v.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 i=new Set(t.map(n=>n.msgid));for(const n in e.translations)if(n==="")for(const r in e.translations[n])r!==""&&i.has(r)&&(s.translations[n]||(s.translations[n]={}),s.translations[n][r]={...e.translations[n][r]});return Object.keys(s.translations[""]).length<=1?null:s}parseScript(t){const e=d.readFileSync(a.default.join(this.source,t),"utf8"),s=(0,S.transformSync)(e,{configFile:!1,presets:["@babel/preset-env"],compact:!1,comments:!0,sourceMaps:!1,plugins:[({types:i})=>({visitor:{CallExpression(n){const r=n.node.callee;if(i.isSequenceExpression(r)){const l=r.expressions[1];if(i.isMemberExpression(l)){const p=l.property;if(i.isIdentifier(p)){const f=p;u.allowedFunctions.has(f.name)&&(n.node.callee=i.identifier(f.name))}}}}}})]})?.code??"";return(0,J.doTree)(s,t,this.debug)}}var B=T;0&&(module.exports={MakeJsonCommand});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var makeJson_exports = {};
30
+ __export(makeJson_exports, {
31
+ MakeJsonCommand: () => MakeJsonCommand,
32
+ default: () => makeJson_default
33
+ });
34
+ module.exports = __toCommonJS(makeJson_exports);
35
+ var import_node_crypto = __toESM(require("node:crypto"));
36
+ var fs = __toESM(require("node:fs"));
37
+ var import_node_path = __toESM(require("node:path"));
38
+ var import_core = require("@babel/core");
39
+ var import_gettext_parser = require("gettext-parser");
40
+ var import_glob = require("glob");
41
+ var import_const = require("../const.js");
42
+ var import_common = require("../utils/common.js");
43
+ var import_tree = require("./tree");
44
+ class MakeJsonCommand {
45
+ /**
46
+ * The source file path.
47
+ * Should be the "build" directory containing .js files
48
+ * @private
49
+ */
50
+ source;
51
+ /**
52
+ * The destination file path.
53
+ * Should be the "languages" directory containing .po files
54
+ * @private
55
+ */
56
+ destination;
57
+ /**
58
+ * The allowed file extensions.
59
+ * @private
60
+ */
61
+ allowedFormats;
62
+ /**
63
+ * Remove old POT files.
64
+ * @private
65
+ */
66
+ purge;
67
+ /**
68
+ * Pretty print JSON.
69
+ * @private
70
+ */
71
+ prettyPrint;
72
+ /**
73
+ * Enable debug mode.
74
+ * @private
75
+ */
76
+ debug;
77
+ /**
78
+ * The script to be translated.
79
+ * @private
80
+ */
81
+ scriptName;
82
+ /**
83
+ * The paths to be translated.
84
+ * @private
85
+ */
86
+ paths;
87
+ /**
88
+ * The source directory.
89
+ * @private
90
+ */
91
+ sourceDir;
92
+ /**
93
+ * Whenever to strip unused translations from js files
94
+ * @private
95
+ */
96
+ stripUnused;
97
+ /**
98
+ * The constructor.
99
+ * @param args - The arguments to the command.
100
+ */
101
+ constructor(args) {
102
+ this.sourceDir = import_node_path.default.relative(args.paths.cwd, args.source ?? "");
103
+ if (!fs.existsSync(this.sourceDir)) {
104
+ console.error("Source directory not found", args);
105
+ throw new Error(`Source directory ${this.sourceDir} not found`);
106
+ }
107
+ this.stripUnused = args.stripUnused;
108
+ this.scriptName = args.scriptName;
109
+ this.source = args.source;
110
+ this.destination = args.destination;
111
+ this.allowedFormats = args.allowedFormats ?? [
112
+ ".ts",
113
+ ".tsx",
114
+ ".js",
115
+ ".jsx",
116
+ ".mjs",
117
+ ".cjs"
118
+ ];
119
+ this.purge = args.purge;
120
+ this.prettyPrint = args.prettyPrint;
121
+ this.debug = args.debug;
122
+ this.paths = args.paths;
123
+ }
124
+ /**
125
+ * The main function. Parses the PO files and generates the JSON files.
126
+ */
127
+ async exec() {
128
+ const files = await (0, import_glob.glob)("**/*.po", { cwd: this.destination, nodir: true });
129
+ console.log("Found po files", files, "in", this.destination, "folder");
130
+ const output = {};
131
+ for (const file of files) {
132
+ if (!this.scriptName) {
133
+ this.scriptName = await (0, import_glob.glob)("**/*.js", {
134
+ cwd: this.source,
135
+ nodir: true
136
+ });
137
+ console.log(
138
+ `Found script: ${this.scriptName} in ${this.source} folder`
139
+ );
140
+ }
141
+ if (typeof this.scriptName === "string") {
142
+ this.scriptName = [this.scriptName];
143
+ }
144
+ for (const script of this.scriptName) {
145
+ const pot = this.addPot(file, script);
146
+ if (pot.data) {
147
+ output[pot.filename] = pot.data;
148
+ } else {
149
+ console.log(
150
+ `\u274C Translation strings not found in Script ${script} in ${file} po file`
151
+ );
152
+ }
153
+ }
154
+ }
155
+ for (const [filename, content] of Object.entries(output)) {
156
+ let contentString;
157
+ if (this.purge) {
158
+ if (fs.existsSync(import_node_path.default.join(this.destination, filename))) {
159
+ console.log(
160
+ `Removing ${import_node_path.default.join(this.destination, filename)} as the purge option is enabled`
161
+ );
162
+ fs.unlinkSync(import_node_path.default.join(this.destination, filename));
163
+ }
164
+ contentString = JSON.stringify(
165
+ content,
166
+ null,
167
+ this?.prettyPrint ? 2 : 0
168
+ );
169
+ } else {
170
+ const oldJedContent = fs.readFileSync(
171
+ import_node_path.default.join(this.source, filename),
172
+ "utf8"
173
+ );
174
+ contentString = JSON.stringify(
175
+ { ...content, ...JSON.parse(oldJedContent) },
176
+ null,
177
+ this?.prettyPrint ? 2 : 0
178
+ );
179
+ }
180
+ const destinationPath = import_node_path.default.join(this.destination, filename);
181
+ fs.writeFileSync(destinationPath, contentString);
182
+ console.log(
183
+ `\u2705 JSON file written to ${destinationPath} with ${filename}`
184
+ );
185
+ }
186
+ return output;
187
+ }
188
+ /**
189
+ * Process a PO file and return the JSON data.
190
+ * @param file - The path to the PO file.
191
+ * @param script - The script to be translated.
192
+ * @param encoding - The encoding of the PO file.
193
+ */
194
+ processFile(file, script, encoding = "utf8") {
195
+ const filePath = import_node_path.default.join(this.destination, file);
196
+ const content = fs.readFileSync(filePath, encoding);
197
+ const poContent = this.parsePoFile(content);
198
+ if (this.stripUnused) {
199
+ const scriptContent = this.parseScript(script);
200
+ if (!scriptContent) {
201
+ return null;
202
+ }
203
+ const stringsNotInPoFile = this.compareStrings(
204
+ scriptContent.blocks,
205
+ poContent
206
+ );
207
+ if (!stringsNotInPoFile) {
208
+ return null;
209
+ }
210
+ poContent.translations = stringsNotInPoFile.translations;
211
+ }
212
+ return this.convertToJed(
213
+ poContent.headers,
214
+ poContent.translations,
215
+ script,
216
+ this.extractIsoCode(filePath)
217
+ // extract the ISO code from the po filename
218
+ );
219
+ }
220
+ /**
221
+ * Takes a PO file and returns the header and translations.
222
+ * @param content - The content of the PO file.
223
+ * @private
224
+ *
225
+ * @returns An object containing the header and translations.
226
+ */
227
+ parsePoFile(content) {
228
+ return import_gettext_parser.po.parse(content);
229
+ }
230
+ /**
231
+ * Converts PO data to Jed data.
232
+ * @param header - The header of the PO file.
233
+ * @param translations - The translations of the PO file.
234
+ * @param source - The source of the PO file.
235
+ * @param languageIsoCode - The ISO code of the language.
236
+ * @private
237
+ *
238
+ * @return An object containing the Jed data.
239
+ */
240
+ convertToJed(header, translations, source, languageIsoCode) {
241
+ const packageJson = (0, import_common.getPkgJsonData)(import_const.modulePath, "name", "version");
242
+ const domain = "messages";
243
+ const generator = `${packageJson.name}/${packageJson.version}`;
244
+ const jedData = {
245
+ [domain]: {
246
+ "": {
247
+ domain,
248
+ lang: languageIsoCode || header.Language || "en",
249
+ plural_forms: header["Plural-Forms"] || "nplurals=2; plural=(n != 1);"
250
+ }
251
+ }
252
+ };
253
+ for (const msgctxt of Object.keys(translations)) {
254
+ const contextTranslations = translations[msgctxt];
255
+ for (const msgid of Object.keys(contextTranslations)) {
256
+ const translation = contextTranslations[msgid];
257
+ if (msgid === "") continue;
258
+ const key = msgctxt && msgctxt !== "" ? `${msgctxt}${msgid}` : msgid;
259
+ jedData[domain][key] = translation.msgstr;
260
+ }
261
+ }
262
+ const makeJson = {
263
+ "translation-revision-date": (/* @__PURE__ */ new Date()).toISOString(),
264
+ generator,
265
+ source: import_node_path.default.join(this.sourceDir, source).replace(/\\/g, "/"),
266
+ domain,
267
+ locale_data: jedData
268
+ };
269
+ return makeJson;
270
+ }
271
+ /**
272
+ * Gets the ISO code from the filename.
273
+ * @param filename The filename to extract the ISO code from.
274
+ * @private
275
+ *
276
+ * @returns The ISO code if found, otherwise null.
277
+ */
278
+ extractIsoCode(filename) {
279
+ const match = filename.match(import_const.IsoCodeRegex);
280
+ return match ? match[1] : void 0;
281
+ }
282
+ /**
283
+ * Takes a string and returns its md5 hash.
284
+ * @param text
285
+ * @private
286
+ */
287
+ md5(text) {
288
+ return import_node_crypto.default.createHash("md5").update(text).digest("hex");
289
+ }
290
+ /**
291
+ * Generates the filename for the json file.
292
+ * @param script
293
+ * @param file
294
+ * @private
295
+ */
296
+ generateFilename(script, file) {
297
+ const scriptName = this.md5(script);
298
+ return file.replace(".po", `-${scriptName}.json`);
299
+ }
300
+ /**
301
+ * Adds a script to the output object.
302
+ * @private
303
+ *
304
+ * @param potFile - The pot file to parse.
305
+ * @param script - The script to add.
306
+ * @return {Record<string, JedData>} - The output object.
307
+ * */
308
+ addPot(potFile, script) {
309
+ const filename = this.generateFilename(
310
+ import_node_path.default.join(this.source, script).replace(/\\/g, "/"),
311
+ potFile
312
+ );
313
+ return {
314
+ filename,
315
+ data: this.processFile(potFile, script)
316
+ };
317
+ }
318
+ /**
319
+ * Compares the strings used in the script with the strings in the po file.
320
+ * @param jsArray - The strings used in the script.
321
+ * @param poObject - The content of the po file.
322
+ * @private
323
+ */
324
+ compareStrings(jsArray, poObject) {
325
+ const filteredPo = {
326
+ charset: poObject.charset,
327
+ headers: { ...poObject.headers },
328
+ translations: { "": {} }
329
+ };
330
+ if (poObject.translations[""][""]) {
331
+ filteredPo.translations[""][""] = { ...poObject.translations[""][""] };
332
+ }
333
+ const jsMessageIds = new Set(jsArray.map((item) => item.msgid));
334
+ for (const domain in poObject.translations) {
335
+ if (domain !== "") continue;
336
+ for (const msgid in poObject.translations[domain]) {
337
+ if (msgid === "") continue;
338
+ if (jsMessageIds.has(msgid)) {
339
+ if (!filteredPo.translations[domain]) {
340
+ filteredPo.translations[domain] = {};
341
+ }
342
+ filteredPo.translations[domain][msgid] = {
343
+ ...poObject.translations[domain][msgid]
344
+ };
345
+ }
346
+ }
347
+ }
348
+ if (Object.keys(filteredPo.translations[""]).length <= 1) {
349
+ return null;
350
+ }
351
+ return filteredPo;
352
+ }
353
+ parseScript(script) {
354
+ const fileContent = fs.readFileSync(import_node_path.default.join(this.source, script), "utf8");
355
+ const transformedScript = (0, import_core.transformSync)(fileContent, {
356
+ configFile: false,
357
+ presets: ["@babel/preset-env"],
358
+ compact: false,
359
+ comments: true,
360
+ sourceMaps: false,
361
+ plugins: [
362
+ ({ types: t }) => ({
363
+ visitor: {
364
+ CallExpression(path2) {
365
+ const callee = path2.node.callee;
366
+ if (t.isSequenceExpression(callee)) {
367
+ const seqExpr = callee;
368
+ const secondExpression = seqExpr.expressions[1];
369
+ if (t.isMemberExpression(secondExpression)) {
370
+ const memberExpr = secondExpression;
371
+ const property = memberExpr.property;
372
+ if (t.isIdentifier(property)) {
373
+ const identifier = property;
374
+ if (import_const.allowedFunctions.has(identifier.name)) {
375
+ path2.node.callee = t.identifier(identifier.name);
376
+ }
377
+ }
378
+ }
379
+ }
380
+ }
381
+ }
382
+ })
383
+ ]
384
+ })?.code ?? "";
385
+ return (0, import_tree.doTree)(transformedScript, script, this.debug);
386
+ }
387
+ }
388
+ var makeJson_default = MakeJsonCommand;
389
+ // Annotate the CommonJS export names for ESM import in node:
390
+ 0 && (module.exports = {
391
+ MakeJsonCommand
392
+ });
393
+ //# sourceMappingURL=makeJson.js.map
@@ -1 +1,48 @@
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});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var makePot_exports = {};
20
+ __export(makePot_exports, {
21
+ makePot: () => makePot
22
+ });
23
+ module.exports = __toCommonJS(makePot_exports);
24
+ var import_headers = require("../extractors/headers.js");
25
+ var import_packageJson = require("../extractors/packageJson.js");
26
+ var import_fs = require("../fs/fs.js");
27
+ var import_exec = require("./exec.js");
28
+ async function makePot(args) {
29
+ const pkgData = (0, import_packageJson.extractPackageJson)(args);
30
+ const metadata = (0, import_headers.extractMainFileData)(args);
31
+ args.headers = {
32
+ ...args?.options?.headers,
33
+ ...pkgData,
34
+ ...metadata
35
+ };
36
+ return await (0, import_exec.exec)(args).then((jsonTranslations) => {
37
+ (0, import_fs.writeFile)(jsonTranslations, args);
38
+ return jsonTranslations;
39
+ }).catch((error) => {
40
+ console.error(error);
41
+ return "";
42
+ });
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ makePot
47
+ });
48
+ //# sourceMappingURL=makePot.js.map
@@ -1 +1,54 @@
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
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var patterns_exports = {};
20
+ __export(patterns_exports, {
21
+ getPatterns: () => getPatterns
22
+ });
23
+ module.exports = __toCommonJS(patterns_exports);
24
+ function getPatterns(args) {
25
+ const pattern = {
26
+ include: args.patterns.include || [],
27
+ exclude: args.patterns.exclude || [],
28
+ mergePaths: args.patterns.mergePaths,
29
+ subtractPaths: args.patterns.subtractPaths,
30
+ subtractAndMerge: args.patterns.subtractAndMerge
31
+ };
32
+ if (args.options) {
33
+ if (args.options.skip.blade) {
34
+ pattern.exclude.push("**/*.blade.php");
35
+ } else if (args.options.skip.php) {
36
+ pattern.exclude.push("**/*.php", "**/*.blade.php");
37
+ }
38
+ if (args.options.skip.js) {
39
+ pattern.exclude.push("**/*.{js,jsx,ts,tsx,mjs,cjs}");
40
+ }
41
+ if (args.options.skip.blockJson) {
42
+ pattern.exclude.push("block.json");
43
+ }
44
+ if (args.options.skip.themeJson) {
45
+ pattern.exclude.push("theme.json");
46
+ }
47
+ }
48
+ return pattern;
49
+ }
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ getPatterns
53
+ });
54
+ //# sourceMappingURL=patterns.js.map
@@ -1 +1,85 @@
1
- "use strict";var S=Object.create;var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var O=(t,e)=>{for(var o in e)f(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!x.call(t,s)&&s!==o&&f(t,s,{get:()=>e[s],enumerable:!(i=b(e,s))||i.enumerable});return t};var j=(t,e,o)=>(o=t!=null?S(w(t)):{},d(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),A=t=>d(f({},"__esModule",{value:!0}),t);var $={};O($,{processFiles:()=>T});module.exports=A($);var n=j(require("node:path")),h=require("../const.js"),u=require("../extractors/json.js"),c=require("../fs/fs.js"),k=require("../fs/glob.js"),P=require("./tree.js");async function T(t,e,o){const i=[];let s=0;const r=await(0,k.getFiles)(e,t);o&&(o.setTotal(r.length),o.update(0,{filename:`Found ${r.length} files`}));for(const l of r){s++;const a=n.default.basename(l),y=n.default.extname(l).replace(/^./,""),p=n.default.resolve(e.paths.cwd,l);if(a==="theme.json"||a==="block.json")i.push((0,c.readFileAsync)(p).then(m=>(0,u.parseJsonCallback)(m,e.paths.cwd,a)));else if(h.allowedFormats.includes(y)){const m=(0,c.readFileAsync)(p).then(F=>(0,P.doTree)(F,l,e.debug,e));m&&i.push(m)}o&&o.update(s,{filename:`${n.default.basename(l)} (Valid: ${i.length})`})}return i}0&&(module.exports={processFiles});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var process_exports = {};
30
+ __export(process_exports, {
31
+ processFiles: () => processFiles
32
+ });
33
+ module.exports = __toCommonJS(process_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_json = require("../extractors/json.js");
36
+ var import_fs = require("../fs/fs.js");
37
+ var import_glob = require("../fs/glob.js");
38
+ var import_tree = require("./tree.js");
39
+ var import_const = require("../const");
40
+ async function processFiles(patterns, args, progressBar) {
41
+ const tasks = [];
42
+ let processedCount = 0;
43
+ let skippedCount = 0;
44
+ const files = await (0, import_glob.getFiles)(args, patterns);
45
+ if (progressBar) {
46
+ progressBar.setTotal(files.length);
47
+ progressBar.update(0, {
48
+ filename: `Found ${files.length} files`
49
+ });
50
+ }
51
+ for (const file of files) {
52
+ const filename = import_node_path.default.basename(file);
53
+ const ext = import_node_path.default.extname(file).replace(/^./, "");
54
+ const fileRealPath = import_node_path.default.resolve(args.paths.cwd, file);
55
+ if (filename === "theme.json" || filename === "block.json") {
56
+ processedCount++;
57
+ tasks.push(
58
+ (0, import_fs.readFileAsync)(fileRealPath).then(
59
+ (sourceCode) => (0, import_json.parseJsonCallback)(sourceCode, args.paths.cwd, filename)
60
+ )
61
+ );
62
+ } else if (import_const.allowedFormats.includes(ext)) {
63
+ processedCount++;
64
+ const fileTree = (0, import_fs.readFileAsync)(fileRealPath).then(
65
+ (content) => (0, import_tree.doTree)(content, file, args.debug, args)
66
+ );
67
+ if (fileTree) {
68
+ tasks.push(fileTree);
69
+ }
70
+ } else {
71
+ skippedCount++;
72
+ }
73
+ if (progressBar) {
74
+ progressBar.update(processedCount + skippedCount, {
75
+ filename: `${import_node_path.default.basename(file)} (Processed: ${processedCount} | Skipped: ${skippedCount})`
76
+ });
77
+ }
78
+ }
79
+ return { tasks, processedCount, skippedCount };
80
+ }
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ processFiles
84
+ });
85
+ //# sourceMappingURL=process.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/parser/process.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport { allowedFormats } from \"../const.js\";\r\nimport { parseJsonCallback } from \"../extractors/json.js\";\r\nimport { readFileAsync } from \"../fs/fs.js\";\r\nimport { getFiles } from \"../fs/glob.js\";\r\nimport type { Args, Patterns } from \"../types.js\";\r\nimport { doTree } from \"./tree.js\";\r\n\r\n/**\r\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\r\n *\r\n * @param patterns\r\n * @param {Args} args - The arguments for processing the files.\r\n * @param progressBar - The progress bar element.\r\n * @return {Promise<SetOfBlocks[]>} - An array of promises that resolve to TranslationStrings.\r\n */\r\nexport async function processFiles(\r\n\tpatterns: Patterns,\r\n\targs: Args,\r\n\tprogressBar?: SingleBar,\r\n): Promise<Promise<SetOfBlocks>[]> {\r\n\tconst tasks: Promise<SetOfBlocks>[] = [];\r\n\tlet processedFilesCount = 0;\r\n\r\n\tconst files = await getFiles(args, patterns);\r\n\r\n\tif (progressBar) {\r\n\t\tprogressBar.setTotal(files.length);\r\n\t\tprogressBar.update(0, {\r\n\t\t\tfilename: `Found ${files.length} files`,\r\n\t\t});\r\n\t}\r\n\r\n\t// Loop through the array\r\n\tfor (const file of files) {\r\n\t\tprocessedFilesCount++;\r\n\t\tconst filename = path.basename(file);\r\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\r\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\r\n\r\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\r\n\t\t\ttasks.push(\r\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\r\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t} else if (allowedFormats.includes(ext)) {\r\n\t\t\tconst fileTree = readFileAsync(fileRealPath).then((content) =>\r\n\t\t\t\tdoTree(content, file, args.debug, args),\r\n\t\t\t);\r\n\t\t\tif (fileTree) {\r\n\t\t\t\ttasks.push(fileTree as Promise<SetOfBlocks>);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (progressBar) {\r\n\t\t\tprogressBar.update(processedFilesCount, {\r\n\t\t\t\tfilename: `${path.basename(file)} (Valid: ${tasks.length})`\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\treturn tasks;\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,mBAA+B;AAC/B,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AAUvB,eAAsB,aACrB,UACA,MACA,aACkC;AAClC,QAAM,QAAgC,CAAC;AACvC,MAAI,sBAAsB;AAE1B,QAAM,QAAQ,UAAM,sBAAS,MAAM,QAAQ;AAE3C,MAAI,aAAa;AAChB,gBAAY,SAAS,MAAM,MAAM;AACjC,gBAAY,OAAO,GAAG;AAAA,MACrB,UAAU,SAAS,MAAM,MAAM;AAAA,IAChC,CAAC;AAAA,EACF;AAGA,aAAW,QAAQ,OAAO;AACzB;AACA,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC,YAAM,eAAW,yBAAc,YAAY,EAAE;AAAA,QAAK,CAAC,gBAClD,oBAAO,SAAS,MAAM,KAAK,OAAO,IAAI;AAAA,MACvC;AACA,UAAI,UAAU;AACb,cAAM,KAAK,QAAgC;AAAA,MAC5C;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,qBAAqB;AAAA,QACvC,UAAU,GAAG,iBAAAA,QAAK,SAAS,IAAI,CAAC,YAAY,MAAM,MAAM;AAAA,MACzD,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["import path from 'node:path'\r\nimport type { SingleBar } from 'cli-progress'\r\nimport type { SetOfBlocks } from 'gettext-merger'\r\nimport { parseJsonCallback } from '../extractors/json.js'\r\nimport { readFileAsync } from '../fs/fs.js'\r\nimport { getFiles } from '../fs/glob.js'\r\nimport type { Args, Patterns } from '../types.js'\r\nimport { doTree } from './tree.js'\r\nimport { allowedFormats } from '../const'\r\n\r\n/**\r\n * The result of processing files.\r\n */\r\nexport interface ProcessResult {\r\n\ttasks: Promise<SetOfBlocks>[];\r\n\tprocessedCount: number;\r\n\tskippedCount: number;\r\n}\r\n\r\n/**\r\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\r\n *\r\n * @param patterns\r\n * @param {Args} args - The arguments for processing the files.\r\n * @param progressBar - The progress bar element.\r\n * @return {Promise<ProcessResult>} - The tasks and file counts.\r\n */\r\nexport async function processFiles(\r\n\tpatterns: Patterns,\r\n\targs: Args,\r\n\tprogressBar?: SingleBar,\r\n): Promise<ProcessResult> {\r\n\tconst tasks: Promise<SetOfBlocks>[] = [];\r\n\tlet processedCount = 0;\r\n\tlet skippedCount = 0;\r\n\r\n\tconst files = await getFiles(args, patterns);\r\n\r\n\tif (progressBar) {\r\n\t\tprogressBar.setTotal(files.length);\r\n\t\tprogressBar.update(0, {\r\n\t\t\tfilename: `Found ${files.length} files`,\r\n\t\t});\r\n\t}\r\n\r\n\t// Loop through the array\r\n\tfor (const file of files) {\r\n\t\tconst filename = path.basename(file);\r\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\r\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\r\n\r\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\r\n\t\t\tprocessedCount++;\r\n\t\t\ttasks.push(\r\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\r\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t} else if (allowedFormats.includes(ext)) {\r\n\t\t\tprocessedCount++;\r\n\t\t\tconst fileTree = readFileAsync(fileRealPath).then((content) =>\r\n\t\t\t\tdoTree(content, file, args.debug, args),\r\n\t\t\t);\r\n\t\t\tif (fileTree) {\r\n\t\t\t\ttasks.push(fileTree as Promise<SetOfBlocks>);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tskippedCount++;\r\n\t\t}\r\n\r\n\t\tif (progressBar) {\r\n\t\t\tprogressBar.update(processedCount + skippedCount, {\r\n\t\t\t\tfilename: `${path.basename(file)} (Processed: ${processedCount} | Skipped: ${skippedCount})`,\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\treturn { tasks, processedCount, skippedCount };\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AACvB,mBAA+B;AAmB/B,eAAsB,aACrB,UACA,MACA,aACyB;AACzB,QAAM,QAAgC,CAAC;AACvC,MAAI,iBAAiB;AACrB,MAAI,eAAe;AAEnB,QAAM,QAAQ,UAAM,sBAAS,MAAM,QAAQ;AAE3C,MAAI,aAAa;AAChB,gBAAY,SAAS,MAAM,MAAM;AACjC,gBAAY,OAAO,GAAG;AAAA,MACrB,UAAU,SAAS,MAAM,MAAM;AAAA,IAChC,CAAC;AAAA,EACF;AAGA,aAAW,QAAQ,OAAO;AACzB,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D;AACA,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC;AACA,YAAM,eAAW,yBAAc,YAAY,EAAE;AAAA,QAAK,CAAC,gBAClD,oBAAO,SAAS,MAAM,KAAK,OAAO,IAAI;AAAA,MACvC;AACA,UAAI,UAAU;AACb,cAAM,KAAK,QAAgC;AAAA,MAC5C;AAAA,IACD,OAAO;AACN;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,iBAAiB,cAAc;AAAA,QACjD,UAAU,GAAG,iBAAAA,QAAK,SAAS,IAAI,CAAC,gBAAgB,cAAc,eAAe,YAAY;AAAA,MAC1F,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO,EAAE,OAAO,gBAAgB,aAAa;AAC9C;",
6
6
  "names": ["path"]
7
7
  }