@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.
Files changed (59) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +6 -6
  3. package/assets/custom-components/setup/package.json +1 -1
  4. package/assets/custom-components/setup/tsconfig.json +0 -1
  5. package/assets/injectedReactShim17.jsx +15 -0
  6. package/assets/injectedReactShim18.jsx +16 -0
  7. package/assets/injectedReactShimShared.jsx +140 -0
  8. package/bin/dev +5 -7
  9. package/bin/run +1 -3
  10. package/dist/appendHotReloadEventPlugin.d.mts +2 -0
  11. package/dist/appendHotReloadEventPlugin.mjs +43 -0
  12. package/dist/commands/commits.d.mts +18 -0
  13. package/dist/commands/{commits.js → commits.mjs} +59 -67
  14. package/dist/commands/components/{create.d.ts → create.d.mts} +2 -2
  15. package/dist/commands/components/{create.js → create.mjs} +84 -93
  16. package/dist/commands/components/{register.d.ts → register.d.mts} +1 -1
  17. package/dist/commands/components/register.mjs +12 -0
  18. package/dist/commands/components/{upload.d.ts → upload.d.mts} +2 -2
  19. package/dist/commands/components/{upload.js → upload.mjs} +39 -43
  20. package/dist/commands/components/{watch.d.ts → watch.d.mts} +1 -1
  21. package/dist/commands/components/{watch.js → watch.mjs} +29 -36
  22. package/dist/commands/config/{set.d.ts → set.d.mts} +2 -2
  23. package/dist/commands/config/{set.js → set.mjs} +28 -32
  24. package/dist/commands/{init.d.ts → init.d.mts} +4 -4
  25. package/dist/commands/{init.js → init.mjs} +63 -65
  26. package/dist/commands/{login.d.ts → login.d.mts} +1 -1
  27. package/dist/commands/login.mjs +55 -0
  28. package/dist/commands/{migrate.d.ts → migrate.d.mts} +1 -1
  29. package/dist/commands/{migrate.js → migrate.mjs} +38 -46
  30. package/dist/commands/pull.d.mts +17 -0
  31. package/dist/commands/{pull.js → pull.mjs} +74 -80
  32. package/dist/commands/push.d.mts +15 -0
  33. package/dist/commands/{push.js → push.mjs} +81 -90
  34. package/dist/commands/{rm.d.ts → rm.d.mts} +2 -2
  35. package/dist/commands/{rm.js → rm.mjs} +34 -40
  36. package/dist/common/{authenticated-command.js → authenticated-command.mjs} +65 -75
  37. package/dist/common/defaults/{create-component-defaults.js → create-component-defaults.mjs} +2 -7
  38. package/dist/common/{version-control.d.ts → version-control.d.mts} +13 -6
  39. package/dist/common/version-control.mjs +1064 -0
  40. package/dist/index.js +1 -5
  41. package/dist/productionCssPlugin.d.mts +2 -0
  42. package/dist/productionCssPlugin.mjs +50 -0
  43. package/dist/reactShimPlugin.d.mts +2 -0
  44. package/dist/reactShimPlugin.mjs +127 -0
  45. package/dist/util/migrationWarningsForApplications.mjs +47 -0
  46. package/dist/util/{migrationsForDotfiles.js → migrationsForDotfiles.mjs} +10 -17
  47. package/oclif.manifest.json +274 -161
  48. package/package.json +45 -45
  49. package/dist/commands/commits.d.ts +0 -18
  50. package/dist/commands/components/register.js +0 -15
  51. package/dist/commands/login.js +0 -61
  52. package/dist/commands/pull.d.ts +0 -17
  53. package/dist/commands/push.d.ts +0 -15
  54. package/dist/common/version-control.js +0 -716
  55. package/dist/util/migrationWarningsForApplications.js +0 -52
  56. /package/dist/common/{authenticated-command.d.ts → authenticated-command.d.mts} +0 -0
  57. /package/dist/common/defaults/{create-component-defaults.d.ts → create-component-defaults.d.mts} +0 -0
  58. /package/dist/util/{migrationWarningsForApplications.d.ts → migrationWarningsForApplications.d.mts} +0 -0
  59. /package/dist/util/{migrationsForDotfiles.d.ts → migrationsForDotfiles.d.mts} +0 -0
@@ -1,34 +1,67 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
5
- const core_1 = require("@oclif/core");
6
- const sdk_1 = require("@superblocksteam/sdk");
7
- const util_1 = require("@superblocksteam/util");
8
- const listr2_1 = require("listr2");
9
- const authenticated_command_1 = require("../common/authenticated-command");
10
- const version_control_1 = require("../common/version-control");
11
- class Pull extends authenticated_command_1.AuthenticatedCommand {
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 listr2_1.Listr([
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 (0, util_1.getSuperblocksMonorepoConfigJson)(true);
61
+ ] = await getSuperblocksMonorepoConfigJson(true);
29
62
  ctx.existingSuperblocksResourceConfig =
30
- await (0, util_1.getSuperblocksResourceConfigIfExists)();
31
- ctx.superblocksRootPath = node_path_1.default.resolve(node_path_1.default.dirname(ctx.superblocksRootConfigPath), "..");
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 (0, version_control_1.getCurrentGitBranchIfGit)()) || version_control_1.DEFAULT_BRANCH;
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((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
58
- switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
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 util_1.NotFoundError) {
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 util_1.NotFoundError) {
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 (0, version_control_1.deleteResourcesAndUpdateRootConfig)(ctx.removedResourceIds, ctx.existingSuperblocksRootConfig, ctx.superblocksRootPath, ctx.superblocksRootConfigPath);
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 = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId];
141
- const resourceTitle = `${((_b = resource.resourceType) !== null && _b !== void 0 ? _b : "").toLowerCase()} ${resourceId}`;
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 === null || resource === void 0 ? void 0 : resource.resourceType, resourceId, util_1.ComponentEvent.PULL, ctx.localBranchName);
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 ((0, version_control_1.isCI)() && error instanceof sdk_1.ValidateGitSetupError) {
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 (0, version_control_1.getMode)(task, mode);
219
+ viewMode = await getMode(task, mode);
190
220
  }
191
221
  const subtasks = [];
192
222
  for (const resourceId of ctx.resourceIdsToPull) {
193
- const resource = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId];
194
- const branchName = (_b = ctx.branchToPullFrom.get(resourceId)) !== null && _b !== void 0 ? _b : ctx.localBranchName;
195
- switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
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
- [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.PULL,
231
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.PULL,
202
232
  };
203
233
  try {
204
234
  task.title += `: fetched`;
205
- const fileStructureType = await (0, version_control_1.getFileStructureType)(ctx.superblocksRootPath, resource.location);
206
- if (fileStructureType === version_control_1.FileStructureType.SINGLE_PAGE) {
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 (0, version_control_1.writeMultiPageApplicationToDisk)(application, ctx.superblocksRootPath, resource.location, false);
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 util_1.NotFoundError) {
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 (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, ctx.superblocksRootPath, resource.location);
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((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
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 (0, util_1.getSuperblocksResourceConfigIfExists)();
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((_d = (_c = ctx.existingSuperblocksRootConfig) === null || _c === void 0 ? void 0 : _c.resources) !== null && _d !== void 0 ? _d : {})) {
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 (((_e = ctx.existingSuperblocksResourceConfig) === null || _e === void 0 ? void 0 : _e.id) === resourceId) {
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 (${version_control_1.MULTI_SELECT_PROMPT_HELP})`,
340
+ message: `Select resources to pull (${MULTI_SELECT_PROMPT_HELP})`,
312
341
  choices: choices,
313
342
  initial: initialSelections,
314
- validate: version_control_1.atLeastOneSelection,
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
+ }