@wp-blocks/make-pot 0.0.1

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 (68) hide show
  1. package/ .prettierignore +3 -0
  2. package/.editorconfig +15 -0
  3. package/.eslintrc.json +12 -0
  4. package/.github/workflows/node.js.yml +33 -0
  5. package/jest.config.json +14 -0
  6. package/lib/cliArgs.d.ts +4 -0
  7. package/lib/cliArgs.js +177 -0
  8. package/lib/cliArgs.js.map +1 -0
  9. package/lib/consolidate.d.ts +2 -0
  10. package/lib/consolidate.js +27 -0
  11. package/lib/consolidate.js.map +1 -0
  12. package/lib/const.d.ts +26 -0
  13. package/lib/const.js +56 -0
  14. package/lib/const.js.map +1 -0
  15. package/lib/extractors-json.d.ts +9 -0
  16. package/lib/extractors-json.js +53 -0
  17. package/lib/extractors-json.js.map +1 -0
  18. package/lib/extractors-maps.d.ts +109 -0
  19. package/lib/extractors-maps.js +139 -0
  20. package/lib/extractors-maps.js.map +1 -0
  21. package/lib/extractors-php.d.ts +1 -0
  22. package/lib/extractors-php.js +24 -0
  23. package/lib/extractors-php.js.map +1 -0
  24. package/lib/extractors-text.d.ts +1 -0
  25. package/lib/extractors-text.js +21 -0
  26. package/lib/extractors-text.js.map +1 -0
  27. package/lib/extractors.d.ts +17 -0
  28. package/lib/extractors.js +128 -0
  29. package/lib/extractors.js.map +1 -0
  30. package/lib/fs.d.ts +2 -0
  31. package/lib/fs.js +51 -0
  32. package/lib/fs.js.map +1 -0
  33. package/lib/glob.d.ts +13 -0
  34. package/lib/glob.js +60 -0
  35. package/lib/glob.js.map +1 -0
  36. package/lib/index.d.ts +2 -0
  37. package/lib/index.js +25 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/makePot.d.ts +2 -0
  40. package/lib/makePot.js +56 -0
  41. package/lib/makePot.js.map +1 -0
  42. package/lib/parser.d.ts +6 -0
  43. package/lib/parser.js +93 -0
  44. package/lib/parser.js.map +1 -0
  45. package/lib/tree.d.ts +2 -0
  46. package/lib/tree.js +77 -0
  47. package/lib/tree.js.map +1 -0
  48. package/lib/types.d.ts +46 -0
  49. package/lib/types.js +3 -0
  50. package/lib/types.js.map +1 -0
  51. package/lib/utils.d.ts +8 -0
  52. package/lib/utils.js +74 -0
  53. package/lib/utils.js.map +1 -0
  54. package/package.json +50 -0
  55. package/tests/consolidate.test.ts +77 -0
  56. package/tests/extract-2.test.ts +97 -0
  57. package/tests/extract.test.ts +380 -0
  58. package/tests/getFiles.test.ts +114 -0
  59. package/tests/getStrings.test.ts +149 -0
  60. package/tests/index.html +78 -0
  61. package/tests/ingnoreFunction.test.ts +177 -0
  62. package/tests/jsonParse.test.ts +60 -0
  63. package/tests/makePot.ts +46 -0
  64. package/tests/treeJs.test.ts +15 -0
  65. package/tests/treePhp.test.ts +30 -0
  66. package/tests/treeTs.test.ts +15 -0
  67. package/tests/utils.test.ts +28 -0
  68. package/tsconfig.json +35 -0
@@ -0,0 +1,78 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>WordPress Plugin Translator</title>
7
+ <style>
8
+ #drop-area {
9
+ border: 2px dashed #ccc;
10
+ border-radius: 8px;
11
+ padding: 20px;
12
+ text-align: center;
13
+ cursor: pointer;
14
+ }
15
+ </style>
16
+ </head>
17
+ <body>
18
+
19
+ <div id="drop-area" ondragover="allowDrop(event)" ondrop="handleDrop(event)">
20
+ <p>Drop WordPress plugin (zip or tar) file here</p>
21
+ <input type="file" id="fileInput" style="display: none;" accept=".zip, .tar">
22
+ </div>
23
+
24
+ <script>
25
+ function allowDrop(event) {
26
+ event.preventDefault();
27
+ event.target.classList.add('drag-over');
28
+ }
29
+
30
+ function handleDrop(event) {
31
+ event.preventDefault();
32
+ event.target.classList.remove('drag-over');
33
+
34
+ const files = event.dataTransfer.files;
35
+ if (files.length > 0) {
36
+ const file = files[0];
37
+ if (file.name.endsWith('.zip') || file.name.endsWith('.tar')) {
38
+ handleFile(file);
39
+ } else {
40
+ alert("Please drop a valid zip or tar file.");
41
+ }
42
+ }
43
+ }
44
+
45
+ function handleFile(file) {
46
+ const reader = new FileReader();
47
+
48
+ reader.onload = function (e) {
49
+ const arrayBuffer = e.target.result;
50
+ // Use a library or custom code to unpack the zip file and parse the WordPress plugin.
51
+ // This is a simplified example, and you may need to include a library like JSZip for handling zip files.
52
+ // Example: const zip = new JSZip(arrayBuffer);
53
+
54
+ // For demonstration purposes, let's assume the plugin is parsed, and the pot file is generated.
55
+ const potFileContent = "msgid \"\"\nmsgstr \"\"\n";
56
+
57
+ // Display the pot file content (you may want to handle it differently in your application).
58
+ alert("Pot File Content:\n" + potFileContent);
59
+ };
60
+
61
+ reader.readAsArrayBuffer(file);
62
+ }
63
+
64
+ // Alternatively, you can trigger the file input manually.
65
+ document.getElementById('drop-area').addEventListener('click', function () {
66
+ document.getElementById('fileInput').click();
67
+ });
68
+
69
+ document.getElementById('fileInput').addEventListener('change', function () {
70
+ const file = this.files[0];
71
+ if (file) {
72
+ handleFile(file);
73
+ }
74
+ });
75
+ </script>
76
+
77
+ </body>
78
+ </html>
@@ -0,0 +1,177 @@
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('tesing paths includes', () => {
11
+ expect(
12
+ path.normalize(
13
+ path.relative(
14
+ 'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures',
15
+ 'fixtures'
16
+ )
17
+ )
18
+ ).toBe(path.normalize('..\\..\\fixtures'))
19
+ expect(
20
+ path
21
+ .normalize(
22
+ 'D:\\vvv-local\\www\\phpeighttwo\\public_html\\wp-content\\plugins\\makePot\\tests\\fixtures'
23
+ )
24
+ .includes('tests')
25
+ ).toBe(true)
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: [
56
+ 'tsconfig.json',
57
+ 'package.json',
58
+ 'package-lock.json',
59
+ 'jest.config.json',
60
+ 'src\\utils.ts',
61
+ 'src\\types.ts',
62
+ 'src\\tree.ts',
63
+ 'src\\parser.ts',
64
+ 'src\\makePot.ts',
65
+ 'src\\index.ts',
66
+ 'src\\glob.ts',
67
+ 'src\\fs.ts',
68
+ 'src\\const.ts',
69
+ 'src\\consolidate.ts',
70
+ 'src\\cliArgs.ts',
71
+ 'lib\\utils.js',
72
+ 'lib\\utils.d.ts',
73
+ 'lib\\types.js',
74
+ 'lib\\types.d.ts',
75
+ 'lib\\tree.js',
76
+ 'lib\\tree.d.ts',
77
+ 'lib\\parser.js',
78
+ 'lib\\parser.d.ts',
79
+ 'lib\\makePot.js',
80
+ 'lib\\makePot.d.ts',
81
+ 'lib\\index.js',
82
+ 'lib\\index.d.ts',
83
+ 'lib\\glob.js',
84
+ 'lib\\glob.d.ts',
85
+ 'lib\\fs.js',
86
+ 'lib\\fs.d.ts',
87
+ 'lib\\const.js',
88
+ 'lib\\consolidate.js',
89
+ 'lib\\cliArgs.js',
90
+ ],
91
+ },
92
+ {
93
+ title: 'exclude file.php',
94
+ src: 'tests/fixtures/sourcedir',
95
+ exclude: ['file.php'],
96
+ result: [
97
+ 'theme.json',
98
+ 'svgTools.ts',
99
+ 'plugin-header.php',
100
+ 'package.json',
101
+ 'file2.txt',
102
+ 'vendor' + path.sep + 'index.php',
103
+ 'node_modules\\module\\block.json',
104
+ ],
105
+ },
106
+ {
107
+ title: 'exclude node_modules and vendor',
108
+ src: 'tests/fixtures/sourcedir',
109
+ exclude: ['node_modules', 'vendor'],
110
+ result: [
111
+ 'theme.json',
112
+ 'svgTools.ts',
113
+ 'plugin-header.php',
114
+ 'package.json',
115
+ 'file2.txt',
116
+ 'file.php',
117
+ ],
118
+ },
119
+ {
120
+ title: 'globstar path',
121
+ src: 'tests/fixtures',
122
+ exclude: ['**/*.php', '**/*.json', 'block/**'],
123
+ result: [
124
+ 'file1.txt',
125
+ 'theme\\style.css',
126
+ 'sourcedir\\svgTools.ts',
127
+ 'sourcedir\\file2.txt',
128
+ 'fse\\style.css',
129
+ 'child-theme\\style.css',
130
+ 'Block Patterns\\README.md',
131
+ 'Block Patterns\\mother.jpg',
132
+ 'Block Patterns\\flora.png',
133
+ 'Block Patterns\\clothes.jpg',
134
+ 'fse\\templates\\single.html',
135
+ 'fse\\templates\\search.html',
136
+ 'fse\\templates\\page.html',
137
+ 'fse\\templates\\index.html',
138
+ 'fse\\templates\\archive.html',
139
+ 'fse\\parts\\header.html',
140
+ 'fse\\parts\\footer.html',
141
+ ],
142
+ },
143
+ {
144
+ title: 'should exclude globstar',
145
+ src: 'tests/fixtures/',
146
+ exclude: ['**'],
147
+ result: [],
148
+ },
149
+ {
150
+ title: 'should remove excluded patterns',
151
+ src: 'tests/fixtures/node_modules',
152
+ exclude: [],
153
+ result: ['block.json'],
154
+ },
155
+ ]
156
+
157
+ describe('testing the ignoreFunc used to ignore files', () => {
158
+ tests.forEach((test) => {
159
+ it('should ignore files ' + test.title, () => {
160
+ const foundDirs: string[] = []
161
+
162
+ const dirs = new Glob('**', {
163
+ ignore: {
164
+ ignored: (p: Path) => ignoreFunc(p, test.exclude),
165
+ },
166
+ nodir: true,
167
+ cwd: path.join(process.cwd(), test.src),
168
+ })
169
+
170
+ for (const dir of dirs) {
171
+ foundDirs.push(dir)
172
+ }
173
+
174
+ expect(foundDirs).toStrictEqual(test.result)
175
+ })
176
+ })
177
+ })
@@ -0,0 +1,60 @@
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 variation description': {
19
+ description: {
20
+ comments: {
21
+ reference: 'block/block.json',
22
+ },
23
+ msgctxt: 'block variation description',
24
+ msgid: 'description',
25
+ msgstr: [],
26
+ },
27
+ },
28
+ 'block variation keyword': {
29
+ undefined: {
30
+ comments: {
31
+ reference: 'block/block.json',
32
+ },
33
+ msgctxt: 'block variation keyword',
34
+ msgstr: [],
35
+ },
36
+ },
37
+ 'block variation title': {
38
+ title: {
39
+ comments: {
40
+ reference: 'block/block.json',
41
+ },
42
+ msgctxt: 'block variation title',
43
+ msgid: 'title',
44
+ msgstr: [],
45
+ },
46
+ },
47
+ }
48
+
49
+ const result = parseJsonFile({
50
+ sourceCode: fs.readFileSync(
51
+ 'tests/fixtures/block/block.json',
52
+ 'utf8'
53
+ ),
54
+ filename: 'block.json',
55
+ filepath: 'block/block.json',
56
+ })
57
+
58
+ expect(result).toEqual(expected)
59
+ })
60
+ })
@@ -0,0 +1,46 @@
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
+ })
@@ -0,0 +1,15 @@
1
+ import { doTree } from '../src/tree'
2
+ import fs from 'fs'
3
+
4
+ import path from 'path'
5
+
6
+ describe('doTree js', () => {
7
+ it('Should build pot file js', () => {
8
+ const fileContent = fs.readFileSync(
9
+ path.join(process.cwd(), 'tests/fixtures/block/javascript.js'),
10
+ 'utf8'
11
+ )
12
+ const fileParsed = doTree(fileContent, 'block/javascript.js')
13
+ expect(fileParsed).toMatchSnapshot()
14
+ })
15
+ })
@@ -0,0 +1,30 @@
1
+ import { doTree } from '../src/tree'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
+
5
+ describe('doTree php', () => {
6
+ it('Should build pot file', () => {
7
+ const filePath = path.join(
8
+ process.cwd(),
9
+ 'tests/fixtures/sourcedir/file.php'
10
+ )
11
+ const fileContent = fs.readFileSync(filePath, 'utf8')
12
+ console.log('My file path is: ' + filePath)
13
+ const fileParsed = doTree(fileContent, 'tests/fixtures/php.php')
14
+
15
+ expect(fileParsed).toMatchSnapshot()
16
+ })
17
+
18
+ it('Should build pot file php', () => {
19
+ const fileContent = fs.readFileSync(
20
+ path.join(process.cwd(), 'tests/fixtures/sourcedir/file.php'),
21
+ 'utf8'
22
+ )
23
+ const fileParsed = doTree(
24
+ fileContent,
25
+ 'tests/fixtures/sourcedir/file.php'
26
+ )
27
+
28
+ expect(fileParsed).toMatchSnapshot()
29
+ })
30
+ })
@@ -0,0 +1,15 @@
1
+ import { doTree } from '../src/tree'
2
+ import path from 'path'
3
+
4
+ import fs from 'fs'
5
+
6
+ describe('doTree tsx', () => {
7
+ it('Should parse TSX file and extract strings', () => {
8
+ const fileContent = fs.readFileSync(
9
+ path.join(process.cwd(), 'tests/fixtures/block/SvgControls.tsx'),
10
+ 'utf8'
11
+ )
12
+ const fileParsed = doTree(fileContent, 'SvgControls.tsx')
13
+ expect(fileParsed).toMatchSnapshot()
14
+ })
15
+ })
@@ -0,0 +1,28 @@
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 "directory" 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
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "Node16",
4
+ "target": "es2021",
5
+ "lib": [ "es2021", "Es6" ],
6
+ "noImplicitAny": true,
7
+ "removeComments": true,
8
+ "preserveConstEnums": true,
9
+ "sourceMap": true,
10
+ "strict": true,
11
+ "declaration": true,
12
+ "downlevelIteration": true,
13
+ "esModuleInterop": true,
14
+ "resolveJsonModule": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "experimentalDecorators": true,
17
+ // Import non-ES modules as default imports.
18
+ "outDir": "lib",
19
+ "rootDir": "src",
20
+ // Minify
21
+ "pretty": false,
22
+ // types
23
+ "typeRoots": [
24
+ "src/types.d.ts",
25
+ "node_modules/@types",
26
+ "@types"
27
+ ]
28
+ },
29
+ "include": [
30
+ "./src/**/*"
31
+ ],
32
+ "exclude": [
33
+ "lib",
34
+ ]
35
+ }