@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,128 +1,126 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { Glob, Path } from 'glob'
3
- import { ignoreFunc } from '../src/glob'
4
- import path from 'path'
5
- import { minimatch } from 'minimatch'
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
- })
31
-
32
- const tests = [
33
- {
34
- title: 'defaults',
35
- src: '.',
36
- exclude: [
37
- '.git',
38
- 'node_modules',
39
- 'vendor',
40
- 'build',
41
- 'dist',
42
- 'uploads',
43
- 'Gruntfile.js',
44
- 'webpack.config.js',
45
- '**/*.min.js',
46
- 'tsconfig.js',
47
- '**.test.**',
48
- 'tests',
49
- 'coverage',
50
- '**/extractors**',
51
- '**/*.js.map',
52
- '**/lib/c**.d.ts',
53
- '**/**tt**',
54
- ],
55
- result: 20,
56
- },
57
- {
58
- title: 'exclude file.php',
59
- src: 'tests/fixtures/sourcedir',
60
- exclude: ['file.php'],
61
- result: [
62
- 'theme.json',
63
- 'svgTools.ts',
64
- 'plugin-header.php',
65
- 'package.json',
66
- 'file2.txt',
67
- 'vendor' + path.sep + 'index.php',
68
- 'node_modules' + path.sep + 'module' + path.sep + 'block.json',
69
- ],
70
- },
71
- {
72
- title: 'exclude node_modules and vendor',
73
- src: 'tests/fixtures/sourcedir',
74
- exclude: ['node_modules', 'vendor'],
75
- result: [
76
- 'theme.json',
77
- 'svgTools.ts',
78
- 'plugin-header.php',
79
- 'package.json',
80
- 'file2.txt',
81
- 'file.php',
82
- ],
83
- },
84
- {
85
- title: 'globstar path',
86
- src: 'tests/fixtures',
87
- exclude: ['**/*.php', '**/*.json', 'block/**'],
88
- result: 15,
89
- },
90
- {
91
- title: 'should exclude globstar',
92
- src: 'tests/fixtures/',
93
- exclude: ['**'],
94
- result: [],
95
- },
96
- {
97
- title: 'should remove excluded patterns',
98
- src: 'tests/fixtures/node_modules',
99
- exclude: [],
100
- result: ['block.json'],
101
- },
102
- ]
103
-
104
- describe('testing the ignoreFunc used to ignore files', () => {
105
- tests.forEach((test) => {
106
- it('should ignore files ' + test.title, () => {
107
- const foundDirs: string[] = []
108
-
109
- const dirs = new Glob('**', {
110
- ignore: {
111
- ignored: (p: Path) => ignoreFunc(p, test.exclude),
112
- },
113
- nodir: true,
114
- cwd: path.join(process.cwd(), test.src),
115
- })
116
-
117
- for (const dir of dirs) {
118
- foundDirs.push(dir)
119
- }
120
-
121
- if (typeof test.result === 'number') {
122
- expect(foundDirs.length).toBeGreaterThanOrEqual(test.result)
123
- } else {
124
- expect(foundDirs).toStrictEqual(test.result)
125
- }
126
- })
127
- })
128
- })
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,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
- 'block title': {
39
- title: {
40
- comments: {
41
- reference: 'block/block.json',
42
- },
43
- msgctxt: 'block title',
44
- msgid: 'title',
45
- msgstr: [],
46
- },
47
- },
48
- }
49
-
50
- const result = await parseJsonFile({
51
- sourceCode: fs.readFileSync(
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('getStrings-extra', () => {
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
@@ -1,46 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { Args, DomainType } from '../src/types'
3
- import { runExtract } from '../src/parser'
4
-
5
- const args = {
6
- paths: { cwd: 'tests/fixtures/', out: 'tests/fixtures/' },
7
- slug: 'plugin-slug',
8
- domain: 'plugin' as DomainType,
9
- }
10
- describe('makePot', () => {
11
- it('Should build pot file', async () => {
12
- const dataExtracted = await runExtract({
13
- ...args,
14
- patterns: {
15
- include: ['file.php'],
16
- exclude: ['node_modules', 'dist'],
17
- },
18
- } as Args)
19
- expect(dataExtracted).toMatchSnapshot()
20
- })
21
- })
22
- describe('makePot block json', () => {
23
- it('Should build pot file from fixtures', async () => {
24
- const dataExtracted = await runExtract({
25
- ...args,
26
- patterns: {
27
- include: ['block.json'],
28
- exclude: ['node_modules', 'dist'],
29
- },
30
- } as Args)
31
- expect(dataExtracted).toMatchSnapshot()
32
- })
33
- })
34
- describe('makePot plugin', () => {
35
- it('Should build pot file from fixtures/plugin', async () => {
36
- const dataExtracted = await runExtract({
37
- ...args,
38
- sourceDirectory: 'tests/fixtures/theme/',
39
- patterns: {
40
- include: ['**/*.css'],
41
- exclude: ['node_modules', 'dist'],
42
- },
43
- } as Args)
44
- expect(dataExtracted).toMatchSnapshot()
45
- })
46
- })
@@ -1,16 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { doTree } from '../src/tree'
3
- import fs from 'fs'
4
-
5
- import path from 'path'
6
-
7
- describe('doTree js', () => {
8
- it('Should build pot file js', () => {
9
- const fileContent = fs.readFileSync(
10
- path.join(process.cwd(), 'tests/fixtures/block/javascript.js'),
11
- 'utf8'
12
- )
13
- const fileParsed = doTree(fileContent, 'block/javascript.js')
14
- expect(fileParsed).toMatchSnapshot()
15
- })
16
- })
@@ -1,31 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { doTree } from '../src/tree'
3
- import path from 'path'
4
- import fs from 'fs'
5
-
6
- describe('doTree php', () => {
7
- it('Should build pot file', () => {
8
- const filePath = path.join(
9
- process.cwd(),
10
- 'tests/fixtures/sourcedir/file.php'
11
- )
12
- const fileContent = fs.readFileSync(filePath, 'utf8')
13
- console.log('My file path is: ' + filePath)
14
- const fileParsed = doTree(fileContent, 'tests/fixtures/php.php')
15
-
16
- expect(fileParsed).toMatchSnapshot()
17
- })
18
-
19
- it('Should build pot file php', () => {
20
- const fileContent = fs.readFileSync(
21
- path.join(process.cwd(), 'tests/fixtures/sourcedir/file.php'),
22
- 'utf8'
23
- )
24
- const fileParsed = doTree(
25
- fileContent,
26
- 'tests/fixtures/sourcedir/file.php'
27
- )
28
-
29
- expect(fileParsed).toMatchSnapshot()
30
- })
31
- })
@@ -1,16 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { doTree } from '../src/tree'
3
- import path from 'path'
4
-
5
- import fs from 'fs'
6
-
7
- describe('doTree tsx', () => {
8
- it('Should parse TSX file and extract strings', () => {
9
- const fileContent = fs.readFileSync(
10
- path.join(process.cwd(), 'tests/fixtures/block/SvgControls.tsx'),
11
- 'utf8'
12
- )
13
- const fileParsed = doTree(fileContent, 'SvgControls.tsx')
14
- expect(fileParsed).toMatchSnapshot()
15
- })
16
- })
@@ -1,28 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { detectPatternType } from '../src/utils'
3
-
4
- describe('detectPatternType', () => {
5
- test('should return "file" when pattern has an extension and no directory separator', () => {
6
- expect(detectPatternType('example.txt')).toBe('file')
7
- })
8
-
9
- test('should return "directory" when pattern has no extension and no directory separator', () => {
10
- expect(detectPatternType('example')).toBe('directory')
11
- })
12
-
13
- test('should return "glob" when pattern ends with a directory separator', () => {
14
- expect(detectPatternType('example/')).toBe('directory')
15
- })
16
-
17
- test('should return "glob" when pattern contains an asterisk', () => {
18
- expect(detectPatternType('*.txt')).toBe('glob')
19
- })
20
-
21
- test('should return "file" when pattern has directory separator and extension', () => {
22
- expect(detectPatternType('folder/example.txt')).toBe('file')
23
- })
24
-
25
- test('should return "glob" when pattern is a complex glob pattern', () => {
26
- expect(detectPatternType('folder/**/*.txt')).toBe('glob')
27
- })
28
- })