@applicaster/zapplicaster-cli 17.0.0-alpha.5804334713 → 17.0.0-alpha.9147048829

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.
@@ -1,190 +1,90 @@
1
- const getConfig = (config = {}) => ({
2
- platforms: ["android", "ios"],
3
- pluginPath: "plugins/my-plugn",
4
- dryRun: false,
5
- zappOwnerAccountId: "A1234",
6
- ...config,
7
- });
8
-
9
- jest.mock("path", () => ({
10
- resolve: jest.fn((path, platformpath) => {
11
- if (path.includes("resolve_error")) {
12
- throw new Error("cannot resolve manifest");
13
- }
14
-
15
- if (path.includes("zappifest_error")) {
16
- /* eslint-disable-next-line no-path-concat */
17
- return __dirname + "/zappifest_error.json";
18
- }
1
+ const { resolve } = require("path");
19
2
 
20
- /* eslint-disable-next-line no-path-concat */
21
- return __dirname + "/" + platformpath;
22
- }),
23
- }));
24
-
25
- jest.mock("../../../shell", () => ({
26
- runInShellAsync: jest.fn((command) => {
27
- return command.includes("zappifest_error")
28
- ? Promise.reject(new Error("zappifest failed"))
29
- : Promise.resolve(true);
30
- }),
3
+ jest.mock("@applicaster/zappifest-nano", () => ({
4
+ publish: jest.fn().mockResolvedValue({ uploaded: 2 }),
31
5
  }));
32
6
 
33
7
  jest.mock("../../../logger", () => ({
34
8
  log: jest.fn(),
9
+ warn: jest.fn(),
35
10
  }));
36
11
 
37
- jest.mock("../zappApi", () => ({
38
- findPlugin: jest.fn().mockImplementation(async ({ identifier }) => {
39
- if (identifier === "cell_info_mobile") {
40
- return { id: 11, name: "Cell Info" };
41
- }
42
-
43
- if (identifier === "cell_info_tv") {
44
- return { id: 22, name: "Cell Info TV" };
45
- }
46
-
47
- return { id: 99, name: "Test Plugin" };
48
- }),
49
- uploadPluginVersion: jest.fn().mockResolvedValue({ ok: true }),
50
- }));
51
-
52
- const {
53
- zappifestPublish,
54
- groupManifestsByIdentifier,
55
- } = require("../zappifestPublish");
56
-
57
- const { runInShellAsync } = require("../../../shell");
58
- const { findPlugin, uploadPluginVersion } = require("../zappApi");
12
+ const { publish } = require("@applicaster/zappifest-nano");
59
13
  const logger = require("../../../logger");
14
+ const { zappifestPublish } = require("../zappifestPublish");
60
15
 
61
- function clearMocks() {
62
- logger.log.mockClear();
63
- runInShellAsync.mockClear();
64
- findPlugin.mockClear();
65
- uploadPluginVersion.mockClear();
66
- delete process.env.USE_LEGACY_ZAPPIFEST;
67
- }
16
+ const configuration = {
17
+ platforms: ["android", "ios"],
18
+ pluginPath: resolve(__dirname),
19
+ };
68
20
 
69
21
  describe("publish zappifests", () => {
70
- beforeEach(clearMocks);
22
+ beforeEach(() => {
23
+ publish.mockReset().mockResolvedValue({ uploaded: 2 });
24
+ jest.clearAllMocks();
25
+ });
71
26
 
72
- it("publishes manifests natively via zappApi by default", async () => {
73
- const configuration = getConfig();
27
+ it("delegates the selected manifests in one batch without requiring an account", async () => {
28
+ expect(await zappifestPublish(configuration)).toBe(true);
74
29
 
75
- const result = await zappifestPublish(configuration);
76
- expect(result).toBe(true);
30
+ expect(publish).toHaveBeenCalledTimes(1);
77
31
 
78
- expect(findPlugin).toHaveBeenCalledWith({
79
- identifier: "my_plugin",
80
- name: "my plugin name",
32
+ expect(publish).toHaveBeenCalledWith({
33
+ manifestPaths: [
34
+ resolve(__dirname, "manifests/android.json"),
35
+ resolve(__dirname, "manifests/ios.json"),
36
+ ],
37
+ dryRun: false,
38
+ log: logger.log,
39
+ onWarning: logger.warn,
81
40
  });
82
-
83
- expect(uploadPluginVersion).toHaveBeenCalledTimes(2);
84
- expect(runInShellAsync).not.toHaveBeenCalled();
85
41
  });
86
42
 
87
- it("looks up each distinct Zapp identifier separately (e.g. cell-info mobile vs TV)", async () => {
88
- const configuration = getConfig({
89
- platforms: [
90
- "ios_for_quickbrick",
91
- "android_for_quickbrick",
92
- "android_tv_for_quickbrick",
93
- "tvos_for_quickbrick",
94
- ],
43
+ it("does not pass legacy owner metadata as an account-validation request", async () => {
44
+ await zappifestPublish({
45
+ ...configuration,
46
+ zappOwnerAccountId: "A1234",
95
47
  });
96
48
 
97
- await zappifestPublish(configuration);
98
-
99
- expect(findPlugin).toHaveBeenCalledTimes(2);
100
-
101
- expect(findPlugin).toHaveBeenCalledWith({
102
- identifier: "cell_info_mobile",
103
- name: "Cell Info",
104
- });
49
+ expect(publish.mock.calls[0][0]).not.toHaveProperty("account");
50
+ });
105
51
 
106
- expect(findPlugin).toHaveBeenCalledWith({
107
- identifier: "cell_info_tv",
108
- name: "Cell Info TV",
52
+ it("publishes only the configured platform, not the entire manifest directory", async () => {
53
+ await zappifestPublish({
54
+ ...configuration,
55
+ platforms: ["ios"],
109
56
  });
110
57
 
111
- expect(uploadPluginVersion).toHaveBeenCalledTimes(4);
112
-
113
- const uploadsByPluginId = uploadPluginVersion.mock.calls.reduce(
114
- (acc, [{ pluginId, manifest }]) => {
115
- acc[pluginId] = acc[pluginId] || [];
116
- acc[pluginId].push(manifest.platform);
117
-
118
- return acc;
119
- },
120
- {}
121
- );
122
-
123
- expect(uploadsByPluginId[11].sort()).toEqual([
124
- "android_for_quickbrick",
125
- "ios_for_quickbrick",
126
- ]);
127
-
128
- expect(uploadsByPluginId[22].sort()).toEqual([
129
- "android_tv_for_quickbrick",
130
- "tvos_for_quickbrick",
131
- ]);
132
- });
133
-
134
- it("groups manifests by identifier", () => {
135
- const grouped = groupManifestsByIdentifier([
136
- { identifier: "a", platform: "ios" },
137
- { identifier: "b", platform: "tvos" },
138
- { identifier: "a", platform: "android" },
58
+ expect(publish.mock.calls[0][0].manifestPaths).toEqual([
59
+ resolve(__dirname, "manifests/ios.json"),
139
60
  ]);
140
-
141
- expect(Object.keys(grouped).sort()).toEqual(["a", "b"]);
142
- expect(grouped.a.map((m) => m.platform).sort()).toEqual(["android", "ios"]);
143
- expect(grouped.b.map((m) => m.platform)).toEqual(["tvos"]);
144
61
  });
145
62
 
146
- it("falls back to legacy Ruby zappifest when USE_LEGACY_ZAPPIFEST is true", async () => {
147
- process.env.USE_LEGACY_ZAPPIFEST = "true";
148
- const configuration = getConfig();
149
-
150
- const expectedResult = new Array(configuration.platforms.length)
151
- .fill()
152
- .map(() => true);
153
-
154
- expect(await zappifestPublish(configuration)).toEqual(expectedResult);
155
-
156
- expect(runInShellAsync).toHaveBeenCalledTimes(
157
- configuration.platforms.length
158
- );
159
-
160
- configuration.platforms.forEach((val, index) => {
161
- expect(runInShellAsync).toHaveBeenNthCalledWith(
162
- index + 1,
163
- `zappifest publish --manifest ${__dirname}/manifests/${val}.json --account A1234`
63
+ it.each([{ dryRun: true }, { manifestOnly: true }])(
64
+ "does not upload with %j",
65
+ async (options) => {
66
+ expect(await zappifestPublish({ ...configuration, ...options })).toBe(
67
+ true
164
68
  );
165
- });
166
69
 
167
- expect(findPlugin).not.toHaveBeenCalled();
168
- expect(uploadPluginVersion).not.toHaveBeenCalled();
169
- });
70
+ expect(publish.mock.calls[0][0].dryRun).toBe(true);
71
+ }
72
+ );
170
73
 
171
- it("only logs in the console when running with dry run flag", async () => {
172
- const configuration = getConfig({ dryRun: true });
74
+ it.each([undefined, []])("skips absent platforms: %j", async (platforms) => {
75
+ expect(await zappifestPublish({ ...configuration, platforms })).toBe(true);
173
76
 
174
- expect(await zappifestPublish(configuration)).toBe(true);
175
- expect(runInShellAsync).not.toHaveBeenCalled();
176
- expect(uploadPluginVersion).not.toHaveBeenCalled();
77
+ expect(publish).not.toHaveBeenCalled();
177
78
 
178
79
  expect(logger.log).toHaveBeenCalledWith(
179
- "Running with --dry-run or --manifest-only option - not actually pushing to zapp"
80
+ "Manifest does not exist, Skipping publishing"
180
81
  );
181
82
  });
182
83
 
183
- it("it throws if a manifest cannot be found", async () => {
184
- const configuration = getConfig({ pluginPath: "resolve_error" });
84
+ it("propagates validation, file, and upload failures to the task runner", async () => {
85
+ const error = new Error("Cannot read manifest");
86
+ publish.mockRejectedValueOnce(error);
185
87
 
186
- await expect(zappifestPublish(configuration)).rejects.toThrow(
187
- "cannot resolve manifest"
188
- );
88
+ await expect(zappifestPublish(configuration)).rejects.toBe(error);
189
89
  });
190
90
  });
@@ -50,13 +50,6 @@ function resolvePluginPath(pluginPath) {
50
50
  );
51
51
  }
52
52
 
53
- if (
54
- manifestExists(pluginPath) &&
55
- !pluginPackageJson.applicaster.zappOwnerAccountId
56
- ) {
57
- throw new Error("your plugin's package.json is missing zappOwnerAccountId");
58
- }
59
-
60
53
  return [resolvedPluginPath, pluginPackageJson];
61
54
  }
62
55
 
@@ -1,168 +1,27 @@
1
- const R = require("ramda");
2
1
  const { resolve } = require("path");
3
- const { inspect } = require("util");
2
+ const { publish } = require("@applicaster/zappifest-nano");
4
3
 
5
- const { runInShellAsync } = require("../../shell");
6
4
  const logger = require("../../logger");
7
- const { findPlugin, uploadPluginVersion } = require("./zappApi");
8
-
9
- function pushZappifestLegacy({
10
- pluginPath,
11
- dryRun,
12
- manifestOnly,
13
- zappOwnerAccountId,
14
- }) {
15
- return async function (platform) {
16
- const manifestPath = resolve(pluginPath, `manifests/${platform}.json`);
17
- const publishCommand = `zappifest publish --manifest ${manifestPath} --account ${zappOwnerAccountId}`;
18
-
19
- if (dryRun || manifestOnly) {
20
- logger.log(`running ${publishCommand}`);
21
- logger.log(`with manifest: ${inspect(require(manifestPath))}`);
22
-
23
- return true;
24
- }
25
-
26
- return await runInShellAsync(publishCommand);
27
- };
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
5
 
128
6
  async function zappifestPublish(configuration) {
129
- const { platforms, pluginPath, dryRun, manifestOnly, zappOwnerAccountId } =
130
- configuration;
131
-
132
- if (dryRun || manifestOnly) {
133
- logger.log(
134
- "Running with --dry-run or --manifest-only option - not actually pushing to zapp"
135
- );
136
- }
7
+ const { platforms, pluginPath, dryRun, manifestOnly } = configuration;
137
8
 
138
- if (!platforms || !zappOwnerAccountId) {
9
+ if (!platforms || platforms.length === 0) {
139
10
  logger.log("Manifest does not exist, Skipping publishing");
140
11
 
141
12
  return true;
142
13
  }
143
14
 
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,
15
+ await publish({
16
+ manifestPaths: platforms.map((platform) =>
17
+ resolve(pluginPath, `manifests/${platform}.json`)
18
+ ),
19
+ dryRun: Boolean(dryRun || manifestOnly),
20
+ log: logger.log,
21
+ onWarning: logger.warn,
165
22
  });
23
+
24
+ return true;
166
25
  }
167
26
 
168
- module.exports = { zappifestPublish, groupManifestsByIdentifier };
27
+ module.exports = { zappifestPublish };