@wp-blocks/make-pot 0.0.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/ .prettierignore +3 -0
- package/.editorconfig +15 -0
- package/.eslintrc.json +12 -0
- package/.github/workflows/node.js.yml +33 -0
- package/jest.config.json +14 -0
- package/lib/cliArgs.d.ts +4 -0
- package/lib/cliArgs.js +177 -0
- package/lib/cliArgs.js.map +1 -0
- package/lib/consolidate.d.ts +2 -0
- package/lib/consolidate.js +27 -0
- package/lib/consolidate.js.map +1 -0
- package/lib/const.d.ts +26 -0
- package/lib/const.js +56 -0
- package/lib/const.js.map +1 -0
- package/lib/extractors-json.d.ts +9 -0
- package/lib/extractors-json.js +53 -0
- package/lib/extractors-json.js.map +1 -0
- package/lib/extractors-maps.d.ts +109 -0
- package/lib/extractors-maps.js +139 -0
- package/lib/extractors-maps.js.map +1 -0
- package/lib/extractors-php.d.ts +1 -0
- package/lib/extractors-php.js +24 -0
- package/lib/extractors-php.js.map +1 -0
- package/lib/extractors-text.d.ts +1 -0
- package/lib/extractors-text.js +21 -0
- package/lib/extractors-text.js.map +1 -0
- package/lib/extractors.d.ts +17 -0
- package/lib/extractors.js +128 -0
- package/lib/extractors.js.map +1 -0
- package/lib/fs.d.ts +2 -0
- package/lib/fs.js +51 -0
- package/lib/fs.js.map +1 -0
- package/lib/glob.d.ts +13 -0
- package/lib/glob.js +60 -0
- package/lib/glob.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/makePot.d.ts +2 -0
- package/lib/makePot.js +56 -0
- package/lib/makePot.js.map +1 -0
- package/lib/parser.d.ts +6 -0
- package/lib/parser.js +93 -0
- package/lib/parser.js.map +1 -0
- package/lib/tree.d.ts +2 -0
- package/lib/tree.js +77 -0
- package/lib/tree.js.map +1 -0
- package/lib/types.d.ts +46 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +74 -0
- package/lib/utils.js.map +1 -0
- package/package.json +50 -0
- package/tests/consolidate.test.ts +77 -0
- package/tests/extract-2.test.ts +97 -0
- package/tests/extract.test.ts +380 -0
- package/tests/getFiles.test.ts +114 -0
- package/tests/getStrings.test.ts +149 -0
- package/tests/index.html +78 -0
- package/tests/ingnoreFunction.test.ts +177 -0
- package/tests/jsonParse.test.ts +60 -0
- package/tests/makePot.ts +46 -0
- package/tests/treeJs.test.ts +15 -0
- package/tests/treePhp.test.ts +30 -0
- package/tests/treeTs.test.ts +15 -0
- package/tests/utils.test.ts +28 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { describe, expect } from '@jest/globals'
|
|
2
|
+
import { doTree } from '../src/tree'
|
|
3
|
+
|
|
4
|
+
describe('getStrings', () => {
|
|
5
|
+
it('should extract translations with context', () => {
|
|
6
|
+
const content = `<?php __('Hello World', 'greeting'); ?>`
|
|
7
|
+
const filename = 'filename.php'
|
|
8
|
+
|
|
9
|
+
const result = doTree(content, filename)
|
|
10
|
+
|
|
11
|
+
expect(result).toMatchObject({
|
|
12
|
+
'': {
|
|
13
|
+
'Hello World': {
|
|
14
|
+
comments: {
|
|
15
|
+
reference: 'filename.php:1',
|
|
16
|
+
},
|
|
17
|
+
msgid: 'Hello World',
|
|
18
|
+
msgstr: [],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
it('should extract translations from code content with no context or translator comments', () => {
|
|
24
|
+
const content = `<?php _e('Hello World'); ?>`
|
|
25
|
+
const expected = {
|
|
26
|
+
'': {
|
|
27
|
+
'Hello World': {
|
|
28
|
+
comments: {
|
|
29
|
+
reference: 'filename.php:1',
|
|
30
|
+
},
|
|
31
|
+
msgid: 'Hello World',
|
|
32
|
+
msgstr: [],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
const filename = 'filename.php'
|
|
37
|
+
|
|
38
|
+
const result = doTree(content, filename)
|
|
39
|
+
|
|
40
|
+
expect(result).toEqual(expected)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should extract translations with comments', () => {
|
|
44
|
+
const filename = 'filename.php'
|
|
45
|
+
const content = `
|
|
46
|
+
<?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`
|
|
47
|
+
const expected = {
|
|
48
|
+
'': {
|
|
49
|
+
'Hello World': {
|
|
50
|
+
comments: {
|
|
51
|
+
reference: 'filename.php:2',
|
|
52
|
+
translator: 'ciao!',
|
|
53
|
+
},
|
|
54
|
+
msgid: 'Hello World',
|
|
55
|
+
msgstr: [],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = doTree(content, filename)
|
|
61
|
+
|
|
62
|
+
expect(result).toEqual(expected)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should extract translations with comments reporting the right position', () => {
|
|
66
|
+
const filename = 'filename.php'
|
|
67
|
+
const content = `
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/** line 5*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
<?php echo _x('Hello World', 'greeting'); ?>`
|
|
77
|
+
const expected = {
|
|
78
|
+
'': {
|
|
79
|
+
'Hello World': {
|
|
80
|
+
comments: {
|
|
81
|
+
reference: 'filename.php:10',
|
|
82
|
+
},
|
|
83
|
+
msgid: 'Hello World',
|
|
84
|
+
msgstr: [],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const result = doTree(content, filename)
|
|
90
|
+
|
|
91
|
+
expect(result).toEqual(expected)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should extract translations inside a sprint', () => {
|
|
95
|
+
const filename = 'filename.php'
|
|
96
|
+
const content = ` <?php
|
|
97
|
+
$url = 'http://example.com';
|
|
98
|
+
$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 ) );
|
|
99
|
+
echo $link;`
|
|
100
|
+
const expected = {
|
|
101
|
+
'': {
|
|
102
|
+
'Check out this link to my <a href="%s">website</a> made with WordPress.':
|
|
103
|
+
{
|
|
104
|
+
comments: {
|
|
105
|
+
reference: 'filename.php:3',
|
|
106
|
+
},
|
|
107
|
+
msgid: 'Check out this link to my <a href="%s">website</a> made with WordPress.',
|
|
108
|
+
msgstr: [],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const result = doTree(content, filename)
|
|
114
|
+
|
|
115
|
+
expect(result).toEqual(expected)
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
describe('getStrings wp cli', () => {
|
|
119
|
+
it('should extract translations with translator comments inside the formatting hell', () => {
|
|
120
|
+
const filename = 'filename.php'
|
|
121
|
+
const content = `<?php /** 1*/
|
|
122
|
+
/** 2*/ /** translators: 1: Site URL, 2: Username, 3: User email address, 4: Lost password URL. */
|
|
123
|
+
sprintf(__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
|
|
124
|
+
/** 6*/\t\t\tsprintf( '<a href="http://%1$s%2$s">%1$s%2$s</a>', $signup->domain, $blog_details->path ),
|
|
125
|
+
/** 7*/\t\t\t$signup->user_login,
|
|
126
|
+
/** 8*/\t\t\t$signup->user_email,
|
|
127
|
+
/** 9*/\t\t\twp_lostpassword_url()
|
|
128
|
+
/** 10*/\t\t);
|
|
129
|
+
|
|
130
|
+
/** 11*/\t\techo __( 'aaaaaaa' );
|
|
131
|
+
/** 12*/\t\techo __( 'aaaaaaa' );
|
|
132
|
+
/** 13 */\t\techo __( 'aaaaaaa' );
|
|
133
|
+
/** 14 */
|
|
134
|
+
/** 15 */ printf(
|
|
135
|
+
\t\t\t\t/* translators: 1: Site URL, 2: Username, 3: User email address, 4: Lost password URL. */
|
|
136
|
+
\t\t\t__( 'aaaaaaa' ),
|
|
137
|
+
/** 18 */\t\t\t\t);
|
|
138
|
+
/** translators:aaaa */
|
|
139
|
+
echo __( 'Your site at %1$s' )
|
|
140
|
+
|
|
141
|
+
/** translators:aaaa */
|
|
142
|
+
_e( 'Your site at %1$s' )`
|
|
143
|
+
const expected = [
|
|
144
|
+
{
|
|
145
|
+
'': {
|
|
146
|
+
'Your site at %1$s is active. You may now log in to your site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.':
|
|
147
|
+
{
|
|
148
|
+
comments: {
|
|
149
|
+
reference: 'filename.php:3',
|
|
150
|
+
},
|
|
151
|
+
msgid: 'Your site at %1$s is active. You may now log in to your site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.',
|
|
152
|
+
msgstr: [],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
'': {
|
|
158
|
+
aaaaaaa: {
|
|
159
|
+
comments: {
|
|
160
|
+
reference: 'filename.php:10',
|
|
161
|
+
},
|
|
162
|
+
msgid: 'aaaaaaa',
|
|
163
|
+
msgstr: [],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
'': {
|
|
169
|
+
aaaaaaa: {
|
|
170
|
+
comments: {
|
|
171
|
+
reference: 'filename.php:11',
|
|
172
|
+
},
|
|
173
|
+
msgid: 'aaaaaaa',
|
|
174
|
+
msgstr: [],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
'': {
|
|
180
|
+
aaaaaaa: {
|
|
181
|
+
comments: {
|
|
182
|
+
reference: 'filename.php:12',
|
|
183
|
+
},
|
|
184
|
+
msgid: 'aaaaaaa',
|
|
185
|
+
msgstr: [],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
'': {
|
|
191
|
+
aaaaaaa: {
|
|
192
|
+
comments: {
|
|
193
|
+
reference: 'filename.php:16',
|
|
194
|
+
translator: '',
|
|
195
|
+
},
|
|
196
|
+
msgid: 'aaaaaaa',
|
|
197
|
+
msgstr: [],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
'': {
|
|
203
|
+
'Your site at %1$s': {
|
|
204
|
+
comments: {
|
|
205
|
+
reference: 'filename.php:19',
|
|
206
|
+
},
|
|
207
|
+
msgid: 'Your site at %1$s',
|
|
208
|
+
msgstr: [],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
const result = doTree(content, filename)
|
|
215
|
+
expect(result).toMatchObject(result)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
/** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
|
|
219
|
+
it('should extract translations and comments from code content', () => {
|
|
220
|
+
const content = `<?php
|
|
221
|
+
|
|
222
|
+
And a foo-plugin/foo-plugin.php file:
|
|
223
|
+
"""
|
|
224
|
+
<?php
|
|
225
|
+
/**
|
|
226
|
+
*/
|
|
227
|
+
__( 'Hello World', 'foo-plugin' );
|
|
228
|
+
"""
|
|
229
|
+
And a foo-plugin/vendor/ignored.php file:
|
|
230
|
+
"""
|
|
231
|
+
<?php
|
|
232
|
+
__( 'I am being ignored', 'foo-plugin' );
|
|
233
|
+
"""
|
|
234
|
+
__( '__', 'foo-plugin' );
|
|
235
|
+
esc_attr__( 'esc_attr__', 'foo-plugin' );
|
|
236
|
+
esc_html__( 'esc_html__', 'foo-plugin' );
|
|
237
|
+
esc_xml__( 'esc_xml__', 'foo-plugin' );
|
|
238
|
+
_e( '_e', 'foo-plugin' );
|
|
239
|
+
esc_attr_e( 'esc_attr_e', 'foo-plugin' );
|
|
240
|
+
esc_html_e( 'esc_html_e', 'foo-plugin' );
|
|
241
|
+
esc_xml_e( 'esc_xml_e', 'foo-plugin' );
|
|
242
|
+
_x( '_x', '_x_context', 'foo-plugin' );
|
|
243
|
+
_ex( '_ex', '_ex_context', 'foo-plugin' );
|
|
244
|
+
esc_attr_x( 'esc_attr_x', 'esc_attr_x_context', 'foo-plugin' );
|
|
245
|
+
esc_html_x( 'esc_html_x', 'esc_html_x_context', 'foo-plugin' );
|
|
246
|
+
esc_xml_x( 'esc_xml_x', 'esc_xml_x_context', 'foo-plugin' );
|
|
247
|
+
_n( '_n_single', '_n_plural', $number, 'foo-plugin' );
|
|
248
|
+
_nx( '_nx_single', '_nx_plural', $number, '_nx_context', 'foo-plugin' );
|
|
249
|
+
_n_noop( '_n_noop_single', '_n_noop_plural', 'foo-plugin' );
|
|
250
|
+
_nx_noop( '_nx_noop_single', '_nx_noop_plural', '_nx_noop_context', 'foo-plugin' );
|
|
251
|
+
|
|
252
|
+
// Compat.
|
|
253
|
+
_( '_', 'foo-plugin' );
|
|
254
|
+
|
|
255
|
+
// Deprecated.
|
|
256
|
+
_c( '_c', 'foo-plugin' );
|
|
257
|
+
_nc( '_nc_single', '_nc_plural', $number, 'foo-plugin' );
|
|
258
|
+
__ngettext( '__ngettext_single', '__ngettext_plural', $number, 'foo-plugin' );
|
|
259
|
+
__ngettext_noop( '__ngettext_noop_single', '__ngettext_noop_plural', 'foo-plugin' );
|
|
260
|
+
|
|
261
|
+
__unsupported_func( '__unsupported_func', 'foo-plugin' );
|
|
262
|
+
__( 'wrong-domain', 'wrong-domain' );
|
|
263
|
+
|
|
264
|
+
// See https://github.com/wp-cli/i18n-command/issues/344
|
|
265
|
+
\\__( '\\__', 'foo-plugin' );
|
|
266
|
+
\\_e( '\\_e', 'foo-plugin' );
|
|
267
|
+
// Included to test if peast correctly parses regexes containing a quote.
|
|
268
|
+
// See: https://github.com/wp-cli/i18n-command/issues/98
|
|
269
|
+
n = n.replace(/"/g, '"');
|
|
270
|
+
n = n.replace(/"|'/g, '"');
|
|
271
|
+
|
|
272
|
+
__( '__', 'foo-plugin' );
|
|
273
|
+
_x( '_x', '_x_context', 'foo-plugin' );
|
|
274
|
+
_n( '_n_single', '_n_plural', number, 'foo-plugin' );
|
|
275
|
+
_nx( '_nx_single', '_nx_plural', number, '_nx_context', 'foo-plugin' );
|
|
276
|
+
|
|
277
|
+
__( 'wrong-domain', 'wrong-domain' );
|
|
278
|
+
|
|
279
|
+
__( 'Hello world' ); // translators: Greeting`
|
|
280
|
+
|
|
281
|
+
const filename = 'filename.php'
|
|
282
|
+
|
|
283
|
+
const result = doTree(content, filename)
|
|
284
|
+
|
|
285
|
+
expect(result).toMatchSnapshot()
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
/** see wp cli tests */
|
|
289
|
+
it('should extract translations and comments from code content', () => {
|
|
290
|
+
const content = `<?php
|
|
291
|
+
|
|
292
|
+
// translators: Foo Bar Comment
|
|
293
|
+
__( 'Foo Bar', 'foo-plugin' );
|
|
294
|
+
|
|
295
|
+
// TrANslAtORs: Bar Baz Comment
|
|
296
|
+
__( 'Bar Baz', 'foo-plugin' );
|
|
297
|
+
|
|
298
|
+
// translators: Software name
|
|
299
|
+
const string = __( 'WordPress', 'foo-plugin' );
|
|
300
|
+
|
|
301
|
+
// translators: So much space
|
|
302
|
+
|
|
303
|
+
__( 'Spacey text', 'foo-plugin' );
|
|
304
|
+
|
|
305
|
+
/* translators: Long comment
|
|
306
|
+
spanning multiple
|
|
307
|
+
lines */
|
|
308
|
+
const string = __( 'Short text', 'foo-plugin' );
|
|
309
|
+
|
|
310
|
+
ReactDOM.render(
|
|
311
|
+
<h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
|
|
312
|
+
document.getElementById('root')
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
|
|
316
|
+
wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
|
|
317
|
+
|
|
318
|
+
const translate = wp.i18n;
|
|
319
|
+
translate.__( 'translate.__', 'foo-plugin' );
|
|
320
|
+
|
|
321
|
+
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
|
|
322
|
+
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
|
|
323
|
+
|
|
324
|
+
Object(u.__)( 'minified.__', 'foo-plugin' );
|
|
325
|
+
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
|
|
326
|
+
|
|
327
|
+
/* translators: babel */
|
|
328
|
+
(0, __)( 'babel.__', 'foo-plugin' );
|
|
329
|
+
(0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
|
|
330
|
+
(0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
|
|
331
|
+
|
|
332
|
+
eval( "__( 'Hello Eval World', 'foo-plugin' );" );
|
|
333
|
+
|
|
334
|
+
__( \`This is a \${bug}\`, 'foo-plugin' );
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Plugin Name: Plugin name
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
/* translators: Translators 1! */
|
|
341
|
+
_e( 'hello world', 'foo-plugin' );
|
|
342
|
+
|
|
343
|
+
/* Translators: Translators 2! */
|
|
344
|
+
$foo = __( 'foo', 'foo-plugin' );
|
|
345
|
+
|
|
346
|
+
/* translators: localized date and time format, see https://secure.php.net/date */
|
|
347
|
+
__( 'F j, Y g:i a', 'foo-plugin' );
|
|
348
|
+
|
|
349
|
+
// translators: let your ears fly!
|
|
350
|
+
__( 'on', 'foo-plugin' );
|
|
351
|
+
|
|
352
|
+
/*
|
|
353
|
+
* Translators: If there are characters in your language that are not supported
|
|
354
|
+
* by Lato, translate this to 'off'. Do not translate into your own language.
|
|
355
|
+
*/
|
|
356
|
+
__( 'off', 'foo-plugin' );
|
|
357
|
+
|
|
358
|
+
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
|
|
359
|
+
|
|
360
|
+
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
|
|
361
|
+
|
|
362
|
+
{TAB}/*
|
|
363
|
+
{TAB} * translators: this comment block is indented with a tab and should get extracted too.
|
|
364
|
+
{TAB} */
|
|
365
|
+
{TAB}__( 'yolo', 'foo-plugin' );
|
|
366
|
+
|
|
367
|
+
/* translators: This is a comment */
|
|
368
|
+
__( 'Plugin name', 'foo-plugin' );
|
|
369
|
+
|
|
370
|
+
/* Translators: This is another comment! */
|
|
371
|
+
__( 'https://example.com', 'foo-plugin' );
|
|
372
|
+
`
|
|
373
|
+
|
|
374
|
+
const filename = 'filename.php'
|
|
375
|
+
|
|
376
|
+
const result = doTree(content, filename)
|
|
377
|
+
|
|
378
|
+
expect(result).toMatchSnapshot()
|
|
379
|
+
})
|
|
380
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect } from '@jest/globals'
|
|
2
|
+
import { getFiles } from '../src/glob'
|
|
3
|
+
import { Args, DomainType } from '../src/types'
|
|
4
|
+
import { parseCliArgs } from '../src/cliArgs'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
describe('getFiles', () => {
|
|
8
|
+
const DEFAULTS = parseCliArgs({
|
|
9
|
+
domain: 'plugin' as DomainType,
|
|
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' } as Args
|
|
21
|
+
const pattern = { include: ['**'], exclude: [] }
|
|
22
|
+
|
|
23
|
+
const files = await getFiles(args, pattern)
|
|
24
|
+
const collected: string[] = []
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
expect(file).toBeTruthy()
|
|
27
|
+
collected.push(file)
|
|
28
|
+
}
|
|
29
|
+
expect(collected.length).toBeGreaterThan(2)
|
|
30
|
+
expect(collected.find((e) => e.includes('theme.json'))).toBeTruthy()
|
|
31
|
+
})
|
|
32
|
+
it('Should retrieve a list of txt files based on the provided plugin pattern', async () => {
|
|
33
|
+
const args = {
|
|
34
|
+
...DEFAULTS,
|
|
35
|
+
}
|
|
36
|
+
const pattern = {
|
|
37
|
+
include: ['**/*.txt'],
|
|
38
|
+
exclude: ['node_modules', 'dist'],
|
|
39
|
+
}
|
|
40
|
+
const expectedFiles = [
|
|
41
|
+
'tests' + path.sep + 'fixtures' + path.sep + 'file1.txt',
|
|
42
|
+
'tests' +
|
|
43
|
+
path.sep +
|
|
44
|
+
'fixtures' +
|
|
45
|
+
path.sep +
|
|
46
|
+
'sourcedir' +
|
|
47
|
+
path.sep +
|
|
48
|
+
'file2.txt',
|
|
49
|
+
'tests' +
|
|
50
|
+
path.sep +
|
|
51
|
+
'fixtures' +
|
|
52
|
+
path.sep +
|
|
53
|
+
'block' +
|
|
54
|
+
path.sep +
|
|
55
|
+
'readme.txt',
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
const files = await getFiles(args, pattern)
|
|
59
|
+
const collected: string[] = []
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
expect(file).toBeTruthy()
|
|
62
|
+
collected.push(file)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
expect(collected).toEqual(expectedFiles)
|
|
66
|
+
})
|
|
67
|
+
it('should retrieve a list of theme.json files based on the provided theme pattern', async () => {
|
|
68
|
+
const args = {
|
|
69
|
+
...DEFAULTS,
|
|
70
|
+
}
|
|
71
|
+
const pattern = {
|
|
72
|
+
include: ['**/*.json'],
|
|
73
|
+
exclude: [],
|
|
74
|
+
}
|
|
75
|
+
const expectedFiles = [
|
|
76
|
+
`sourcedir${path.sep}theme.json`,
|
|
77
|
+
`sourcedir${path.sep}package.json`,
|
|
78
|
+
`sourcedir${path.sep}node_modules${path.sep}module${path.sep}block.json`,
|
|
79
|
+
`node_modules${path.sep}block.json`,
|
|
80
|
+
`fse${path.sep}theme.json`,
|
|
81
|
+
`block${path.sep}block.json`,
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
const files = await getFiles(args, pattern)
|
|
85
|
+
let collected = []
|
|
86
|
+
for (const file of files) {
|
|
87
|
+
expect(file).toBeTruthy()
|
|
88
|
+
collected.push(file)
|
|
89
|
+
}
|
|
90
|
+
expect(
|
|
91
|
+
collected.filter((file) => !expectedFiles.includes(file))
|
|
92
|
+
).toBeTruthy()
|
|
93
|
+
})
|
|
94
|
+
it('Should retrieve a list of files without any node_modules folder', async () => {
|
|
95
|
+
const args = {
|
|
96
|
+
...DEFAULTS,
|
|
97
|
+
}
|
|
98
|
+
const pattern = {
|
|
99
|
+
include: ['**'],
|
|
100
|
+
exclude: ['node_modules'],
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const files = await getFiles(args, pattern)
|
|
104
|
+
let collected = []
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
expect(file).toBeTruthy()
|
|
107
|
+
collected.push(file)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// for each file check if that strings contains the node_modules folder
|
|
111
|
+
expect(collected.find((e) => e.includes('node_modules'))).toBeFalsy()
|
|
112
|
+
expect(collected.length).toBeGreaterThan(10)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect } from '@jest/globals'
|
|
2
|
+
import { getStrings } from '../src/parser'
|
|
3
|
+
import { Args, DomainType } from '../src/types'
|
|
4
|
+
import { getFiles } from '../src/glob'
|
|
5
|
+
|
|
6
|
+
const args: Args = {
|
|
7
|
+
slug: 'plugin-slug',
|
|
8
|
+
paths: { cwd: 'tests/fixtures/sourcedir/', out: 'tests/fixtures/' },
|
|
9
|
+
domain: 'plugin' as DomainType,
|
|
10
|
+
patterns: {
|
|
11
|
+
include: ['**'],
|
|
12
|
+
exclude: [
|
|
13
|
+
'node_modules',
|
|
14
|
+
'vendor',
|
|
15
|
+
'dist',
|
|
16
|
+
'tests',
|
|
17
|
+
'package-lock.json',
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('getStrings', () => {
|
|
23
|
+
it('Should build pot file', async () => {
|
|
24
|
+
const files = await getFiles(args as Args, {
|
|
25
|
+
include: ['file.php'],
|
|
26
|
+
exclude: ['node_modules', 'dist'],
|
|
27
|
+
})
|
|
28
|
+
const dataExtracted = await getStrings({ ...args } as Args, files)
|
|
29
|
+
const expected = {
|
|
30
|
+
'': {
|
|
31
|
+
sdasdasdasd: {
|
|
32
|
+
msgid: 'sdasdasdasd',
|
|
33
|
+
msgid_plural: undefined,
|
|
34
|
+
msgstr: [],
|
|
35
|
+
},
|
|
36
|
+
'strong magenta': {
|
|
37
|
+
msgid: 'strong magenta',
|
|
38
|
+
msgid_plural: undefined,
|
|
39
|
+
msgstr: [],
|
|
40
|
+
},
|
|
41
|
+
'light grayish magenta': {
|
|
42
|
+
msgid: 'light grayish magenta',
|
|
43
|
+
msgid_plural: undefined,
|
|
44
|
+
msgstr: [],
|
|
45
|
+
},
|
|
46
|
+
'very light gray': {
|
|
47
|
+
msgid: 'very light gray',
|
|
48
|
+
msgid_plural: undefined,
|
|
49
|
+
msgstr: [],
|
|
50
|
+
},
|
|
51
|
+
'very dark gray': {
|
|
52
|
+
msgid: 'very dark gray',
|
|
53
|
+
msgid_plural: undefined,
|
|
54
|
+
msgstr: [],
|
|
55
|
+
},
|
|
56
|
+
'Vivid cyan blue to vivid purple': {
|
|
57
|
+
msgid: 'Vivid cyan blue to vivid purple',
|
|
58
|
+
msgid_plural: undefined,
|
|
59
|
+
msgstr: [],
|
|
60
|
+
},
|
|
61
|
+
'Vivid green cyan to vivid cyan blue': {
|
|
62
|
+
msgid: 'Vivid green cyan to vivid cyan blue',
|
|
63
|
+
msgid_plural: undefined,
|
|
64
|
+
msgstr: [],
|
|
65
|
+
},
|
|
66
|
+
'Light green cyan to vivid green cyan': {
|
|
67
|
+
msgid: 'Light green cyan to vivid green cyan',
|
|
68
|
+
msgid_plural: undefined,
|
|
69
|
+
msgstr: [],
|
|
70
|
+
},
|
|
71
|
+
'Luminous vivid amber to luminous vivid orange': {
|
|
72
|
+
msgid: 'Luminous vivid amber to luminous vivid orange',
|
|
73
|
+
msgid_plural: undefined,
|
|
74
|
+
msgstr: [],
|
|
75
|
+
},
|
|
76
|
+
'Luminous vivid orange to vivid red': {
|
|
77
|
+
msgid: 'Luminous vivid orange to vivid red',
|
|
78
|
+
msgid_plural: undefined,
|
|
79
|
+
msgstr: [],
|
|
80
|
+
},
|
|
81
|
+
Small: {
|
|
82
|
+
msgid: 'Small',
|
|
83
|
+
msgid_plural: undefined,
|
|
84
|
+
msgstr: [],
|
|
85
|
+
},
|
|
86
|
+
Regular: {
|
|
87
|
+
msgid: 'Regular',
|
|
88
|
+
msgid_plural: undefined,
|
|
89
|
+
msgstr: [],
|
|
90
|
+
},
|
|
91
|
+
Large: {
|
|
92
|
+
msgid: 'Large',
|
|
93
|
+
msgid_plural: undefined,
|
|
94
|
+
msgstr: [],
|
|
95
|
+
},
|
|
96
|
+
Huge: {
|
|
97
|
+
msgid: 'Huge',
|
|
98
|
+
msgid_plural: undefined,
|
|
99
|
+
msgstr: [],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
expect(dataExtracted).toMatchObject(expected)
|
|
104
|
+
})
|
|
105
|
+
it('Should build pot file from fixtures block.json', async () => {
|
|
106
|
+
const currentArgs = {
|
|
107
|
+
...args,
|
|
108
|
+
paths: { cwd: 'tests/fixtures/block/', out: 'tests/fixtures/' },
|
|
109
|
+
patterns: {
|
|
110
|
+
include: ['block.json'],
|
|
111
|
+
exclude: ['node_modules'],
|
|
112
|
+
},
|
|
113
|
+
} as Args
|
|
114
|
+
const files = await getFiles(currentArgs as Args, currentArgs.patterns)
|
|
115
|
+
const dataExtracted = await getStrings(currentArgs as Args, files)
|
|
116
|
+
|
|
117
|
+
const expected = {
|
|
118
|
+
'block variation keyword': {
|
|
119
|
+
undefined: {
|
|
120
|
+
msgstr: [],
|
|
121
|
+
msgid: 'undefined',
|
|
122
|
+
msgctxt: 'block variation keyword',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
'block variation title': {
|
|
126
|
+
title: {
|
|
127
|
+
msgstr: [],
|
|
128
|
+
msgid: 'title',
|
|
129
|
+
msgctxt: 'block variation title',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
'block variation description': {
|
|
133
|
+
description: {
|
|
134
|
+
msgstr: [],
|
|
135
|
+
msgid: 'description',
|
|
136
|
+
msgctxt: 'block variation description',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
'block style label': {
|
|
140
|
+
label: {
|
|
141
|
+
msgstr: [],
|
|
142
|
+
msgid: 'label',
|
|
143
|
+
msgctxt: 'block style label',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
expect(dataExtracted).toMatchObject(expected)
|
|
148
|
+
})
|
|
149
|
+
})
|