@superblocksteam/cli 0.0.22 → 0.0.23

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/0.0.23 linux-x64 node-v18.17.1
16
16
  $ superblocks --help [COMMAND]
17
17
  USAGE
18
18
  $ superblocks COMMAND
@@ -38,7 +38,10 @@ Creates a new Superblocks component in the current application folder
38
38
 
39
39
  ```
40
40
  USAGE
41
- $ superblocks components create
41
+ $ superblocks components create [--example]
42
+
43
+ FLAGS
44
+ --example Create example component
42
45
 
43
46
  DESCRIPTION
44
47
  Creates a new Superblocks component in the current application folder
@@ -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": "0.0.23",
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
  }
@@ -28,7 +28,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
28
28
  ctx.writtenResources = {};
29
29
  ctx.now = new Date().toISOString();
30
30
  try {
31
- ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)())[0];
31
+ ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)(true))[0];
32
32
  }
33
33
  catch {
34
34
  // no existing superblocks config
@@ -150,7 +150,10 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
150
150
 
151
151
  ${(0, colorette_1.cyan)("superblocks migrate")}`);
152
152
  }
153
- if (!semver_1.default.satisfies(this.config.version, versionStr)) {
153
+ if (versionStr.startsWith("file:")) {
154
+ 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.`);
155
+ }
156
+ else if (!semver_1.default.satisfies(this.config.version, versionStr)) {
154
157
  throw new Error(`You must upgrade the @superblocksteam/custom-components library. You are using ${versionStr} but the CLI is ${this.config.version}. Run:
155
158
 
156
159
  ${(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
  }
@@ -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": "0.0.23",
3
3
  "commands": {
4
4
  "init": {
5
5
  "id": "init",
@@ -113,7 +113,14 @@
113
113
  "pluginAlias": "@superblocksteam/cli",
114
114
  "pluginType": "core",
115
115
  "aliases": [],
116
- "flags": {},
116
+ "flags": {
117
+ "example": {
118
+ "name": "example",
119
+ "type": "boolean",
120
+ "description": "Create example component",
121
+ "allowNo": false
122
+ }
123
+ },
117
124
  "args": {}
118
125
  },
119
126
  "components:register": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
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": "0.0.23",
22
+ "@superblocksteam/react-shim": "0.0.23",
23
+ "@superblocksteam/sdk": "0.0.23",
24
+ "@superblocksteam/util": "0.0.23",
25
+ "@superblocksteam/vite-custom-component-reload-plugin": "0.0.23",
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"