@superblocksteam/cli 1.0.0 → 1.1.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 +49 -18
- package/assets/custom-components/setup/package.json +1 -1
- package/dist/commands/components/create.js +11 -8
- package/dist/commands/components/upload.d.ts +3 -0
- package/dist/commands/components/upload.js +16 -2
- package/dist/commands/components/watch.js +20 -3
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +26 -15
- package/dist/commands/login.js +3 -5
- package/dist/commands/pull.d.ts +2 -1
- package/dist/commands/pull.js +53 -23
- package/dist/commands/push.d.ts +14 -0
- package/dist/commands/push.js +240 -0
- package/dist/commands/rm.d.ts +1 -1
- package/dist/commands/rm.js +4 -4
- package/dist/common/authenticated-command.js +2 -0
- package/dist/common/version-control.d.ts +13 -1
- package/dist/common/version-control.js +93 -12
- package/oclif.manifest.json +56 -12
- package/package.json +9 -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.
|
|
15
|
+
@superblocksteam/cli/1.1.0 linux-x64 node-v18.18.0
|
|
16
16
|
$ superblocks --help [COMMAND]
|
|
17
17
|
USAGE
|
|
18
18
|
$ superblocks COMMAND
|
|
@@ -27,11 +27,12 @@ USAGE
|
|
|
27
27
|
* [`superblocks components watch`](#superblocks-components-watch)
|
|
28
28
|
* [`superblocks config set PROPERTY VALUE`](#superblocks-config-set-property-value)
|
|
29
29
|
* [`superblocks help [COMMANDS]`](#superblocks-help-commands)
|
|
30
|
-
* [`superblocks init [
|
|
30
|
+
* [`superblocks init [RESOURCE_URL]`](#superblocks-init-resource_url)
|
|
31
31
|
* [`superblocks login`](#superblocks-login)
|
|
32
32
|
* [`superblocks migrate`](#superblocks-migrate)
|
|
33
|
-
* [`superblocks pull [
|
|
34
|
-
* [`superblocks
|
|
33
|
+
* [`superblocks pull [RESOURCE_PATH]`](#superblocks-pull-resource_path)
|
|
34
|
+
* [`superblocks push [RESOURCE_PATH]`](#superblocks-push-resource_path)
|
|
35
|
+
* [`superblocks rm [RESOURCE_PATH]`](#superblocks-rm-resource_path)
|
|
35
36
|
|
|
36
37
|
## `superblocks components create`
|
|
37
38
|
|
|
@@ -69,13 +70,18 @@ Upload creates a production-ready bundle and saves the files for use outside of
|
|
|
69
70
|
|
|
70
71
|
```
|
|
71
72
|
USAGE
|
|
72
|
-
$ superblocks components upload
|
|
73
|
+
$ superblocks components upload [-b <value>]
|
|
74
|
+
|
|
75
|
+
FLAGS
|
|
76
|
+
-b, --branch=<value> Superblocks branch to push to, the current (local) git branch will be used by default
|
|
73
77
|
|
|
74
78
|
DESCRIPTION
|
|
75
79
|
Upload creates a production-ready bundle and saves the files for use outside of Local Development mode.
|
|
76
80
|
|
|
77
81
|
EXAMPLES
|
|
78
82
|
$ superblocks components upload
|
|
83
|
+
|
|
84
|
+
$ superblocks components upload -b feature-branch
|
|
79
85
|
```
|
|
80
86
|
|
|
81
87
|
## `superblocks components watch`
|
|
@@ -132,16 +138,17 @@ DESCRIPTION
|
|
|
132
138
|
|
|
133
139
|
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.16/src/commands/help.ts)_
|
|
134
140
|
|
|
135
|
-
## `superblocks init [
|
|
141
|
+
## `superblocks init [RESOURCE_URL]`
|
|
136
142
|
|
|
137
143
|
Interactively configure the current directory as a Superblocks project or initialize new services in an already configured Superblocks project directory
|
|
138
144
|
|
|
139
145
|
```
|
|
140
146
|
USAGE
|
|
141
|
-
$ superblocks init [
|
|
147
|
+
$ superblocks init [RESOURCE_URL] [-m latest-edits|most-recent-commit|deployed]
|
|
142
148
|
|
|
143
149
|
ARGUMENTS
|
|
144
|
-
|
|
150
|
+
RESOURCE_URL Superblocks resource URL (i.e.
|
|
151
|
+
https://app.superblocks.com/applications/<application_id>/pages/<page_id>)
|
|
145
152
|
|
|
146
153
|
FLAGS
|
|
147
154
|
-m, --mode=<option> Pull mode
|
|
@@ -187,20 +194,21 @@ EXAMPLES
|
|
|
187
194
|
$ superblocks migrate
|
|
188
195
|
```
|
|
189
196
|
|
|
190
|
-
## `superblocks pull [
|
|
197
|
+
## `superblocks pull [RESOURCE_PATH]`
|
|
191
198
|
|
|
192
199
|
Download objects from Superblocks and save them locally
|
|
193
200
|
|
|
194
201
|
```
|
|
195
202
|
USAGE
|
|
196
|
-
$ superblocks pull [
|
|
203
|
+
$ superblocks pull [RESOURCE_PATH] [-m latest-edits|most-recent-commit|deployed] [-b <value>]
|
|
197
204
|
|
|
198
205
|
ARGUMENTS
|
|
199
|
-
|
|
206
|
+
RESOURCE_PATH Superblocks resource location to pull (i.e. apps/my-app)
|
|
200
207
|
|
|
201
208
|
FLAGS
|
|
202
|
-
-
|
|
203
|
-
|
|
209
|
+
-b, --branch=<value> Superblocks branch to pull from, the current git branch will be used by default
|
|
210
|
+
-m, --mode=<option> [default: latest-edits] Pull mode
|
|
211
|
+
<options: latest-edits|most-recent-commit|deployed>
|
|
204
212
|
|
|
205
213
|
DESCRIPTION
|
|
206
214
|
Download objects from Superblocks and save them locally
|
|
@@ -210,21 +218,44 @@ EXAMPLES
|
|
|
210
218
|
|
|
211
219
|
$ superblocks pull apps/my-app
|
|
212
220
|
|
|
213
|
-
$ superblocks pull
|
|
221
|
+
$ superblocks pull apps/my-app -b feature-branch
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## `superblocks push [RESOURCE_PATH]`
|
|
225
|
+
|
|
226
|
+
Import objects from local filesystem to Superblocks
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
USAGE
|
|
230
|
+
$ superblocks push [RESOURCE_PATH] [-b <value>]
|
|
231
|
+
|
|
232
|
+
ARGUMENTS
|
|
233
|
+
RESOURCE_PATH Superblocks resource location to push (e.g. apps/my-app)
|
|
234
|
+
|
|
235
|
+
FLAGS
|
|
236
|
+
-b, --branch=<value> Superblocks branch to push to, the current git branch will be used by default
|
|
237
|
+
|
|
238
|
+
DESCRIPTION
|
|
239
|
+
Import objects from local filesystem to Superblocks
|
|
240
|
+
|
|
241
|
+
EXAMPLES
|
|
242
|
+
$ superblocks push
|
|
243
|
+
|
|
244
|
+
$ superblocks push apps/my-app
|
|
214
245
|
|
|
215
|
-
$ superblocks
|
|
246
|
+
$ superblocks push apps/my-app -b feature-branch
|
|
216
247
|
```
|
|
217
248
|
|
|
218
|
-
## `superblocks rm [
|
|
249
|
+
## `superblocks rm [RESOURCE_PATH]`
|
|
219
250
|
|
|
220
251
|
Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)
|
|
221
252
|
|
|
222
253
|
```
|
|
223
254
|
USAGE
|
|
224
|
-
$ superblocks rm [
|
|
255
|
+
$ superblocks rm [RESOURCE_PATH]
|
|
225
256
|
|
|
226
257
|
ARGUMENTS
|
|
227
|
-
|
|
258
|
+
RESOURCE_PATH Superblocks resource location (i.e. apps/my-spectacular-app)
|
|
228
259
|
|
|
229
260
|
DESCRIPTION
|
|
230
261
|
Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if
|
|
@@ -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;
|
|
@@ -2,5 +2,8 @@ import { AuthenticatedApplicationCommand } from "../../common/authenticated-comm
|
|
|
2
2
|
export default class Upload extends AuthenticatedApplicationCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
branch: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
+
};
|
|
5
8
|
run(): Promise<void>;
|
|
6
9
|
}
|
|
@@ -7,11 +7,14 @@ const css_plugin_1 = require("@superblocksteam/css-plugin");
|
|
|
7
7
|
const react_shim_1 = require("@superblocksteam/react-shim");
|
|
8
8
|
const util_1 = require("@superblocksteam/util");
|
|
9
9
|
const plugin_react_1 = tslib_1.__importDefault(require("@vitejs/plugin-react"));
|
|
10
|
+
const colorette_1 = require("colorette");
|
|
10
11
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
11
12
|
const vite_1 = require("vite");
|
|
12
13
|
const authenticated_command_1 = require("../../common/authenticated-command");
|
|
14
|
+
const version_control_1 = require("../../common/version-control");
|
|
13
15
|
class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
14
16
|
async run() {
|
|
17
|
+
const { flags } = await this.parse(Upload);
|
|
15
18
|
core_1.ux.action.start("Scanning for Superblocks components...");
|
|
16
19
|
const exists = await fs.pathExists(util_1.CUSTOM_COMPONENTS_PATH);
|
|
17
20
|
if (!exists) {
|
|
@@ -20,6 +23,7 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
|
20
23
|
exit: 1,
|
|
21
24
|
});
|
|
22
25
|
}
|
|
26
|
+
const branch = flags.branch || (await (0, version_control_1.getCurrentGitBranchIfGit)());
|
|
23
27
|
const headers = {
|
|
24
28
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.REGISTER,
|
|
25
29
|
};
|
|
@@ -89,7 +93,7 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
|
89
93
|
];
|
|
90
94
|
await walkThroughDirectory(".", fileRelativePaths, excluded);
|
|
91
95
|
this.log(fileRelativePaths.join("\n"));
|
|
92
|
-
await this.getSdk().uploadComponents(this.applicationConfig.id, configs, fileRelativePaths);
|
|
96
|
+
await this.getSdk().uploadComponents(this.applicationConfig.id, configs, fileRelativePaths, branch);
|
|
93
97
|
core_1.ux.action.stop();
|
|
94
98
|
}
|
|
95
99
|
catch (e) {
|
|
@@ -97,10 +101,20 @@ class Upload extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
|
97
101
|
this.error(`Failed to upload components - ${e.message}`, { exit: 1 });
|
|
98
102
|
}
|
|
99
103
|
this.log("You can now disable local dev mode and test your production assets");
|
|
104
|
+
this.log((0, colorette_1.bold)((0, colorette_1.green)("Once you are done developing please remember to commit your changes in the Superblocks UI.")));
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
107
|
Upload.description = "Upload creates a production-ready bundle and saves the files for use outside of Local Development mode.";
|
|
103
|
-
Upload.examples = [
|
|
108
|
+
Upload.examples = [
|
|
109
|
+
"<%= config.bin %> components upload",
|
|
110
|
+
"<%= config.bin %> components upload -b feature-branch",
|
|
111
|
+
];
|
|
112
|
+
Upload.flags = {
|
|
113
|
+
branch: core_1.Flags.string({
|
|
114
|
+
char: "b",
|
|
115
|
+
description: "Superblocks branch to push to, the current (local) git branch will be used by default",
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
104
118
|
exports.default = Upload;
|
|
105
119
|
async function walkThroughDirectory(directory, mutableFiles, excluded) {
|
|
106
120
|
const files = await fs.readdir(directory);
|
|
@@ -9,17 +9,29 @@ const plugin_react_1 = tslib_1.__importDefault(require("@vitejs/plugin-react"));
|
|
|
9
9
|
const colorette_1 = require("colorette");
|
|
10
10
|
const vite_1 = require("vite");
|
|
11
11
|
const authenticated_command_1 = require("../../common/authenticated-command");
|
|
12
|
+
const version_control_1 = require("../../common/version-control");
|
|
12
13
|
function healthEndpointMiddleware() {
|
|
13
14
|
return {
|
|
14
15
|
name: "health-endpoint-middleware",
|
|
15
16
|
configureServer: (server) => {
|
|
16
|
-
server.middlewares.use("/health", (req, res) => {
|
|
17
|
+
server.middlewares.use("/health", async (req, res) => {
|
|
18
|
+
let branch;
|
|
19
|
+
try {
|
|
20
|
+
branch = await (0, version_control_1.getCurrentGitBranchIfGit)();
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
branch = null;
|
|
24
|
+
}
|
|
25
|
+
const gitState = branch
|
|
26
|
+
? { active: true, branch }
|
|
27
|
+
: { active: false };
|
|
17
28
|
res.setHeader("Cache-Control", "no-cache");
|
|
18
29
|
res.setHeader("Content-Type", "application/json");
|
|
19
30
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
20
31
|
const response = {
|
|
21
32
|
status: "up",
|
|
22
33
|
uptime: Math.floor(process.uptime()),
|
|
34
|
+
git: gitState,
|
|
23
35
|
};
|
|
24
36
|
res.write(JSON.stringify(response) + "\n");
|
|
25
37
|
res.end();
|
|
@@ -36,8 +48,13 @@ class Watch extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
|
36
48
|
await this.registerComponents(headers);
|
|
37
49
|
this.log((0, colorette_1.yellow)("Remember to refresh your application to see any newly registered components."));
|
|
38
50
|
this.log();
|
|
51
|
+
const editModeUrl = new URL(await this.getEditModeUrl());
|
|
52
|
+
editModeUrl.searchParams.set("devMode", "true");
|
|
53
|
+
const branch = await (0, version_control_1.getCurrentGitBranchIfGit)();
|
|
54
|
+
if (branch) {
|
|
55
|
+
editModeUrl.searchParams.set("branch", branch);
|
|
56
|
+
}
|
|
39
57
|
const port = 3002;
|
|
40
|
-
const editModeUrl = await this.getEditModeUrl();
|
|
41
58
|
const viteLogger = (0, vite_1.createLogger)();
|
|
42
59
|
viteLogger.info = (message) => {
|
|
43
60
|
this.log(message);
|
|
@@ -75,7 +92,7 @@ class Watch extends authenticated_command_1.AuthenticatedApplicationCommand {
|
|
|
75
92
|
this.log((0, colorette_1.green)(`Local server started at port ${port}`));
|
|
76
93
|
this.log((0, colorette_1.green)(`Visit your application at:`));
|
|
77
94
|
this.log();
|
|
78
|
-
this.log((0, colorette_1.bold)((0, colorette_1.magenta)(
|
|
95
|
+
this.log((0, colorette_1.bold)((0, colorette_1.magenta)(editModeUrl.href)));
|
|
79
96
|
this.log();
|
|
80
97
|
this.log((0, colorette_1.yellow)(`Please ensure that Local Dev Mode is enabled in your Application so that the component is fetched from your local dev server. Learn more about Local Dev Mode here: ${(0, colorette_1.magenta)("https://docs.superblocks.com/applications/custom-components/development-lifecycle#local-development-mode")}`));
|
|
81
98
|
})();
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export default class Initialize extends AuthenticatedCommand {
|
|
|
6
6
|
mode: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
7
|
};
|
|
8
8
|
static args: {
|
|
9
|
-
|
|
9
|
+
resource_url: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
10
10
|
};
|
|
11
11
|
run(): Promise<void>;
|
|
12
12
|
private createTasks;
|
package/dist/commands/init.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
4
5
|
const core_1 = require("@oclif/core");
|
|
5
6
|
const util_1 = require("@superblocksteam/util");
|
|
6
7
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
@@ -27,7 +28,10 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
27
28
|
ctx.fetchedResources = {};
|
|
28
29
|
ctx.writtenResources = {};
|
|
29
30
|
try {
|
|
30
|
-
|
|
31
|
+
[
|
|
32
|
+
ctx.existingSuperblocksRootConfig,
|
|
33
|
+
ctx.superblocksRootConfigPath,
|
|
34
|
+
] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
31
35
|
}
|
|
32
36
|
catch {
|
|
33
37
|
// no existing superblocks config
|
|
@@ -39,7 +43,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
39
43
|
task: (ctx, task) => task.newListr([
|
|
40
44
|
{
|
|
41
45
|
title: "Fetching applications...",
|
|
42
|
-
enabled: () => !args.
|
|
46
|
+
enabled: () => !args.resource_url,
|
|
43
47
|
task: async (ctx, task) => {
|
|
44
48
|
// applications choices
|
|
45
49
|
const applications = await this.getSdk().fetchApplications();
|
|
@@ -56,15 +60,16 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
56
60
|
},
|
|
57
61
|
{
|
|
58
62
|
title: "Fetching resource by resourceUrl...",
|
|
59
|
-
enabled: () => args.
|
|
63
|
+
enabled: () => !(0, lodash_1.isEmpty)(args.resource_url),
|
|
60
64
|
task: async (ctx, task) => {
|
|
61
|
-
const [resourceId, resourceType] = getResourceIdFromUrl(args.
|
|
65
|
+
const [resourceId, resourceType] = getResourceIdFromUrl(args.resource_url);
|
|
62
66
|
if (resourceType === "APPLICATION") {
|
|
63
67
|
const headers = {
|
|
64
68
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.INIT,
|
|
65
69
|
};
|
|
66
70
|
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
67
71
|
applicationId: resourceId,
|
|
72
|
+
branch: version_control_1.DEFAULT_BRANCH,
|
|
68
73
|
headers,
|
|
69
74
|
});
|
|
70
75
|
if (!application) {
|
|
@@ -100,6 +105,11 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
100
105
|
title: "Writing resources to a disk...",
|
|
101
106
|
task: async (ctx, task) => {
|
|
102
107
|
const subtasks = [];
|
|
108
|
+
// if ctx.superblocksRootConfigPath is defined, we are initializing a new resource in an existing Superblocks project
|
|
109
|
+
// otherwise, we are initializing a new Superblocks project
|
|
110
|
+
const superblocksRootPath = ctx.superblocksRootConfigPath
|
|
111
|
+
? path_1.default.resolve(path_1.default.dirname(ctx.superblocksRootConfigPath), "..")
|
|
112
|
+
: undefined;
|
|
103
113
|
for (const resourceId of ctx.resourceIdsToInitialize) {
|
|
104
114
|
const resource = ctx.fetchedResources[resourceId];
|
|
105
115
|
if (!resource) {
|
|
@@ -115,12 +125,13 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
115
125
|
};
|
|
116
126
|
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
117
127
|
applicationId: resourceId,
|
|
128
|
+
branch: version_control_1.DEFAULT_BRANCH,
|
|
118
129
|
viewMode: ctx.viewMode,
|
|
119
130
|
headers,
|
|
120
131
|
});
|
|
121
132
|
task.title += `: fetched`;
|
|
122
133
|
ctx.writtenResources[resourceId] =
|
|
123
|
-
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, process.cwd());
|
|
134
|
+
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, superblocksRootPath !== null && superblocksRootPath !== void 0 ? superblocksRootPath : process.cwd());
|
|
124
135
|
task.title += `: done`;
|
|
125
136
|
},
|
|
126
137
|
});
|
|
@@ -152,7 +163,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
152
163
|
{
|
|
153
164
|
title: "Updating Superblocks project file...",
|
|
154
165
|
task: async (ctx) => {
|
|
155
|
-
var _a, _b;
|
|
166
|
+
var _a, _b, _c;
|
|
156
167
|
const superblocksConfig = {
|
|
157
168
|
configType: "ROOT",
|
|
158
169
|
resources: {},
|
|
@@ -165,14 +176,14 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
165
176
|
superblocksConfig.resources[resourceId] = resource;
|
|
166
177
|
}
|
|
167
178
|
// existing resources
|
|
168
|
-
for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.
|
|
179
|
+
for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
|
|
169
180
|
superblocksConfig.resources[resourceId] = resource;
|
|
170
181
|
}
|
|
171
182
|
if (!(await fs.exists(util_1.SUPERBLOCKS_HOME_FOLDER_NAME))) {
|
|
172
183
|
await fs.mkdir(util_1.SUPERBLOCKS_HOME_FOLDER_NAME);
|
|
173
184
|
}
|
|
174
185
|
// create superblocks.json file
|
|
175
|
-
await fs.writeFile(util_1.RESOURCE_CONFIG_PATH, JSON.stringify((0, version_control_1.sortByKey)(superblocksConfig), null, 2));
|
|
186
|
+
await fs.writeFile((_c = ctx.superblocksRootConfigPath) !== null && _c !== void 0 ? _c : util_1.RESOURCE_CONFIG_PATH, JSON.stringify((0, version_control_1.sortByKey)(superblocksConfig), null, 2));
|
|
176
187
|
},
|
|
177
188
|
},
|
|
178
189
|
], {
|
|
@@ -182,13 +193,13 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
182
193
|
}
|
|
183
194
|
async getResourcesToInitialize(ctx, task, args) {
|
|
184
195
|
var _a, _b;
|
|
185
|
-
if (args.
|
|
196
|
+
if (args.resource_url) {
|
|
186
197
|
try {
|
|
187
|
-
const [resourceId] = getResourceIdFromUrl(args.
|
|
198
|
+
const [resourceId] = getResourceIdFromUrl(args.resource_url);
|
|
188
199
|
return [resourceId];
|
|
189
200
|
}
|
|
190
201
|
catch {
|
|
191
|
-
throw new Error(`Invalid resource URL: ${args.
|
|
202
|
+
throw new Error(`Invalid resource URL: ${args.resource_url}`);
|
|
192
203
|
}
|
|
193
204
|
}
|
|
194
205
|
else {
|
|
@@ -199,9 +210,9 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
199
210
|
choices.push({
|
|
200
211
|
name: resourceId,
|
|
201
212
|
message: `${resource.name} (${resource.resourceType})`,
|
|
202
|
-
disabled: (_a = ctx.
|
|
213
|
+
disabled: (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId],
|
|
203
214
|
});
|
|
204
|
-
if ((_b = ctx.
|
|
215
|
+
if ((_b = ctx.existingSuperblocksRootConfig) === null || _b === void 0 ? void 0 : _b.resources[resourceId]) {
|
|
205
216
|
initialSelections.push(counter);
|
|
206
217
|
}
|
|
207
218
|
counter++;
|
|
@@ -229,7 +240,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
229
240
|
.join(", ")}. Please make sure to select unique resources or rename them so that they have unique names.`);
|
|
230
241
|
}
|
|
231
242
|
// filter out disabled resources
|
|
232
|
-
return resourceIdsToInitialize.filter((resourceId) => { var _a; return !((_a = ctx.
|
|
243
|
+
return resourceIdsToInitialize.filter((resourceId) => { var _a; return !((_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId]); });
|
|
233
244
|
}
|
|
234
245
|
}
|
|
235
246
|
async findDuplicates(selectedResourcesIds, resources) {
|
|
@@ -266,7 +277,7 @@ Initialize.flags = {
|
|
|
266
277
|
}),
|
|
267
278
|
};
|
|
268
279
|
Initialize.args = {
|
|
269
|
-
|
|
280
|
+
resource_url: core_1.Args.string({
|
|
270
281
|
description: "Superblocks resource URL (i.e. https://app.superblocks.com/applications/<application_id>/pages/<page_id>)",
|
|
271
282
|
required: false,
|
|
272
283
|
}),
|
package/dist/commands/login.js
CHANGED
|
@@ -15,15 +15,13 @@ class Login extends core_1.Command {
|
|
|
15
15
|
var _a;
|
|
16
16
|
const { flags } = await this.parse(Login);
|
|
17
17
|
let token = flags.token;
|
|
18
|
-
|
|
18
|
+
const result = await (0, util_1.getLocalTokenWithUrlIfExists)();
|
|
19
|
+
const superblocksBaseUrl = (_a = result === null || result === void 0 ? void 0 : result.superblocksBaseUrl) !== null && _a !== void 0 ? _a : this.DEFAULT_BASE_URL;
|
|
19
20
|
if (!token) {
|
|
20
|
-
const result = await (0, util_1.getLocalTokenWithUrlIfExists)();
|
|
21
21
|
if (result && "token" in result) {
|
|
22
|
-
|
|
22
|
+
token = result.token;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
superblocksBaseUrl =
|
|
26
|
-
(_a = result === null || result === void 0 ? void 0 : result.superblocksBaseUrl) !== null && _a !== void 0 ? _a : this.DEFAULT_BASE_URL;
|
|
27
25
|
const tokenPageUrl = new URL("personal-settings#apiKey", superblocksBaseUrl).href;
|
|
28
26
|
token = (await (0, enquirer_1.prompt)({
|
|
29
27
|
type: "password",
|
package/dist/commands/pull.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ export default class Pull extends AuthenticatedCommand {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
mode: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
+
branch: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
};
|
|
8
9
|
static args: {
|
|
9
|
-
|
|
10
|
+
resource_path: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
10
11
|
};
|
|
11
12
|
run(): Promise<void>;
|
|
12
13
|
private createTasks;
|