@superblocksteam/cli 0.0.14 → 0.0.15

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/README.md CHANGED
@@ -12,7 +12,7 @@ $ npm install -g @superblocksteam/cli
12
12
  $ superblocks COMMAND
13
13
  running command...
14
14
  $ superblocks (--version)
15
- @superblocksteam/cli/0.0.14 linux-x64 node-v18.17.0
15
+ @superblocksteam/cli/0.0.15 linux-x64 node-v18.17.0
16
16
  $ superblocks --help [COMMAND]
17
17
  USAGE
18
18
  $ superblocks COMMAND
@@ -11,7 +11,7 @@
11
11
  "react-dom": "^18"
12
12
  },
13
13
  "devDependencies": {
14
- "@superblocksteam/cli": "0.0.14",
14
+ "@superblocksteam/cli": "0.0.15",
15
15
  "@types/react": "^18",
16
16
  "@types/react-dom": "^18",
17
17
  "@typescript-eslint/eslint-plugin": "^5.62.0",
@@ -7,7 +7,6 @@ const node_crypto_1 = require("node:crypto");
7
7
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
8
  const node_util_1 = tslib_1.__importDefault(require("node:util"));
9
9
  const core_1 = require("@oclif/core");
10
- const util_1 = require("@superblocksteam/util");
11
10
  const colorette_1 = require("colorette");
12
11
  const enquirer_1 = require("enquirer");
13
12
  const fs = tslib_1.__importStar(require("fs-extra"));
@@ -196,10 +195,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
196
195
  }
197
196
  core_1.ux.action.stop();
198
197
  }
199
- core_1.ux.action.start("Registering components...");
200
- const components = await (0, util_1.getComponentConfigs)();
201
- await this.getSdk().registerComponents(this.applicationConfig.id, components);
202
- core_1.ux.action.stop();
198
+ this.registerComponents();
203
199
  }
204
200
  }
205
201
  CreateComponent.description = "Creates a new Superblocks component in the current application folder";
@@ -1,36 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const core_1 = require("@oclif/core");
5
- const util_1 = require("@superblocksteam/util");
6
- const fs = tslib_1.__importStar(require("fs-extra"));
7
3
  const authenticated_command_1 = require("../../common/authenticated-command");
8
4
  class Register extends authenticated_command_1.AuthenticatedApplicationCommand {
9
5
  async run() {
10
- core_1.ux.action.start("Scanning for Superblocks components...");
11
- const exists = await fs.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
12
- if (!exists) {
13
- core_1.ux.action.stop();
14
- this.error("No components folder found in current directory, please run 'superblocks components create' first", {
15
- exit: 1,
16
- });
17
- }
18
- const configs = await (0, util_1.getComponentConfigs)();
19
- if (configs.length === 0) {
20
- core_1.ux.action.stop();
21
- this.log("No components found in current components directory, please run 'superblocks components create' first");
22
- }
23
- core_1.ux.action.stop();
24
- this.log(JSON.stringify(configs, null, 2));
25
- try {
26
- core_1.ux.action.start("Registering components...");
27
- await this.getSdk().registerComponents(this.applicationConfig.id, configs);
28
- core_1.ux.action.stop();
29
- }
30
- catch {
31
- core_1.ux.action.stop();
32
- this.error("Failed to register components", { exit: 1 });
33
- }
6
+ await this.registerComponents();
34
7
  }
35
8
  }
36
9
  Register.description = "Registers all local component config files";
@@ -21,22 +21,9 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
21
21
  exit: 1,
22
22
  });
23
23
  }
24
- const configs = await (0, util_1.getComponentConfigs)();
25
- if (configs.length === 0) {
26
- core_1.ux.action.stop();
27
- this.log("No components found in current components directory, please run 'superblocks components create' first");
28
- }
29
- core_1.ux.action.stop();
30
- try {
31
- core_1.ux.action.start("Registering components...");
32
- await this.getSdk().registerComponents(this.applicationConfig.id, configs);
33
- core_1.ux.action.stop();
34
- }
35
- catch (e) {
36
- core_1.ux.action.stop();
37
- this.log(e.message);
38
- this.error("Failed to register components", { exit: 1 });
39
- }
24
+ const configs = await this.registerComponents();
25
+ if (!configs)
26
+ return;
40
27
  // Map component name to component path- each name is a separate entry point
41
28
  const entryFiles = Object.fromEntries(Object.values(configs).map((config) => [
42
29
  config.name,
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.healthEndpointMiddleware = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const core_1 = require("@oclif/core");
6
5
  const react_shim_1 = require("@superblocksteam/react-shim");
7
- const util_1 = require("@superblocksteam/util");
8
6
  const vite_custom_component_reload_plugin_1 = require("@superblocksteam/vite-custom-component-reload-plugin");
9
7
  const plugin_react_1 = tslib_1.__importDefault(require("@vitejs/plugin-react"));
10
8
  const colorette_1 = require("colorette");
@@ -31,10 +29,7 @@ function healthEndpointMiddleware() {
31
29
  exports.healthEndpointMiddleware = healthEndpointMiddleware;
32
30
  class Watch extends authenticated_command_1.AuthenticatedApplicationCommand {
33
31
  async run() {
34
- core_1.ux.action.start("Registering components...");
35
- const components = await (0, util_1.getComponentConfigs)();
36
- await this.getSdk().registerComponents(this.applicationConfig.id, components);
37
- core_1.ux.action.stop();
32
+ await this.registerComponents();
38
33
  this.log((0, colorette_1.yellow)("Remember to refresh your application to see any newly registered components."));
39
34
  this.log();
40
35
  this.log((0, colorette_1.green)(`Visit ${await this.getBaseUrl()} and access your application in edit mode to see your components! 🐨`));
@@ -58,20 +53,6 @@ class Watch extends authenticated_command_1.AuthenticatedApplicationCommand {
58
53
  await (async () => {
59
54
  const server = await (0, vite_1.createServer)({
60
55
  configFile: false,
61
- build: {
62
- rollupOptions: {
63
- input: [
64
- // eslint-disable-next-line no-warning-comments
65
- /* TODO */
66
- ],
67
- preserveEntrySignatures: "strict",
68
- output: {
69
- entryFileNames: "[name].js",
70
- },
71
- },
72
- copyPublicDir: true,
73
- write: true,
74
- },
75
56
  base: `http://localhost:${port}`,
76
57
  server: {
77
58
  port,
@@ -40,10 +40,8 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
40
40
  task: (ctx, task) => task.newListr([
41
41
  {
42
42
  title: "Fetching applications...",
43
+ enabled: () => !args.resourceUrl,
43
44
  task: async (ctx, task) => {
44
- if (args.resourceUrl) {
45
- task.skip("Skipping fetching applications");
46
- }
47
45
  // applications choices
48
46
  const applications = await this.getSdk().fetchApplications();
49
47
  for (const app of applications) {
@@ -58,6 +56,28 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
58
56
  task.title += `: completed`;
59
57
  },
60
58
  },
59
+ {
60
+ title: "Fetching resource by resourceUrl...",
61
+ enabled: () => args.resourceUrl,
62
+ task: async (ctx, task) => {
63
+ const [resourceId, resourceType] = getResourceIdFromUrl(args.resourceUrl);
64
+ if (resourceType === "APPLICATION") {
65
+ const application = await this.getSdk().fetchApplication(resourceId);
66
+ ctx.fetchedResources[application.application.id] = {
67
+ resourceType,
68
+ name: application.application.name,
69
+ };
70
+ }
71
+ else if (resourceType === "BACKEND") {
72
+ const api = await this.getSdk().fetchApi(resourceId);
73
+ ctx.fetchedResources[api.id] = {
74
+ resourceType,
75
+ name: api.actions.name,
76
+ };
77
+ }
78
+ task.title += `: completed`;
79
+ },
80
+ },
61
81
  ]),
62
82
  },
63
83
  {
@@ -76,6 +96,9 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
76
96
  const now = new Date().toISOString();
77
97
  for (const resourceId of ctx.resourceIdsToInitialize) {
78
98
  const resource = ctx.fetchedResources[resourceId];
99
+ if (!resource) {
100
+ this.error(`Resource with id ${resourceId} does not exist in fetched resources`);
101
+ }
79
102
  switch (resource.resourceType) {
80
103
  case "APPLICATION": {
81
104
  subtasks.push({
@@ -152,13 +175,8 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
152
175
  var _a, _b;
153
176
  if (args.resourceUrl) {
154
177
  try {
155
- const resourceUrl = new URL(args.resourceUrl);
156
- if (resourceUrl.pathname.startsWith("/applications") ||
157
- resourceUrl.pathname.startsWith("/workflows") ||
158
- resourceUrl.pathname.startsWith("/scheduled-jobs")) {
159
- return [resourceUrl.pathname.split("/")[2]];
160
- }
161
- throw new Error(`Failed to parse resource URL: ${args.resourceUrl}`);
178
+ const [resourceId] = getResourceIdFromUrl(args.resourceUrl);
179
+ return [resourceId];
162
180
  }
163
181
  catch {
164
182
  throw new Error(`Invalid resource URL: ${args.resourceUrl}`);
@@ -245,3 +263,14 @@ Initialize.args = {
245
263
  }),
246
264
  };
247
265
  exports.default = Initialize;
266
+ function getResourceIdFromUrl(resourceUrl) {
267
+ const url = new URL(resourceUrl);
268
+ if (url.pathname.startsWith("/applications")) {
269
+ return [url.pathname.split("/")[2], "APPLICATION"];
270
+ }
271
+ else if (url.pathname.startsWith("/workflows") ||
272
+ url.pathname.startsWith("/scheduled-jobs")) {
273
+ return [url.pathname.split("/")[2], "BACKEND"];
274
+ }
275
+ throw new Error(`Failed to parse resource URL: ${resourceUrl}`);
276
+ }
@@ -11,4 +11,5 @@ export declare abstract class AuthenticatedApplicationCommand extends Authentica
11
11
  applicationConfig: SuperblocksApplicationConfig;
12
12
  protected getEditModeUrl(): Promise<string>;
13
13
  protected init(): Promise<void>;
14
+ protected registerComponents(): Promise<Record<string, any> | undefined>;
14
15
  }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuthenticatedApplicationCommand = exports.AuthenticatedCommand = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const core_1 = require("@oclif/core");
5
6
  const sdk_1 = require("@superblocksteam/sdk");
6
7
  const util_1 = require("@superblocksteam/util");
8
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
9
  class AuthenticatedCommand extends core_1.Command {
8
10
  async init() {
9
11
  await super.init();
@@ -54,5 +56,37 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
54
56
  });
55
57
  }
56
58
  }
59
+ async registerComponents() {
60
+ core_1.ux.action.start("Scanning for Superblocks components...");
61
+ const exists = await fs_extra_1.default.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
62
+ if (!exists) {
63
+ core_1.ux.action.stop();
64
+ this.error("No components folder found in current directory, please run 'superblocks components create' first", {
65
+ exit: 1,
66
+ });
67
+ }
68
+ const { configs, hasError } = await (0, util_1.getComponentConfigs)();
69
+ if (hasError) {
70
+ core_1.ux.action.stop();
71
+ this.error("Failed to register components", { exit: 1 });
72
+ // Stop immediately
73
+ return;
74
+ }
75
+ if (configs.length === 0) {
76
+ core_1.ux.action.stop();
77
+ this.log("No components found in current components directory, please run 'superblocks components create' first");
78
+ }
79
+ core_1.ux.action.stop();
80
+ try {
81
+ core_1.ux.action.start("Registering components...");
82
+ await this.getSdk().registerComponents(this.applicationConfig.id, configs);
83
+ core_1.ux.action.stop();
84
+ }
85
+ catch {
86
+ core_1.ux.action.stop();
87
+ this.error("Failed to register components", { exit: 1 });
88
+ }
89
+ return configs;
90
+ }
57
91
  }
58
92
  exports.AuthenticatedApplicationCommand = AuthenticatedApplicationCommand;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.14",
2
+ "version": "0.0.15",
3
3
  "commands": {
4
4
  "init": {
5
5
  "id": "init",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Official Superblocks CLI",
5
5
  "bin": {
6
6
  "superblocks": "bin/run"
@@ -18,8 +18,8 @@
18
18
  "@oclif/core": "^2",
19
19
  "@oclif/plugin-help": "^5",
20
20
  "@oclif/plugin-plugins": "^2.4.4",
21
- "@superblocksteam/sdk": "*",
22
21
  "@superblocksteam/react-shim": "*",
22
+ "@superblocksteam/sdk": "*",
23
23
  "@superblocksteam/util": "*",
24
24
  "@superblocksteam/vite-custom-component-reload-plugin": "*",
25
25
  "@vitejs/plugin-react": "^4.0.0",