@wp-blocks/make-pot 1.0.0 → 1.0.2

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.
Files changed (38) hide show
  1. package/README.md +58 -58
  2. package/jest.config.json +5 -1
  3. package/lib/assets/package-i18n.json +2 -0
  4. package/lib/cli/parseCli.js.map +1 -1
  5. package/lib/const.d.ts +2 -0
  6. package/lib/const.js.map +1 -1
  7. package/lib/extractors/headers.d.ts +2 -2
  8. package/lib/extractors/headers.js +16 -12
  9. package/lib/extractors/headers.js.map +1 -1
  10. package/lib/extractors/index.js +2 -2
  11. package/lib/extractors/index.js.map +1 -1
  12. package/lib/fs/glob.js +2 -2
  13. package/lib/fs/glob.js.map +1 -1
  14. package/lib/parser/exec.js +1 -1
  15. package/lib/parser/exec.js.map +1 -1
  16. package/lib/parser/index.d.ts +2 -2
  17. package/lib/parser/index.js +1 -1
  18. package/lib/parser/index.js.map +1 -1
  19. package/lib/parser/makePot.js +5 -9
  20. package/lib/parser/makePot.js.map +1 -1
  21. package/lib/parser/process.js +5 -6
  22. package/lib/parser/process.js.map +1 -1
  23. package/lib/parser/tree.js +14 -5
  24. package/lib/parser/tree.js.map +1 -1
  25. package/lib/utils/index.js +1 -1
  26. package/lib/utils/index.js.map +1 -1
  27. package/package.json +6 -6
  28. package/tests/{extract.old.ts → extract.test.ts} +20 -18
  29. package/tests/{getFiles.old.ts → getFiles.test.ts} +114 -114
  30. package/tests/{getStrings.old.ts → getStrings.test.ts} +85 -76
  31. package/tests/{ingnoreFunction.old.ts → ignoreFunction.test.ts} +126 -128
  32. package/tests/{jsonParse.ts → jsonParse.test.ts} +51 -61
  33. package/tests/{extract-2.test.ts → tree.test.ts} +49 -1
  34. package/tests/makePot.old.ts +0 -46
  35. package/tests/treeJs.old.ts +0 -16
  36. package/tests/treePhp.old.ts +0 -31
  37. package/tests/treeTs.old.ts +0 -16
  38. package/tests/utils.old.ts +0 -28
@@ -1,5 +1,5 @@
1
1
  import { describe, expect } from '@jest/globals'
2
- import { doTree } from '../src/tree'
2
+ import { doTree } from '../src/parser/tree'
3
3
 
4
4
  describe('getStrings', () => {
5
5
  it('should extract translations from js', () => {
@@ -15,7 +15,7 @@ describe('getStrings', () => {
15
15
  reference: 'filename.js:1',
16
16
  },
17
17
  msgid: 'Hello World',
18
- msgstr: [],
18
+ msgstr: [''],
19
19
  },
20
20
  },
21
21
  })
@@ -33,7 +33,7 @@ describe('getStrings', () => {
33
33
  reference: 'filename.ts:1',
34
34
  },
35
35
  msgid: 'Hello World',
36
- msgstr: [],
36
+ msgstr: [''],
37
37
  },
38
38
  },
39
39
  })
@@ -52,7 +52,7 @@ describe('getStrings', () => {
52
52
  reference: 'filename.tsx:1',
53
53
  },
54
54
  msgid: 'Hello World',
55
- msgstr: [],
55
+ msgstr: [''],
56
56
  },
57
57
  },
58
58
  })
@@ -73,7 +73,7 @@ describe('getStrings', () => {
73
73
  msgctxt: '',
74
74
  msgid: 'Hello World',
75
75
  msgid_plural: '',
76
- msgstr: [],
76
+ msgstr: [''],
77
77
  },
78
78
  },
79
79
  })
@@ -89,7 +89,7 @@ describe('getStrings', () => {
89
89
  },
90
90
  msgctxt: '',
91
91
  msgid: 'Hello World',
92
- msgstr: [],
92
+ msgstr: [''],
93
93
  msgid_plural: '',
94
94
  },
95
95
  },
@@ -106,16 +106,16 @@ describe('getStrings', () => {
106
106
  const content = `
107
107
  <?php /** translators: ciao! */ echo _x('Hello World', 'greeting'); ?>`
108
108
  const expected = {
109
- '': {
109
+ greeting: {
110
110
  'Hello World': {
111
111
  comments: {
112
112
  reference: 'filename.php:2',
113
113
  translator: 'ciao!',
114
114
  },
115
+ msgctxt: 'greeting',
115
116
  msgid: 'Hello World',
116
- msgctxt: '',
117
- msgid_plural: 'greeting',
118
- msgstr: [],
117
+ msgid_plural: '',
118
+ msgstr: [''],
119
119
  },
120
120
  },
121
121
  }
@@ -138,15 +138,16 @@ describe('getStrings', () => {
138
138
 
139
139
  <?php echo _x('Hello World', 'greeting'); ?>`
140
140
  const expected = {
141
- '': {
141
+ greeting: {
142
142
  'Hello World': {
143
+ msgctxt: 'greeting',
144
+ msgid: 'Hello World',
145
+ msgid_plural: '',
146
+ msgstr: [''],
143
147
  comments: {
148
+ translator: '',
144
149
  reference: 'filename.php:10',
145
150
  },
146
- msgid: 'Hello World',
147
- msgctxt: '',
148
- msgid_plural: '',
149
- msgstr: [],
150
151
  },
151
152
  },
152
153
  }
@@ -170,7 +171,7 @@ echo $link;`
170
171
  reference: 'filename.php:3',
171
172
  },
172
173
  msgid: 'Check out this link to my <a href="%s">website</a> made with WordPress.',
173
- msgstr: [],
174
+ msgstr: [''],
174
175
  },
175
176
  },
176
177
  }
@@ -214,8 +215,9 @@ describe('getStrings wp cli', () => {
214
215
  },
215
216
  msgctxt: '',
216
217
  msgid: '%1$d error found: %2$s when re-migrating order. Please review the error above.',
217
- msgid_plural: '',
218
- msgstr: [],
218
+ msgid_plural:
219
+ '%1$d errors found: %2$s when re-migrating orders. Please review the errors above.',
220
+ msgstr: ['', ''],
219
221
  },
220
222
  },
221
223
  }
@@ -1,114 +1,114 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { getFiles } from '../src/glob'
3
- import { Args, DomainType } from '../src/types'
4
- import path from 'path'
5
- import { parseCliArgs } from '../src/cli/parseCli'
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
- })
1
+ import { describe, expect } from '@jest/globals'
2
+ import { getFiles } from '../src/fs/glob'
3
+ import { Args, DomainType } from '../src/types'
4
+ import path from 'path'
5
+ import { parseCliArgs } from '../src/cli/parseCli'
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
+ })
@@ -1,76 +1,85 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { Args, DomainType } from '../src/types'
3
- import { getFiles } from '../src/glob'
4
- import { getStrings } from '../src/parser/process'
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
-
30
- expect(dataExtracted).toMatchSnapshot()
31
- })
32
- it('Should build pot file from fixtures block.json', async () => {
33
- const currentArgs = {
34
- ...args,
35
- paths: { cwd: 'tests/fixtures/block/', out: 'tests/fixtures/' },
36
- patterns: {
37
- include: ['block.json'],
38
- exclude: ['node_modules'],
39
- },
40
- } as Args
41
- const files = await getFiles(currentArgs as Args, currentArgs.patterns)
42
- const dataExtracted = await getStrings(currentArgs as Args, files)
43
-
44
- const expected = {
45
- 'block variation keyword': {
46
- undefined: {
47
- msgstr: [],
48
- msgid: 'undefined',
49
- msgctxt: 'block variation keyword',
50
- },
51
- },
52
- 'block variation title': {
53
- title: {
54
- msgstr: [],
55
- msgid: 'title',
56
- msgctxt: 'block variation title',
57
- },
58
- },
59
- 'block variation description': {
60
- description: {
61
- msgstr: [],
62
- msgid: 'description',
63
- msgctxt: 'block variation description',
64
- },
65
- },
66
- 'block style label': {
67
- label: {
68
- msgstr: [],
69
- msgid: 'label',
70
- msgctxt: 'block style label',
71
- },
72
- },
73
- }
74
- expect(dataExtracted).toMatchObject(expected)
75
- })
76
- })
1
+ import { describe, expect } from '@jest/globals'
2
+ import { Args, DomainType } from '../src/types'
3
+ import { getFiles } from '../src/fs/glob'
4
+ import { getStrings } from '../src/parser/process'
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
+
30
+ expect(dataExtracted).toMatchSnapshot()
31
+ })
32
+ })
33
+
34
+ describe('getFiles', () => {
35
+ it('Should build pot file from fixtures block.json', async () => {
36
+ const currentArgs = {
37
+ ...args,
38
+ paths: { cwd: 'tests/fixtures/block/', out: 'tests/fixtures/' },
39
+ patterns: {
40
+ include: ['block.json'],
41
+ exclude: ['node_modules'],
42
+ },
43
+ } as Args
44
+ const files = await getFiles(currentArgs as Args, currentArgs.patterns)
45
+ const dataExtracted = await getStrings(currentArgs as Args, files)
46
+
47
+ const expected = [
48
+ {
49
+ '': {
50
+ description: {
51
+ comments: {
52
+ extracted: 'description',
53
+ reference: 'tests\\fixtures\\block\\block.json',
54
+ },
55
+ msgctxt: undefined,
56
+ msgid: 'description',
57
+ msgid_plural: '',
58
+ msgstr: [],
59
+ },
60
+ keywords: {
61
+ comments: {
62
+ extracted: 'keywords',
63
+ reference: 'tests\\fixtures\\block\\block.json',
64
+ },
65
+ msgctxt: undefined,
66
+ msgid: 'keywords',
67
+ msgid_plural: '',
68
+ msgstr: [],
69
+ },
70
+ title: {
71
+ comments: {
72
+ extracted: 'title',
73
+ reference: 'tests\\fixtures\\block\\block.json',
74
+ },
75
+ msgctxt: undefined,
76
+ msgid: 'title',
77
+ msgid_plural: '',
78
+ msgstr: [],
79
+ },
80
+ },
81
+ },
82
+ ]
83
+ expect(dataExtracted).toMatchObject(expected)
84
+ })
85
+ })