@superblocksteam/cli 1.9.3 → 1.12.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/LICENSE.txt +87 -0
- package/README.md +6 -6
- package/assets/custom-components/setup/package.json +1 -1
- package/assets/custom-components/setup/tsconfig.json +0 -1
- package/assets/injectedReactShim17.jsx +15 -0
- package/assets/injectedReactShim18.jsx +16 -0
- package/assets/injectedReactShimShared.jsx +140 -0
- package/bin/dev +5 -7
- package/bin/run +1 -3
- package/dist/appendHotReloadEventPlugin.d.mts +2 -0
- package/dist/appendHotReloadEventPlugin.mjs +43 -0
- package/dist/commands/commits.d.mts +18 -0
- package/dist/commands/{commits.js → commits.mjs} +59 -67
- package/dist/commands/components/{create.d.ts → create.d.mts} +2 -2
- package/dist/commands/components/{create.js → create.mjs} +84 -93
- package/dist/commands/components/{register.d.ts → register.d.mts} +1 -1
- package/dist/commands/components/register.mjs +12 -0
- package/dist/commands/components/{upload.d.ts → upload.d.mts} +2 -2
- package/dist/commands/components/{upload.js → upload.mjs} +39 -43
- package/dist/commands/components/{watch.d.ts → watch.d.mts} +1 -1
- package/dist/commands/components/{watch.js → watch.mjs} +29 -36
- package/dist/commands/config/{set.d.ts → set.d.mts} +2 -2
- package/dist/commands/config/{set.js → set.mjs} +28 -32
- package/dist/commands/{init.d.ts → init.d.mts} +4 -4
- package/dist/commands/{init.js → init.mjs} +63 -65
- package/dist/commands/{login.d.ts → login.d.mts} +1 -1
- package/dist/commands/login.mjs +55 -0
- package/dist/commands/{migrate.d.ts → migrate.d.mts} +1 -1
- package/dist/commands/{migrate.js → migrate.mjs} +38 -46
- package/dist/commands/pull.d.mts +17 -0
- package/dist/commands/{pull.js → pull.mjs} +74 -80
- package/dist/commands/push.d.mts +15 -0
- package/dist/commands/{push.js → push.mjs} +81 -90
- package/dist/commands/{rm.d.ts → rm.d.mts} +2 -2
- package/dist/commands/{rm.js → rm.mjs} +34 -40
- package/dist/common/{authenticated-command.js → authenticated-command.mjs} +65 -75
- package/dist/common/defaults/{create-component-defaults.js → create-component-defaults.mjs} +2 -7
- package/dist/common/{version-control.d.ts → version-control.d.mts} +13 -6
- package/dist/common/version-control.mjs +1064 -0
- package/dist/index.js +1 -5
- package/dist/productionCssPlugin.d.mts +2 -0
- package/dist/productionCssPlugin.mjs +50 -0
- package/dist/reactShimPlugin.d.mts +2 -0
- package/dist/reactShimPlugin.mjs +127 -0
- package/dist/util/migrationWarningsForApplications.mjs +47 -0
- package/dist/util/{migrationsForDotfiles.js → migrationsForDotfiles.mjs} +10 -17
- package/oclif.manifest.json +274 -161
- package/package.json +45 -45
- package/dist/commands/commits.d.ts +0 -18
- package/dist/commands/components/register.js +0 -15
- package/dist/commands/login.js +0 -61
- package/dist/commands/pull.d.ts +0 -17
- package/dist/commands/push.d.ts +0 -15
- package/dist/common/version-control.js +0 -716
- package/dist/util/migrationWarningsForApplications.js +0 -52
- /package/dist/common/{authenticated-command.d.ts → authenticated-command.d.mts} +0 -0
- /package/dist/common/defaults/{create-component-defaults.d.ts → create-component-defaults.d.mts} +0 -0
- /package/dist/util/{migrationWarningsForApplications.d.ts → migrationWarningsForApplications.d.mts} +0 -0
- /package/dist/util/{migrationsForDotfiles.d.ts → migrationsForDotfiles.d.mts} +0 -0
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { Args, Flags } from "@oclif/core";
|
|
3
|
+
import { COMPONENT_EVENT_HEADER, getSuperblocksMonorepoConfigJson, SUPERBLOCKS_HOME_FOLDER_NAME, RESOURCE_CONFIG_PATH, ComponentEvent, NotFoundError, } from "@superblocksteam/util";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import { Listr } from "listr2";
|
|
6
|
+
import { isEmpty } from "lodash-es";
|
|
7
|
+
import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
|
|
8
|
+
import { atLeastOneSelection, DEFAULT_BRANCH, extractApiName, getMode, modeFlagValuesMap, MULTI_SELECT_PROMPT_HELP, sortByKey, writeMultiPageApplicationToDisk, writeResourceToDisk, } from "../common/version-control.mjs";
|
|
9
|
+
export default class Initialize extends AuthenticatedCommand {
|
|
10
|
+
static description = "Interactively configure the current directory as a Superblocks project or initialize new services in an already configured Superblocks project directory";
|
|
11
|
+
static examples = [
|
|
12
|
+
"<%= config.bin %> <%= command.id %>",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> https://app.superblocks.com/applications/11111111-1111-1111-1111-111111111111/pages/22222222-2222-2222-2222-222222222222",
|
|
14
|
+
];
|
|
15
|
+
static flags = {
|
|
16
|
+
mode: Flags.string({
|
|
17
|
+
char: "m",
|
|
18
|
+
description: "Pull mode",
|
|
19
|
+
options: Object.keys(modeFlagValuesMap),
|
|
20
|
+
}),
|
|
21
|
+
"skip-signing-verification": Flags.boolean({
|
|
22
|
+
char: "s",
|
|
23
|
+
description: "If true, signature verification for signing enabled organizations will be skipped.",
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
static args = {
|
|
28
|
+
resource_url: Args.string({
|
|
29
|
+
description: "Superblocks resource URL (i.e. https://app.superblocks.com/applications/<application_id> or https://app.superblocks.com/applications/edit/<application_id>)",
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
13
33
|
async run() {
|
|
14
34
|
const { flags, args } = await this.parse(Initialize);
|
|
15
35
|
const tasks = this.createTasks(flags, args);
|
|
@@ -22,17 +42,19 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
22
42
|
}
|
|
23
43
|
createTasks(flags, args) {
|
|
24
44
|
const skipSigningVerification = flags["skip-signing-verification"];
|
|
25
|
-
const tasks = new
|
|
45
|
+
const tasks = new Listr([
|
|
26
46
|
{
|
|
27
47
|
title: "Checking for existing Superblocks project...",
|
|
28
48
|
task: async (ctx) => {
|
|
29
49
|
ctx.fetchedResources = {};
|
|
30
50
|
ctx.writtenResources = {};
|
|
51
|
+
ctx.featureFlags =
|
|
52
|
+
await this.getSdk().getFeatureFlagsForCurrentUser();
|
|
31
53
|
try {
|
|
32
54
|
[
|
|
33
55
|
ctx.existingSuperblocksRootConfig,
|
|
34
56
|
ctx.superblocksRootConfigPath,
|
|
35
|
-
] = await
|
|
57
|
+
] = await getSuperblocksMonorepoConfigJson(true);
|
|
36
58
|
}
|
|
37
59
|
catch {
|
|
38
60
|
// no existing superblocks config
|
|
@@ -68,7 +90,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
68
90
|
for (const api of apis) {
|
|
69
91
|
ctx.fetchedResources[api.id] = {
|
|
70
92
|
resourceType: "BACKEND",
|
|
71
|
-
name:
|
|
93
|
+
name: extractApiName(api),
|
|
72
94
|
};
|
|
73
95
|
}
|
|
74
96
|
task.title += `: completed`;
|
|
@@ -76,21 +98,21 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
76
98
|
},
|
|
77
99
|
{
|
|
78
100
|
title: "Fetching resource by resourceUrl...",
|
|
79
|
-
enabled: () => !
|
|
101
|
+
enabled: () => !isEmpty(args.resource_url),
|
|
80
102
|
task: async (ctx, task) => {
|
|
81
103
|
const [resourceId, resourceType] = getResourceIdFromUrl(args.resource_url);
|
|
82
104
|
if (resourceType === "APPLICATION") {
|
|
83
105
|
const headers = {
|
|
84
|
-
[
|
|
106
|
+
[COMPONENT_EVENT_HEADER]: ComponentEvent.INIT,
|
|
85
107
|
};
|
|
86
108
|
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
87
109
|
applicationId: resourceId,
|
|
88
|
-
branch:
|
|
110
|
+
branch: DEFAULT_BRANCH,
|
|
89
111
|
headers,
|
|
90
112
|
skipSigningVerification,
|
|
91
113
|
});
|
|
92
114
|
if (!application) {
|
|
93
|
-
throw new
|
|
115
|
+
throw new NotFoundError(`Application ${resourceId} was not found`);
|
|
94
116
|
}
|
|
95
117
|
ctx.fetchedResources[application.application.id] = {
|
|
96
118
|
resourceType,
|
|
@@ -104,7 +126,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
104
126
|
});
|
|
105
127
|
ctx.fetchedResources[api.id] = {
|
|
106
128
|
resourceType,
|
|
107
|
-
name:
|
|
129
|
+
name: extractApiName(api),
|
|
108
130
|
};
|
|
109
131
|
}
|
|
110
132
|
task.title += `: completed`;
|
|
@@ -117,7 +139,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
117
139
|
task: async (ctx, task) => {
|
|
118
140
|
const resourceIdsToInitialize = await this.getResourcesToInitialize(ctx, task, args);
|
|
119
141
|
ctx.resourceIdsToInitialize = resourceIdsToInitialize;
|
|
120
|
-
const viewMode = await
|
|
142
|
+
const viewMode = await getMode(task, flags.mode);
|
|
121
143
|
ctx.viewMode = viewMode;
|
|
122
144
|
},
|
|
123
145
|
},
|
|
@@ -128,7 +150,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
128
150
|
// if ctx.superblocksRootConfigPath is defined, we are initializing a new resource in an existing Superblocks project
|
|
129
151
|
// otherwise, we are initializing a new Superblocks project
|
|
130
152
|
const superblocksRootPath = ctx.superblocksRootConfigPath
|
|
131
|
-
?
|
|
153
|
+
? path.resolve(path.dirname(ctx.superblocksRootConfigPath), "..")
|
|
132
154
|
: undefined;
|
|
133
155
|
for (const resourceId of ctx.resourceIdsToInitialize) {
|
|
134
156
|
const resource = ctx.fetchedResources[resourceId];
|
|
@@ -141,11 +163,11 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
141
163
|
title: `Fetching application ${resource.name}...`,
|
|
142
164
|
task: async (_ctx, task) => {
|
|
143
165
|
const headers = {
|
|
144
|
-
[
|
|
166
|
+
[COMPONENT_EVENT_HEADER]: ComponentEvent.INIT,
|
|
145
167
|
};
|
|
146
168
|
const application = (await this.getSdk().fetchApplicationWithComponents({
|
|
147
169
|
applicationId: resourceId,
|
|
148
|
-
branch:
|
|
170
|
+
branch: DEFAULT_BRANCH,
|
|
149
171
|
viewMode: ctx.viewMode,
|
|
150
172
|
headers,
|
|
151
173
|
skipSigningVerification,
|
|
@@ -153,7 +175,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
153
175
|
task.title += `: fetched`;
|
|
154
176
|
if (application) {
|
|
155
177
|
ctx.writtenResources[resourceId] =
|
|
156
|
-
await
|
|
178
|
+
await writeMultiPageApplicationToDisk(application, superblocksRootPath ?? process.cwd(), ctx.featureFlags);
|
|
157
179
|
}
|
|
158
180
|
task.title += `: done`;
|
|
159
181
|
},
|
|
@@ -167,12 +189,14 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
167
189
|
const backend = await this.getSdk().fetchApi({
|
|
168
190
|
apiId: resourceId,
|
|
169
191
|
viewMode: ctx.viewMode,
|
|
170
|
-
branch:
|
|
192
|
+
branch: DEFAULT_BRANCH,
|
|
171
193
|
skipSigningVerification,
|
|
172
194
|
});
|
|
173
195
|
task.title += `: fetched`;
|
|
174
|
-
|
|
175
|
-
|
|
196
|
+
if (backend) {
|
|
197
|
+
ctx.writtenResources[resourceId] =
|
|
198
|
+
await writeResourceToDisk("BACKEND", resourceId, backend, superblocksRootPath ?? process.cwd(), ctx.featureFlags);
|
|
199
|
+
}
|
|
176
200
|
task.title += `: done`;
|
|
177
201
|
},
|
|
178
202
|
});
|
|
@@ -191,7 +215,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
191
215
|
{
|
|
192
216
|
title: "Updating Superblocks project file...",
|
|
193
217
|
task: async (ctx) => {
|
|
194
|
-
var _a, _b, _c;
|
|
195
218
|
const superblocksConfig = {
|
|
196
219
|
configType: "ROOT",
|
|
197
220
|
resources: {},
|
|
@@ -204,14 +227,14 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
204
227
|
superblocksConfig.resources[resourceId] = resource;
|
|
205
228
|
}
|
|
206
229
|
// existing resources
|
|
207
|
-
for (const [resourceId, resource] of Object.entries(
|
|
230
|
+
for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
|
|
208
231
|
superblocksConfig.resources[resourceId] = resource;
|
|
209
232
|
}
|
|
210
|
-
if (!(await fs.exists(
|
|
211
|
-
await fs.mkdir(
|
|
233
|
+
if (!(await fs.exists(SUPERBLOCKS_HOME_FOLDER_NAME))) {
|
|
234
|
+
await fs.mkdir(SUPERBLOCKS_HOME_FOLDER_NAME);
|
|
212
235
|
}
|
|
213
236
|
// create superblocks.json file
|
|
214
|
-
await fs.writeFile(
|
|
237
|
+
await fs.writeFile(ctx.superblocksRootConfigPath ?? RESOURCE_CONFIG_PATH, JSON.stringify(sortByKey(superblocksConfig), null, 2));
|
|
215
238
|
},
|
|
216
239
|
},
|
|
217
240
|
], {
|
|
@@ -220,7 +243,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
220
243
|
return tasks;
|
|
221
244
|
}
|
|
222
245
|
async getResourcesToInitialize(ctx, task, args) {
|
|
223
|
-
var _a, _b;
|
|
224
246
|
if (args.resource_url) {
|
|
225
247
|
try {
|
|
226
248
|
const [resourceId] = getResourceIdFromUrl(args.resource_url);
|
|
@@ -238,37 +260,37 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
238
260
|
choices.push({
|
|
239
261
|
name: resourceId,
|
|
240
262
|
message: `${resource.name} (${resource.resourceType})`,
|
|
241
|
-
disabled:
|
|
263
|
+
disabled: ctx.existingSuperblocksRootConfig?.resources[resourceId],
|
|
242
264
|
});
|
|
243
|
-
if (
|
|
265
|
+
if (ctx.existingSuperblocksRootConfig?.resources[resourceId]) {
|
|
244
266
|
initialSelections.push(counter);
|
|
245
267
|
}
|
|
246
268
|
counter++;
|
|
247
269
|
}
|
|
248
|
-
if (
|
|
270
|
+
if (isEmpty(choices)) {
|
|
249
271
|
this.error(`No resources found in your account. Please make sure you have access to at least one application, workflow or scheduled job.`);
|
|
250
272
|
}
|
|
251
273
|
const resourceIdsToInitialize = await task.prompt([
|
|
252
274
|
{
|
|
253
275
|
type: "AutoComplete",
|
|
254
276
|
name: "resourceIdsToInitialize",
|
|
255
|
-
message: `Select resources to initialize (${
|
|
277
|
+
message: `Select resources to initialize (${MULTI_SELECT_PROMPT_HELP})`,
|
|
256
278
|
choices: choices,
|
|
257
279
|
initial: initialSelections,
|
|
258
280
|
multiple: true,
|
|
259
|
-
validate:
|
|
281
|
+
validate: atLeastOneSelection,
|
|
260
282
|
prefix: "▸",
|
|
261
283
|
indicator: "◉",
|
|
262
284
|
},
|
|
263
285
|
]);
|
|
264
286
|
const duplicates = await this.findDuplicates(resourceIdsToInitialize, ctx.fetchedResources);
|
|
265
|
-
if (!
|
|
287
|
+
if (!isEmpty(duplicates)) {
|
|
266
288
|
this.error(`Duplicate resources selected: ${duplicates
|
|
267
289
|
.map((duplicate) => `${duplicate.name} (${duplicate.resourceType}) id: ${duplicate.id}`)
|
|
268
290
|
.join(", ")}. Please make sure to select unique resources or rename them so that they have unique names.`);
|
|
269
291
|
}
|
|
270
292
|
// filter out disabled resources
|
|
271
|
-
return resourceIdsToInitialize.filter((resourceId) =>
|
|
293
|
+
return resourceIdsToInitialize.filter((resourceId) => !ctx.existingSuperblocksRootConfig?.resources[resourceId]);
|
|
272
294
|
}
|
|
273
295
|
}
|
|
274
296
|
async findDuplicates(selectedResourcesIds, resources) {
|
|
@@ -292,30 +314,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
292
314
|
return selectedResources.filter((resource) => countResourceNamesByType[resource.resourceType][resource.name] > 1);
|
|
293
315
|
}
|
|
294
316
|
}
|
|
295
|
-
Initialize.description = "Interactively configure the current directory as a Superblocks project or initialize new services in an already configured Superblocks project directory";
|
|
296
|
-
Initialize.examples = [
|
|
297
|
-
"<%= config.bin %> <%= command.id %>",
|
|
298
|
-
"<%= config.bin %> <%= command.id %> https://app.superblocks.com/applications/11111111-1111-1111-1111-111111111111/pages/22222222-2222-2222-2222-222222222222",
|
|
299
|
-
];
|
|
300
|
-
Initialize.flags = {
|
|
301
|
-
mode: core_1.Flags.string({
|
|
302
|
-
char: "m",
|
|
303
|
-
description: "Pull mode",
|
|
304
|
-
options: Object.keys(version_control_1.modeFlagValuesMap),
|
|
305
|
-
}),
|
|
306
|
-
"skip-signing-verification": core_1.Flags.boolean({
|
|
307
|
-
char: "s",
|
|
308
|
-
description: "If true, signature verification for signing enabled organizations will be skipped.",
|
|
309
|
-
default: false,
|
|
310
|
-
}),
|
|
311
|
-
};
|
|
312
|
-
Initialize.args = {
|
|
313
|
-
resource_url: core_1.Args.string({
|
|
314
|
-
description: "Superblocks resource URL (i.e. https://app.superblocks.com/applications/<application_id> or https://app.superblocks.com/applications/edit/<application_id>)",
|
|
315
|
-
required: false,
|
|
316
|
-
}),
|
|
317
|
-
};
|
|
318
|
-
exports.default = Initialize;
|
|
319
317
|
function getResourceIdFromUrl(resourceUrl) {
|
|
320
318
|
const url = new URL(resourceUrl);
|
|
321
319
|
if (url.pathname.startsWith("/applications")) {
|
|
@@ -2,7 +2,7 @@ import { Command } from "@oclif/core";
|
|
|
2
2
|
export default class Login extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
token: import("@oclif/core/
|
|
5
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
6
|
};
|
|
7
7
|
DEFAULT_BASE_URL: string;
|
|
8
8
|
run(): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import { SuperblocksSdk } from "@superblocksteam/sdk";
|
|
3
|
+
import { FileAccessError, getLocalTokenWithUrlIfExists, saveApiToken, } from "@superblocksteam/util";
|
|
4
|
+
import { green, red } from "colorette";
|
|
5
|
+
import enquirer from "enquirer";
|
|
6
|
+
import { isEmpty } from "lodash-es";
|
|
7
|
+
const { prompt } = enquirer;
|
|
8
|
+
export default class Login extends Command {
|
|
9
|
+
static description = "Authenticate with Superblocks cloud";
|
|
10
|
+
static flags = {
|
|
11
|
+
// flag with a value (-t, --token=VALUE)
|
|
12
|
+
token: Flags.string({
|
|
13
|
+
char: "t",
|
|
14
|
+
description: "Superblocks user API key",
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
DEFAULT_BASE_URL = "https://app.superblocks.com/";
|
|
18
|
+
async run() {
|
|
19
|
+
const { flags } = await this.parse(Login);
|
|
20
|
+
let token = flags.token;
|
|
21
|
+
const result = await getLocalTokenWithUrlIfExists();
|
|
22
|
+
const superblocksBaseUrl = result?.superblocksBaseUrl ?? this.DEFAULT_BASE_URL;
|
|
23
|
+
if (!token) {
|
|
24
|
+
if (result && "token" in result) {
|
|
25
|
+
token = result.token;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const tokenPageUrl = new URL("personal-settings#apiKey", superblocksBaseUrl).href;
|
|
29
|
+
token = (await prompt({
|
|
30
|
+
type: "password",
|
|
31
|
+
name: "token",
|
|
32
|
+
message: `Enter your Superblocks API key (then press Enter) which can be found at ${tokenPageUrl}`,
|
|
33
|
+
validate: (response) => !isEmpty(response.trim()),
|
|
34
|
+
})).token;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.log();
|
|
38
|
+
try {
|
|
39
|
+
const sdk = new SuperblocksSdk(token, superblocksBaseUrl, this.config.version);
|
|
40
|
+
const user = await sdk.fetchCurrentUser();
|
|
41
|
+
await saveApiToken(superblocksBaseUrl, token);
|
|
42
|
+
this.log(green(`Welcome to the Superblocks 🐨 CLI ${user.user.name}!`));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof FileAccessError) {
|
|
46
|
+
this.log(red("Could not save token, ensure the Superblocks CLI has access to create folders in your home directory."));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (error.message) {
|
|
50
|
+
this.log(red(error.message));
|
|
51
|
+
}
|
|
52
|
+
this.log(red(`Login failed. Ensure you've copied the correct token from ${superblocksBaseUrl}. If using a different domain, run "superblocks help config set" for configuration options.`));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import util from "node:util";
|
|
4
|
+
import { getSuperblocksMonorepoConfigJson, getSuperblocksResourceConfigIfExists, } from "@superblocksteam/util";
|
|
5
|
+
import { cyan } from "colorette";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
import { Listr, } from "listr2";
|
|
8
|
+
import semver from "semver";
|
|
9
|
+
import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
|
|
10
|
+
import { FileStructureType, MULTI_SELECT_PROMPT_HELP, atLeastOneSelection, getFileStructureType, readApplicationFromDisk, writeMultiPageApplicationToDisk, } from "../common/version-control.mjs";
|
|
11
|
+
export default class Migrate extends AuthenticatedCommand {
|
|
12
|
+
static description = "Migrate files to use the current CLI version";
|
|
13
|
+
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
15
14
|
async run() {
|
|
16
15
|
const tasks = this.createTasks();
|
|
17
16
|
await tasks.run();
|
|
18
17
|
}
|
|
19
18
|
createTasks() {
|
|
20
|
-
const tasks = new
|
|
19
|
+
const tasks = new Listr([
|
|
21
20
|
{
|
|
22
21
|
title: "Checking for existing Superblocks project...",
|
|
23
22
|
task: async (ctx) => {
|
|
@@ -25,31 +24,30 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
25
24
|
[
|
|
26
25
|
ctx.existingSuperblocksRootConfig,
|
|
27
26
|
ctx.superblocksRootConfigPath,
|
|
28
|
-
] = await
|
|
27
|
+
] = await getSuperblocksMonorepoConfigJson(true);
|
|
29
28
|
ctx.existingSuperblocksResourceConfig =
|
|
30
|
-
await
|
|
29
|
+
await getSuperblocksResourceConfigIfExists();
|
|
31
30
|
}
|
|
32
31
|
catch {
|
|
33
32
|
// no existing superblocks config
|
|
34
|
-
this.error(`No Superblocks project found in the current folder hierarchy. Run ${
|
|
33
|
+
this.error(`No Superblocks project found in the current folder hierarchy. Run ${cyan("superblocks init")} to initialize a new project.`);
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
},
|
|
38
37
|
{
|
|
39
38
|
title: "Migrating resources...",
|
|
40
39
|
task: async (ctx, task) => {
|
|
41
|
-
var _a;
|
|
42
40
|
const resourceIdsToMigrate = await this.getResourceIdsToMigrate(ctx, task);
|
|
43
41
|
const subtasks = [];
|
|
44
|
-
const superblocksRootPath =
|
|
42
|
+
const superblocksRootPath = path.resolve(path.dirname(ctx.superblocksRootConfigPath), "..");
|
|
45
43
|
for (const resourceId of resourceIdsToMigrate) {
|
|
46
|
-
const resource =
|
|
47
|
-
switch (resource
|
|
44
|
+
const resource = ctx.existingSuperblocksRootConfig?.resources[resourceId];
|
|
45
|
+
switch (resource?.resourceType) {
|
|
48
46
|
case "APPLICATION": {
|
|
49
47
|
subtasks.push({
|
|
50
48
|
title: `Migrating application ${resource.location}...`,
|
|
51
49
|
task: async (_ctx, task) => {
|
|
52
|
-
await this.migrateApplication(resource, superblocksRootPath);
|
|
50
|
+
await this.migrateApplication(resource, superblocksRootPath, ctx.featureFlags);
|
|
53
51
|
task.title += `: done`;
|
|
54
52
|
},
|
|
55
53
|
});
|
|
@@ -81,7 +79,6 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
81
79
|
return tasks;
|
|
82
80
|
}
|
|
83
81
|
async getResourceIdsToMigrate(ctx, task) {
|
|
84
|
-
var _a, _b, _c, _d, _e;
|
|
85
82
|
const choices = [];
|
|
86
83
|
const initialSelections = [];
|
|
87
84
|
choices.push({
|
|
@@ -89,12 +86,12 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
89
86
|
message: "",
|
|
90
87
|
});
|
|
91
88
|
let counter = 1;
|
|
92
|
-
for (const [resourceId, resource] of Object.entries(
|
|
89
|
+
for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
|
|
93
90
|
choices.push({
|
|
94
91
|
name: resourceId,
|
|
95
92
|
message: resource.location,
|
|
96
93
|
});
|
|
97
|
-
if (
|
|
94
|
+
if (ctx.existingSuperblocksResourceConfig?.id === resourceId) {
|
|
98
95
|
initialSelections.push(counter);
|
|
99
96
|
}
|
|
100
97
|
counter++;
|
|
@@ -105,25 +102,24 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
105
102
|
{
|
|
106
103
|
type: "MultiSelect",
|
|
107
104
|
name: "resourceIdsToMigrate",
|
|
108
|
-
message: `Select resources to migrate (${
|
|
105
|
+
message: `Select resources to migrate (${MULTI_SELECT_PROMPT_HELP})`,
|
|
109
106
|
choices: choices,
|
|
110
107
|
initial: initialSelections,
|
|
111
|
-
validate:
|
|
112
|
-
// @ts-expect-error listr2 types are wrong for prefix
|
|
108
|
+
validate: atLeastOneSelection,
|
|
113
109
|
prefix: "▸",
|
|
114
110
|
indicator: "◉",
|
|
115
111
|
},
|
|
116
112
|
]);
|
|
117
113
|
if (resourceIdsToMigrate[0] === "All Resources") {
|
|
118
|
-
return Object.entries(
|
|
114
|
+
return Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {}).map(([id]) => id);
|
|
119
115
|
}
|
|
120
116
|
return resourceIdsToMigrate;
|
|
121
117
|
}
|
|
122
|
-
async migrateSinglePageApplicationToMultiPage(applicationResource, superblocksRootPath) {
|
|
123
|
-
const fileStructure = await
|
|
124
|
-
if (fileStructure ==
|
|
118
|
+
async migrateSinglePageApplicationToMultiPage(applicationResource, superblocksRootPath, featureFlags) {
|
|
119
|
+
const fileStructure = await getFileStructureType(superblocksRootPath, applicationResource.location);
|
|
120
|
+
if (fileStructure == FileStructureType.SINGLE_PAGE) {
|
|
125
121
|
this.log(`Migrating single page application at ${applicationResource.location} to multi-page application...`);
|
|
126
|
-
const singlePageApplication = await
|
|
122
|
+
const singlePageApplication = await readApplicationFromDisk(superblocksRootPath, applicationResource.location);
|
|
127
123
|
const multiPageApplication = {
|
|
128
124
|
application: {
|
|
129
125
|
id: singlePageApplication.application.id,
|
|
@@ -141,21 +137,20 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
141
137
|
],
|
|
142
138
|
componentFiles: [],
|
|
143
139
|
};
|
|
144
|
-
await
|
|
140
|
+
await writeMultiPageApplicationToDisk(multiPageApplication, superblocksRootPath, featureFlags, applicationResource.location, true);
|
|
145
141
|
this.log(`Successfully migrated single page application at ${applicationResource.location} to multi-page application.`);
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
async migrateCustomComponentVersion(applicationResource, superblocksRootPath) {
|
|
149
|
-
|
|
150
|
-
const packageJsonPath = node_path_1.default.join(superblocksRootPath, applicationResource.location, "package.json");
|
|
145
|
+
const packageJsonPath = path.join(superblocksRootPath, applicationResource.location, "package.json");
|
|
151
146
|
if (await fs.pathExists(packageJsonPath)) {
|
|
152
147
|
this.log("Checking CLI version compatibility...");
|
|
153
148
|
const packageJson = await fs.readJson(packageJsonPath);
|
|
154
|
-
const versionStr =
|
|
155
|
-
if (!
|
|
149
|
+
const versionStr = packageJson.dependencies?.["@superblocksteam/custom-components"];
|
|
150
|
+
if (!semver.satisfies(this.config.version, versionStr)) {
|
|
156
151
|
this.log("Migrating application dependencies...");
|
|
157
|
-
await
|
|
158
|
-
cwd:
|
|
152
|
+
await util.promisify(exec)(`npm install @superblocksteam/custom-components@${this.config.version}`, {
|
|
153
|
+
cwd: path.join(superblocksRootPath, applicationResource.location),
|
|
159
154
|
});
|
|
160
155
|
}
|
|
161
156
|
else {
|
|
@@ -166,10 +161,10 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
166
161
|
this.log(`No package.json found in ${applicationResource.location}. Skipping migration of dependencies.`);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
|
-
async migrateApplication(applicationResource, superblocksRootPath) {
|
|
164
|
+
async migrateApplication(applicationResource, superblocksRootPath, featureFlags) {
|
|
170
165
|
try {
|
|
171
166
|
await this.migrateCustomComponentVersion(applicationResource, superblocksRootPath);
|
|
172
|
-
await this.migrateSinglePageApplicationToMultiPage(applicationResource, superblocksRootPath);
|
|
167
|
+
await this.migrateSinglePageApplicationToMultiPage(applicationResource, superblocksRootPath, featureFlags);
|
|
173
168
|
}
|
|
174
169
|
catch (e) {
|
|
175
170
|
this.error(e.message, {
|
|
@@ -178,6 +173,3 @@ class Migrate extends authenticated_command_1.AuthenticatedCommand {
|
|
|
178
173
|
}
|
|
179
174
|
}
|
|
180
175
|
}
|
|
181
|
-
Migrate.description = "Migrate files to use the current CLI version";
|
|
182
|
-
Migrate.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
183
|
-
exports.default = Migrate;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
|
|
2
|
+
export default class Pull extends AuthenticatedCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
mode: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
"commit-id": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
"skip-signing-verification": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
resource_path: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private createTasks;
|
|
16
|
+
private getResourceIdsToPull;
|
|
17
|
+
}
|