@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,34 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Args, Flags } from "@oclif/core";
|
|
3
|
+
import { ValidateGitSetupError, } from "@superblocksteam/sdk";
|
|
4
|
+
import { getSuperblocksMonorepoConfigJson, getSuperblocksResourceConfigIfExists, ComponentEvent, COMPONENT_EVENT_HEADER, NotFoundError, } from "@superblocksteam/util";
|
|
5
|
+
import { Listr } from "listr2";
|
|
6
|
+
import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
|
|
7
|
+
import { DEFAULT_BRANCH, FileStructureType, LATEST_EDITS_MODE, MULTI_SELECT_PROMPT_HELP, atLeastOneSelection, deleteResourcesAndUpdateRootConfig, getCurrentGitBranchIfGit, getFileStructureType, getMode, isCI, modeFlagValuesMap, writeMultiPageApplicationToDisk, writeResourceToDisk, } from "../common/version-control.mjs";
|
|
8
|
+
export default class Pull extends AuthenticatedCommand {
|
|
9
|
+
static description = "Download objects from Superblocks and save them locally";
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %>",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> apps/my-app",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> apps/my-app -b feature-branch",
|
|
14
|
+
"<%= config.bin %> <%= command.id %> apps/my-app -c commit-id",
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
mode: Flags.string({
|
|
18
|
+
char: "m",
|
|
19
|
+
description: "Pull mode",
|
|
20
|
+
options: Object.keys(modeFlagValuesMap),
|
|
21
|
+
default: LATEST_EDITS_MODE,
|
|
22
|
+
}),
|
|
23
|
+
branch: Flags.string({
|
|
24
|
+
char: "b",
|
|
25
|
+
description: "Superblocks branch to pull from, the current git branch will be used by default",
|
|
26
|
+
}),
|
|
27
|
+
"commit-id": Flags.string({
|
|
28
|
+
char: "c",
|
|
29
|
+
description: "Superblocks commit id to pull, the live edit will be used by default",
|
|
30
|
+
}),
|
|
31
|
+
"skip-signing-verification": Flags.boolean({
|
|
32
|
+
char: "s",
|
|
33
|
+
description: "If true, signature verification for signing enabled organizations will be skipped.",
|
|
34
|
+
default: false,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
static args = {
|
|
38
|
+
resource_path: Args.string({
|
|
39
|
+
description: "Superblocks resource location to pull (i.e. apps/my-app)",
|
|
40
|
+
required: false,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
12
43
|
async run() {
|
|
13
44
|
const { flags, args } = await this.parse(Pull);
|
|
14
45
|
const tasks = this.createTasks(args.resource_path, flags.mode, flags.branch, flags["skip-signing-verification"], flags["commit-id"]);
|
|
15
46
|
await tasks.run();
|
|
16
47
|
}
|
|
17
48
|
createTasks(resourcePath, mode, branch, skipSigningVerification = false, commitId) {
|
|
18
|
-
const tasks = new
|
|
49
|
+
const tasks = new Listr([
|
|
19
50
|
{
|
|
20
51
|
title: "Checking for existing Superblocks project...",
|
|
21
52
|
task: async (ctx) => {
|
|
22
53
|
ctx.writtenResources = {};
|
|
23
54
|
ctx.removedResourceIds = [];
|
|
55
|
+
ctx.featureFlags =
|
|
56
|
+
await this.getSdk().getFeatureFlagsForCurrentUser();
|
|
24
57
|
try {
|
|
25
58
|
[
|
|
26
59
|
ctx.existingSuperblocksRootConfig,
|
|
27
60
|
ctx.superblocksRootConfigPath,
|
|
28
|
-
] = await
|
|
61
|
+
] = await getSuperblocksMonorepoConfigJson(true);
|
|
29
62
|
ctx.existingSuperblocksResourceConfig =
|
|
30
|
-
await
|
|
31
|
-
ctx.superblocksRootPath =
|
|
63
|
+
await getSuperblocksResourceConfigIfExists();
|
|
64
|
+
ctx.superblocksRootPath = path.resolve(path.dirname(ctx.superblocksRootConfigPath), "..");
|
|
32
65
|
}
|
|
33
66
|
catch {
|
|
34
67
|
// no existing superblocks config
|
|
@@ -42,7 +75,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
42
75
|
ctx.branchToPullFrom = new Map();
|
|
43
76
|
try {
|
|
44
77
|
ctx.localBranchName =
|
|
45
|
-
branch || (await
|
|
78
|
+
branch || (await getCurrentGitBranchIfGit()) || DEFAULT_BRANCH;
|
|
46
79
|
}
|
|
47
80
|
catch (e) {
|
|
48
81
|
this.error(`Failed to check for existing git repository: ${e.message}. Please make sure to clone or initialize a git repository.`);
|
|
@@ -52,10 +85,9 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
52
85
|
{
|
|
53
86
|
title: "Checking for deleted Superblocks resources...",
|
|
54
87
|
task: async (ctx, task) => {
|
|
55
|
-
var _a, _b;
|
|
56
88
|
try {
|
|
57
|
-
for (const [resourceId, resource] of Object.entries(
|
|
58
|
-
switch (resource
|
|
89
|
+
for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
|
|
90
|
+
switch (resource?.resourceType) {
|
|
59
91
|
case "APPLICATION": {
|
|
60
92
|
try {
|
|
61
93
|
await this.getSdk().fetchApplication({
|
|
@@ -65,7 +97,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
65
97
|
});
|
|
66
98
|
}
|
|
67
99
|
catch (error) {
|
|
68
|
-
if (error instanceof
|
|
100
|
+
if (error instanceof NotFoundError) {
|
|
69
101
|
ctx.removedResourceIds.push(resourceId);
|
|
70
102
|
}
|
|
71
103
|
else {
|
|
@@ -83,7 +115,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
83
115
|
});
|
|
84
116
|
}
|
|
85
117
|
catch (error) {
|
|
86
|
-
if (error instanceof
|
|
118
|
+
if (error instanceof NotFoundError) {
|
|
87
119
|
ctx.removedResourceIds.push(resourceId);
|
|
88
120
|
}
|
|
89
121
|
else {
|
|
@@ -116,7 +148,7 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
116
148
|
},
|
|
117
149
|
]);
|
|
118
150
|
if (removeResourcesFromDisk) {
|
|
119
|
-
await
|
|
151
|
+
await deleteResourcesAndUpdateRootConfig(ctx.removedResourceIds, ctx.existingSuperblocksRootConfig, ctx.superblocksRootPath, ctx.superblocksRootConfigPath);
|
|
120
152
|
}
|
|
121
153
|
}
|
|
122
154
|
catch (e) {
|
|
@@ -132,22 +164,21 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
132
164
|
},
|
|
133
165
|
{
|
|
134
166
|
task: async (ctx, task) => {
|
|
135
|
-
var _a, _b;
|
|
136
167
|
task.title = `Validating git configuration...`;
|
|
137
168
|
const subtasks = [];
|
|
138
169
|
ctx.resourceIdsToSkip = new Set();
|
|
139
170
|
for (const resourceId of ctx.resourceIdsToPull) {
|
|
140
|
-
const resource =
|
|
141
|
-
const resourceTitle = `${(
|
|
171
|
+
const resource = ctx.existingSuperblocksRootConfig?.resources[resourceId];
|
|
172
|
+
const resourceTitle = `${(resource.resourceType ?? "").toLowerCase()} ${resourceId}`;
|
|
142
173
|
subtasks.push({
|
|
143
174
|
title: `Checking ${resourceTitle}...`,
|
|
144
175
|
task: async () => {
|
|
145
176
|
try {
|
|
146
|
-
const { branchName } = await this.validateGitSetup(resource
|
|
177
|
+
const { branchName } = await this.validateGitSetup(resource?.resourceType, resourceId, ComponentEvent.PULL, ctx.localBranchName);
|
|
147
178
|
ctx.branchToPullFrom.set(resourceId, branchName);
|
|
148
179
|
}
|
|
149
180
|
catch (error) {
|
|
150
|
-
if (
|
|
181
|
+
if (isCI() && error instanceof ValidateGitSetupError) {
|
|
151
182
|
this.log(`WARN: Failed to validate git setup for ${resourceTitle}. Skipping pull.\n\n${error.message}.`);
|
|
152
183
|
ctx.resourceIdsToSkip.add(resourceId);
|
|
153
184
|
}
|
|
@@ -179,31 +210,30 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
179
210
|
},
|
|
180
211
|
{
|
|
181
212
|
task: async (ctx, task) => {
|
|
182
|
-
var _a, _b;
|
|
183
213
|
task.title = `Pulling resources from branch ${ctx.localBranchName}...`;
|
|
184
214
|
let viewMode;
|
|
185
215
|
if (commitId) {
|
|
186
216
|
viewMode = "export-commit";
|
|
187
217
|
}
|
|
188
218
|
else {
|
|
189
|
-
viewMode = await
|
|
219
|
+
viewMode = await getMode(task, mode);
|
|
190
220
|
}
|
|
191
221
|
const subtasks = [];
|
|
192
222
|
for (const resourceId of ctx.resourceIdsToPull) {
|
|
193
|
-
const resource =
|
|
194
|
-
const branchName =
|
|
195
|
-
switch (resource
|
|
223
|
+
const resource = ctx.existingSuperblocksRootConfig?.resources[resourceId];
|
|
224
|
+
const branchName = ctx.branchToPullFrom.get(resourceId) ?? ctx.localBranchName;
|
|
225
|
+
switch (resource?.resourceType) {
|
|
196
226
|
case "APPLICATION": {
|
|
197
227
|
subtasks.push({
|
|
198
228
|
title: `Pulling application ${resource.location} from branch ${branchName}...`,
|
|
199
229
|
task: async (_ctx, task) => {
|
|
200
230
|
const headers = {
|
|
201
|
-
[
|
|
231
|
+
[COMPONENT_EVENT_HEADER]: ComponentEvent.PULL,
|
|
202
232
|
};
|
|
203
233
|
try {
|
|
204
234
|
task.title += `: fetched`;
|
|
205
|
-
const fileStructureType = await
|
|
206
|
-
if (fileStructureType ===
|
|
235
|
+
const fileStructureType = await getFileStructureType(ctx.superblocksRootPath, resource.location);
|
|
236
|
+
if (fileStructureType === FileStructureType.SINGLE_PAGE) {
|
|
207
237
|
this.error(`Application files at ${resource.location} are in single page format, but the multi-page feature is enabled for your account. Please run superblocks migrate to convert your application to multi-page format and commit the changes before pulling.`);
|
|
208
238
|
}
|
|
209
239
|
else {
|
|
@@ -219,12 +249,12 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
219
249
|
return;
|
|
220
250
|
}
|
|
221
251
|
ctx.writtenResources[resourceId] =
|
|
222
|
-
await
|
|
252
|
+
await writeMultiPageApplicationToDisk(application, ctx.superblocksRootPath, ctx.featureFlags, resource.location, false);
|
|
223
253
|
}
|
|
224
254
|
task.title += `: done`;
|
|
225
255
|
}
|
|
226
256
|
catch (e) {
|
|
227
|
-
if (e instanceof
|
|
257
|
+
if (e instanceof NotFoundError) {
|
|
228
258
|
//NOTE(alex): today, branches are not shared between applications, so we can't pull from a branch that doesn't exist in the current application
|
|
229
259
|
//once we have shared branches, we can remove this catch block
|
|
230
260
|
task.title += `: not found in this branch. skipped`;
|
|
@@ -250,7 +280,7 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
250
280
|
});
|
|
251
281
|
task.title += `: fetched`;
|
|
252
282
|
ctx.writtenResources[resourceId] =
|
|
253
|
-
await
|
|
283
|
+
await writeResourceToDisk("BACKEND", resourceId, backend, ctx.superblocksRootPath, ctx.featureFlags, resource.location);
|
|
254
284
|
task.title += `: done`;
|
|
255
285
|
},
|
|
256
286
|
});
|
|
@@ -273,23 +303,22 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
273
303
|
return tasks;
|
|
274
304
|
}
|
|
275
305
|
async getResourceIdsToPull(ctx, task, resourcePath) {
|
|
276
|
-
var _a, _b, _c, _d, _e;
|
|
277
306
|
if (resourcePath) {
|
|
278
|
-
for (const [resourceId, resource] of Object.entries(
|
|
307
|
+
for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
|
|
279
308
|
if (resource.location === resourcePath) {
|
|
280
309
|
return [resourceId];
|
|
281
310
|
}
|
|
282
311
|
}
|
|
283
312
|
throw new Error(`No resource found with the given location: ${resourcePath}`);
|
|
284
313
|
}
|
|
285
|
-
const resourceConfig = await
|
|
314
|
+
const resourceConfig = await getSuperblocksResourceConfigIfExists();
|
|
286
315
|
if (resourceConfig) {
|
|
287
316
|
return [resourceConfig.id];
|
|
288
317
|
}
|
|
289
318
|
const choices = [];
|
|
290
319
|
const initialSelections = [];
|
|
291
320
|
let counter = 0;
|
|
292
|
-
for (const [resourceId, resource] of Object.entries(
|
|
321
|
+
for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
|
|
293
322
|
if (ctx.removedResourceIds.includes(resourceId)) {
|
|
294
323
|
continue;
|
|
295
324
|
}
|
|
@@ -297,7 +326,7 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
297
326
|
name: resourceId,
|
|
298
327
|
message: resource.location,
|
|
299
328
|
});
|
|
300
|
-
if (
|
|
329
|
+
if (ctx.existingSuperblocksResourceConfig?.id === resourceId) {
|
|
301
330
|
initialSelections.push(counter);
|
|
302
331
|
}
|
|
303
332
|
counter++;
|
|
@@ -308,10 +337,10 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
308
337
|
{
|
|
309
338
|
type: "MultiSelect",
|
|
310
339
|
name: "resourceIdsToPull",
|
|
311
|
-
message: `Select resources to pull (${
|
|
340
|
+
message: `Select resources to pull (${MULTI_SELECT_PROMPT_HELP})`,
|
|
312
341
|
choices: choices,
|
|
313
342
|
initial: initialSelections,
|
|
314
|
-
validate:
|
|
343
|
+
validate: atLeastOneSelection,
|
|
315
344
|
prefix: "▸",
|
|
316
345
|
indicator: "◉",
|
|
317
346
|
},
|
|
@@ -319,38 +348,3 @@ Would you like to also delete these resources from your filesystem?`,
|
|
|
319
348
|
return resourceIdsToPull;
|
|
320
349
|
}
|
|
321
350
|
}
|
|
322
|
-
Pull.description = "Download objects from Superblocks and save them locally";
|
|
323
|
-
Pull.examples = [
|
|
324
|
-
"<%= config.bin %> <%= command.id %>",
|
|
325
|
-
"<%= config.bin %> <%= command.id %> apps/my-app",
|
|
326
|
-
"<%= config.bin %> <%= command.id %> apps/my-app -b feature-branch",
|
|
327
|
-
"<%= config.bin %> <%= command.id %> apps/my-app -c commit-id",
|
|
328
|
-
];
|
|
329
|
-
Pull.flags = {
|
|
330
|
-
mode: core_1.Flags.string({
|
|
331
|
-
char: "m",
|
|
332
|
-
description: "Pull mode",
|
|
333
|
-
options: Object.keys(version_control_1.modeFlagValuesMap),
|
|
334
|
-
default: version_control_1.LATEST_EDITS_MODE,
|
|
335
|
-
}),
|
|
336
|
-
branch: core_1.Flags.string({
|
|
337
|
-
char: "b",
|
|
338
|
-
description: "Superblocks branch to pull from, the current git branch will be used by default",
|
|
339
|
-
}),
|
|
340
|
-
"commit-id": core_1.Flags.string({
|
|
341
|
-
char: "c",
|
|
342
|
-
description: "Superblocks commit id to pull, the live edit will be used by default",
|
|
343
|
-
}),
|
|
344
|
-
"skip-signing-verification": core_1.Flags.boolean({
|
|
345
|
-
char: "s",
|
|
346
|
-
description: "If true, signature verification for signing enabled organizations will be skipped.",
|
|
347
|
-
default: false,
|
|
348
|
-
}),
|
|
349
|
-
};
|
|
350
|
-
Pull.args = {
|
|
351
|
-
resource_path: core_1.Args.string({
|
|
352
|
-
description: "Superblocks resource location to pull (i.e. apps/my-app)",
|
|
353
|
-
required: false,
|
|
354
|
-
}),
|
|
355
|
-
};
|
|
356
|
-
exports.default = Pull;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
|
|
2
|
+
export default class Push extends AuthenticatedCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
"skip-commit": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
};
|
|
9
|
+
static args: {
|
|
10
|
+
resource_path: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private createTasks;
|
|
14
|
+
private getResourceIdsToPush;
|
|
15
|
+
}
|