@applicaster/zapplicaster-cli 16.0.0-rc.99 → 17.0.0-rc.2
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,271 @@
|
|
|
1
|
+
const {
|
|
2
|
+
formatIdentifier,
|
|
3
|
+
findPlugin,
|
|
4
|
+
uploadPluginVersion,
|
|
5
|
+
ZAPP_URL,
|
|
6
|
+
USER_AGENT,
|
|
7
|
+
} = require("../zappApi");
|
|
8
|
+
|
|
9
|
+
describe("zappApi", () => {
|
|
10
|
+
const originalFetch = global.fetch;
|
|
11
|
+
const originalToken = process.env.ZAPP_TOKEN;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
process.env.ZAPP_TOKEN = "dummy-token";
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
global.fetch = originalFetch;
|
|
19
|
+
process.env.ZAPP_TOKEN = originalToken;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("formatIdentifier", () => {
|
|
23
|
+
it("strips _ios, -ios, _android, -android suffixes", () => {
|
|
24
|
+
expect(formatIdentifier("my_plugin_ios")).toBe("my_plugin");
|
|
25
|
+
expect(formatIdentifier("my_plugin-ios")).toBe("my_plugin");
|
|
26
|
+
expect(formatIdentifier("my_plugin_android")).toBe("my_plugin");
|
|
27
|
+
expect(formatIdentifier("my_plugin-android")).toBe("my_plugin");
|
|
28
|
+
expect(formatIdentifier("my_plugin")).toBe("my_plugin");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("handles empty or null identifier gracefully", () => {
|
|
32
|
+
expect(formatIdentifier("")).toBe("");
|
|
33
|
+
expect(formatIdentifier(null)).toBe("");
|
|
34
|
+
expect(formatIdentifier(undefined)).toBe("");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("findPlugin", () => {
|
|
39
|
+
it("finds plugin by slug on direct lookup", async () => {
|
|
40
|
+
const mockPlugin = {
|
|
41
|
+
id: 42,
|
|
42
|
+
name: "My Plugin",
|
|
43
|
+
external_identifier: "my-plugin",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
47
|
+
ok: true,
|
|
48
|
+
status: 200,
|
|
49
|
+
json: async () => mockPlugin,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = await findPlugin({
|
|
53
|
+
identifier: "my-plugin_ios",
|
|
54
|
+
name: "My Plugin",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(result).toEqual(mockPlugin);
|
|
58
|
+
|
|
59
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
60
|
+
`${ZAPP_URL}/plugins/my-plugin.json?access_token=dummy-token`,
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
headers: expect.objectContaining({ Accept: "application/json" }),
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("falls back to raw identifier if formatted slug returns 404", async () => {
|
|
68
|
+
const mockPlugin = {
|
|
69
|
+
id: 42,
|
|
70
|
+
name: "My Plugin",
|
|
71
|
+
external_identifier: "my-plugin_ios",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
global.fetch = jest
|
|
75
|
+
.fn()
|
|
76
|
+
.mockResolvedValueOnce({
|
|
77
|
+
ok: false,
|
|
78
|
+
status: 404,
|
|
79
|
+
})
|
|
80
|
+
.mockResolvedValueOnce({
|
|
81
|
+
ok: true,
|
|
82
|
+
status: 200,
|
|
83
|
+
json: async () => mockPlugin,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const result = await findPlugin({
|
|
87
|
+
identifier: "my-plugin_ios",
|
|
88
|
+
name: "My Plugin",
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(result).toEqual(mockPlugin);
|
|
92
|
+
expect(global.fetch).toHaveBeenCalledTimes(2);
|
|
93
|
+
|
|
94
|
+
expect(global.fetch).toHaveBeenNthCalledWith(
|
|
95
|
+
1,
|
|
96
|
+
`${ZAPP_URL}/plugins/my-plugin.json?access_token=dummy-token`,
|
|
97
|
+
expect.anything()
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(global.fetch).toHaveBeenNthCalledWith(
|
|
101
|
+
2,
|
|
102
|
+
`${ZAPP_URL}/plugins/my-plugin_ios.json?access_token=dummy-token`,
|
|
103
|
+
expect.anything()
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("throws error when plugin is not found in Zapp", async () => {
|
|
108
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
109
|
+
ok: false,
|
|
110
|
+
status: 404,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
await expect(
|
|
114
|
+
findPlugin({ identifier: "non-existent", name: "Non Existent" })
|
|
115
|
+
).rejects.toThrow(
|
|
116
|
+
"Plugin with identifier 'non-existent' not found in Zapp"
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("throws error on server error with status text", async () => {
|
|
121
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
122
|
+
ok: false,
|
|
123
|
+
status: 500,
|
|
124
|
+
text: async () => "Internal Error",
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await expect(findPlugin({ identifier: "some-plugin" })).rejects.toThrow(
|
|
128
|
+
"Failed to fetch plugin 'some-plugin' from Zapp: HTTP 500 - Internal Error"
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("throws error when ZAPP_TOKEN is not set", async () => {
|
|
133
|
+
delete process.env.ZAPP_TOKEN;
|
|
134
|
+
|
|
135
|
+
await expect(
|
|
136
|
+
findPlugin({ identifier: "my-plugin", token: null })
|
|
137
|
+
).rejects.toThrow("ZAPP_TOKEN environment variable is not set");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("uploadPluginVersion", () => {
|
|
142
|
+
it("submits multipart FormData with targets and ui_frameworks to /plugin_versions", async () => {
|
|
143
|
+
let requestBody = null;
|
|
144
|
+
let requestMethod = null;
|
|
145
|
+
let requestHeaders = null;
|
|
146
|
+
|
|
147
|
+
global.fetch = jest.fn().mockImplementation((url, options) => {
|
|
148
|
+
if (url.includes("/targets.json")) {
|
|
149
|
+
return Promise.resolve({
|
|
150
|
+
ok: true,
|
|
151
|
+
status: 200,
|
|
152
|
+
json: async () => [
|
|
153
|
+
{ id: 1, name: "mobile" },
|
|
154
|
+
{ id: 2, name: "tv" },
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (url.includes("/ui_frameworks.json")) {
|
|
160
|
+
return Promise.resolve({
|
|
161
|
+
ok: true,
|
|
162
|
+
status: 200,
|
|
163
|
+
json: async () => [
|
|
164
|
+
{ id: 1, name: "native" },
|
|
165
|
+
{ id: 2, name: "quickbrick" },
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
requestMethod = options.method;
|
|
171
|
+
requestBody = options.body;
|
|
172
|
+
requestHeaders = options.headers;
|
|
173
|
+
|
|
174
|
+
return Promise.resolve({
|
|
175
|
+
ok: true,
|
|
176
|
+
status: 200,
|
|
177
|
+
text: async () => "OK",
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const manifest = {
|
|
182
|
+
name: "My Plugin",
|
|
183
|
+
identifier: "my-plugin",
|
|
184
|
+
manifest_version: "1.0.0",
|
|
185
|
+
platform: "ios_for_quickbrick",
|
|
186
|
+
author_email: "test@example.com",
|
|
187
|
+
scheme: "my-scheme",
|
|
188
|
+
targets: ["mobile"],
|
|
189
|
+
ui_frameworks: ["quickbrick"],
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
await uploadPluginVersion({
|
|
193
|
+
pluginId: 42,
|
|
194
|
+
manifest,
|
|
195
|
+
token: "secret-token",
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
199
|
+
`${ZAPP_URL}/plugin_versions`,
|
|
200
|
+
expect.objectContaining({
|
|
201
|
+
method: "POST",
|
|
202
|
+
headers: expect.objectContaining({
|
|
203
|
+
"User-Agent": USER_AGENT,
|
|
204
|
+
Accept: "application/json",
|
|
205
|
+
}),
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
expect(requestMethod).toBe("POST");
|
|
210
|
+
expect(requestHeaders["User-Agent"]).toBe(USER_AGENT);
|
|
211
|
+
expect(requestBody).toBeInstanceOf(FormData);
|
|
212
|
+
expect(requestBody.get("access_token")).toBe("secret-token");
|
|
213
|
+
expect(requestBody.get("plugin_version[plugin_id]")).toBe("42");
|
|
214
|
+
expect(requestBody.get("plugin_version[version]")).toBe("1.0.0");
|
|
215
|
+
|
|
216
|
+
expect(requestBody.get("plugin_version[platform]")).toBe(
|
|
217
|
+
"ios_for_quickbrick"
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
expect(requestBody.get("plugin_version[author_email]")).toBe(
|
|
221
|
+
"test@example.com"
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
expect(requestBody.get("plugin_version[scheme]")).toBe("my-scheme");
|
|
225
|
+
|
|
226
|
+
expect(requestBody.get("plugin_version[targets]")).toBe(
|
|
227
|
+
JSON.stringify([1])
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
expect(requestBody.get("plugin_version[ui_frameworks]")).toBe(
|
|
231
|
+
JSON.stringify([2])
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
expect(requestBody.get("plugin_version[manifest]")).toBe(
|
|
235
|
+
JSON.stringify(manifest)
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("throws error on HTTP failure status", async () => {
|
|
240
|
+
global.fetch = jest.fn().mockImplementation((url) => {
|
|
241
|
+
if (
|
|
242
|
+
url.includes("/targets.json") ||
|
|
243
|
+
url.includes("/ui_frameworks.json")
|
|
244
|
+
) {
|
|
245
|
+
return Promise.resolve({
|
|
246
|
+
ok: true,
|
|
247
|
+
status: 200,
|
|
248
|
+
json: async () => [],
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return Promise.resolve({
|
|
253
|
+
ok: false,
|
|
254
|
+
status: 422,
|
|
255
|
+
text: async () => "Validation failed: version has already been taken",
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const manifest = {
|
|
260
|
+
manifest_version: "1.0.0",
|
|
261
|
+
platform: "ios_for_quickbrick",
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
await expect(
|
|
265
|
+
uploadPluginVersion({ pluginId: 42, manifest })
|
|
266
|
+
).rejects.toThrow(
|
|
267
|
+
"Failed to upload manifest for platform 'ios_for_quickbrick': HTTP 422 - Validation failed: version has already been taken"
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -34,20 +34,117 @@ jest.mock("../../../logger", () => ({
|
|
|
34
34
|
log: jest.fn(),
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
|
-
|
|
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
|
+
|
|
38
57
|
const { runInShellAsync } = require("../../../shell");
|
|
58
|
+
const { findPlugin, uploadPluginVersion } = require("../zappApi");
|
|
39
59
|
const logger = require("../../../logger");
|
|
40
|
-
const { inspect } = require("util");
|
|
41
60
|
|
|
42
61
|
function clearMocks() {
|
|
43
62
|
logger.log.mockClear();
|
|
44
63
|
runInShellAsync.mockClear();
|
|
64
|
+
findPlugin.mockClear();
|
|
65
|
+
uploadPluginVersion.mockClear();
|
|
66
|
+
delete process.env.USE_LEGACY_ZAPPIFEST;
|
|
45
67
|
}
|
|
46
68
|
|
|
47
69
|
describe("publish zappifests", () => {
|
|
48
70
|
beforeEach(clearMocks);
|
|
49
71
|
|
|
50
|
-
it("
|
|
72
|
+
it("publishes manifests natively via zappApi by default", async () => {
|
|
73
|
+
const configuration = getConfig();
|
|
74
|
+
|
|
75
|
+
const result = await zappifestPublish(configuration);
|
|
76
|
+
expect(result).toBe(true);
|
|
77
|
+
|
|
78
|
+
expect(findPlugin).toHaveBeenCalledWith({
|
|
79
|
+
identifier: "my_plugin",
|
|
80
|
+
name: "my plugin name",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(uploadPluginVersion).toHaveBeenCalledTimes(2);
|
|
84
|
+
expect(runInShellAsync).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
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
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
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
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(findPlugin).toHaveBeenCalledWith({
|
|
107
|
+
identifier: "cell_info_tv",
|
|
108
|
+
name: "Cell Info TV",
|
|
109
|
+
});
|
|
110
|
+
|
|
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" },
|
|
139
|
+
]);
|
|
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
|
+
});
|
|
145
|
+
|
|
146
|
+
it("falls back to legacy Ruby zappifest when USE_LEGACY_ZAPPIFEST is true", async () => {
|
|
147
|
+
process.env.USE_LEGACY_ZAPPIFEST = "true";
|
|
51
148
|
const configuration = getConfig();
|
|
52
149
|
|
|
53
150
|
const expectedResult = new Array(configuration.platforms.length)
|
|
@@ -66,49 +163,28 @@ describe("publish zappifests", () => {
|
|
|
66
163
|
`zappifest publish --manifest ${__dirname}/manifests/${val}.json --account A1234`
|
|
67
164
|
);
|
|
68
165
|
});
|
|
166
|
+
|
|
167
|
+
expect(findPlugin).not.toHaveBeenCalled();
|
|
168
|
+
expect(uploadPluginVersion).not.toHaveBeenCalled();
|
|
69
169
|
});
|
|
70
170
|
|
|
71
171
|
it("only logs in the console when running with dry run flag", async () => {
|
|
72
172
|
const configuration = getConfig({ dryRun: true });
|
|
73
173
|
|
|
74
|
-
|
|
75
|
-
.fill()
|
|
76
|
-
.map(() => true);
|
|
77
|
-
|
|
78
|
-
expect(await zappifestPublish(configuration)).toEqual(expectedResult);
|
|
174
|
+
expect(await zappifestPublish(configuration)).toBe(true);
|
|
79
175
|
expect(runInShellAsync).not.toHaveBeenCalled();
|
|
176
|
+
expect(uploadPluginVersion).not.toHaveBeenCalled();
|
|
80
177
|
|
|
81
|
-
expect(logger.log).
|
|
82
|
-
1 + configuration.platforms.length * 2
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(logger.log).toHaveBeenNthCalledWith(
|
|
86
|
-
1,
|
|
178
|
+
expect(logger.log).toHaveBeenCalledWith(
|
|
87
179
|
"Running with --dry-run or --manifest-only option - not actually pushing to zapp"
|
|
88
180
|
);
|
|
89
|
-
|
|
90
|
-
configuration.platforms.forEach((val, index) => {
|
|
91
|
-
expect(logger.log).toHaveBeenNthCalledWith(
|
|
92
|
-
index * 2 + 2,
|
|
93
|
-
expect.stringMatching(
|
|
94
|
-
/running zappifest publish --manifest .*(ios|android)\.json/
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
expect(logger.log).toHaveBeenNthCalledWith(
|
|
99
|
-
index * 2 + 3,
|
|
100
|
-
`with manifest: ${inspect(require(`./manifests/${val}.json`))}`
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
181
|
});
|
|
104
182
|
|
|
105
183
|
it("it throws if a manifest cannot be found", async () => {
|
|
106
184
|
const configuration = getConfig({ pluginPath: "resolve_error" });
|
|
107
|
-
expect(zappifestPublish(configuration)).rejects.toMatchSnapshot();
|
|
108
|
-
});
|
|
109
185
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
186
|
+
await expect(zappifestPublish(configuration)).rejects.toThrow(
|
|
187
|
+
"cannot resolve manifest"
|
|
188
|
+
);
|
|
113
189
|
});
|
|
114
190
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const R = require("ramda");
|
|
2
2
|
const { resolve } = require("path");
|
|
3
3
|
const semver = require("semver");
|
|
4
|
-
const git = require("simple-git
|
|
4
|
+
const git = require("simple-git");
|
|
5
5
|
const logger = require("../../logger");
|
|
6
6
|
const { existsSync } = require("fs");
|
|
7
7
|
|
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
const R = require("ramda");
|
|
2
2
|
const path = require("path");
|
|
3
3
|
|
|
4
|
-
const { writeJsonToFile } = require("../../file");
|
|
4
|
+
const { writeJsonToFile, readJsonFile } = require("../../file");
|
|
5
5
|
const logger = require("../../logger");
|
|
6
6
|
|
|
7
7
|
const PACKAGE_DOT_JSON = "package.json";
|
|
8
8
|
const QUICK_BRICK_WORKSPACE_NAME = "quick-brick";
|
|
9
9
|
const CORE_PLUGINS_PATH = "packages/quick-brick-core-plugins";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const { name: workspaceName } = require(
|
|
13
|
-
path.join(process.cwd(), PACKAGE_DOT_JSON)
|
|
14
|
-
);
|
|
11
|
+
let writeLock = Promise.resolve();
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
async function doUpdateCorePlugins(configuration) {
|
|
14
|
+
const rootPackageJsonPath = path.join(process.cwd(), PACKAGE_DOT_JSON);
|
|
15
|
+
const rootPackageJson = await readJsonFile(rootPackageJsonPath);
|
|
16
|
+
|
|
17
|
+
if (rootPackageJson.name !== QUICK_BRICK_WORKSPACE_NAME) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const { version, pluginPackageJson } = configuration;
|
|
21
22
|
const { name } = pluginPackageJson;
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const corePluginsPackageJsonPath = path.join(
|
|
25
|
+
process.cwd(),
|
|
26
|
+
CORE_PLUGINS_PATH,
|
|
27
|
+
PACKAGE_DOT_JSON
|
|
25
28
|
);
|
|
26
29
|
|
|
30
|
+
const corePluginsPackageJson = await readJsonFile(corePluginsPackageJsonPath);
|
|
31
|
+
|
|
27
32
|
const { dependencies } = corePluginsPackageJson;
|
|
28
33
|
const isPluginCore = R.contains(name, R.keys(dependencies));
|
|
29
34
|
|
|
30
35
|
if (isPluginCore) {
|
|
31
36
|
corePluginsPackageJson.dependencies[name] = version;
|
|
32
37
|
|
|
33
|
-
await writeJsonToFile(
|
|
34
|
-
path.join(process.cwd(), CORE_PLUGINS_PATH, PACKAGE_DOT_JSON),
|
|
35
|
-
corePluginsPackageJson
|
|
36
|
-
);
|
|
38
|
+
await writeJsonToFile(corePluginsPackageJsonPath, corePluginsPackageJson);
|
|
37
39
|
|
|
38
40
|
logger.log(`Core Plugins updated with ${name}@${version}`);
|
|
39
41
|
} else {
|
|
@@ -41,4 +43,12 @@ async function updateCorePluginsIfNeeded(configuration) {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
async function updateCorePluginsIfNeeded(configuration) {
|
|
47
|
+
// Ensure that concurrent publishing tasks do not race when updating core plugins
|
|
48
|
+
const result = writeLock.then(() => doUpdateCorePlugins(configuration));
|
|
49
|
+
writeLock = result.catch(() => {});
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
44
54
|
module.exports = { updateCorePluginsIfNeeded };
|