@wp-blocks/make-pot 1.0.2 → 1.3.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.
- package/README.md +18 -1
- package/biome.json +12 -0
- package/lib/assets/block-i18n.js +1 -0
- package/lib/assets/package-i18n.js +1 -0
- package/lib/assets/theme-i18n.js +1 -0
- package/lib/assets/wp-plugin-i18n.js +1 -0
- package/lib/assets/wp-theme-i18n.js +1 -0
- package/lib/cli/getArgs.js +1 -0
- package/lib/cli/parseCli.js +1 -111
- package/lib/const.js +1 -93
- package/lib/extractors/css.js +1 -42
- package/lib/extractors/headers.js +1 -63
- package/lib/extractors/json.js +1 -82
- package/lib/extractors/php.js +2 -49
- package/lib/extractors/schema.js +1 -121
- package/lib/extractors/text.js +1 -19
- package/lib/extractors/utils.js +1 -54
- package/lib/fs/fs.js +1 -0
- package/lib/fs/glob.js +3 -95
- package/lib/index.js +1 -26
- package/lib/parser/exec.js +3 -71
- package/lib/parser/makePot.js +1 -35
- package/lib/parser/patterns.js +1 -34
- package/lib/parser/process.js +1 -70
- package/lib/parser/progress.js +1 -0
- package/lib/parser/taskRunner.js +1 -0
- package/lib/parser/tree.js +1 -87
- package/lib/run.js +1 -0
- package/lib/types.js +1 -3
- package/lib/utils/common.js +2 -0
- package/package.json +68 -62
- package/tsconfig.json +3 -19
- package/ .prettierignore +0 -3
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -12
- package/jest.config.json +0 -18
- package/lib/assets/block-i18n.json +0 -17
- package/lib/assets/package-i18n.json +0 -13
- package/lib/assets/theme-i18n.json +0 -86
- package/lib/assets/wp-plugin-i18n.json +0 -14
- package/lib/assets/wp-theme-i18n.json +0 -13
- package/lib/cli/index.d.ts +0 -1
- package/lib/cli/index.js +0 -114
- package/lib/cli/index.js.map +0 -1
- package/lib/cli/parseCli.d.ts +0 -3
- package/lib/cli/parseCli.js.map +0 -1
- package/lib/cliArgs.d.ts +0 -4
- package/lib/cliArgs.js +0 -216
- package/lib/cliArgs.js.map +0 -1
- package/lib/consolidate.d.ts +0 -2
- package/lib/consolidate.js +0 -37
- package/lib/consolidate.js.map +0 -1
- package/lib/const.d.ts +0 -140
- package/lib/const.js.map +0 -1
- package/lib/extractors/css.d.ts +0 -2
- package/lib/extractors/css.js.map +0 -1
- package/lib/extractors/headers.d.ts +0 -6
- package/lib/extractors/headers.js.map +0 -1
- package/lib/extractors/index.d.ts +0 -2
- package/lib/extractors/index.js +0 -60
- package/lib/extractors/index.js.map +0 -1
- package/lib/extractors/json.d.ts +0 -9
- package/lib/extractors/json.js.map +0 -1
- package/lib/extractors/php.d.ts +0 -3
- package/lib/extractors/php.js.map +0 -1
- package/lib/extractors/schema.d.ts +0 -13
- package/lib/extractors/schema.js.map +0 -1
- package/lib/extractors/text.d.ts +0 -1
- package/lib/extractors/text.js.map +0 -1
- package/lib/extractors/utils.d.ts +0 -5
- package/lib/extractors/utils.js.map +0 -1
- package/lib/fs/glob.d.ts +0 -13
- package/lib/fs/glob.js.map +0 -1
- package/lib/fs/index.d.ts +0 -2
- package/lib/fs/index.js +0 -69
- package/lib/fs/index.js.map +0 -1
- package/lib/fs.d.ts +0 -2
- package/lib/fs.js +0 -69
- package/lib/fs.js.map +0 -1
- package/lib/glob.d.ts +0 -13
- package/lib/glob.js +0 -95
- package/lib/glob.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js.map +0 -1
- package/lib/makePot.d.ts +0 -2
- package/lib/makePot.js +0 -83
- package/lib/makePot.js.map +0 -1
- package/lib/maps.d.ts +0 -122
- package/lib/maps.js +0 -73
- package/lib/maps.js.map +0 -1
- package/lib/parser/consolidate.d.ts +0 -2
- package/lib/parser/consolidate.js +0 -37
- package/lib/parser/consolidate.js.map +0 -1
- package/lib/parser/exec.d.ts +0 -3
- package/lib/parser/exec.js.map +0 -1
- package/lib/parser/index.d.ts +0 -2
- package/lib/parser/index.js +0 -24
- package/lib/parser/index.js.map +0 -1
- package/lib/parser/makePot.d.ts +0 -2
- package/lib/parser/makePot.js.map +0 -1
- package/lib/parser/patterns.d.ts +0 -2
- package/lib/parser/patterns.js.map +0 -1
- package/lib/parser/process.d.ts +0 -5
- package/lib/parser/process.js.map +0 -1
- package/lib/parser/tree.d.ts +0 -2
- package/lib/parser/tree.js.map +0 -1
- package/lib/parser.d.ts +0 -6
- package/lib/parser.js +0 -110
- package/lib/parser.js.map +0 -1
- package/lib/tree.d.ts +0 -2
- package/lib/tree.js +0 -78
- package/lib/tree.js.map +0 -1
- package/lib/types.d.ts +0 -50
- package/lib/types.js.map +0 -1
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/index.js +0 -78
- package/lib/utils/index.js.map +0 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +0 -78
- package/lib/utils.js.map +0 -1
- package/tests/consolidate.test.ts +0 -77
- package/tests/extract.test.ts +0 -391
- package/tests/getFiles.test.ts +0 -114
- package/tests/getStrings.test.ts +0 -85
- package/tests/ignoreFunction.test.ts +0 -126
- package/tests/jsonParse.test.ts +0 -51
- package/tests/tree.test.ts +0 -152
- /package/{LICENSE.md → LICENSE} +0 -0
|
@@ -1,126 +0,0 @@
|
|
|
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
|
-
})
|
package/tests/jsonParse.test.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
})
|
package/tests/tree.test.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { describe, expect } from '@jest/globals'
|
|
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
|
-
})
|
|
51
|
-
|
|
52
|
-
describe('doTree php test file', () => {
|
|
53
|
-
/** see wp cli tests */
|
|
54
|
-
it('should extract translations and comments from code content', () => {
|
|
55
|
-
const content = `<?php
|
|
56
|
-
|
|
57
|
-
// translators: Foo Bar Comment
|
|
58
|
-
__( 'Foo Bar', 'foo-plugin' );
|
|
59
|
-
|
|
60
|
-
// TrANslAtORs: Bar Baz Comment
|
|
61
|
-
__( 'Bar Baz', 'foo-plugin' );
|
|
62
|
-
|
|
63
|
-
// translators: Software name
|
|
64
|
-
const string = __( 'WordPress', 'foo-plugin' );
|
|
65
|
-
|
|
66
|
-
// translators: So much space
|
|
67
|
-
|
|
68
|
-
__( 'Spacey text', 'foo-plugin' );
|
|
69
|
-
|
|
70
|
-
/* translators: Long comment
|
|
71
|
-
spanning multiple
|
|
72
|
-
lines */
|
|
73
|
-
const string = __( 'Short text', 'foo-plugin' );
|
|
74
|
-
|
|
75
|
-
ReactDOM.render(
|
|
76
|
-
<h1>{__( 'Hello JSX', 'foo-plugin' )}</h1>,
|
|
77
|
-
document.getElementById('root')
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
wp.i18n.__( 'wp.i18n.__', 'foo-plugin' );
|
|
81
|
-
wp.i18n._n( 'wp.i18n._n_single', 'wp.i18n._n_plural', number, 'foo-plugin' );
|
|
82
|
-
|
|
83
|
-
const translate = wp.i18n;
|
|
84
|
-
translate.__( 'translate.__', 'foo-plugin' );
|
|
85
|
-
|
|
86
|
-
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
|
|
87
|
-
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );
|
|
88
|
-
|
|
89
|
-
Object(u.__)( 'minified.__', 'foo-plugin' );
|
|
90
|
-
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
|
|
91
|
-
|
|
92
|
-
/* translators: babel */
|
|
93
|
-
(0, __)( 'babel.__', 'foo-plugin' );
|
|
94
|
-
(0, _i18n.__)( 'babel-i18n.__', 'foo-plugin' );
|
|
95
|
-
(0, _i18n._x)( 'babel-i18n._x', 'babel-i18n._x_context', 'foo-plugin' );
|
|
96
|
-
|
|
97
|
-
eval( "__( 'Hello Eval World', 'foo-plugin' );" );
|
|
98
|
-
|
|
99
|
-
__( \`This is a \${bug}\`, 'foo-plugin' );
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Plugin Name: Plugin name
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
/* translators: Translators 1! */
|
|
106
|
-
_e( 'hello world', 'foo-plugin' );
|
|
107
|
-
|
|
108
|
-
/* Translators: Translators 2! */
|
|
109
|
-
$foo = __( 'foo', 'foo-plugin' );
|
|
110
|
-
|
|
111
|
-
/* translators: localized date and time format, see https://secure.php.net/date */
|
|
112
|
-
__( 'F j, Y g:i a', 'foo-plugin' );
|
|
113
|
-
|
|
114
|
-
// translators: let your ears fly!
|
|
115
|
-
__( 'on', 'foo-plugin' );
|
|
116
|
-
|
|
117
|
-
/*
|
|
118
|
-
* Translators: If there are characters in your language that are not supported
|
|
119
|
-
* by Lato, translate this to 'off'. Do not translate into your own language.
|
|
120
|
-
*/
|
|
121
|
-
__( 'off', 'foo-plugin' );
|
|
122
|
-
|
|
123
|
-
/* translators: this should get extracted. */ $foo = __( 'baba', 'foo-plugin' );
|
|
124
|
-
|
|
125
|
-
/* translators: boo */ /* translators: this should get extracted too. */ /* some other comment */ $bar = g( __( 'bubu', 'foo-plugin' ) );
|
|
126
|
-
|
|
127
|
-
{TAB}/*
|
|
128
|
-
{TAB} * translators: this comment block is indented with a tab and should get extracted too.
|
|
129
|
-
{TAB} */
|
|
130
|
-
{TAB}__( 'yolo', 'foo-plugin' );
|
|
131
|
-
|
|
132
|
-
/* translators: This is a comment */
|
|
133
|
-
__( 'Plugin name', 'foo-plugin' );
|
|
134
|
-
|
|
135
|
-
/* Translators: This is another comment! */
|
|
136
|
-
__( 'https://example.com', 'foo-plugin' );
|
|
137
|
-
`
|
|
138
|
-
|
|
139
|
-
const filename = 'filename.php'
|
|
140
|
-
|
|
141
|
-
const r = doTree(content, filename)
|
|
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
|
-
|
|
148
|
-
expect(translations.length).toBeGreaterThanOrEqual(19)
|
|
149
|
-
expect(comments.length).toBeGreaterThanOrEqual(8)
|
|
150
|
-
expect(res).toMatchSnapshot()
|
|
151
|
-
})
|
|
152
|
-
})
|
/package/{LICENSE.md → LICENSE}
RENAMED
|
File without changes
|