@wp-blocks/make-pot 1.0.1 → 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 +75 -58
- package/jest.config.json +5 -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 +10 -22
- 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 +21 -8
- package/tests/extract.test.ts +95 -104
- package/tests/{getFiles.old.ts → getFiles.test.ts} +3 -3
- package/tests/{ingnoreFunction.old.ts → ignoreFunction.test.ts} +4 -30
- package/tests/jsonParse.ts +51 -61
- package/tests/{extract-2.test.ts → tree.test.ts} +55 -8
- package/tsconfig.json +3 -3
- package/.github/workflows/node.js.yml +0 -33
- package/.github/workflows/tsDoc.yml +0 -52
- 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 -33
- 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.old.ts +0 -76
- package/tests/makePot.old.ts +0 -46
- package/tests/treeJs.old.ts +0 -16
- package/tests/treePhp.old.ts +0 -31
- package/tests/treeTs.old.ts +0 -16
- package/tests/utils.old.ts +0 -28
- /package/{LICENSE.md → LICENSE} +0 -0
package/tests/extract.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect } from '@jest/globals'
|
|
2
2
|
import { doTree } from '../src/parser/tree'
|
|
3
|
+
import { Block } from 'gettext-merger'
|
|
3
4
|
|
|
4
5
|
describe('getStrings', () => {
|
|
5
6
|
it('should extract translations from js', () => {
|
|
@@ -7,36 +8,34 @@ describe('getStrings', () => {
|
|
|
7
8
|
const filename = 'filename.js'
|
|
8
9
|
|
|
9
10
|
const result = doTree(content, filename)
|
|
11
|
+
const expected = new Block([])
|
|
12
|
+
expected.msgid = 'Hello World'
|
|
13
|
+
expected.comments = {
|
|
14
|
+
reference: ['filename.js:1'],
|
|
15
|
+
translator: [''],
|
|
16
|
+
}
|
|
10
17
|
|
|
11
|
-
expect(result).
|
|
12
|
-
'': {
|
|
13
|
-
'Hello World': {
|
|
14
|
-
comments: {
|
|
15
|
-
reference: 'filename.js:1',
|
|
16
|
-
},
|
|
17
|
-
msgid: 'Hello World',
|
|
18
|
-
msgstr: [''],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
})
|
|
18
|
+
expect(result.blocks[0].msgid).toBe(expected.msgid)
|
|
22
19
|
})
|
|
20
|
+
|
|
23
21
|
it('should extract translations from ts', () => {
|
|
24
22
|
const content = `__('Hello World', 'greeting');`
|
|
25
23
|
const filename = 'filename.ts'
|
|
26
24
|
|
|
27
|
-
const result = doTree(content, filename)
|
|
25
|
+
const result = doTree(content, filename).blocks[0].toJson()
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const expected = new Block([])
|
|
28
|
+
expected.msgid = 'Hello World'
|
|
29
|
+
expected.comments = {
|
|
30
|
+
reference: ['filename.ts:1'],
|
|
31
|
+
translator: [''],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(result.msgid).toBe(expected.msgid)
|
|
35
|
+
expect(expected.comments?.reference).toHaveLength(1)
|
|
36
|
+
expect([result.comments?.reference]).toEqual(
|
|
37
|
+
expected.comments?.reference
|
|
38
|
+
)
|
|
40
39
|
})
|
|
41
40
|
it('should extract translations from tsx', () => {
|
|
42
41
|
const content = `const element = <h1>{ __('Hello World', 'greeting')}</h1>;`
|
|
@@ -45,17 +44,15 @@ describe('getStrings', () => {
|
|
|
45
44
|
|
|
46
45
|
const result = doTree(content, filename)
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
})
|
|
47
|
+
const expected = new Block([])
|
|
48
|
+
expected.msgid = 'Hello World'
|
|
49
|
+
expected.msgstr = ['']
|
|
50
|
+
expected.comments = {
|
|
51
|
+
reference: ['filename.tsx:1'],
|
|
52
|
+
translator: [''],
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
expect(result.blocks[0].toJson()).toEqual(expected.toJson())
|
|
59
56
|
})
|
|
60
57
|
it('should extract translations with context', () => {
|
|
61
58
|
const content = `<?php __('Hello World', 'greeting'); ?>`
|
|
@@ -63,42 +60,30 @@ describe('getStrings', () => {
|
|
|
63
60
|
|
|
64
61
|
const result = doTree(content, filename)
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
msgid_plural: '',
|
|
76
|
-
msgstr: [''],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
})
|
|
63
|
+
const expected = new Block([])
|
|
64
|
+
expected.msgid = 'Hello World'
|
|
65
|
+
expected.msgstr = ['']
|
|
66
|
+
expected.comments = {
|
|
67
|
+
reference: ['filename.php:1'],
|
|
68
|
+
translator: [''],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(result.blocks[0].toJson()).toEqual(expected.toJson())
|
|
80
72
|
})
|
|
81
73
|
it('should extract translations from code content with no context or translator comments', () => {
|
|
82
74
|
const content = `<?php _e('Hello World'); ?>`
|
|
83
|
-
const expected =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
msgctxt: '',
|
|
91
|
-
msgid: 'Hello World',
|
|
92
|
-
msgstr: [''],
|
|
93
|
-
msgid_plural: '',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
75
|
+
const expected = new Block([])
|
|
76
|
+
expected.msgid = 'Hello World'
|
|
77
|
+
expected.msgstr = ['']
|
|
78
|
+
expected.comments = {
|
|
79
|
+
translator: undefined,
|
|
80
|
+
reference: ['filename.php:1'],
|
|
96
81
|
}
|
|
97
82
|
const filename = 'filename.php'
|
|
98
83
|
|
|
99
84
|
const result = doTree(content, filename)
|
|
100
85
|
|
|
101
|
-
expect(result).toEqual(expected)
|
|
86
|
+
expect(result.blocks[0]).toEqual(expected)
|
|
102
87
|
})
|
|
103
88
|
|
|
104
89
|
it('should extract translations with comments', () => {
|
|
@@ -106,18 +91,18 @@ describe('getStrings', () => {
|
|
|
106
91
|
const content = `
|
|
107
92
|
<?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`
|
|
108
93
|
const expected = {
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
blocks: [
|
|
95
|
+
{
|
|
111
96
|
comments: {
|
|
112
|
-
reference: 'filename.php:2',
|
|
113
|
-
translator: 'ciao!',
|
|
97
|
+
reference: ['filename.php:2'],
|
|
98
|
+
translator: ['ciao!'],
|
|
114
99
|
},
|
|
115
100
|
msgctxt: 'greeting',
|
|
116
101
|
msgid: 'Hello World',
|
|
117
|
-
msgid_plural: '',
|
|
118
102
|
msgstr: [''],
|
|
119
103
|
},
|
|
120
|
-
|
|
104
|
+
],
|
|
105
|
+
path: 'filename.php',
|
|
121
106
|
}
|
|
122
107
|
|
|
123
108
|
const result = doTree(content, filename)
|
|
@@ -137,24 +122,14 @@ describe('getStrings', () => {
|
|
|
137
122
|
|
|
138
123
|
|
|
139
124
|
<?php echo _x('Hello World', 'greeting'); ?>`
|
|
140
|
-
const expected =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
msgid: 'Hello World',
|
|
145
|
-
msgid_plural: '',
|
|
146
|
-
msgstr: [''],
|
|
147
|
-
comments: {
|
|
148
|
-
translator: '',
|
|
149
|
-
reference: 'filename.php:10',
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
}
|
|
125
|
+
const expected = `#: filename.php:10
|
|
126
|
+
msgctxt "greeting"
|
|
127
|
+
msgid "Hello World"
|
|
128
|
+
msgstr ""`
|
|
154
129
|
|
|
155
130
|
const result = doTree(content, filename)
|
|
156
131
|
|
|
157
|
-
expect(result).
|
|
132
|
+
expect(result.blocks[0].toStr()).toBe(expected)
|
|
158
133
|
})
|
|
159
134
|
|
|
160
135
|
it('should extract translations inside a sprint', () => {
|
|
@@ -168,9 +143,15 @@ echo $link;`
|
|
|
168
143
|
'Check out this link to my <a href="%s">website</a> made with WordPress.':
|
|
169
144
|
{
|
|
170
145
|
comments: {
|
|
146
|
+
extracted: '',
|
|
147
|
+
flag: '',
|
|
148
|
+
previous: '',
|
|
171
149
|
reference: 'filename.php:3',
|
|
150
|
+
translator: '',
|
|
172
151
|
},
|
|
152
|
+
msgctxt: '',
|
|
173
153
|
msgid: 'Check out this link to my <a href="%s">website</a> made with WordPress.',
|
|
154
|
+
msgid_plural: undefined,
|
|
174
155
|
msgstr: [''],
|
|
175
156
|
},
|
|
176
157
|
},
|
|
@@ -178,11 +159,36 @@ echo $link;`
|
|
|
178
159
|
|
|
179
160
|
const result = doTree(content, filename)
|
|
180
161
|
|
|
181
|
-
expect(result).toMatchObject(expected)
|
|
162
|
+
expect(result.toJson()).toMatchObject(expected)
|
|
182
163
|
})
|
|
183
164
|
})
|
|
184
165
|
|
|
185
166
|
describe('getStrings wp cli', () => {
|
|
167
|
+
it('should extract from an array of translations', () => {
|
|
168
|
+
const filename = 'filename.php'
|
|
169
|
+
const content = `<?php $var = 'don't do this'; $instructions = array(
|
|
170
|
+
"Overview" => array(
|
|
171
|
+
"title" => __( 'Overview', '3d-product-viewer' ),
|
|
172
|
+
"text" => __( "Hold down the right button to move the model", '3d-product-viewer' ),
|
|
173
|
+
"icon" => 'icon-book'
|
|
174
|
+
),
|
|
175
|
+
"Rotation" => array(
|
|
176
|
+
"title" => __( 'Rotation', '3d-product-viewer' ),
|
|
177
|
+
"text" => __( "Left-click and drag to change the angle", '3d-product-viewer' ),
|
|
178
|
+
"icon" => 'icon-rotation'
|
|
179
|
+
),
|
|
180
|
+
"Zoom" => array(
|
|
181
|
+
"title" => __( 'Zoom', '3d-product-viewer' ),
|
|
182
|
+
"text" => __( "Variable is % and not {$var}", '3d-product-viewer' ),
|
|
183
|
+
"icon" => 'icon-zoom'
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
`
|
|
187
|
+
|
|
188
|
+
const result = doTree(content, filename)
|
|
189
|
+
expect(result).toMatchSnapshot()
|
|
190
|
+
})
|
|
191
|
+
|
|
186
192
|
it('should extract translations with translator comments inside the formatting hell', () => {
|
|
187
193
|
const filename = 'filename.php'
|
|
188
194
|
const content = `<?php if ( count( $errors_in_remigrate_batch ) > 0 ) {
|
|
@@ -190,10 +196,10 @@ describe('getStrings wp cli', () => {
|
|
|
190
196
|
WP_CLI::warning(
|
|
191
197
|
sprintf(
|
|
192
198
|
/* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
|
|
193
|
-
|
|
199
|
+
_n(
|
|
194
200
|
'%1$d error found: %2$s when re-migrating order. Please review the error above.',
|
|
195
201
|
'%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
|
|
196
|
-
|
|
202
|
+
count( %s ),
|
|
197
203
|
'woocommerce'
|
|
198
204
|
),
|
|
199
205
|
count( $errors_in_remigrate_batch ),
|
|
@@ -204,26 +210,11 @@ describe('getStrings wp cli', () => {
|
|
|
204
210
|
WP_CLI::warning( 'Re-migration successful.', 'woocommerce' );
|
|
205
211
|
}
|
|
206
212
|
`
|
|
207
|
-
const expected = {
|
|
208
|
-
'': {
|
|
209
|
-
'%1$d error found: %2$s when re-migrating order. Please review the error above.':
|
|
210
|
-
{
|
|
211
|
-
comments: {
|
|
212
|
-
reference: 'filename.php:6',
|
|
213
|
-
translator:
|
|
214
|
-
'%1$d is number of errors and %2$s is the formatted array of order IDs.',
|
|
215
|
-
},
|
|
216
|
-
msgctxt: '',
|
|
217
|
-
msgid: '%1$d error found: %2$s when re-migrating order. Please review the error above.',
|
|
218
|
-
msgid_plural:
|
|
219
|
-
'%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
|
|
220
|
-
msgstr: ['', ''],
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
}
|
|
224
213
|
|
|
225
214
|
const result = doTree(content, filename)
|
|
226
|
-
expect(
|
|
215
|
+
expect(
|
|
216
|
+
'%1$d error found: %2$s when re-migrating order. Please review the error above.'
|
|
217
|
+
).toBe(result.blocks[0].msgid)
|
|
227
218
|
})
|
|
228
219
|
|
|
229
220
|
/** see https://github.com/wp-cli/i18n-command/blob/main/features/makepot.feature */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect } from '@jest/globals'
|
|
2
|
-
import { getFiles } from '../src/glob'
|
|
2
|
+
import { getFiles } from '../src/fs/glob'
|
|
3
3
|
import { Args, DomainType } from '../src/types'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import { parseCliArgs } from '../src/cli/parseCli'
|
|
@@ -82,7 +82,7 @@ describe('getFiles', () => {
|
|
|
82
82
|
]
|
|
83
83
|
|
|
84
84
|
const files = await getFiles(args, pattern)
|
|
85
|
-
|
|
85
|
+
const collected = []
|
|
86
86
|
for (const file of files) {
|
|
87
87
|
expect(file).toBeTruthy()
|
|
88
88
|
collected.push(file)
|
|
@@ -101,7 +101,7 @@ describe('getFiles', () => {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
const files = await getFiles(args, pattern)
|
|
104
|
-
|
|
104
|
+
const collected = []
|
|
105
105
|
for (const file of files) {
|
|
106
106
|
expect(file).toBeTruthy()
|
|
107
107
|
collected.push(file)
|
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
import { describe, expect } from '@jest/globals'
|
|
2
2
|
import { Glob, Path } from 'glob'
|
|
3
|
-
import { ignoreFunc } from '../src/glob'
|
|
4
3
|
import path from 'path'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const sep = path.sep
|
|
8
|
-
|
|
9
|
-
describe('includes or not', () => {
|
|
10
|
-
it('paths includes', () => {
|
|
11
|
-
expect(
|
|
12
|
-
path
|
|
13
|
-
.normalize(
|
|
14
|
-
'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures'
|
|
15
|
-
)
|
|
16
|
-
.includes('tests')
|
|
17
|
-
).toBe(true)
|
|
18
|
-
expect(
|
|
19
|
-
path.normalize(
|
|
20
|
-
path.relative(
|
|
21
|
-
'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures',
|
|
22
|
-
'tests'
|
|
23
|
-
)
|
|
24
|
-
)
|
|
25
|
-
).toBe('..')
|
|
26
|
-
expect(
|
|
27
|
-
minimatch(path.normalize('block/SvgControls.tsx'), 'block/**')
|
|
28
|
-
).toBe(true)
|
|
29
|
-
})
|
|
30
|
-
})
|
|
4
|
+
import { ignoreFunc } from '../src/fs/glob'
|
|
31
5
|
|
|
32
6
|
const tests = [
|
|
33
7
|
{
|
|
@@ -61,7 +35,7 @@ const tests = [
|
|
|
61
35
|
result: [
|
|
62
36
|
'theme.json',
|
|
63
37
|
'svgTools.ts',
|
|
64
|
-
'
|
|
38
|
+
'sourcedir.php',
|
|
65
39
|
'package.json',
|
|
66
40
|
'file2.txt',
|
|
67
41
|
'vendor' + path.sep + 'index.php',
|
|
@@ -75,7 +49,7 @@ const tests = [
|
|
|
75
49
|
result: [
|
|
76
50
|
'theme.json',
|
|
77
51
|
'svgTools.ts',
|
|
78
|
-
'
|
|
52
|
+
'sourcedir.php',
|
|
79
53
|
'package.json',
|
|
80
54
|
'file2.txt',
|
|
81
55
|
'file.php',
|
|
@@ -111,7 +85,7 @@ describe('testing the ignoreFunc used to ignore files', () => {
|
|
|
111
85
|
ignored: (p: Path) => ignoreFunc(p, test.exclude),
|
|
112
86
|
},
|
|
113
87
|
nodir: true,
|
|
114
|
-
cwd: path.join(
|
|
88
|
+
cwd: path.join(test.src),
|
|
115
89
|
})
|
|
116
90
|
|
|
117
91
|
for (const dir of dirs) {
|
package/tests/jsonParse.ts
CHANGED
|
@@ -1,61 +1,51 @@
|
|
|
1
|
-
import { describe, expect } from '@jest/globals'
|
|
2
|
-
import { parseJsonFile } from '../src/extractors/json'
|
|
3
|
-
import fs from 'fs'
|
|
4
|
-
|
|
5
|
-
describe('should parse json', () => {
|
|
6
|
-
it('theme.json', async () => {
|
|
7
|
-
const expected = {
|
|
8
|
-
'block style label': {
|
|
9
|
-
label: {
|
|
10
|
-
comments: {
|
|
11
|
-
reference: 'block/block.json',
|
|
12
|
-
},
|
|
13
|
-
msgctxt: 'block style label',
|
|
14
|
-
msgid: 'label',
|
|
15
|
-
msgstr: [],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
'block description': {
|
|
19
|
-
description: {
|
|
20
|
-
comments: {
|
|
21
|
-
reference: 'block/block.json',
|
|
22
|
-
},
|
|
23
|
-
msgctxt: 'block description',
|
|
24
|
-
msgid: 'description',
|
|
25
|
-
msgstr: [],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
'block keyword': {
|
|
29
|
-
undefined: {
|
|
30
|
-
comments: {
|
|
31
|
-
reference: 'block/block.json',
|
|
32
|
-
},
|
|
33
|
-
msgctxt: 'block keyword',
|
|
34
|
-
msgid: undefined,
|
|
35
|
-
msgstr: [],
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'tests/fixtures/block/block.json',
|
|
53
|
-
'utf8'
|
|
54
|
-
),
|
|
55
|
-
filename: 'block.json',
|
|
56
|
-
filepath: 'block/block.json',
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
expect(result).toEqual(expected)
|
|
60
|
-
})
|
|
61
|
-
})
|
|
1
|
+
import { describe, expect } from '@jest/globals'
|
|
2
|
+
import { parseJsonFile } from '../src/extractors/json'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
|
|
5
|
+
describe('should parse json', () => {
|
|
6
|
+
it('theme.json', async () => {
|
|
7
|
+
const expected = {
|
|
8
|
+
'block style label': {
|
|
9
|
+
label: {
|
|
10
|
+
comments: {
|
|
11
|
+
reference: 'block/block.json',
|
|
12
|
+
},
|
|
13
|
+
msgctxt: 'block style label',
|
|
14
|
+
msgid: 'label',
|
|
15
|
+
msgstr: [],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
'block description': {
|
|
19
|
+
description: {
|
|
20
|
+
comments: {
|
|
21
|
+
reference: 'block/block.json',
|
|
22
|
+
},
|
|
23
|
+
msgctxt: 'block description',
|
|
24
|
+
msgid: 'description',
|
|
25
|
+
msgstr: [],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
'block keyword': {
|
|
29
|
+
undefined: {
|
|
30
|
+
comments: {
|
|
31
|
+
reference: 'block/block.json',
|
|
32
|
+
},
|
|
33
|
+
msgctxt: 'block keyword',
|
|
34
|
+
msgid: undefined,
|
|
35
|
+
msgstr: [],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = await parseJsonFile({
|
|
41
|
+
fileContent: fs.readFileSync(
|
|
42
|
+
'tests/fixtures/block/block.json',
|
|
43
|
+
'utf8'
|
|
44
|
+
),
|
|
45
|
+
filename: 'block.json',
|
|
46
|
+
filepath: 'block/block.json',
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
expect(result).toEqual(expected)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -1,7 +1,55 @@
|
|
|
1
1
|
import { describe, expect } from '@jest/globals'
|
|
2
2
|
import { doTree } from '../src/parser/tree'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
describe('doTree js', () => {
|
|
8
|
+
const filepath = 'tests/fixtures/block/javascript.js'
|
|
9
|
+
let filePath: string
|
|
10
|
+
let fileContent: string
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
filePath = path.join(process.cwd(), filepath)
|
|
13
|
+
console.log('My file path is: ' + filePath)
|
|
14
|
+
fileContent = fs.readFileSync(filePath, 'utf8')
|
|
15
|
+
})
|
|
16
|
+
test('Should parse TSX file and extract strings', () => {
|
|
17
|
+
const fileParsed = doTree(fileContent, filepath)
|
|
18
|
+
expect(fileParsed).toMatchSnapshot()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('doTree php', () => {
|
|
23
|
+
const filepath = 'tests/fixtures/sourcedir/file.php'
|
|
24
|
+
let filePath: string
|
|
25
|
+
let fileContent: string
|
|
26
|
+
beforeAll(() => {
|
|
27
|
+
filePath = path.join(process.cwd(), filepath)
|
|
28
|
+
console.log('My file path is: ' + filePath)
|
|
29
|
+
fileContent = fs.readFileSync(filePath, 'utf8')
|
|
30
|
+
})
|
|
31
|
+
test('Should parse TSX file and extract strings', () => {
|
|
32
|
+
const fileParsed = doTree(fileContent, filepath)
|
|
33
|
+
expect(fileParsed).toMatchSnapshot()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('doTree tsx file', () => {
|
|
38
|
+
const filepath = 'tests/fixtures/block/SvgControls.tsx'
|
|
39
|
+
let filePath: string
|
|
40
|
+
let fileContent: string
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
filePath = path.join(process.cwd(), filepath)
|
|
43
|
+
console.log('My file path is: ' + filePath)
|
|
44
|
+
fileContent = fs.readFileSync(filePath, 'utf8')
|
|
45
|
+
})
|
|
46
|
+
test('Should parse TSX file and extract strings', () => {
|
|
47
|
+
const fileParsed = doTree(fileContent, filepath)
|
|
48
|
+
expect(fileParsed).toMatchSnapshot()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
3
51
|
|
|
4
|
-
describe('
|
|
52
|
+
describe('doTree php test file', () => {
|
|
5
53
|
/** see wp cli tests */
|
|
6
54
|
it('should extract translations and comments from code content', () => {
|
|
7
55
|
const content = `<?php
|
|
@@ -90,15 +138,14 @@ describe('getStrings-extra', () => {
|
|
|
90
138
|
|
|
91
139
|
const filename = 'filename.php'
|
|
92
140
|
|
|
93
|
-
const r = doTree(content, filename)
|
|
141
|
+
const r = doTree(content, filename).blocks
|
|
94
142
|
const res = Object.values(r)[0]
|
|
95
|
-
const translations = Object.keys(res)
|
|
96
|
-
const comments = Object.entries(res).filter(
|
|
97
|
-
([x, translation]) => !!translation.comments?.translator
|
|
98
|
-
)
|
|
99
143
|
|
|
100
|
-
|
|
101
|
-
expect(
|
|
144
|
+
/** TODO: fix this test - btw i counted 19 blocks and 8 comments in the test file */
|
|
145
|
+
expect(r.map((block) => block).length).toBeGreaterThanOrEqual(19)
|
|
146
|
+
expect(
|
|
147
|
+
r.filter((block) => block.comments).length
|
|
148
|
+
).toBeGreaterThanOrEqual(8)
|
|
102
149
|
expect(res).toMatchSnapshot()
|
|
103
150
|
})
|
|
104
151
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Node.js CI
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches: [ "master" ]
|
|
9
|
-
pull_request:
|
|
10
|
-
branches: [ "master" ]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
build:
|
|
14
|
-
|
|
15
|
-
runs-on: ${{ matrix.os }}
|
|
16
|
-
|
|
17
|
-
strategy:
|
|
18
|
-
matrix:
|
|
19
|
-
node-version: [lts/*, latest]
|
|
20
|
-
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
21
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
22
|
-
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v3
|
|
25
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
26
|
-
uses: actions/setup-node@v3
|
|
27
|
-
with:
|
|
28
|
-
node-version: ${{ matrix.node-version }}
|
|
29
|
-
cache: 'npm'
|
|
30
|
-
- run: npm install
|
|
31
|
-
- run: npm run build --if-present
|
|
32
|
-
- run: npm test
|
|
33
|
-
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Simple workflow for deploying static content to GitHub Pages
|
|
2
|
-
name: TypeDoc generation
|
|
3
|
-
|
|
4
|
-
on:
|
|
5
|
-
release:
|
|
6
|
-
branches: [ "master" ]
|
|
7
|
-
# Allows you to run this workflow manually from the Actions tab
|
|
8
|
-
workflow_dispatch:
|
|
9
|
-
|
|
10
|
-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
pages: write
|
|
14
|
-
id-token: write
|
|
15
|
-
|
|
16
|
-
jobs:
|
|
17
|
-
# Single deploy job since we're just deploying
|
|
18
|
-
deploy:
|
|
19
|
-
name: Deploy Documentation
|
|
20
|
-
|
|
21
|
-
# Deploy to the github-pages environment
|
|
22
|
-
environment:
|
|
23
|
-
name: github-pages
|
|
24
|
-
url: ${{ steps.deployment.outputs.page_url }}
|
|
25
|
-
|
|
26
|
-
# Specify runner + deployment step
|
|
27
|
-
runs-on: ubuntu-latest
|
|
28
|
-
steps:
|
|
29
|
-
- name: Checkout code
|
|
30
|
-
uses: actions/checkout@v3
|
|
31
|
-
|
|
32
|
-
- name: TypeDoc Action
|
|
33
|
-
uses: erikyo/tsdoc-action@v1
|
|
34
|
-
with:
|
|
35
|
-
source_dir: ./src/**/*
|
|
36
|
-
output_dir: ./docs
|
|
37
|
-
skipErrorChecking: true
|
|
38
|
-
darkHighlightTheme: dark-plus
|
|
39
|
-
basePath: ./src/
|
|
40
|
-
|
|
41
|
-
- name: Setup Pages
|
|
42
|
-
uses: actions/configure-pages@v3
|
|
43
|
-
|
|
44
|
-
- name: Upload artifact
|
|
45
|
-
uses: actions/upload-pages-artifact@v2
|
|
46
|
-
with:
|
|
47
|
-
# Upload entire repository
|
|
48
|
-
path: './docs'
|
|
49
|
-
|
|
50
|
-
- name: Deploy to GitHub Pages
|
|
51
|
-
id: deployment
|
|
52
|
-
uses: actions/deploy-pages@v2
|
package/lib/cliArgs.d.ts
DELETED