@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/parser/makePot.js
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
package/lib/parser/patterns.js
CHANGED
|
@@ -1 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
package/lib/parser/process.js
CHANGED
|
@@ -1 +1,85 @@
|
|
|
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 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
|
package/lib/parser/progress.js
CHANGED
|
@@ -1 +1,57 @@
|
|
|
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 progress_exports = {};
|
|
30
|
+
__export(progress_exports, {
|
|
31
|
+
initProgress: () => initProgress
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(progress_exports);
|
|
34
|
+
var import_cli_progress = __toESM(require("cli-progress"));
|
|
35
|
+
function initProgress(_args, _filesCount) {
|
|
36
|
+
const FILENAME_WIDTH = 40;
|
|
37
|
+
return new import_cli_progress.default.SingleBar(
|
|
38
|
+
{
|
|
39
|
+
clearOnComplete: true,
|
|
40
|
+
etaBuffer: 1e3,
|
|
41
|
+
hideCursor: true,
|
|
42
|
+
format: (options, params, payload) => {
|
|
43
|
+
const bar = options.barCompleteString?.substring(0, Math.round(params.progress * (options.barsize ?? 40))) ?? "";
|
|
44
|
+
const emptyBar = options.barIncompleteString?.substring(0, (options.barsize ?? 40) - bar.length) ?? "";
|
|
45
|
+
const pct = Math.round(params.progress * 100);
|
|
46
|
+
const filename = (payload.filename || "").substring(0, FILENAME_WIDTH).padEnd(FILENAME_WIDTH);
|
|
47
|
+
return ` ${bar}${emptyBar} ${pct}% | ETA: ${params.eta}s | ${filename} | ${params.value}/${params.total}`;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
import_cli_progress.default.Presets.shades_classic
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
initProgress
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=progress.js.map
|
package/lib/parser/taskRunner.js
CHANGED
|
@@ -1,2 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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 taskRunner_exports = {};
|
|
30
|
+
__export(taskRunner_exports, {
|
|
31
|
+
taskRunner: () => taskRunner
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(taskRunner_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
async function taskRunner(tasks, destination, args, progressBar) {
|
|
36
|
+
const tasksWithProgress = tasks.map(
|
|
37
|
+
(task) => task.then((result) => {
|
|
38
|
+
progressBar.increment({
|
|
39
|
+
filename: result.path ? import_node_path.default.basename(result.path) : ""
|
|
40
|
+
});
|
|
41
|
+
return result;
|
|
42
|
+
}).catch((err) => {
|
|
43
|
+
progressBar.increment({ filename: "error" });
|
|
44
|
+
throw err;
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
await Promise.allSettled(tasksWithProgress).then((strings) => {
|
|
48
|
+
return strings.map((block) => block.status === "fulfilled" && block.value).filter(Boolean);
|
|
49
|
+
}).then((consolidated) => {
|
|
50
|
+
for (const result of consolidated) {
|
|
51
|
+
if (result.blocks.length > 0) {
|
|
52
|
+
destination.addArray(result.blocks);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}).catch((err) => {
|
|
56
|
+
return new Error(err);
|
|
57
|
+
});
|
|
58
|
+
progressBar.stop();
|
|
59
|
+
return destination;
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
taskRunner
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=taskRunner.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/parser/taskRunner.ts"],
|
|
4
|
-
"sourcesContent": ["import * as os from \"node:os\";\r\nimport path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Task runner for the extraction process.\r\n *\r\n * @param tasks - The tasks to run\r\n * @param destination - The destination\r\n * @param args - The command line arguments\r\n * @param progressBar\r\n */\r\nexport async function taskRunner(\r\n\ttasks: Promise<SetOfBlocks>[],\r\n\tdestination: SetOfBlocks,\r\n\targs: Args,\r\n\tprogressBar: SingleBar,\r\n) {\r\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import * as os from \"node:os\";\r\nimport path from \"node:path\";\r\nimport type { SingleBar } from \"cli-progress\";\r\nimport type { SetOfBlocks } from \"gettext-merger\";\r\nimport type { Args } from \"../types.js\";\r\n\r\n/**\r\n * Task runner for the extraction process.\r\n *\r\n * @param tasks - The tasks to run\r\n * @param destination - The destination\r\n * @param args - The command line arguments\r\n * @param progressBar\r\n */\r\nexport async function taskRunner(\r\n\ttasks: Promise<SetOfBlocks>[],\r\n\tdestination: SetOfBlocks,\r\n\targs: Args,\r\n\tprogressBar: SingleBar,\r\n) {\r\n\t// Create a new array of promises that update the bar when they finish.\r\n\tconst tasksWithProgress = tasks.map((task) =>\r\n\t\ttask.then((result) => {\r\n\t\t\tprogressBar.increment({\r\n\t\t\t\tfilename: result.path ? path.basename(result.path) : \"\",\r\n\t\t\t});\r\n\t\t\treturn result;\r\n\t\t}).catch((err) => {\r\n\t\t\tprogressBar.increment({ filename: \"error\" });\r\n\t\t\tthrow err;\r\n\t\t})\r\n\t);\r\n\tawait Promise.allSettled(tasksWithProgress)\r\n\t\t.then((strings) => {\r\n\t\t\t/**\r\n\t\t\t * Return the strings that are not rejected (they are fulfilled)\r\n\t\t\t */\r\n\t\t\treturn strings\r\n\t\t\t\t.map((block) => block.status === \"fulfilled\" && block.value)\r\n\t\t\t\t.filter(Boolean) as SetOfBlocks[]; // remove nullish\r\n\t\t})\r\n\t\t.then((consolidated) => {\r\n\t\t\t/** Log the results */\r\n\t\t\tfor (const result of consolidated) {\r\n\t\t\t\tif (result.blocks.length > 0) {\r\n\t\t\t\t\t/**\r\n\t\t\t\t\t * Add the strings to the destination set\r\n\t\t\t\t\t */\r\n\t\t\t\t\tdestination.addArray(result.blocks);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t})\r\n\t\t.catch((err) => {\r\n\t\t\treturn new Error(err);\r\n\t\t});\r\n\r\n\tprogressBar.stop();\r\n\r\n\treturn destination;\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AAED,QAAM,oBAAoB,MAAM;AAAA,IAAI,CAAC,SACpC,KAAK,KAAK,CAAC,WAAW;AACrB,kBAAY,UAAU;AAAA,QACrB,UAAU,OAAO,OAAO,iBAAAA,QAAK,SAAS,OAAO,IAAI,IAAI;AAAA,MACtD,CAAC;AACD,aAAO;AAAA,IACR,CAAC,EAAE,MAAM,CAAC,QAAQ;AACjB,kBAAY,UAAU,EAAE,UAAU,QAAQ,CAAC;AAC3C,YAAM;AAAA,IACP,CAAC;AAAA,EACF;AACA,QAAM,QAAQ,WAAW,iBAAiB,EACxC,KAAK,CAAC,YAAY;AAIlB,WAAO,QACL,IAAI,CAAC,UAAU,MAAM,WAAW,eAAe,MAAM,KAAK,EAC1D,OAAO,OAAO;AAAA,EACjB,CAAC,EACA,KAAK,CAAC,iBAAiB;AAEvB,eAAW,UAAU,cAAc;AAClC,UAAI,OAAO,OAAO,SAAS,GAAG;AAI7B,oBAAY,SAAS,OAAO,MAAM;AAAA,MACnC;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,SAAO;AACR;",
|
|
6
6
|
"names": ["path"]
|
|
7
7
|
}
|
package/lib/parser/tree.js
CHANGED
|
@@ -1,2 +1,228 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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 tree_exports = {};
|
|
30
|
+
__export(tree_exports, {
|
|
31
|
+
doTree: () => doTree
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(tree_exports);
|
|
34
|
+
var import_tree_sitter = __toESM(require("tree-sitter"));
|
|
35
|
+
var import_const = require("../const.js");
|
|
36
|
+
var import_gettext_merger = require("gettext-merger");
|
|
37
|
+
var import_glob = require("../fs/glob.js");
|
|
38
|
+
var import_common = require("../utils/common.js");
|
|
39
|
+
function collectComments(node) {
|
|
40
|
+
let currentNode = node;
|
|
41
|
+
let depth = 0;
|
|
42
|
+
while (currentNode && depth < 6) {
|
|
43
|
+
if (currentNode.previousSibling?.type === "comment" && currentNode.previousSibling.text.toLowerCase().includes("translators")) {
|
|
44
|
+
return (0, import_common.stripTranslationMarkup)(currentNode.previousSibling.text);
|
|
45
|
+
}
|
|
46
|
+
depth++;
|
|
47
|
+
currentNode = currentNode.parent;
|
|
48
|
+
}
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const escapeMap = {
|
|
52
|
+
"n": "\n",
|
|
53
|
+
"r": "\r",
|
|
54
|
+
"t": " ",
|
|
55
|
+
"f": "\f",
|
|
56
|
+
"v": "\v",
|
|
57
|
+
"0": "\0",
|
|
58
|
+
"\\": "\\",
|
|
59
|
+
'"': '"',
|
|
60
|
+
"'": "'",
|
|
61
|
+
"$": "$",
|
|
62
|
+
"e": "\x1B"
|
|
63
|
+
};
|
|
64
|
+
function resolveStringValue(node) {
|
|
65
|
+
if (node.type === "encapsed_string") {
|
|
66
|
+
return node.children.map((child) => {
|
|
67
|
+
if (child.type === "escape_sequence") {
|
|
68
|
+
const ch = child.text.slice(1);
|
|
69
|
+
return ch in escapeMap ? escapeMap[ch] : child.text;
|
|
70
|
+
}
|
|
71
|
+
if (child.type === "string_content") {
|
|
72
|
+
return child.text;
|
|
73
|
+
}
|
|
74
|
+
if (child.type === "variable_name") {
|
|
75
|
+
return child.text;
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
}).join("");
|
|
79
|
+
}
|
|
80
|
+
if (node.type === "string") {
|
|
81
|
+
const text = node.text;
|
|
82
|
+
if (text.startsWith("'") && text.endsWith("'") || text.startsWith('"') && text.endsWith('"')) {
|
|
83
|
+
const isDouble = text.startsWith('"');
|
|
84
|
+
let inner = text.slice(1, -1);
|
|
85
|
+
if (isDouble) {
|
|
86
|
+
inner = inner.replace(
|
|
87
|
+
/\\(.)/g,
|
|
88
|
+
(_match, ch) => ch in escapeMap ? escapeMap[ch] : _match
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
inner = inner.replace(/\\'/g, "'").replace(/\\\\/g, "\\");
|
|
92
|
+
}
|
|
93
|
+
return inner;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return node.text;
|
|
97
|
+
}
|
|
98
|
+
function doTree(sourceCode, filepath, debugEnabled, args) {
|
|
99
|
+
const parser = new import_tree_sitter.default();
|
|
100
|
+
const parserExt = (0, import_glob.getParser)(filepath);
|
|
101
|
+
if (!parserExt) return new import_gettext_merger.SetOfBlocks([], filepath);
|
|
102
|
+
parser.setLanguage(parserExt);
|
|
103
|
+
const gettextTranslations = new import_gettext_merger.SetOfBlocks([], filepath);
|
|
104
|
+
const typeToMatch = filepath.split(".").pop()?.toLowerCase() !== "php" ? "call_expression" : "function_call_expression";
|
|
105
|
+
const stringType = [
|
|
106
|
+
"name",
|
|
107
|
+
"string",
|
|
108
|
+
"string_value",
|
|
109
|
+
"variable_name",
|
|
110
|
+
"binary_expression",
|
|
111
|
+
"member_expression",
|
|
112
|
+
"subscript_expression",
|
|
113
|
+
"shell_command_expression",
|
|
114
|
+
"function_call_expression",
|
|
115
|
+
"encapsed_string"
|
|
116
|
+
];
|
|
117
|
+
function traverse(node) {
|
|
118
|
+
if (node?.children.length) {
|
|
119
|
+
for (const child of node.children) {
|
|
120
|
+
traverse(child);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (node?.type === typeToMatch) {
|
|
124
|
+
const functionName = node.firstChild?.text ?? null;
|
|
125
|
+
if (functionName === null || !Object.keys(import_const.i18nFunctions).includes(functionName)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const argsNode = node.childForFieldName("arguments");
|
|
129
|
+
if (argsNode === null || argsNode.childCount === 0 || argsNode.type !== "arguments") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!argsNode) return;
|
|
133
|
+
const translation = {
|
|
134
|
+
// WordPress default text domain is 'default'
|
|
135
|
+
text_domain: "default"
|
|
136
|
+
};
|
|
137
|
+
const translationKeys = import_const.i18nFunctions[functionName];
|
|
138
|
+
const children = argsNode.children;
|
|
139
|
+
let translationKeyIndex = 0;
|
|
140
|
+
for (const child of children) {
|
|
141
|
+
let node2 = child;
|
|
142
|
+
if (node2.type === "(" || node2.type === ")" || node2.type === "," || node2.type === "[" || node2.type === "]") {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (node2.type === "comment") {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (child.type === "argument") {
|
|
149
|
+
if (child.children.length === 0) continue;
|
|
150
|
+
const nameNode = child.childForFieldName("name");
|
|
151
|
+
let foundValue = false;
|
|
152
|
+
for (const argChild of child.children) {
|
|
153
|
+
if (argChild.id === nameNode?.id) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (argChild.type === "comment" || argChild.type === ":") {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
node2 = argChild;
|
|
160
|
+
foundValue = true;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
if (!foundValue) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (translationKeyIndex >= translationKeys.length) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
const currentKey = translationKeys[translationKeyIndex];
|
|
171
|
+
let nodeValue = resolveStringValue(node2);
|
|
172
|
+
if (currentKey === "number") {
|
|
173
|
+
nodeValue = node2.text;
|
|
174
|
+
} else if (!node2?.type || !stringType.includes(node2.type)) {
|
|
175
|
+
if (debugEnabled) {
|
|
176
|
+
console.error(
|
|
177
|
+
`Unexpected node type ${node2?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node2.startPosition.row + 1} pos ${node2.startPosition.column + 1}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
translation[currentKey] = nodeValue;
|
|
183
|
+
translationKeyIndex += 1;
|
|
184
|
+
}
|
|
185
|
+
if (Array.isArray(args?.options?.translationDomains) && translation.text_domain && !args.options.translationDomains.includes(translation.text_domain)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const comments = collectComments(node);
|
|
189
|
+
const block = new import_gettext_merger.Block({
|
|
190
|
+
msgctxt: translation.msgctxt,
|
|
191
|
+
msgid: translation.msgid ?? "",
|
|
192
|
+
msgid_plural: translation.msgid_plural,
|
|
193
|
+
msgstr: translation.msgid_plural ? ["", ""] : [""],
|
|
194
|
+
comments: {
|
|
195
|
+
translator: comments ? [comments] : void 0,
|
|
196
|
+
reference: [
|
|
197
|
+
`${(0, import_common.reverseSlashes)(filepath)}:${node.startPosition.row + 1}`
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
gettextTranslations.add(block);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
if (sourceCode) {
|
|
206
|
+
const fileSize = Buffer.byteLength(sourceCode, "utf8");
|
|
207
|
+
let bufferSize = 1024 * 32;
|
|
208
|
+
if (fileSize >= bufferSize) {
|
|
209
|
+
bufferSize = fileSize + 32;
|
|
210
|
+
}
|
|
211
|
+
if (fileSize >= 1024 * 1024 * 2) {
|
|
212
|
+
console.warn(`File size warning: ${filepath} exceeds 2 MB.`);
|
|
213
|
+
}
|
|
214
|
+
const tree = parser.parse(sourceCode, void 0, { bufferSize });
|
|
215
|
+
if (tree) {
|
|
216
|
+
traverse(tree.rootNode);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.error(`Failed to parse ${filepath}: ${e}`);
|
|
221
|
+
}
|
|
222
|
+
return gettextTranslations;
|
|
223
|
+
}
|
|
224
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
225
|
+
0 && (module.exports = {
|
|
226
|
+
doTree
|
|
227
|
+
});
|
|
228
|
+
//# sourceMappingURL=tree.js.map
|
package/lib/potCommand.js
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
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 potCommand_exports = {};
|
|
20
|
+
__export(potCommand_exports, {
|
|
21
|
+
default: () => potCommand
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(potCommand_exports);
|
|
24
|
+
var import_makePot = require("./parser/makePot.js");
|
|
25
|
+
var import_common = require("./utils/common.js");
|
|
26
|
+
function potCommand(args) {
|
|
27
|
+
if (Object.keys(args).length > 0) {
|
|
28
|
+
(0, import_common.printModuleInfo)();
|
|
29
|
+
(0, import_makePot.makePot)(args).then(() => {
|
|
30
|
+
(0, import_common.printTimeElapsed)("Make-Pot", args.timeStart);
|
|
31
|
+
}).catch((error) => {
|
|
32
|
+
console.error(`\u{1FAE4} Make-pot - ${error}`);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=potCommand.js.map
|
package/lib/potCommand.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/potCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import { makePot } from \"./parser/makePot.js\";\n\nimport type { Args } from \"./types.js\";\nimport { printModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function potCommand(args: Args) {\n\tif (Object.keys(args).length > 0) {\n\t\tprintModuleInfo();\n\t\t
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAGxB,oBAAkD;AAEnC,SAAR,WAA4B,MAAY;AAC9C,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,uCAAgB;AAEhB,
|
|
4
|
+
"sourcesContent": ["import { makePot } from \"./parser/makePot.js\";\n\nimport type { Args } from \"./types.js\";\nimport { printModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function potCommand(args: Args) {\n\tif (Object.keys(args).length > 0) {\n\t\tprintModuleInfo();\n\t\t/** make the pot file */\n\t\tmakePot(args)\n\t\t\t.then(() => {\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Pot\", args.timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 Make-pot - ${error}`);\n\t\t\t});\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAGxB,oBAAkD;AAEnC,SAAR,WAA4B,MAAY;AAC9C,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,uCAAgB;AAEhB,gCAAQ,IAAI,EACV,KAAK,MAAM;AAEX,0CAAiB,YAAY,KAAK,SAAS;AAAA,IAC5C,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,wBAAiB,KAAK,EAAE;AAAA,IACvC,CAAC;AAAA,EACH;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/types.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|