@superblocksteam/cli 0.0.11 → 0.0.12

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.11 linux-x64 node-v18.16.1
15
+ @superblocksteam/cli/0.0.12 linux-x64 node-v18.16.1
16
16
  $ superblocks --help [COMMAND]
17
17
  USAGE
18
18
  $ superblocks COMMAND
@@ -110,14 +110,14 @@ Interactively configure the current directory as a Superblocks project or initia
110
110
 
111
111
  ```
112
112
  USAGE
113
- $ superblocks init [RESOURCEURL] [-m live|latest|deployed]
113
+ $ superblocks init [RESOURCEURL] [-m latest-edits|most-recent-commit|deployed]
114
114
 
115
115
  ARGUMENTS
116
116
  RESOURCEURL Superblocks resource URL (i.e. https://app.superblocks.com/applications/<application_id>/pages/<page_id>)
117
117
 
118
118
  FLAGS
119
119
  -m, --mode=<option> Pull mode
120
- <options: live|latest|deployed>
120
+ <options: latest-edits|most-recent-commit|deployed>
121
121
 
122
122
  DESCRIPTION
123
123
  Interactively configure the current directory as a Superblocks project or initialize new services in an already
@@ -151,14 +151,14 @@ Download objects from Superblocks and save them locally
151
151
 
152
152
  ```
153
153
  USAGE
154
- $ superblocks pull [ONLY] [-m live|latest|deployed]
154
+ $ superblocks pull [ONLY] [-m latest-edits|most-recent-commit|deployed]
155
155
 
156
156
  ARGUMENTS
157
157
  ONLY Superblocks resource location to pull (i.e. apps/my-app or backends/my-workflow)
158
158
 
159
159
  FLAGS
160
160
  -m, --mode=<option> Pull mode
161
- <options: live|latest|deployed>
161
+ <options: latest-edits|most-recent-commit|deployed>
162
162
 
163
163
  DESCRIPTION
164
164
  Download objects from Superblocks and save them locally
@@ -12,7 +12,7 @@
12
12
  "react-dom": "^17"
13
13
  },
14
14
  "devDependencies": {
15
- "@superblocksteam/cli": "0.0.11",
15
+ "@superblocksteam/cli": "0.0.12",
16
16
  "@types/react": "^17",
17
17
  "@types/react-dom": "^17",
18
18
  "@typescript-eslint/eslint-plugin": "^5.62.0",
@@ -7,7 +7,7 @@
7
7
  "target": "es2019",
8
8
  "lib": ["dom", "es2015", "es2019"],
9
9
  "esModuleInterop": true,
10
- "jsx": "react-jsxdev",
10
+ "jsx": "react-jsx",
11
11
  },
12
12
  "include": ["components/**/*"],
13
13
  }
@@ -9,12 +9,12 @@ const node_util_1 = tslib_1.__importDefault(require("node:util"));
9
9
  const core_1 = require("@oclif/core");
10
10
  const util_1 = require("@superblocksteam/util");
11
11
  const colorette_1 = require("colorette");
12
+ const enquirer_1 = require("enquirer");
12
13
  const fs = tslib_1.__importStar(require("fs-extra"));
13
- const listr2_1 = require("listr2");
14
+ const lodash_1 = require("lodash");
14
15
  const authenticated_command_1 = require("../../common/authenticated-command");
15
16
  const create_component_defaults_1 = require("../../common/defaults/create-component-defaults");
16
17
  const identifiers_1 = require("../../util/identifiers");
17
- const prompt_1 = require("../../util/prompt");
18
18
  const types_1 = require("../../util/types");
19
19
  // eslint-disable-next-line unicorn/prefer-module
20
20
  const rootDirectory = node_path_1.default.resolve(__dirname, "../../../");
@@ -28,65 +28,125 @@ const tsStringify = (obj) => {
28
28
  };
29
29
  class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCommand {
30
30
  async run() {
31
- var _a;
32
- const displayName = await core_1.ux.prompt("What is the display name of the component you want to create? (e.g. Date Picker)");
33
- const name = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the component you want to create?", { default: (0, identifiers_1.suggestIdentifier)(displayName, true) || "DatePicker" }, (response) => (0, identifiers_1.isValidIdentifier)(response) || "Invalid identifier");
31
+ const displayName = (await (0, enquirer_1.prompt)({
32
+ type: "input",
33
+ name: "displayName",
34
+ message: "What is the display name of the component you want to create? (e.g. Date Picker)",
35
+ validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
36
+ })).displayName;
37
+ const name = (await (0, enquirer_1.prompt)({
38
+ type: "input",
39
+ name: "name",
40
+ message: "What is the machine readable name of the component you want to create?",
41
+ validate: (response) => (0, identifiers_1.isValidIdentifier)(response) || "Invalid identifier",
42
+ initial: (0, identifiers_1.suggestIdentifier)(displayName, true) || "DatePicker",
43
+ })).name;
34
44
  this.log();
35
- const hasStatefulProps = await core_1.ux.confirm("Does this component have stateful props? (e.g. a date picker component that has a selected date prop) [y/n]");
45
+ this.log(`${(0, colorette_1.cyanBright)("ℹ")} A ${(0, colorette_1.bold)("stateful property")} determines what shows up in the properties panel of a custom component`);
46
+ this.log();
47
+ const hasStatefulProps = (await (0, enquirer_1.prompt)({
48
+ type: "confirm",
49
+ name: "hasStatefulProps",
50
+ message: `Does this component have ${(0, colorette_1.bold)("stateful properties")}?`,
51
+ initial: false,
52
+ })).hasStatefulProps;
36
53
  const statefulProps = [];
37
54
  if (hasStatefulProps) {
38
55
  for (;;) {
39
- const statefulPropName = await core_1.ux.prompt("What is the label of the stateful prop? (e.g. Selected Date)");
40
- const statefulPropPath = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the stateful prop?", { default: (0, identifiers_1.suggestIdentifier)(statefulPropName) || "selectedDate" }, (response) => {
41
- if (!(0, identifiers_1.isValidIdentifier)(response))
42
- return "Invalid identifier";
43
- if (statefulProps.some((v) => v.path === response))
44
- return "Duplicate property name";
45
- return true;
46
- });
47
- const task = new listr2_1.Listr({
48
- task: async (ctx, task) => {
49
- ctx.inputType = await task.prompt({
50
- type: "Select",
51
- message: `What input type should ${statefulPropName} be?`,
52
- choices: Object.values(types_1.inputTypeDefinions).map((v) => v.prompt),
53
- initial: 0,
54
- });
56
+ const statefulPropName = (await (0, enquirer_1.prompt)({
57
+ type: "input",
58
+ name: "statefulPropName",
59
+ message: "What is the label of the stateful prop? (e.g. Selected Date)",
60
+ validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
61
+ })).statefulPropName.trim();
62
+ const statefulPropPath = (await (0, enquirer_1.prompt)({
63
+ type: "input",
64
+ name: "path",
65
+ initial: (0, identifiers_1.suggestIdentifier)(statefulPropName) || "selectedDate",
66
+ message: "What is the machine readable name of the stateful prop?",
67
+ validate: (response) => {
68
+ if (!(0, identifiers_1.isValidIdentifier)(response))
69
+ return "Invalid identifier";
70
+ if (statefulProps.some((v) => v.path === response))
71
+ return "Duplicate property name";
72
+ return true;
55
73
  },
56
- });
57
- const runContext = await task.run();
58
- const statefulPropType = (_a = Object.entries(types_1.inputTypeDefinions).find(([, v]) => v.prompt === runContext.inputType)) === null || _a === void 0 ? void 0 : _a[0];
59
- const placeholderText = await core_1.ux.prompt(`What placeholder text should ${statefulPropName} have, if any?`, { required: false });
74
+ })).path;
75
+ const statefulPropType = (await (0, enquirer_1.prompt)({
76
+ type: "select",
77
+ name: "type",
78
+ message: `What input type should ${statefulPropName} be?`,
79
+ choices: Object.entries(types_1.inputTypeDefinions).map(([k, v]) => ({
80
+ name: k,
81
+ message: v.prompt,
82
+ value: k,
83
+ })),
84
+ initial: 0,
85
+ })).type;
86
+ const placeholderText = (await (0, enquirer_1.prompt)({
87
+ type: "input",
88
+ name: "value",
89
+ message: `What placeholder text should ${statefulPropName} have, if any?`,
90
+ required: false,
91
+ })).value;
60
92
  statefulProps.push({
61
93
  label: statefulPropName,
62
94
  path: statefulPropPath,
63
95
  inputType: statefulPropType,
64
96
  placeholder: placeholderText || undefined,
65
97
  });
66
- const addAnotherStatefulProp = await core_1.ux.confirm("Do you want to add another stateful prop? [y/n]");
98
+ const addAnotherStatefulProp = (await (0, enquirer_1.prompt)({
99
+ type: "confirm",
100
+ name: "value",
101
+ message: "Do you want to add another stateful prop?",
102
+ initial: false,
103
+ })).value;
67
104
  if (!addAnotherStatefulProp) {
68
105
  break;
69
106
  }
70
107
  }
71
108
  }
72
109
  this.log();
73
- const hasEventHandlers = await core_1.ux.confirm("Does this component have event handlers? (e.g. a date picker component that has a On Change event handler) [y/n]");
110
+ this.log(`${(0, colorette_1.cyanBright)("ℹ")} ${(0, colorette_1.bold)("Event handlers")} represent the events your custom component can fire`);
111
+ this.log();
112
+ const hasEventHandlers = (await (0, enquirer_1.prompt)({
113
+ type: "confirm",
114
+ name: "value",
115
+ message: `Does this component have ${(0, colorette_1.bold)("event handlers")}? (e.g. a date picker component that has a On Change event handler)`,
116
+ initial: false,
117
+ })).value;
74
118
  const eventHandlers = [];
75
119
  if (hasEventHandlers) {
76
120
  for (;;) {
77
- const eventHandlerName = await core_1.ux.prompt("What is the label of the event handler? (e.g. On Change)");
78
- const eventHandlerPath = await (0, prompt_1.validatedPrompt)("What is the machine readable name of the event handler?", { default: (0, identifiers_1.suggestIdentifier)(eventHandlerName) || "onChange" }, (response) => {
79
- if (!(0, identifiers_1.isValidIdentifier)(response))
80
- return "Invalid identifier";
81
- if (eventHandlers.some((v) => v.path === response))
82
- return "Duplicate property name";
83
- return true;
84
- });
121
+ const eventHandlerName = (await (0, enquirer_1.prompt)({
122
+ name: "value",
123
+ type: "input",
124
+ message: "What is the label of the event handler? (e.g. On Change)",
125
+ validate: (response) => !(0, lodash_1.isEmpty)(response.trim()),
126
+ })).value.trim();
127
+ const eventHandlerPath = (await (0, enquirer_1.prompt)({
128
+ name: "value",
129
+ message: "What is the machine readable name of the event handler?",
130
+ type: "input",
131
+ initial: (0, identifiers_1.suggestIdentifier)(eventHandlerName) || "onChange",
132
+ validate: (response) => {
133
+ if (!(0, identifiers_1.isValidIdentifier)(response))
134
+ return "Invalid identifier";
135
+ if (eventHandlers.some((v) => v.path === response))
136
+ return "Duplicate property name";
137
+ return true;
138
+ },
139
+ })).value;
85
140
  eventHandlers.push({
86
141
  label: eventHandlerName,
87
142
  path: eventHandlerPath,
88
143
  });
89
- const addAnotherEventHandler = await core_1.ux.confirm("Do you want to add another event handler? [y/n]");
144
+ const addAnotherEventHandler = (await (0, enquirer_1.prompt)({
145
+ name: "value",
146
+ type: "confirm",
147
+ message: "Do you want to add another event handler?",
148
+ initial: false,
149
+ })).value;
90
150
  if (!addAnotherEventHandler) {
91
151
  break;
92
152
  }
@@ -54,7 +54,20 @@ export default function Component({
54
54
  ? ",\n" + eventHandlers.map((v) => indent(v, 2)).join(",\n")
55
55
  : ""}
56
56
  }: Props) {
57
- return <div>Hello World!</div>;
57
+ return (
58
+ <div
59
+ style={{
60
+ height: "100%",
61
+ width: "100%",
62
+ display: "flex",
63
+ alignItems: "center",
64
+ justifyContent: "center",
65
+ backgroundColor: "#a7aebe",
66
+ }}
67
+ >
68
+ <h1 style={{ color: "white" }}>{"<Insert Component Here>"}</h1>
69
+ </div>
70
+ );
58
71
  }
59
72
  `;
60
73
  exports.getDefaultComponentTsx = getDefaultComponentTsx;
@@ -6,10 +6,12 @@ export type SuperblocksMetadata = {
6
6
  lastUpdated: number;
7
7
  created: number;
8
8
  };
9
- export declare const LIVE_MODE = "live";
10
- export declare const modeFlagValues: string[];
9
+ export declare const LATEST_EDITS_MODE = "latest-edits";
10
+ export declare const MOST_RECENT_COMMIT_MODE = "most-recent-commit";
11
+ export declare const DEPLOYED_MODE = "deployed";
12
+ export declare const modeFlagValuesMap: Record<string, string>;
11
13
  export declare function modeFlagToViewMode(modeFlag: ModeFlag): ViewMode;
12
- export type ModeFlag = (typeof modeFlagValues)[number];
14
+ export type ModeFlag = (keyof typeof modeFlagValuesMap)[number];
13
15
  export declare const commonFlags: {
14
16
  mode: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
17
  };
@@ -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.commonFlags = exports.modeFlagToViewMode = exports.modeFlagValues = exports.LIVE_MODE = void 0;
3
+ exports.sortByKey = exports.getMode = exports.writeResourceToDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = exports.commonFlags = 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 node_path_1 = tslib_1.__importDefault(require("node:path"));
6
6
  const core_1 = require("@oclif/core");
@@ -11,15 +11,21 @@ const lodash_1 = require("lodash");
11
11
  const lodash_2 = tslib_1.__importDefault(require("lodash"));
12
12
  const slugify_1 = tslib_1.__importDefault(require("slugify"));
13
13
  const yaml_1 = require("yaml");
14
- exports.LIVE_MODE = "live";
15
- exports.modeFlagValues = [exports.LIVE_MODE, "latest", "deployed"];
14
+ exports.LATEST_EDITS_MODE = "latest-edits";
15
+ exports.MOST_RECENT_COMMIT_MODE = "most-recent-commit";
16
+ exports.DEPLOYED_MODE = "deployed";
17
+ exports.modeFlagValuesMap = {
18
+ [exports.LATEST_EDITS_MODE]: "Latest edits",
19
+ [exports.MOST_RECENT_COMMIT_MODE]: "Most recent commit",
20
+ [exports.DEPLOYED_MODE]: "Deployed",
21
+ };
16
22
  function modeFlagToViewMode(modeFlag) {
17
23
  switch (modeFlag) {
18
- case exports.LIVE_MODE:
24
+ case exports.LATEST_EDITS_MODE:
19
25
  return "export-live";
20
- case "latest":
26
+ case exports.MOST_RECENT_COMMIT_MODE:
21
27
  return "export-latest";
22
- case "deployed":
28
+ case exports.DEPLOYED_MODE:
23
29
  return "export-deployed";
24
30
  default:
25
31
  throw new Error(`Unsupported mode flag: ${modeFlag}`);
@@ -30,7 +36,7 @@ exports.commonFlags = {
30
36
  mode: core_1.Flags.string({
31
37
  char: "m",
32
38
  description: "Pull mode",
33
- options: exports.modeFlagValues,
39
+ options: Object.keys(exports.modeFlagValuesMap),
34
40
  }),
35
41
  };
36
42
  exports.SELECT_PROMPT_HELP = "Use ↑/↓ arrow keys, Enter to confirm";
@@ -137,10 +143,10 @@ async function getMode(task, mode) {
137
143
  {
138
144
  type: "Select",
139
145
  name: "mode",
140
- message: `Select fetch mode (${exports.SELECT_PROMPT_HELP})`,
141
- choices: exports.modeFlagValues.map((mode) => ({
146
+ message: `Select which version of a resource you would like to fetch (${exports.SELECT_PROMPT_HELP})`,
147
+ choices: Object.keys(exports.modeFlagValuesMap).map((mode) => ({
142
148
  name: mode,
143
- message: mode,
149
+ message: exports.modeFlagValuesMap[mode],
144
150
  })),
145
151
  initial: 0,
146
152
  multiple: false,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.11",
2
+ "version": "0.0.12",
3
3
  "commands": {
4
4
  "init": {
5
5
  "id": "init",
@@ -21,8 +21,8 @@
21
21
  "description": "Pull mode",
22
22
  "multiple": false,
23
23
  "options": [
24
- "live",
25
- "latest",
24
+ "latest-edits",
25
+ "most-recent-commit",
26
26
  "deployed"
27
27
  ]
28
28
  }
@@ -83,8 +83,8 @@
83
83
  "description": "Pull mode",
84
84
  "multiple": false,
85
85
  "options": [
86
- "live",
87
- "latest",
86
+ "latest-edits",
87
+ "most-recent-commit",
88
88
  "deployed"
89
89
  ]
90
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Official Superblocks CLI",
5
5
  "bin": {
6
6
  "superblocks": "bin/run"
@@ -1,7 +0,0 @@
1
- import { IPromptOptions } from "@oclif/core/lib/cli-ux";
2
- type ValidatorFn = (input: string) => string | boolean;
3
- /**
4
- * A wrapper around `oclif`'s `ux.prompt` function that allows for validation of user responses.
5
- */
6
- export declare function validatedPrompt(name: string, options: IPromptOptions | undefined, validator: ValidatorFn | RegExp): Promise<string>;
7
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validatedPrompt = void 0;
4
- const core_1 = require("@oclif/core");
5
- /**
6
- * A wrapper around `oclif`'s `ux.prompt` function that allows for validation of user responses.
7
- */
8
- async function validatedPrompt(name, options, validator) {
9
- let validatorFn;
10
- if (validator === undefined) {
11
- validatorFn = () => true;
12
- }
13
- else if (validator instanceof RegExp) {
14
- validatorFn = (response) => validator.test(response);
15
- }
16
- else {
17
- validatorFn = validator;
18
- }
19
- for (;;) {
20
- const response = await core_1.ux.prompt(name, options);
21
- const validationResult = validatorFn(response);
22
- if (typeof validationResult === "string") {
23
- core_1.ux.log(`Error: ${validationResult}`);
24
- }
25
- else if (validationResult === false) {
26
- core_1.ux.log("Error: Invalid response");
27
- }
28
- else {
29
- return response;
30
- }
31
- }
32
- }
33
- exports.validatedPrompt = validatedPrompt;