@superblocksteam/cli 1.10.0 → 1.13.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 (56) 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/bin/dev +5 -7
  6. package/bin/run +1 -3
  7. package/dist/appendHotReloadEventPlugin.mjs +43 -0
  8. package/dist/commands/commits.d.mts +18 -0
  9. package/dist/commands/{commits.js → commits.mjs} +59 -67
  10. package/dist/commands/components/{create.d.ts → create.d.mts} +2 -2
  11. package/dist/commands/components/{create.js → create.mjs} +84 -93
  12. package/dist/commands/components/{register.d.ts → register.d.mts} +1 -1
  13. package/dist/commands/components/register.mjs +12 -0
  14. package/dist/commands/components/{upload.d.ts → upload.d.mts} +2 -2
  15. package/dist/commands/components/{upload.js → upload.mjs} +39 -43
  16. package/dist/commands/components/{watch.d.ts → watch.d.mts} +1 -1
  17. package/dist/commands/components/{watch.js → watch.mjs} +29 -36
  18. package/dist/commands/config/{set.d.ts → set.d.mts} +2 -2
  19. package/dist/commands/config/{set.js → set.mjs} +28 -32
  20. package/dist/commands/{init.d.ts → init.d.mts} +4 -4
  21. package/dist/commands/{init.js → init.mjs} +58 -64
  22. package/dist/commands/{login.d.ts → login.d.mts} +1 -1
  23. package/dist/commands/login.mjs +55 -0
  24. package/dist/commands/{migrate.d.ts → migrate.d.mts} +1 -1
  25. package/dist/commands/{migrate.js → migrate.mjs} +34 -42
  26. package/dist/commands/pull.d.mts +17 -0
  27. package/dist/commands/{pull.js → pull.mjs} +72 -80
  28. package/dist/commands/push.d.mts +15 -0
  29. package/dist/commands/{push.js → push.mjs} +81 -90
  30. package/dist/commands/{rm.d.ts → rm.d.mts} +2 -2
  31. package/dist/commands/{rm.js → rm.mjs} +34 -40
  32. package/dist/common/{authenticated-command.js → authenticated-command.mjs} +65 -75
  33. package/dist/common/defaults/{create-component-defaults.js → create-component-defaults.mjs} +2 -7
  34. package/dist/common/{version-control.d.ts → version-control.d.mts} +1 -1
  35. package/dist/common/{version-control.js → version-control.mjs} +170 -202
  36. package/dist/index.js +1 -5
  37. package/dist/{productionCssPlugin.js → productionCssPlugin.mjs} +4 -10
  38. package/dist/{reactShimPlugin.js → reactShimPlugin.mjs} +17 -24
  39. package/dist/util/migrationWarningsForApplications.mjs +47 -0
  40. package/dist/util/{migrationsForDotfiles.js → migrationsForDotfiles.mjs} +10 -17
  41. package/oclif.manifest.json +284 -171
  42. package/package.json +43 -41
  43. package/dist/appendHotReloadEventPlugin.js +0 -48
  44. package/dist/commands/commits.d.ts +0 -18
  45. package/dist/commands/components/register.js +0 -15
  46. package/dist/commands/login.js +0 -61
  47. package/dist/commands/pull.d.ts +0 -17
  48. package/dist/commands/push.d.ts +0 -15
  49. package/dist/util/migrationWarningsForApplications.js +0 -52
  50. /package/dist/{appendHotReloadEventPlugin.d.ts → appendHotReloadEventPlugin.d.mts} +0 -0
  51. /package/dist/common/{authenticated-command.d.ts → authenticated-command.d.mts} +0 -0
  52. /package/dist/common/defaults/{create-component-defaults.d.ts → create-component-defaults.d.mts} +0 -0
  53. /package/dist/{productionCssPlugin.d.ts → productionCssPlugin.d.mts} +0 -0
  54. /package/dist/{reactShimPlugin.d.ts → reactShimPlugin.d.mts} +0 -0
  55. /package/dist/util/{migrationWarningsForApplications.d.ts → migrationWarningsForApplications.d.mts} +0 -0
  56. /package/dist/util/{migrationsForDotfiles.d.ts → migrationsForDotfiles.d.mts} +0 -0
@@ -1,27 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthenticatedApplicationCommand = exports.AuthenticatedCommand = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
- const core_1 = require("@oclif/core");
7
- const sdk_1 = require("@superblocksteam/sdk");
8
- const util_1 = require("@superblocksteam/util");
9
- const colorette_1 = require("colorette");
10
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
- const semver_1 = tslib_1.__importDefault(require("semver"));
12
- const migrationWarningsForApplications_1 = require("../util/migrationWarningsForApplications");
13
- const migrationsForDotfiles_1 = require("../util/migrationsForDotfiles");
14
- const version_control_1 = require("./version-control");
15
- class AuthenticatedCommand extends core_1.Command {
1
+ import path from "node:path";
2
+ import { Command, ux } from "@oclif/core";
3
+ import { SuperblocksSdk } from "@superblocksteam/sdk";
4
+ import { ComponentEvent, CUSTOM_COMPONENTS_PATH, getComponentConfigs, getLocalTokenWithUrl, getLocalTokenWithUrlIfExists, getSuperblocksApplicationConfigJson, getSuperblocksMonorepoConfigJson, } from "@superblocksteam/util";
5
+ import { cyan } from "colorette";
6
+ import fs from "fs-extra";
7
+ import semver from "semver";
8
+ import { getWarningsForApplicationMigration } from "../util/migrationWarningsForApplications.mjs";
9
+ import { isDotfileMigrationNeeded, migrateSuperblocksEntityConfig, migrateSuperblocksMonorepoConfig, } from "../util/migrationsForDotfiles.mjs";
10
+ import { DEFAULT_BRANCH, getLocalGitRepoState, sortByKey, } from "./version-control.mjs";
11
+ export class AuthenticatedCommand extends Command {
12
+ sdk;
16
13
  async init() {
17
14
  await super.init();
18
15
  try {
19
- const result = await (0, util_1.getLocalTokenWithUrl)();
16
+ const result = await getLocalTokenWithUrl();
20
17
  if (!("token" in result)) {
21
18
  throw new Error();
22
19
  }
23
20
  const { token, superblocksBaseUrl } = result;
24
- this.sdk = new sdk_1.SuperblocksSdk(token, superblocksBaseUrl, this.config.version);
21
+ this.sdk = new SuperblocksSdk(token, superblocksBaseUrl, this.config.version);
25
22
  await this.runAutomatedDotfileUpdates();
26
23
  }
27
24
  catch (e) {
@@ -30,7 +27,7 @@ class AuthenticatedCommand extends core_1.Command {
30
27
  }
31
28
  }
32
29
  async validateGitSetup(resourceType, resourceId, event, overrideLocalBranch, injectedHeaders) {
33
- const localGitRepoState = await (0, version_control_1.getLocalGitRepoState)(overrideLocalBranch);
30
+ const localGitRepoState = await getLocalGitRepoState(overrideLocalBranch);
34
31
  const { branchName } = await this.getSdk().validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders);
35
32
  return {
36
33
  branchName,
@@ -40,9 +37,8 @@ class AuthenticatedCommand extends core_1.Command {
40
37
  };
41
38
  }
42
39
  async getBaseUrl() {
43
- var _a;
44
- const result = await (0, util_1.getLocalTokenWithUrlIfExists)();
45
- return (_a = result === null || result === void 0 ? void 0 : result.superblocksBaseUrl) !== null && _a !== void 0 ? _a : "";
40
+ const result = await getLocalTokenWithUrlIfExists();
41
+ return result?.superblocksBaseUrl ?? "";
46
42
  }
47
43
  getSdk() {
48
44
  if (!this.sdk) {
@@ -54,7 +50,8 @@ class AuthenticatedCommand extends core_1.Command {
54
50
  let previousConfig;
55
51
  let rootConfigPath;
56
52
  try {
57
- [previousConfig, rootConfigPath] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
53
+ [previousConfig, rootConfigPath] =
54
+ await getSuperblocksMonorepoConfigJson(true);
58
55
  }
59
56
  catch {
60
57
  // This might fail for a brand-new project folder, which is deliberately ignored
@@ -62,25 +59,25 @@ class AuthenticatedCommand extends core_1.Command {
62
59
  }
63
60
  if (previousConfig &&
64
61
  rootConfigPath &&
65
- (0, migrationsForDotfiles_1.isDotfileMigrationNeeded)(previousConfig.metadata.cliVersion, this.config.version)) {
62
+ isDotfileMigrationNeeded(previousConfig.metadata.cliVersion, this.config.version)) {
66
63
  this.log(`Migrating Superblocks settings from ${previousConfig.metadata.cliVersion} to ${this.config.version}...`);
67
64
  try {
68
- const newConfig = await (0, migrationsForDotfiles_1.migrateSuperblocksMonorepoConfig)(previousConfig, {
65
+ const newConfig = await migrateSuperblocksMonorepoConfig(previousConfig, {
69
66
  previousVersion: previousConfig.metadata.cliVersion,
70
67
  currentVersion: this.config.version,
71
68
  });
72
- await fs_extra_1.default.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(newConfig), null, 2));
69
+ await fs.writeFile(rootConfigPath, JSON.stringify(sortByKey(newConfig), null, 2));
73
70
  await Promise.all(Object.entries(newConfig.resources).map(async ([, resource]) => {
74
71
  this.log(`Migrating ${resource.location}`);
75
72
  try {
76
- const resourcePath = node_path_1.default.join(rootConfigPath, "../..", resource.location, ".superblocks/superblocks.json");
77
- const resourceConfig = await fs_extra_1.default.readJSON(resourcePath);
78
- const newConfig = await (0, migrationsForDotfiles_1.migrateSuperblocksEntityConfig)(resourceConfig, {
73
+ const resourcePath = path.join(rootConfigPath, "../..", resource.location, ".superblocks/superblocks.json");
74
+ const resourceConfig = await fs.readJSON(resourcePath);
75
+ const newConfig = await migrateSuperblocksEntityConfig(resourceConfig, {
79
76
  previousVersion: previousConfig
80
77
  .metadata.cliVersion,
81
78
  currentVersion: this.config.version,
82
79
  });
83
- await fs_extra_1.default.writeFile(resourcePath, JSON.stringify((0, version_control_1.sortByKey)(newConfig), null, 2));
80
+ await fs.writeFile(resourcePath, JSON.stringify(sortByKey(newConfig), null, 2));
84
81
  }
85
82
  catch (e) {
86
83
  this.error(e);
@@ -88,14 +85,14 @@ class AuthenticatedCommand extends core_1.Command {
88
85
  }));
89
86
  this.log(`Finalizing migration`);
90
87
  this.log(`After upgrading the CLI version, you may need to perform additional migrations using
91
- ${(0, colorette_1.cyan)("superblocks migrate")}`);
88
+ ${cyan("superblocks migrate")}`);
92
89
  }
93
90
  catch (e) {
94
91
  this.error(e);
95
92
  }
96
93
  }
97
94
  if (previousConfig.metadata.cliVersion) {
98
- const warningMessage = (0, migrationWarningsForApplications_1.getWarningsForApplicationMigration)(previousConfig.metadata.cliVersion, this.config.version);
95
+ const warningMessage = getWarningsForApplicationMigration(previousConfig.metadata.cliVersion, this.config.version);
99
96
  if (warningMessage) {
100
97
  this.log(warningMessage);
101
98
  }
@@ -103,54 +100,49 @@ ${(0, colorette_1.cyan)("superblocks migrate")}`);
103
100
  // Always upgrade the root config even if there's no migration
104
101
  if (rootConfigPath) {
105
102
  previousConfig.metadata.cliVersion = this.config.version;
106
- await fs_extra_1.default.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(previousConfig), null, 2));
103
+ await fs.writeFile(rootConfigPath, JSON.stringify(sortByKey(previousConfig), null, 2));
107
104
  }
108
105
  }
109
106
  }
110
- exports.AuthenticatedCommand = AuthenticatedCommand;
111
- class AuthenticatedApplicationCommand extends AuthenticatedCommand {
112
- constructor() {
113
- super(...arguments);
114
- this.applicationConfig = {
115
- configType: "APPLICATION",
116
- id: "",
117
- defaultPageId: "",
118
- apis: {},
119
- };
120
- }
107
+ export class AuthenticatedApplicationCommand extends AuthenticatedCommand {
108
+ applicationConfig = {
109
+ configType: "APPLICATION",
110
+ id: "",
111
+ defaultPageId: "",
112
+ apis: {},
113
+ };
121
114
  async getEditModeUrl() {
122
- const result = await (0, util_1.getLocalTokenWithUrlIfExists)();
123
- const baseUrl = typeof result === "string" ? result : result === null || result === void 0 ? void 0 : result.superblocksBaseUrl;
115
+ const result = await getLocalTokenWithUrlIfExists();
116
+ const baseUrl = typeof result === "string" ? result : result?.superblocksBaseUrl;
124
117
  return new URL(`/applications/edit/${this.applicationConfig.id}`, baseUrl).toString();
125
118
  }
126
119
  async init() {
127
- var _a, _b;
128
120
  await super.init();
129
121
  try {
130
- this.applicationConfig = await (0, util_1.getSuperblocksApplicationConfigJson)();
122
+ this.applicationConfig = await getSuperblocksApplicationConfigJson();
131
123
  }
132
124
  catch (error) {
133
125
  this.error(error.message, {
134
126
  exit: 1,
135
127
  });
136
128
  }
137
- const { branchName } = await this.validateApplicationGitSetup(util_1.ComponentEvent.INIT);
138
- core_1.ux.action.start("Checking application...");
129
+ const { branchName } = await this.validateApplicationGitSetup(ComponentEvent.INIT);
130
+ ux.action.start("Checking application...");
139
131
  try {
140
132
  const application = await this.getSdk().fetchApplication({
141
133
  applicationId: this.applicationConfig.id,
142
- branch: branchName !== null && branchName !== void 0 ? branchName : version_control_1.DEFAULT_BRANCH,
134
+ branch: branchName ?? DEFAULT_BRANCH,
143
135
  });
144
- core_1.ux.action.stop();
145
- if ((_b = (_a = application === null || application === void 0 ? void 0 : application.application) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.cliVersion) {
146
- const warningMessage = (0, migrationWarningsForApplications_1.getWarningsForApplicationMigration)(application.application.settings.cliVersion, this.config.version);
136
+ ux.action.stop();
137
+ if (application?.application?.settings?.cliVersion) {
138
+ const warningMessage = getWarningsForApplicationMigration(application.application.settings.cliVersion, this.config.version);
147
139
  if (warningMessage) {
148
140
  this.log(warningMessage);
149
141
  }
150
142
  }
151
143
  }
152
144
  catch (e) {
153
- core_1.ux.action.stop();
145
+ ux.action.stop();
154
146
  this.warn(`Could not read the application from Superblocks: ${e.message}`);
155
147
  }
156
148
  }
@@ -158,64 +150,62 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
158
150
  return this.validateGitSetup("APPLICATION", this.applicationConfig.id, event, overrideLocalBranch, injectedHeaders);
159
151
  }
160
152
  async registerComponents(injectedHeaders) {
161
- var _a;
162
- core_1.ux.action.start("Checking CLI version compatibility...");
153
+ ux.action.start("Checking CLI version compatibility...");
163
154
  try {
164
- const packageJson = await fs_extra_1.default.readJson("package.json");
165
- const versionStr = (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["@superblocksteam/custom-components"];
155
+ const packageJson = await fs.readJson("package.json");
156
+ const versionStr = packageJson.dependencies?.["@superblocksteam/custom-components"];
166
157
  if (!versionStr) {
167
158
  throw new Error(`You must install the @superblocksteam/custom-components library as a dependency in your package.json file. Run:
168
159
 
169
- ${(0, colorette_1.cyan)("superblocks migrate")}`);
160
+ ${cyan("superblocks migrate")}`);
170
161
  }
171
162
  if (versionStr.startsWith("file:")) {
172
163
  this.warn(`You are using a local version of the @superblocksteam/custom-components library. It is not possible to check its version compatibility with the CLI.`);
173
164
  }
174
- else if (!semver_1.default.satisfies(this.config.version, versionStr)) {
165
+ else if (!semver.satisfies(this.config.version, versionStr)) {
175
166
  throw new Error(`You must upgrade the @superblocksteam/custom-components library. You are using ${versionStr} but the CLI is ${this.config.version}. Run:
176
167
 
177
- ${(0, colorette_1.cyan)("superblocks migrate")}`);
168
+ ${cyan("superblocks migrate")}`);
178
169
  }
179
170
  }
180
171
  catch (e) {
181
- core_1.ux.action.stop();
172
+ ux.action.stop();
182
173
  this.error(e.message, {
183
174
  exit: 1,
184
175
  });
185
176
  }
186
- core_1.ux.action.stop();
187
- core_1.ux.action.start("Scanning for Superblocks components...");
188
- const exists = await fs_extra_1.default.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
177
+ ux.action.stop();
178
+ ux.action.start("Scanning for Superblocks components...");
179
+ const exists = await fs.pathExists(CUSTOM_COMPONENTS_PATH);
189
180
  if (!exists) {
190
- core_1.ux.action.stop();
181
+ ux.action.stop();
191
182
  this.error("No components folder found in current directory, please run 'superblocks components create' first", {
192
183
  exit: 1,
193
184
  });
194
185
  }
195
- const { configs, hasError } = await (0, util_1.getComponentConfigs)(true);
186
+ const { configs, hasError } = await getComponentConfigs(true);
196
187
  if (hasError) {
197
- core_1.ux.action.stop();
188
+ ux.action.stop();
198
189
  this.error("Failed to register components", { exit: 1 });
199
190
  // Stop immediately
200
191
  return;
201
192
  }
202
193
  if (configs.length === 0) {
203
- core_1.ux.action.stop();
194
+ ux.action.stop();
204
195
  this.log("No components found in current components directory, please run 'superblocks components create' first");
205
196
  }
206
- core_1.ux.action.stop();
197
+ ux.action.stop();
207
198
  try {
208
- core_1.ux.action.start("Registering components...");
209
- const { branchName } = await this.validateApplicationGitSetup(util_1.ComponentEvent.REGISTER);
199
+ ux.action.start("Registering components...");
200
+ const { branchName } = await this.validateApplicationGitSetup(ComponentEvent.REGISTER);
210
201
  await this.getSdk().registerComponents(this.applicationConfig.id, configs, branchName, injectedHeaders);
211
- core_1.ux.action.stop();
202
+ ux.action.stop();
212
203
  }
213
204
  catch (e) {
214
- core_1.ux.action.stop();
205
+ ux.action.stop();
215
206
  console.log(e.message);
216
207
  this.error("Failed to register components", { exit: 1 });
217
208
  }
218
209
  return configs;
219
210
  }
220
211
  }
221
- exports.AuthenticatedApplicationCommand = AuthenticatedApplicationCommand;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultComponentTsx = exports.getDefaultConfigTs = void 0;
4
1
  const indent = (str, spaces) => {
5
2
  const spacesString = " ".repeat(spaces);
6
3
  return str
@@ -8,7 +5,7 @@ const indent = (str, spaces) => {
8
5
  .map((line) => `${spacesString}${line}`)
9
6
  .join("\n");
10
7
  };
11
- const getDefaultConfigTs = ({ id, name, displayName, propertiesRendered, eventHandlersRendered, }) => `import { type ComponentConfig } from "@superblocksteam/custom-components";
8
+ export const getDefaultConfigTs = ({ id, name, displayName, propertiesRendered, eventHandlersRendered, }) => `import { type ComponentConfig } from "@superblocksteam/custom-components";
12
9
 
13
10
  export default {
14
11
  // DO NOT CHANGE THE ID ONCE THE COMPONENT HAS BEEN REGISTERED!
@@ -24,8 +21,7 @@ export default {
24
21
  },
25
22
  } satisfies ComponentConfig;
26
23
  `;
27
- exports.getDefaultConfigTs = getDefaultConfigTs;
28
- const getDefaultComponentTsx = (properties, eventHandlers) => `import { useSuperblocksContext, useSuperblocksIsLoading } from "@superblocksteam/custom-components";
24
+ export const getDefaultComponentTsx = (properties, eventHandlers) => `import { useSuperblocksContext, useSuperblocksIsLoading } from "@superblocksteam/custom-components";
29
25
  import { type Props, type EventTriggers } from "./types";
30
26
 
31
27
  export default function Component({${properties.length === 0
@@ -55,4 +51,3 @@ export default function Component({${properties.length === 0
55
51
  );
56
52
  }
57
53
  `;
58
- exports.getDefaultComponentTsx = getDefaultComponentTsx;
@@ -1,5 +1,5 @@
1
1
  import { ApiWrapper, ApplicationWrapper, FeatureFlags, MultiPageApplicationWrapper } from "@superblocksteam/sdk";
2
- import { Api, ViewMode } from "@superblocksteam/sdk/dist/types";
2
+ import { Api, ViewMode } from "@superblocksteam/sdk";
3
3
  import { LocalGitRepoState, SuperblocksMonorepoConfig, SuperblocksResourceConfig, VersionedResourceConfig, ApiInfo } from "@superblocksteam/util";
4
4
  export declare const LATEST_EDITS_MODE = "latest-edits";
5
5
  export declare const MOST_RECENT_COMMIT_MODE = "most-recent-commit";