@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/extractors/css.js
CHANGED
|
@@ -1 +1,69 @@
|
|
|
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 css_exports = {};
|
|
30
|
+
__export(css_exports, {
|
|
31
|
+
extractCssThemeData: () => extractCssThemeData
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(css_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
35
|
+
var import_node_path = __toESM(require("node:path"));
|
|
36
|
+
var import_const = require("../const.js");
|
|
37
|
+
var import_common = require("../utils/common.js");
|
|
38
|
+
var import_extractors = require("../utils/extractors.js");
|
|
39
|
+
var import_text = require("./text.js");
|
|
40
|
+
function extractCssThemeData(args, filename = "style.css") {
|
|
41
|
+
let fileData = {};
|
|
42
|
+
const styleCssFile = import_node_path.default.join(args.paths.cwd, filename);
|
|
43
|
+
if (import_node_fs.default.existsSync(styleCssFile)) {
|
|
44
|
+
const fileContent = import_node_fs.default.readFileSync(styleCssFile, "utf8");
|
|
45
|
+
const commentBlock = (0, import_common.getCommentBlock)(fileContent);
|
|
46
|
+
fileData = (0, import_text.extractFileData)(commentBlock);
|
|
47
|
+
if ("Theme Name" in fileData) {
|
|
48
|
+
console.log(`\u{1F535} Theme stylesheet detected. (${styleCssFile})`);
|
|
49
|
+
args.domain = "theme";
|
|
50
|
+
const themeInfo = {};
|
|
51
|
+
for (const keyValueMatch of Object.entries(fileData)) {
|
|
52
|
+
if (keyValueMatch?.[0] && keyValueMatch[1]) {
|
|
53
|
+
const header = (0, import_extractors.getKeyByValue)(import_const.themeHeaders, keyValueMatch[0].trim());
|
|
54
|
+
if (header === void 0) continue;
|
|
55
|
+
themeInfo[header] = keyValueMatch[1].trim();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return themeInfo;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`Theme stylesheet not found in ${styleCssFile}`);
|
|
62
|
+
}
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
extractCssThemeData
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -1,15 +1,253 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 headers_exports = {};
|
|
30
|
+
__export(headers_exports, {
|
|
31
|
+
extractMainFileData: () => extractMainFileData,
|
|
32
|
+
generateHeader: () => generateHeader,
|
|
33
|
+
getAuthorFromPackage: () => getAuthorFromPackage,
|
|
34
|
+
translationsHeaders: () => translationsHeaders
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(headers_exports);
|
|
37
|
+
var import_node_path = __toESM(require("node:path"));
|
|
38
|
+
var import_node_process = __toESM(require("node:process"));
|
|
39
|
+
var readline = __toESM(require("node:readline"));
|
|
40
|
+
var import_gettext_merger = require("gettext-merger");
|
|
41
|
+
var import_const = require("../const.js");
|
|
42
|
+
var import_fs = require("../fs/fs.js");
|
|
43
|
+
var import_common = require("../utils/common.js");
|
|
44
|
+
var import_extractors = require("../utils/extractors.js");
|
|
45
|
+
var import_css = require("./css.js");
|
|
46
|
+
var import_php = require("./php.js");
|
|
47
|
+
function validateRequiredFields(headerData, debug, silent = false) {
|
|
48
|
+
const requiredFields = [
|
|
49
|
+
{ key: "slug", name: "Plugin/Theme slug", placeholder: "PLUGIN NAME" },
|
|
50
|
+
{ key: "author", name: "Author name", placeholder: "AUTHOR" },
|
|
51
|
+
{ key: "version", name: "Version", placeholder: "" },
|
|
52
|
+
{ key: "email", name: "Author email", placeholder: "AUTHOR EMAIL" },
|
|
53
|
+
{ key: "xDomain", name: "Text domain", placeholder: "PLUGIN TEXTDOMAIN" }
|
|
54
|
+
];
|
|
55
|
+
const missingFields = requiredFields.filter(
|
|
56
|
+
(field) => !headerData[field.key] || headerData[field.key] === field.placeholder || field.key === "version" && headerData[field.key] === "0.0.1"
|
|
57
|
+
);
|
|
58
|
+
if (missingFields.length > 0) {
|
|
59
|
+
if (!silent) {
|
|
60
|
+
console.error("\n\u26A0\uFE0F Missing required information for POT file header:\n");
|
|
61
|
+
for (const field of missingFields) {
|
|
62
|
+
console.error(
|
|
63
|
+
` - ${field.name} is missing or has a default value (eg. version: 0.0.1")`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
console.error(
|
|
67
|
+
"\nPlease provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.",
|
|
68
|
+
"\nFor more information check the documentation at https://github.com/wp-blocks/makePot"
|
|
69
|
+
);
|
|
70
|
+
if (missingFields.some((field) => field.key === "email")) {
|
|
71
|
+
console.error(
|
|
72
|
+
"\n\nWordpress didn't require an email field in the headers object but it's required in order to generate a valid pot file.",
|
|
73
|
+
'\nPlease add the email field to the package.json file (author field eg. author: "AUTHOR <EMAIL>")',
|
|
74
|
+
'\nor inject those information using the --headers flag to the "makePot" command (eg. --headers=email:erik@ck.it).',
|
|
75
|
+
"\nFor more information check the documentation at https://github.com/wp-blocks/makePot"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (missingFields && debug) {
|
|
79
|
+
console.error(
|
|
80
|
+
"\nDebug information:",
|
|
81
|
+
"\nMissing fields:",
|
|
82
|
+
missingFields,
|
|
83
|
+
"\nHeader data:",
|
|
84
|
+
headerData
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
console.error("\n");
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function extractAuthorData(authorData) {
|
|
94
|
+
const defaultResult = { name: "AUTHOR", email: "AUTHOR EMAIL" };
|
|
95
|
+
if (!authorData) {
|
|
96
|
+
return defaultResult;
|
|
97
|
+
}
|
|
98
|
+
if (typeof authorData === "string") {
|
|
99
|
+
const emailMatch = authorData.match(/<([^>]+)>/);
|
|
100
|
+
const email = emailMatch ? emailMatch[1].trim() : void 0;
|
|
101
|
+
const websiteMatch = authorData.match(/\(([^)]+)\)/);
|
|
102
|
+
const website = websiteMatch ? websiteMatch[1].trim() : void 0;
|
|
103
|
+
let name = authorData.trim();
|
|
104
|
+
if (emailMatch) name = name.replace(emailMatch[0], "").trim();
|
|
105
|
+
if (websiteMatch) name = name.replace(websiteMatch[0], "").trim();
|
|
106
|
+
return { name, email, website };
|
|
107
|
+
}
|
|
108
|
+
if (typeof authorData === "object") {
|
|
109
|
+
return {
|
|
110
|
+
name: authorData.name,
|
|
111
|
+
email: authorData.email,
|
|
112
|
+
website: authorData.website
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function getAuthorFromPackage(pkgJsonData) {
|
|
117
|
+
const fields = [
|
|
118
|
+
"author",
|
|
119
|
+
// Standard author field
|
|
120
|
+
"authors",
|
|
121
|
+
// Some packages use authors (plural)
|
|
122
|
+
"contributors",
|
|
123
|
+
// Try contributors if no author
|
|
124
|
+
"maintainers"
|
|
125
|
+
// Try maintainers as a last resort
|
|
126
|
+
];
|
|
127
|
+
for (const field of fields) {
|
|
128
|
+
const value = pkgJsonData[field];
|
|
129
|
+
if (value) {
|
|
130
|
+
let authorData;
|
|
131
|
+
if (typeof value === "string") {
|
|
132
|
+
authorData = extractAuthorData(value);
|
|
133
|
+
} else if (Array.isArray(value)) {
|
|
134
|
+
for (const author of value) {
|
|
135
|
+
if (!author) continue;
|
|
136
|
+
if (typeof author === "string" || typeof author === "object") {
|
|
137
|
+
authorData = extractAuthorData(author);
|
|
138
|
+
if (authorData) break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else if (typeof value === "object") {
|
|
142
|
+
authorData = extractAuthorData(value);
|
|
143
|
+
}
|
|
144
|
+
if (authorData?.name !== "AUTHOR" || authorData?.email !== "AUTHOR EMAIL") {
|
|
145
|
+
return authorData;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { name: "AUTHOR", email: "AUTHOR EMAIL" };
|
|
150
|
+
}
|
|
151
|
+
function consolidateUserHeaderData(args) {
|
|
152
|
+
const pkgJsonData = (0, import_common.getPkgJsonData)(
|
|
153
|
+
args.paths?.cwd,
|
|
154
|
+
"name",
|
|
155
|
+
"version",
|
|
156
|
+
"author",
|
|
157
|
+
"authors",
|
|
158
|
+
"contributors",
|
|
159
|
+
"maintainers"
|
|
160
|
+
);
|
|
161
|
+
const pkgAuthor = getAuthorFromPackage(
|
|
162
|
+
pkgJsonData
|
|
163
|
+
);
|
|
164
|
+
const currentDir = import_node_path.default.basename(args.paths?.cwd || import_node_process.default.cwd())?.toLowerCase().replace(" ", "-");
|
|
165
|
+
const authorName = args?.headers?.author || pkgAuthor?.name;
|
|
166
|
+
const email = args?.headers?.email || pkgAuthor?.email;
|
|
167
|
+
const authorString = `${authorName} <${email}>`;
|
|
168
|
+
const slug = args.slug || currentDir || args.headers?.name?.toString().replace(/ /g, "-") || (args.domain === "theme" ? "THEME NAME" : "PLUGIN NAME");
|
|
169
|
+
const bugs = `https://wordpress.org/support/${args.domain === "theme" ? "themes" : "plugins"}/${slug}`;
|
|
170
|
+
return {
|
|
171
|
+
...args.headers,
|
|
172
|
+
name: args.headers?.name?.toString() || slug,
|
|
173
|
+
author: authorName,
|
|
174
|
+
authorString,
|
|
175
|
+
// this is the author + email address in this format: author <email>
|
|
176
|
+
slug,
|
|
177
|
+
email,
|
|
178
|
+
bugs,
|
|
179
|
+
license: args.headers?.license || "gpl-2.0 or later",
|
|
180
|
+
version: args.headers?.version || pkgJsonData.version || "0.0.1",
|
|
181
|
+
language: "en",
|
|
182
|
+
xDomain: args.headers?.textDomain?.toString() || slug
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function generateHeader(args) {
|
|
186
|
+
const headerData = consolidateUserHeaderData(args);
|
|
187
|
+
const { name, version } = (0, import_common.getPkgJsonData)(import_const.modulePath, "name", "version");
|
|
188
|
+
if (!validateRequiredFields(headerData, args.debug, args.options?.silent)) {
|
|
189
|
+
if (args.options?.silent) {
|
|
190
|
+
} else {
|
|
191
|
+
const rl = readline.createInterface({
|
|
192
|
+
input: import_node_process.default.stdin,
|
|
193
|
+
output: import_node_process.default.stdout
|
|
194
|
+
});
|
|
195
|
+
const answer = await new Promise((resolve) => {
|
|
196
|
+
rl.question(
|
|
197
|
+
"\nMissing required fields. Use default values? (y/N) ",
|
|
198
|
+
resolve
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
rl.close();
|
|
202
|
+
if (typeof answer === "string" && answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
|
|
203
|
+
import_node_process.default.exit(1);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
"Project-Id-Version": `${headerData.name} ${headerData.version}`,
|
|
209
|
+
"Report-Msgid-Bugs-To": headerData.bugs,
|
|
210
|
+
"MIME-Version": "1.0",
|
|
211
|
+
"Content-Transfer-Encoding": "8bit",
|
|
212
|
+
"content-type": `text/plain; charset=${(0, import_fs.getEncodingCharset)(args.options?.charset)}`,
|
|
213
|
+
"plural-forms": "nplurals=2; plural=(n!=1);",
|
|
214
|
+
"POT-Creation-Date": `${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
215
|
+
"PO-Revision-Date": `${(/* @__PURE__ */ new Date()).getFullYear()}-MO-DA HO:MI+ZONE`,
|
|
216
|
+
"Last-Translator": headerData.authorString,
|
|
217
|
+
"Language-Team": headerData.authorString,
|
|
218
|
+
"X-Generator": `${name} ${version}`,
|
|
219
|
+
Language: `${headerData.language}`,
|
|
220
|
+
"X-Domain": headerData.xDomain
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function extractMainFileData(args) {
|
|
224
|
+
let extractedData = {};
|
|
225
|
+
if (["plugin", "block", "generic"].includes(args.domain)) {
|
|
226
|
+
extractedData = (0, import_php.extractPhpPluginData)(args);
|
|
227
|
+
} else if (["theme", "theme-block"].includes(args.domain)) {
|
|
228
|
+
extractedData = (0, import_css.extractCssThemeData)(args);
|
|
229
|
+
} else {
|
|
230
|
+
console.log("No main file detected.");
|
|
231
|
+
}
|
|
232
|
+
return extractedData;
|
|
233
|
+
}
|
|
234
|
+
function translationsHeaders(args) {
|
|
235
|
+
const { domain, headers } = args;
|
|
236
|
+
const { name, description, author, authorUri, url } = headers;
|
|
237
|
+
const fakePath = domain === "plugin" ? `${args.slug}.php` : "style.css";
|
|
238
|
+
const blocks = [];
|
|
239
|
+
if (name) blocks.push((0, import_extractors.buildBlock)(`Name of the ${domain}`, name, [fakePath]));
|
|
240
|
+
if (url) blocks.push((0, import_extractors.buildBlock)(`Url of the ${domain}`, url, [fakePath]));
|
|
241
|
+
if (description) blocks.push((0, import_extractors.buildBlock)(`Description of the ${domain}`, description, [fakePath]));
|
|
242
|
+
if (author) blocks.push((0, import_extractors.buildBlock)(`Author of the ${domain}`, author, [fakePath]));
|
|
243
|
+
if (authorUri) blocks.push((0, import_extractors.buildBlock)(`Author URI of the ${domain}`, authorUri, [fakePath]));
|
|
244
|
+
return new import_gettext_merger.SetOfBlocks(blocks);
|
|
245
|
+
}
|
|
246
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
247
|
+
0 && (module.exports = {
|
|
248
|
+
extractMainFileData,
|
|
249
|
+
generateHeader,
|
|
250
|
+
getAuthorFromPackage,
|
|
251
|
+
translationsHeaders
|
|
252
|
+
});
|
|
253
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractors/headers.ts"],
|
|
4
|
-
"sourcesContent": ["import path from 'node:path'\r\nimport process from 'node:process'\r\nimport * as readline from 'node:readline'\r\nimport { SetOfBlocks } from 'gettext-merger'\r\nimport { modulePath } from '../const.js'\r\nimport { getEncodingCharset } from '../fs/fs.js'\r\nimport type { Args, AuthorData, I18nHeaders, PotHeaders } from '../types.js'\r\nimport { getPkgJsonData } from '../utils/common.js'\r\nimport { buildBlock } from '../utils/extractors.js'\r\nimport { extractCssThemeData } from './css.js'\r\nimport { extractPhpPluginData } from './php.js'\r\n\r\n/**\r\n * Checks if required fields are missing and logs a clear error message\r\n * @param {object} headerData - The header data to validate\r\n * @param {boolean} debug - Debug mode flag\r\n * @param {boolean} silent - Silent mode flag\r\n * @returns {boolean} - true if all required fields are present, false otherwise\r\n */\r\nfunction validateRequiredFields(\r\n\theaderData: I18nHeaders,\r\n\tdebug: boolean,\r\n\tsilent = false,\r\n): boolean {\r\n\t// Define the required fields with strict key types\r\n\tconst requiredFields: {\r\n\t\tkey: keyof I18nHeaders;\r\n\t\tname: string;\r\n\t\tplaceholder: string;\r\n\t}[] = [\r\n\t\t\t{ key: \"slug\", name: \"Plugin/Theme slug\", placeholder: \"PLUGIN NAME\" },\r\n\t\t\t{ key: \"author\", name: \"Author name\", placeholder: \"AUTHOR\" },\r\n\t\t\t{ key: \"version\", name: \"Version\", placeholder: \"\" },\r\n\t\t\t{ key: \"email\", name: \"Author email\", placeholder: \"AUTHOR EMAIL\" },\r\n\t\t\t{ key: \"xDomain\", name: \"Text domain\", placeholder: \"PLUGIN TEXTDOMAIN\" },\r\n\t\t];\r\n\r\n\t// Filter out the missing or default fields\r\n\tconst missingFields = requiredFields.filter(\r\n\t\t(field) =>\r\n\t\t\t!headerData[field.key] ||\r\n\t\t\theaderData[field.key] === field.placeholder ||\r\n\t\t\t(field.key === \"version\" && headerData[field.key] === \"0.0.1\"),\r\n\t);\r\n\r\n\tif (missingFields.length > 0) {\r\n\t\tif (!silent) {\r\n\t\t\tconsole.error(\"\\n! Missing required information for POT file header:\\n\");\r\n\r\n\t\t\tfor (const field of missingFields) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t` - ${field.name} is missing or has a default value (eg. version: 0.0.1\")`,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconsole.error(\r\n\t\t\t\t\"\\nPlease provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.\",\r\n\t\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t\t);\r\n\r\n\t\t\tif (missingFields.some((field) => field.key === \"email\")) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t\"\\n\\nWordpress didn't require an email field in the headers object but it's required in order to generate a valid pot file.\",\r\n\t\t\t\t\t'\\nPlease add the email field to the package.json file (author field eg. author: \"AUTHOR <EMAIL>\")',\r\n\t\t\t\t\t'\\nor inject those information using the --headers flag to the \"makePot\" command (eg. --headers=email:erik@ck.it).',\r\n\t\t\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (missingFields && debug) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t\"\\nDebug information:\",\r\n\t\t\t\t\t\"\\nMissing fields:\",\r\n\t\t\t\t\tmissingFields,\r\n\t\t\t\t\t\"\\nHeader data:\",\r\n\t\t\t\t\theaderData,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconsole.error(\"\\n\");\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\treturn true;\r\n}\r\n\r\n/**\r\n * Extract author data from package.json author field and return an array of strings\r\n * the original field is a string and it's longer form is \"Your Name <email@example.com> (https://example.com)\"\r\n *\r\n * @returns an object with name, email, and website\r\n * @param authorData\r\n */\r\nfunction extractAuthorData(\r\n\tauthorData: string | AuthorData,\r\n): AuthorData | undefined {\r\n\t// Default result with placeholder values\r\n\tconst defaultResult = { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n\r\n\t// Return default if no author data\r\n\tif (!authorData) {\r\n\t\treturn defaultResult;\r\n\t}\r\n\r\n\t// Handle string format: \"Barney Rubble <barney@npmjs.com> (http://barnyrubble.npmjs.com/)\"\r\n\tif (typeof authorData === \"string\") {\r\n\t\t// Try to extract email with regex\r\n\t\tconst emailMatch = authorData.match(/<([^>]+)>/);\r\n\t\tconst email = emailMatch ? emailMatch[1].trim() : undefined;\r\n\r\n\t\t// Try to extract website with regex\r\n\t\tconst websiteMatch = authorData.match(/\\(([^)]+)\\)/);\r\n\t\tconst website = websiteMatch ? websiteMatch[1].trim() : undefined;\r\n\r\n\t\t// Extract name by removing email and website parts if present\r\n\t\tlet name = authorData.trim();\r\n\t\tif (emailMatch) name = name.replace(emailMatch[0], \"\").trim();\r\n\t\tif (websiteMatch) name = name.replace(websiteMatch[0], \"\").trim();\r\n\r\n\t\treturn { name, email, website };\r\n\t}\r\n\tif (typeof authorData === \"object\") {\r\n\t\t// Handle object format: { name: \"Barney Rubble\", email: \"barney@npmjs.com\", website: \"http://barnyrubble.npmjs.com/\" }\r\n\t\treturn {\r\n\t\t\tname: authorData.name,\r\n\t\t\temail: authorData.email,\r\n\t\t\twebsite: authorData.website,\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Gets author data by checking multiple possible locations in package.json\r\n *\r\n * @param pkgJsonData The package.json data object\r\n * @returns Author data with name, email and website\r\n */\r\nexport function getAuthorFromPackage(\r\n\tpkgJsonData: Record<string, unknown>,\r\n): AuthorData {\r\n\t// Check multiple possible locations for author information\r\n\tconst fields = [\r\n\t\t\"author\", // Standard author field\r\n\t\t\"authors\", // Some packages use authors (plural)\r\n\t\t\"contributors\", // Try contributors if no author\r\n\t\t\"maintainers\", // Try maintainers as a last resort\r\n\t] as string[];\r\n\r\n\t// Try each location in order\r\n\tfor (const field of fields) {\r\n\t\tconst value = pkgJsonData[field];\r\n\t\tif (value) {\r\n\t\t\tlet authorData: AuthorData | undefined;\r\n\r\n\t\t\tif (typeof value === \"string\") {\r\n\t\t\t\tauthorData = extractAuthorData(value);\r\n\t\t\t} else if (Array.isArray(value)) {\r\n\t\t\t\tfor (const author of value) {\r\n\t\t\t\t\tif (!author) continue;\r\n\t\t\t\t\tif (typeof author === \"string\" || typeof author === \"object\") {\r\n\t\t\t\t\t\tauthorData = extractAuthorData(author as string | AuthorData);\r\n\t\t\t\t\t\tif (authorData) break;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (typeof value === \"object\") {\r\n\t\t\t\t// Handle single object author field\r\n\t\t\t\tauthorData = extractAuthorData(value as AuthorData);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\tauthorData?.name !== \"AUTHOR\" ||\r\n\t\t\t\tauthorData?.email !== \"AUTHOR EMAIL\"\r\n\t\t\t) {\r\n\t\t\t\treturn authorData as AuthorData; // Returns the valid author data found\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// If no valid author data found in any location\r\n\treturn { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n}\r\n\r\n/**\r\n * This function consolidates the user headers data into a single object\r\n *\r\n * @param args the command line arguments\r\n * @return {Record<string, string>} the consolidated headers data object\r\n */\r\nfunction consolidateUserHeaderData(args: Args): I18nHeaders {\r\n\tconst pkgJsonData = getPkgJsonData(\r\n\t\targs.paths?.cwd,\r\n\t\t\"name\",\r\n\t\t\"version\",\r\n\t\t\"author\",\r\n\t\t\"authors\",\r\n\t\t\"contributors\",\r\n\t\t\"maintainers\",\r\n\t);\r\n\t// get author data from package.json\r\n\tconst pkgAuthor = getAuthorFromPackage(\r\n\t\tpkgJsonData as unknown as Record<string, unknown>,\r\n\t);\r\n\r\n\t// get the current directory name as slug\r\n\tconst currentDir = path\r\n\t\t.basename(args.paths?.cwd || process.cwd())\r\n\t\t?.toLowerCase()\r\n\t\t.replace(\" \", \"-\");\r\n\r\n\t// Use command line author name if provided, fallback to package.json\r\n\tconst authorName = args?.headers?.author || pkgAuthor?.name;\r\n\tconst email = args?.headers?.email || pkgAuthor?.email;\r\n\t// this is the author with email address in this format: author <email>\r\n\tconst authorString = `${authorName} <${email}>`;\r\n\tconst slug =\r\n\t\targs.slug ||\r\n\t\tcurrentDir ||\r\n\t\targs.headers?.name?.toString().replace(/ /g, \"-\") ||\r\n\t\t(args.domain === \"theme\" ? \"THEME NAME\" : \"PLUGIN NAME\");\r\n\r\n\tconst bugs = `https://wordpress.org/support/${args.domain === \"theme\" ? \"themes\" : \"plugins\"\r\n\t\t}/${slug}`;\r\n\r\n\treturn {\r\n\t\t...args.headers,\r\n\t\tname: args.headers?.name?.toString() || slug,\r\n\t\tauthor: authorName,\r\n\t\tauthorString: authorString, // this is the author + email address in this format: author <email>\r\n\t\tslug,\r\n\t\temail,\r\n\t\tbugs,\r\n\t\tlicense: args.headers?.license || \"gpl-2.0 or later\",\r\n\t\tversion:\r\n\t\t\targs.headers?.version || (pkgJsonData.version as string) || \"0.0.1\",\r\n\t\tlanguage: \"en\",\r\n\t\txDomain: args.headers?.textDomain?.toString() || slug,\r\n\t};\r\n}\r\n\r\n/**\r\n * Generates a POT header for a given set of arguments.\r\n * https://developer.wordpress.org/cli/commands/i18n/make-pot/\r\n * String that should be added as a comment to the top of the resulting POT file.\r\n * By default, a copyright comment is added for WordPress plugins and themes in the following manner:\r\n * `\r\n * Copyright (C) 2018 Example Plugin Author\r\n * This file is distributed under the same license as the Example Plugin package.\r\n * `\r\n * If a plugin or theme specifies a license in their main plugin file or stylesheet,\r\n * the comment looks like this: Copyright (C) 2018 Example Plugin Author This file is distributed under the GPLv2.\r\n *\r\n * @param args - The argument object containing the headers and their values.\r\n * @return The generated POT header.\r\n */\r\nexport async function generateHeader(\r\n\targs: Args,\r\n): Promise<Record<string, string> | null> {\r\n\t// Consolidate the user headers data into a single object\r\n\tconst headerData = consolidateUserHeaderData(args);\r\n\r\n\t// the makepot module name and version\r\n\tconst { name, version } = getPkgJsonData(modulePath, \"name\", \"version\");\r\n\r\n\t// Validate required fields - exit early if validation fails\r\n\tif (!validateRequiredFields(headerData, args.debug, args.options?.silent)) {\r\n\t\tif (args.options?.silent) {\r\n\t\t\t// In silent mode, we use defaults without asking\r\n\t\t} else {\r\n\t\t\t// Ask the user if default values should be used\r\n\t\t\tconst rl = readline.createInterface({\r\n\t\t\t\tinput: process.stdin,\r\n\t\t\t\toutput: process.stdout,\r\n\t\t\t});\r\n\r\n\t\t\tconst answer = await new Promise((resolve) => {\r\n\t\t\t\trl.question(\r\n\t\t\t\t\t\"\\nMissing required fields. Use default values? (y/N) \",\r\n\t\t\t\t\tresolve,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t\trl.close();\r\n\r\n\t\t\tif (\r\n\t\t\t\ttypeof answer === \"string\" &&\r\n\t\t\t\tanswer.toLowerCase() !== \"y\" &&\r\n\t\t\t\tanswer.toLowerCase() !== \"yes\"\r\n\t\t\t) {\r\n\t\t\t\tprocess.exit(1); // Exit with error code\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\t\"Project-Id-Version\": `${headerData.name} ${headerData.version}`,\r\n\t\t\"Report-Msgid-Bugs-To\": headerData.bugs,\r\n\t\t\"MIME-Version\": \"1.0\",\r\n\t\t\"Content-Transfer-Encoding\": \"8bit\",\r\n\t\t\"content-type\": `text/plain; charset=${getEncodingCharset(args.options?.charset)}`,\r\n\t\t\"plural-forms\": \"nplurals=2; plural=(n!=1);\",\r\n\t\t\"POT-Creation-Date\": `${new Date().toISOString()}`,\r\n\t\t\"PO-Revision-Date\": `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,\r\n\t\t\"Last-Translator\": headerData.authorString,\r\n\t\t\"Language-Team\": headerData.authorString,\r\n\t\t\"X-Generator\": `${name} ${version}`,\r\n\t\tLanguage: `${headerData.language}`,\r\n\t\t\"X-Domain\": headerData.xDomain,\r\n\t};\r\n}\r\n\r\n/**\r\n * Extracts main file data based on the given arguments.\r\n *\r\n * @param {Args} args - The arguments for extracting the main file data.\r\n * @return {Record<string, string>} The extracted main file data.\r\n */\r\nexport function extractMainFileData(args: Args): Record<string, string> {\r\n\tlet extractedData = {};\r\n\tif ([\"plugin\", \"block\", \"generic\"].includes(args.domain)) {\r\n\t\textractedData = extractPhpPluginData(args);\r\n\t} else if ([\"theme\", \"theme-block\"].includes(args.domain)) {\r\n\t\textractedData = extractCssThemeData(args);\r\n\t} else {\r\n\t\tconsole.log(\"No main file detected.\");\r\n\t}\r\n\r\n\treturn extractedData;\r\n}\r\n\r\n/**\r\n * Generate translation strings based on the given type and headers.\r\n *\r\n * @return {Record<string, string>} the generated translation strings\r\n * @param args\r\n */\r\nexport function translationsHeaders(args: Args): SetOfBlocks {\r\n\tconst { domain, headers } = args as Args;\r\n\tconst { name, description, author, authorUri, url } = headers as {\r\n\t\t[key in PotHeaders]: string;\r\n\t};\r\n\r\n\t// the main file is the plugin main php file or the css file\r\n\tconst fakePath = domain === \"plugin\" ? `${args.slug}.php` : \"style.css\";\r\n\r\n\treturn new SetOfBlocks([\r\n\t\tbuildBlock(`Name of the ${domain}`, name, [fakePath]),\r\n\t\tbuildBlock(`Url of the ${domain}`, url, [fakePath]),\r\n\t\tbuildBlock(`Description of the ${domain}`, description, [fakePath]),\r\n\t\tbuildBlock(`Author of the ${domain}`, author, [fakePath]),\r\n\t\tbuildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]),\r\n\t]);\r\n}\r\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,0BAAoB;AACpB,eAA0B;AAC1B,4BAA4B;AAC5B,mBAA2B;AAC3B,gBAAmC;AAEnC,oBAA+B;AAC/B,wBAA2B;AAC3B,iBAAoC;AACpC,iBAAqC;AASrC,SAAS,uBACR,YACA,OACA,SAAS,OACC;AAEV,QAAM,iBAIA;AAAA,IACJ,EAAE,KAAK,QAAQ,MAAM,qBAAqB,aAAa,cAAc;AAAA,IACrE,EAAE,KAAK,UAAU,MAAM,eAAe,aAAa,SAAS;AAAA,IAC5D,EAAE,KAAK,WAAW,MAAM,WAAW,aAAa,GAAG;AAAA,IACnD,EAAE,KAAK,SAAS,MAAM,gBAAgB,aAAa,eAAe;AAAA,IAClE,EAAE,KAAK,WAAW,MAAM,eAAe,aAAa,oBAAoB;AAAA,EACzE;AAGD,QAAM,gBAAgB,eAAe;AAAA,IACpC,CAAC,UACA,CAAC,WAAW,MAAM,GAAG,KACrB,WAAW,MAAM,GAAG,MAAM,MAAM,eAC/B,MAAM,QAAQ,aAAa,WAAW,MAAM,GAAG,MAAM;AAAA,EACxD;AAEA,MAAI,cAAc,SAAS,GAAG;AAC7B,QAAI,CAAC,QAAQ;AACZ,cAAQ,MAAM,
|
|
4
|
+
"sourcesContent": ["import path from 'node:path'\r\nimport process from 'node:process'\r\nimport * as readline from 'node:readline'\r\nimport { SetOfBlocks } from 'gettext-merger'\r\nimport { modulePath } from '../const.js'\r\nimport { getEncodingCharset } from '../fs/fs.js'\r\nimport type { Args, AuthorData, I18nHeaders, PotHeaders } from '../types.js'\r\nimport { getPkgJsonData } from '../utils/common.js'\r\nimport { buildBlock } from '../utils/extractors.js'\r\nimport { extractCssThemeData } from './css.js'\r\nimport { extractPhpPluginData } from './php.js'\r\n\r\n/**\r\n * Checks if required fields are missing and logs a clear error message\r\n * @param {object} headerData - The header data to validate\r\n * @param {boolean} debug - Debug mode flag\r\n * @param {boolean} silent - Silent mode flag\r\n * @returns {boolean} - true if all required fields are present, false otherwise\r\n */\r\nfunction validateRequiredFields(\r\n\theaderData: I18nHeaders,\r\n\tdebug: boolean,\r\n\tsilent = false,\r\n): boolean {\r\n\t// Define the required fields with strict key types\r\n\tconst requiredFields: {\r\n\t\tkey: keyof I18nHeaders;\r\n\t\tname: string;\r\n\t\tplaceholder: string;\r\n\t}[] = [\r\n\t\t\t{ key: \"slug\", name: \"Plugin/Theme slug\", placeholder: \"PLUGIN NAME\" },\r\n\t\t\t{ key: \"author\", name: \"Author name\", placeholder: \"AUTHOR\" },\r\n\t\t\t{ key: \"version\", name: \"Version\", placeholder: \"\" },\r\n\t\t\t{ key: \"email\", name: \"Author email\", placeholder: \"AUTHOR EMAIL\" },\r\n\t\t\t{ key: \"xDomain\", name: \"Text domain\", placeholder: \"PLUGIN TEXTDOMAIN\" },\r\n\t\t];\r\n\r\n\t// Filter out the missing or default fields\r\n\tconst missingFields = requiredFields.filter(\r\n\t\t(field) =>\r\n\t\t\t!headerData[field.key] ||\r\n\t\t\theaderData[field.key] === field.placeholder ||\r\n\t\t\t(field.key === \"version\" && headerData[field.key] === \"0.0.1\"),\r\n\t);\r\n\r\n\tif (missingFields.length > 0) {\r\n\t\tif (!silent) {\r\n\t\t\tconsole.error(\"\\n\u26A0\uFE0F Missing required information for POT file header:\\n\");\r\n\r\n\t\t\tfor (const field of missingFields) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t` - ${field.name} is missing or has a default value (eg. version: 0.0.1\")`,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconsole.error(\r\n\t\t\t\t\"\\nPlease provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.\",\r\n\t\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t\t);\r\n\r\n\t\t\tif (missingFields.some((field) => field.key === \"email\")) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t\"\\n\\nWordpress didn't require an email field in the headers object but it's required in order to generate a valid pot file.\",\r\n\t\t\t\t\t'\\nPlease add the email field to the package.json file (author field eg. author: \"AUTHOR <EMAIL>\")',\r\n\t\t\t\t\t'\\nor inject those information using the --headers flag to the \"makePot\" command (eg. --headers=email:erik@ck.it).',\r\n\t\t\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tif (missingFields && debug) {\r\n\t\t\t\tconsole.error(\r\n\t\t\t\t\t\"\\nDebug information:\",\r\n\t\t\t\t\t\"\\nMissing fields:\",\r\n\t\t\t\t\tmissingFields,\r\n\t\t\t\t\t\"\\nHeader data:\",\r\n\t\t\t\t\theaderData,\r\n\t\t\t\t);\r\n\t\t\t}\r\n\r\n\t\t\tconsole.error(\"\\n\");\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\treturn true;\r\n}\r\n\r\n/**\r\n * Extract author data from package.json author field and return an array of strings\r\n * the original field is a string and it's longer form is \"Your Name <email@example.com> (https://example.com)\"\r\n *\r\n * @returns an object with name, email, and website\r\n * @param authorData\r\n */\r\nfunction extractAuthorData(\r\n\tauthorData: string | AuthorData,\r\n): AuthorData | undefined {\r\n\t// Default result with placeholder values\r\n\tconst defaultResult = { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n\r\n\t// Return default if no author data\r\n\tif (!authorData) {\r\n\t\treturn defaultResult;\r\n\t}\r\n\r\n\t// Handle string format: \"Barney Rubble <barney@npmjs.com> (http://barnyrubble.npmjs.com/)\"\r\n\tif (typeof authorData === \"string\") {\r\n\t\t// Try to extract email with regex\r\n\t\tconst emailMatch = authorData.match(/<([^>]+)>/);\r\n\t\tconst email = emailMatch ? emailMatch[1].trim() : undefined;\r\n\r\n\t\t// Try to extract website with regex\r\n\t\tconst websiteMatch = authorData.match(/\\(([^)]+)\\)/);\r\n\t\tconst website = websiteMatch ? websiteMatch[1].trim() : undefined;\r\n\r\n\t\t// Extract name by removing email and website parts if present\r\n\t\tlet name = authorData.trim();\r\n\t\tif (emailMatch) name = name.replace(emailMatch[0], \"\").trim();\r\n\t\tif (websiteMatch) name = name.replace(websiteMatch[0], \"\").trim();\r\n\r\n\t\treturn { name, email, website };\r\n\t}\r\n\tif (typeof authorData === \"object\") {\r\n\t\t// Handle object format: { name: \"Barney Rubble\", email: \"barney@npmjs.com\", website: \"http://barnyrubble.npmjs.com/\" }\r\n\t\treturn {\r\n\t\t\tname: authorData.name,\r\n\t\t\temail: authorData.email,\r\n\t\t\twebsite: authorData.website,\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Gets author data by checking multiple possible locations in package.json\r\n *\r\n * @param pkgJsonData The package.json data object\r\n * @returns Author data with name, email and website\r\n */\r\nexport function getAuthorFromPackage(\r\n\tpkgJsonData: Record<string, unknown>,\r\n): AuthorData {\r\n\t// Check multiple possible locations for author information\r\n\tconst fields = [\r\n\t\t\"author\", // Standard author field\r\n\t\t\"authors\", // Some packages use authors (plural)\r\n\t\t\"contributors\", // Try contributors if no author\r\n\t\t\"maintainers\", // Try maintainers as a last resort\r\n\t] as string[];\r\n\r\n\t// Try each location in order\r\n\tfor (const field of fields) {\r\n\t\tconst value = pkgJsonData[field];\r\n\t\tif (value) {\r\n\t\t\tlet authorData: AuthorData | undefined;\r\n\r\n\t\t\tif (typeof value === \"string\") {\r\n\t\t\t\tauthorData = extractAuthorData(value);\r\n\t\t\t} else if (Array.isArray(value)) {\r\n\t\t\t\tfor (const author of value) {\r\n\t\t\t\t\tif (!author) continue;\r\n\t\t\t\t\tif (typeof author === \"string\" || typeof author === \"object\") {\r\n\t\t\t\t\t\tauthorData = extractAuthorData(author as string | AuthorData);\r\n\t\t\t\t\t\tif (authorData) break;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else if (typeof value === \"object\") {\r\n\t\t\t\t// Handle single object author field\r\n\t\t\t\tauthorData = extractAuthorData(value as AuthorData);\r\n\t\t\t}\r\n\r\n\t\t\tif (\r\n\t\t\t\tauthorData?.name !== \"AUTHOR\" ||\r\n\t\t\t\tauthorData?.email !== \"AUTHOR EMAIL\"\r\n\t\t\t) {\r\n\t\t\t\treturn authorData as AuthorData; // Returns the valid author data found\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// If no valid author data found in any location\r\n\treturn { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\r\n}\r\n\r\n/**\r\n * This function consolidates the user headers data into a single object\r\n *\r\n * @param args the command line arguments\r\n * @return {Record<string, string>} the consolidated headers data object\r\n */\r\nfunction consolidateUserHeaderData(args: Args): I18nHeaders {\r\n\tconst pkgJsonData = getPkgJsonData(\r\n\t\targs.paths?.cwd,\r\n\t\t\"name\",\r\n\t\t\"version\",\r\n\t\t\"author\",\r\n\t\t\"authors\",\r\n\t\t\"contributors\",\r\n\t\t\"maintainers\",\r\n\t);\r\n\t// get author data from package.json\r\n\tconst pkgAuthor = getAuthorFromPackage(\r\n\t\tpkgJsonData as unknown as Record<string, unknown>,\r\n\t);\r\n\r\n\t// get the current directory name as slug\r\n\tconst currentDir = path\r\n\t\t.basename(args.paths?.cwd || process.cwd())\r\n\t\t?.toLowerCase()\r\n\t\t.replace(\" \", \"-\");\r\n\r\n\t// Use command line author name if provided, fallback to package.json\r\n\tconst authorName = args?.headers?.author || pkgAuthor?.name;\r\n\tconst email = args?.headers?.email || pkgAuthor?.email;\r\n\t// this is the author with email address in this format: author <email>\r\n\tconst authorString = `${authorName} <${email}>`;\r\n\tconst slug =\r\n\t\targs.slug ||\r\n\t\tcurrentDir ||\r\n\t\targs.headers?.name?.toString().replace(/ /g, \"-\") ||\r\n\t\t(args.domain === \"theme\" ? \"THEME NAME\" : \"PLUGIN NAME\");\r\n\r\n\tconst bugs = `https://wordpress.org/support/${args.domain === \"theme\" ? \"themes\" : \"plugins\"\r\n\t\t}/${slug}`;\r\n\r\n\treturn {\r\n\t\t...args.headers,\r\n\t\tname: args.headers?.name?.toString() || slug,\r\n\t\tauthor: authorName,\r\n\t\tauthorString: authorString, // this is the author + email address in this format: author <email>\r\n\t\tslug,\r\n\t\temail,\r\n\t\tbugs,\r\n\t\tlicense: args.headers?.license || \"gpl-2.0 or later\",\r\n\t\tversion:\r\n\t\t\targs.headers?.version || (pkgJsonData.version as string) || \"0.0.1\",\r\n\t\tlanguage: \"en\",\r\n\t\txDomain: args.headers?.textDomain?.toString() || slug,\r\n\t};\r\n}\r\n\r\n/**\r\n * Generates a POT header for a given set of arguments.\r\n * https://developer.wordpress.org/cli/commands/i18n/make-pot/\r\n * String that should be added as a comment to the top of the resulting POT file.\r\n * By default, a copyright comment is added for WordPress plugins and themes in the following manner:\r\n * `\r\n * Copyright (C) 2018 Example Plugin Author\r\n * This file is distributed under the same license as the Example Plugin package.\r\n * `\r\n * If a plugin or theme specifies a license in their main plugin file or stylesheet,\r\n * the comment looks like this: Copyright (C) 2018 Example Plugin Author This file is distributed under the GPLv2.\r\n *\r\n * @param args - The argument object containing the headers and their values.\r\n * @return The generated POT header.\r\n */\r\nexport async function generateHeader(\r\n\targs: Args,\r\n): Promise<Record<string, string> | null> {\r\n\t// Consolidate the user headers data into a single object\r\n\tconst headerData = consolidateUserHeaderData(args);\r\n\r\n\t// the makepot module name and version\r\n\tconst { name, version } = getPkgJsonData(modulePath, \"name\", \"version\");\r\n\r\n\t// Validate required fields - exit early if validation fails\r\n\tif (!validateRequiredFields(headerData, args.debug, args.options?.silent)) {\r\n\t\tif (args.options?.silent) {\r\n\t\t\t// In silent mode, we use defaults without asking\r\n\t\t} else {\r\n\t\t\t// Ask the user if default values should be used\r\n\t\t\tconst rl = readline.createInterface({\r\n\t\t\t\tinput: process.stdin,\r\n\t\t\t\toutput: process.stdout,\r\n\t\t\t});\r\n\r\n\t\t\tconst answer = await new Promise((resolve) => {\r\n\t\t\t\trl.question(\r\n\t\t\t\t\t\"\\nMissing required fields. Use default values? (y/N) \",\r\n\t\t\t\t\tresolve,\r\n\t\t\t\t);\r\n\t\t\t});\r\n\t\t\trl.close();\r\n\r\n\t\t\tif (\r\n\t\t\t\ttypeof answer === \"string\" &&\r\n\t\t\t\tanswer.toLowerCase() !== \"y\" &&\r\n\t\t\t\tanswer.toLowerCase() !== \"yes\"\r\n\t\t\t) {\r\n\t\t\t\tprocess.exit(1); // Exit with error code\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\t\"Project-Id-Version\": `${headerData.name} ${headerData.version}`,\r\n\t\t\"Report-Msgid-Bugs-To\": headerData.bugs,\r\n\t\t\"MIME-Version\": \"1.0\",\r\n\t\t\"Content-Transfer-Encoding\": \"8bit\",\r\n\t\t\"content-type\": `text/plain; charset=${getEncodingCharset(args.options?.charset)}`,\r\n\t\t\"plural-forms\": \"nplurals=2; plural=(n!=1);\",\r\n\t\t\"POT-Creation-Date\": `${new Date().toISOString()}`,\r\n\t\t\"PO-Revision-Date\": `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,\r\n\t\t\"Last-Translator\": headerData.authorString,\r\n\t\t\"Language-Team\": headerData.authorString,\r\n\t\t\"X-Generator\": `${name} ${version}`,\r\n\t\tLanguage: `${headerData.language}`,\r\n\t\t\"X-Domain\": headerData.xDomain,\r\n\t};\r\n}\r\n\r\n/**\r\n * Extracts main file data based on the given arguments.\r\n *\r\n * @param {Args} args - The arguments for extracting the main file data.\r\n * @return {Record<string, string>} The extracted main file data.\r\n */\r\nexport function extractMainFileData(args: Args): Record<string, string> {\r\n\tlet extractedData = {};\r\n\tif ([\"plugin\", \"block\", \"generic\"].includes(args.domain)) {\r\n\t\textractedData = extractPhpPluginData(args);\r\n\t} else if ([\"theme\", \"theme-block\"].includes(args.domain)) {\r\n\t\textractedData = extractCssThemeData(args);\r\n\t} else {\r\n\t\tconsole.log(\"No main file detected.\");\r\n\t}\r\n\r\n\treturn extractedData;\r\n}\r\n\r\n/**\r\n * Generate translation strings based on the given type and headers.\r\n *\r\n * @return {Record<string, string>} the generated translation strings\r\n * @param args\r\n */\r\nexport function translationsHeaders(args: Args): SetOfBlocks {\r\n\tconst { domain, headers } = args as Args;\r\n\tconst { name, description, author, authorUri, url } = headers as {\r\n\t\t[key in PotHeaders]: string;\r\n\t};\r\n\r\n\t// the main file is the plugin main php file or the css file\r\n\tconst fakePath = domain === \"plugin\" ? `${args.slug}.php` : \"style.css\";\r\n\r\n\tconst blocks = [];\r\n\r\n\tif (name) blocks.push(buildBlock(`Name of the ${domain}`, name, [fakePath]));\r\n\tif (url) blocks.push(buildBlock(`Url of the ${domain}`, url, [fakePath]));\r\n\tif (description) blocks.push(buildBlock(`Description of the ${domain}`, description, [fakePath]));\r\n\tif (author) blocks.push(buildBlock(`Author of the ${domain}`, author, [fakePath]));\r\n\tif (authorUri) blocks.push(buildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]));\r\n\r\n\treturn new SetOfBlocks(blocks);\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,0BAAoB;AACpB,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oB,IAAI;AAAA,EACzC,OAAO;AACN,YAAQ,IAAI,wBAAwB;AAAA,EACrC;AAEA,SAAO;AACR;AAQO,SAAS,oBAAoB,MAAyB;AAC5D,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAC5B,QAAM,EAAE,MAAM,aAAa,QAAQ,WAAW,IAAI,IAAI;AAKtD,QAAM,WAAW,WAAW,WAAW,GAAG,KAAK,IAAI,SAAS;AAE5D,QAAM,SAAS,CAAC;AAEhB,MAAI,KAAM,QAAO,SAAK,8BAAW,eAAe,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3E,MAAI,IAAK,QAAO,SAAK,8BAAW,cAAc,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxE,MAAI,YAAa,QAAO,SAAK,8BAAW,sBAAsB,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;AAChG,MAAI,OAAQ,QAAO,SAAK,8BAAW,iBAAiB,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACjF,MAAI,UAAW,QAAO,SAAK,8BAAW,qBAAqB,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;AAE3F,SAAO,IAAI,kCAAY,MAAM;AAC9B;",
|
|
6
6
|
"names": ["path", "process"]
|
|
7
7
|
}
|
package/lib/extractors/json.js
CHANGED
|
@@ -1 +1,70 @@
|
|
|
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 json_exports = {};
|
|
30
|
+
__export(json_exports, {
|
|
31
|
+
parseJsonCallback: () => parseJsonCallback,
|
|
32
|
+
parseJsonFile: () => parseJsonFile
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(json_exports);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"));
|
|
36
|
+
var import_extractors = require("../utils/extractors.js");
|
|
37
|
+
var import_schema = require("./schema.js");
|
|
38
|
+
async function parseJsonFile(opts) {
|
|
39
|
+
const isTheme = opts.filename === "theme.json";
|
|
40
|
+
const schema = {
|
|
41
|
+
url: isTheme ? import_schema.JsonSchemaExtractor.themeJsonSource : import_schema.JsonSchemaExtractor.blockJsonSource,
|
|
42
|
+
fallback: isTheme ? import_schema.JsonSchemaExtractor.themeJsonFallback : import_schema.JsonSchemaExtractor.blockJsonFallback
|
|
43
|
+
};
|
|
44
|
+
if (!schema.url || !schema.fallback) {
|
|
45
|
+
console.error("Schema URL or fallback not provided");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const jsonTranslations = await import_schema.JsonSchemaExtractor.parse(
|
|
49
|
+
opts.fileContent,
|
|
50
|
+
schema,
|
|
51
|
+
{
|
|
52
|
+
file: opts.filename,
|
|
53
|
+
addReferences: true
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return jsonTranslations ?? [];
|
|
57
|
+
}
|
|
58
|
+
async function parseJsonCallback(fileContent, filePath, filename) {
|
|
59
|
+
const data = await parseJsonFile({
|
|
60
|
+
fileContent,
|
|
61
|
+
filename
|
|
62
|
+
});
|
|
63
|
+
return (0, import_extractors.yieldParsedData)(data, filename, import_node_path.default.join(filePath, filename));
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
parseJsonCallback,
|
|
68
|
+
parseJsonFile
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -1 +1,55 @@
|
|
|
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 packageJson_exports = {};
|
|
30
|
+
__export(packageJson_exports, {
|
|
31
|
+
extractPackageJson: () => extractPackageJson
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(packageJson_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
35
|
+
var import_node_path = __toESM(require("node:path"));
|
|
36
|
+
var import_const = require("../const.js");
|
|
37
|
+
function extractPackageJson(args) {
|
|
38
|
+
const fields = import_const.pkgJsonHeaders;
|
|
39
|
+
const pkgJsonMeta = {};
|
|
40
|
+
const packageJsonPath = args.paths.cwd ? import_node_path.default.join(args.paths.cwd, "package.json") : "package.json";
|
|
41
|
+
if (import_node_fs.default.existsSync(packageJsonPath)) {
|
|
42
|
+
const packageJson = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
|
|
43
|
+
for (const field of Object.keys(fields)) {
|
|
44
|
+
if (field in packageJson) {
|
|
45
|
+
pkgJsonMeta[field] = `${packageJson[field]}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return pkgJsonMeta;
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
extractPackageJson
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=packageJson.js.map
|