@superblocksteam/cli 1.0.0 → 1.0.2
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 +1 -1
- package/assets/custom-components/setup/package.json +1 -1
- package/dist/commands/components/create.js +11 -8
- package/dist/common/version-control.js +5 -8
- package/oclif.manifest.json +1 -1
- package/package.json +8 -7
- package/dist/util/identifiers.d.ts +0 -7
- package/dist/util/identifiers.js +0 -37
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/1.0.
|
|
15
|
+
@superblocksteam/cli/1.0.2 linux-x64 node-v18.18.0
|
|
16
16
|
$ superblocks --help [COMMAND]
|
|
17
17
|
USAGE
|
|
18
18
|
$ superblocks COMMAND
|
|
@@ -14,7 +14,6 @@ const fs = tslib_1.__importStar(require("fs-extra"));
|
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
15
|
const authenticated_command_1 = require("../../common/authenticated-command");
|
|
16
16
|
const create_component_defaults_1 = require("../../common/defaults/create-component-defaults");
|
|
17
|
-
const identifiers_1 = require("../../util/identifiers");
|
|
18
17
|
// eslint-disable-next-line unicorn/prefer-module
|
|
19
18
|
const rootDirectory = node_path_1.default.resolve(__dirname, "../../../");
|
|
20
19
|
const DEFAULT_PACKAGE_JSON_TEMPLATE_PATH = node_path_1.default.resolve(rootDirectory, "assets/custom-components/setup");
|
|
@@ -53,8 +52,8 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
|
|
|
53
52
|
type: "input",
|
|
54
53
|
name: "name",
|
|
55
54
|
message: "What is the machine readable name of the component you want to create?",
|
|
56
|
-
validate: (response) => (0,
|
|
57
|
-
initial: (0,
|
|
55
|
+
validate: (response) => (0, util_1.isValidIdentifier)(response) || "Invalid identifier",
|
|
56
|
+
initial: (0, util_1.suggestIdentifier)(displayName, true) || "ToDoList",
|
|
58
57
|
})).name;
|
|
59
58
|
this.log();
|
|
60
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")}`);
|
|
@@ -73,10 +72,12 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
|
|
|
73
72
|
name: "path",
|
|
74
73
|
message: "What is the path of the property? This will be used to access the property in your code (e.g. currentTasks)",
|
|
75
74
|
validate: (response) => {
|
|
76
|
-
if (!(0,
|
|
75
|
+
if (!(0, util_1.isValidIdentifier)(response))
|
|
77
76
|
return "Invalid identifier";
|
|
77
|
+
if ((0, util_1.isReservedPropertyName)(response))
|
|
78
|
+
return "Reserved property path (see https://docs.superblocks.com/applications/custom-components/faq#what-is-a-reserved-property)";
|
|
78
79
|
if (properties.some((v) => v.path === response))
|
|
79
|
-
return "Duplicate property
|
|
80
|
+
return "Duplicate property path";
|
|
80
81
|
return true;
|
|
81
82
|
},
|
|
82
83
|
})).path;
|
|
@@ -155,12 +156,14 @@ class CreateComponent extends authenticated_command_1.AuthenticatedApplicationCo
|
|
|
155
156
|
name: "value",
|
|
156
157
|
message: "What is the path of the event? This will be used to trigger the event in your code (e.g. onChange)",
|
|
157
158
|
type: "input",
|
|
158
|
-
initial: (0,
|
|
159
|
+
initial: (0, util_1.suggestIdentifier)(eventHandlerName) || "onChange",
|
|
159
160
|
validate: (response) => {
|
|
160
|
-
if (!(0,
|
|
161
|
+
if (!(0, util_1.isValidIdentifier)(response))
|
|
161
162
|
return "Invalid identifier";
|
|
163
|
+
if ((0, util_1.isReservedPropertyName)(response))
|
|
164
|
+
return "Reserved property path (see https://docs.superblocks.com/applications/custom-components/faq#what-is-a-reserved-property)";
|
|
162
165
|
if (events.some((v) => v.path === response))
|
|
163
|
-
return "Duplicate property
|
|
166
|
+
return "Duplicate property path";
|
|
164
167
|
return true;
|
|
165
168
|
},
|
|
166
169
|
})).value;
|
|
@@ -119,17 +119,16 @@ async function writeResourceToDisk(resourceType, resourceId, resource, rootPath,
|
|
|
119
119
|
};
|
|
120
120
|
if (resource.apis) {
|
|
121
121
|
for (const api of resource.apis) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const apiContent = (0, yaml_1.stringify)(api, {
|
|
122
|
+
const originalApiName = (_d = (_c = (_b = api.apiPb) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : api.actions.name;
|
|
123
|
+
const apiName = slugifyName(originalApiName);
|
|
124
|
+
const apiContent = (0, yaml_1.stringify)(api.apiPb, {
|
|
126
125
|
sortMapEntries: true,
|
|
127
126
|
});
|
|
128
127
|
const handleApi = async () => {
|
|
129
128
|
await fs.outputFile(`${apisDirName}/${apiName}.yaml`, apiContent);
|
|
130
129
|
};
|
|
131
130
|
apiPromises.push(handleApi());
|
|
132
|
-
applicationConfig.apis[api.id] =
|
|
131
|
+
applicationConfig.apis[api.id] = originalApiName;
|
|
133
132
|
}
|
|
134
133
|
await Promise.all(apiPromises);
|
|
135
134
|
}
|
|
@@ -152,15 +151,13 @@ async function writeResourceToDisk(resourceType, resourceId, resource, rootPath,
|
|
|
152
151
|
case "BACKEND": {
|
|
153
152
|
const parentDirName = "backends";
|
|
154
153
|
const apiName = slugifyName((_j = (_h = (_g = resource.apiPb) === null || _g === void 0 ? void 0 : _g.metadata) === null || _h === void 0 ? void 0 : _h.name) !== null && _j !== void 0 ? _j : resource.actions.name);
|
|
155
|
-
// server is still sending actions for a backwards compatibility
|
|
156
|
-
delete resource.actions;
|
|
157
154
|
const newRelativeLocation = `${parentDirName}/${apiName}`;
|
|
158
155
|
const relativeLocation = existingRelativeLocation !== null && existingRelativeLocation !== void 0 ? existingRelativeLocation : newRelativeLocation;
|
|
159
156
|
const backendDirName = node_path_1.default.resolve(rootPath, relativeLocation);
|
|
160
157
|
if (!(await fs.pathExists(backendDirName))) {
|
|
161
158
|
await fs.mkdir(backendDirName, { recursive: true });
|
|
162
159
|
}
|
|
163
|
-
const backendContent = (0, yaml_1.stringify)(resource, {
|
|
160
|
+
const backendContent = (0, yaml_1.stringify)(resource.apiPb, {
|
|
164
161
|
sortMapEntries: true,
|
|
165
162
|
});
|
|
166
163
|
await fs.outputFile(`${backendDirName}/api.yaml`, backendContent);
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Official Superblocks CLI",
|
|
5
5
|
"bin": {
|
|
6
6
|
"superblocks": "bin/run"
|
|
@@ -18,11 +18,11 @@
|
|
|
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": "1.0.
|
|
22
|
-
"@superblocksteam/react-shim": "1.0.
|
|
23
|
-
"@superblocksteam/sdk": "1.0.
|
|
24
|
-
"@superblocksteam/util": "1.0.
|
|
25
|
-
"@superblocksteam/vite-custom-component-reload-plugin": "1.0.
|
|
21
|
+
"@superblocksteam/css-plugin": "1.0.2",
|
|
22
|
+
"@superblocksteam/react-shim": "1.0.2",
|
|
23
|
+
"@superblocksteam/sdk": "1.0.2",
|
|
24
|
+
"@superblocksteam/util": "1.0.2",
|
|
25
|
+
"@superblocksteam/vite-custom-component-reload-plugin": "1.0.2",
|
|
26
26
|
"@vitejs/plugin-react": "^4.0.4",
|
|
27
27
|
"colorette": "^2.0.19",
|
|
28
28
|
"enquirer": "^2.3.6",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
46
46
|
"@typescript-eslint/parser": "^5.60.1",
|
|
47
47
|
"chai": "^4",
|
|
48
|
-
"eslint": "^8.
|
|
48
|
+
"eslint": "^8.48.0",
|
|
49
49
|
"eslint-config-prettier": "8.8.0",
|
|
50
50
|
"eslint-plugin-import": "2.27.5",
|
|
51
51
|
"eslint-plugin-prettier": "4.2.1",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"typescript": "^5.1.6"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
|
+
"preinstall": "node -e 'if (process.versions.node.split(`.`)[0] < 16) { console.error(`Incompatible Node version: Please use Node.js v16 or higher`); process.exit(1);}'",
|
|
62
63
|
"build": "tsc --build",
|
|
63
64
|
"clean": "npm run clean:build && rm -rf node_modules",
|
|
64
65
|
"clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Suggest an identifier based on a label, e.g. `My Component` -> `myComponent`.
|
|
3
|
-
* @param label The label to suggest an identifier for.
|
|
4
|
-
* @param capitalizeFirst Whether to capitalize the first letter of the identifier.
|
|
5
|
-
*/
|
|
6
|
-
export declare function suggestIdentifier(label: string, capitalizeFirst?: boolean): string;
|
|
7
|
-
export declare function isValidIdentifier(str: string): boolean;
|
package/dist/util/identifiers.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidIdentifier = exports.suggestIdentifier = void 0;
|
|
4
|
-
// convert a string to upper camel case, e.g. "123 & this is my component, foo-bar" -> "123ThisIsMyComponentFooBar"
|
|
5
|
-
function wordsToUpperCamelCase(str) {
|
|
6
|
-
return str
|
|
7
|
-
.split(/[^A-Za-z0-9_]+/)
|
|
8
|
-
.filter(Boolean)
|
|
9
|
-
.map((word) => word[0].toUpperCase() + word.slice(1))
|
|
10
|
-
.join("");
|
|
11
|
-
}
|
|
12
|
-
const digits = "Zero One Two Three Four Five Six Seven Eight Nine".split(" ");
|
|
13
|
-
// convert digits to words, e.g. "123" -> "OneTwoThree"
|
|
14
|
-
function digitsToWords(str) {
|
|
15
|
-
return str.replace(/\d/g, (char) => { var _a; return (_a = digits[parseInt(char, 10)]) !== null && _a !== void 0 ? _a : char; });
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Suggest an identifier based on a label, e.g. `My Component` -> `myComponent`.
|
|
19
|
-
* @param label The label to suggest an identifier for.
|
|
20
|
-
* @param capitalizeFirst Whether to capitalize the first letter of the identifier.
|
|
21
|
-
*/
|
|
22
|
-
function suggestIdentifier(label, capitalizeFirst = false) {
|
|
23
|
-
const upperCamelCase = wordsToUpperCamelCase(label)
|
|
24
|
-
// convert any digits at the start of the string to words as these are not valid in identifiers
|
|
25
|
-
.replace(/^\d+/, digitsToWords);
|
|
26
|
-
if (capitalizeFirst) {
|
|
27
|
-
return upperCamelCase;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return upperCamelCase[0].toLowerCase() + upperCamelCase.slice(1);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.suggestIdentifier = suggestIdentifier;
|
|
34
|
-
function isValidIdentifier(str) {
|
|
35
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(str);
|
|
36
|
-
}
|
|
37
|
-
exports.isValidIdentifier = isValidIdentifier;
|