@superblocksteam/cli 1.10.0 → 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.
- package/LICENSE.txt +87 -0
- package/README.md +6 -6
- package/assets/custom-components/setup/tsconfig.json +0 -1
- package/bin/dev +5 -7
- package/bin/run +1 -3
- package/dist/appendHotReloadEventPlugin.mjs +43 -0
- package/dist/commands/commits.d.mts +18 -0
- package/dist/commands/{commits.js → commits.mjs} +59 -67
- package/dist/commands/components/{create.d.ts → create.d.mts} +2 -2
- package/dist/commands/components/{create.js → create.mjs} +84 -93
- package/dist/commands/components/{register.d.ts → register.d.mts} +1 -1
- package/dist/commands/components/register.mjs +12 -0
- package/dist/commands/components/{upload.d.ts → upload.d.mts} +2 -2
- package/dist/commands/components/{upload.js → upload.mjs} +39 -43
- package/dist/commands/components/{watch.d.ts → watch.d.mts} +1 -1
- package/dist/commands/components/{watch.js → watch.mjs} +29 -36
- package/dist/commands/config/{set.d.ts → set.d.mts} +2 -2
- package/dist/commands/config/{set.js → set.mjs} +28 -32
- package/dist/commands/{init.d.ts → init.d.mts} +4 -4
- package/dist/commands/{init.js → init.mjs} +58 -64
- package/dist/commands/{login.d.ts → login.d.mts} +1 -1
- package/dist/commands/login.mjs +55 -0
- package/dist/commands/{migrate.d.ts → migrate.d.mts} +1 -1
- package/dist/commands/{migrate.js → migrate.mjs} +34 -42
- package/dist/commands/pull.d.mts +17 -0
- package/dist/commands/{pull.js → pull.mjs} +72 -80
- package/dist/commands/push.d.mts +15 -0
- package/dist/commands/{push.js → push.mjs} +81 -90
- package/dist/commands/{rm.d.ts → rm.d.mts} +2 -2
- package/dist/commands/{rm.js → rm.mjs} +34 -40
- package/dist/common/{authenticated-command.js → authenticated-command.mjs} +65 -75
- package/dist/common/defaults/{create-component-defaults.js → create-component-defaults.mjs} +2 -7
- package/dist/common/{version-control.d.ts → version-control.d.mts} +1 -1
- package/dist/common/{version-control.js → version-control.mjs} +170 -202
- package/dist/index.js +1 -5
- package/dist/{productionCssPlugin.js → productionCssPlugin.mjs} +4 -10
- package/dist/{reactShimPlugin.js → reactShimPlugin.mjs} +17 -24
- package/dist/util/migrationWarningsForApplications.mjs +47 -0
- package/dist/util/{migrationsForDotfiles.js → migrationsForDotfiles.mjs} +10 -17
- package/oclif.manifest.json +274 -161
- package/package.json +43 -41
- package/dist/appendHotReloadEventPlugin.js +0 -48
- package/dist/commands/commits.d.ts +0 -18
- package/dist/commands/components/register.js +0 -15
- package/dist/commands/login.js +0 -61
- package/dist/commands/pull.d.ts +0 -17
- package/dist/commands/push.d.ts +0 -15
- package/dist/util/migrationWarningsForApplications.js +0 -52
- /package/dist/{appendHotReloadEventPlugin.d.ts → appendHotReloadEventPlugin.d.mts} +0 -0
- /package/dist/common/{authenticated-command.d.ts → authenticated-command.d.mts} +0 -0
- /package/dist/common/defaults/{create-component-defaults.d.ts → create-component-defaults.d.mts} +0 -0
- /package/dist/{productionCssPlugin.d.ts → productionCssPlugin.d.mts} +0 -0
- /package/dist/{reactShimPlugin.d.ts → reactShimPlugin.d.mts} +0 -0
- /package/dist/util/{migrationWarningsForApplications.d.ts → migrationWarningsForApplications.d.mts} +0 -0
- /package/dist/util/{migrationsForDotfiles.d.ts → migrationsForDotfiles.d.mts} +0 -0
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const migrationsForDotfiles_1 = require("../util/migrationsForDotfiles");
|
|
14
|
-
const version_control_1 = require("./version-control");
|
|
15
|
-
class AuthenticatedCommand extends core_1.Command {
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Command, ux } from "@oclif/core";
|
|
3
|
+
import { SuperblocksSdk } from "@superblocksteam/sdk";
|
|
4
|
+
import { ComponentEvent, CUSTOM_COMPONENTS_PATH, getComponentConfigs, getLocalTokenWithUrl, getLocalTokenWithUrlIfExists, getSuperblocksApplicationConfigJson, getSuperblocksMonorepoConfigJson, } from "@superblocksteam/util";
|
|
5
|
+
import { cyan } from "colorette";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
import semver from "semver";
|
|
8
|
+
import { getWarningsForApplicationMigration } from "../util/migrationWarningsForApplications.mjs";
|
|
9
|
+
import { isDotfileMigrationNeeded, migrateSuperblocksEntityConfig, migrateSuperblocksMonorepoConfig, } from "../util/migrationsForDotfiles.mjs";
|
|
10
|
+
import { DEFAULT_BRANCH, getLocalGitRepoState, sortByKey, } from "./version-control.mjs";
|
|
11
|
+
export class AuthenticatedCommand extends Command {
|
|
12
|
+
sdk;
|
|
16
13
|
async init() {
|
|
17
14
|
await super.init();
|
|
18
15
|
try {
|
|
19
|
-
const result = await
|
|
16
|
+
const result = await getLocalTokenWithUrl();
|
|
20
17
|
if (!("token" in result)) {
|
|
21
18
|
throw new Error();
|
|
22
19
|
}
|
|
23
20
|
const { token, superblocksBaseUrl } = result;
|
|
24
|
-
this.sdk = new
|
|
21
|
+
this.sdk = new SuperblocksSdk(token, superblocksBaseUrl, this.config.version);
|
|
25
22
|
await this.runAutomatedDotfileUpdates();
|
|
26
23
|
}
|
|
27
24
|
catch (e) {
|
|
@@ -30,7 +27,7 @@ class AuthenticatedCommand extends core_1.Command {
|
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
async validateGitSetup(resourceType, resourceId, event, overrideLocalBranch, injectedHeaders) {
|
|
33
|
-
const localGitRepoState = await
|
|
30
|
+
const localGitRepoState = await getLocalGitRepoState(overrideLocalBranch);
|
|
34
31
|
const { branchName } = await this.getSdk().validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders);
|
|
35
32
|
return {
|
|
36
33
|
branchName,
|
|
@@ -40,9 +37,8 @@ class AuthenticatedCommand extends core_1.Command {
|
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
39
|
async getBaseUrl() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return (_a = result === null || result === void 0 ? void 0 : result.superblocksBaseUrl) !== null && _a !== void 0 ? _a : "";
|
|
40
|
+
const result = await getLocalTokenWithUrlIfExists();
|
|
41
|
+
return result?.superblocksBaseUrl ?? "";
|
|
46
42
|
}
|
|
47
43
|
getSdk() {
|
|
48
44
|
if (!this.sdk) {
|
|
@@ -54,7 +50,8 @@ class AuthenticatedCommand extends core_1.Command {
|
|
|
54
50
|
let previousConfig;
|
|
55
51
|
let rootConfigPath;
|
|
56
52
|
try {
|
|
57
|
-
[previousConfig, rootConfigPath] =
|
|
53
|
+
[previousConfig, rootConfigPath] =
|
|
54
|
+
await getSuperblocksMonorepoConfigJson(true);
|
|
58
55
|
}
|
|
59
56
|
catch {
|
|
60
57
|
// This might fail for a brand-new project folder, which is deliberately ignored
|
|
@@ -62,25 +59,25 @@ class AuthenticatedCommand extends core_1.Command {
|
|
|
62
59
|
}
|
|
63
60
|
if (previousConfig &&
|
|
64
61
|
rootConfigPath &&
|
|
65
|
-
|
|
62
|
+
isDotfileMigrationNeeded(previousConfig.metadata.cliVersion, this.config.version)) {
|
|
66
63
|
this.log(`Migrating Superblocks settings from ${previousConfig.metadata.cliVersion} to ${this.config.version}...`);
|
|
67
64
|
try {
|
|
68
|
-
const newConfig = await
|
|
65
|
+
const newConfig = await migrateSuperblocksMonorepoConfig(previousConfig, {
|
|
69
66
|
previousVersion: previousConfig.metadata.cliVersion,
|
|
70
67
|
currentVersion: this.config.version,
|
|
71
68
|
});
|
|
72
|
-
await
|
|
69
|
+
await fs.writeFile(rootConfigPath, JSON.stringify(sortByKey(newConfig), null, 2));
|
|
73
70
|
await Promise.all(Object.entries(newConfig.resources).map(async ([, resource]) => {
|
|
74
71
|
this.log(`Migrating ${resource.location}`);
|
|
75
72
|
try {
|
|
76
|
-
const resourcePath =
|
|
77
|
-
const resourceConfig = await
|
|
78
|
-
const newConfig = await
|
|
73
|
+
const resourcePath = path.join(rootConfigPath, "../..", resource.location, ".superblocks/superblocks.json");
|
|
74
|
+
const resourceConfig = await fs.readJSON(resourcePath);
|
|
75
|
+
const newConfig = await migrateSuperblocksEntityConfig(resourceConfig, {
|
|
79
76
|
previousVersion: previousConfig
|
|
80
77
|
.metadata.cliVersion,
|
|
81
78
|
currentVersion: this.config.version,
|
|
82
79
|
});
|
|
83
|
-
await
|
|
80
|
+
await fs.writeFile(resourcePath, JSON.stringify(sortByKey(newConfig), null, 2));
|
|
84
81
|
}
|
|
85
82
|
catch (e) {
|
|
86
83
|
this.error(e);
|
|
@@ -88,14 +85,14 @@ class AuthenticatedCommand extends core_1.Command {
|
|
|
88
85
|
}));
|
|
89
86
|
this.log(`Finalizing migration`);
|
|
90
87
|
this.log(`After upgrading the CLI version, you may need to perform additional migrations using
|
|
91
|
-
${
|
|
88
|
+
${cyan("superblocks migrate")}`);
|
|
92
89
|
}
|
|
93
90
|
catch (e) {
|
|
94
91
|
this.error(e);
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
if (previousConfig.metadata.cliVersion) {
|
|
98
|
-
const warningMessage =
|
|
95
|
+
const warningMessage = getWarningsForApplicationMigration(previousConfig.metadata.cliVersion, this.config.version);
|
|
99
96
|
if (warningMessage) {
|
|
100
97
|
this.log(warningMessage);
|
|
101
98
|
}
|
|
@@ -103,54 +100,49 @@ ${(0, colorette_1.cyan)("superblocks migrate")}`);
|
|
|
103
100
|
// Always upgrade the root config even if there's no migration
|
|
104
101
|
if (rootConfigPath) {
|
|
105
102
|
previousConfig.metadata.cliVersion = this.config.version;
|
|
106
|
-
await
|
|
103
|
+
await fs.writeFile(rootConfigPath, JSON.stringify(sortByKey(previousConfig), null, 2));
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
defaultPageId: "",
|
|
118
|
-
apis: {},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
107
|
+
export class AuthenticatedApplicationCommand extends AuthenticatedCommand {
|
|
108
|
+
applicationConfig = {
|
|
109
|
+
configType: "APPLICATION",
|
|
110
|
+
id: "",
|
|
111
|
+
defaultPageId: "",
|
|
112
|
+
apis: {},
|
|
113
|
+
};
|
|
121
114
|
async getEditModeUrl() {
|
|
122
|
-
const result = await
|
|
123
|
-
const baseUrl = typeof result === "string" ? result : result
|
|
115
|
+
const result = await getLocalTokenWithUrlIfExists();
|
|
116
|
+
const baseUrl = typeof result === "string" ? result : result?.superblocksBaseUrl;
|
|
124
117
|
return new URL(`/applications/edit/${this.applicationConfig.id}`, baseUrl).toString();
|
|
125
118
|
}
|
|
126
119
|
async init() {
|
|
127
|
-
var _a, _b;
|
|
128
120
|
await super.init();
|
|
129
121
|
try {
|
|
130
|
-
this.applicationConfig = await
|
|
122
|
+
this.applicationConfig = await getSuperblocksApplicationConfigJson();
|
|
131
123
|
}
|
|
132
124
|
catch (error) {
|
|
133
125
|
this.error(error.message, {
|
|
134
126
|
exit: 1,
|
|
135
127
|
});
|
|
136
128
|
}
|
|
137
|
-
const { branchName } = await this.validateApplicationGitSetup(
|
|
138
|
-
|
|
129
|
+
const { branchName } = await this.validateApplicationGitSetup(ComponentEvent.INIT);
|
|
130
|
+
ux.action.start("Checking application...");
|
|
139
131
|
try {
|
|
140
132
|
const application = await this.getSdk().fetchApplication({
|
|
141
133
|
applicationId: this.applicationConfig.id,
|
|
142
|
-
branch: branchName
|
|
134
|
+
branch: branchName ?? DEFAULT_BRANCH,
|
|
143
135
|
});
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
const warningMessage =
|
|
136
|
+
ux.action.stop();
|
|
137
|
+
if (application?.application?.settings?.cliVersion) {
|
|
138
|
+
const warningMessage = getWarningsForApplicationMigration(application.application.settings.cliVersion, this.config.version);
|
|
147
139
|
if (warningMessage) {
|
|
148
140
|
this.log(warningMessage);
|
|
149
141
|
}
|
|
150
142
|
}
|
|
151
143
|
}
|
|
152
144
|
catch (e) {
|
|
153
|
-
|
|
145
|
+
ux.action.stop();
|
|
154
146
|
this.warn(`Could not read the application from Superblocks: ${e.message}`);
|
|
155
147
|
}
|
|
156
148
|
}
|
|
@@ -158,64 +150,62 @@ class AuthenticatedApplicationCommand extends AuthenticatedCommand {
|
|
|
158
150
|
return this.validateGitSetup("APPLICATION", this.applicationConfig.id, event, overrideLocalBranch, injectedHeaders);
|
|
159
151
|
}
|
|
160
152
|
async registerComponents(injectedHeaders) {
|
|
161
|
-
|
|
162
|
-
core_1.ux.action.start("Checking CLI version compatibility...");
|
|
153
|
+
ux.action.start("Checking CLI version compatibility...");
|
|
163
154
|
try {
|
|
164
|
-
const packageJson = await
|
|
165
|
-
const versionStr =
|
|
155
|
+
const packageJson = await fs.readJson("package.json");
|
|
156
|
+
const versionStr = packageJson.dependencies?.["@superblocksteam/custom-components"];
|
|
166
157
|
if (!versionStr) {
|
|
167
158
|
throw new Error(`You must install the @superblocksteam/custom-components library as a dependency in your package.json file. Run:
|
|
168
159
|
|
|
169
|
-
${
|
|
160
|
+
${cyan("superblocks migrate")}`);
|
|
170
161
|
}
|
|
171
162
|
if (versionStr.startsWith("file:")) {
|
|
172
163
|
this.warn(`You are using a local version of the @superblocksteam/custom-components library. It is not possible to check its version compatibility with the CLI.`);
|
|
173
164
|
}
|
|
174
|
-
else if (!
|
|
165
|
+
else if (!semver.satisfies(this.config.version, versionStr)) {
|
|
175
166
|
throw new Error(`You must upgrade the @superblocksteam/custom-components library. You are using ${versionStr} but the CLI is ${this.config.version}. Run:
|
|
176
167
|
|
|
177
|
-
${
|
|
168
|
+
${cyan("superblocks migrate")}`);
|
|
178
169
|
}
|
|
179
170
|
}
|
|
180
171
|
catch (e) {
|
|
181
|
-
|
|
172
|
+
ux.action.stop();
|
|
182
173
|
this.error(e.message, {
|
|
183
174
|
exit: 1,
|
|
184
175
|
});
|
|
185
176
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const exists = await
|
|
177
|
+
ux.action.stop();
|
|
178
|
+
ux.action.start("Scanning for Superblocks components...");
|
|
179
|
+
const exists = await fs.pathExists(CUSTOM_COMPONENTS_PATH);
|
|
189
180
|
if (!exists) {
|
|
190
|
-
|
|
181
|
+
ux.action.stop();
|
|
191
182
|
this.error("No components folder found in current directory, please run 'superblocks components create' first", {
|
|
192
183
|
exit: 1,
|
|
193
184
|
});
|
|
194
185
|
}
|
|
195
|
-
const { configs, hasError } = await
|
|
186
|
+
const { configs, hasError } = await getComponentConfigs(true);
|
|
196
187
|
if (hasError) {
|
|
197
|
-
|
|
188
|
+
ux.action.stop();
|
|
198
189
|
this.error("Failed to register components", { exit: 1 });
|
|
199
190
|
// Stop immediately
|
|
200
191
|
return;
|
|
201
192
|
}
|
|
202
193
|
if (configs.length === 0) {
|
|
203
|
-
|
|
194
|
+
ux.action.stop();
|
|
204
195
|
this.log("No components found in current components directory, please run 'superblocks components create' first");
|
|
205
196
|
}
|
|
206
|
-
|
|
197
|
+
ux.action.stop();
|
|
207
198
|
try {
|
|
208
|
-
|
|
209
|
-
const { branchName } = await this.validateApplicationGitSetup(
|
|
199
|
+
ux.action.start("Registering components...");
|
|
200
|
+
const { branchName } = await this.validateApplicationGitSetup(ComponentEvent.REGISTER);
|
|
210
201
|
await this.getSdk().registerComponents(this.applicationConfig.id, configs, branchName, injectedHeaders);
|
|
211
|
-
|
|
202
|
+
ux.action.stop();
|
|
212
203
|
}
|
|
213
204
|
catch (e) {
|
|
214
|
-
|
|
205
|
+
ux.action.stop();
|
|
215
206
|
console.log(e.message);
|
|
216
207
|
this.error("Failed to register components", { exit: 1 });
|
|
217
208
|
}
|
|
218
209
|
return configs;
|
|
219
210
|
}
|
|
220
211
|
}
|
|
221
|
-
exports.AuthenticatedApplicationCommand = AuthenticatedApplicationCommand;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultComponentTsx = exports.getDefaultConfigTs = void 0;
|
|
4
1
|
const indent = (str, spaces) => {
|
|
5
2
|
const spacesString = " ".repeat(spaces);
|
|
6
3
|
return str
|
|
@@ -8,7 +5,7 @@ const indent = (str, spaces) => {
|
|
|
8
5
|
.map((line) => `${spacesString}${line}`)
|
|
9
6
|
.join("\n");
|
|
10
7
|
};
|
|
11
|
-
const getDefaultConfigTs = ({ id, name, displayName, propertiesRendered, eventHandlersRendered, }) => `import { type ComponentConfig } from "@superblocksteam/custom-components";
|
|
8
|
+
export const getDefaultConfigTs = ({ id, name, displayName, propertiesRendered, eventHandlersRendered, }) => `import { type ComponentConfig } from "@superblocksteam/custom-components";
|
|
12
9
|
|
|
13
10
|
export default {
|
|
14
11
|
// DO NOT CHANGE THE ID ONCE THE COMPONENT HAS BEEN REGISTERED!
|
|
@@ -24,8 +21,7 @@ export default {
|
|
|
24
21
|
},
|
|
25
22
|
} satisfies ComponentConfig;
|
|
26
23
|
`;
|
|
27
|
-
|
|
28
|
-
const getDefaultComponentTsx = (properties, eventHandlers) => `import { useSuperblocksContext, useSuperblocksIsLoading } from "@superblocksteam/custom-components";
|
|
24
|
+
export const getDefaultComponentTsx = (properties, eventHandlers) => `import { useSuperblocksContext, useSuperblocksIsLoading } from "@superblocksteam/custom-components";
|
|
29
25
|
import { type Props, type EventTriggers } from "./types";
|
|
30
26
|
|
|
31
27
|
export default function Component({${properties.length === 0
|
|
@@ -55,4 +51,3 @@ export default function Component({${properties.length === 0
|
|
|
55
51
|
);
|
|
56
52
|
}
|
|
57
53
|
`;
|
|
58
|
-
exports.getDefaultComponentTsx = getDefaultComponentTsx;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiWrapper, ApplicationWrapper, FeatureFlags, MultiPageApplicationWrapper } from "@superblocksteam/sdk";
|
|
2
|
-
import { Api, ViewMode } from "@superblocksteam/sdk
|
|
2
|
+
import { Api, ViewMode } from "@superblocksteam/sdk";
|
|
3
3
|
import { LocalGitRepoState, SuperblocksMonorepoConfig, SuperblocksResourceConfig, VersionedResourceConfig, ApiInfo } from "@superblocksteam/util";
|
|
4
4
|
export declare const LATEST_EDITS_MODE = "latest-edits";
|
|
5
5
|
export declare const MOST_RECENT_COMMIT_MODE = "most-recent-commit";
|