@dittowords/cli 4.5.2 → 5.0.0-beta.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 +6 -5
- package/bin/ditto.js +110 -285
- package/package.json +16 -10
- package/.github/actions/install-node-dependencies/action.yml +0 -24
- package/.github/workflows/required-checks.yml +0 -24
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -0
- package/.prettierrc.json +0 -1
- package/__mocks__/fs.js +0 -2
- package/babel.config.js +0 -6
- package/bin/__mocks__/api.js +0 -48
- package/bin/__mocks__/api.js.map +0 -1
- package/bin/add-project.js +0 -104
- package/bin/add-project.js.map +0 -1
- package/bin/api.js +0 -54
- package/bin/api.js.map +0 -1
- package/bin/component-folders.js +0 -59
- package/bin/component-folders.js.map +0 -1
- package/bin/config.js +0 -242
- package/bin/config.js.map +0 -1
- package/bin/config.test.js +0 -93
- package/bin/config.test.js.map +0 -1
- package/bin/consts.js +0 -57
- package/bin/consts.js.map +0 -1
- package/bin/ditto.js.map +0 -1
- package/bin/generate-suggestions.js +0 -183
- package/bin/generate-suggestions.js.map +0 -1
- package/bin/generate-suggestions.test.js +0 -200
- package/bin/generate-suggestions.test.js.map +0 -1
- package/bin/http/__mocks__/fetchComponentFolders.js +0 -71
- package/bin/http/__mocks__/fetchComponentFolders.js.map +0 -1
- package/bin/http/__mocks__/fetchComponents.js +0 -73
- package/bin/http/__mocks__/fetchComponents.js.map +0 -1
- package/bin/http/__mocks__/fetchVariants.js +0 -71
- package/bin/http/__mocks__/fetchVariants.js.map +0 -1
- package/bin/http/fetchComponentFolders.js +0 -64
- package/bin/http/fetchComponentFolders.js.map +0 -1
- package/bin/http/fetchComponents.js +0 -78
- package/bin/http/fetchComponents.js.map +0 -1
- package/bin/http/fetchVariants.js +0 -87
- package/bin/http/fetchVariants.js.map +0 -1
- package/bin/http/http.test.js +0 -159
- package/bin/http/http.test.js.map +0 -1
- package/bin/http/importComponents.js +0 -114
- package/bin/http/importComponents.js.map +0 -1
- package/bin/importComponents.js +0 -65
- package/bin/importComponents.js.map +0 -1
- package/bin/init/init.js +0 -126
- package/bin/init/init.js.map +0 -1
- package/bin/init/project.js +0 -182
- package/bin/init/project.js.map +0 -1
- package/bin/init/project.test.js +0 -26
- package/bin/init/project.test.js.map +0 -1
- package/bin/init/token.js +0 -196
- package/bin/init/token.js.map +0 -1
- package/bin/init/token.test.js +0 -147
- package/bin/init/token.test.js.map +0 -1
- package/bin/output.js +0 -76
- package/bin/output.js.map +0 -1
- package/bin/pull-lib.test.js +0 -379
- package/bin/pull-lib.test.js.map +0 -1
- package/bin/pull.js +0 -562
- package/bin/pull.js.map +0 -1
- package/bin/pull.test.js +0 -151
- package/bin/pull.test.js.map +0 -1
- package/bin/remove-project.js +0 -99
- package/bin/remove-project.js.map +0 -1
- package/bin/replace.js +0 -171
- package/bin/replace.js.map +0 -1
- package/bin/replace.test.js +0 -197
- package/bin/replace.test.js.map +0 -1
- package/bin/types.js +0 -21
- package/bin/types.js.map +0 -1
- package/bin/utils/cleanFileName.js +0 -40
- package/bin/utils/cleanFileName.js.map +0 -1
- package/bin/utils/cleanFileName.test.js +0 -15
- package/bin/utils/cleanFileName.test.js.map +0 -1
- package/bin/utils/createSentryContext.js +0 -43
- package/bin/utils/createSentryContext.js.map +0 -1
- package/bin/utils/determineModuleType.js +0 -79
- package/bin/utils/determineModuleType.js.map +0 -1
- package/bin/utils/determineModuleType.test.js +0 -60
- package/bin/utils/determineModuleType.test.js.map +0 -1
- package/bin/utils/generateIOSBundles.js +0 -147
- package/bin/utils/generateIOSBundles.js.map +0 -1
- package/bin/utils/generateJsDriver.js +0 -178
- package/bin/utils/generateJsDriver.js.map +0 -1
- package/bin/utils/generateJsDriverTypeFile.js +0 -105
- package/bin/utils/generateJsDriverTypeFile.js.map +0 -1
- package/bin/utils/generateSwiftDriver.js +0 -93
- package/bin/utils/generateSwiftDriver.js.map +0 -1
- package/bin/utils/getSelectedProjects.js +0 -67
- package/bin/utils/getSelectedProjects.js.map +0 -1
- package/bin/utils/processMetaOption.js +0 -40
- package/bin/utils/processMetaOption.js.map +0 -1
- package/bin/utils/processMetaOption.test.js +0 -45
- package/bin/utils/processMetaOption.test.js.map +0 -1
- package/bin/utils/projectsToText.js +0 -58
- package/bin/utils/projectsToText.js.map +0 -1
- package/bin/utils/promptForProject.js +0 -96
- package/bin/utils/promptForProject.js.map +0 -1
- package/bin/utils/quit.js +0 -73
- package/bin/utils/quit.js.map +0 -1
- package/bin/utils/sourcesToText.js +0 -57
- package/bin/utils/sourcesToText.js.map +0 -1
- package/etsc.config.js +0 -13
- package/jest.config.ts +0 -16
- package/jsconfig.json +0 -5
- package/lib/__mocks__/api.ts +0 -12
- package/lib/add-project.ts +0 -48
- package/lib/api.ts +0 -16
- package/lib/component-folders.ts +0 -9
- package/lib/config.test.ts +0 -79
- package/lib/config.ts +0 -279
- package/lib/consts.ts +0 -22
- package/lib/ditto.ts +0 -285
- package/lib/generate-suggestions.test.ts +0 -169
- package/lib/generate-suggestions.ts +0 -166
- package/lib/http/__mocks__/fetchComponentFolders.ts +0 -23
- package/lib/http/__mocks__/fetchComponents.ts +0 -24
- package/lib/http/__mocks__/fetchVariants.ts +0 -21
- package/lib/http/fetchComponentFolders.ts +0 -23
- package/lib/http/fetchComponents.ts +0 -43
- package/lib/http/fetchVariants.ts +0 -42
- package/lib/http/http.test.ts +0 -122
- package/lib/http/importComponents.ts +0 -79
- package/lib/importComponents.ts +0 -24
- package/lib/init/init.ts +0 -79
- package/lib/init/project.test.ts +0 -26
- package/lib/init/project.ts +0 -136
- package/lib/init/token.test.ts +0 -99
- package/lib/init/token.ts +0 -156
- package/lib/output.ts +0 -21
- package/lib/pull-lib.test.ts +0 -367
- package/lib/pull.test.ts +0 -117
- package/lib/pull.ts +0 -629
- package/lib/remove-project.ts +0 -44
- package/lib/replace.test.ts +0 -157
- package/lib/replace.ts +0 -140
- package/lib/types.ts +0 -83
- package/lib/utils/cleanFileName.test.ts +0 -11
- package/lib/utils/cleanFileName.ts +0 -8
- package/lib/utils/createSentryContext.ts +0 -20
- package/lib/utils/determineModuleType.test.ts +0 -48
- package/lib/utils/determineModuleType.ts +0 -55
- package/lib/utils/generateIOSBundles.ts +0 -122
- package/lib/utils/generateJsDriver.ts +0 -207
- package/lib/utils/generateJsDriverTypeFile.ts +0 -75
- package/lib/utils/generateSwiftDriver.ts +0 -48
- package/lib/utils/getSelectedProjects.ts +0 -36
- package/lib/utils/processMetaOption.test.ts +0 -18
- package/lib/utils/processMetaOption.ts +0 -16
- package/lib/utils/projectsToText.ts +0 -29
- package/lib/utils/promptForProject.ts +0 -61
- package/lib/utils/quit.ts +0 -7
- package/lib/utils/sourcesToText.ts +0 -25
- package/pull_request_template.md +0 -20
- package/testfiles/en.json +0 -5
- package/testfiles/es.json +0 -5
- package/testfiles/fr.json +0 -5
- package/testfiles/test1.jsx +0 -18
- package/testfiles/test2.jsx +0 -9
- package/testing/.gitkeep +0 -0
- package/testing/fixtures/bad-yaml.yml +0 -6
- package/testing/fixtures/ditto-config-no-token +0 -2
- package/testing/fixtures/project-config-empty-projects.yml +0 -1
- package/testing/fixtures/project-config-no-id.yml +0 -2
- package/testing/fixtures/project-config-no-name.yml +0 -2
- package/testing/fixtures/project-config-pull.yml +0 -0
- package/testing/fixtures/project-config-working.yml +0 -3
- package/tsconfig.json +0 -16
package/lib/pull-lib.test.ts
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { _test } from "./pull";
|
|
4
|
-
import { jest } from "@jest/globals";
|
|
5
|
-
import axios from "axios";
|
|
6
|
-
const axiosMock = jest.mocked(axios);
|
|
7
|
-
|
|
8
|
-
jest.mock("fs");
|
|
9
|
-
jest.mock("./api");
|
|
10
|
-
|
|
11
|
-
const testProjects: Project[] = [
|
|
12
|
-
{
|
|
13
|
-
id: "1",
|
|
14
|
-
name: "Project 1",
|
|
15
|
-
fileName: "Project 1",
|
|
16
|
-
},
|
|
17
|
-
{ id: "2", name: "Project 2", fileName: "Project 2" },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
jest.mock("./consts", () => ({
|
|
21
|
-
TEXT_DIR: "/.testing",
|
|
22
|
-
API_HOST: "https://api.dittowords.com",
|
|
23
|
-
CONFIG_FILE: "/.testing/ditto",
|
|
24
|
-
PROJECT_CONFIG_FILE: "/.testing/config.yml",
|
|
25
|
-
TEXT_FILE: "/.testing/text.json",
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
import consts from "./consts";
|
|
29
|
-
import allPull, { getFormatDataIsValid } from "./pull";
|
|
30
|
-
import { Project, SupportedExtension, SupportedFormat } from "./types";
|
|
31
|
-
|
|
32
|
-
const {
|
|
33
|
-
_testing: { cleanOutputFiles, downloadAndSaveBase },
|
|
34
|
-
} = allPull;
|
|
35
|
-
|
|
36
|
-
const cleanOutputDir = () => {
|
|
37
|
-
if (fs.existsSync(consts.TEXT_DIR))
|
|
38
|
-
fs.rmSync(consts.TEXT_DIR, { recursive: true, force: true });
|
|
39
|
-
|
|
40
|
-
fs.mkdirSync(consts.TEXT_DIR);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
afterAll(() => {
|
|
44
|
-
fs.rmSync(consts.TEXT_DIR, { force: true, recursive: true });
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("cleanOutputFiles", () => {
|
|
48
|
-
it("removes .js, .json, .xml, .strings, .stringsdict files", () => {
|
|
49
|
-
cleanOutputDir();
|
|
50
|
-
|
|
51
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.json"), "test");
|
|
52
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.js"), "test");
|
|
53
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.xml"), "test");
|
|
54
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.strings"), "test");
|
|
55
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.stringsdict"), "test");
|
|
56
|
-
// this file shouldn't be deleted
|
|
57
|
-
fs.writeFileSync(path.resolve(consts.TEXT_DIR, "test.txt"), "test");
|
|
58
|
-
|
|
59
|
-
expect(fs.readdirSync(consts.TEXT_DIR).length).toEqual(6);
|
|
60
|
-
|
|
61
|
-
cleanOutputFiles();
|
|
62
|
-
|
|
63
|
-
expect(fs.readdirSync(consts.TEXT_DIR).length).toEqual(1);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("downloadAndSaveBase", () => {
|
|
68
|
-
beforeAll(() => {
|
|
69
|
-
if (!fs.existsSync(consts.TEXT_DIR)) {
|
|
70
|
-
fs.mkdirSync(consts.TEXT_DIR);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
cleanOutputDir();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const mockDataFlat = { hello: "world" };
|
|
79
|
-
const mockDataNested = { hello: { text: "world" } };
|
|
80
|
-
const mockDataStructured = { hello: { text: "world" } };
|
|
81
|
-
const mockDataIcu = { hello: "world" };
|
|
82
|
-
const mockDataAndroid = `
|
|
83
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
84
|
-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
|
85
|
-
<string name="hello-world" ditto_api_id="hello-world">Hello World</string>
|
|
86
|
-
</resources>
|
|
87
|
-
`;
|
|
88
|
-
const mockDataIosStrings = `
|
|
89
|
-
"hello" = "world";
|
|
90
|
-
`;
|
|
91
|
-
const mockDataIosStringsDict = `
|
|
92
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
93
|
-
<plist version="1.0">
|
|
94
|
-
<dict>
|
|
95
|
-
<key>hello-world</key>
|
|
96
|
-
<dict>
|
|
97
|
-
<key>NSStringLocalizedFormatKey</key>
|
|
98
|
-
<string>%1$#@count@</string>
|
|
99
|
-
<key>count</key>
|
|
100
|
-
<dict>
|
|
101
|
-
<key>NSStringFormatSpecTypeKey</key>
|
|
102
|
-
<string>NSStringPluralRuleType</string>
|
|
103
|
-
<key>NSStringFormatValueTypeKey</key>
|
|
104
|
-
<string>d</string>
|
|
105
|
-
<key>other</key>
|
|
106
|
-
<string>espanol</string>
|
|
107
|
-
</dict>
|
|
108
|
-
</dict>
|
|
109
|
-
</dict>
|
|
110
|
-
</plist>
|
|
111
|
-
`;
|
|
112
|
-
|
|
113
|
-
const formats: Array<{
|
|
114
|
-
format: SupportedFormat;
|
|
115
|
-
data: Object;
|
|
116
|
-
ext: SupportedExtension;
|
|
117
|
-
}> = [
|
|
118
|
-
{ format: "flat", data: mockDataFlat, ext: ".json" },
|
|
119
|
-
{ format: "nested", data: mockDataNested, ext: ".json" },
|
|
120
|
-
{ format: "structured", data: mockDataStructured, ext: ".json" },
|
|
121
|
-
{ format: "icu", data: mockDataIcu, ext: ".json" },
|
|
122
|
-
{ format: "android", data: mockDataAndroid, ext: ".xml" },
|
|
123
|
-
{ format: "ios-strings", data: mockDataIosStrings, ext: ".strings" },
|
|
124
|
-
{
|
|
125
|
-
format: "ios-stringsdict",
|
|
126
|
-
data: mockDataIosStringsDict,
|
|
127
|
-
ext: ".stringsdict",
|
|
128
|
-
},
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
const mockApiCall = (data: unknown) => {
|
|
132
|
-
axiosMock.get.mockResolvedValue({ data });
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const verifySavedData = async (
|
|
136
|
-
format: SupportedFormat,
|
|
137
|
-
data: unknown,
|
|
138
|
-
ext: SupportedExtension
|
|
139
|
-
) => {
|
|
140
|
-
const output = await downloadAndSaveBase({
|
|
141
|
-
projects: testProjects,
|
|
142
|
-
format: format,
|
|
143
|
-
} as any);
|
|
144
|
-
expect(/successfully saved/i.test(output)).toEqual(true);
|
|
145
|
-
const directoryContents = fs.readdirSync(consts.TEXT_DIR);
|
|
146
|
-
expect(directoryContents.length).toEqual(testProjects.length);
|
|
147
|
-
expect(directoryContents.every((f) => f.endsWith(ext))).toBe(true);
|
|
148
|
-
const fileDataString = fs.readFileSync(
|
|
149
|
-
path.resolve(consts.TEXT_DIR, directoryContents[0]),
|
|
150
|
-
"utf8"
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
switch (format) {
|
|
154
|
-
case "android":
|
|
155
|
-
case "ios-strings":
|
|
156
|
-
case "ios-stringsdict":
|
|
157
|
-
expect(typeof data).toBe("string");
|
|
158
|
-
expect(fileDataString.replace(/\s/g, "")).toEqual(
|
|
159
|
-
(data as string).replace(/\s/g, "")
|
|
160
|
-
);
|
|
161
|
-
break;
|
|
162
|
-
|
|
163
|
-
case "flat":
|
|
164
|
-
case "nested":
|
|
165
|
-
case "structured":
|
|
166
|
-
case "icu":
|
|
167
|
-
default:
|
|
168
|
-
expect(JSON.parse(fileDataString)).toEqual(data);
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
formats.forEach(({ format, data, ext }) => {
|
|
174
|
-
it(`writes the ${format} format to disk`, async () => {
|
|
175
|
-
mockApiCall(data);
|
|
176
|
-
await verifySavedData(format, data, ext);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe("getFormatDataIsValid", () => {
|
|
182
|
-
it("handles flat format appropriately", () => {
|
|
183
|
-
expect(getFormatDataIsValid.flat("{}")).toBe(false);
|
|
184
|
-
expect(getFormatDataIsValid.flat(`{ "hello": "world" }`)).toBe(true);
|
|
185
|
-
expect(
|
|
186
|
-
getFormatDataIsValid.flat(`{
|
|
187
|
-
"__variant-name": "English",
|
|
188
|
-
"__variant-description": ""
|
|
189
|
-
}`)
|
|
190
|
-
).toBe(false);
|
|
191
|
-
expect(
|
|
192
|
-
getFormatDataIsValid.flat(`{
|
|
193
|
-
"__variant-name": "English",
|
|
194
|
-
"__variant-description": "",
|
|
195
|
-
"hello": "world"
|
|
196
|
-
}`)
|
|
197
|
-
).toBe(true);
|
|
198
|
-
});
|
|
199
|
-
it("handles structured format appropriately", () => {
|
|
200
|
-
expect(getFormatDataIsValid.structured("{}")).toBe(false);
|
|
201
|
-
expect(
|
|
202
|
-
getFormatDataIsValid.structured(`{ "hello": { "text": "world" } }`)
|
|
203
|
-
).toBe(true);
|
|
204
|
-
expect(
|
|
205
|
-
getFormatDataIsValid.structured(`{
|
|
206
|
-
"__variant-name": "English",
|
|
207
|
-
"__variant-description": ""
|
|
208
|
-
}`)
|
|
209
|
-
).toBe(false);
|
|
210
|
-
expect(
|
|
211
|
-
getFormatDataIsValid.structured(`{
|
|
212
|
-
"__variant-name": "English",
|
|
213
|
-
"__variant-description": "",
|
|
214
|
-
"hello": { "text": "world" }
|
|
215
|
-
}`)
|
|
216
|
-
).toBe(true);
|
|
217
|
-
});
|
|
218
|
-
it("handles icu format appropriately", () => {
|
|
219
|
-
expect(getFormatDataIsValid.icu("{}")).toBe(false);
|
|
220
|
-
expect(getFormatDataIsValid.icu(`{ "hello": "world" }`)).toBe(true);
|
|
221
|
-
expect(
|
|
222
|
-
getFormatDataIsValid.icu(`{
|
|
223
|
-
"__variant-name": "English",
|
|
224
|
-
"__variant-description": ""
|
|
225
|
-
}`)
|
|
226
|
-
).toBe(false);
|
|
227
|
-
expect(
|
|
228
|
-
getFormatDataIsValid.icu(`{
|
|
229
|
-
"__variant-name": "English",
|
|
230
|
-
"__variant-description": "",
|
|
231
|
-
"hello": "world"
|
|
232
|
-
}`)
|
|
233
|
-
).toBe(true);
|
|
234
|
-
});
|
|
235
|
-
it("handles android format appropriately", () => {
|
|
236
|
-
expect(
|
|
237
|
-
getFormatDataIsValid.android(`
|
|
238
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
239
|
-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>
|
|
240
|
-
`)
|
|
241
|
-
).toBe(false);
|
|
242
|
-
expect(
|
|
243
|
-
getFormatDataIsValid.android(`
|
|
244
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
245
|
-
<!--Variant Name: English-->
|
|
246
|
-
<!--Variant Description: -->
|
|
247
|
-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>
|
|
248
|
-
`)
|
|
249
|
-
).toBe(false);
|
|
250
|
-
expect(
|
|
251
|
-
getFormatDataIsValid.android(`
|
|
252
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
253
|
-
<!--Variant Name: English-->
|
|
254
|
-
<!--Variant Description: -->
|
|
255
|
-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
|
256
|
-
<string name="hello-world" ditto_api_id="hello-world">Hello World</string>
|
|
257
|
-
</resources>
|
|
258
|
-
`)
|
|
259
|
-
).toBe(true);
|
|
260
|
-
});
|
|
261
|
-
it("handles ios-strings format appropriately", () => {
|
|
262
|
-
expect(getFormatDataIsValid["ios-strings"]("")).toBe(false);
|
|
263
|
-
expect(
|
|
264
|
-
getFormatDataIsValid["ios-strings"](`
|
|
265
|
-
/* Variant Name: English */
|
|
266
|
-
/* Variant Description: */
|
|
267
|
-
`)
|
|
268
|
-
).toBe(false);
|
|
269
|
-
expect(
|
|
270
|
-
getFormatDataIsValid["ios-strings"](`
|
|
271
|
-
/* Variant Name: English */
|
|
272
|
-
/* Variant Description: */
|
|
273
|
-
"Hello" = "World";
|
|
274
|
-
`)
|
|
275
|
-
).toBe(true);
|
|
276
|
-
});
|
|
277
|
-
it("handles ios-stringsdict format appropriately", () => {
|
|
278
|
-
expect(
|
|
279
|
-
getFormatDataIsValid["ios-stringsdict"](`
|
|
280
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
281
|
-
<plist version="1.0">
|
|
282
|
-
<dict/>
|
|
283
|
-
</plist>
|
|
284
|
-
`)
|
|
285
|
-
).toBe(false);
|
|
286
|
-
expect(
|
|
287
|
-
getFormatDataIsValid["ios-stringsdict"](`
|
|
288
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
289
|
-
<!--Variant Name: English-->
|
|
290
|
-
<!--Variant Description: -->
|
|
291
|
-
<plist version="1.0">
|
|
292
|
-
<dict/>
|
|
293
|
-
</plist>
|
|
294
|
-
`)
|
|
295
|
-
).toBe(false);
|
|
296
|
-
expect(
|
|
297
|
-
getFormatDataIsValid["ios-stringsdict"](`
|
|
298
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
299
|
-
<!--Variant Name: English-->
|
|
300
|
-
<!--Variant Description: -->
|
|
301
|
-
<plist version="1.0">
|
|
302
|
-
<dict>
|
|
303
|
-
<key>Hello World</key>
|
|
304
|
-
<dict>
|
|
305
|
-
<key>NSStringLocalizedFormatKey</key>
|
|
306
|
-
<string>%1$#@count@</string>
|
|
307
|
-
<key>count</key>
|
|
308
|
-
<dict>
|
|
309
|
-
<key>NSStringFormatSpecTypeKey</key>
|
|
310
|
-
<string>NSStringPluralRuleType</string>
|
|
311
|
-
<key>NSStringFormatValueTypeKey</key>
|
|
312
|
-
<string>d</string>
|
|
313
|
-
<key>other</key>
|
|
314
|
-
<string>espanol</string>
|
|
315
|
-
</dict>
|
|
316
|
-
</dict>
|
|
317
|
-
</dict>
|
|
318
|
-
</plist>
|
|
319
|
-
`)
|
|
320
|
-
).toBe(true);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
const { getJsonFormat } = _test;
|
|
325
|
-
describe("getJsonFormat", () => {
|
|
326
|
-
it("returns 'flat' if no format specified", () => {
|
|
327
|
-
expect(getJsonFormat([])).toBe("flat");
|
|
328
|
-
});
|
|
329
|
-
it("returns 'flat' if invalid format specified", () => {
|
|
330
|
-
expect(getJsonFormat(["invalid-format"])).toBe("flat");
|
|
331
|
-
});
|
|
332
|
-
it("returns valid specified formats", () => {
|
|
333
|
-
expect(getJsonFormat(["structured"])).toBe("structured");
|
|
334
|
-
expect(getJsonFormat(["nested"])).toBe("nested");
|
|
335
|
-
expect(getJsonFormat(["icu"])).toBe("icu");
|
|
336
|
-
expect(getJsonFormat(["flat"])).toBe("flat");
|
|
337
|
-
});
|
|
338
|
-
it("returns last of formats if multiple specified", () => {
|
|
339
|
-
expect(getJsonFormat(["flat", "structured", "icu"])).toBe("icu");
|
|
340
|
-
expect(getJsonFormat(["flat", "icu", "structured"])).toBe("structured");
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
const { getJsonFormatIsValid } = _test;
|
|
345
|
-
describe("getJsonFormatIsValid", () => {
|
|
346
|
-
it("returns true for valid json", () => {
|
|
347
|
-
expect(getJsonFormatIsValid(`{ "key": "value" }`)).toBe(true);
|
|
348
|
-
expect(getJsonFormatIsValid(`{ "key": { "text": "value" }}`)).toBe(true);
|
|
349
|
-
expect(getJsonFormatIsValid(`{ "nested": { "key": "value" }}`)).toBe(true);
|
|
350
|
-
});
|
|
351
|
-
it("returns false for empty json", () => {
|
|
352
|
-
expect(getJsonFormatIsValid(`{}`)).toBe(false);
|
|
353
|
-
});
|
|
354
|
-
it("returns false for invalid json", () => {
|
|
355
|
-
expect(getJsonFormatIsValid(`abcdefg`)).toBe(false);
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const { ensureEndsWithNewLine } = _test;
|
|
360
|
-
describe("ensureEndsWithNewLine", () => {
|
|
361
|
-
it("adds a newline to the end of a string if it doesn't already have one", () => {
|
|
362
|
-
expect(ensureEndsWithNewLine("hello")).toBe("hello\n");
|
|
363
|
-
});
|
|
364
|
-
it("doesn't add a newline to the end of a string if it already has one", () => {
|
|
365
|
-
expect(ensureEndsWithNewLine("hello\n")).toBe("hello\n");
|
|
366
|
-
});
|
|
367
|
-
});
|
package/lib/pull.test.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { pull } from "./pull";
|
|
2
|
-
import { vol } from "memfs";
|
|
3
|
-
import consts from "./consts";
|
|
4
|
-
import { jest } from "@jest/globals";
|
|
5
|
-
import axios from "axios";
|
|
6
|
-
const axiosMock = jest.mocked(axios);
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
|
|
9
|
-
jest.mock("fs");
|
|
10
|
-
jest.mock("./api");
|
|
11
|
-
|
|
12
|
-
jest.mock("./http/fetchComponentFolders");
|
|
13
|
-
jest.mock("./http/fetchComponents");
|
|
14
|
-
jest.mock("./http/fetchVariants");
|
|
15
|
-
|
|
16
|
-
const defaultEnv = { ...process.env };
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
vol.reset();
|
|
20
|
-
process.env = { ...defaultEnv };
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const mockGlobalConfigFile = `
|
|
24
|
-
api.dittowords.com:
|
|
25
|
-
- token: xxx-xxx-xxx
|
|
26
|
-
`;
|
|
27
|
-
const mockProjectConfigFile = `
|
|
28
|
-
sources:
|
|
29
|
-
components: true
|
|
30
|
-
projects:
|
|
31
|
-
- id: project-id-1
|
|
32
|
-
name: Test Project
|
|
33
|
-
variants: true
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
describe("pull", () => {
|
|
37
|
-
it("correctly writes files to disk per source for basic config", async () => {
|
|
38
|
-
process.env.DITTO_TEXT_DIR = "/ditto";
|
|
39
|
-
process.env.DITTO_PROJECT_CONFIG_FILE = "/ditto/config.yml";
|
|
40
|
-
|
|
41
|
-
// we need to manually mock responses for the http calls that happen
|
|
42
|
-
// directly within the pull function; we don't need to mock the http
|
|
43
|
-
// calls that happen by way of http/* function calls since those have
|
|
44
|
-
// their own mocks already.
|
|
45
|
-
axiosMock.get.mockImplementation(
|
|
46
|
-
(): Promise<any> => Promise.resolve({ data: "data" })
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
vol.fromJSON({
|
|
50
|
-
[consts.CONFIG_FILE]: mockGlobalConfigFile,
|
|
51
|
-
[consts.PROJECT_CONFIG_FILE]: mockProjectConfigFile,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await pull();
|
|
55
|
-
|
|
56
|
-
const filesOnDiskExpected = new Set([
|
|
57
|
-
"components__example-folder__base.json",
|
|
58
|
-
"components__example-folder__example-variant-1.json",
|
|
59
|
-
"components__example-folder__example-variant-2.json",
|
|
60
|
-
"components__root__base.json",
|
|
61
|
-
"components__root__example-variant-1.json",
|
|
62
|
-
"components__root__example-variant-2.json",
|
|
63
|
-
"test-project__base.json",
|
|
64
|
-
"test-project__example-variant-1.json",
|
|
65
|
-
"test-project__example-variant-2.json",
|
|
66
|
-
"index.d.ts",
|
|
67
|
-
"index.js",
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
const filesOnDisk = fs.readdirSync("/ditto");
|
|
71
|
-
filesOnDisk.forEach((file) => {
|
|
72
|
-
filesOnDiskExpected.delete(file);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expect(filesOnDiskExpected.size).toBe(0);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("correctly does not write index.js or index.d.ts when `disableJsDriver: true` is specified", async () => {
|
|
79
|
-
process.env.DITTO_TEXT_DIR = "/ditto";
|
|
80
|
-
process.env.DITTO_PROJECT_CONFIG_FILE = "/ditto/config.yml";
|
|
81
|
-
|
|
82
|
-
// we need to manually mock responses for the http calls that happen
|
|
83
|
-
// directly within the pull function; we don't need to mock the http
|
|
84
|
-
// calls that happen by way of http/* function calls since those have
|
|
85
|
-
// their own mocks already.
|
|
86
|
-
axiosMock.get.mockImplementation(
|
|
87
|
-
(): Promise<any> => Promise.resolve({ data: "data" })
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
vol.fromJSON({
|
|
91
|
-
[consts.CONFIG_FILE]: mockGlobalConfigFile,
|
|
92
|
-
[consts.PROJECT_CONFIG_FILE]:
|
|
93
|
-
mockProjectConfigFile + "\n" + "disableJsDriver: true",
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
await pull();
|
|
97
|
-
|
|
98
|
-
const filesOnDiskExpected = new Set([
|
|
99
|
-
"components__example-folder__base.json",
|
|
100
|
-
"components__example-folder__example-variant-1.json",
|
|
101
|
-
"components__example-folder__example-variant-2.json",
|
|
102
|
-
"components__root__base.json",
|
|
103
|
-
"components__root__example-variant-1.json",
|
|
104
|
-
"components__root__example-variant-2.json",
|
|
105
|
-
"test-project__base.json",
|
|
106
|
-
"test-project__example-variant-1.json",
|
|
107
|
-
"test-project__example-variant-2.json",
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
const filesOnDisk = fs.readdirSync("/ditto");
|
|
111
|
-
filesOnDisk.forEach((file) => {
|
|
112
|
-
filesOnDiskExpected.delete(file);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(filesOnDiskExpected.size).toBe(0);
|
|
116
|
-
});
|
|
117
|
-
});
|