@wp-blocks/make-pot 1.6.5 → 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.
- package/README.md +2 -2
- package/lib/assets/block-i18n.js +41 -1
- package/lib/assets/package-i18n.js +38 -1
- package/lib/assets/theme-i18n.js +110 -1
- package/lib/assets/wp-plugin-i18n.js +39 -1
- package/lib/assets/wp-theme-i18n.js +37 -1
- package/lib/cli/getArgs.js +156 -1
- package/lib/cli/getArgs.js.map +2 -2
- package/lib/cli/getJsonArgs.js +82 -1
- package/lib/cli/parseCli.js +179 -1
- package/lib/cli.js +43 -1
- package/lib/const.js +111 -1
- package/lib/extractors/auditStrings.js +177 -6
- package/lib/extractors/auditStrings.js.map +2 -2
- package/lib/extractors/css.js +69 -1
- package/lib/extractors/headers.js +253 -15
- package/lib/extractors/headers.js.map +2 -2
- package/lib/extractors/json.js +70 -1
- package/lib/extractors/packageJson.js +55 -1
- package/lib/extractors/php.js +79 -2
- package/lib/extractors/php.js.map +2 -2
- package/lib/extractors/schema.js +217 -3
- package/lib/extractors/text.js +41 -1
- package/lib/fs/fs.js +114 -2
- package/lib/fs/glob.js +103 -1
- package/lib/index.js +64 -1
- package/lib/jsonCommand.js +51 -1
- package/lib/makeJson.js +28 -1
- package/lib/makePot.js +27 -1
- package/lib/parser/exec.js +94 -3
- package/lib/parser/exec.js.map +2 -2
- package/lib/parser/makeJson.js +393 -1
- package/lib/parser/makePot.js +48 -1
- package/lib/parser/patterns.js +54 -1
- package/lib/parser/process.js +85 -1
- package/lib/parser/progress.js +57 -1
- package/lib/parser/taskRunner.js +65 -2
- package/lib/parser/taskRunner.js.map +2 -2
- package/lib/parser/tree.js +228 -2
- package/lib/potCommand.js +36 -1
- package/lib/potCommand.js.map +2 -2
- package/lib/types.js +17 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/common.js +161 -8
- package/lib/utils/common.js.map +2 -2
- package/lib/utils/extractors.js +69 -1
- package/lib/utils/output.js +59 -1
- package/lib/utils/output.js.map +3 -3
- package/package.json +1 -2
- package/tests/parse-php.test.js +47 -0
package/lib/jsonCommand.js
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
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 jsonCommand_exports = {};
|
|
30
|
+
__export(jsonCommand_exports, {
|
|
31
|
+
default: () => makeJsonCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(jsonCommand_exports);
|
|
34
|
+
var import_makeJson = __toESM(require("./parser/makeJson.js"));
|
|
35
|
+
var import_common = require("./utils/common.js");
|
|
36
|
+
function makeJsonCommand(args) {
|
|
37
|
+
const makeJson = new import_makeJson.default(args);
|
|
38
|
+
if (Object.keys(args).length > 0) {
|
|
39
|
+
(0, import_common.printModuleInfo)();
|
|
40
|
+
const timeStart = /* @__PURE__ */ new Date();
|
|
41
|
+
makeJson.exec().then((result) => {
|
|
42
|
+
if (args.debug) {
|
|
43
|
+
console.log(result);
|
|
44
|
+
}
|
|
45
|
+
(0, import_common.printTimeElapsed)("Make-Json", timeStart);
|
|
46
|
+
}).catch((error) => {
|
|
47
|
+
console.error(`\u{1FAE4} make-json - Error: ${error}`);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=jsonCommand.js.map
|
package/lib/makeJson.js
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var import_getJsonArgs = require("./cli/getJsonArgs.js");
|
|
26
|
+
var import_jsonCommand = __toESM(require("./jsonCommand.js"));
|
|
27
|
+
const args = (0, import_getJsonArgs.getJsonArgs)();
|
|
28
|
+
(0, import_jsonCommand.default)(args);
|
|
29
|
+
//# sourceMappingURL=makeJson.js.map
|
package/lib/makePot.js
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var import_getArgs = require("./cli/getArgs.js");
|
|
26
|
+
var import_potCommand = __toESM(require("./potCommand.js"));
|
|
27
|
+
(0, import_potCommand.default)((0, import_getArgs.getArgs)());
|
|
28
|
+
//# sourceMappingURL=makePot.js.map
|
package/lib/parser/exec.js
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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 exec_exports = {};
|
|
30
|
+
__export(exec_exports, {
|
|
31
|
+
exec: () => exec
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(exec_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
var import_gettext_parser = require("gettext-parser");
|
|
36
|
+
var import_auditStrings = require("../extractors/auditStrings.js");
|
|
37
|
+
var import_headers = require("../extractors/headers.js");
|
|
38
|
+
var import_fs = require("../fs/fs.js");
|
|
39
|
+
var import_common = require("../utils/common.js");
|
|
40
|
+
var import_output = require("../utils/output");
|
|
41
|
+
var import_patterns = require("./patterns.js");
|
|
42
|
+
var import_process = require("./process.js");
|
|
43
|
+
var import_progress = require("./progress.js");
|
|
44
|
+
var import_taskRunner = require("./taskRunner.js");
|
|
45
|
+
async function exec(args) {
|
|
46
|
+
if (!args.options?.silent) {
|
|
47
|
+
console.log("\u{1F4DD} Starting makePot for", args?.slug);
|
|
48
|
+
(0, import_common.printStats)();
|
|
49
|
+
}
|
|
50
|
+
const potHeader = await (0, import_headers.generateHeader)(args);
|
|
51
|
+
args.timeStart = /* @__PURE__ */ new Date();
|
|
52
|
+
let translationsUnion = (0, import_headers.translationsHeaders)(args);
|
|
53
|
+
if (!args.options?.silent)
|
|
54
|
+
(0, import_common.outputPathRecap)(import_node_path.default.resolve(args.paths.cwd), args.patterns);
|
|
55
|
+
const progressBar = (0, import_progress.initProgress)(args, 0);
|
|
56
|
+
progressBar.start(3, 1, {
|
|
57
|
+
filename: `Resolving files in ${import_node_path.default.resolve(args.paths.cwd)}`
|
|
58
|
+
});
|
|
59
|
+
const patterns = (0, import_patterns.getPatterns)(args);
|
|
60
|
+
const { tasks, processedCount, skippedCount } = await (0, import_process.processFiles)(patterns, args, progressBar);
|
|
61
|
+
progressBar.start(tasks.length, 0, {
|
|
62
|
+
filename: `Processing ${processedCount} files (${skippedCount} skipped)... `
|
|
63
|
+
});
|
|
64
|
+
translationsUnion = await (0, import_taskRunner.taskRunner)(
|
|
65
|
+
tasks,
|
|
66
|
+
translationsUnion,
|
|
67
|
+
args,
|
|
68
|
+
progressBar
|
|
69
|
+
);
|
|
70
|
+
if (!args.options?.skip.audit) {
|
|
71
|
+
console.log("\nAudit strings...");
|
|
72
|
+
(0, import_auditStrings.audit)(args, translationsUnion);
|
|
73
|
+
}
|
|
74
|
+
if (args.options?.json) {
|
|
75
|
+
return (0, import_output.outputJson)(args, potHeader, translationsUnion);
|
|
76
|
+
}
|
|
77
|
+
const getTextTranslations = {
|
|
78
|
+
charset: (0, import_fs.getEncodingCharset)(args.options?.charset),
|
|
79
|
+
headers: potHeader,
|
|
80
|
+
translations: translationsUnion.toJson()
|
|
81
|
+
};
|
|
82
|
+
const pluginTranslations = import_gettext_parser.po.compile(getTextTranslations).toString((0, import_fs.getCharset)(args.options?.charset));
|
|
83
|
+
const copyrightComment = args.options?.fileComment || (0, import_common.getCopyright)(
|
|
84
|
+
args.headers?.name || args.slug,
|
|
85
|
+
args.headers?.license ?? "GPL v2 or later"
|
|
86
|
+
);
|
|
87
|
+
return `${copyrightComment}
|
|
88
|
+
${pluginTranslations}`;
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
exec
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=exec.js.map
|
package/lib/parser/exec.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/parser/exec.ts"],
|
|
4
|
-
"sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport { type GetTextTranslations, po } from \"gettext-parser\";\r\nimport { audit } from \"../extractors/auditStrings.js\";\r\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\r\nimport { getCharset, getEncodingCharset } from \"../fs/fs.js\";\r\nimport type { Args } from \"../types.js\";\r\nimport { getCopyright, outputPathRecap, printStats } from \"../utils/common.js\";\r\nimport { outputJson } from \"../utils/output\";\r\nimport { getPatterns } from \"./patterns.js\";\r\nimport { processFiles } from \"./process.js\";\r\nimport { initProgress } from \"./progress.js\";\r\nimport { taskRunner } from \"./taskRunner.js\";\r\n\r\n/**\r\n * Runs the parser and generates the pot file or the json file based on the command line arguments\r\n *\r\n * @param {Args} args - The command line arguments\r\n * @return {Promise<string>} - A promise that resolves with the generated pot file\r\n */\r\nexport async function exec(args: Args): Promise<string> {\r\n\tif (!args.options?.silent) {\r\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\r\n\t\tprintStats();\r\n\t}\r\n\r\n\t/** The pot file header contains the data about the plugin or theme */\r\n\tconst potHeader = await generateHeader(args);\r\n\r\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\r\n\tlet translationsUnion = translationsHeaders(args);\r\n\r\n\tif (!args.options?.silent)\r\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\r\n\r\n\t/**\r\n\t * The progress bar that is used to show the progress of the extraction process.\r\n\t */\r\n\tconst progressBar: SingleBar = initProgress(args, 0);\r\n\tprogressBar.start(3, 1, {\r\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\r\n\t});\r\n\r\n\t/**\r\n\t * Extract the strings from the files\r\n\t */\r\n\tconst patterns = getPatterns(args);\r\n\tconst { tasks, processedCount, skippedCount } = await processFiles(patterns, args, progressBar);\r\n\r\n\tprogressBar.start(tasks.length, 0, {\r\n\t\tfilename: `Processing ${processedCount} files (${skippedCount} skipped)... `,\r\n\t});\r\n\r\n\ttranslationsUnion = await taskRunner(\r\n\t\ttasks,\r\n\t\ttranslationsUnion,\r\n\t\targs,\r\n\t\tprogressBar,\r\n\t);\r\n\r\n\t/**\r\n\t * Audit Strings: Strings are validated and reported to the user if they are not compliant.\r\n\t * --skip-audit flag turns this off\r\n\t **/\r\n\tif (!args.options?.skip.audit) {\r\n\t\tconsole.log(\"\\nAudit strings...\");\r\n\t\taudit(args, translationsUnion);\r\n\t}\r\n\r\n\t/** generate the JSON file based on the --json flag passed */\r\n\tif (args.options?.json) {\r\n\t\treturn outputJson(args, potHeader, translationsUnion);\r\n\t}\r\n\r\n\t/** Generate the pot file JSON */\r\n\tconst getTextTranslations: GetTextTranslations = {\r\n\t\tcharset: getEncodingCharset(args.options?.charset),\r\n\t\theaders: potHeader as { [headerName: string]: string },\r\n\t\ttranslations: translationsUnion.toJson(),\r\n\t};\r\n\r\n\t/** And then compile the pot file to a string */\r\n\tconst pluginTranslations = po\r\n\t\t.compile(getTextTranslations)\r\n\t\t.toString(getCharset(args.options?.charset));\r\n\r\n\t/** Return the pot file as a string, prefixed with the header */\r\n\tconst copyrightComment =\r\n\t\targs.options?.fileComment ||\r\n\t\tgetCopyright(\r\n\t\t\targs.headers?.name || args.slug,\r\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\r\n\t\t);\r\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\r\n}\r\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,0BAAsB;AACtB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAA0D;AAC1D,oBAA2B;AAC3B,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAQ3B,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,uCAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AACnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,EAAE,OAAO,gBAAgB,aAAa,IAAI,UAAM,6BAAa,UAAU,MAAM,WAAW;AAE9F,cAAY,MAAM,MAAM,QAAQ,GAAG;AAAA,IAClC,UAAU,cAAc,cAAc,WAAW,YAAY;AAAA,EAC9D,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAMA,MAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC9B,YAAQ,IAAI,oBAAoB;AAChC,mCAAM,MAAM,iBAAiB;AAAA,EAC9B;AAGA,MAAI,KAAK,SAAS,MAAM;AACvB,eAAO,0BAAW,MAAM,WAAW,iBAAiB;AAAA,EACrD;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK,SAAS,QAAQ,KAAK;AAAA,IAC1B,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
|
|
4
|
+
"sourcesContent": ["import path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport { type GetTextTranslations, po } from \"gettext-parser\";\r\nimport { audit } from \"../extractors/auditStrings.js\";\r\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\r\nimport { getCharset, getEncodingCharset } from \"../fs/fs.js\";\r\nimport type { Args } from \"../types.js\";\r\nimport { getCopyright, outputPathRecap, printStats } from \"../utils/common.js\";\r\nimport { outputJson } from \"../utils/output\";\r\nimport { getPatterns } from \"./patterns.js\";\r\nimport { processFiles } from \"./process.js\";\r\nimport { initProgress } from \"./progress.js\";\r\nimport { taskRunner } from \"./taskRunner.js\";\r\n\r\n/**\r\n * Runs the parser and generates the pot file or the json file based on the command line arguments\r\n *\r\n * @param {Args} args - The command line arguments\r\n * @return {Promise<string>} - A promise that resolves with the generated pot file\r\n */\r\nexport async function exec(args: Args): Promise<string> {\r\n\tif (!args.options?.silent) {\r\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\r\n\t\tprintStats();\r\n\t}\r\n\r\n\t/** The pot file header contains the data about the plugin or theme */\r\n\tconst potHeader = await generateHeader(args);\r\n\r\n\t/** Capture the start time */\r\n\targs.timeStart = new Date();\r\n\r\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\r\n\tlet translationsUnion = translationsHeaders(args);\r\n\r\n\tif (!args.options?.silent)\r\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\r\n\r\n\t/**\r\n\t * The progress bar that is used to show the progress of the extraction process.\r\n\t */\r\n\tconst progressBar: SingleBar = initProgress(args, 0);\r\n\tprogressBar.start(3, 1, {\r\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\r\n\t});\r\n\r\n\t/**\r\n\t * Extract the strings from the files\r\n\t */\r\n\tconst patterns = getPatterns(args);\r\n\tconst { tasks, processedCount, skippedCount } = await processFiles(patterns, args, progressBar);\r\n\r\n\tprogressBar.start(tasks.length, 0, {\r\n\t\tfilename: `Processing ${processedCount} files (${skippedCount} skipped)... `,\r\n\t});\r\n\r\n\ttranslationsUnion = await taskRunner(\r\n\t\ttasks,\r\n\t\ttranslationsUnion,\r\n\t\targs,\r\n\t\tprogressBar,\r\n\t);\r\n\r\n\t/**\r\n\t * Audit Strings: Strings are validated and reported to the user if they are not compliant.\r\n\t * --skip-audit flag turns this off\r\n\t **/\r\n\tif (!args.options?.skip.audit) {\r\n\t\tconsole.log(\"\\nAudit strings...\");\r\n\t\taudit(args, translationsUnion);\r\n\t}\r\n\r\n\t/** generate the JSON file based on the --json flag passed */\r\n\tif (args.options?.json) {\r\n\t\treturn outputJson(args, potHeader, translationsUnion);\r\n\t}\r\n\r\n\t/** Generate the pot file JSON */\r\n\tconst getTextTranslations: GetTextTranslations = {\r\n\t\tcharset: getEncodingCharset(args.options?.charset),\r\n\t\theaders: potHeader as { [headerName: string]: string },\r\n\t\ttranslations: translationsUnion.toJson(),\r\n\t};\r\n\r\n\t/** And then compile the pot file to a string */\r\n\tconst pluginTranslations = po\r\n\t\t.compile(getTextTranslations)\r\n\t\t.toString(getCharset(args.options?.charset));\r\n\r\n\t/** Return the pot file as a string, prefixed with the header */\r\n\tconst copyrightComment =\r\n\t\targs.options?.fileComment ||\r\n\t\tgetCopyright(\r\n\t\t\targs.headers?.name || args.slug,\r\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\r\n\t\t);\r\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,0BAAsB;AACtB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAA0D;AAC1D,oBAA2B;AAC3B,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAQ3B,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,OAAK,YAAY,oBAAI,KAAK;AAG1B,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,uCAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AACnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,EAAE,OAAO,gBAAgB,aAAa,IAAI,UAAM,6BAAa,UAAU,MAAM,WAAW;AAE9F,cAAY,MAAM,MAAM,QAAQ,GAAG;AAAA,IAClC,UAAU,cAAc,cAAc,WAAW,YAAY;AAAA,EAC9D,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAMA,MAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC9B,YAAQ,IAAI,oBAAoB;AAChC,mCAAM,MAAM,iBAAiB;AAAA,EAC9B;AAGA,MAAI,KAAK,SAAS,MAAM;AACvB,eAAO,0BAAW,MAAM,WAAW,iBAAiB;AAAA,EACrD;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK,SAAS,QAAQ,KAAK;AAAA,IAC1B,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
|
|
6
6
|
"names": ["path"]
|
|
7
7
|
}
|
package/lib/parser/makeJson.js
CHANGED
|
@@ -1 +1,393 @@
|
|
|
1
|
-
"use strict";
|
|
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
|