@wp-blocks/make-pot 1.2.0 → 1.3.1
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/.gitignore +11 -0
- package/.npmignore +12 -0
- package/biome.json +12 -0
- package/lib/assets/block-i18n.js +1 -0
- package/lib/assets/package-i18n.js +1 -0
- package/lib/assets/theme-i18n.js +1 -0
- package/lib/assets/wp-plugin-i18n.js +1 -0
- package/lib/assets/wp-theme-i18n.js +1 -0
- package/lib/cli/getArgs.js +1 -0
- package/lib/cli/parseCli.js +1 -110
- package/lib/const.js +1 -82
- package/lib/extractors/css.js +1 -42
- package/lib/extractors/headers.js +1 -73
- package/lib/extractors/json.js +1 -69
- package/lib/extractors/php.js +2 -49
- package/lib/extractors/schema.js +1 -100
- package/lib/extractors/text.js +1 -18
- package/lib/extractors/utils.js +1 -55
- package/lib/fs/fs.js +1 -0
- package/lib/fs/glob.js +3 -83
- package/lib/index.js +1 -26
- package/lib/parser/exec.js +3 -49
- package/lib/parser/makePot.js +1 -0
- package/lib/parser/patterns.js +1 -33
- package/lib/parser/process.js +1 -38
- package/lib/parser/progress.js +1 -21
- package/lib/parser/taskRunner.js +1 -33
- package/lib/parser/tree.js +1 -104
- package/lib/run.js +1 -0
- package/lib/types.js +1 -3
- package/lib/utils/common.js +2 -0
- package/package.json +38 -36
- package/tests/{extract.test.ts → extract.test.js} +139 -140
- package/tests/getFiles.test.no.js +85 -0
- package/tests/jsonParse.no.js +49 -0
- package/tests/{tree.test.ts → tree.test.js} +74 -67
- package/tests/wpcliCompare.no.js +32 -0
- package/tsconfig.json +4 -20
- package/ .prettierignore +0 -3
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -12
- package/jest.config.json +0 -18
- package/lib/assets/block-i18n.json +0 -17
- package/lib/assets/package-i18n.json +0 -13
- package/lib/assets/theme-i18n.json +0 -86
- package/lib/assets/wp-plugin-i18n.json +0 -14
- package/lib/assets/wp-theme-i18n.json +0 -13
- package/lib/cli/index.d.ts +0 -1
- package/lib/cli/index.js +0 -114
- package/lib/cli/index.js.map +0 -1
- package/lib/cli/parseCli.d.ts +0 -3
- package/lib/cli/parseCli.js.map +0 -1
- package/lib/const.d.ts +0 -140
- package/lib/const.js.map +0 -1
- package/lib/extractors/css.d.ts +0 -2
- package/lib/extractors/css.js.map +0 -1
- package/lib/extractors/headers.d.ts +0 -5
- package/lib/extractors/headers.js.map +0 -1
- package/lib/extractors/index.d.ts +0 -2
- package/lib/extractors/index.js +0 -50
- package/lib/extractors/index.js.map +0 -1
- package/lib/extractors/json.d.ts +0 -10
- package/lib/extractors/json.js.map +0 -1
- package/lib/extractors/php.d.ts +0 -3
- package/lib/extractors/php.js.map +0 -1
- package/lib/extractors/schema.d.ts +0 -84
- package/lib/extractors/schema.js.map +0 -1
- package/lib/extractors/text.d.ts +0 -1
- package/lib/extractors/text.js.map +0 -1
- package/lib/extractors/utils.d.ts +0 -5
- package/lib/extractors/utils.js.map +0 -1
- package/lib/fs/glob.d.ts +0 -13
- package/lib/fs/glob.js.map +0 -1
- package/lib/fs/index.d.ts +0 -2
- package/lib/fs/index.js +0 -58
- package/lib/fs/index.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js.map +0 -1
- package/lib/parser/exec.d.ts +0 -2
- package/lib/parser/exec.js.map +0 -1
- package/lib/parser/index.d.ts +0 -2
- package/lib/parser/index.js +0 -30
- package/lib/parser/index.js.map +0 -1
- package/lib/parser/patterns.d.ts +0 -2
- package/lib/parser/patterns.js.map +0 -1
- package/lib/parser/process.d.ts +0 -4
- package/lib/parser/process.js.map +0 -1
- package/lib/parser/progress.d.ts +0 -3
- package/lib/parser/progress.js.map +0 -1
- package/lib/parser/taskRunner.d.ts +0 -4
- package/lib/parser/taskRunner.js.map +0 -1
- package/lib/parser/tree.d.ts +0 -2
- package/lib/parser/tree.js.map +0 -1
- package/lib/types.d.ts +0 -50
- package/lib/types.js.map +0 -1
- package/lib/utils/index.d.ts +0 -9
- package/lib/utils/index.js +0 -83
- package/lib/utils/index.js.map +0 -1
- package/tests/getFiles.test.ts +0 -114
- package/tests/ignoreFunction.test.ts +0 -102
- package/tests/jsonParse.ts +0 -51
|
@@ -1,117 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
expected
|
|
1
|
+
const { describe, it, beforeEach, before } = require("node:test");
|
|
2
|
+
const assert = require("node:assert");
|
|
3
|
+
const { Block } = require("gettext-merger");
|
|
4
|
+
const { doTree } = require("../lib/");
|
|
5
|
+
|
|
6
|
+
describe("getStrings", () => {
|
|
7
|
+
it("should extract translations from js", () => {
|
|
8
|
+
const content = `var foo = __('Hello World', 'greeting');`;
|
|
9
|
+
const filename = "filename.js";
|
|
10
|
+
|
|
11
|
+
const result = doTree(content, filename);
|
|
12
|
+
const expected = new Block([]);
|
|
13
|
+
expected.msgid = "Hello World";
|
|
13
14
|
expected.comments = {
|
|
14
|
-
reference: [
|
|
15
|
-
translator: [
|
|
16
|
-
}
|
|
15
|
+
reference: ["filename.js:1"],
|
|
16
|
+
translator: [""],
|
|
17
|
+
};
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
})
|
|
19
|
+
assert.strictEqual(result.blocks[0].msgid, expected.msgid);
|
|
20
|
+
});
|
|
20
21
|
|
|
21
|
-
it(
|
|
22
|
-
const content = `__('Hello World', 'greeting')
|
|
23
|
-
const filename =
|
|
22
|
+
it("should extract translations from ts", () => {
|
|
23
|
+
const content = `__('Hello World', 'greeting');`;
|
|
24
|
+
const filename = "filename.ts";
|
|
24
25
|
|
|
25
|
-
const result = doTree(content, filename).blocks[0].toJson()
|
|
26
|
+
const result = doTree(content, filename).blocks[0].toJson();
|
|
26
27
|
|
|
27
|
-
const expected = new Block([])
|
|
28
|
-
expected.msgid =
|
|
28
|
+
const expected = new Block([]);
|
|
29
|
+
expected.msgid = "Hello World";
|
|
29
30
|
expected.comments = {
|
|
30
|
-
reference: [
|
|
31
|
-
translator: [
|
|
32
|
-
}
|
|
31
|
+
reference: ["filename.ts:1"],
|
|
32
|
+
translator: [""],
|
|
33
|
+
};
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
assert.strictEqual(result.msgid, expected.msgid);
|
|
36
|
+
assert.strictEqual(expected.comments?.reference.length, 1);
|
|
37
|
+
assert.deepStrictEqual(
|
|
38
|
+
[result.comments.reference],
|
|
39
|
+
expected.comments.reference,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should extract translations from tsx", () => {
|
|
44
|
+
const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`;
|
|
42
45
|
|
|
43
|
-
const filename =
|
|
46
|
+
const filename = "filename.tsx";
|
|
44
47
|
|
|
45
|
-
const result = doTree(content, filename)
|
|
48
|
+
const result = doTree(content, filename);
|
|
46
49
|
|
|
47
|
-
const expected = new Block([])
|
|
48
|
-
expected.msgid =
|
|
49
|
-
expected.msgstr = [
|
|
50
|
+
const expected = new Block([]);
|
|
51
|
+
expected.msgid = "Hello World";
|
|
52
|
+
expected.msgstr = [""];
|
|
50
53
|
expected.comments = {
|
|
51
|
-
reference: [
|
|
52
|
-
translator: [
|
|
53
|
-
}
|
|
54
|
+
reference: ["filename.tsx:1"],
|
|
55
|
+
translator: [""],
|
|
56
|
+
};
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
it('should extract translations with context', () => {
|
|
58
|
-
const content = `<?php __('Hello World', 'greeting'); ?>`
|
|
59
|
-
const filename = 'filename.php'
|
|
58
|
+
assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
|
|
59
|
+
});
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
it("should extract translations with context", () => {
|
|
62
|
+
const content = `<?php __('Hello World', 'greeting'); ?>`;
|
|
63
|
+
const filename = "filename.php";
|
|
62
64
|
|
|
63
|
-
const
|
|
64
|
-
expected.msgid = 'Hello World'
|
|
65
|
-
expected.msgstr = ['']
|
|
66
|
-
expected.comments = {
|
|
67
|
-
reference: ['filename.php:1'],
|
|
68
|
-
translator: [''],
|
|
69
|
-
}
|
|
65
|
+
const result = doTree(content, filename);
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
const expected = new Block([]);
|
|
68
|
+
expected.msgid = "Hello World";
|
|
69
|
+
expected.msgstr = [""];
|
|
70
|
+
expected.comments = {
|
|
71
|
+
reference: ["filename.php:1"],
|
|
72
|
+
translator: [""],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
assert.deepStrictEqual(result.blocks[0].toJson(), expected.toJson());
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should extract translations from code content with no context or translator comments", () => {
|
|
79
|
+
const content = `<?php _e('Hello World'); ?>`;
|
|
80
|
+
const expected = new Block([]);
|
|
81
|
+
expected.msgctxt = undefined;
|
|
82
|
+
expected.msgid = "Hello World";
|
|
83
|
+
expected.msgid_plural = undefined;
|
|
84
|
+
expected.msgstr = [""];
|
|
78
85
|
expected.comments = {
|
|
79
86
|
translator: undefined,
|
|
80
|
-
reference: [
|
|
81
|
-
}
|
|
82
|
-
const filename =
|
|
87
|
+
reference: ["filename.php:1"],
|
|
88
|
+
};
|
|
89
|
+
const filename = "filename.php";
|
|
83
90
|
|
|
84
|
-
const result = doTree(content, filename)
|
|
91
|
+
const result = doTree(content, filename);
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
})
|
|
93
|
+
assert.deepEqual(result.blocks[0], expected);
|
|
94
|
+
});
|
|
88
95
|
|
|
89
|
-
it(
|
|
90
|
-
const filename =
|
|
96
|
+
it("should extract translations with comments", () => {
|
|
97
|
+
const filename = "filename.php";
|
|
91
98
|
const content = `
|
|
92
|
-
<?php /** translators: ciao! */ echo _x('Hello World', 'greeting');
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
reference: ['filename.php:2'],
|
|
98
|
-
translator: ['ciao!'],
|
|
99
|
-
},
|
|
100
|
-
msgctxt: 'greeting',
|
|
101
|
-
msgid: 'Hello World',
|
|
102
|
-
msgstr: [''],
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
path: 'filename.php',
|
|
106
|
-
}
|
|
99
|
+
<?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`;
|
|
100
|
+
const expectedComments = {
|
|
101
|
+
reference: ["filename.php:2"],
|
|
102
|
+
translator: ["ciao!"],
|
|
103
|
+
};
|
|
107
104
|
|
|
108
|
-
const result = doTree(content, filename)
|
|
105
|
+
const result = doTree(content, filename);
|
|
109
106
|
|
|
110
|
-
|
|
111
|
-
})
|
|
107
|
+
assert.deepEqual(result.blocks[0].comments, expectedComments);
|
|
108
|
+
});
|
|
112
109
|
|
|
113
|
-
it(
|
|
114
|
-
const filename =
|
|
110
|
+
it("should extract translations with comments reporting the right position", () => {
|
|
111
|
+
const filename = "filename.php";
|
|
115
112
|
const content = `
|
|
116
113
|
|
|
117
114
|
|
|
@@ -121,51 +118,52 @@ describe('getStrings', () => {
|
|
|
121
118
|
|
|
122
119
|
|
|
123
120
|
|
|
124
|
-
<?php echo _x('Hello World', 'greeting');
|
|
121
|
+
<?php echo _x('Hello World', 'greeting'); ?>`;
|
|
125
122
|
const expected = `#: filename.php:10
|
|
126
123
|
msgctxt "greeting"
|
|
127
124
|
msgid "Hello World"
|
|
128
|
-
msgstr ""
|
|
125
|
+
msgstr ""`;
|
|
129
126
|
|
|
130
|
-
const result = doTree(content, filename)
|
|
127
|
+
const result = doTree(content, filename);
|
|
131
128
|
|
|
132
|
-
|
|
133
|
-
})
|
|
129
|
+
assert.strictEqual(result.blocks[0].toStr(), expected);
|
|
130
|
+
});
|
|
134
131
|
|
|
135
|
-
it(
|
|
136
|
-
const filename =
|
|
132
|
+
it("should extract translations inside a sprint", () => {
|
|
133
|
+
const filename = "filename.php";
|
|
137
134
|
const content = ` <?php
|
|
138
135
|
$url = 'http://example.com';
|
|
139
136
|
$link = sprintf( wp_kses( __( 'Check out this link to my <a href="%s">website</a> made with WordPress.', 'my-text-domain' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
|
|
140
|
-
echo $link
|
|
137
|
+
echo $link;`;
|
|
141
138
|
const expected = {
|
|
142
|
-
|
|
139
|
+
"": {
|
|
143
140
|
'Check out this link to my <a href="%s">website</a> made with WordPress.':
|
|
144
141
|
{
|
|
145
142
|
comments: {
|
|
146
|
-
extracted:
|
|
147
|
-
flag:
|
|
148
|
-
previous:
|
|
149
|
-
reference:
|
|
150
|
-
translator:
|
|
143
|
+
extracted: "",
|
|
144
|
+
flag: "",
|
|
145
|
+
previous: "",
|
|
146
|
+
reference: "filename.php:3",
|
|
147
|
+
translator: "",
|
|
151
148
|
},
|
|
152
|
-
msgctxt:
|
|
153
|
-
msgid:
|
|
149
|
+
msgctxt: "",
|
|
150
|
+
msgid:
|
|
151
|
+
'Check out this link to my <a href="%s">website</a> made with WordPress.',
|
|
154
152
|
msgid_plural: undefined,
|
|
155
|
-
msgstr: [
|
|
153
|
+
msgstr: [""],
|
|
156
154
|
},
|
|
157
155
|
},
|
|
158
|
-
}
|
|
156
|
+
};
|
|
159
157
|
|
|
160
|
-
const result = doTree(content, filename)
|
|
158
|
+
const result = doTree(content, filename);
|
|
161
159
|
|
|
162
|
-
|
|
163
|
-
})
|
|
164
|
-
})
|
|
160
|
+
assert.deepStrictEqual(result.toJson(), expected);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
165
163
|
|
|
166
|
-
describe(
|
|
167
|
-
it(
|
|
168
|
-
const filename =
|
|
164
|
+
describe("getStrings wp cli", () => {
|
|
165
|
+
it("should extract from an array of translations", () => {
|
|
166
|
+
const filename = "filename.php";
|
|
169
167
|
const content = `<?php $var = 'don't do this'; $instructions = array(
|
|
170
168
|
"Overview" => array(
|
|
171
169
|
"title" => __( 'Overview', '3d-product-viewer' ),
|
|
@@ -183,14 +181,14 @@ describe('getStrings wp cli', () => {
|
|
|
183
181
|
"icon" => 'icon-zoom'
|
|
184
182
|
)
|
|
185
183
|
);
|
|
186
|
-
|
|
184
|
+
`;
|
|
187
185
|
|
|
188
|
-
const result = doTree(content, filename)
|
|
189
|
-
|
|
190
|
-
})
|
|
186
|
+
const result = doTree(content, filename);
|
|
187
|
+
assert.deepStrictEqual(result.blocks[0].msgid, "Overview");
|
|
188
|
+
});
|
|
191
189
|
|
|
192
|
-
it(
|
|
193
|
-
const filename =
|
|
190
|
+
it("should extract translations with translator comments inside the formatting hell", () => {
|
|
191
|
+
const filename = "filename.php";
|
|
194
192
|
const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
|
|
195
193
|
$formatted_errors = wp_json_encode( $errors_in_remigrate_batch, JSON_PRETTY_PRINT );
|
|
196
194
|
WP_CLI::warning(
|
|
@@ -209,16 +207,17 @@ describe('getStrings wp cli', () => {
|
|
|
209
207
|
} else {
|
|
210
208
|
WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
|
|
211
209
|
}
|
|
212
|
-
|
|
210
|
+
`;
|
|
213
211
|
|
|
214
|
-
const result = doTree(content, filename)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
212
|
+
const result = doTree(content, filename);
|
|
213
|
+
assert.strictEqual(
|
|
214
|
+
"%1$d error found: %2$s when re-migrating order. Please review the error above.",
|
|
215
|
+
result.blocks[0].msgid,
|
|
216
|
+
);
|
|
217
|
+
});
|
|
219
218
|
|
|
220
219
|
/** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
|
|
221
|
-
it(
|
|
220
|
+
it("should extract translations and comments from code content", () => {
|
|
222
221
|
const content = `<?php
|
|
223
222
|
|
|
224
223
|
And a foo-plugin/foo-plugin.php file:
|
|
@@ -278,17 +277,17 @@ describe('getStrings wp cli', () => {
|
|
|
278
277
|
|
|
279
278
|
__( 'wrong-domain', 'wrong-domain' );
|
|
280
279
|
|
|
281
|
-
__( 'Hello world' ); // translators: Greeting
|
|
280
|
+
__( 'Hello world' ); // translators: Greeting`;
|
|
282
281
|
|
|
283
|
-
const filename =
|
|
282
|
+
const filename = "filename.php";
|
|
284
283
|
|
|
285
|
-
const result = doTree(content, filename)
|
|
284
|
+
const result = doTree(content, filename);
|
|
286
285
|
|
|
287
|
-
|
|
288
|
-
})
|
|
286
|
+
assert.strictEqual(result.blocks.length, 26);
|
|
287
|
+
});
|
|
289
288
|
|
|
290
289
|
/** see wp cli tests */
|
|
291
|
-
it(
|
|
290
|
+
it("should extract translations and comments from code content", () => {
|
|
292
291
|
const content = `<?php
|
|
293
292
|
|
|
294
293
|
// translators: Foo Bar Comment
|
|
@@ -371,12 +370,12 @@ describe('getStrings wp cli', () => {
|
|
|
371
370
|
|
|
372
371
|
/* Translators: This is another comment! */
|
|
373
372
|
__( 'https://example.com', 'foo-plugin' );
|
|
374
|
-
|
|
373
|
+
`;
|
|
375
374
|
|
|
376
|
-
const filename =
|
|
375
|
+
const filename = "filename.php";
|
|
377
376
|
|
|
378
|
-
const result = doTree(content, filename)
|
|
377
|
+
const result = doTree(content, filename);
|
|
379
378
|
|
|
380
|
-
|
|
381
|
-
})
|
|
382
|
-
})
|
|
379
|
+
assert.strictEqual(result.blocks.length, 20);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const { sep } = require("node:path");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { parseCliArgs } = require("./lib/cli/parseCli.js");
|
|
5
|
+
const { getFiles } = require("./lib/fs/glob.js");
|
|
6
|
+
|
|
7
|
+
describe("getFiles", () => {
|
|
8
|
+
const DEFAULTS = parseCliArgs({
|
|
9
|
+
domain: "plugin",
|
|
10
|
+
slug: "plugin-slug",
|
|
11
|
+
paths: { cwd: "tests/fixtures/", out: "tests/fixtures/" },
|
|
12
|
+
options: {
|
|
13
|
+
silent: true,
|
|
14
|
+
},
|
|
15
|
+
$0: "makepot",
|
|
16
|
+
_: [0, 1],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should retrieve a all files", async () => {
|
|
20
|
+
const args = { ...DEFAULTS, domain: "theme" };
|
|
21
|
+
const pattern = { include: ["./src/**"], exclude: [] };
|
|
22
|
+
|
|
23
|
+
const files = getFiles(args, pattern);
|
|
24
|
+
const collected = [];
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
assert.equal(!!file, true);
|
|
27
|
+
collected.push(file);
|
|
28
|
+
}
|
|
29
|
+
assert.deepStrictEqual(collected.length, 28);
|
|
30
|
+
assert.strictEqual(
|
|
31
|
+
collected.find((e) => e.includes("const.ts")),
|
|
32
|
+
"src\\const.ts",
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("Should retrieve a list of txt files based on the provided plugin pattern", async () => {
|
|
37
|
+
const args = {
|
|
38
|
+
...DEFAULTS,
|
|
39
|
+
};
|
|
40
|
+
const pattern = {
|
|
41
|
+
include: ["**/*.txt"],
|
|
42
|
+
exclude: ["node_modules", "dist"],
|
|
43
|
+
};
|
|
44
|
+
const expectedFiles = [
|
|
45
|
+
`tests${sep}fixtures${sep}file1.txt`,
|
|
46
|
+
`tests${sep}fixtures${sep}sourcedir${sep}file2.txt`,
|
|
47
|
+
`tests${sep}fixtures${sep}block${sep}readme.txt`,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const files = getFiles(args, pattern);
|
|
51
|
+
const collected = [];
|
|
52
|
+
for (const file of files) {
|
|
53
|
+
assert.equal(!!file, true);
|
|
54
|
+
collected.push(file);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
assert.deepStrictEqual(collected, expectedFiles);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should retrieve a list of theme.json files based on the provided theme pattern", async () => {
|
|
61
|
+
const args = {
|
|
62
|
+
...DEFAULTS,
|
|
63
|
+
};
|
|
64
|
+
const pattern = {
|
|
65
|
+
include: ["tests/fixtures/sourcedir/**/*.json"],
|
|
66
|
+
exclude: [],
|
|
67
|
+
};
|
|
68
|
+
const expectedFiles = [
|
|
69
|
+
`tests${sep}fixtures${sep}sourcedir${sep}theme.json`,
|
|
70
|
+
`tests${sep}fixtures${sep}sourcedir${sep}package.json`,
|
|
71
|
+
`tests${sep}fixtures${sep}sourcedir${sep}node_modules${sep}module${sep}block.json`,
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const files = getFiles(args, pattern);
|
|
75
|
+
const collected = [];
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
assert.equal(!!file, true);
|
|
78
|
+
collected.push(file);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const fileFound = collected.filter((file) => expectedFiles.includes(file));
|
|
82
|
+
|
|
83
|
+
assert.deepStrictEqual(fileFound.length, 3);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const { describe, it } = require("node:test");
|
|
3
|
+
const assert = require("node:assert");
|
|
4
|
+
const { parseJsonFile } = require("../lib/extractors/json.js");
|
|
5
|
+
|
|
6
|
+
describe("should parse json", () => {
|
|
7
|
+
it("theme.json", async () => {
|
|
8
|
+
const expected = {
|
|
9
|
+
"block style label": {
|
|
10
|
+
label: {
|
|
11
|
+
comments: {
|
|
12
|
+
reference: "block/block.json",
|
|
13
|
+
},
|
|
14
|
+
msgctxt: "block style label",
|
|
15
|
+
msgid: "label",
|
|
16
|
+
msgstr: [],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
"block description": {
|
|
20
|
+
description: {
|
|
21
|
+
comments: {
|
|
22
|
+
reference: "block/block.json",
|
|
23
|
+
},
|
|
24
|
+
msgctxt: "block description",
|
|
25
|
+
msgid: "description",
|
|
26
|
+
msgstr: [],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
"block keyword": {
|
|
30
|
+
undefined: {
|
|
31
|
+
comments: {
|
|
32
|
+
reference: "block/block.json",
|
|
33
|
+
},
|
|
34
|
+
msgctxt: "block keyword",
|
|
35
|
+
msgid: undefined,
|
|
36
|
+
msgstr: [],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = await parseJsonFile({
|
|
42
|
+
fileContent: fs.readFileSync("tests/fixtures/block/block.json", "utf8"),
|
|
43
|
+
filename: "block.json",
|
|
44
|
+
filepath: "block/block.json",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
assert.strictEqual(result, expected);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,57 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe(
|
|
8
|
-
const filepath =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
const path = require("node:path");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const { describe, it } = require("node:test");
|
|
4
|
+
const assert = require("node:assert");
|
|
5
|
+
const { doTree } = require("../lib/");
|
|
6
|
+
|
|
7
|
+
describe("doTree js", () => {
|
|
8
|
+
const filepath = "tests/fixtures/block/javascript.js";
|
|
9
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
10
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
11
|
+
it("Should parse TSX file and extract strings", () => {
|
|
12
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
13
|
+
assert.deepEqual(fileParsed.blocks[0], {
|
|
14
|
+
comments: {
|
|
15
|
+
reference: ["tests\\fixtures\\block\\javascript.js:7"],
|
|
16
|
+
translator: undefined,
|
|
17
|
+
},
|
|
18
|
+
msgctxt: undefined,
|
|
19
|
+
msgid: "Simple Block",
|
|
20
|
+
msgid_plural: undefined,
|
|
21
|
+
msgstr: [""],
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("doTree php", () => {
|
|
27
|
+
const filepath = "tests/fixtures/plugin/plugin.php";
|
|
28
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
29
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
30
|
+
it("Should parse TSX file and extract strings", () => {
|
|
31
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
32
|
+
assert.deepEqual(fileParsed.blocks[1], {
|
|
33
|
+
comments: {
|
|
34
|
+
reference: ["tests\\fixtures\\plugin\\plugin.php:65"],
|
|
35
|
+
translator: undefined,
|
|
36
|
+
},
|
|
37
|
+
msgctxt: undefined,
|
|
38
|
+
msgid: "You\\'re a silly monkey",
|
|
39
|
+
msgid_plural: undefined,
|
|
40
|
+
msgstr: [""],
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("doTree tsx file", () => {
|
|
46
|
+
const filepath = "tests/fixtures/block/SvgControls.tsx";
|
|
47
|
+
const filePath = path.join(process.cwd(), filepath);
|
|
48
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
49
|
+
it("Should parse TSX file and extract strings", () => {
|
|
50
|
+
const fileParsed = doTree(fileContent, filepath);
|
|
51
|
+
assert.deepEqual(fileParsed.blocks[2], {
|
|
52
|
+
comments: {
|
|
53
|
+
reference: ["tests\\fixtures\\block\\SvgControls.tsx:107"],
|
|
54
|
+
translator: undefined,
|
|
55
|
+
},
|
|
56
|
+
msgctxt: undefined,
|
|
57
|
+
msgid: "Replace SVG",
|
|
58
|
+
msgid_plural: undefined,
|
|
59
|
+
msgstr: [""],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("doTree php test file", async () => {
|
|
53
65
|
/** see wp cli tests */
|
|
54
|
-
it(
|
|
66
|
+
it("should extract translations and comments from code content", () => {
|
|
55
67
|
const content = `<?php
|
|
56
68
|
|
|
57
69
|
// translators: Foo Bar Comment
|
|
@@ -78,7 +90,6 @@ describe('doTree php test file', () => {
|
|
|
78
90
|
);
|
|
79
91
|
|
|
80
92
|
wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
|
|
81
|
-
wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
|
|
82
93
|
|
|
83
94
|
const translate = wp.i18n;
|
|
84
95
|
translate.__( 'translate.__', 'foo-plugin' );
|
|
@@ -96,7 +107,7 @@ describe('doTree php test file', () => {
|
|
|
96
107
|
|
|
97
108
|
eval( "__( 'Hello Eval World', 'foo-plugin' );" );
|
|
98
109
|
|
|
99
|
-
__(
|
|
110
|
+
__( "ASDASDASD', 'foo-plugin' );
|
|
100
111
|
|
|
101
112
|
/**
|
|
102
113
|
* Plugin Name: Plugin name
|
|
@@ -134,18 +145,14 @@ describe('doTree php test file', () => {
|
|
|
134
145
|
|
|
135
146
|
/* Translators: This is another comment! */
|
|
136
147
|
__( 'https://example.com', 'foo-plugin' );
|
|
137
|
-
|
|
148
|
+
`;
|
|
138
149
|
|
|
139
|
-
const filename =
|
|
150
|
+
const filename = "filename.php";
|
|
140
151
|
|
|
141
|
-
const r = doTree(content, filename).blocks
|
|
142
|
-
const res = Object.values(r)[0]
|
|
152
|
+
const r = doTree(content, filename).blocks;
|
|
153
|
+
const res = Object.values(r)[0];
|
|
143
154
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
).toBeGreaterThanOrEqual(8)
|
|
149
|
-
expect(res).toMatchSnapshot()
|
|
150
|
-
})
|
|
151
|
-
})
|
|
155
|
+
assert.strictEqual(r.map((block) => block).length, 11);
|
|
156
|
+
assert.strictEqual(r.filter((block) => block.comments).length, 11);
|
|
157
|
+
});
|
|
158
|
+
});
|