@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.
Files changed (103) hide show
  1. package/README.md +75 -58
  2. package/jest.config.json +5 -1
  3. package/lib/cli/parseCli.js +11 -12
  4. package/lib/cli/parseCli.js.map +1 -1
  5. package/lib/const.js +1 -12
  6. package/lib/const.js.map +1 -1
  7. package/lib/extractors/headers.d.ts +2 -3
  8. package/lib/extractors/headers.js +23 -13
  9. package/lib/extractors/headers.js.map +1 -1
  10. package/lib/extractors/index.d.ts +2 -2
  11. package/lib/extractors/index.js +15 -25
  12. package/lib/extractors/index.js.map +1 -1
  13. package/lib/extractors/json.d.ts +3 -2
  14. package/lib/extractors/json.js +17 -30
  15. package/lib/extractors/json.js.map +1 -1
  16. package/lib/extractors/schema.d.ts +73 -2
  17. package/lib/extractors/schema.js +31 -52
  18. package/lib/extractors/schema.js.map +1 -1
  19. package/lib/extractors/text.js +3 -4
  20. package/lib/extractors/text.js.map +1 -1
  21. package/lib/extractors/utils.d.ts +4 -4
  22. package/lib/extractors/utils.js +17 -16
  23. package/lib/extractors/utils.js.map +1 -1
  24. package/lib/fs/glob.d.ts +2 -2
  25. package/lib/fs/glob.js +10 -22
  26. package/lib/fs/glob.js.map +1 -1
  27. package/lib/fs/index.js +2 -13
  28. package/lib/fs/index.js.map +1 -1
  29. package/lib/index.js +2 -2
  30. package/lib/index.js.map +1 -1
  31. package/lib/parser/exec.d.ts +0 -1
  32. package/lib/parser/exec.js +38 -60
  33. package/lib/parser/exec.js.map +1 -1
  34. package/lib/parser/index.d.ts +2 -2
  35. package/lib/parser/index.js +25 -19
  36. package/lib/parser/index.js.map +1 -1
  37. package/lib/parser/patterns.js +6 -7
  38. package/lib/parser/patterns.js.map +1 -1
  39. package/lib/parser/process.d.ts +4 -5
  40. package/lib/parser/process.js +25 -57
  41. package/lib/parser/process.js.map +1 -1
  42. package/lib/parser/progress.d.ts +3 -0
  43. package/lib/parser/progress.js +21 -0
  44. package/lib/parser/progress.js.map +1 -0
  45. package/lib/parser/taskRunner.d.ts +4 -0
  46. package/lib/parser/taskRunner.js +33 -0
  47. package/lib/parser/taskRunner.js.map +1 -0
  48. package/lib/parser/tree.d.ts +2 -2
  49. package/lib/parser/tree.js +40 -23
  50. package/lib/parser/tree.js.map +1 -1
  51. package/lib/utils/index.d.ts +1 -0
  52. package/lib/utils/index.js +7 -2
  53. package/lib/utils/index.js.map +1 -1
  54. package/package.json +21 -8
  55. package/tests/extract.test.ts +95 -104
  56. package/tests/{getFiles.old.ts → getFiles.test.ts} +3 -3
  57. package/tests/{ingnoreFunction.old.ts → ignoreFunction.test.ts} +4 -30
  58. package/tests/jsonParse.ts +51 -61
  59. package/tests/{extract-2.test.ts → tree.test.ts} +55 -8
  60. package/tsconfig.json +3 -3
  61. package/.github/workflows/node.js.yml +0 -33
  62. package/.github/workflows/tsDoc.yml +0 -52
  63. package/lib/cliArgs.d.ts +0 -4
  64. package/lib/cliArgs.js +0 -216
  65. package/lib/cliArgs.js.map +0 -1
  66. package/lib/consolidate.d.ts +0 -2
  67. package/lib/consolidate.js +0 -37
  68. package/lib/consolidate.js.map +0 -1
  69. package/lib/fs.d.ts +0 -2
  70. package/lib/fs.js +0 -69
  71. package/lib/fs.js.map +0 -1
  72. package/lib/glob.d.ts +0 -13
  73. package/lib/glob.js +0 -95
  74. package/lib/glob.js.map +0 -1
  75. package/lib/makePot.d.ts +0 -2
  76. package/lib/makePot.js +0 -83
  77. package/lib/makePot.js.map +0 -1
  78. package/lib/maps.d.ts +0 -122
  79. package/lib/maps.js +0 -73
  80. package/lib/maps.js.map +0 -1
  81. package/lib/parser/consolidate.d.ts +0 -2
  82. package/lib/parser/consolidate.js +0 -37
  83. package/lib/parser/consolidate.js.map +0 -1
  84. package/lib/parser/makePot.d.ts +0 -2
  85. package/lib/parser/makePot.js +0 -33
  86. package/lib/parser/makePot.js.map +0 -1
  87. package/lib/parser.d.ts +0 -6
  88. package/lib/parser.js +0 -110
  89. package/lib/parser.js.map +0 -1
  90. package/lib/tree.d.ts +0 -2
  91. package/lib/tree.js +0 -78
  92. package/lib/tree.js.map +0 -1
  93. package/lib/utils.d.ts +0 -8
  94. package/lib/utils.js +0 -78
  95. package/lib/utils.js.map +0 -1
  96. package/tests/consolidate.test.ts +0 -77
  97. package/tests/getStrings.old.ts +0 -76
  98. package/tests/makePot.old.ts +0 -46
  99. package/tests/treeJs.old.ts +0 -16
  100. package/tests/treePhp.old.ts +0 -31
  101. package/tests/treeTs.old.ts +0 -16
  102. package/tests/utils.old.ts +0 -28
  103. /package/{LICENSE.md → LICENSE} +0 -0
@@ -1,77 +0,0 @@
1
- import { describe, expect } from '@jest/globals'
2
- import { consolidate } from '../src/parser/consolidate'
3
- import { GetTextComment } from 'gettext-parser'
4
-
5
- describe('consolidate', () => {
6
- it('should consolidate strings with translator comments', () => {
7
- const translationStrings = {
8
- '': {
9
- '': {
10
- msgid: '',
11
- msgstr: [
12
- 'Content-Type: text/plain; charset=iso-8859-1\n...',
13
- ],
14
- },
15
- },
16
- '': {
17
- a: {
18
- msgid: '',
19
- msgstr: ['a'],
20
- },
21
- },
22
- 'another context': {
23
- '%s example': {
24
- msgctxt: 'another context',
25
- msgid: '%s example',
26
- msgid_plural: '%s examples',
27
- msgstr: ['% näide', '%s näidet'],
28
- comments: {
29
- translator: 'This is a regular comment',
30
- reference: '/path/to/file:123',
31
- } as GetTextComment,
32
- },
33
- },
34
- }
35
- const translationStrings2 = {
36
- '': {
37
- '': {
38
- msgid: '',
39
- msgstr: [
40
- 'Content-Type: text/plain; charset=iso-8859-1\n...',
41
- ],
42
- },
43
- },
44
- }
45
- // eslint-disable-next-line
46
- const expected = {
47
- '': {
48
- '': {
49
- msgid: '',
50
- msgstr: [
51
- 'Content-Type: text/plain; charset=iso-8859-1\n...',
52
- ],
53
- },
54
- a: {
55
- msgid: 'a',
56
- msgstr: ['a'],
57
- },
58
- },
59
- 'another context': {
60
- '%s example': {
61
- comments: {
62
- reference: '/path/to/file:123',
63
- translator: 'This is a regular comment',
64
- },
65
- msgctxt: 'another context',
66
- msgid: '%s example',
67
- msgid_plural: '%s examples',
68
- msgstr: ['% näide', '%s näidet'],
69
- },
70
- },
71
- }
72
-
73
- const result = consolidate([translationStrings, translationStrings2])
74
-
75
- expect(result).toMatchObject(expected)
76
- })
77
- })
@@ -1,76 +0,0 @@
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,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
- })
File without changes