@wp-blocks/make-pot 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +18 -1
  2. package/lib/cli/parseCli.js +11 -12
  3. package/lib/cli/parseCli.js.map +1 -1
  4. package/lib/const.js +1 -12
  5. package/lib/const.js.map +1 -1
  6. package/lib/extractors/headers.d.ts +2 -3
  7. package/lib/extractors/headers.js +23 -13
  8. package/lib/extractors/headers.js.map +1 -1
  9. package/lib/extractors/index.d.ts +2 -2
  10. package/lib/extractors/index.js +15 -25
  11. package/lib/extractors/index.js.map +1 -1
  12. package/lib/extractors/json.d.ts +3 -2
  13. package/lib/extractors/json.js +17 -30
  14. package/lib/extractors/json.js.map +1 -1
  15. package/lib/extractors/schema.d.ts +73 -2
  16. package/lib/extractors/schema.js +31 -52
  17. package/lib/extractors/schema.js.map +1 -1
  18. package/lib/extractors/text.js +3 -4
  19. package/lib/extractors/text.js.map +1 -1
  20. package/lib/extractors/utils.d.ts +4 -4
  21. package/lib/extractors/utils.js +17 -16
  22. package/lib/extractors/utils.js.map +1 -1
  23. package/lib/fs/glob.d.ts +2 -2
  24. package/lib/fs/glob.js +9 -21
  25. package/lib/fs/glob.js.map +1 -1
  26. package/lib/fs/index.js +2 -13
  27. package/lib/fs/index.js.map +1 -1
  28. package/lib/index.js +2 -2
  29. package/lib/index.js.map +1 -1
  30. package/lib/parser/exec.d.ts +0 -1
  31. package/lib/parser/exec.js +38 -60
  32. package/lib/parser/exec.js.map +1 -1
  33. package/lib/parser/index.d.ts +2 -2
  34. package/lib/parser/index.js +25 -19
  35. package/lib/parser/index.js.map +1 -1
  36. package/lib/parser/patterns.js +6 -7
  37. package/lib/parser/patterns.js.map +1 -1
  38. package/lib/parser/process.d.ts +4 -5
  39. package/lib/parser/process.js +25 -57
  40. package/lib/parser/process.js.map +1 -1
  41. package/lib/parser/progress.d.ts +3 -0
  42. package/lib/parser/progress.js +21 -0
  43. package/lib/parser/progress.js.map +1 -0
  44. package/lib/parser/taskRunner.d.ts +4 -0
  45. package/lib/parser/taskRunner.js +33 -0
  46. package/lib/parser/taskRunner.js.map +1 -0
  47. package/lib/parser/tree.d.ts +2 -2
  48. package/lib/parser/tree.js +40 -23
  49. package/lib/parser/tree.js.map +1 -1
  50. package/lib/utils/index.d.ts +1 -0
  51. package/lib/utils/index.js +7 -2
  52. package/lib/utils/index.js.map +1 -1
  53. package/package.json +16 -3
  54. package/tests/extract.test.ts +95 -104
  55. package/tests/getFiles.test.ts +114 -114
  56. package/tests/ignoreFunction.test.ts +102 -126
  57. package/tests/tree.test.ts +6 -7
  58. package/tsconfig.json +3 -3
  59. package/lib/cliArgs.d.ts +0 -4
  60. package/lib/cliArgs.js +0 -216
  61. package/lib/cliArgs.js.map +0 -1
  62. package/lib/consolidate.d.ts +0 -2
  63. package/lib/consolidate.js +0 -37
  64. package/lib/consolidate.js.map +0 -1
  65. package/lib/fs.d.ts +0 -2
  66. package/lib/fs.js +0 -69
  67. package/lib/fs.js.map +0 -1
  68. package/lib/glob.d.ts +0 -13
  69. package/lib/glob.js +0 -95
  70. package/lib/glob.js.map +0 -1
  71. package/lib/makePot.d.ts +0 -2
  72. package/lib/makePot.js +0 -83
  73. package/lib/makePot.js.map +0 -1
  74. package/lib/maps.d.ts +0 -122
  75. package/lib/maps.js +0 -73
  76. package/lib/maps.js.map +0 -1
  77. package/lib/parser/consolidate.d.ts +0 -2
  78. package/lib/parser/consolidate.js +0 -37
  79. package/lib/parser/consolidate.js.map +0 -1
  80. package/lib/parser/makePot.d.ts +0 -2
  81. package/lib/parser/makePot.js +0 -35
  82. package/lib/parser/makePot.js.map +0 -1
  83. package/lib/parser.d.ts +0 -6
  84. package/lib/parser.js +0 -110
  85. package/lib/parser.js.map +0 -1
  86. package/lib/tree.d.ts +0 -2
  87. package/lib/tree.js +0 -78
  88. package/lib/tree.js.map +0 -1
  89. package/lib/utils.d.ts +0 -8
  90. package/lib/utils.js +0 -78
  91. package/lib/utils.js.map +0 -1
  92. package/tests/consolidate.test.ts +0 -77
  93. package/tests/getStrings.test.ts +0 -85
  94. /package/{LICENSE.md → LICENSE} +0 -0
  95. /package/tests/{jsonParse.test.ts → jsonParse.ts} +0 -0
@@ -1,114 +1,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
+ 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
+ const 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
+ const 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,126 +1,102 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { Glob, Path } from 'glob'
3
- import path from 'path'
4
- import { minimatch } from 'minimatch'
5
- import { ignoreFunc } from '../src/fs/glob'
6
-
7
- describe('includes or not', () => {
8
- it('paths includes', () => {
9
- expect(
10
- path
11
- .normalize(
12
- 'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures'
13
- )
14
- .includes('tests')
15
- ).toBe(true)
16
- expect(
17
- path.normalize(
18
- path.relative(
19
- 'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures',
20
- 'tests'
21
- )
22
- )
23
- ).toBe('..')
24
- expect(
25
- minimatch(path.normalize('block/SvgControls.tsx'), 'block/**')
26
- ).toBe(true)
27
- })
28
- })
29
-
30
- const tests = [
31
- {
32
- title: 'defaults',
33
- src: '.',
34
- exclude: [
35
- '.git',
36
- 'node_modules',
37
- 'vendor',
38
- 'build',
39
- 'dist',
40
- 'uploads',
41
- 'Gruntfile.js',
42
- 'webpack.config.js',
43
- '**/*.min.js',
44
- 'tsconfig.js',
45
- '**.test.**',
46
- 'tests',
47
- 'coverage',
48
- '**/extractors**',
49
- '**/*.js.map',
50
- '**/lib/c**.d.ts',
51
- '**/**tt**',
52
- ],
53
- result: 20,
54
- },
55
- {
56
- title: 'exclude file.php',
57
- src: 'tests/fixtures/sourcedir',
58
- exclude: ['file.php'],
59
- result: [
60
- 'theme.json',
61
- 'svgTools.ts',
62
- 'plugin-header.php',
63
- 'package.json',
64
- 'file2.txt',
65
- 'vendor' + path.sep + 'index.php',
66
- 'node_modules' + path.sep + 'module' + path.sep + 'block.json',
67
- ],
68
- },
69
- {
70
- title: 'exclude node_modules and vendor',
71
- src: 'tests/fixtures/sourcedir',
72
- exclude: ['node_modules', 'vendor'],
73
- result: [
74
- 'theme.json',
75
- 'svgTools.ts',
76
- 'plugin-header.php',
77
- 'package.json',
78
- 'file2.txt',
79
- 'file.php',
80
- ],
81
- },
82
- {
83
- title: 'globstar path',
84
- src: 'tests/fixtures',
85
- exclude: ['**/*.php', '**/*.json', 'block/**'],
86
- result: 15,
87
- },
88
- {
89
- title: 'should exclude globstar',
90
- src: 'tests/fixtures/',
91
- exclude: ['**'],
92
- result: [],
93
- },
94
- {
95
- title: 'should remove excluded patterns',
96
- src: 'tests/fixtures/node_modules',
97
- exclude: [],
98
- result: ['block.json'],
99
- },
100
- ]
101
-
102
- describe('testing the ignoreFunc used to ignore files', () => {
103
- tests.forEach((test) => {
104
- it('should ignore files ' + test.title, () => {
105
- const foundDirs: string[] = []
106
-
107
- const dirs = new Glob('**', {
108
- ignore: {
109
- ignored: (p: Path) => ignoreFunc(p, test.exclude),
110
- },
111
- nodir: true,
112
- cwd: path.join(process.cwd(), test.src),
113
- })
114
-
115
- for (const dir of dirs) {
116
- foundDirs.push(dir)
117
- }
118
-
119
- if (typeof test.result === 'number') {
120
- expect(foundDirs.length).toBeGreaterThanOrEqual(test.result)
121
- } else {
122
- expect(foundDirs).toStrictEqual(test.result)
123
- }
124
- })
125
- })
126
- })
1
+ import { describe, expect } from '@jest/globals'
2
+ import { Glob, Path } from 'glob'
3
+ import path from 'path'
4
+ import { ignoreFunc } from '../src/fs/glob'
5
+
6
+ const tests = [
7
+ {
8
+ title: 'defaults',
9
+ src: '.',
10
+ exclude: [
11
+ '.git',
12
+ 'node_modules',
13
+ 'vendor',
14
+ 'build',
15
+ 'dist',
16
+ 'uploads',
17
+ 'Gruntfile.js',
18
+ 'webpack.config.js',
19
+ '**/*.min.js',
20
+ 'tsconfig.js',
21
+ '**.test.**',
22
+ 'tests',
23
+ 'coverage',
24
+ '**/extractors**',
25
+ '**/*.js.map',
26
+ '**/lib/c**.d.ts',
27
+ '**/**tt**',
28
+ ],
29
+ result: 20,
30
+ },
31
+ {
32
+ title: 'exclude file.php',
33
+ src: 'tests/fixtures/sourcedir',
34
+ exclude: ['file.php'],
35
+ result: [
36
+ 'theme.json',
37
+ 'svgTools.ts',
38
+ 'sourcedir.php',
39
+ 'package.json',
40
+ 'file2.txt',
41
+ 'vendor' + path.sep + 'index.php',
42
+ 'node_modules' + path.sep + 'module' + path.sep + 'block.json',
43
+ ],
44
+ },
45
+ {
46
+ title: 'exclude node_modules and vendor',
47
+ src: 'tests/fixtures/sourcedir',
48
+ exclude: ['node_modules', 'vendor'],
49
+ result: [
50
+ 'theme.json',
51
+ 'svgTools.ts',
52
+ 'sourcedir.php',
53
+ 'package.json',
54
+ 'file2.txt',
55
+ 'file.php',
56
+ ],
57
+ },
58
+ {
59
+ title: 'globstar path',
60
+ src: 'tests/fixtures',
61
+ exclude: ['**/*.php', '**/*.json', 'block/**'],
62
+ result: 15,
63
+ },
64
+ {
65
+ title: 'should exclude globstar',
66
+ src: 'tests/fixtures/',
67
+ exclude: ['**'],
68
+ result: [],
69
+ },
70
+ {
71
+ title: 'should remove excluded patterns',
72
+ src: 'tests/fixtures/node_modules',
73
+ exclude: [],
74
+ result: ['block.json'],
75
+ },
76
+ ]
77
+
78
+ describe('testing the ignoreFunc used to ignore files', () => {
79
+ tests.forEach((test) => {
80
+ it('should ignore files ' + test.title, () => {
81
+ const foundDirs: string[] = []
82
+
83
+ const dirs = new Glob('**', {
84
+ ignore: {
85
+ ignored: (p: Path) => ignoreFunc(p, test.exclude),
86
+ },
87
+ nodir: true,
88
+ cwd: path.join(test.src),
89
+ })
90
+
91
+ for (const dir of dirs) {
92
+ foundDirs.push(dir)
93
+ }
94
+
95
+ if (typeof test.result === 'number') {
96
+ expect(foundDirs.length).toBeGreaterThanOrEqual(test.result)
97
+ } else {
98
+ expect(foundDirs).toStrictEqual(test.result)
99
+ }
100
+ })
101
+ })
102
+ })
@@ -138,15 +138,14 @@ describe('doTree php test file', () => {
138
138
 
139
139
  const filename = 'filename.php'
140
140
 
141
- const r = doTree(content, filename)
141
+ const r = doTree(content, filename).blocks
142
142
  const res = Object.values(r)[0]
143
- const translations = Object.keys(res)
144
- const comments = Object.entries(res).filter(
145
- ([x, translation]) => !!translation.comments?.translator
146
- )
147
143
 
148
- expect(translations.length).toBeGreaterThanOrEqual(19)
149
- expect(comments.length).toBeGreaterThanOrEqual(8)
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)
150
149
  expect(res).toMatchSnapshot()
151
150
  })
152
151
  })
package/tsconfig.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "ES2015",
5
- "lib": [ "Es6" ],
3
+ "module": "NodeNext",
4
+ "target": "ES2021",
5
+ "lib": [ "es2021" ],
6
6
  "noImplicitAny": true,
7
7
  "removeComments": true,
8
8
  "preserveConstEnums": true,
package/lib/cliArgs.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import yargs from 'yargs';
2
- import { Args } from './types';
3
- export declare function getArgs(): Args;
4
- export declare function parseCliArgs(args: yargs.PositionalOptions & yargs.Options & yargs.Arguments): Args;