@applicaster/zapplicaster-cli 16.0.0-rc.98 → 17.0.0-rc.1
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__/buildPluginsCreator.test.js +99 -0
- package/src/commands/prepareWorkspace/buildPluginsCreator.js +61 -0
- package/src/commands/prepareWorkspace/configFilesRetriever.js +3 -0
- package/src/commands/publishPlugin/README.md +140 -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__/manifests/android.json +3 -1
- package/src/commands/publishPlugin/__tests__/manifests/android_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/android_tv_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/ios.json +3 -1
- package/src/commands/publishPlugin/__tests__/manifests/ios_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/tvos_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/zappApi.test.js +271 -0
- package/src/commands/publishPlugin/__tests__/zappifestPublish.test.js +109 -33
- package/src/commands/publishPlugin/commitToGit.js +1 -1
- package/src/commands/publishPlugin/configurator.js +1 -1
- package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +22 -12
- package/src/commands/publishPlugin/zappApi.js +283 -0
- package/src/commands/publishPlugin/zappifestPublish.js +123 -8
- package/src/commands/publishPlugin/__tests__/__snapshots__/zappifestPublish.test.js.snap +0 -5
|
@@ -0,0 +1,283 @@
|
|
|
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.map((name) => targetsMap[name]).filter(Boolean);
|
|
232
|
+
|
|
233
|
+
if (targetIds.length) {
|
|
234
|
+
formData.append("plugin_version[targets]", JSON.stringify(targetIds));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let rawUiFrameworks = manifest.ui_frameworks;
|
|
238
|
+
|
|
239
|
+
if (!rawUiFrameworks || !rawUiFrameworks.length) {
|
|
240
|
+
rawUiFrameworks = ["quickbrick"];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const uiFrameworkIds = rawUiFrameworks
|
|
244
|
+
.map((name) => uiFrameworksMap[name])
|
|
245
|
+
.filter(Boolean);
|
|
246
|
+
|
|
247
|
+
if (uiFrameworkIds.length) {
|
|
248
|
+
formData.append(
|
|
249
|
+
"plugin_version[ui_frameworks]",
|
|
250
|
+
JSON.stringify(uiFrameworkIds)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const res = await fetch(url, {
|
|
255
|
+
method: "POST",
|
|
256
|
+
headers: {
|
|
257
|
+
Accept: "application/json",
|
|
258
|
+
"User-Agent": USER_AGENT,
|
|
259
|
+
},
|
|
260
|
+
body: formData,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (!res.ok) {
|
|
264
|
+
const errText = await res.text();
|
|
265
|
+
throw new Error(
|
|
266
|
+
`Failed to upload manifest for platform '${manifest.platform}': HTTP ${res.status} - ${errText}`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
module.exports = {
|
|
274
|
+
ZAPP_URL,
|
|
275
|
+
USER_AGENT,
|
|
276
|
+
DEFAULT_TARGETS_MAP,
|
|
277
|
+
DEFAULT_UI_FRAMEWORKS_MAP,
|
|
278
|
+
formatIdentifier,
|
|
279
|
+
getTargetsMap,
|
|
280
|
+
getUiFrameworksMap,
|
|
281
|
+
findPlugin,
|
|
282
|
+
uploadPluginVersion,
|
|
283
|
+
};
|
|
@@ -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,104 @@ function pushZappifest({
|
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Group platform manifests by Zapp plugin identifier.
|
|
32
|
+
* Some plugins (e.g. cell-info) ship mobile + TV under different identifiers
|
|
33
|
+
* in one npm package; each identifier must resolve to its own Zapp plugin id.
|
|
34
|
+
*/
|
|
35
|
+
function groupManifestsByIdentifier(manifests) {
|
|
36
|
+
return manifests.reduce((groups, manifest) => {
|
|
37
|
+
const key = manifest.identifier || "__missing_identifier__";
|
|
38
|
+
|
|
39
|
+
if (!groups[key]) {
|
|
40
|
+
groups[key] = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
groups[key].push(manifest);
|
|
44
|
+
|
|
45
|
+
return groups;
|
|
46
|
+
}, {});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function uploadManifestGroup({ identifier, manifests }) {
|
|
50
|
+
if (identifier === "__missing_identifier__") {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Cannot publish manifests without an identifier (platforms: ${manifests
|
|
53
|
+
.map((m) => m.platform)
|
|
54
|
+
.join(", ")})`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { name } = manifests[0];
|
|
59
|
+
|
|
60
|
+
logger.log(`Looking up plugin '${identifier}' in Zapp...`);
|
|
61
|
+
const plugin = await findPlugin({ identifier, name });
|
|
62
|
+
logger.log(`Found plugin '${plugin.name}' (id: ${plugin.id}) in Zapp`);
|
|
63
|
+
|
|
64
|
+
await Promise.all(
|
|
65
|
+
manifests.map(async (manifest) => {
|
|
66
|
+
await uploadPluginVersion({ pluginId: plugin.id, manifest });
|
|
67
|
+
|
|
68
|
+
logger.log(
|
|
69
|
+
`✓ Uploaded manifest for platform '${manifest.platform}' (${manifest.manifest_version}) → plugin '${identifier}' (id: ${plugin.id})`
|
|
70
|
+
);
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return manifests.length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function nativePublish({ platforms, pluginPath, dryRun, manifestOnly }) {
|
|
78
|
+
const manifests = platforms.map((platform) => {
|
|
79
|
+
const manifestPath = resolve(pluginPath, `manifests/${platform}.json`);
|
|
80
|
+
|
|
81
|
+
return require(manifestPath);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const grouped = groupManifestsByIdentifier(manifests);
|
|
85
|
+
const identifierCount = Object.keys(grouped).length;
|
|
86
|
+
|
|
87
|
+
if (dryRun || manifestOnly) {
|
|
88
|
+
Object.entries(grouped).forEach(([identifier, group]) => {
|
|
89
|
+
const platformsInGroup = group.map((m) => m.platform).join(", ");
|
|
90
|
+
|
|
91
|
+
logger.log(
|
|
92
|
+
`[dry-run] Would look up Zapp plugin '${identifier}' and upload ${group.length} platform(s): ${platformsInGroup}`
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
group.forEach((m) => {
|
|
96
|
+
logger.log(`[dry-run] Manifest: ${inspect(m)}`);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const startTime = Date.now();
|
|
104
|
+
|
|
105
|
+
logger.log(
|
|
106
|
+
`Uploading ${manifests.length} platform manifest(s) across ${identifierCount} Zapp plugin identifier(s)...`
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Resolve + upload each identifier group independently. Groups run
|
|
110
|
+
// sequentially so a lookup failure for one identifier does not leave
|
|
111
|
+
// ambiguous partial state across unrelated Zapp plugins; platforms
|
|
112
|
+
// within a group still upload in parallel.
|
|
113
|
+
let uploaded = 0;
|
|
114
|
+
|
|
115
|
+
for (const [identifier, group] of Object.entries(grouped)) {
|
|
116
|
+
uploaded += await uploadManifestGroup({ identifier, manifests: group });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const duration = Date.now() - startTime;
|
|
120
|
+
|
|
121
|
+
logger.log(
|
|
122
|
+
`All ${uploaded} manifest(s) successfully uploaded to Zapp in ${duration}ms`
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
29
128
|
async function zappifestPublish(configuration) {
|
|
30
129
|
const { platforms, pluginPath, dryRun, manifestOnly, zappOwnerAccountId } =
|
|
31
130
|
configuration;
|
|
@@ -42,12 +141,28 @@ async function zappifestPublish(configuration) {
|
|
|
42
141
|
return true;
|
|
43
142
|
}
|
|
44
143
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
144
|
+
if (process.env.USE_LEGACY_ZAPPIFEST === "true") {
|
|
145
|
+
logger.log("USE_LEGACY_ZAPPIFEST enabled: Using legacy Ruby zappifest CLI");
|
|
146
|
+
|
|
147
|
+
return Promise.all(
|
|
148
|
+
R.map(
|
|
149
|
+
pushZappifestLegacy({
|
|
150
|
+
pluginPath,
|
|
151
|
+
dryRun,
|
|
152
|
+
manifestOnly,
|
|
153
|
+
zappOwnerAccountId,
|
|
154
|
+
}),
|
|
155
|
+
platforms
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return nativePublish({
|
|
161
|
+
platforms,
|
|
162
|
+
pluginPath,
|
|
163
|
+
dryRun,
|
|
164
|
+
manifestOnly,
|
|
165
|
+
});
|
|
51
166
|
}
|
|
52
167
|
|
|
53
|
-
module.exports = { zappifestPublish };
|
|
168
|
+
module.exports = { zappifestPublish, groupManifestsByIdentifier };
|