@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,20 +1,47 @@
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 util_1 = require("@superblocksteam/util");
7
- const listr2_1 = require("listr2");
8
- const authenticated_command_1 = require("../common/authenticated-command");
9
- const version_control_1 = require("../common/version-control");
10
- class Commits extends authenticated_command_1.AuthenticatedCommand {
1
+ import path from "node:path";
2
+ import { Args, Flags } from "@oclif/core";
3
+ import { getSuperblocksMonorepoConfigJson, getSuperblocksResourceConfigIfExists, ComponentEvent, COMPONENT_EVENT_HEADER, NotFoundError, } from "@superblocksteam/util";
4
+ import { Listr } from "listr2";
5
+ import { AuthenticatedCommand } from "../common/authenticated-command.mjs";
6
+ import { DEFAULT_BRANCH, SELECT_PROMPT_HELP, atLeastOneSelection, deleteResourcesAndUpdateRootConfig, getCurrentGitBranchIfGit, } from "../common/version-control.mjs";
7
+ export default class Commits extends AuthenticatedCommand {
8
+ static description = "List Superblocks commits for a resource";
9
+ static examples = [
10
+ "<%= config.bin %> <%= command.id %>",
11
+ "<%= config.bin %> <%= command.id %> apps/my-app",
12
+ "<%= config.bin %> <%= command.id %> apps/my-app -b feature-branch",
13
+ "<%= config.bin %> <%= command.id %> --limit 20",
14
+ "<%= config.bin %> <%= command.id %> --offset 10",
15
+ ];
16
+ static flags = {
17
+ branch: Flags.string({
18
+ char: "b",
19
+ description: "Superblocks branch to show commits for, the current git branch will be used by default",
20
+ }),
21
+ limit: Flags.integer({
22
+ char: "l",
23
+ default: 10,
24
+ description: "Number of commits to be displayed, default is 10",
25
+ }),
26
+ offset: Flags.integer({
27
+ char: "o",
28
+ default: 0,
29
+ description: "Number of commits to be skipped before displaying by creation time, default is 0",
30
+ }),
31
+ };
32
+ static args = {
33
+ resource_path: Args.string({
34
+ description: "Superblocks resource location to show commits for (i.e. apps/my-app)",
35
+ required: false,
36
+ }),
37
+ };
11
38
  async run() {
12
39
  const { flags, args } = await this.parse(Commits);
13
40
  const tasks = this.createTasks(args.resource_path, flags.branch, flags.limit, flags.offset);
14
41
  await tasks.run();
15
42
  }
16
43
  createTasks(resourcePath, branch, limit, offset) {
17
- const tasks = new listr2_1.Listr([
44
+ const tasks = new Listr([
18
45
  {
19
46
  title: "Checking for existing Superblocks project...",
20
47
  task: async (ctx) => {
@@ -24,10 +51,10 @@ class Commits extends authenticated_command_1.AuthenticatedCommand {
24
51
  [
25
52
  ctx.existingSuperblocksRootConfig,
26
53
  ctx.superblocksRootConfigPath,
27
- ] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
54
+ ] = await getSuperblocksMonorepoConfigJson(true);
28
55
  ctx.existingSuperblocksResourceConfig =
29
- await (0, util_1.getSuperblocksResourceConfigIfExists)();
30
- ctx.superblocksRootPath = node_path_1.default.resolve(node_path_1.default.dirname(ctx.superblocksRootConfigPath), "..");
56
+ await getSuperblocksResourceConfigIfExists();
57
+ ctx.superblocksRootPath = path.resolve(path.dirname(ctx.superblocksRootConfigPath), "..");
31
58
  }
32
59
  catch {
33
60
  // no existing superblocks config
@@ -41,7 +68,7 @@ class Commits extends authenticated_command_1.AuthenticatedCommand {
41
68
  ctx.branchToShowCommitsFor = new Map();
42
69
  try {
43
70
  ctx.localBranchName =
44
- branch || (await (0, version_control_1.getCurrentGitBranchIfGit)()) || version_control_1.DEFAULT_BRANCH;
71
+ branch || (await getCurrentGitBranchIfGit()) || DEFAULT_BRANCH;
45
72
  }
46
73
  catch (e) {
47
74
  this.error(`Failed to check for existing git repository: ${e.message}. Please make sure to clone or initialize a git repository.`);
@@ -51,10 +78,9 @@ class Commits extends authenticated_command_1.AuthenticatedCommand {
51
78
  {
52
79
  title: "Checking for deleted Superblocks resources...",
53
80
  task: async (ctx, task) => {
54
- var _a, _b;
55
81
  try {
56
- for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
57
- switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
82
+ for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
83
+ switch (resource?.resourceType) {
58
84
  case "APPLICATION": {
59
85
  try {
60
86
  await this.getSdk().fetchApplication({
@@ -64,7 +90,7 @@ class Commits extends authenticated_command_1.AuthenticatedCommand {
64
90
  });
65
91
  }
66
92
  catch (error) {
67
- if (error instanceof util_1.NotFoundError) {
93
+ if (error instanceof NotFoundError) {
68
94
  ctx.removedResourceIds.push(resourceId);
69
95
  }
70
96
  else {
@@ -82,7 +108,7 @@ class Commits extends authenticated_command_1.AuthenticatedCommand {
82
108
  });
83
109
  }
84
110
  catch (error) {
85
- if (error instanceof util_1.NotFoundError) {
111
+ if (error instanceof NotFoundError) {
86
112
  ctx.removedResourceIds.push(resourceId);
87
113
  }
88
114
  else {
@@ -115,7 +141,7 @@ Would you like to also delete these resources from your filesystem?`,
115
141
  },
116
142
  ]);
117
143
  if (removeResourcesFromDisk) {
118
- await (0, version_control_1.deleteResourcesAndUpdateRootConfig)(ctx.removedResourceIds, ctx.existingSuperblocksRootConfig, ctx.superblocksRootPath, ctx.superblocksRootConfigPath);
144
+ await deleteResourcesAndUpdateRootConfig(ctx.removedResourceIds, ctx.existingSuperblocksRootConfig, ctx.superblocksRootPath, ctx.superblocksRootConfigPath);
119
145
  }
120
146
  }
121
147
  catch (e) {
@@ -131,19 +157,18 @@ Would you like to also delete these resources from your filesystem?`,
131
157
  },
132
158
  {
133
159
  task: async (ctx, task) => {
134
- var _a, _b;
135
160
  task.title = `Get commits for the resource from branch ${ctx.localBranchName}...`;
136
161
  const subtasks = [];
137
162
  const resourceId = ctx.resourceIdToShowCommits;
138
- const resource = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId];
139
- const branchName = (_b = ctx.branchToShowCommitsFor.get(resourceId)) !== null && _b !== void 0 ? _b : ctx.localBranchName;
140
- switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
163
+ const resource = ctx.existingSuperblocksRootConfig?.resources[resourceId];
164
+ const branchName = ctx.branchToShowCommitsFor.get(resourceId) ?? ctx.localBranchName;
165
+ switch (resource?.resourceType) {
141
166
  case "APPLICATION": {
142
167
  subtasks.push({
143
168
  title: `Fetching commits for application ${resource.location} from branch ${branchName}...`,
144
169
  task: async (_ctx, task) => {
145
170
  const headers = {
146
- [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.COMMITS,
171
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.COMMITS,
147
172
  };
148
173
  try {
149
174
  task.title += `: fetched`;
@@ -158,7 +183,7 @@ Would you like to also delete these resources from your filesystem?`,
158
183
  task.title += `: done`;
159
184
  }
160
185
  catch (e) {
161
- if (e instanceof util_1.NotFoundError) {
186
+ if (e instanceof NotFoundError) {
162
187
  task.title += `: not found in this branch. skipped`;
163
188
  }
164
189
  else {
@@ -202,23 +227,22 @@ Would you like to also delete these resources from your filesystem?`,
202
227
  return tasks;
203
228
  }
204
229
  async getResourceIdToShowCommits(ctx, task, resourcePath) {
205
- var _a, _b, _c, _d, _e;
206
230
  if (resourcePath) {
207
- for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
231
+ for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
208
232
  if (resource.location === resourcePath) {
209
233
  return resourceId;
210
234
  }
211
235
  }
212
236
  throw new Error(`No resource found with the given location: ${resourcePath}`);
213
237
  }
214
- const resourceConfig = await (0, util_1.getSuperblocksResourceConfigIfExists)();
238
+ const resourceConfig = await getSuperblocksResourceConfigIfExists();
215
239
  if (resourceConfig) {
216
240
  return resourceConfig.id;
217
241
  }
218
242
  const choices = [];
219
243
  const initialSelections = [];
220
244
  let counter = 0;
221
- for (const [resourceId, resource] of Object.entries((_d = (_c = ctx.existingSuperblocksRootConfig) === null || _c === void 0 ? void 0 : _c.resources) !== null && _d !== void 0 ? _d : {})) {
245
+ for (const [resourceId, resource] of Object.entries(ctx.existingSuperblocksRootConfig?.resources ?? {})) {
222
246
  if (ctx.removedResourceIds.includes(resourceId)) {
223
247
  continue;
224
248
  }
@@ -226,7 +250,7 @@ Would you like to also delete these resources from your filesystem?`,
226
250
  name: resourceId,
227
251
  message: resource.location,
228
252
  });
229
- if (((_e = ctx.existingSuperblocksResourceConfig) === null || _e === void 0 ? void 0 : _e.id) === resourceId) {
253
+ if (ctx.existingSuperblocksResourceConfig?.id === resourceId) {
230
254
  initialSelections.push(counter);
231
255
  }
232
256
  counter++;
@@ -240,10 +264,10 @@ Would you like to also delete these resources from your filesystem?`,
240
264
  {
241
265
  type: "Select",
242
266
  name: "resourceIdToShowCommits",
243
- message: `Select a resource to see commits (${version_control_1.SELECT_PROMPT_HELP})`,
267
+ message: `Select a resource to see commits (${SELECT_PROMPT_HELP})`,
244
268
  choices: choices,
245
269
  initial: initialSelections,
246
- validate: version_control_1.atLeastOneSelection,
270
+ validate: atLeastOneSelection,
247
271
  prefix: "▸",
248
272
  indicator: "◉",
249
273
  },
@@ -251,48 +275,16 @@ Would you like to also delete these resources from your filesystem?`,
251
275
  return resourceIdToShowCommitFor;
252
276
  }
253
277
  printCommits(commits, branch) {
254
- var _a;
255
278
  if (commits.commits.length === 0) {
256
279
  console.log("No commits have been created.");
257
280
  return;
258
281
  }
259
282
  for (const commit of commits.commits) {
260
283
  console.log(`commit ${commit.commitId}`, branch ? `(${branch})` : "");
261
- console.log(`Author: ${(_a = commit.committer.name) !== null && _a !== void 0 ? _a : ""} <${commit.committer.email}>`);
284
+ console.log(`Author: ${commit.committer.name ?? ""} <${commit.committer.email}>`);
262
285
  console.log(`Date: ${new Date(commit.commitDate).toLocaleString()}`);
263
286
  console.log(`Message: ${commit.commitMessage}`);
264
287
  console.log("---");
265
288
  }
266
289
  }
267
290
  }
268
- Commits.description = "List Superblocks commits for a resource";
269
- Commits.examples = [
270
- "<%= config.bin %> <%= command.id %>",
271
- "<%= config.bin %> <%= command.id %> apps/my-app",
272
- "<%= config.bin %> <%= command.id %> apps/my-app -b feature-branch",
273
- "<%= config.bin %> <%= command.id %> --limit 20",
274
- "<%= config.bin %> <%= command.id %> --offset 10",
275
- ];
276
- Commits.flags = {
277
- branch: core_1.Flags.string({
278
- char: "b",
279
- description: "Superblocks branch to show commits for, the current git branch will be used by default",
280
- }),
281
- limit: core_1.Flags.integer({
282
- char: "l",
283
- default: 10,
284
- description: "Number of commits to be displayed, default is 10",
285
- }),
286
- offset: core_1.Flags.integer({
287
- char: "o",
288
- default: 0,
289
- description: "Number of commits to be skipped before displaying by creation time, default is 0",
290
- }),
291
- };
292
- Commits.args = {
293
- resource_path: core_1.Args.string({
294
- description: "Superblocks resource location to show commits for (i.e. apps/my-app)",
295
- required: false,
296
- }),
297
- };
298
- exports.default = Commits;
@@ -1,9 +1,9 @@
1
- import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command.mjs";
2
2
  export default class CreateComponent extends AuthenticatedApplicationCommand {
3
3
  static description: string;
4
4
  private dataTypeToDefaultControlType;
5
5
  static flags: {
6
- example: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
+ example: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
7
  };
8
8
  private initializeComponentByWizard;
9
9
  private initializeComponentByExample;
@@ -1,23 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /* eslint-disable no-await-in-loop */
5
- const node_child_process_1 = require("node:child_process");
6
- const node_crypto_1 = require("node:crypto");
7
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
- const node_util_1 = tslib_1.__importDefault(require("node:util"));
9
- const core_1 = require("@oclif/core");
10
- const util_1 = require("@superblocksteam/util");
11
- const colorette_1 = require("colorette");
12
- const enquirer_1 = require("enquirer");
13
- const fs = tslib_1.__importStar(require("fs-extra"));
14
- const lodash_1 = require("lodash");
15
- const authenticated_command_1 = require("../../common/authenticated-command");
16
- const create_component_defaults_1 = require("../../common/defaults/create-component-defaults");
17
- // eslint-disable-next-line unicorn/prefer-module
18
- const rootDirectory = node_path_1.default.resolve(__dirname, "../../../");
19
- const DEFAULT_PACKAGE_JSON_TEMPLATE_PATH = node_path_1.default.resolve(rootDirectory, "assets/custom-components/setup");
20
- const DEFAULT_EXAMPLE_COMPONENT_TEMPLATE_PATH = node_path_1.default.resolve(rootDirectory, "assets/custom-components/example");
1
+ import { exec } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import path from "node:path";
4
+ import util from "node:util";
5
+ import { Flags, ux } from "@oclif/core";
6
+ import { dataTypeDefinions, ComponentEvent, COMPONENT_EVENT_HEADER, isValidIdentifier, isReservedPropertyName, suggestIdentifier, } from "@superblocksteam/util";
7
+ import { bold, cyanBright, green, magenta, red } from "colorette";
8
+ import enquirer from "enquirer";
9
+ import fs from "fs-extra";
10
+ import { isEmpty } from "lodash-es";
11
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command.mjs";
12
+ import { getDefaultComponentTsx, getDefaultConfigTs, } from "../../common/defaults/create-component-defaults.mjs";
13
+ const { prompt } = enquirer;
14
+ const rootDirectory = path.resolve(new URL(import.meta.url).pathname, "../../../../");
15
+ const DEFAULT_PACKAGE_JSON_TEMPLATE_PATH = path.resolve(rootDirectory, "assets/custom-components/setup");
16
+ const DEFAULT_EXAMPLE_COMPONENT_TEMPLATE_PATH = path.resolve(rootDirectory, "assets/custom-components/example");
21
17
  const tsStringify = (obj) => {
22
18
  const entries = Object.entries(obj);
23
19
  const stringifiedEntries = entries.map(([key, value]) => {
@@ -25,74 +21,77 @@ const tsStringify = (obj) => {
25
21
  });
26
22
  return `{\n${stringifiedEntries.join(",\n")}\n},\n`;
27
23
  };
28
- class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCommand {
29
- constructor() {
30
- super(...arguments);
31
- this.dataTypeToDefaultControlType = (propertyType) => {
32
- switch (propertyType) {
33
- case "any":
34
- return "js-expr";
35
- case "boolean":
36
- return "switch";
37
- default:
38
- return "text";
39
- }
40
- };
41
- }
24
+ export default class CreateComponent extends AuthenticatedApplicationCommand {
25
+ static description = "Creates a new Superblocks component in the current application folder";
26
+ dataTypeToDefaultControlType = (propertyType) => {
27
+ switch (propertyType) {
28
+ case "any":
29
+ return "js-expr";
30
+ case "boolean":
31
+ return "switch";
32
+ default:
33
+ return "text";
34
+ }
35
+ };
36
+ static flags = {
37
+ example: Flags.boolean({
38
+ description: "Create example component",
39
+ }),
40
+ };
42
41
  async initializeComponentByWizard(isFirstTimeCreate) {
43
- this.log(`${(0, colorette_1.cyanBright)("ℹ")} Follow this wizard to configure your Custom Component. You can always edit the generated config.ts file directly to modify your properties or events.`);
42
+ this.log(`${cyanBright("ℹ")} Follow this wizard to configure your Custom Component. You can always edit the generated config.ts file directly to modify your properties or events.`);
44
43
  this.log();
45
- const displayName = (await (0, enquirer_1.prompt)({
44
+ const displayName = (await prompt({
46
45
  type: "input",
47
46
  name: "displayName",
48
47
  message: "What is the display name of the component you want to create? (e.g. To-Do List)",
49
- validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
48
+ validate: (response) => !isEmpty(response.trim()),
50
49
  })).displayName;
51
- const name = (await (0, enquirer_1.prompt)({
50
+ const name = (await prompt({
52
51
  type: "input",
53
52
  name: "name",
54
53
  message: "What is the machine readable name of the component you want to create?",
55
- validate: (response) => (0, util_1.isValidIdentifier)(response) || "Invalid identifier",
56
- initial: (0, util_1.suggestIdentifier)(displayName, true) || "ToDoList",
54
+ validate: (response) => isValidIdentifier(response) || "Invalid identifier",
55
+ initial: suggestIdentifier(displayName, true) || "ToDoList",
57
56
  })).name;
58
57
  this.log();
59
- this.log(`${(0, colorette_1.cyanBright)("ℹ")} Properties represent the state of the component. You will define how each property is made available to the rest of your App and whether each property is displayed in the Properties Panel. Read more about properties here: ${(0, colorette_1.magenta)("https://docs.superblocks.com/applications/custom-components/#properties--events")}`);
58
+ this.log(`${cyanBright("ℹ")} Properties represent the state of the component. You will define how each property is made available to the rest of your App and whether each property is displayed in the Properties Panel. Read more about properties here: ${magenta("https://docs.superblocks.com/applications/custom-components/#properties--events")}`);
60
59
  this.log();
61
- const hasProperties = (await (0, enquirer_1.prompt)({
60
+ const hasProperties = (await prompt({
62
61
  type: "confirm",
63
62
  name: "hasProperties",
64
- message: `Does this component have ${(0, colorette_1.bold)("properties")}?`,
63
+ message: `Does this component have ${bold("properties")}?`,
65
64
  initial: false,
66
65
  })).hasProperties;
67
66
  const properties = [];
68
67
  if (hasProperties) {
69
68
  for (;;) {
70
- const propertyPath = (await (0, enquirer_1.prompt)({
69
+ const propertyPath = (await prompt({
71
70
  type: "input",
72
71
  name: "path",
73
72
  message: "What is the path of the property? This will be used to access the property in your code (e.g. currentTasks)",
74
73
  validate: (response) => {
75
- if (!(0, util_1.isValidIdentifier)(response))
74
+ if (!isValidIdentifier(response))
76
75
  return "Invalid identifier";
77
- if ((0, util_1.isReservedPropertyName)(response))
76
+ if (isReservedPropertyName(response))
78
77
  return "Reserved property path (see https://docs.superblocks.com/applications/custom-components/faq#what-is-a-reserved-property)";
79
78
  if (properties.some((v) => v.path === response))
80
79
  return "Duplicate property path";
81
80
  return true;
82
81
  },
83
82
  })).path;
84
- const propertyType = (await (0, enquirer_1.prompt)({
83
+ const propertyType = (await prompt({
85
84
  type: "select",
86
85
  name: "type",
87
86
  message: `What is the type of ${propertyPath}?`,
88
- choices: Object.entries(util_1.dataTypeDefinions).map(([k, v]) => ({
87
+ choices: Object.entries(dataTypeDefinions).map(([k, v]) => ({
89
88
  name: k,
90
89
  message: v.prompt,
91
90
  value: k,
92
91
  })),
93
92
  initial: 0,
94
93
  })).type;
95
- const showInPropsPanel = (await (0, enquirer_1.prompt)({
94
+ const showInPropsPanel = (await prompt({
96
95
  name: "value",
97
96
  type: "confirm",
98
97
  message: "Should this property be shown in the properties panel?",
@@ -101,12 +100,12 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
101
100
  let propertiesPanelDisplay = undefined;
102
101
  if (showInPropsPanel) {
103
102
  this.log();
104
- this.log((0, colorette_1.bold)("Properties Panel Display Configuration"));
105
- const propertyLabel = (await (0, enquirer_1.prompt)({
103
+ this.log(bold("Properties Panel Display Configuration"));
104
+ const propertyLabel = (await prompt({
106
105
  type: "input",
107
106
  name: "label",
108
107
  message: "What is the label of the property? (e.g. Tasks)",
109
- validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
108
+ validate: (response) => !isEmpty(response.trim()),
110
109
  })).label.trim();
111
110
  propertiesPanelDisplay = {
112
111
  label: propertyLabel,
@@ -123,7 +122,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
123
122
  isExternallySettable: true,
124
123
  });
125
124
  this.log();
126
- const addAnotherProperty = (await (0, enquirer_1.prompt)({
125
+ const addAnotherProperty = (await prompt({
127
126
  type: "confirm",
128
127
  name: "value",
129
128
  message: "Do you want to add another property?",
@@ -135,32 +134,32 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
135
134
  }
136
135
  }
137
136
  this.log();
138
- this.log(`${(0, colorette_1.cyanBright)("ℹ")} ${(0, colorette_1.bold)("Events")} represent the types of events that the component can trigger in Superblocks. Learn more about events: ${(0, colorette_1.magenta)("https://docs.superblocks.com/applications/custom-components/#properties--events")}`);
137
+ this.log(`${cyanBright("ℹ")} ${bold("Events")} represent the types of events that the component can trigger in Superblocks. Learn more about events: ${magenta("https://docs.superblocks.com/applications/custom-components/#properties--events")}`);
139
138
  this.log();
140
- const hasEventHandlers = (await (0, enquirer_1.prompt)({
139
+ const hasEventHandlers = (await prompt({
141
140
  type: "confirm",
142
141
  name: "value",
143
- message: `Does this component have ${(0, colorette_1.bold)("events")}? (e.g. a date picker component that triggers an On Change event)`,
142
+ message: `Does this component have ${bold("events")}? (e.g. a date picker component that triggers an On Change event)`,
144
143
  initial: false,
145
144
  })).value;
146
145
  const events = [];
147
146
  if (hasEventHandlers) {
148
147
  for (;;) {
149
- const eventHandlerName = (await (0, enquirer_1.prompt)({
148
+ const eventHandlerName = (await prompt({
150
149
  name: "value",
151
150
  type: "input",
152
151
  message: "What is the label of the event? (e.g. On Change)",
153
- validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
152
+ validate: (response) => !isEmpty(response.trim()),
154
153
  })).value.trim();
155
- const eventHandlerPath = (await (0, enquirer_1.prompt)({
154
+ const eventHandlerPath = (await prompt({
156
155
  name: "value",
157
156
  message: "What is the path of the event? This will be used to trigger the event in your code (e.g. onChange)",
158
157
  type: "input",
159
- initial: (0, util_1.suggestIdentifier)(eventHandlerName) || "onChange",
158
+ initial: suggestIdentifier(eventHandlerName) || "onChange",
160
159
  validate: (response) => {
161
- if (!(0, util_1.isValidIdentifier)(response))
160
+ if (!isValidIdentifier(response))
162
161
  return "Invalid identifier";
163
- if ((0, util_1.isReservedPropertyName)(response))
162
+ if (isReservedPropertyName(response))
164
163
  return "Reserved property path (see https://docs.superblocks.com/applications/custom-components/faq#what-is-a-reserved-property)";
165
164
  if (events.some((v) => v.path === response))
166
165
  return "Duplicate property path";
@@ -171,7 +170,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
171
170
  label: eventHandlerName,
172
171
  path: eventHandlerPath,
173
172
  });
174
- const addAnotherEventHandler = (await (0, enquirer_1.prompt)({
173
+ const addAnotherEventHandler = (await prompt({
175
174
  name: "value",
176
175
  type: "confirm",
177
176
  message: "Do you want to add another event?",
@@ -182,8 +181,8 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
182
181
  }
183
182
  }
184
183
  }
185
- const configTs = (0, create_component_defaults_1.getDefaultConfigTs)({
186
- id: (0, node_crypto_1.randomUUID)(),
184
+ const configTs = getDefaultConfigTs({
185
+ id: randomUUID(),
187
186
  name,
188
187
  displayName,
189
188
  propertiesRendered: properties
@@ -193,7 +192,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
193
192
  .map((eventHandler) => tsStringify(eventHandler))
194
193
  .join(""),
195
194
  });
196
- const componentTsx = (0, create_component_defaults_1.getDefaultComponentTsx)(properties, events.map((prop) => prop.path));
195
+ const componentTsx = getDefaultComponentTsx(properties, events.map((prop) => prop.path));
197
196
  if (isFirstTimeCreate) {
198
197
  await fs.copy(DEFAULT_PACKAGE_JSON_TEMPLATE_PATH, ".");
199
198
  // There is a very old npm bug where it won't publish .gitignore files
@@ -241,8 +240,8 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
241
240
  },
242
241
  ],
243
242
  };
244
- const configTs = (0, create_component_defaults_1.getDefaultConfigTs)({
245
- id: (0, node_crypto_1.randomUUID)(),
243
+ const configTs = getDefaultConfigTs({
244
+ id: randomUUID(),
246
245
  name: response.name,
247
246
  displayName: response.displayName,
248
247
  propertiesRendered: response.properties
@@ -268,7 +267,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
268
267
  const { flags: parsedFlags } = await this.parse(CreateComponent);
269
268
  const isFirstTimeCreate = !(await fs.exists("package.json"));
270
269
  if (isFirstTimeCreate) {
271
- this.log(`${(0, colorette_1.cyanBright)("ℹ")} Welcome to Custom Components! In order to help you get started, weve 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")}`);
270
+ this.log(`${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: ${magenta("https://docs.superblocks.com/applications/custom-components/quickstart")}`);
272
271
  this.log();
273
272
  }
274
273
  let initExampleComponent = parsedFlags.example;
@@ -276,7 +275,7 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
276
275
  // if the example component flag is not set and this is the first time the user is creating a component, prompt the user
277
276
  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. `);
278
277
  this.log();
279
- initExampleComponent = (await (0, enquirer_1.prompt)({
278
+ initExampleComponent = (await prompt({
280
279
  name: "value",
281
280
  type: "confirm",
282
281
  message: "Would you like to generate an example custom component?",
@@ -286,42 +285,34 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
286
285
  const response = initExampleComponent
287
286
  ? await this.initializeComponentByExample()
288
287
  : await this.initializeComponentByWizard(isFirstTimeCreate);
289
- this.log((0, colorette_1.green)("Successfully created component! Added the following files:"));
288
+ this.log(green("Successfully created component! Added the following files:"));
290
289
  this.log();
291
- const tree = core_1.ux.tree();
292
- tree.insert("components");
293
- tree.nodes.components.insert(response.name);
294
- tree.nodes.components.nodes[response.name].insert("config.ts # update this file to manage your component's properties and events");
295
- tree.nodes.components.nodes[response.name].insert("types.ts # this file contains your react component type definitions and is automatically updated while you run 'superblocks components watch'");
296
- tree.nodes.components.nodes[response.name].insert("component.tsx # your component's react code");
297
- tree.display();
290
+ const tree = `├─ components
291
+ │ └─ ${response.name}
292
+ │ ├─ config.ts # update this file to manage your component's properties and events
293
+ │ ├─ types.ts # this file contains your react component type definitions and is automatically updated while you run 'superblocks components watch'
294
+ │ └─ component.tsx # your component's react code`;
295
+ this.log(tree);
298
296
  this.log();
299
- this.log(`${(0, colorette_1.green)("Remember to run $ ")}${(0, colorette_1.magenta)("superblocks components watch")}${(0, colorette_1.green)(" to watch for changes to your component files")}`);
297
+ this.log(`${green("Remember to run $ ")}${magenta("superblocks components watch")}${green(" to watch for changes to your component files")}`);
300
298
  this.log();
301
299
  this.log(`Edit your component's react code here:
302
- ${(0, colorette_1.green)(`components/${response.name}/component.tsx`)}`);
300
+ ${green(`components/${response.name}/component.tsx`)}`);
303
301
  this.log();
304
302
  if (isFirstTimeCreate) {
305
- core_1.ux.action.start("Installing dependencies...");
303
+ ux.action.start("Installing dependencies...");
306
304
  try {
307
- await node_util_1.default.promisify(node_child_process_1.exec)("npm i");
305
+ await util.promisify(exec)("npm i");
308
306
  }
309
307
  catch {
310
- core_1.ux.action.stop();
311
- this.error((0, colorette_1.red)("Failed to install dependencies. Please run 'npm install' manually."));
308
+ ux.action.stop();
309
+ this.error(red("Failed to install dependencies. Please run 'npm install' manually."));
312
310
  }
313
- core_1.ux.action.stop();
311
+ ux.action.stop();
314
312
  }
315
313
  const headers = {
316
- [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.CREATE,
314
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.CREATE,
317
315
  };
318
316
  this.registerComponents(headers);
319
317
  }
320
318
  }
321
- CreateComponent.description = "Creates a new Superblocks component in the current application folder";
322
- CreateComponent.flags = {
323
- example: core_1.Flags.boolean({
324
- description: "Create example component",
325
- }),
326
- };
327
- exports.default = CreateComponent;
@@ -1,4 +1,4 @@
1
- import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command.mjs";
2
2
  export default class Register extends AuthenticatedApplicationCommand {
3
3
  static description: string;
4
4
  static examples: string[];
@@ -0,0 +1,12 @@
1
+ import { COMPONENT_EVENT_HEADER, ComponentEvent } from "@superblocksteam/util";
2
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command.mjs";
3
+ export default class Register extends AuthenticatedApplicationCommand {
4
+ static description = "Registers all local component config files";
5
+ static examples = ["superblocks components register"];
6
+ async run() {
7
+ const headers = {
8
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.REGISTER,
9
+ };
10
+ await this.registerComponents(headers);
11
+ }
12
+ }
@@ -1,9 +1,9 @@
1
- import { AuthenticatedApplicationCommand } from "../../common/authenticated-command";
1
+ import { AuthenticatedApplicationCommand } from "../../common/authenticated-command.mjs";
2
2
  export default class Upload extends AuthenticatedApplicationCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
- branch: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
+ branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
7
  };
8
8
  run(): Promise<void>;
9
9
  }