@wp-blocks/make-pot 1.0.1 → 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.
@@ -1,76 +1,85 @@
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
+ import { describe, expect } from '@jest/globals'
2
+ import { Args, DomainType } from '../src/types'
3
+ import { getFiles } from '../src/fs/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
+ })
33
+
34
+ describe('getFiles', () => {
35
+ it('Should build pot file from fixtures block.json', async () => {
36
+ const currentArgs = {
37
+ ...args,
38
+ paths: { cwd: 'tests/fixtures/block/', out: 'tests/fixtures/' },
39
+ patterns: {
40
+ include: ['block.json'],
41
+ exclude: ['node_modules'],
42
+ },
43
+ } as Args
44
+ const files = await getFiles(currentArgs as Args, currentArgs.patterns)
45
+ const dataExtracted = await getStrings(currentArgs as Args, files)
46
+
47
+ const expected = [
48
+ {
49
+ '': {
50
+ description: {
51
+ comments: {
52
+ extracted: 'description',
53
+ reference: 'tests\\fixtures\\block\\block.json',
54
+ },
55
+ msgctxt: undefined,
56
+ msgid: 'description',
57
+ msgid_plural: '',
58
+ msgstr: [],
59
+ },
60
+ keywords: {
61
+ comments: {
62
+ extracted: 'keywords',
63
+ reference: 'tests\\fixtures\\block\\block.json',
64
+ },
65
+ msgctxt: undefined,
66
+ msgid: 'keywords',
67
+ msgid_plural: '',
68
+ msgstr: [],
69
+ },
70
+ title: {
71
+ comments: {
72
+ extracted: 'title',
73
+ reference: 'tests\\fixtures\\block\\block.json',
74
+ },
75
+ msgctxt: undefined,
76
+ msgid: 'title',
77
+ msgid_plural: '',
78
+ msgstr: [],
79
+ },
80
+ },
81
+ },
82
+ ]
83
+ expect(dataExtracted).toMatchObject(expected)
84
+ })
85
+ })
@@ -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,33 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ "master" ]
9
- pull_request:
10
- branches: [ "master" ]
11
-
12
- jobs:
13
- build:
14
-
15
- runs-on: ${{ matrix.os }}
16
-
17
- strategy:
18
- matrix:
19
- node-version: [lts/*, latest]
20
- os: [ubuntu-latest, macos-latest, windows-latest]
21
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
22
-
23
- steps:
24
- - uses: actions/checkout@v3
25
- - name: Use Node.js ${{ matrix.node-version }}
26
- uses: actions/setup-node@v3
27
- with:
28
- node-version: ${{ matrix.node-version }}
29
- cache: 'npm'
30
- - run: npm install
31
- - run: npm run build --if-present
32
- - run: npm test
33
-
@@ -1,52 +0,0 @@
1
- # Simple workflow for deploying static content to GitHub Pages
2
- name: TypeDoc generation
3
-
4
- on:
5
- release:
6
- branches: [ "master" ]
7
- # Allows you to run this workflow manually from the Actions tab
8
- workflow_dispatch:
9
-
10
- # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
11
- permissions:
12
- contents: read
13
- pages: write
14
- id-token: write
15
-
16
- jobs:
17
- # Single deploy job since we're just deploying
18
- deploy:
19
- name: Deploy Documentation
20
-
21
- # Deploy to the github-pages environment
22
- environment:
23
- name: github-pages
24
- url: ${{ steps.deployment.outputs.page_url }}
25
-
26
- # Specify runner + deployment step
27
- runs-on: ubuntu-latest
28
- steps:
29
- - name: Checkout code
30
- uses: actions/checkout@v3
31
-
32
- - name: TypeDoc Action
33
- uses: erikyo/tsdoc-action@v1
34
- with:
35
- source_dir: ./src/**/*
36
- output_dir: ./docs
37
- skipErrorChecking: true
38
- darkHighlightTheme: dark-plus
39
- basePath: ./src/
40
-
41
- - name: Setup Pages
42
- uses: actions/configure-pages@v3
43
-
44
- - name: Upload artifact
45
- uses: actions/upload-pages-artifact@v2
46
- with:
47
- # Upload entire repository
48
- path: './docs'
49
-
50
- - name: Deploy to GitHub Pages
51
- id: deployment
52
- uses: actions/deploy-pages@v2