@applicaster/zapplicaster-cli 16.0.0-alpha.1740103407 → 16.0.0-alpha.1774022213
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/package.json +5 -5
- package/src/commands/prepareWorkspace/__tests__/__snapshots__/configurator.test.js.snap +2 -0
- package/src/commands/prepareWorkspace/appBootstrapper.js +9 -0
- package/src/commands/prepareWorkspace/configurator.js +26 -1
- package/src/commands/prepareWorkspace/parseFonts.js +6 -0
- package/src/commands/publishPlugin/__tests__/commitToGit.test.js +1 -1
- package/src/commands/publishPlugin/__tests__/configurator.test.js +2 -2
- package/src/commands/publishPlugin/__tests__/zappApi.test.js +268 -0
- package/src/commands/publishPlugin/__tests__/zappifestPublish.test.js +35 -32
- package/src/commands/publishPlugin/commitToGit.js +1 -1
- package/src/commands/publishPlugin/configurator.js +1 -1
- package/src/commands/publishPlugin/generateManifest.js +1 -0
- package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +22 -12
- package/src/commands/publishPlugin/zappApi.js +285 -0
- package/src/commands/publishPlugin/zappifestPublish.js +72 -7
- package/src/commands/reloadConfig/__tests__/__snapshots__/reloadConfig.test.js.snap +58 -0
- package/src/commands/reloadConfig/__tests__/reloadConfig.test.js +86 -0
- package/src/commands/reloadConfig/index.js +6 -6
- package/src/download/__tests__/download.test.js +53 -0
- package/src/download/index.js +65 -1
- package/src/file/index.js +15 -9
- package/src/templates/__tests__/__snapshots__/templates.test.js.snap +1 -1
- package/src/templates/index.js +1 -0
- package/src/commands/publishPlugin/__tests__/__snapshots__/zappifestPublish.test.js.snap +0 -5
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const ZAPP_URL =
|
|
2
|
+
process.env.ZAPP_URL || "https://zapp.applicaster.com/api/v1/admin";
|
|
3
|
+
|
|
4
|
+
const USER_AGENT = "Zappifest/0.66.0";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_TARGETS_MAP = {
|
|
7
|
+
mobile: 1,
|
|
8
|
+
tv: 2,
|
|
9
|
+
roku: 3,
|
|
10
|
+
tablet: 4,
|
|
11
|
+
web: 5,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const DEFAULT_UI_FRAMEWORKS_MAP = {
|
|
15
|
+
native: 1,
|
|
16
|
+
quickbrick: 2,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let targetsCache = null;
|
|
20
|
+
let uiFrameworksCache = null;
|
|
21
|
+
|
|
22
|
+
async function getTargetsMap({
|
|
23
|
+
token = process.env.ZAPP_TOKEN,
|
|
24
|
+
baseUrl = ZAPP_URL,
|
|
25
|
+
} = {}) {
|
|
26
|
+
if (targetsCache) {
|
|
27
|
+
return targetsCache;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const url = `${baseUrl}/targets.json?access_token=${encodeURIComponent(token)}`;
|
|
32
|
+
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
headers: {
|
|
35
|
+
Accept: "application/json",
|
|
36
|
+
"User-Agent": USER_AGENT,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (res.ok) {
|
|
41
|
+
const data = await res.json();
|
|
42
|
+
const map = {};
|
|
43
|
+
|
|
44
|
+
data.forEach((t) => {
|
|
45
|
+
if (t.name && t.id) {
|
|
46
|
+
map[t.name] = t.id;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
targetsCache = map;
|
|
51
|
+
|
|
52
|
+
return map;
|
|
53
|
+
}
|
|
54
|
+
} catch (_e) {
|
|
55
|
+
// fallback to static defaults
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return DEFAULT_TARGETS_MAP;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function getUiFrameworksMap({
|
|
62
|
+
token = process.env.ZAPP_TOKEN,
|
|
63
|
+
baseUrl = ZAPP_URL,
|
|
64
|
+
} = {}) {
|
|
65
|
+
if (uiFrameworksCache) {
|
|
66
|
+
return uiFrameworksCache;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const url = `${baseUrl}/ui_frameworks.json?access_token=${encodeURIComponent(token)}`;
|
|
71
|
+
|
|
72
|
+
const res = await fetch(url, {
|
|
73
|
+
headers: {
|
|
74
|
+
Accept: "application/json",
|
|
75
|
+
"User-Agent": USER_AGENT,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (res.ok) {
|
|
80
|
+
const data = await res.json();
|
|
81
|
+
const map = {};
|
|
82
|
+
|
|
83
|
+
data.forEach((f) => {
|
|
84
|
+
if (f.name && f.id) {
|
|
85
|
+
map[f.name] = f.id;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
uiFrameworksCache = map;
|
|
90
|
+
|
|
91
|
+
return map;
|
|
92
|
+
}
|
|
93
|
+
} catch (_e) {
|
|
94
|
+
// fallback to static defaults
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return DEFAULT_UI_FRAMEWORKS_MAP;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function formatIdentifier(identifier) {
|
|
101
|
+
if (!identifier) return "";
|
|
102
|
+
|
|
103
|
+
return String(identifier).replace(/((_|-)(ios|android))/gi, "");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function findPlugin({
|
|
107
|
+
identifier,
|
|
108
|
+
_name,
|
|
109
|
+
token = process.env.ZAPP_TOKEN,
|
|
110
|
+
baseUrl = ZAPP_URL,
|
|
111
|
+
}) {
|
|
112
|
+
if (!token) {
|
|
113
|
+
throw new Error("ZAPP_TOKEN environment variable is not set");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const formattedSlug = encodeURIComponent(formatIdentifier(identifier));
|
|
117
|
+
let url = `${baseUrl}/plugins/${formattedSlug}.json?access_token=${encodeURIComponent(token)}`;
|
|
118
|
+
|
|
119
|
+
let res = await fetch(url, {
|
|
120
|
+
headers: {
|
|
121
|
+
Accept: "application/json",
|
|
122
|
+
"User-Agent": USER_AGENT,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (res.ok) {
|
|
127
|
+
const plugin = await res.json();
|
|
128
|
+
|
|
129
|
+
if (plugin && plugin.id) {
|
|
130
|
+
return plugin;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Fallback: if formatted slug returned 404, try raw identifier if different
|
|
135
|
+
const rawSlug = encodeURIComponent(identifier);
|
|
136
|
+
|
|
137
|
+
if (res.status === 404 && rawSlug !== formattedSlug) {
|
|
138
|
+
url = `${baseUrl}/plugins/${rawSlug}.json?access_token=${encodeURIComponent(token)}`;
|
|
139
|
+
|
|
140
|
+
res = await fetch(url, {
|
|
141
|
+
headers: {
|
|
142
|
+
Accept: "application/json",
|
|
143
|
+
"User-Agent": USER_AGENT,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (res.ok) {
|
|
148
|
+
const plugin = await res.json();
|
|
149
|
+
|
|
150
|
+
if (plugin && plugin.id) {
|
|
151
|
+
return plugin;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (res.status === 404) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Plugin with identifier '${identifier}' not found in Zapp.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const errText = await res.text();
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Failed to fetch plugin '${identifier}' from Zapp: HTTP ${res.status} - ${errText}`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function uploadPluginVersion({
|
|
169
|
+
pluginId,
|
|
170
|
+
manifest,
|
|
171
|
+
token = process.env.ZAPP_TOKEN,
|
|
172
|
+
baseUrl = ZAPP_URL,
|
|
173
|
+
}) {
|
|
174
|
+
if (!token) {
|
|
175
|
+
throw new Error("ZAPP_TOKEN environment variable is not set");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!pluginId) {
|
|
179
|
+
throw new Error("pluginId is required to upload plugin version");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const targetsMap = await getTargetsMap({ token, baseUrl });
|
|
183
|
+
const uiFrameworksMap = await getUiFrameworksMap({ token, baseUrl });
|
|
184
|
+
|
|
185
|
+
const url = `${baseUrl}/plugin_versions`;
|
|
186
|
+
|
|
187
|
+
const formData = new FormData();
|
|
188
|
+
formData.append("access_token", token);
|
|
189
|
+
formData.append("plugin_version[plugin_id]", String(pluginId));
|
|
190
|
+
|
|
191
|
+
formData.append(
|
|
192
|
+
"plugin_version[manifest]",
|
|
193
|
+
typeof manifest === "string" ? manifest : JSON.stringify(manifest)
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
if (manifest.author_email) {
|
|
197
|
+
formData.append("plugin_version[author_email]", manifest.author_email);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (manifest.manifest_version) {
|
|
201
|
+
formData.append("plugin_version[version]", manifest.manifest_version);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (manifest.platform) {
|
|
205
|
+
formData.append("plugin_version[platform]", manifest.platform);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (manifest.scheme) {
|
|
209
|
+
formData.append("plugin_version[scheme]", manifest.scheme);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
formData.append(
|
|
213
|
+
"plugin_version[latest_version]",
|
|
214
|
+
String(manifest.latest_version ?? true)
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
let rawTargets = manifest.targets;
|
|
218
|
+
|
|
219
|
+
if (!rawTargets || !rawTargets.length) {
|
|
220
|
+
const isTV =
|
|
221
|
+
manifest.platform &&
|
|
222
|
+
(manifest.platform.includes("tv") ||
|
|
223
|
+
manifest.platform.includes("lg") ||
|
|
224
|
+
manifest.platform.includes("samsung") ||
|
|
225
|
+
manifest.platform.includes("vidaa") ||
|
|
226
|
+
manifest.platform.includes("vizio"));
|
|
227
|
+
|
|
228
|
+
rawTargets = isTV ? ["tv"] : ["mobile"];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const targetIds = rawTargets
|
|
232
|
+
.map((name) => targetsMap[name])
|
|
233
|
+
.filter(Boolean);
|
|
234
|
+
|
|
235
|
+
if (targetIds.length) {
|
|
236
|
+
formData.append("plugin_version[targets]", JSON.stringify(targetIds));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let rawUiFrameworks = manifest.ui_frameworks;
|
|
240
|
+
|
|
241
|
+
if (!rawUiFrameworks || !rawUiFrameworks.length) {
|
|
242
|
+
rawUiFrameworks = ["quickbrick"];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const uiFrameworkIds = rawUiFrameworks
|
|
246
|
+
.map((name) => uiFrameworksMap[name])
|
|
247
|
+
.filter(Boolean);
|
|
248
|
+
|
|
249
|
+
if (uiFrameworkIds.length) {
|
|
250
|
+
formData.append(
|
|
251
|
+
"plugin_version[ui_frameworks]",
|
|
252
|
+
JSON.stringify(uiFrameworkIds)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const res = await fetch(url, {
|
|
257
|
+
method: "POST",
|
|
258
|
+
headers: {
|
|
259
|
+
Accept: "application/json",
|
|
260
|
+
"User-Agent": USER_AGENT,
|
|
261
|
+
},
|
|
262
|
+
body: formData,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
if (!res.ok) {
|
|
266
|
+
const errText = await res.text();
|
|
267
|
+
throw new Error(
|
|
268
|
+
`Failed to upload manifest for platform '${manifest.platform}': HTTP ${res.status} - ${errText}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return res;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
module.exports = {
|
|
276
|
+
ZAPP_URL,
|
|
277
|
+
USER_AGENT,
|
|
278
|
+
DEFAULT_TARGETS_MAP,
|
|
279
|
+
DEFAULT_UI_FRAMEWORKS_MAP,
|
|
280
|
+
formatIdentifier,
|
|
281
|
+
getTargetsMap,
|
|
282
|
+
getUiFrameworksMap,
|
|
283
|
+
findPlugin,
|
|
284
|
+
uploadPluginVersion,
|
|
285
|
+
};
|
|
@@ -4,8 +4,9 @@ const { inspect } = require("util");
|
|
|
4
4
|
|
|
5
5
|
const { runInShellAsync } = require("../../shell");
|
|
6
6
|
const logger = require("../../logger");
|
|
7
|
+
const { findPlugin, uploadPluginVersion } = require("./zappApi");
|
|
7
8
|
|
|
8
|
-
function
|
|
9
|
+
function pushZappifestLegacy({
|
|
9
10
|
pluginPath,
|
|
10
11
|
dryRun,
|
|
11
12
|
manifestOnly,
|
|
@@ -26,6 +27,54 @@ function pushZappifest({
|
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
async function nativePublish({ platforms, pluginPath, dryRun, manifestOnly }) {
|
|
31
|
+
const manifests = platforms.map((platform) => {
|
|
32
|
+
const manifestPath = resolve(pluginPath, `manifests/${platform}.json`);
|
|
33
|
+
|
|
34
|
+
return require(manifestPath);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (dryRun || manifestOnly) {
|
|
38
|
+
manifests.forEach((m) => {
|
|
39
|
+
logger.log(`[dry-run] Would upload manifest for platform: ${m.platform}`);
|
|
40
|
+
logger.log(`[dry-run] Manifest: ${inspect(m)}`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const firstManifest = manifests[0];
|
|
47
|
+
const { identifier, name } = firstManifest;
|
|
48
|
+
|
|
49
|
+
logger.log(`Looking up plugin '${identifier}' in Zapp...`);
|
|
50
|
+
const plugin = await findPlugin({ identifier, name });
|
|
51
|
+
logger.log(`Found plugin '${plugin.name}' (id: ${plugin.id}) in Zapp`);
|
|
52
|
+
|
|
53
|
+
const startTime = Date.now();
|
|
54
|
+
|
|
55
|
+
logger.log(
|
|
56
|
+
`Uploading ${manifests.length} platform manifest(s) directly to Zapp in parallel...`
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await Promise.all(
|
|
60
|
+
manifests.map(async (manifest) => {
|
|
61
|
+
await uploadPluginVersion({ pluginId: plugin.id, manifest });
|
|
62
|
+
|
|
63
|
+
logger.log(
|
|
64
|
+
`✓ Uploaded manifest for platform '${manifest.platform}' (${manifest.manifest_version})`
|
|
65
|
+
);
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const duration = Date.now() - startTime;
|
|
70
|
+
|
|
71
|
+
logger.log(
|
|
72
|
+
`All ${manifests.length} manifest(s) successfully uploaded to Zapp in ${duration}ms`
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
29
78
|
async function zappifestPublish(configuration) {
|
|
30
79
|
const { platforms, pluginPath, dryRun, manifestOnly, zappOwnerAccountId } =
|
|
31
80
|
configuration;
|
|
@@ -42,12 +91,28 @@ async function zappifestPublish(configuration) {
|
|
|
42
91
|
return true;
|
|
43
92
|
}
|
|
44
93
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
94
|
+
if (process.env.USE_LEGACY_ZAPPIFEST === "true") {
|
|
95
|
+
logger.log("USE_LEGACY_ZAPPIFEST enabled: Using legacy Ruby zappifest CLI");
|
|
96
|
+
|
|
97
|
+
return Promise.all(
|
|
98
|
+
R.map(
|
|
99
|
+
pushZappifestLegacy({
|
|
100
|
+
pluginPath,
|
|
101
|
+
dryRun,
|
|
102
|
+
manifestOnly,
|
|
103
|
+
zappOwnerAccountId,
|
|
104
|
+
}),
|
|
105
|
+
platforms
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return nativePublish({
|
|
111
|
+
platforms,
|
|
112
|
+
pluginPath,
|
|
113
|
+
dryRun,
|
|
114
|
+
manifestOnly,
|
|
115
|
+
});
|
|
51
116
|
}
|
|
52
117
|
|
|
53
118
|
module.exports = { zappifestPublish };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`reloadConfig runs the reload config task 1`] = `
|
|
4
|
+
[
|
|
5
|
+
[
|
|
6
|
+
"reload configuration",
|
|
7
|
+
"We're reloading the configuration for your app",
|
|
8
|
+
],
|
|
9
|
+
]
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
exports[`reloadConfig runs the reload config task 2`] = `[]`;
|
|
13
|
+
|
|
14
|
+
exports[`reloadConfig runs the reload config task 3`] = `[]`;
|
|
15
|
+
|
|
16
|
+
exports[`reloadConfig runs the reload config task 4`] = `[]`;
|
|
17
|
+
|
|
18
|
+
exports[`reloadConfig runs the reload config task 5`] = `
|
|
19
|
+
[
|
|
20
|
+
[
|
|
21
|
+
"checking prerequisites...",
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"Gathering configuration",
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
"Creating workspace",
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"Creating runtime URLs configuration file",
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
"Retrieving configuration files",
|
|
34
|
+
],
|
|
35
|
+
]
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`reloadConfig runs the reload config task 6`] = `
|
|
39
|
+
[
|
|
40
|
+
[
|
|
41
|
+
"All good - moving on",
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"configuration retrieved",
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
"Workspace created !",
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"Runtime configuration URLs file created",
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
"Configuration files retrieved !",
|
|
54
|
+
],
|
|
55
|
+
]
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
exports[`reloadConfig runs the reload config task 7`] = `[]`;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const { reloadConfig } = require("../index");
|
|
2
|
+
|
|
3
|
+
const appVersionId = "e7a17c6f-4113-41ac-9450-6281d22153a1";
|
|
4
|
+
|
|
5
|
+
const options = {
|
|
6
|
+
appVersionId,
|
|
7
|
+
openSdk: true,
|
|
8
|
+
config: "some_file",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
jest.mock("../../../logger", () => ({
|
|
12
|
+
welcome: jest.fn(),
|
|
13
|
+
log: jest.fn(),
|
|
14
|
+
error: jest.fn(),
|
|
15
|
+
warn: jest.fn(),
|
|
16
|
+
startStep: jest.fn(),
|
|
17
|
+
endStep: jest.fn(),
|
|
18
|
+
success: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock("../../prepareWorkspace/prerequisitesChecker.js", () => ({
|
|
22
|
+
prerequisitesChecker: jest.fn(() => true),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const mockConfig = { appVersionId, buildParams: {} };
|
|
26
|
+
|
|
27
|
+
jest.mock("../../prepareWorkspace/configurator.js", () => ({
|
|
28
|
+
configurator: jest.fn(() => mockConfig),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock("../../prepareWorkspace/workspaceCreator.js", () => ({
|
|
32
|
+
workspaceCreator: jest.fn(),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
jest.mock("../../prepareWorkspace/configFilesRetriever.js", () => ({
|
|
36
|
+
configFilesRetriever: jest.fn(),
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
jest.mock("../../prepareWorkspace/runtimeConfigurationUrlsCreator.js", () => ({
|
|
40
|
+
runtimeConfigurationUrlsCreator: jest.fn(),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
prerequisitesChecker,
|
|
45
|
+
} = require("../../prepareWorkspace/prerequisitesChecker");
|
|
46
|
+
|
|
47
|
+
const { configurator } = require("../../prepareWorkspace/configurator");
|
|
48
|
+
const { workspaceCreator } = require("../../prepareWorkspace/workspaceCreator");
|
|
49
|
+
|
|
50
|
+
const {
|
|
51
|
+
configFilesRetriever,
|
|
52
|
+
} = require("../../prepareWorkspace/configFilesRetriever");
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
runtimeConfigurationUrlsCreator,
|
|
56
|
+
} = require("../../prepareWorkspace/runtimeConfigurationUrlsCreator");
|
|
57
|
+
|
|
58
|
+
const logger = require("../../../logger");
|
|
59
|
+
|
|
60
|
+
describe("reloadConfig", () => {
|
|
61
|
+
it("runs the reload config task", async () => {
|
|
62
|
+
await reloadConfig(appVersionId, options);
|
|
63
|
+
|
|
64
|
+
expect(logger.welcome.mock.calls).toMatchSnapshot();
|
|
65
|
+
expect(logger.log.mock.calls).toMatchSnapshot();
|
|
66
|
+
expect(logger.error.mock.calls).toMatchSnapshot();
|
|
67
|
+
expect(logger.warn.mock.calls).toMatchSnapshot();
|
|
68
|
+
expect(logger.startStep.mock.calls).toMatchSnapshot();
|
|
69
|
+
expect(logger.endStep.mock.calls).toMatchSnapshot();
|
|
70
|
+
expect(logger.success.mock.calls).toMatchSnapshot();
|
|
71
|
+
|
|
72
|
+
expect(prerequisitesChecker).toHaveBeenCalledWith({
|
|
73
|
+
cliArgs: [appVersionId],
|
|
74
|
+
cliOptions: options,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(configurator).toHaveBeenCalledWith({
|
|
78
|
+
cliArgs: [appVersionId],
|
|
79
|
+
cliOptions: options,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(workspaceCreator).toHaveBeenCalledWith(mockConfig);
|
|
83
|
+
expect(runtimeConfigurationUrlsCreator).toHaveBeenCalledWith(mockConfig);
|
|
84
|
+
expect(configFilesRetriever).toHaveBeenCalledWith(mockConfig);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -27,18 +27,18 @@ const reloadConfigTask = {
|
|
|
27
27
|
error: "Could not create workspace",
|
|
28
28
|
completion: "Workspace created !",
|
|
29
29
|
},
|
|
30
|
-
{
|
|
31
|
-
start: "Retrieving configuration files",
|
|
32
|
-
run: configFilesRetriever,
|
|
33
|
-
error: "Could not retrieve configuration files",
|
|
34
|
-
completion: "Configuration files retrieved !",
|
|
35
|
-
},
|
|
36
30
|
{
|
|
37
31
|
start: "Creating runtime URLs configuration file",
|
|
38
32
|
run: runtimeConfigurationUrlsCreator,
|
|
39
33
|
error: "Could not create runtime_configuration_urls.json",
|
|
40
34
|
completion: "Runtime configuration URLs file created",
|
|
41
35
|
},
|
|
36
|
+
{
|
|
37
|
+
start: "Retrieving configuration files",
|
|
38
|
+
run: configFilesRetriever,
|
|
39
|
+
error: "Could not retrieve configuration files",
|
|
40
|
+
completion: "Configuration files retrieved !",
|
|
41
|
+
},
|
|
42
42
|
],
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { saveRemoteJsonToFile, saveAssets, saveFontFiles } = require("../index");
|
|
2
2
|
const nock = require("nock");
|
|
3
3
|
const R = require("ramda");
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const logger = require("../../logger");
|
|
5
6
|
|
|
6
7
|
const getFileName = R.compose(R.last, R.split("/"));
|
|
@@ -109,9 +110,37 @@ describe("saveAssets", () => {
|
|
|
109
110
|
|
|
110
111
|
afterEach(() => {
|
|
111
112
|
clearAllMocks();
|
|
113
|
+
|
|
114
|
+
["existsSync", "openSync", "closeSync", "readSync", "readFileSync"].forEach(
|
|
115
|
+
(method) => {
|
|
116
|
+
if (fs[method] && fs[method].mockRestore) {
|
|
117
|
+
fs[method].mockRestore();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
);
|
|
112
121
|
});
|
|
113
122
|
|
|
123
|
+
function mockDownloadedFile({ isZip, content } = {}) {
|
|
124
|
+
jest.spyOn(fs, "existsSync").mockReturnValue(true);
|
|
125
|
+
jest.spyOn(fs, "openSync").mockReturnValue(1);
|
|
126
|
+
jest.spyOn(fs, "closeSync").mockImplementation(() => ({}));
|
|
127
|
+
|
|
128
|
+
jest.spyOn(fs, "readSync").mockImplementation((fd, buffer) => {
|
|
129
|
+
const header = isZip
|
|
130
|
+
? Buffer.from([0x50, 0x4b, 0x03, 0x04])
|
|
131
|
+
: Buffer.from("<?xm");
|
|
132
|
+
|
|
133
|
+
header.copy(buffer);
|
|
134
|
+
|
|
135
|
+
return 4;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
jest.spyOn(fs, "readFileSync").mockReturnValue(content || "");
|
|
139
|
+
}
|
|
140
|
+
|
|
114
141
|
it("downloads the files with cURL, and unzips the assets", () => {
|
|
142
|
+
mockDownloadedFile({ isZip: true });
|
|
143
|
+
|
|
115
144
|
saveAssets({ destinationPath, platform }, assetsUrl);
|
|
116
145
|
|
|
117
146
|
expect(loggerSpy).toHaveBeenCalledWith(`saving assets from ${assetsUrl}`);
|
|
@@ -122,6 +151,30 @@ describe("saveAssets", () => {
|
|
|
122
151
|
filePath
|
|
123
152
|
);
|
|
124
153
|
});
|
|
154
|
+
|
|
155
|
+
it("throws a clear error and skips unzip when the bundle is not a zip", () => {
|
|
156
|
+
mockDownloadedFile({
|
|
157
|
+
isZip: false,
|
|
158
|
+
content:
|
|
159
|
+
'<?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code></Error>',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(() => saveAssets({ destinationPath, platform }, assetsUrl)).toThrow(
|
|
163
|
+
/AccessDenied/
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(shell.unzip).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("throws a clear error when the bundle was not downloaded", () => {
|
|
170
|
+
jest.spyOn(fs, "existsSync").mockReturnValue(false);
|
|
171
|
+
|
|
172
|
+
expect(() => saveAssets({ destinationPath, platform }, assetsUrl)).toThrow(
|
|
173
|
+
/was not downloaded/
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect(shell.unzip).not.toHaveBeenCalled();
|
|
177
|
+
});
|
|
125
178
|
});
|
|
126
179
|
|
|
127
180
|
describe("saveFontFiles", () => {
|
package/src/download/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const R = require("ramda");
|
|
2
|
+
const fs = require("fs");
|
|
2
3
|
const axios = require("axios");
|
|
3
4
|
const { resolve } = require("path");
|
|
4
5
|
const { curlFile, curlMultipleFiles, unzip } = require("../shell");
|
|
@@ -12,6 +13,64 @@ const getFileName = R.ifElse(
|
|
|
12
13
|
R.prop("name")
|
|
13
14
|
);
|
|
14
15
|
|
|
16
|
+
// Local file signature for a zip archive: "PK\x03\x04"
|
|
17
|
+
const ZIP_SIGNATURE = "504b0304";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* checks whether a file on disk is a real zip archive by reading its magic bytes.
|
|
21
|
+
* @param {String} file path to the file to inspect
|
|
22
|
+
* @returns {Boolean} true if the file starts with the zip local file signature
|
|
23
|
+
*/
|
|
24
|
+
function isZipFile(file) {
|
|
25
|
+
const fd = fs.openSync(file, "r");
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const header = Buffer.alloc(4);
|
|
29
|
+
const bytesRead = fs.readSync(fd, header, 0, 4, 0);
|
|
30
|
+
|
|
31
|
+
return bytesRead === 4 && header.toString("hex") === ZIP_SIGNATURE;
|
|
32
|
+
} finally {
|
|
33
|
+
fs.closeSync(fd);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* verifies that the downloaded assets bundle is a real zip archive.
|
|
39
|
+
* The assets CDN responds with a small XML/HTML body (e.g. S3 "AccessDenied")
|
|
40
|
+
* when the bundle is missing or not yet published. Because the download uses
|
|
41
|
+
* `curl -O` without `-f`, that error body is saved as assets.zip and the process
|
|
42
|
+
* continues, only to crash later in webpack with a confusing parse error. This
|
|
43
|
+
* check fails fast in the prepare step with an actionable message instead.
|
|
44
|
+
* @param {String} file path to the downloaded assets bundle
|
|
45
|
+
* @param {String} assetsUrl original url, surfaced in the error message
|
|
46
|
+
*/
|
|
47
|
+
function assertValidAssetsBundle(file, assetsUrl) {
|
|
48
|
+
if (!fs.existsSync(file)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Assets bundle was not downloaded from ${assetsUrl}. ` +
|
|
51
|
+
"Verify the app has a published build with generated assets for this platform."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isZipFile(file)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const preview = fs
|
|
60
|
+
.readFileSync(file, "utf8")
|
|
61
|
+
.replace(/\s+/g, " ")
|
|
62
|
+
.trim()
|
|
63
|
+
.slice(0, 300);
|
|
64
|
+
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Invalid assets bundle downloaded from ${assetsUrl} - expected a zip archive ` +
|
|
67
|
+
`but received non-zip content:\n "${preview}"\n` +
|
|
68
|
+
"This usually means the assets bundle has not been generated/published for " +
|
|
69
|
+
'this platform, or the URL is not accessible (e.g. S3 "AccessDenied"). ' +
|
|
70
|
+
"Publish a build with assets for this platform before preparing the workspace."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
15
74
|
/**
|
|
16
75
|
* saves a remote json file in the app's configuration folder.
|
|
17
76
|
* curried function of the shape saveRemoteJsonToFile(configuration)(fileUrl)
|
|
@@ -65,7 +124,12 @@ function saveAssets({ destinationPath, platform }, assetsUrl) {
|
|
|
65
124
|
});
|
|
66
125
|
|
|
67
126
|
curlFile(assetsUrl, filePath);
|
|
68
|
-
|
|
127
|
+
|
|
128
|
+
const downloadedFile = resolve(filePath, fileName);
|
|
129
|
+
|
|
130
|
+
assertValidAssetsBundle(downloadedFile, assetsUrl);
|
|
131
|
+
|
|
132
|
+
unzip(downloadedFile, filePath);
|
|
69
133
|
}
|
|
70
134
|
|
|
71
135
|
/**
|