@superblocksteam/cli 0.0.22 → 1.0.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/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.22 linux-x64 node-v18.17.0
15
+ @superblocksteam/cli/1.0.0 linux-x64 node-v18.17.1
16
16
  $ superblocks --help [COMMAND]
17
17
  USAGE
18
18
  $ superblocks COMMAND
@@ -31,6 +31,7 @@ USAGE
31
31
  * [`superblocks login`](#superblocks-login)
32
32
  * [`superblocks migrate`](#superblocks-migrate)
33
33
  * [`superblocks pull [ONLY]`](#superblocks-pull-only)
34
+ * [`superblocks rm [RESOURCELOCATION]`](#superblocks-rm-resourcelocation)
34
35
 
35
36
  ## `superblocks components create`
36
37
 
@@ -38,7 +39,10 @@ Creates a new Superblocks component in the current application folder
38
39
 
39
40
  ```
40
41
  USAGE
41
- $ superblocks components create
42
+ $ superblocks components create [--example]
43
+
44
+ FLAGS
45
+ --example Create example component
42
46
 
43
47
  DESCRIPTION
44
48
  Creates a new Superblocks component in the current application folder
@@ -210,4 +214,25 @@ EXAMPLES
210
214
 
211
215
  $ superblocks pull backends/my-scheduled-job
212
216
  ```
217
+
218
+ ## `superblocks rm [RESOURCELOCATION]`
219
+
220
+ Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)
221
+
222
+ ```
223
+ USAGE
224
+ $ superblocks rm [RESOURCELOCATION]
225
+
226
+ ARGUMENTS
227
+ RESOURCELOCATION Superblocks resource location (i.e. apps/my-spectacular-app)
228
+
229
+ DESCRIPTION
230
+ Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if
231
+ it exists)
232
+
233
+ EXAMPLES
234
+ $ superblocks rm
235
+
236
+ $ superblocks rm apps/my-spectacular-app
237
+ ```
213
238
  <!-- commandsstop -->
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useState } from "react";
1
+ import { useCallback, useState } from "react";
2
2
  import { useSuperblocksContext } from "@superblocksteam/custom-components";
3
3
  import { type Props, type EventTriggers } from "./types";
4
4
  import { Task, ErrorComponent, validateTasks } from "./validation";
@@ -7,7 +7,7 @@
7
7
  "lint:fix": "npx eslint . --fix"
8
8
  },
9
9
  "dependencies": {
10
- "@superblocksteam/custom-components": "0.0.22",
10
+ "@superblocksteam/custom-components": "1.0.0",
11
11
  "react": "^18",
12
12
  "react-dom": "^18"
13
13
  },
@@ -19,6 +19,7 @@
19
19
  "eslint-config-prettier": "^8.8.0",
20
20
  "eslint-plugin-prettier": "^5.0.0",
21
21
  "eslint-plugin-react": "^7.32.2",
22
+ "eslint-plugin-react-hooks": "^4.6.0",
22
23
  "prettier": "3.0.0",
23
24
  "sass": "^1.64.2",
24
25
  "typescript": "^5.1.6"
@@ -2,6 +2,9 @@ import { AuthenticatedApplicationCommand } from "../../common/authenticated-comm
2
2
  export default class CreateComponent extends AuthenticatedApplicationCommand {
3
3
  static description: string;
4
4
  private dataTypeToDefaultControlType;
5
+ static flags: {
6
+ example: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
+ };
5
8
  private initializeComponentByWizard;
6
9
  private initializeComponentByExample;
7
10
  run(): Promise<void>;
@@ -111,6 +111,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
111
111
  label: propertyLabel,
112
112
  controlType: this.dataTypeToDefaultControlType(propertyType),
113
113
  };
114
+ this.log(`You can configure the remaining display attributes (placeholder, etc) in the config.ts file directly.`);
114
115
  }
115
116
  properties.push({
116
117
  path: propertyPath,
@@ -120,7 +121,6 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
120
121
  isExternallyReadable: true,
121
122
  isExternallySettable: true,
122
123
  });
123
- this.log(`You can configure the remaining display attributes (placeholder, etc) in the config.ts file directly.`);
124
124
  this.log();
125
125
  const addAnotherProperty = (await (0, enquirer_1.prompt)({
126
126
  type: "confirm",
@@ -208,6 +208,9 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
208
208
  };
209
209
  }
210
210
  async initializeComponentByExample() {
211
+ if (await fs.exists("components/ToDoList")) {
212
+ this.error("Example component ToDoList already exists", { exit: 1 });
213
+ }
211
214
  const response = {
212
215
  displayName: "To-Do List (Example)",
213
216
  name: "ToDoList",
@@ -247,6 +250,11 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
247
250
  .join(""),
248
251
  });
249
252
  await fs.copy(DEFAULT_PACKAGE_JSON_TEMPLATE_PATH, ".");
253
+ // There is a very old npm bug where it won't publish .gitignore files
254
+ // https://github.com/npm/npm/issues/3763
255
+ await fs.move("./gitignore_will_rename", "./.gitignore", {
256
+ overwrite: true,
257
+ });
250
258
  await fs.ensureDir("components/" + response.name);
251
259
  await fs.copy(DEFAULT_EXAMPLE_COMPONENT_TEMPLATE_PATH, `./components/${response.name}/`);
252
260
  await fs.writeFile(`components/${response.name}/config.ts`, configTs);
@@ -254,26 +262,27 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
254
262
  }
255
263
  async run() {
256
264
  this.log();
265
+ const { flags: parsedFlags } = await this.parse(CreateComponent);
257
266
  const isFirstTimeCreate = !(await fs.exists("package.json"));
258
- let response;
259
267
  if (isFirstTimeCreate) {
260
268
  this.log(`${(0, colorette_1.cyanBright)("ℹ")} Welcome to Custom Components! In order to help you get started, we’ve built an example To-Do List Component. You can use this component as a template as you build your own Custom Component. To work with this component, we recommend following along with our quickstart guide: ${(0, colorette_1.magenta)("https://docs.superblocks.com/applications/custom-components/quickstart")}`);
261
269
  this.log();
270
+ }
271
+ let initExampleComponent = parsedFlags.example;
272
+ if (!parsedFlags.example && isFirstTimeCreate) {
273
+ // if the example component flag is not set and this is the first time the user is creating a component, prompt the user
262
274
  this.log(`If you choose to generate the example component, you will not have to provide any additional inputs. You can re-run superblocks components create once you are ready to create your own component from scratch. `);
263
275
  this.log();
264
- const initExampleComponent = (await (0, enquirer_1.prompt)({
276
+ initExampleComponent = (await (0, enquirer_1.prompt)({
265
277
  name: "value",
266
278
  type: "confirm",
267
279
  message: "Would you like to generate an example custom component?",
268
280
  initial: false,
269
281
  })).value;
270
- response = initExampleComponent
271
- ? await this.initializeComponentByExample()
272
- : await this.initializeComponentByWizard(isFirstTimeCreate);
273
- }
274
- else {
275
- response = await this.initializeComponentByWizard(isFirstTimeCreate);
276
282
  }
283
+ const response = initExampleComponent
284
+ ? await this.initializeComponentByExample()
285
+ : await this.initializeComponentByWizard(isFirstTimeCreate);
277
286
  this.log((0, colorette_1.green)("Successfully created component! Added the following files:"));
278
287
  this.log();
279
288
  const tree = core_1.ux.tree();
@@ -307,4 +316,9 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
307
316
  }
308
317
  }
309
318
  CreateComponent.description = "Creates a new Superblocks component in the current application folder";
319
+ CreateComponent.flags = {
320
+ example: core_1.Flags.boolean({
321
+ description: "Create example component",
322
+ }),
323
+ };
310
324
  exports.default = CreateComponent;
@@ -52,7 +52,20 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
52
52
  write: true,
53
53
  },
54
54
  customLogger: viteLogger,
55
- plugins: [(0, plugin_react_1.default)(), (0, react_shim_1.injectReactVersionsPlugin)(), (0, css_plugin_1.productionCssPlugin)()],
55
+ plugins: [
56
+ (0, plugin_react_1.default)(),
57
+ (0, react_shim_1.injectReactVersionsPlugin)(),
58
+ (0, css_plugin_1.productionCssPlugin)(),
59
+ {
60
+ name: "remove-node-module-maps",
61
+ apply: "build",
62
+ transform(code, id) {
63
+ if (id.includes("node_modules")) {
64
+ return { code, map: { mappings: "" } }; // removes these sourcemaps
65
+ }
66
+ },
67
+ },
68
+ ],
56
69
  });
57
70
  })();
58
71
  core_1.ux.action.stop();
@@ -68,6 +81,7 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
68
81
  const fileRelativePaths = [];
69
82
  const excluded = [
70
83
  ".superblocks",
84
+ ".git",
71
85
  "node_modules",
72
86
  "apis",
73
87
  "page.yaml",
@@ -80,8 +94,7 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
80
94
  }
81
95
  catch (e) {
82
96
  core_1.ux.action.stop();
83
- this.log(e.message);
84
- this.error("Failed to upload components", { exit: 1 });
97
+ this.error(`Failed to upload components - ${e.message}`, { exit: 1 });
85
98
  }
86
99
  this.log("You can now disable local dev mode and test your production assets");
87
100
  }
@@ -60,6 +60,9 @@ class Watch extends authenticated_command_1.AuthenticatedApplicationCommand {
60
60
  server: {
61
61
  port,
62
62
  },
63
+ resolve: {
64
+ preserveSymlinks: true,
65
+ },
63
66
  customLogger: viteLogger,
64
67
  plugins: [
65
68
  healthEndpointMiddleware(),
@@ -26,9 +26,8 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
26
26
  task: async (ctx) => {
27
27
  ctx.fetchedResources = {};
28
28
  ctx.writtenResources = {};
29
- ctx.now = new Date().toISOString();
30
29
  try {
31
- ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)())[0];
30
+ ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)(true))[0];
32
31
  }
33
32
  catch {
34
33
  // no existing superblocks config
@@ -36,7 +35,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
36
35
  },
37
36
  },
38
37
  {
39
- title: "Fetching applications, workflows and scheduled jobs...",
38
+ title: "Fetching applications...",
40
39
  task: (ctx, task) => task.newListr([
41
40
  {
42
41
  title: "Fetching applications...",
@@ -46,7 +45,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
46
45
  const applications = await this.getSdk().fetchApplications();
47
46
  for (const app of applications) {
48
47
  if (app.isEditable) {
49
- 0;
50
48
  ctx.fetchedResources[app.id] = {
51
49
  resourceType: "APPLICATION",
52
50
  name: app.name,
@@ -65,10 +63,13 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
65
63
  const headers = {
66
64
  [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.INIT,
67
65
  };
68
- const application = await this.getSdk().fetchApplication({
66
+ const application = await this.getSdk().fetchApplicationWithComponents({
69
67
  applicationId: resourceId,
70
68
  headers,
71
69
  });
70
+ if (!application) {
71
+ throw new util_1.NotFoundError(`Application ${resourceId} was not found`);
72
+ }
72
73
  ctx.fetchedResources[application.application.id] = {
73
74
  resourceType,
74
75
  name: application.application.name,
@@ -99,7 +100,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
99
100
  title: "Writing resources to a disk...",
100
101
  task: async (ctx, task) => {
101
102
  const subtasks = [];
102
- const now = new Date().toISOString();
103
103
  for (const resourceId of ctx.resourceIdsToInitialize) {
104
104
  const resource = ctx.fetchedResources[resourceId];
105
105
  if (!resource) {
@@ -113,14 +113,14 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
113
113
  const headers = {
114
114
  [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.INIT,
115
115
  };
116
- const application = await this.getSdk().fetchApplication({
116
+ const application = await this.getSdk().fetchApplicationWithComponents({
117
117
  applicationId: resourceId,
118
118
  viewMode: ctx.viewMode,
119
119
  headers,
120
120
  });
121
121
  task.title += `: fetched`;
122
122
  ctx.writtenResources[resourceId] =
123
- await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, now, process.cwd());
123
+ await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, process.cwd());
124
124
  task.title += `: done`;
125
125
  },
126
126
  });
@@ -133,7 +133,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
133
133
  const backend = await this.getSdk().fetchApi(resourceId, ctx.viewMode);
134
134
  task.title += `: fetched`;
135
135
  ctx.writtenResources[resourceId] =
136
- await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, now, process.cwd());
136
+ await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, process.cwd());
137
137
  task.title += `: done`;
138
138
  },
139
139
  });
@@ -20,7 +20,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
20
20
  title: "Checking for existing Superblocks project...",
21
21
  task: async (ctx) => {
22
22
  ctx.writtenResources = {};
23
- ctx.now = new Date().toISOString();
23
+ ctx.removedResourceIds = [];
24
24
  try {
25
25
  [
26
26
  ctx.existingSuperblocksRootConfig,
@@ -35,6 +35,78 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
35
35
  }
36
36
  },
37
37
  },
38
+ {
39
+ title: "Checking for deleted Superblocks resources...",
40
+ task: async (ctx, task) => {
41
+ var _a, _b, _c;
42
+ try {
43
+ for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
44
+ switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
45
+ case "APPLICATION": {
46
+ try {
47
+ await this.getSdk().fetchApplication({
48
+ applicationId: resourceId,
49
+ });
50
+ }
51
+ catch (error) {
52
+ if (error instanceof util_1.NotFoundError) {
53
+ ctx.removedResourceIds.push(resourceId);
54
+ }
55
+ else {
56
+ throw error;
57
+ }
58
+ }
59
+ break;
60
+ }
61
+ case "BACKEND": {
62
+ try {
63
+ await this.getSdk().fetchApi(resourceId);
64
+ }
65
+ catch (error) {
66
+ if (error instanceof util_1.NotFoundError) {
67
+ ctx.removedResourceIds.push(resourceId);
68
+ }
69
+ else {
70
+ throw error;
71
+ }
72
+ }
73
+ break;
74
+ }
75
+ default: {
76
+ this.warn(`Unsupported resource type, resource: ${JSON.stringify(resource)}`);
77
+ }
78
+ }
79
+ }
80
+ if (ctx.removedResourceIds.length === 0) {
81
+ return;
82
+ }
83
+ const listOfDeletedResources = ctx.removedResourceIds
84
+ .map((id) => `- ${ctx.existingSuperblocksRootConfig.resources[id].location}`)
85
+ .join("\n");
86
+ const removeResourcesFromDisk = await task.prompt([
87
+ {
88
+ name: "removeResourcesFromDisk",
89
+ type: "confirm",
90
+ message: `Warning: The following resources could not be found in Superblocks.
91
+ ${listOfDeletedResources}
92
+
93
+ Automatically removing resources from your local Superblocks project.
94
+
95
+ Would you like to also delete these resources from your filesystem?`,
96
+ },
97
+ ]);
98
+ if (removeResourcesFromDisk) {
99
+ for (const resourceId of ctx.removedResourceIds) {
100
+ const resource = (_c = ctx.existingSuperblocksRootConfig) === null || _c === void 0 ? void 0 : _c.resources[resourceId];
101
+ await (0, version_control_1.removeResourceFromDisk)(resource.location);
102
+ }
103
+ }
104
+ }
105
+ catch (e) {
106
+ this.warn(`Could not check for deleted Superblocks resources. Continuing...: ${e.message}`);
107
+ }
108
+ },
109
+ },
38
110
  {
39
111
  title: "Pulling resources...",
40
112
  task: async (ctx, task) => {
@@ -42,7 +114,6 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
42
114
  const viewMode = await (0, version_control_1.getMode)(task, mode);
43
115
  const resourceIdsToPull = await this.getResourceIdsToPull(ctx, task, only);
44
116
  const subtasks = [];
45
- const now = new Date().toISOString();
46
117
  const superblocksRootPath = node_path_1.default.resolve(node_path_1.default.dirname(ctx.superblocksRootConfigPath), "..");
47
118
  for (const resourceId of resourceIdsToPull) {
48
119
  const resource = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId];
@@ -54,14 +125,14 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
54
125
  const headers = {
55
126
  [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.PULL,
56
127
  };
57
- const application = await this.getSdk().fetchApplication({
128
+ const application = await this.getSdk().fetchApplicationWithComponents({
58
129
  applicationId: resourceId,
59
130
  viewMode,
60
131
  headers,
61
132
  });
62
133
  task.title += `: fetched`;
63
134
  ctx.writtenResources[resourceId] =
64
- await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, now, superblocksRootPath, resource.location);
135
+ await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, superblocksRootPath, resource.location);
65
136
  task.title += `: done`;
66
137
  },
67
138
  });
@@ -74,7 +145,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
74
145
  const backend = await this.getSdk().fetchApi(resourceId, viewMode);
75
146
  task.title += `: fetched`;
76
147
  ctx.writtenResources[resourceId] =
77
- await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, now, superblocksRootPath, resource.location);
148
+ await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, superblocksRootPath, resource.location);
78
149
  task.title += `: done`;
79
150
  },
80
151
  });
@@ -95,8 +166,8 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
95
166
  title: "Updating Superblocks project file...",
96
167
  task: async (ctx) => {
97
168
  const [superblocksRootConfig, rootConfigPath] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
98
- for (const [resourceId, resource] of Object.entries(ctx.writtenResources)) {
99
- superblocksRootConfig.resources[resourceId] = resource;
169
+ for (const removedResourceId of ctx.removedResourceIds) {
170
+ delete superblocksRootConfig.resources[removedResourceId];
100
171
  }
101
172
  // update superblocks.json file
102
173
  await fs.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(superblocksRootConfig), null, 2));
@@ -125,6 +196,9 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
125
196
  const initialSelections = [];
126
197
  let counter = 0;
127
198
  for (const [resourceId, resource] of Object.entries((_f = (_e = ctx.existingSuperblocksRootConfig) === null || _e === void 0 ? void 0 : _e.resources) !== null && _f !== void 0 ? _f : {})) {
199
+ if (ctx.removedResourceIds.includes(resourceId)) {
200
+ continue;
201
+ }
128
202
  choices.push({
129
203
  name: resourceId,
130
204
  message: resource.location,
@@ -0,0 +1,12 @@
1
+ import { AuthenticatedCommand } from "../common/authenticated-command";
2
+ export default class Remove extends AuthenticatedCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ resourceLocation: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
7
+ };
8
+ run(): Promise<void>;
9
+ private createTasks;
10
+ private getResourcesToRemove;
11
+ private findDuplicates;
12
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
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
+ const listr2_1 = require("listr2");
8
+ const lodash_1 = require("lodash");
9
+ const authenticated_command_1 = require("../common/authenticated-command");
10
+ const version_control_1 = require("../common/version-control");
11
+ class Remove extends authenticated_command_1.AuthenticatedCommand {
12
+ async run() {
13
+ const { args } = await this.parse(Remove);
14
+ const tasks = this.createTasks(args);
15
+ try {
16
+ await tasks.run();
17
+ }
18
+ catch (error) {
19
+ this.error(error.message);
20
+ }
21
+ }
22
+ createTasks(args) {
23
+ const tasks = new listr2_1.Listr([
24
+ {
25
+ title: "Checking for existing Superblocks project...",
26
+ task: async (ctx) => {
27
+ ctx.fetchedResources = {};
28
+ ctx.removedResourceIds = [];
29
+ try {
30
+ ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)(true))[0];
31
+ }
32
+ catch {
33
+ // no existing superblocks config
34
+ this.error(`No Superblocks project found in the current folder hierarchy.`);
35
+ }
36
+ },
37
+ },
38
+ {
39
+ title: "Fetching applications...",
40
+ task: (ctx, task) => task.newListr([
41
+ {
42
+ title: "Fetching applications...",
43
+ enabled: () => !args.resourceLocation,
44
+ task: async (ctx, task) => {
45
+ // applications choices
46
+ const applications = await this.getSdk().fetchApplications();
47
+ for (const app of applications) {
48
+ ctx.fetchedResources[app.id] = {
49
+ resourceType: "APPLICATION",
50
+ name: app.name,
51
+ };
52
+ }
53
+ task.title += `: completed`;
54
+ },
55
+ },
56
+ ]),
57
+ },
58
+ {
59
+ title: "Selecting resources to remove...",
60
+ task: async (ctx, task) => {
61
+ const resourceIdsToRemove = await this.getResourcesToRemove(ctx, task, args);
62
+ ctx.resourceIdsToRemove = resourceIdsToRemove;
63
+ },
64
+ },
65
+ {
66
+ title: "Removing resources...",
67
+ task: async (ctx, task) => {
68
+ var _a;
69
+ const subtasks = [];
70
+ for (const resourceId of ctx.resourceIdsToRemove) {
71
+ const resourceLocation = (_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId].location;
72
+ if (!resourceLocation) {
73
+ this.error(`Resource location not found for resource with id ${resourceId}`);
74
+ }
75
+ subtasks.push({
76
+ title: `Removing ${resourceId} from ${resourceLocation}...`,
77
+ task: async (_ctx, task) => {
78
+ await (0, version_control_1.removeResourceFromDisk)(resourceLocation);
79
+ ctx.removedResourceIds.push(resourceId);
80
+ task.title += `: done`;
81
+ },
82
+ });
83
+ }
84
+ return task.newListr(subtasks, {
85
+ concurrent: true,
86
+ });
87
+ },
88
+ },
89
+ {
90
+ title: "Updating Superblocks project file...",
91
+ task: async (ctx) => {
92
+ const [superblocksRootConfig, rootConfigPath] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
93
+ for (const removedResourceId of ctx.removedResourceIds) {
94
+ delete superblocksRootConfig.resources[removedResourceId];
95
+ }
96
+ // update superblocks.json file
97
+ await fs.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(superblocksRootConfig), null, 2));
98
+ },
99
+ },
100
+ ], {
101
+ concurrent: false,
102
+ });
103
+ return tasks;
104
+ }
105
+ async getResourcesToRemove(ctx, task, args) {
106
+ var _a;
107
+ if (args.resourceLocation) {
108
+ const [resourceId] = getResourceIdFromLocation(ctx, args.resourceLocation);
109
+ return [resourceId];
110
+ }
111
+ else {
112
+ const choices = [];
113
+ for (const [resourceId, resource] of Object.entries(ctx.fetchedResources)) {
114
+ if ((_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId]) {
115
+ choices.push({
116
+ name: resourceId,
117
+ message: `${resource.name} (${resource.resourceType})`,
118
+ });
119
+ }
120
+ }
121
+ if ((0, lodash_1.isEmpty)(choices)) {
122
+ this.error(`No resources found in your project. Please make sure you have at least one application, workflow or scheduled job in your project.`);
123
+ }
124
+ const resourceIdsToRemove = await task.prompt([
125
+ {
126
+ type: "AutoComplete",
127
+ name: "resourceIdsToRemove",
128
+ message: `Select resources to remove (${version_control_1.MULTI_SELECT_PROMPT_HELP})`,
129
+ choices: choices,
130
+ multiple: true,
131
+ validate: version_control_1.atLeastOneSelection,
132
+ prefix: "▸",
133
+ indicator: "◉",
134
+ },
135
+ ]);
136
+ const duplicates = await this.findDuplicates(resourceIdsToRemove, ctx.fetchedResources);
137
+ if (!(0, lodash_1.isEmpty)(duplicates)) {
138
+ this.error(`Duplicate resources selected: ${duplicates
139
+ .map((duplicate) => `${duplicate.name} (${duplicate.resourceType}) id: ${duplicate.id}`)
140
+ .join(", ")}. Please make sure to select unique resources or rename them so that they have unique names.`);
141
+ }
142
+ return resourceIdsToRemove;
143
+ }
144
+ }
145
+ async findDuplicates(selectedResourcesIds, resources) {
146
+ const selectedResources = selectedResourcesIds
147
+ .map((id) => {
148
+ return { ...resources[id], id };
149
+ })
150
+ .filter((resource) => resource !== undefined);
151
+ const countResourceNamesByType = {};
152
+ for (const resource of selectedResources) {
153
+ if (!countResourceNamesByType[resource.resourceType]) {
154
+ countResourceNamesByType[resource.resourceType] = {};
155
+ }
156
+ if (countResourceNamesByType[resource.resourceType][resource.name]) {
157
+ countResourceNamesByType[resource.resourceType][resource.name] += 1;
158
+ }
159
+ else {
160
+ countResourceNamesByType[resource.resourceType][resource.name] = 1;
161
+ }
162
+ }
163
+ return selectedResources.filter((resource) => countResourceNamesByType[resource.resourceType][resource.name] > 1);
164
+ }
165
+ }
166
+ Remove.description = "Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)";
167
+ Remove.examples = [
168
+ "<%= config.bin %> <%= command.id %>",
169
+ "<%= config.bin %> <%= command.id %> apps/my-spectacular-app",
170
+ ];
171
+ Remove.args = {
172
+ resourceLocation: core_1.Args.string({
173
+ description: "Superblocks resource location (i.e. apps/my-spectacular-app)",
174
+ }),
175
+ };
176
+ exports.default = Remove;
177
+ function getResourceIdFromLocation(ctx, resourceLocation) {
178
+ var _a, _b;
179
+ for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
180
+ if (resource.location === resourceLocation) {
181
+ return [resourceId, resource.resourceType];
182
+ }
183
+ }
184
+ throw new Error(`No resource found with the given location: ${resourceLocation}`);
185
+ }
@@ -9,7 +9,6 @@ const util_1 = require("@superblocksteam/util");
9
9
  const colorette_1 = require("colorette");
10
10
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
11
11
  const semver_1 = tslib_1.__importDefault(require("semver"));
12
- const yaml_1 = require("yaml");
13
12
  const migrationWarningsForApplications_1 = require("../util/migrationWarningsForApplications");
14
13
  const migrationsForDotfiles_1 = require("../util/migrationsForDotfiles");
15
14
  const version_control_1 = require("./version-control");
@@ -115,7 +114,7 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
115
114
  return new URL(`/applications/${this.applicationConfig.id}/pages/${this.applicationConfig.defaultPageId}/edit`, baseUrl).toString();
116
115
  }
117
116
  async init() {
118
- var _a;
117
+ var _a, _b;
119
118
  await super.init();
120
119
  try {
121
120
  this.applicationConfig = await (0, util_1.getSuperblocksApplicationConfigJson)();
@@ -125,18 +124,22 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
125
124
  exit: 1,
126
125
  });
127
126
  }
127
+ core_1.ux.action.start("Checking application...");
128
128
  try {
129
- const appYaml = await fs_extra_1.default.readFile("application.yaml", "utf-8");
130
- const appJson = await (0, yaml_1.parse)(appYaml);
131
- if ((_a = appJson === null || appJson === void 0 ? void 0 : appJson.settings) === null || _a === void 0 ? void 0 : _a.cliVersion) {
132
- const warningMessage = (0, migrationWarningsForApplications_1.getWarningsForApplicationMigration)(appJson.settings.cliVersion, this.config.version);
129
+ const application = await this.getSdk().fetchApplication({
130
+ applicationId: this.applicationConfig.id,
131
+ });
132
+ core_1.ux.action.stop();
133
+ 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) {
134
+ const warningMessage = (0, migrationWarningsForApplications_1.getWarningsForApplicationMigration)(application.application.settings.cliVersion, this.config.version);
133
135
  if (warningMessage) {
134
136
  this.log(warningMessage);
135
137
  }
136
138
  }
137
139
  }
138
140
  catch (e) {
139
- this.warn(`Could not read page.yaml to determine version compatibility: ${e.message}`);
141
+ core_1.ux.action.stop();
142
+ this.warn(`Could not read the application from Superblocks: ${e.message}`);
140
143
  }
141
144
  }
142
145
  async registerComponents(injectedHeaders) {
@@ -150,7 +153,10 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
150
153
 
151
154
  ${(0, colorette_1.cyan)("superblocks migrate")}`);
152
155
  }
153
- if (!semver_1.default.satisfies(this.config.version, versionStr)) {
156
+ if (versionStr.startsWith("file:")) {
157
+ 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.`);
158
+ }
159
+ else if (!semver_1.default.satisfies(this.config.version, versionStr)) {
154
160
  throw new Error(`You must upgrade the @superblocksteam/custom-components library. You are using ${versionStr} but the CLI is ${this.config.version}. Run:
155
161
 
156
162
  ${(0, colorette_1.cyan)("superblocks migrate")}`);
@@ -18,16 +18,22 @@ export default {
18
18
  componentPath: "components/${name}/component.tsx",
19
19
  properties: [${indent(propertiesRendered, 4).trim()}],
20
20
  events: [${indent(eventHandlersRendered, 4).trim()}],
21
+ gridDimensions: {
22
+ initialColumns: 50,
23
+ initialRows: 30,
24
+ },
21
25
  } satisfies ComponentConfig;
22
26
  `;
23
27
  exports.getDefaultConfigTs = getDefaultConfigTs;
24
- const getDefaultComponentTsx = (properties, eventHandlers) => `import React from "react";
25
- import { useSuperblocksContext } from "@superblocksteam/custom-components";
28
+ const getDefaultComponentTsx = (properties, eventHandlers) => `import { useSuperblocksContext, useSuperblocksIsLoading } from "@superblocksteam/custom-components";
26
29
  import { type Props, type EventTriggers } from "./types";
27
30
 
28
31
  export default function Component({${properties.length === 0
29
32
  ? ""
30
33
  : "\n" + properties.map((v) => indent(v.path, 2) + ",\n").join("")}}: Props) {
34
+ // If any of your component's properties are connected to APIs, you might want to show a loading indicator while the data is
35
+ // loading. The \`useSuperblocksIsLoading\` hook returns a boolean that indicates whether this is the case.
36
+ const isLoading = useSuperblocksIsLoading();
31
37
  const {
32
38
  updateProperties,
33
39
  events: {${"\n" + eventHandlers.map((v) => indent(v, 6) + ",\n").join("")} },
@@ -44,7 +50,7 @@ export default function Component({${properties.length === 0
44
50
  backgroundColor: "#a7aebe",
45
51
  }}
46
52
  >
47
- <h1 style={{ color: "white" }}>{"<Insert Component Here>"}</h1>
53
+ <h1 style={{ color: "white" }}>{isLoading ? <div>Loading...</div> : "<Insert Component Here>"}</h1>
48
54
  </div>
49
55
  );
50
56
  }
@@ -9,6 +9,7 @@ export type ModeFlag = (keyof typeof modeFlagValuesMap)[number];
9
9
  export declare const SELECT_PROMPT_HELP = "Use \u2191/\u2193 arrow keys, Enter to confirm";
10
10
  export declare const MULTI_SELECT_PROMPT_HELP = "Type to filter, Use \u2191/\u2193 arrow keys, Space to select, Enter to confirm";
11
11
  export declare const atLeastOneSelection: (value: string[]) => string | true;
12
- export declare function writeResourceToDisk(resourceType: string, resourceId: string, resource: any, now: string, rootPath: string, existingRelativeLocation?: string): Promise<VersionedResourceConfig>;
12
+ export declare function writeResourceToDisk(resourceType: string, resourceId: string, resource: any, rootPath: string, existingRelativeLocation?: string): Promise<VersionedResourceConfig>;
13
+ export declare function removeResourceFromDisk(resourceLocation: string): Promise<void>;
13
14
  export declare function getMode(task: any, mode: ModeFlag): Promise<ViewMode>;
14
15
  export declare function sortByKey(obj: unknown): unknown;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortByKey = exports.getMode = exports.writeResourceToDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = exports.modeFlagToViewMode = exports.modeFlagValuesMap = exports.DEPLOYED_MODE = exports.MOST_RECENT_COMMIT_MODE = exports.LATEST_EDITS_MODE = void 0;
3
+ exports.sortByKey = exports.getMode = exports.removeResourceFromDisk = exports.writeResourceToDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = exports.modeFlagToViewMode = exports.modeFlagValuesMap = exports.DEPLOYED_MODE = exports.MOST_RECENT_COMMIT_MODE = exports.LATEST_EDITS_MODE = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const https = tslib_1.__importStar(require("https"));
6
6
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
@@ -87,7 +87,7 @@ async function downloadFile(rootDirectory, filepath, url) {
87
87
  }
88
88
  return Promise.resolve("");
89
89
  }
90
- async function writeResourceToDisk(resourceType, resourceId, resource, now, rootPath, existingRelativeLocation) {
90
+ async function writeResourceToDisk(resourceType, resourceId, resource, rootPath, existingRelativeLocation) {
91
91
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
92
92
  switch (resourceType) {
93
93
  case "APPLICATION": {
@@ -181,6 +181,10 @@ async function writeResourceToDisk(resourceType, resourceId, resource, now, root
181
181
  }
182
182
  }
183
183
  exports.writeResourceToDisk = writeResourceToDisk;
184
+ async function removeResourceFromDisk(resourceLocation) {
185
+ await fs.remove(resourceLocation);
186
+ }
187
+ exports.removeResourceFromDisk = removeResourceFromDisk;
184
188
  async function getMode(task, mode) {
185
189
  if (mode) {
186
190
  return modeFlagToViewMode(mode);
@@ -26,6 +26,20 @@ To manually migrate:
26
26
 
27
27
  1. Rename "eventHandlers" to "events".
28
28
  2. Update your properties to use the new format: ${(0, colorette_1.magenta)("https://docs.superblocks.com/applications/custom-components/development-lifecycle#configts")}
29
+ `,
30
+ },
31
+ {
32
+ version: "0.0.23",
33
+ message: `${(0, colorette_1.red)("Warning")}: Type definitions for custom components have changed to include null values,
34
+ which were missing from previous types. The previous types were not accurate.
35
+ Superblocks represents missing/undefined properties as null.
36
+
37
+ To manually update, you should follow Typescript errors in your IDE and update your code
38
+ to handle null values.
39
+
40
+ ${(0, colorette_1.bold)("Your existing components are safe.")}
41
+
42
+ See changelog: ${(0, colorette_1.magenta)("https://github.com/superblocksteam/superblocks-cli/blob/main/CHANGELOG.md")}
29
43
  `,
30
44
  },
31
45
  ];
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.22",
2
+ "version": "1.0.0",
3
3
  "commands": {
4
4
  "init": {
5
5
  "id": "init",
@@ -105,6 +105,26 @@
105
105
  }
106
106
  }
107
107
  },
108
+ "rm": {
109
+ "id": "rm",
110
+ "description": "Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)",
111
+ "strict": true,
112
+ "pluginName": "@superblocksteam/cli",
113
+ "pluginAlias": "@superblocksteam/cli",
114
+ "pluginType": "core",
115
+ "aliases": [],
116
+ "examples": [
117
+ "<%= config.bin %> <%= command.id %>",
118
+ "<%= config.bin %> <%= command.id %> apps/my-spectacular-app"
119
+ ],
120
+ "flags": {},
121
+ "args": {
122
+ "resourceLocation": {
123
+ "name": "resourceLocation",
124
+ "description": "Superblocks resource location (i.e. apps/my-spectacular-app)"
125
+ }
126
+ }
127
+ },
108
128
  "components:create": {
109
129
  "id": "components:create",
110
130
  "description": "Creates a new Superblocks component in the current application folder",
@@ -113,7 +133,14 @@
113
133
  "pluginAlias": "@superblocksteam/cli",
114
134
  "pluginType": "core",
115
135
  "aliases": [],
116
- "flags": {},
136
+ "flags": {
137
+ "example": {
138
+ "name": "example",
139
+ "type": "boolean",
140
+ "description": "Create example component",
141
+ "allowNo": false
142
+ }
143
+ },
117
144
  "args": {}
118
145
  },
119
146
  "components:register": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "0.0.22",
3
+ "version": "1.0.0",
4
4
  "description": "Official Superblocks CLI",
5
5
  "bin": {
6
6
  "superblocks": "bin/run"
@@ -18,12 +18,12 @@
18
18
  "@oclif/core": "^2.11.7",
19
19
  "@oclif/plugin-help": "^5.2.16",
20
20
  "@oclif/plugin-plugins": "^3.1.10",
21
- "@superblocksteam/css-plugin": "*",
22
- "@superblocksteam/react-shim": "*",
23
- "@superblocksteam/sdk": "*",
24
- "@superblocksteam/util": "*",
25
- "@superblocksteam/vite-custom-component-reload-plugin": "*",
26
- "@vitejs/plugin-react": "^4.0.0",
21
+ "@superblocksteam/css-plugin": "1.0.0",
22
+ "@superblocksteam/react-shim": "1.0.0",
23
+ "@superblocksteam/sdk": "1.0.0",
24
+ "@superblocksteam/util": "1.0.0",
25
+ "@superblocksteam/vite-custom-component-reload-plugin": "1.0.0",
26
+ "@vitejs/plugin-react": "^4.0.4",
27
27
  "colorette": "^2.0.19",
28
28
  "enquirer": "^2.3.6",
29
29
  "fs-extra": "^11.1.1",
@@ -68,10 +68,12 @@
68
68
  "posttest": "npm run lint",
69
69
  "prepack": "npm run build && oclif manifest && oclif readme",
70
70
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
71
+ "typecheck": "tsc --noEmit",
71
72
  "update-readme": "oclif readme"
72
73
  },
73
74
  "engines": {
74
- "node": ">=14.0.0"
75
+ "node": ">=16.0.0",
76
+ "npm": ">=8.0.0"
75
77
  },
76
78
  "keywords": [
77
79
  "oclif"