Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit 08db726

Browse files
author
Long Ho
committed
feat(@formatjs/cli): export extracting API
1 parent d1e630d commit 08db726

File tree

8 files changed

+512
-37
lines changed

8 files changed

+512
-37
lines changed

package-lock.json

Lines changed: 311 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"eslint-plugin-prettier": "^3.1.2",
6060
"eslint-plugin-react": "^7.19.0",
6161
"fast-memoize": "^2.5.2",
62-
"fs-extra": "^8.1.0",
62+
"fs-extra": "^9.0.0",
6363
"full-icu": "^1.3.1",
6464
"glob": "^7.1.6",
6565
"jest": "^25.2.7",

packages/babel-plugin-react-intl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@babel/helper-plugin-utils": "^7.0.0",
2020
"@types/babel__core": "^7.1.3",
2121
"@types/schema-utils": "^1.0.0",
22-
"fs-extra": "^8.1.0",
22+
"fs-extra": "^9.0.0",
2323
"intl-messageformat-parser": "^4.1.2",
2424
"schema-utils": "^2.2.0"
2525
},

packages/cli/package-lock.json

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"author": "Linjie Ding <[email protected]>",
2323
"homepage": "https://github.com/formatjs/formatjs",
2424
"license": "MIT",
25+
"main": "dist/index.js",
2526
"bin": {
2627
"formatjs": "bin/formatjs"
2728
},
@@ -47,12 +48,12 @@
4748
"@types/babel__core": "^7.1.3",
4849
"@types/loader-utils": "^1.1.3",
4950
"@types/lodash": "^4.14.138",
50-
"babel-plugin-const-enum": "^0.0.2",
51+
"babel-plugin-const-enum": "^0.0.5",
5152
"babel-plugin-react-intl": "^7.1.1",
52-
"commander": "4.0.0-1",
53-
"fs-extra": "^8.1.0",
53+
"commander": "5.0.0",
54+
"fs-extra": "^9.0.0",
5455
"glob": "^7.1.6",
55-
"loader-utils": "^1.2.3",
56+
"loader-utils": "^2.0.0",
5657
"lodash": "^4.17.15",
5758
"loud-rejection": "^2.1.0"
5859
},

packages/cli/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default as extract, ExtractCLIOptions} from './extract';

packages/cli/tests/extract/integration_tests/__snapshots__/index.test.ts.snap

Lines changed: 102 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Array [
3434
Object {
3535
"defaultMessage": "No ID",
3636
"description": "no ID",
37-
"id": "ae494",
37+
"id": "e695b",
3838
},
3939
]
4040
`;
@@ -75,7 +75,102 @@ Array [
7575
Object {
7676
"defaultMessage": "No ID",
7777
"description": "no ID",
78-
"id": "ae494",
78+
"id": "e695b",
79+
},
80+
]
81+
`;
82+
83+
exports[`basic case: defineMessages -> directory with location 1`] = `
84+
Array [
85+
"actual.json",
86+
]
87+
`;
88+
89+
exports[`basic case: defineMessages -> directory with location 2`] = `
90+
Array [
91+
Object {
92+
"defaultMessage": "Hello World!",
93+
"description": "The default message",
94+
"end": Object {
95+
"column": 3,
96+
"line": 9,
97+
},
98+
"file": "defineMessages/actual.js",
99+
"id": "foo.bar.baz",
100+
"start": Object {
101+
"column": 10,
102+
"line": 5,
103+
},
104+
},
105+
Object {
106+
"defaultMessage": "Hello Nurse!",
107+
"description": "Another message",
108+
"end": Object {
109+
"column": 3,
110+
"line": 14,
111+
},
112+
"file": "defineMessages/actual.js",
113+
"id": "foo.bar.biff",
114+
"start": Object {
115+
"column": 11,
116+
"line": 10,
117+
},
118+
},
119+
Object {
120+
"defaultMessage": "{count, plural, =0 {😭} one {# kitten} other {# kittens}}",
121+
"description": "Counts kittens",
122+
"end": Object {
123+
"column": 3,
124+
"line": 19,
125+
},
126+
"file": "defineMessages/actual.js",
127+
"id": "app.home.kittens",
128+
"start": Object {
129+
"column": 11,
130+
"line": 15,
131+
},
132+
},
133+
Object {
134+
"defaultMessage": " Some whitespace ",
135+
"description": "Whitespace",
136+
"end": Object {
137+
"column": 3,
138+
"line": 24,
139+
},
140+
"file": "defineMessages/actual.js",
141+
"id": "trailing.ws",
142+
"start": Object {
143+
"column": 22,
144+
"line": 20,
145+
},
146+
},
147+
Object {
148+
"defaultMessage": "A quoted value ''{value}'",
149+
"description": "Escaped apostrophe",
150+
"end": Object {
151+
"column": 3,
152+
"line": 29,
153+
},
154+
"file": "defineMessages/actual.js",
155+
"id": "escaped.apostrophe",
156+
"start": Object {
157+
"column": 11,
158+
"line": 25,
159+
},
160+
},
161+
Object {
162+
"defaultMessage": "No ID",
163+
"description": "no ID",
164+
"end": Object {
165+
"column": 3,
166+
"line": 37,
167+
},
168+
"file": "defineMessages/actual.js",
169+
"id": "e695b",
170+
"start": Object {
171+
"column": 19,
172+
"line": 34,
173+
},
79174
},
80175
]
81176
`;
@@ -110,7 +205,7 @@ Array [
110205
Object {
111206
"defaultMessage": "No ID",
112207
"description": "no ID",
113-
"id": "ae494",
208+
"id": "e695b",
114209
},
115210
]
116211
`;
@@ -134,7 +229,7 @@ Options:
134229
--extract-from-format-message-call Opt-in to extract from \`intl.formatMessage\` call with the same restrictions, e.g: has to be called with object literal such as \`intl.formatMessage({ id: 'foo', defaultMessage: 'bar', description: 'baz'})\` (default: false)
135230
--output-empty-json Output file with empty [] if src has no messages. For build systems like bazel that relies on specific output mapping, not writing out a file can cause issues. (default: false)
136231
--ignore <files> List of glob paths to **not** extract translations from.
137-
-h, --help output usage information
232+
-h, --help display help for command
138233
"
139234
`;
140235
@@ -168,7 +263,7 @@ Array [
168263
Object {
169264
"defaultMessage": "No ID",
170265
"description": "no ID",
171-
"id": "ae494",
266+
"id": "e695b",
172267
},
173268
Object {
174269
"defaultMessage": "formatted message",
@@ -212,7 +307,7 @@ Array [
212307
Object {
213308
"defaultMessage": "No ID",
214309
"description": "no ID",
215-
"id": "ae494",
310+
"id": "e695b",
216311
},
217312
]
218313
`;
@@ -247,7 +342,7 @@ Array [
247342
Object {
248343
"defaultMessage": "No ID",
249344
"description": "no ID",
250-
"id": "ae494",
345+
"id": "e695b",
251346
},
252347
Object {
253348
"defaultMessage": "formatted message",

packages/cli/tests/extract/integration_tests/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ test('basic case: defineMessages -> directory', async () => {
5252
).toMatchSnapshot();
5353
}, 10000);
5454

55+
test('basic case: defineMessages -> directory with location', async () => {
56+
process.chdir(__dirname);
57+
const {stdout, stderr} = await exec(
58+
`${BIN_PATH} extract defineMessages/actual.js --extract-source-location --messages-dir ${ARTIFACT_PATH}`
59+
);
60+
expect(stdout).toBe('');
61+
expect(stderr).toBe('');
62+
// Write to test_artifacts/defineMessages/actual.json
63+
expect(
64+
await readdir(path.join(ARTIFACT_PATH, 'defineMessages'))
65+
).toMatchSnapshot();
66+
expect(
67+
await readJSON(path.join(ARTIFACT_PATH, 'defineMessages/actual.json'))
68+
).toMatchSnapshot();
69+
}, 10000);
70+
5571
test('typescript -> stdout', async () => {
5672
const {stdout, stderr} = await exec(
5773
`${BIN_PATH} extract ${path.join(__dirname, 'typescript/actual.tsx')}`

0 commit comments

Comments
 (0)