@formatjs/cli-lib 5.0.7 → 5.0.8

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 (78) hide show
  1. package/index.d.ts +8 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +12 -0
  4. package/main.d.ts +2 -0
  5. package/main.d.ts.map +1 -0
  6. package/main.js +3 -0
  7. package/package.json +3 -3
  8. package/src/cli.d.ts +3 -0
  9. package/src/cli.d.ts.map +1 -0
  10. package/src/cli.js +165 -0
  11. package/src/compile.d.ts +48 -0
  12. package/src/compile.d.ts.map +1 -0
  13. package/src/compile.js +97 -0
  14. package/src/compile_folder.d.ts +3 -0
  15. package/src/compile_folder.d.ts.map +1 -0
  16. package/src/compile_folder.js +11 -0
  17. package/src/console_utils.d.ts +10 -0
  18. package/src/console_utils.d.ts.map +1 -0
  19. package/src/console_utils.js +76 -0
  20. package/src/extract.d.ts +75 -0
  21. package/src/extract.d.ts.map +1 -0
  22. package/src/extract.js +177 -0
  23. package/src/formatters/crowdin.d.ts +8 -0
  24. package/src/formatters/crowdin.d.ts.map +1 -0
  25. package/src/formatters/crowdin.js +27 -0
  26. package/src/formatters/default.d.ts +6 -0
  27. package/src/formatters/default.d.ts.map +1 -0
  28. package/src/formatters/default.js +13 -0
  29. package/src/formatters/index.d.ts +9 -0
  30. package/src/formatters/index.d.ts.map +1 -0
  31. package/src/formatters/index.js +41 -0
  32. package/src/formatters/lokalise.d.ts +10 -0
  33. package/src/formatters/lokalise.d.ts.map +1 -0
  34. package/src/formatters/lokalise.js +24 -0
  35. package/src/formatters/simple.d.ts +5 -0
  36. package/src/formatters/simple.d.ts.map +1 -0
  37. package/src/formatters/simple.js +12 -0
  38. package/src/formatters/smartling.d.ts +24 -0
  39. package/src/formatters/smartling.d.ts.map +1 -0
  40. package/src/formatters/smartling.js +50 -0
  41. package/src/formatters/transifex.d.ts +10 -0
  42. package/src/formatters/transifex.d.ts.map +1 -0
  43. package/src/formatters/transifex.js +24 -0
  44. package/src/parse_script.d.ts +8 -0
  45. package/src/parse_script.d.ts.map +1 -0
  46. package/src/parse_script.js +51 -0
  47. package/src/pseudo_locale.d.ts +7 -0
  48. package/src/pseudo_locale.d.ts.map +1 -0
  49. package/src/pseudo_locale.js +100 -0
  50. package/src/vue_extractor.d.ts +3 -0
  51. package/src/vue_extractor.d.ts.map +1 -0
  52. package/src/vue_extractor.js +62 -0
  53. package/BUILD +0 -118
  54. package/CHANGELOG.md +0 -1097
  55. package/index.ts +0 -7
  56. package/main.ts +0 -5
  57. package/src/cli.ts +0 -240
  58. package/src/compile.ts +0 -141
  59. package/src/compile_folder.ts +0 -15
  60. package/src/console_utils.ts +0 -78
  61. package/src/extract.ts +0 -273
  62. package/src/formatters/crowdin.ts +0 -34
  63. package/src/formatters/default.ts +0 -19
  64. package/src/formatters/index.ts +0 -46
  65. package/src/formatters/lokalise.ts +0 -33
  66. package/src/formatters/simple.ts +0 -12
  67. package/src/formatters/smartling.ts +0 -73
  68. package/src/formatters/transifex.ts +0 -33
  69. package/src/parse_script.ts +0 -49
  70. package/src/pseudo_locale.ts +0 -113
  71. package/src/vue_extractor.ts +0 -96
  72. package/tests/unit/__snapshots__/unit.test.ts.snap +0 -42
  73. package/tests/unit/__snapshots__/vue_extractor.test.ts.snap +0 -36
  74. package/tests/unit/fixtures/bind.vue +0 -46
  75. package/tests/unit/fixtures/comp.vue +0 -17
  76. package/tests/unit/unit.test.ts +0 -44
  77. package/tests/unit/vue_extractor.test.ts +0 -38
  78. package/tsconfig.json +0 -5
@@ -1,96 +0,0 @@
1
- import {parse} from '@vue/compiler-sfc'
2
- import type {
3
- TemplateChildNode,
4
- SimpleExpressionNode,
5
- ElementNode,
6
- InterpolationNode,
7
- CompoundExpressionNode,
8
- DirectiveNode,
9
- } from '@vue/compiler-core'
10
- import {NodeTypes} from '@vue/compiler-core'
11
-
12
- export type ScriptParseFn = (source: string) => void
13
-
14
- function walk(
15
- node: TemplateChildNode | CompoundExpressionNode['children'][0],
16
- visitor: (
17
- node:
18
- | ElementNode
19
- | InterpolationNode
20
- | CompoundExpressionNode
21
- | SimpleExpressionNode
22
- ) => void
23
- ) {
24
- if (typeof node !== 'object') {
25
- return
26
- }
27
- if (
28
- node.type !== NodeTypes.ELEMENT &&
29
- node.type !== NodeTypes.COMPOUND_EXPRESSION &&
30
- node.type !== NodeTypes.INTERPOLATION
31
- ) {
32
- return
33
- }
34
- visitor(node)
35
- if (node.type === NodeTypes.INTERPOLATION) {
36
- visitor(node.content)
37
- } else if (node.type === NodeTypes.ELEMENT) {
38
- node.children.forEach(n => walk(n, visitor))
39
- node.props
40
- .filter(
41
- (prop): prop is DirectiveNode => prop.type === NodeTypes.DIRECTIVE
42
- )
43
- .filter(prop => !!prop.exp)
44
- .forEach(prop => visitor(prop.exp!))
45
- } else {
46
- node.children.forEach(n => walk(n, visitor))
47
- }
48
- }
49
-
50
- function templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {
51
- return (
52
- n:
53
- | ElementNode
54
- | CompoundExpressionNode
55
- | CompoundExpressionNode['children'][0]
56
- ) => {
57
- if (typeof n !== 'object') {
58
- return
59
- }
60
- if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {
61
- return
62
- }
63
-
64
- const {content} = n as SimpleExpressionNode
65
- // Wrap this in () since a vue comp node attribute can just be
66
- // an object literal which, by itself is invalid TS
67
- // but with () it becomes an ExpressionStatement
68
- parseScriptFn(`(${content})`)
69
- }
70
- }
71
-
72
- export function parseFile(
73
- source: string,
74
- filename: string,
75
- parseScriptFn: ScriptParseFn
76
- ): any {
77
- const {descriptor, errors} = parse(source, {
78
- filename,
79
- })
80
- if (errors.length) {
81
- throw errors[0]
82
- }
83
- const {script, scriptSetup, template} = descriptor
84
-
85
- if (template) {
86
- walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn))
87
- }
88
-
89
- if (script) {
90
- parseScriptFn(script.content)
91
- }
92
-
93
- if (scriptSetup) {
94
- parseScriptFn(scriptSetup.content)
95
- }
96
- }
@@ -1,42 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`unit it passes camelCase-converted arguments to typescript API 1`] = `
4
- Array [
5
- Array [
6
- ";",
7
- Object {
8
- "compilerOptions": Object {
9
- "allowJs": true,
10
- "experimentalDecorators": true,
11
- "noEmit": true,
12
- "target": 99,
13
- },
14
- "fileName": "file1.js",
15
- "reportDiagnostics": true,
16
- "transformers": Object {
17
- "before": Array [
18
- [Function],
19
- ],
20
- },
21
- },
22
- ],
23
- Array [
24
- ";",
25
- Object {
26
- "compilerOptions": Object {
27
- "allowJs": true,
28
- "experimentalDecorators": true,
29
- "noEmit": true,
30
- "target": 99,
31
- },
32
- "fileName": "file2.tsx",
33
- "reportDiagnostics": true,
34
- "transformers": Object {
35
- "before": Array [
36
- [Function],
37
- ],
38
- },
39
- },
40
- ],
41
- ]
42
- `;
@@ -1,36 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`vue_extractor 1`] = `
4
- Array [
5
- Object {
6
- "defaultMessage": "in template",
7
- "description": "in template desc",
8
- "id": "f6d14",
9
- },
10
- Object {
11
- "defaultMessage": "in script",
12
- "description": "in script desc",
13
- "id": "1ebd4",
14
- },
15
- ]
16
- `;
17
-
18
- exports[`vue_extractor for bind attr 1`] = `
19
- Array [
20
- Object {
21
- "defaultMessage": "Delete",
22
- "description": "delete button text",
23
- "id": "0705a",
24
- },
25
- Object {
26
- "defaultMessage": "Send the item to the trash.",
27
- "description": "delete button title",
28
- "id": "5b09c",
29
- },
30
- Object {
31
- "defaultMessage": "The item has been deleted.",
32
- "description": "delete result message",
33
- "id": "8fba7",
34
- },
35
- ]
36
- `;
@@ -1,46 +0,0 @@
1
- <template>
2
- <p>
3
- Hello!
4
-
5
- <button
6
- target="_blank"
7
- :title="
8
- $formatMessage({
9
- description: 'delete button title',
10
- defaultMessage: 'Send the item to the trash.',
11
- })
12
- "
13
- :class="{
14
- toggled: toggle,
15
- }"
16
- @click="
17
- alert(
18
- $formatMessage({
19
- description: 'delete result message',
20
- defaultMessage: 'The item has been deleted.',
21
- })
22
- )
23
- "
24
- >
25
- {{
26
- $formatMessage({
27
- description: 'delete button text',
28
- defaultMessage: 'Delete',
29
- })
30
- }}
31
- </button>
32
- </p>
33
- </template>
34
-
35
- <script lang="ts">
36
- import {defineComponent} from 'vue'
37
- export default defineComponent({
38
- name: 'App',
39
-
40
- setup() {
41
- const toggle = true
42
-
43
- return {toggle, alert: (text: any) => alert(text)}
44
- },
45
- })
46
- </script>
@@ -1,17 +0,0 @@
1
- <template>
2
- <p>
3
- {{
4
- $formatMessage({
5
- defaultMessage: 'in template',
6
- description: 'in template desc',
7
- })
8
- }}
9
- </p>
10
- </template>
11
-
12
- <script>
13
- intl.formatMessage({
14
- defaultMessage: 'in script',
15
- description: 'in script desc',
16
- })
17
- </script>
@@ -1,44 +0,0 @@
1
- import cliMain from '../../src/cli'
2
- const glob = require('fast-glob')
3
- const ts = require('typescript')
4
- const transpileModule = jest.spyOn(ts, 'transpileModule')
5
- // Commander.js will call this.
6
- jest.spyOn(process, 'exit').mockImplementation((() => null) as any)
7
- jest.spyOn(glob, 'sync').mockImplementation(p => (Array.isArray(p) ? p : [p]))
8
-
9
- jest.mock('fs-extra', () => ({
10
- outputJSONSync: () => Promise.resolve(),
11
- readFile: () => Promise.resolve(';'),
12
- }))
13
-
14
- describe('unit', function () {
15
- beforeEach(() => {
16
- jest.clearAllMocks()
17
- })
18
-
19
- it('it passes camelCase-converted arguments to typescript API', async () => {
20
- await cliMain([
21
- 'node',
22
- 'path/to/formatjs-cli',
23
- 'extract',
24
- '--extract-source-location',
25
- '--remove-default-message',
26
- '--throws',
27
- '--additional-component-names',
28
- 'Foo,Bar',
29
- '--ignore=file3.ts',
30
- 'file1.js',
31
- 'file2.tsx',
32
- ])
33
-
34
- expect(transpileModule.mock.calls).toMatchSnapshot()
35
- })
36
-
37
- it('does not read from stdin when the glob pattern does NOT match anything', async () => {
38
- // Does not match anything
39
- jest.spyOn(glob, 'sync').mockImplementation(() => [])
40
- // This should not hang
41
- await cliMain(['node', 'path/to/formatjs-cli', 'extract', '*.doesnotexist'])
42
- expect(transpileModule).not.toHaveBeenCalled()
43
- }, 500) // 500ms timeout
44
- })
@@ -1,38 +0,0 @@
1
- import {MessageDescriptor} from '@formatjs/ts-transformer'
2
- import {parseScript} from '../../src/parse_script'
3
- import {parseFile} from '../../src/vue_extractor'
4
- import {readFile} from 'fs-extra'
5
- import {join} from 'path'
6
- test('vue_extractor', async function () {
7
- let messages: MessageDescriptor[] = []
8
- const fixturePath = join(__dirname, './fixtures/comp.vue')
9
- parseFile(
10
- await readFile(fixturePath, 'utf8'),
11
- fixturePath,
12
- parseScript({
13
- additionalFunctionNames: ['$formatMessage'],
14
- onMsgExtracted(_, msgs) {
15
- messages = messages.concat(msgs)
16
- },
17
- overrideIdFn: '[contenthash:5]',
18
- })
19
- )
20
- expect(messages).toMatchSnapshot()
21
- })
22
-
23
- test('vue_extractor for bind attr', async function () {
24
- let messages: MessageDescriptor[] = []
25
- const fixturePath = join(__dirname, './fixtures/bind.vue')
26
- parseFile(
27
- await readFile(fixturePath, 'utf8'),
28
- fixturePath,
29
- parseScript({
30
- additionalFunctionNames: ['$formatMessage'],
31
- onMsgExtracted(_, msgs) {
32
- messages = messages.concat(msgs)
33
- },
34
- overrideIdFn: '[contenthash:5]',
35
- })
36
- )
37
- expect(messages).toMatchSnapshot()
38
- })
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- // @generated
2
- {
3
- // This is purely for IDE, not for compilation
4
- "extends": "../../tsconfig.json"
5
- }