@wp-blocks/make-pot 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/lib/cli/parseCli.js +11 -12
- package/lib/cli/parseCli.js.map +1 -1
- package/lib/const.js +1 -12
- package/lib/const.js.map +1 -1
- package/lib/extractors/headers.d.ts +2 -3
- package/lib/extractors/headers.js +23 -13
- package/lib/extractors/headers.js.map +1 -1
- package/lib/extractors/index.d.ts +2 -2
- package/lib/extractors/index.js +15 -25
- package/lib/extractors/index.js.map +1 -1
- package/lib/extractors/json.d.ts +3 -2
- package/lib/extractors/json.js +17 -30
- package/lib/extractors/json.js.map +1 -1
- package/lib/extractors/schema.d.ts +73 -2
- package/lib/extractors/schema.js +31 -52
- package/lib/extractors/schema.js.map +1 -1
- package/lib/extractors/text.js +3 -4
- package/lib/extractors/text.js.map +1 -1
- package/lib/extractors/utils.d.ts +4 -4
- package/lib/extractors/utils.js +17 -16
- package/lib/extractors/utils.js.map +1 -1
- package/lib/fs/glob.d.ts +2 -2
- package/lib/fs/glob.js +9 -21
- package/lib/fs/glob.js.map +1 -1
- package/lib/fs/index.js +2 -13
- package/lib/fs/index.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/parser/exec.d.ts +0 -1
- package/lib/parser/exec.js +38 -60
- package/lib/parser/exec.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +25 -19
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/patterns.js +6 -7
- package/lib/parser/patterns.js.map +1 -1
- package/lib/parser/process.d.ts +4 -5
- package/lib/parser/process.js +25 -57
- package/lib/parser/process.js.map +1 -1
- package/lib/parser/progress.d.ts +3 -0
- package/lib/parser/progress.js +21 -0
- package/lib/parser/progress.js.map +1 -0
- package/lib/parser/taskRunner.d.ts +4 -0
- package/lib/parser/taskRunner.js +33 -0
- package/lib/parser/taskRunner.js.map +1 -0
- package/lib/parser/tree.d.ts +2 -2
- package/lib/parser/tree.js +40 -23
- package/lib/parser/tree.js.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -2
- package/lib/utils/index.js.map +1 -1
- package/package.json +16 -3
- package/tests/extract.test.ts +95 -104
- package/tests/getFiles.test.ts +114 -114
- package/tests/ignoreFunction.test.ts +102 -126
- package/tests/tree.test.ts +6 -7
- package/tsconfig.json +3 -3
- package/lib/cliArgs.d.ts +0 -4
- package/lib/cliArgs.js +0 -216
- package/lib/cliArgs.js.map +0 -1
- package/lib/consolidate.d.ts +0 -2
- package/lib/consolidate.js +0 -37
- package/lib/consolidate.js.map +0 -1
- package/lib/fs.d.ts +0 -2
- package/lib/fs.js +0 -69
- package/lib/fs.js.map +0 -1
- package/lib/glob.d.ts +0 -13
- package/lib/glob.js +0 -95
- package/lib/glob.js.map +0 -1
- package/lib/makePot.d.ts +0 -2
- package/lib/makePot.js +0 -83
- package/lib/makePot.js.map +0 -1
- package/lib/maps.d.ts +0 -122
- package/lib/maps.js +0 -73
- package/lib/maps.js.map +0 -1
- package/lib/parser/consolidate.d.ts +0 -2
- package/lib/parser/consolidate.js +0 -37
- package/lib/parser/consolidate.js.map +0 -1
- package/lib/parser/makePot.d.ts +0 -2
- package/lib/parser/makePot.js +0 -35
- package/lib/parser/makePot.js.map +0 -1
- package/lib/parser.d.ts +0 -6
- package/lib/parser.js +0 -110
- package/lib/parser.js.map +0 -1
- package/lib/tree.d.ts +0 -2
- package/lib/tree.js +0 -78
- package/lib/tree.js.map +0 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +0 -78
- package/lib/utils.js.map +0 -1
- package/tests/consolidate.test.ts +0 -77
- package/tests/getStrings.test.ts +0 -85
- /package/{LICENSE.md → LICENSE} +0 -0
- /package/tests/{jsonParse.test.ts → jsonParse.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/@wp-blocks/make-pot)
|
|
2
|
+
[](https://github.com/wp-blocks/make-pot?tab=GPL-3.0-1-ov-file#readme)
|
|
3
|
+
[](https://github.com/wp-blocks/make-pot/actions/workflows/node.js.yml)
|
|
4
|
+
|
|
5
|
+
## Make Pot
|
|
2
6
|
|
|
3
7
|
`make-pot` is a Node.js module designed to generate the `.pot` file for your WordPress plugin or theme. This file serves as the basis for internationalization, allowing translators to localize your plugin or theme into different languages.
|
|
4
8
|
|
|
@@ -49,6 +53,17 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
|
49
53
|
- `--json`: Outputs the JSON gettext data.
|
|
50
54
|
- `--output`: Outputs the gettext data.
|
|
51
55
|
|
|
56
|
+
## As a build chain step
|
|
57
|
+
|
|
58
|
+
The `make-pot` module can be used as a build step in your build chain.
|
|
59
|
+
To do so, create a `build:makepot` action in your `package.json` with the following content (refer to the [options](https://github.com/wp-blocks/make-pot?tab=readme-ov-file#options) for more information):
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"build:makepot": "npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
52
67
|
### Credits
|
|
53
68
|
|
|
54
69
|
This module is heavily inspired by the original `makepot` command from [WP-CLI](https://github.com/wp-cli/i18n-command).
|
|
@@ -56,3 +71,5 @@ Special thanks to the maintainers in particular [Swissspidy](https://github.com/
|
|
|
56
71
|
has been very helpful with suggestions and tips on how to rebuild `make-pot`.
|
|
57
72
|
|
|
58
73
|
Feel free to contribute or report issues on [GitHub](https://github.com/example/example).
|
|
74
|
+
|
|
75
|
+
This tool is licensed under the [GNU General Public License v3](LICENSE).
|
package/lib/cli/parseCli.js
CHANGED
|
@@ -51,16 +51,15 @@ function isThemeOrPlugin(currentPath = '/', slug) {
|
|
|
51
51
|
currentWorkingDirectory +
|
|
52
52
|
' does not contain a style.css file');
|
|
53
53
|
}
|
|
54
|
-
if (currentWorkingDirectory.includes('themes')) {
|
|
54
|
+
if (currentWorkingDirectory.includes('wp-content' + path.sep + 'themes')) {
|
|
55
55
|
return 'theme';
|
|
56
56
|
}
|
|
57
|
-
else if (currentWorkingDirectory.includes('plugins')) {
|
|
57
|
+
else if (currentWorkingDirectory.includes('wp-content' + path.sep + 'plugins')) {
|
|
58
58
|
return 'plugin';
|
|
59
59
|
}
|
|
60
60
|
return 'generic';
|
|
61
61
|
}
|
|
62
62
|
function parseCliArgs(args) {
|
|
63
|
-
var _a, _b, _c, _d, _e, _f;
|
|
64
63
|
const inputPath = typeof args._[0] === 'string' ? args._[0] : '.';
|
|
65
64
|
const outputPath = typeof args._[1] === 'string' ? args._[1] : '.';
|
|
66
65
|
const currentWorkingDirectory = process.cwd();
|
|
@@ -69,18 +68,18 @@ function parseCliArgs(args) {
|
|
|
69
68
|
: path.basename(path.resolve(currentWorkingDirectory, inputPath));
|
|
70
69
|
const cwd = path.relative(currentWorkingDirectory, inputPath);
|
|
71
70
|
const out = path.relative(currentWorkingDirectory, outputPath);
|
|
72
|
-
const domain =
|
|
71
|
+
const domain = args?.domain ?? isThemeOrPlugin(path.resolve(cwd), slug);
|
|
73
72
|
const parsedArgs = {
|
|
74
73
|
slug: slug,
|
|
75
74
|
domain: domain,
|
|
76
75
|
paths: { cwd: cwd, out: out },
|
|
77
76
|
options: {
|
|
78
|
-
ignoreDomain: !!
|
|
77
|
+
ignoreDomain: !!args?.ignoreDomain,
|
|
79
78
|
packageName: String(args.packageName),
|
|
80
79
|
silent: !!args.silent,
|
|
81
80
|
json: !!args.json,
|
|
82
|
-
location: !!
|
|
83
|
-
output: !!
|
|
81
|
+
location: !!args?.location,
|
|
82
|
+
output: !!args?.output,
|
|
84
83
|
fileComment: args.fileComment
|
|
85
84
|
? String(args.fileComment)
|
|
86
85
|
: undefined,
|
|
@@ -94,14 +93,14 @@ function parseCliArgs(args) {
|
|
|
94
93
|
},
|
|
95
94
|
},
|
|
96
95
|
headers: {
|
|
97
|
-
fileComment:
|
|
96
|
+
fileComment: args.fileComment ?? '',
|
|
98
97
|
},
|
|
99
98
|
patterns: {
|
|
100
|
-
mergePaths: (
|
|
101
|
-
subtractPaths: (
|
|
99
|
+
mergePaths: (0, utils_1.stringstring)(args.mergePaths) ?? [],
|
|
100
|
+
subtractPaths: (0, utils_1.stringstring)(args.subtractPaths) ?? [],
|
|
102
101
|
subtractAndMerge: !!args.subtractAndMerge,
|
|
103
|
-
include: (
|
|
104
|
-
exclude: (
|
|
102
|
+
include: (0, utils_1.stringstring)(args.include) ?? ['**'],
|
|
103
|
+
exclude: (0, utils_1.stringstring)(args.exclude) ?? const_1.DEFAULT_EXCLUDED_PATH,
|
|
105
104
|
},
|
|
106
105
|
};
|
|
107
106
|
parsedArgs.paths.root = args.root ? String(args.root) : undefined;
|
package/lib/cli/parseCli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCli.js","sourceRoot":"","sources":["../../src/cli/parseCli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAAuC;AACvC,2CAA4B;AAC5B,iDAAkC;AAClC,oCAAgD;AAEhD,mDAAwC;AAExC,SAAS,eAAe,CAAC,cAAsB,GAAG,EAAE,IAAY;IAC/D,MAAM,uBAAuB,GAAG,WAAW,CAAA;IAE3C,IAAI,CAAC;QACJ,IAAA,oBAAU,EACT,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,IAAI,GAAG,MAAM,CAAC,EACjD,iBAAE,CAAC,SAAS,CAAC,IAAI,CACjB,CAAA;QACD,OAAO,QAAQ,CAAA;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAEd,OAAO,CAAC,GAAG,CACV,gCAAgC;YAC/B,uBAAuB;YACvB,sBAAsB;YACtB,IAAI;YACJ,WAAW,CACZ,CAAA;IACF,CAAC;IAED,IAAI,CAAC;QACJ,IAAA,oBAAU,EACT,IAAI,CAAC,IAAI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iB,CAAC,IAAI,CAAC,IAAI,CAAC;YACvD,OAAO,EACN,IAAA,oBAAY,EAAC,IAAI,CAAC,OAAiB,CAAC,IAAI,6BAAqB;SAC9D;KACD,CAAA;IAED,UAAU,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEjE,OAAO,UAAU,CAAA;AAClB,CAAC;AA3DD,oCA2DC"}
|
package/lib/const.js
CHANGED
|
@@ -54,18 +54,7 @@ exports.DEFAULT_EXCLUDED_PATH = [
|
|
|
54
54
|
'**.test.**',
|
|
55
55
|
'tests',
|
|
56
56
|
];
|
|
57
|
-
exports.allowedFiles = [
|
|
58
|
-
'php',
|
|
59
|
-
'js',
|
|
60
|
-
'jsx',
|
|
61
|
-
'ts',
|
|
62
|
-
'tsx',
|
|
63
|
-
'mjs',
|
|
64
|
-
'cjs',
|
|
65
|
-
'txt',
|
|
66
|
-
'html',
|
|
67
|
-
'json',
|
|
68
|
-
];
|
|
57
|
+
exports.allowedFiles = ['php', 'js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs'];
|
|
69
58
|
exports.i18nFunctions = {
|
|
70
59
|
__: ['msgid', 'text_domain'],
|
|
71
60
|
esc_attr__: ['msgid', 'text_domain'],
|
package/lib/const.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAqD;AACrD,oEAAqD;AACrD,wEAAyD;AACzD,yEAA0D;AAC1D,2EAA4D;AAC5D,kDAA4D;AAU/C,QAAA,OAAO,GAA4B;IAC/C,IAAI,EAAJ,mBAAI;IACJ,OAAO,EAAP,sBAAO;IACP,WAAW,EAAX,0BAAW;CACX,CAAA;AAKY,QAAA,SAAS,GAAG,SAAS,CAAA;AACrB,Q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1
|
import { Args, PotHeaders } from '../types';
|
|
2
|
+
import { SetOfBlocks } from 'gettext-merger';
|
|
2
3
|
export declare function generateHeader(args: Args): Record<PotHeaders, string>;
|
|
3
4
|
export declare function extractMainFileData(args: Args): Record<string, string>;
|
|
4
|
-
export declare function translationsHeaders(args: Args):
|
|
5
|
-
[x: string]: import("gettext-parser").GetTextTranslation;
|
|
6
|
-
};
|
|
5
|
+
export declare function translationsHeaders(args: Args): SetOfBlocks;
|
|
@@ -5,15 +5,25 @@ const php_1 = require("./php");
|
|
|
5
5
|
const css_1 = require("./css");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
const const_1 = require("../const");
|
|
8
|
+
const gettext_merger_1 = require("gettext-merger");
|
|
8
9
|
function generateHeader(args) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const headerData = {
|
|
11
|
+
...args.headers,
|
|
12
|
+
author: args.headers?.author || 'AUTHOR',
|
|
13
|
+
slug: args.slug || 'PLUGIN NAME',
|
|
14
|
+
email: args.headers?.email || 'EMAIL',
|
|
15
|
+
license: args.headers?.license || 'gpl-2.0 or later',
|
|
16
|
+
version: args.headers?.version || '1.0.0',
|
|
17
|
+
language: args.headers?.language || 'en',
|
|
18
|
+
domain: args.headers?.textDomain || args.headers?.slug || undefined,
|
|
19
|
+
bugs: {
|
|
20
|
+
url: args.headers?.bugsUrl ||
|
|
12
21
|
'https://wordpress.org/support/plugin/' + args.slug,
|
|
13
|
-
email:
|
|
14
|
-
|
|
22
|
+
email: args.headers?.bugsEmail ||
|
|
23
|
+
args.headers?.authoremail ||
|
|
15
24
|
'AUTHOR EMAIL',
|
|
16
|
-
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
17
27
|
const authorString = `${headerData.author} <${headerData.email}>`;
|
|
18
28
|
const domain = headerData.domain ? `X-Domain: ${headerData.domain}` : '';
|
|
19
29
|
return {
|
|
@@ -51,13 +61,13 @@ function translationsHeaders(args) {
|
|
|
51
61
|
const { domain, headers } = args;
|
|
52
62
|
const { name, description, author, authorUri, url } = headers;
|
|
53
63
|
const fakePath = domain === 'plugin' ? args.slug + '.php' : 'style.css';
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
return new gettext_merger_1.SetOfBlocks([
|
|
65
|
+
(0, utils_1.gentranslation)(`Name of the ${domain}`, name, fakePath),
|
|
66
|
+
(0, utils_1.gentranslation)(`Url of the ${domain}`, url, fakePath),
|
|
67
|
+
(0, utils_1.gentranslation)(`Description of the ${domain}`, description, fakePath),
|
|
68
|
+
(0, utils_1.gentranslation)(`Author of the ${domain}`, author, fakePath),
|
|
69
|
+
(0, utils_1.gentranslation)(`Author URI of the ${domain}`, authorUri, fakePath),
|
|
70
|
+
]);
|
|
61
71
|
}
|
|
62
72
|
exports.translationsHeaders = translationsHeaders;
|
|
63
73
|
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/extractors/headers.ts"],"names":[],"mappings":";;;AACA,+BAA4C;AAC5C,+BAA2C;AAC3C,mCAAwC;AACxC,oCAAkC;
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/extractors/headers.ts"],"names":[],"mappings":";;;AACA,+BAA4C;AAC5C,+BAA2C;AAC3C,mCAAwC;AACxC,oCAAkC;AAClC,mDAA4C;AAiB5C,SAAgB,cAAc,CAAC,IAAU;IAExC,MAAM,UAAU,GAAG;QAClB,GAAG,IAAI,CAAC,OAAO;QACf,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,QAAQ;QACxC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,aAAa;QAChC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,OAAO;QACrC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,kBAAkB;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AAE,SAAS,EAAE,QAAQ,CAAC;KAClE,CAAC,CAAA;AACH,CAAC;AApBD,kDAoBC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function parseFile(file: string, filePath?: string): Promise<
|
|
1
|
+
import { SetOfBlocks } from 'gettext-merger';
|
|
2
|
+
export declare function parseFile(file: string, filePath?: string): Promise<SetOfBlocks | undefined>;
|
package/lib/extractors/index.js
CHANGED
|
@@ -22,39 +22,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.parseFile = void 0;
|
|
36
27
|
const path = __importStar(require("path"));
|
|
37
28
|
const fs_1 = require("../fs");
|
|
38
29
|
const json_1 = require("./json");
|
|
39
30
|
const tree_1 = require("../parser/tree");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'php'].includes(ext)) {
|
|
53
|
-
return (0, fs_1.readFileAsync)(fileRealPath).then((sourceCode) => {
|
|
54
|
-
return (0, tree_1.doTree)(sourceCode, file);
|
|
31
|
+
const const_1 = require("../const");
|
|
32
|
+
async function parseFile(file, filePath = '') {
|
|
33
|
+
const filename = path.basename(file);
|
|
34
|
+
const ext = path.extname(file).replace(/^./, '');
|
|
35
|
+
const fileRealPath = path.resolve(filePath, file);
|
|
36
|
+
if (ext === 'json') {
|
|
37
|
+
if (filename === 'theme.json' || filename === 'block.json') {
|
|
38
|
+
return (0, fs_1.readFileAsync)(fileRealPath).then(async (sourceCode) => {
|
|
39
|
+
return await (0, json_1.parseJsonCallback)(sourceCode, filePath, filename);
|
|
55
40
|
});
|
|
56
41
|
}
|
|
57
|
-
}
|
|
42
|
+
}
|
|
43
|
+
if (const_1.allowedFiles.includes(ext)) {
|
|
44
|
+
return (0, fs_1.readFileAsync)(fileRealPath).then((sourceCode) => {
|
|
45
|
+
return (0, tree_1.doTree)(sourceCode, file);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
58
48
|
}
|
|
59
49
|
exports.parseFile = parseFile;
|
|
60
50
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extractors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extractors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,8BAAqC;AACrC,iCAA0C;AAC1C,yCAAuC;AAEvC,oCAAuC;AAOhC,KAAK,UAAU,SAAS,CAC9B,IAAY,EACZ,WAAmB,EAAE;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAChD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAEjD,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACpB,IAAI,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC5D,OAAO,IAAA,kBAAa,EAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;gBAC5D,OAAO,MAAM,IAAA,wBAAiB,EAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC/D,CAAC,CAAC,CAAA;QACH,CAAC;IACF,CAAC;IAED,IAAI,oBAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAEhC,OAAO,IAAA,kBAAa,EAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;YACtD,OAAO,IAAA,aAAM,EAAC,UAAU,EAAE,IAAI,CAAC,CAAA;QAChC,CAAC,CAAC,CAAA;IACH,CAAC;AACF,CAAC;AAtBD,8BAsBC"}
|
package/lib/extractors/json.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Args, I18nSchema
|
|
1
|
+
import type { Args, I18nSchema } from '../types';
|
|
2
|
+
import { SetOfBlocks } from 'gettext-merger';
|
|
2
3
|
export declare function parseJsonFile(opts: {
|
|
3
4
|
fileContent: string;
|
|
4
5
|
filename: 'block.json' | 'theme.json';
|
|
@@ -6,4 +7,4 @@ export declare function parseJsonFile(opts: {
|
|
|
6
7
|
}): Promise<I18nSchema>;
|
|
7
8
|
export declare function getJsonComment(key: string, type?: string): string;
|
|
8
9
|
export declare function extractPackageJson(args: Args): Record<string, string>;
|
|
9
|
-
export declare function parseJsonCallback(fileContent: string, filePath: string, filename: 'block.json' | 'theme.json'): Promise<
|
|
10
|
+
export declare function parseJsonCallback(fileContent: string, filePath: string, filename: 'block.json' | 'theme.json'): Promise<SetOfBlocks>;
|
package/lib/extractors/json.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -18,20 +9,18 @@ const schema_1 = require("./schema");
|
|
|
18
9
|
const path_1 = __importDefault(require("path"));
|
|
19
10
|
const fs_1 = __importDefault(require("fs"));
|
|
20
11
|
const utils_1 = require("./utils");
|
|
21
|
-
function parseJsonFile(opts) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
addReferences: true,
|
|
32
|
-
});
|
|
33
|
-
return jsonTranslations !== null && jsonTranslations !== void 0 ? jsonTranslations : {};
|
|
12
|
+
async function parseJsonFile(opts) {
|
|
13
|
+
const jsonTranslations = await schema_1.JsonSchemaExtractor.fromString(opts.fileContent, {
|
|
14
|
+
file: opts.filename,
|
|
15
|
+
schema: opts.filename === 'theme.json'
|
|
16
|
+
? schema_1.JsonSchemaExtractor.themeJsonSource
|
|
17
|
+
: schema_1.JsonSchemaExtractor.blockJsonSource,
|
|
18
|
+
schemaFallback: opts.filename === 'theme.json'
|
|
19
|
+
? schema_1.JsonSchemaExtractor.themeJsonFallback
|
|
20
|
+
: schema_1.JsonSchemaExtractor.blockJsonFallback,
|
|
21
|
+
addReferences: true,
|
|
34
22
|
});
|
|
23
|
+
return jsonTranslations ?? {};
|
|
35
24
|
}
|
|
36
25
|
exports.parseJsonFile = parseJsonFile;
|
|
37
26
|
function getSchema(type) {
|
|
@@ -68,15 +57,13 @@ function extractPackageJson(args) {
|
|
|
68
57
|
return pkgJsonMeta;
|
|
69
58
|
}
|
|
70
59
|
exports.extractPackageJson = extractPackageJson;
|
|
71
|
-
function parseJsonCallback(fileContent, filePath, filename) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
filepath: filePath,
|
|
77
|
-
});
|
|
78
|
-
return (0, utils_1.yieldParsedData)(data, filename, path_1.default.join(filePath, filename));
|
|
60
|
+
async function parseJsonCallback(fileContent, filePath, filename) {
|
|
61
|
+
const data = await parseJsonFile({
|
|
62
|
+
fileContent: fileContent,
|
|
63
|
+
filename: filename,
|
|
64
|
+
filepath: filePath,
|
|
79
65
|
});
|
|
66
|
+
return (0, utils_1.yieldParsedData)(data, filename, path_1.default.join(filePath, filename));
|
|
80
67
|
}
|
|
81
68
|
exports.parseJsonCallback = parseJsonCallback;
|
|
82
69
|
//# sourceMappingURL=json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/extractors/json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/extractors/json.ts"],"names":[],"mappings":";;;;;;AACA,oCAA+D;AAC/D,qCAA8C;AAC9C,gDAAuB;AACvB,4CAAmB;AACnB,mCAAyC;AAYlC,KAAK,UAAU,aAAa,CAAC,IAInC;IACA,MAAM,gBAAgB,GAAG,MAAM,4BAAmB,CAAC,UAAU,CAC5D,IAAI,CAAC,WAAW,EAChB;QACC,IAAI,EAAE,IAAI,CAAC,QAAQ;QACnB,MAA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e,EAAE,MAAM,CAAC,CAAC,CAAA;QACxE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAEzC,IAAI,KAAK,IAAI,WAAW,EAAE,CAAC;gBAC1B,WAAW,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAW,CAAA;YAClD,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,WAAW,CAAA;AACnB,CAAC;AArBD,gDAqBC;AAUM,KAAK,UAAU,iBAAiB,CACtC,WAAmB,EACnB,QAAgB,EAChB,QAAqC;IAErC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;QAChC,WAAW,EAAE,WAAW;QACxB,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;KAClB,CAAC,CAAA;IAEF,OAAO,IAAA,uBAAe,EACrB,IAAyC,EACzC,QAAQ,EACR,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAC7B,CAAA;AACF,CAAC;AAhBD,8CAgBC"}
|
|
@@ -2,9 +2,80 @@ import { I18nSchema } from '../types';
|
|
|
2
2
|
export declare class JsonSchemaExtractor {
|
|
3
3
|
private static schemaCache;
|
|
4
4
|
static themeJsonSource: string;
|
|
5
|
-
static themeJsonFallback:
|
|
5
|
+
static themeJsonFallback: {
|
|
6
|
+
title: string;
|
|
7
|
+
settings: {
|
|
8
|
+
typography: {
|
|
9
|
+
fontSizes: {
|
|
10
|
+
name: string;
|
|
11
|
+
}[];
|
|
12
|
+
fontFamilies: {
|
|
13
|
+
name: string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
color: {
|
|
17
|
+
palette: {
|
|
18
|
+
name: string;
|
|
19
|
+
}[];
|
|
20
|
+
gradients: {
|
|
21
|
+
name: string;
|
|
22
|
+
}[];
|
|
23
|
+
duotone: {
|
|
24
|
+
name: string;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
spacing: {
|
|
28
|
+
spacingSizes: {
|
|
29
|
+
name: string;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
blocks: {
|
|
33
|
+
"*": {
|
|
34
|
+
typography: {
|
|
35
|
+
fontSizes: {
|
|
36
|
+
name: string;
|
|
37
|
+
}[];
|
|
38
|
+
fontFamilies: {
|
|
39
|
+
name: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
color: {
|
|
43
|
+
palette: {
|
|
44
|
+
name: string;
|
|
45
|
+
}[];
|
|
46
|
+
gradients: {
|
|
47
|
+
name: string;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
spacing: {
|
|
51
|
+
spacingSizes: {
|
|
52
|
+
name: string;
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
customTemplates: {
|
|
59
|
+
title: string;
|
|
60
|
+
}[];
|
|
61
|
+
templateParts: {
|
|
62
|
+
title: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
6
65
|
static blockJsonSource: string;
|
|
7
|
-
static blockJsonFallback:
|
|
66
|
+
static blockJsonFallback: {
|
|
67
|
+
title: string;
|
|
68
|
+
description: string;
|
|
69
|
+
keywords: string[];
|
|
70
|
+
styles: {
|
|
71
|
+
label: string;
|
|
72
|
+
}[];
|
|
73
|
+
variations: {
|
|
74
|
+
title: string;
|
|
75
|
+
description: string;
|
|
76
|
+
keywords: string[];
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
8
79
|
private static loadSchema;
|
|
9
80
|
static fromString(text: string, options: {
|
|
10
81
|
[key: string]: unknown;
|
package/lib/extractors/schema.js
CHANGED
|
@@ -22,64 +22,43 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
37
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
29
|
exports.JsonSchemaExtractor = void 0;
|
|
39
30
|
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const themei18n = __importStar(require("../assets/theme-i18n.json"));
|
|
32
|
+
const blocki18n = __importStar(require("../assets/block-i18n.json"));
|
|
40
33
|
class JsonSchemaExtractor {
|
|
41
|
-
static loadSchema(url, fallback) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.error(`Failed to load schema from ${url}. Using fallback.`);
|
|
57
|
-
try {
|
|
58
|
-
const fallbackData = yield Promise.resolve(`${fallback}`).then(s => __importStar(require(s)));
|
|
59
|
-
this.schemaCache[url] = fallbackData.default;
|
|
60
|
-
return fallbackData.default;
|
|
61
|
-
}
|
|
62
|
-
catch (fallbackError) {
|
|
63
|
-
console.error(`Failed to load fallback schema from ${fallback}.`);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
34
|
+
static async loadSchema(url, fallback) {
|
|
35
|
+
if (this.schemaCache.url) {
|
|
36
|
+
return this.schemaCache.url;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const response = await axios_1.default.get(url);
|
|
40
|
+
this.schemaCache.url = response.data;
|
|
41
|
+
return response.data;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error(`Failed to load schema from ${url}. Using fallback.`);
|
|
45
|
+
const fallbackData = fallback;
|
|
46
|
+
this.schemaCache.url = fallbackData;
|
|
47
|
+
return fallbackData;
|
|
48
|
+
}
|
|
68
49
|
}
|
|
69
|
-
static fromString(text, options) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return this.extractStringsUsingI18nSchema(schema, json);
|
|
82
|
-
});
|
|
50
|
+
static async fromString(text, options) {
|
|
51
|
+
const schema = await this.loadSchema(options.schema, options.schemaFallback);
|
|
52
|
+
if (!schema) {
|
|
53
|
+
console.error('Failed to load schema.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const json = JSON.parse(text);
|
|
57
|
+
if (json === null) {
|
|
58
|
+
console.error(`Could not parse JSON.`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
return this.extractStringsUsingI18nSchema(schema, json);
|
|
83
62
|
}
|
|
84
63
|
static extractStringsUsingI18nSchema(i18nSchema, settings) {
|
|
85
64
|
if (!i18nSchema || !settings) {
|
|
@@ -115,7 +94,7 @@ class JsonSchemaExtractor {
|
|
|
115
94
|
exports.JsonSchemaExtractor = JsonSchemaExtractor;
|
|
116
95
|
JsonSchemaExtractor.schemaCache = {};
|
|
117
96
|
JsonSchemaExtractor.themeJsonSource = 'http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json';
|
|
118
|
-
JsonSchemaExtractor.themeJsonFallback =
|
|
97
|
+
JsonSchemaExtractor.themeJsonFallback = themei18n;
|
|
119
98
|
JsonSchemaExtractor.blockJsonSource = 'http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json';
|
|
120
|
-
JsonSchemaExtractor.blockJsonFallback =
|
|
99
|
+
JsonSchemaExtractor.blockJsonFallback = blocki18n;
|
|
121
100
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/extractors/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/extractors/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAAyB;AAEzB,qEAAsD;AACtD,qEAAsD;AAKtD,MAAa,mBAAmB;IAmBvB,MAAM,CAAC,KAAK,CAAC,UAAU,CAC9B,GAAW,EACX,QAAoB;QAEpB,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAA;QAC5B,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACrC,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAA;YACpC,OAAO,QAAQ,CAAC,IAAI,CAAA;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,8BAA8B,GAAG,mBAAmB,CAAC,CAAA;YACnE,MAAM,YAAY,GAAG,QAAQ,CAAA;YAC7B,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,YAAY,CAAA;YACnC,OAAO,YAAY,CAAA;QACpB,CAAC;IACF,CAAC;IASM,MAAM,CAAC,KAAK,CAAC,UAAU,CAC7B,IAAY,EACZ,OAAmC;QAEnC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,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I,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBACrB,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;gBAC9B,CAAC;qBAAM,IACN,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EACzD,CAAC;oBACF,MAAM,SAAS,GAAG,IAAI,CAAC,6BAA6B,CACnD,UAAU,CAAC,QAAQ,CAAe,EAClC,KAAK,CACL,CAAA;oBACD,IAAI,SAAS,EAAE,CAAC;wBACf,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;oBACjC,CAAC;gBACF,CAAC;YACF,CAAC;YACD,OAAO,MAAM,CAAA;QACd,CAAC;QAED,OAAO,EAAE,CAAA;IACV,CAAC;;AArHF,kDAsHC;AArHe,+BAAW,GAAkC,EAAE,CAAA;AAGvD,mCAAe,GACrB,wEAAwE,CAAA;AAClE,qCAAiB,GAAG,SAAS,CAAA;AAE7B,mCAAe,GACrB,wEAAwE,CAAA;AAClE,qCAAiB,GAAG,SAAS,CAAA"}
|
package/lib/extractors/text.js
CHANGED
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.extractFileData = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
function extractFileData(fileContent, separator = ':') {
|
|
6
|
-
var _a;
|
|
7
6
|
const data = {};
|
|
8
|
-
(
|
|
9
|
-
|
|
7
|
+
(0, utils_1.removeCommentMarkup)(fileContent)
|
|
8
|
+
?.forEach((line) => {
|
|
10
9
|
const parts = line.split(separator);
|
|
11
10
|
if (parts.length !== 2 && Object.values(data).length > 0) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
|
-
data[
|
|
13
|
+
data[parts[0]?.trim()] = parts[1]?.trim();
|
|
15
14
|
});
|
|
16
15
|
return data;
|
|
17
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/extractors/text.ts"],"names":[],"mappings":";;;AAAA,oCAA+D;AAW/D,SAAgB,eAAe,CAC9B,WAAmB,EACnB,YAAoB,GAAG
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/extractors/text.ts"],"names":[],"mappings":";;;AAAA,oCAA+D;AAW/D,SAAgB,eAAe,CAC9B,WAAmB,EACnB,YAAoB,GAAG;IAEvB,MAAM,IAAI,GAA2B,EAAE,CAAA;IAGvC,IAAA,2BAAmB,EAAC,WAAW,CAAC;QAE/B,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAInC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1D,OAAM;QACP,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEH,OAAO,IAAI,CAAA;AACZ,CAAC;AArBD,0CAqBC"}
|