@superblocksteam/cli 0.0.23 → 1.0.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 +23 -1
- package/assets/custom-components/setup/package.json +1 -1
- package/dist/commands/components/watch.js +3 -0
- package/dist/commands/init.js +8 -8
- package/dist/commands/pull.js +81 -7
- package/dist/commands/rm.d.ts +12 -0
- package/dist/commands/rm.js +185 -0
- package/dist/common/authenticated-command.js +10 -7
- package/dist/common/version-control.d.ts +2 -1
- package/dist/common/version-control.js +6 -2
- package/oclif.manifest.json +21 -1
- package/package.json +6 -6
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
|
|
15
|
+
@superblocksteam/cli/1.0.0 linux-x64 node-v18.17.1
|
|
16
16
|
$ superblocks --help [COMMAND]
|
|
17
17
|
USAGE
|
|
18
18
|
$ superblocks COMMAND
|
|
@@ -31,6 +31,7 @@ USAGE
|
|
|
31
31
|
* [`superblocks login`](#superblocks-login)
|
|
32
32
|
* [`superblocks migrate`](#superblocks-migrate)
|
|
33
33
|
* [`superblocks pull [ONLY]`](#superblocks-pull-only)
|
|
34
|
+
* [`superblocks rm [RESOURCELOCATION]`](#superblocks-rm-resourcelocation)
|
|
34
35
|
|
|
35
36
|
## `superblocks components create`
|
|
36
37
|
|
|
@@ -213,4 +214,25 @@ EXAMPLES
|
|
|
213
214
|
|
|
214
215
|
$ superblocks pull backends/my-scheduled-job
|
|
215
216
|
```
|
|
217
|
+
|
|
218
|
+
## `superblocks rm [RESOURCELOCATION]`
|
|
219
|
+
|
|
220
|
+
Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
USAGE
|
|
224
|
+
$ superblocks rm [RESOURCELOCATION]
|
|
225
|
+
|
|
226
|
+
ARGUMENTS
|
|
227
|
+
RESOURCELOCATION Superblocks resource location (i.e. apps/my-spectacular-app)
|
|
228
|
+
|
|
229
|
+
DESCRIPTION
|
|
230
|
+
Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if
|
|
231
|
+
it exists)
|
|
232
|
+
|
|
233
|
+
EXAMPLES
|
|
234
|
+
$ superblocks rm
|
|
235
|
+
|
|
236
|
+
$ superblocks rm apps/my-spectacular-app
|
|
237
|
+
```
|
|
216
238
|
<!-- commandsstop -->
|
package/dist/commands/init.js
CHANGED
|
@@ -26,7 +26,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
26
26
|
task: async (ctx) => {
|
|
27
27
|
ctx.fetchedResources = {};
|
|
28
28
|
ctx.writtenResources = {};
|
|
29
|
-
ctx.now = new Date().toISOString();
|
|
30
29
|
try {
|
|
31
30
|
ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)(true))[0];
|
|
32
31
|
}
|
|
@@ -36,7 +35,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
36
35
|
},
|
|
37
36
|
},
|
|
38
37
|
{
|
|
39
|
-
title: "Fetching applications
|
|
38
|
+
title: "Fetching applications...",
|
|
40
39
|
task: (ctx, task) => task.newListr([
|
|
41
40
|
{
|
|
42
41
|
title: "Fetching applications...",
|
|
@@ -46,7 +45,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
46
45
|
const applications = await this.getSdk().fetchApplications();
|
|
47
46
|
for (const app of applications) {
|
|
48
47
|
if (app.isEditable) {
|
|
49
|
-
0;
|
|
50
48
|
ctx.fetchedResources[app.id] = {
|
|
51
49
|
resourceType: "APPLICATION",
|
|
52
50
|
name: app.name,
|
|
@@ -65,10 +63,13 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
65
63
|
const headers = {
|
|
66
64
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.INIT,
|
|
67
65
|
};
|
|
68
|
-
const application = await this.getSdk().
|
|
66
|
+
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
69
67
|
applicationId: resourceId,
|
|
70
68
|
headers,
|
|
71
69
|
});
|
|
70
|
+
if (!application) {
|
|
71
|
+
throw new util_1.NotFoundError(`Application ${resourceId} was not found`);
|
|
72
|
+
}
|
|
72
73
|
ctx.fetchedResources[application.application.id] = {
|
|
73
74
|
resourceType,
|
|
74
75
|
name: application.application.name,
|
|
@@ -99,7 +100,6 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
99
100
|
title: "Writing resources to a disk...",
|
|
100
101
|
task: async (ctx, task) => {
|
|
101
102
|
const subtasks = [];
|
|
102
|
-
const now = new Date().toISOString();
|
|
103
103
|
for (const resourceId of ctx.resourceIdsToInitialize) {
|
|
104
104
|
const resource = ctx.fetchedResources[resourceId];
|
|
105
105
|
if (!resource) {
|
|
@@ -113,14 +113,14 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
113
113
|
const headers = {
|
|
114
114
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.INIT,
|
|
115
115
|
};
|
|
116
|
-
const application = await this.getSdk().
|
|
116
|
+
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
117
117
|
applicationId: resourceId,
|
|
118
118
|
viewMode: ctx.viewMode,
|
|
119
119
|
headers,
|
|
120
120
|
});
|
|
121
121
|
task.title += `: fetched`;
|
|
122
122
|
ctx.writtenResources[resourceId] =
|
|
123
|
-
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application,
|
|
123
|
+
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, process.cwd());
|
|
124
124
|
task.title += `: done`;
|
|
125
125
|
},
|
|
126
126
|
});
|
|
@@ -133,7 +133,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
|
|
|
133
133
|
const backend = await this.getSdk().fetchApi(resourceId, ctx.viewMode);
|
|
134
134
|
task.title += `: fetched`;
|
|
135
135
|
ctx.writtenResources[resourceId] =
|
|
136
|
-
await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend,
|
|
136
|
+
await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, process.cwd());
|
|
137
137
|
task.title += `: done`;
|
|
138
138
|
},
|
|
139
139
|
});
|
package/dist/commands/pull.js
CHANGED
|
@@ -20,7 +20,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
20
20
|
title: "Checking for existing Superblocks project...",
|
|
21
21
|
task: async (ctx) => {
|
|
22
22
|
ctx.writtenResources = {};
|
|
23
|
-
ctx.
|
|
23
|
+
ctx.removedResourceIds = [];
|
|
24
24
|
try {
|
|
25
25
|
[
|
|
26
26
|
ctx.existingSuperblocksRootConfig,
|
|
@@ -35,6 +35,78 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
title: "Checking for deleted Superblocks resources...",
|
|
40
|
+
task: async (ctx, task) => {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
try {
|
|
43
|
+
for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
|
|
44
|
+
switch (resource === null || resource === void 0 ? void 0 : resource.resourceType) {
|
|
45
|
+
case "APPLICATION": {
|
|
46
|
+
try {
|
|
47
|
+
await this.getSdk().fetchApplication({
|
|
48
|
+
applicationId: resourceId,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof util_1.NotFoundError) {
|
|
53
|
+
ctx.removedResourceIds.push(resourceId);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "BACKEND": {
|
|
62
|
+
try {
|
|
63
|
+
await this.getSdk().fetchApi(resourceId);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof util_1.NotFoundError) {
|
|
67
|
+
ctx.removedResourceIds.push(resourceId);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
default: {
|
|
76
|
+
this.warn(`Unsupported resource type, resource: ${JSON.stringify(resource)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (ctx.removedResourceIds.length === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const listOfDeletedResources = ctx.removedResourceIds
|
|
84
|
+
.map((id) => `- ${ctx.existingSuperblocksRootConfig.resources[id].location}`)
|
|
85
|
+
.join("\n");
|
|
86
|
+
const removeResourcesFromDisk = await task.prompt([
|
|
87
|
+
{
|
|
88
|
+
name: "removeResourcesFromDisk",
|
|
89
|
+
type: "confirm",
|
|
90
|
+
message: `Warning: The following resources could not be found in Superblocks.
|
|
91
|
+
${listOfDeletedResources}
|
|
92
|
+
|
|
93
|
+
Automatically removing resources from your local Superblocks project.
|
|
94
|
+
|
|
95
|
+
Would you like to also delete these resources from your filesystem?`,
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
if (removeResourcesFromDisk) {
|
|
99
|
+
for (const resourceId of ctx.removedResourceIds) {
|
|
100
|
+
const resource = (_c = ctx.existingSuperblocksRootConfig) === null || _c === void 0 ? void 0 : _c.resources[resourceId];
|
|
101
|
+
await (0, version_control_1.removeResourceFromDisk)(resource.location);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
this.warn(`Could not check for deleted Superblocks resources. Continuing...: ${e.message}`);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
},
|
|
38
110
|
{
|
|
39
111
|
title: "Pulling resources...",
|
|
40
112
|
task: async (ctx, task) => {
|
|
@@ -42,7 +114,6 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
42
114
|
const viewMode = await (0, version_control_1.getMode)(task, mode);
|
|
43
115
|
const resourceIdsToPull = await this.getResourceIdsToPull(ctx, task, only);
|
|
44
116
|
const subtasks = [];
|
|
45
|
-
const now = new Date().toISOString();
|
|
46
117
|
const superblocksRootPath = node_path_1.default.resolve(node_path_1.default.dirname(ctx.superblocksRootConfigPath), "..");
|
|
47
118
|
for (const resourceId of resourceIdsToPull) {
|
|
48
119
|
const resource = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId];
|
|
@@ -54,14 +125,14 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
54
125
|
const headers = {
|
|
55
126
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.PULL,
|
|
56
127
|
};
|
|
57
|
-
const application = await this.getSdk().
|
|
128
|
+
const application = await this.getSdk().fetchApplicationWithComponents({
|
|
58
129
|
applicationId: resourceId,
|
|
59
130
|
viewMode,
|
|
60
131
|
headers,
|
|
61
132
|
});
|
|
62
133
|
task.title += `: fetched`;
|
|
63
134
|
ctx.writtenResources[resourceId] =
|
|
64
|
-
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application,
|
|
135
|
+
await (0, version_control_1.writeResourceToDisk)("APPLICATION", resourceId, application, superblocksRootPath, resource.location);
|
|
65
136
|
task.title += `: done`;
|
|
66
137
|
},
|
|
67
138
|
});
|
|
@@ -74,7 +145,7 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
74
145
|
const backend = await this.getSdk().fetchApi(resourceId, viewMode);
|
|
75
146
|
task.title += `: fetched`;
|
|
76
147
|
ctx.writtenResources[resourceId] =
|
|
77
|
-
await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend,
|
|
148
|
+
await (0, version_control_1.writeResourceToDisk)("BACKEND", resourceId, backend, superblocksRootPath, resource.location);
|
|
78
149
|
task.title += `: done`;
|
|
79
150
|
},
|
|
80
151
|
});
|
|
@@ -95,8 +166,8 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
95
166
|
title: "Updating Superblocks project file...",
|
|
96
167
|
task: async (ctx) => {
|
|
97
168
|
const [superblocksRootConfig, rootConfigPath] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
98
|
-
for (const
|
|
99
|
-
superblocksRootConfig.resources[
|
|
169
|
+
for (const removedResourceId of ctx.removedResourceIds) {
|
|
170
|
+
delete superblocksRootConfig.resources[removedResourceId];
|
|
100
171
|
}
|
|
101
172
|
// update superblocks.json file
|
|
102
173
|
await fs.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(superblocksRootConfig), null, 2));
|
|
@@ -125,6 +196,9 @@ class Pull extends authenticated_command_1.AuthenticatedCommand {
|
|
|
125
196
|
const initialSelections = [];
|
|
126
197
|
let counter = 0;
|
|
127
198
|
for (const [resourceId, resource] of Object.entries((_f = (_e = ctx.existingSuperblocksRootConfig) === null || _e === void 0 ? void 0 : _e.resources) !== null && _f !== void 0 ? _f : {})) {
|
|
199
|
+
if (ctx.removedResourceIds.includes(resourceId)) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
128
202
|
choices.push({
|
|
129
203
|
name: resourceId,
|
|
130
204
|
message: resource.location,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthenticatedCommand } from "../common/authenticated-command";
|
|
2
|
+
export default class Remove extends AuthenticatedCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
resourceLocation: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
private createTasks;
|
|
10
|
+
private getResourcesToRemove;
|
|
11
|
+
private findDuplicates;
|
|
12
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const util_1 = require("@superblocksteam/util");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
7
|
+
const listr2_1 = require("listr2");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const authenticated_command_1 = require("../common/authenticated-command");
|
|
10
|
+
const version_control_1 = require("../common/version-control");
|
|
11
|
+
class Remove extends authenticated_command_1.AuthenticatedCommand {
|
|
12
|
+
async run() {
|
|
13
|
+
const { args } = await this.parse(Remove);
|
|
14
|
+
const tasks = this.createTasks(args);
|
|
15
|
+
try {
|
|
16
|
+
await tasks.run();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
this.error(error.message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
createTasks(args) {
|
|
23
|
+
const tasks = new listr2_1.Listr([
|
|
24
|
+
{
|
|
25
|
+
title: "Checking for existing Superblocks project...",
|
|
26
|
+
task: async (ctx) => {
|
|
27
|
+
ctx.fetchedResources = {};
|
|
28
|
+
ctx.removedResourceIds = [];
|
|
29
|
+
try {
|
|
30
|
+
ctx.existingSuperblocksConfig = (await (0, util_1.getSuperblocksMonorepoConfigJson)(true))[0];
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// no existing superblocks config
|
|
34
|
+
this.error(`No Superblocks project found in the current folder hierarchy.`);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "Fetching applications...",
|
|
40
|
+
task: (ctx, task) => task.newListr([
|
|
41
|
+
{
|
|
42
|
+
title: "Fetching applications...",
|
|
43
|
+
enabled: () => !args.resourceLocation,
|
|
44
|
+
task: async (ctx, task) => {
|
|
45
|
+
// applications choices
|
|
46
|
+
const applications = await this.getSdk().fetchApplications();
|
|
47
|
+
for (const app of applications) {
|
|
48
|
+
ctx.fetchedResources[app.id] = {
|
|
49
|
+
resourceType: "APPLICATION",
|
|
50
|
+
name: app.name,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
task.title += `: completed`;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
]),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: "Selecting resources to remove...",
|
|
60
|
+
task: async (ctx, task) => {
|
|
61
|
+
const resourceIdsToRemove = await this.getResourcesToRemove(ctx, task, args);
|
|
62
|
+
ctx.resourceIdsToRemove = resourceIdsToRemove;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
title: "Removing resources...",
|
|
67
|
+
task: async (ctx, task) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const subtasks = [];
|
|
70
|
+
for (const resourceId of ctx.resourceIdsToRemove) {
|
|
71
|
+
const resourceLocation = (_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId].location;
|
|
72
|
+
if (!resourceLocation) {
|
|
73
|
+
this.error(`Resource location not found for resource with id ${resourceId}`);
|
|
74
|
+
}
|
|
75
|
+
subtasks.push({
|
|
76
|
+
title: `Removing ${resourceId} from ${resourceLocation}...`,
|
|
77
|
+
task: async (_ctx, task) => {
|
|
78
|
+
await (0, version_control_1.removeResourceFromDisk)(resourceLocation);
|
|
79
|
+
ctx.removedResourceIds.push(resourceId);
|
|
80
|
+
task.title += `: done`;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return task.newListr(subtasks, {
|
|
85
|
+
concurrent: true,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
title: "Updating Superblocks project file...",
|
|
91
|
+
task: async (ctx) => {
|
|
92
|
+
const [superblocksRootConfig, rootConfigPath] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
93
|
+
for (const removedResourceId of ctx.removedResourceIds) {
|
|
94
|
+
delete superblocksRootConfig.resources[removedResourceId];
|
|
95
|
+
}
|
|
96
|
+
// update superblocks.json file
|
|
97
|
+
await fs.writeFile(rootConfigPath, JSON.stringify((0, version_control_1.sortByKey)(superblocksRootConfig), null, 2));
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
], {
|
|
101
|
+
concurrent: false,
|
|
102
|
+
});
|
|
103
|
+
return tasks;
|
|
104
|
+
}
|
|
105
|
+
async getResourcesToRemove(ctx, task, args) {
|
|
106
|
+
var _a;
|
|
107
|
+
if (args.resourceLocation) {
|
|
108
|
+
const [resourceId] = getResourceIdFromLocation(ctx, args.resourceLocation);
|
|
109
|
+
return [resourceId];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const choices = [];
|
|
113
|
+
for (const [resourceId, resource] of Object.entries(ctx.fetchedResources)) {
|
|
114
|
+
if ((_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources[resourceId]) {
|
|
115
|
+
choices.push({
|
|
116
|
+
name: resourceId,
|
|
117
|
+
message: `${resource.name} (${resource.resourceType})`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if ((0, lodash_1.isEmpty)(choices)) {
|
|
122
|
+
this.error(`No resources found in your project. Please make sure you have at least one application, workflow or scheduled job in your project.`);
|
|
123
|
+
}
|
|
124
|
+
const resourceIdsToRemove = await task.prompt([
|
|
125
|
+
{
|
|
126
|
+
type: "AutoComplete",
|
|
127
|
+
name: "resourceIdsToRemove",
|
|
128
|
+
message: `Select resources to remove (${version_control_1.MULTI_SELECT_PROMPT_HELP})`,
|
|
129
|
+
choices: choices,
|
|
130
|
+
multiple: true,
|
|
131
|
+
validate: version_control_1.atLeastOneSelection,
|
|
132
|
+
prefix: "▸",
|
|
133
|
+
indicator: "◉",
|
|
134
|
+
},
|
|
135
|
+
]);
|
|
136
|
+
const duplicates = await this.findDuplicates(resourceIdsToRemove, ctx.fetchedResources);
|
|
137
|
+
if (!(0, lodash_1.isEmpty)(duplicates)) {
|
|
138
|
+
this.error(`Duplicate resources selected: ${duplicates
|
|
139
|
+
.map((duplicate) => `${duplicate.name} (${duplicate.resourceType}) id: ${duplicate.id}`)
|
|
140
|
+
.join(", ")}. Please make sure to select unique resources or rename them so that they have unique names.`);
|
|
141
|
+
}
|
|
142
|
+
return resourceIdsToRemove;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async findDuplicates(selectedResourcesIds, resources) {
|
|
146
|
+
const selectedResources = selectedResourcesIds
|
|
147
|
+
.map((id) => {
|
|
148
|
+
return { ...resources[id], id };
|
|
149
|
+
})
|
|
150
|
+
.filter((resource) => resource !== undefined);
|
|
151
|
+
const countResourceNamesByType = {};
|
|
152
|
+
for (const resource of selectedResources) {
|
|
153
|
+
if (!countResourceNamesByType[resource.resourceType]) {
|
|
154
|
+
countResourceNamesByType[resource.resourceType] = {};
|
|
155
|
+
}
|
|
156
|
+
if (countResourceNamesByType[resource.resourceType][resource.name]) {
|
|
157
|
+
countResourceNamesByType[resource.resourceType][resource.name] += 1;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
countResourceNamesByType[resource.resourceType][resource.name] = 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return selectedResources.filter((resource) => countResourceNamesByType[resource.resourceType][resource.name] > 1);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
Remove.description = "Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)";
|
|
167
|
+
Remove.examples = [
|
|
168
|
+
"<%= config.bin %> <%= command.id %>",
|
|
169
|
+
"<%= config.bin %> <%= command.id %> apps/my-spectacular-app",
|
|
170
|
+
];
|
|
171
|
+
Remove.args = {
|
|
172
|
+
resourceLocation: core_1.Args.string({
|
|
173
|
+
description: "Superblocks resource location (i.e. apps/my-spectacular-app)",
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
exports.default = Remove;
|
|
177
|
+
function getResourceIdFromLocation(ctx, resourceLocation) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
for (const [resourceId, resource] of Object.entries((_b = (_a = ctx.existingSuperblocksConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {})) {
|
|
180
|
+
if (resource.location === resourceLocation) {
|
|
181
|
+
return [resourceId, resource.resourceType];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
throw new Error(`No resource found with the given location: ${resourceLocation}`);
|
|
185
|
+
}
|
|
@@ -9,7 +9,6 @@ const util_1 = require("@superblocksteam/util");
|
|
|
9
9
|
const colorette_1 = require("colorette");
|
|
10
10
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
11
|
const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
12
|
-
const yaml_1 = require("yaml");
|
|
13
12
|
const migrationWarningsForApplications_1 = require("../util/migrationWarningsForApplications");
|
|
14
13
|
const migrationsForDotfiles_1 = require("../util/migrationsForDotfiles");
|
|
15
14
|
const version_control_1 = require("./version-control");
|
|
@@ -115,7 +114,7 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
|
|
|
115
114
|
return new URL(`/applications/${this.applicationConfig.id}/pages/${this.applicationConfig.defaultPageId}/edit`, baseUrl).toString();
|
|
116
115
|
}
|
|
117
116
|
async init() {
|
|
118
|
-
var _a;
|
|
117
|
+
var _a, _b;
|
|
119
118
|
await super.init();
|
|
120
119
|
try {
|
|
121
120
|
this.applicationConfig = await (0, util_1.getSuperblocksApplicationConfigJson)();
|
|
@@ -125,18 +124,22 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
|
|
|
125
124
|
exit: 1,
|
|
126
125
|
});
|
|
127
126
|
}
|
|
127
|
+
core_1.ux.action.start("Checking application...");
|
|
128
128
|
try {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
const application = await this.getSdk().fetchApplication({
|
|
130
|
+
applicationId: this.applicationConfig.id,
|
|
131
|
+
});
|
|
132
|
+
core_1.ux.action.stop();
|
|
133
|
+
if ((_b = (_a = application === null || application === void 0 ? void 0 : application.application) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.cliVersion) {
|
|
134
|
+
const warningMessage = (0, migrationWarningsForApplications_1.getWarningsForApplicationMigration)(application.application.settings.cliVersion, this.config.version);
|
|
133
135
|
if (warningMessage) {
|
|
134
136
|
this.log(warningMessage);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
catch (e) {
|
|
139
|
-
|
|
141
|
+
core_1.ux.action.stop();
|
|
142
|
+
this.warn(`Could not read the application from Superblocks: ${e.message}`);
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
async registerComponents(injectedHeaders) {
|
|
@@ -9,6 +9,7 @@ export type ModeFlag = (keyof typeof modeFlagValuesMap)[number];
|
|
|
9
9
|
export declare const SELECT_PROMPT_HELP = "Use \u2191/\u2193 arrow keys, Enter to confirm";
|
|
10
10
|
export declare const MULTI_SELECT_PROMPT_HELP = "Type to filter, Use \u2191/\u2193 arrow keys, Space to select, Enter to confirm";
|
|
11
11
|
export declare const atLeastOneSelection: (value: string[]) => string | true;
|
|
12
|
-
export declare function writeResourceToDisk(resourceType: string, resourceId: string, resource: any,
|
|
12
|
+
export declare function writeResourceToDisk(resourceType: string, resourceId: string, resource: any, rootPath: string, existingRelativeLocation?: string): Promise<VersionedResourceConfig>;
|
|
13
|
+
export declare function removeResourceFromDisk(resourceLocation: string): Promise<void>;
|
|
13
14
|
export declare function getMode(task: any, mode: ModeFlag): Promise<ViewMode>;
|
|
14
15
|
export declare function sortByKey(obj: unknown): unknown;
|
|
@@ -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.modeFlagToViewMode = exports.modeFlagValuesMap = exports.DEPLOYED_MODE = exports.MOST_RECENT_COMMIT_MODE = exports.LATEST_EDITS_MODE = void 0;
|
|
3
|
+
exports.sortByKey = exports.getMode = exports.removeResourceFromDisk = exports.writeResourceToDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = 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 https = tslib_1.__importStar(require("https"));
|
|
6
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
@@ -87,7 +87,7 @@ async function downloadFile(rootDirectory, filepath, url) {
|
|
|
87
87
|
}
|
|
88
88
|
return Promise.resolve("");
|
|
89
89
|
}
|
|
90
|
-
async function writeResourceToDisk(resourceType, resourceId, resource,
|
|
90
|
+
async function writeResourceToDisk(resourceType, resourceId, resource, rootPath, existingRelativeLocation) {
|
|
91
91
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
92
92
|
switch (resourceType) {
|
|
93
93
|
case "APPLICATION": {
|
|
@@ -181,6 +181,10 @@ async function writeResourceToDisk(resourceType, resourceId, resource, now, root
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
exports.writeResourceToDisk = writeResourceToDisk;
|
|
184
|
+
async function removeResourceFromDisk(resourceLocation) {
|
|
185
|
+
await fs.remove(resourceLocation);
|
|
186
|
+
}
|
|
187
|
+
exports.removeResourceFromDisk = removeResourceFromDisk;
|
|
184
188
|
async function getMode(task, mode) {
|
|
185
189
|
if (mode) {
|
|
186
190
|
return modeFlagToViewMode(mode);
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0
|
|
2
|
+
"version": "1.0.0",
|
|
3
3
|
"commands": {
|
|
4
4
|
"init": {
|
|
5
5
|
"id": "init",
|
|
@@ -105,6 +105,26 @@
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
|
+
"rm": {
|
|
109
|
+
"id": "rm",
|
|
110
|
+
"description": "Remove a Superblocks resource from the local Superblocks project and delete the resource folder directory locally (if it exists)",
|
|
111
|
+
"strict": true,
|
|
112
|
+
"pluginName": "@superblocksteam/cli",
|
|
113
|
+
"pluginAlias": "@superblocksteam/cli",
|
|
114
|
+
"pluginType": "core",
|
|
115
|
+
"aliases": [],
|
|
116
|
+
"examples": [
|
|
117
|
+
"<%= config.bin %> <%= command.id %>",
|
|
118
|
+
"<%= config.bin %> <%= command.id %> apps/my-spectacular-app"
|
|
119
|
+
],
|
|
120
|
+
"flags": {},
|
|
121
|
+
"args": {
|
|
122
|
+
"resourceLocation": {
|
|
123
|
+
"name": "resourceLocation",
|
|
124
|
+
"description": "Superblocks resource location (i.e. apps/my-spectacular-app)"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
108
128
|
"components:create": {
|
|
109
129
|
"id": "components:create",
|
|
110
130
|
"description": "Creates a new Superblocks component in the current application folder",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
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": "0.0
|
|
22
|
-
"@superblocksteam/react-shim": "0.0
|
|
23
|
-
"@superblocksteam/sdk": "0.0
|
|
24
|
-
"@superblocksteam/util": "0.0
|
|
25
|
-
"@superblocksteam/vite-custom-component-reload-plugin": "0.0
|
|
21
|
+
"@superblocksteam/css-plugin": "1.0.0",
|
|
22
|
+
"@superblocksteam/react-shim": "1.0.0",
|
|
23
|
+
"@superblocksteam/sdk": "1.0.0",
|
|
24
|
+
"@superblocksteam/util": "1.0.0",
|
|
25
|
+
"@superblocksteam/vite-custom-component-reload-plugin": "1.0.0",
|
|
26
26
|
"@vitejs/plugin-react": "^4.0.4",
|
|
27
27
|
"colorette": "^2.0.19",
|
|
28
28
|
"enquirer": "^2.3.6",
|