@supernovaio/cli-next 2.0.28 → 2.0.30
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/dist/commands/storybook-import.d.ts +10 -19
- package/dist/commands/storybook-import.d.ts.map +1 -1
- package/dist/commands/storybook-import.js +131 -114
- package/dist/commands/storybook-import.js.map +1 -1
- package/dist/types/base-command.d.ts +2 -2
- package/dist/types/base-command.d.ts.map +1 -1
- package/dist/types/base-command.js +9 -18
- package/dist/types/base-command.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
import { z, ZodType } from "zod";
|
|
2
2
|
import { SentryCommand } from "../types/index.js";
|
|
3
|
-
declare const ImportStorybookConfigSchema: z.
|
|
3
|
+
declare const ImportStorybookConfigSchema: z.ZodObject<{
|
|
4
4
|
brandId: z.ZodOptional<z.ZodString>;
|
|
5
5
|
designSystemId: z.ZodOptional<z.ZodString>;
|
|
6
|
-
|
|
6
|
+
from: z.ZodString;
|
|
7
7
|
name: z.ZodOptional<z.ZodString>;
|
|
8
8
|
sourceId: z.ZodOptional<z.ZodString>;
|
|
9
9
|
versionId: z.ZodOptional<z.ZodString>;
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
from: string;
|
|
11
12
|
name?: string | undefined;
|
|
12
13
|
designSystemId?: string | undefined;
|
|
13
14
|
versionId?: string | undefined;
|
|
14
15
|
brandId?: string | undefined;
|
|
15
|
-
dir?: string | undefined;
|
|
16
16
|
sourceId?: string | undefined;
|
|
17
17
|
}, {
|
|
18
|
+
from: string;
|
|
18
19
|
name?: string | undefined;
|
|
19
20
|
designSystemId?: string | undefined;
|
|
20
21
|
versionId?: string | undefined;
|
|
21
22
|
brandId?: string | undefined;
|
|
22
|
-
dir?: string | undefined;
|
|
23
|
-
sourceId?: string | undefined;
|
|
24
|
-
}>, {
|
|
25
|
-
name?: string | undefined;
|
|
26
|
-
designSystemId?: string | undefined;
|
|
27
|
-
versionId?: string | undefined;
|
|
28
|
-
brandId?: string | undefined;
|
|
29
|
-
dir?: string | undefined;
|
|
30
|
-
sourceId?: string | undefined;
|
|
31
|
-
}, {
|
|
32
|
-
name?: string | undefined;
|
|
33
|
-
designSystemId?: string | undefined;
|
|
34
|
-
versionId?: string | undefined;
|
|
35
|
-
brandId?: string | undefined;
|
|
36
|
-
dir?: string | undefined;
|
|
37
23
|
sourceId?: string | undefined;
|
|
38
24
|
}>;
|
|
39
25
|
type ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>;
|
|
@@ -51,10 +37,15 @@ export default class ImportStorybook extends SentryCommand<ImportStorybookConfig
|
|
|
51
37
|
get commandId(): string;
|
|
52
38
|
get configSchema(): ZodType<ImportStorybookConfig>;
|
|
53
39
|
run(): Promise<void>;
|
|
54
|
-
private
|
|
40
|
+
private getStorybookName;
|
|
41
|
+
private getDesignSystemId;
|
|
42
|
+
private getBrandId;
|
|
43
|
+
private getStorybookDirectory;
|
|
55
44
|
private createZipFromDirectory;
|
|
56
45
|
private getIndexJson;
|
|
57
46
|
private uploadArchiveToSignedUrl;
|
|
47
|
+
private waitForPublishing;
|
|
48
|
+
private importStorybookStories;
|
|
58
49
|
private validateStorybookDirectory;
|
|
59
50
|
private validateZipSize;
|
|
60
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storybook-import.d.ts","sourceRoot":"","sources":["../../src/commands/storybook-import.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAEhC,OAAO,EAA6B,aAAa,EAAyC,MAAM,mBAAmB,CAAA;AAUnH,QAAA,MAAM,2BAA2B
|
|
1
|
+
{"version":3,"file":"storybook-import.d.ts","sourceRoot":"","sources":["../../src/commands/storybook-import.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAEhC,OAAO,EAA6B,aAAa,EAAyC,MAAM,mBAAmB,CAAA;AAUnH,QAAA,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;EAO/B,CAAA;AAEF,KAAK,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAaxE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,aAAa,CAAC,qBAAqB,CAAC;IAC/E,OAAgB,IAAI,KAAK;IACzB,OAAgB,WAAW,SAAgD;IAC3E,OAAgB,QAAQ,WAA4D;IACpF,OAAgB,KAAK;;;;;;MAWpB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAEjD;IAGY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YAkDnB,gBAAgB;YAwBhB,iBAAiB;YAYjB,UAAU;YAYV,qBAAqB;IAoBnC,OAAO,CAAC,sBAAsB;IA0E9B,OAAO,CAAC,YAAY;YAYN,wBAAwB;YAuDxB,iBAAiB;YA2CjB,sBAAsB;IAsDpC,OAAO,CAAC,0BAA0B;IA6BlC,OAAO,CAAC,eAAe;CAiBxB"}
|
|
@@ -24,18 +24,14 @@ import { getApiClient } from "../utils/index.js";
|
|
|
24
24
|
const MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024;
|
|
25
25
|
const bytesToKB = (bytes) => (bytes / 1024).toFixed(2);
|
|
26
26
|
const bytesToMB = (bytes) => (bytes / (1024 * 1024)).toFixed(2);
|
|
27
|
-
const ImportStorybookConfigSchema = z
|
|
28
|
-
.object({
|
|
27
|
+
const ImportStorybookConfigSchema = z.object({
|
|
29
28
|
brandId: z.string().optional(),
|
|
30
29
|
designSystemId: z.string().optional(),
|
|
31
|
-
|
|
30
|
+
from: z.string(),
|
|
32
31
|
name: z.string().optional(),
|
|
33
32
|
sourceId: z.string().optional(),
|
|
34
33
|
versionId: z.string().optional(),
|
|
35
|
-
})
|
|
36
|
-
.transform(data => ({
|
|
37
|
-
...data,
|
|
38
|
-
}));
|
|
34
|
+
});
|
|
39
35
|
const storybookEndpoint = (environment, designSystemId, name, accessToken) => {
|
|
40
36
|
const host = storybookUrlForEnvironment(environment);
|
|
41
37
|
const encodedAccessToken = encodeURIComponent(accessToken);
|
|
@@ -64,124 +60,85 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
64
60
|
return ImportStorybookConfigSchema;
|
|
65
61
|
}
|
|
66
62
|
async run() {
|
|
67
|
-
const startTime = Date.now();
|
|
68
63
|
const { flags } = await this.parse(ImportStorybook);
|
|
69
64
|
const env = getTargetEnv();
|
|
70
|
-
const {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
const { sourceId } = flags;
|
|
66
|
+
const storybookDirectory = await this.getStorybookDirectory(flags);
|
|
67
|
+
const storybookName = await this.getStorybookName(flags);
|
|
68
|
+
const designSystemId = await this.getDesignSystemId(env, flags);
|
|
69
|
+
const brandPersistentId = await this.getBrandId(env, flags, designSystemId);
|
|
74
70
|
const apiClient = await getApiClient(env);
|
|
75
71
|
const { designSystems } = apiClient;
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!designSystemId) {
|
|
80
|
-
this.error("Design system ID is required");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (!brandId) {
|
|
84
|
-
brandId = await this.getBrandId(env, designSystemId, "head");
|
|
85
|
-
if (!brandId) {
|
|
86
|
-
this.error("Brand ID is required");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const directoryValidation = this.validateStorybookDirectory(from);
|
|
90
|
-
if (!directoryValidation.isValid) {
|
|
91
|
-
this.error(directoryValidation.error);
|
|
92
|
-
}
|
|
93
|
-
this.log(`Preparing Storybook files from ${from}...`);
|
|
94
|
-
const { sizeBytes, zipPath } = this.createZipFromDirectory(from);
|
|
72
|
+
const { storybookHosting } = designSystems;
|
|
73
|
+
this.log(`Preparing Storybook files from ${storybookDirectory}...`);
|
|
74
|
+
const { sizeBytes, zipPath } = this.createZipFromDirectory(storybookDirectory);
|
|
95
75
|
const sizeValidation = this.validateZipSize(zipPath, sizeBytes);
|
|
96
76
|
if (!sizeValidation.isValid) {
|
|
97
77
|
this.error(sizeValidation.error);
|
|
98
78
|
}
|
|
99
|
-
const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
action.stop("\n✅ Private Storybook deployed successfully!");
|
|
131
|
-
try {
|
|
132
|
-
this.log(`Connecting Storybook as a data source in Supernova...`);
|
|
133
|
-
let storiesCount = 0;
|
|
134
|
-
if (sourceId) {
|
|
135
|
-
const { storiesCount: updatedStoriesCount } = await sources.updateStorybookImport(designSystemId, "head", {
|
|
136
|
-
payload: this.getIndexJson(from),
|
|
137
|
-
sourceId,
|
|
138
|
-
});
|
|
139
|
-
storiesCount = updatedStoriesCount;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
const { source } = await sources.create(designSystemId, {
|
|
143
|
-
brandPersistentId: brandId,
|
|
144
|
-
description: "CLI",
|
|
145
|
-
indexUrl: storybookUrl,
|
|
146
|
-
payload: this.getIndexJson(from),
|
|
147
|
-
type: "Storybook",
|
|
148
|
-
userUrl: storybookUrl,
|
|
149
|
-
});
|
|
150
|
-
storiesCount = source.storybook.storiesCount;
|
|
151
|
-
}
|
|
152
|
-
this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green);
|
|
153
|
-
this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green);
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
this.error(`Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`
|
|
157
|
-
.red);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
action.stop(`\nFailed to deploy Storybook: ${error instanceof Error ? error.message : String(error)}`.red);
|
|
79
|
+
const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, {
|
|
80
|
+
name: storybookName,
|
|
81
|
+
});
|
|
82
|
+
await this.uploadArchiveToSignedUrl({ designSystemId, storybookName, signedUrl, storybookUploadId, zipPath });
|
|
83
|
+
this.log("✅ Upload complete.");
|
|
84
|
+
action.start("Deploying Storybook to private Supernova hosting service...");
|
|
85
|
+
await this.waitForPublishing({ apiClient, designSystemId, storybookUploadId });
|
|
86
|
+
action.stop("\n✅ Private Storybook deployed successfully!");
|
|
87
|
+
action.start("Updating Storybook stories...");
|
|
88
|
+
await this.importStorybookStories(env, {
|
|
89
|
+
apiClient,
|
|
90
|
+
designSystemId,
|
|
91
|
+
brandPersistentId,
|
|
92
|
+
sourceId,
|
|
93
|
+
storybookDirectory,
|
|
94
|
+
storybookName,
|
|
95
|
+
});
|
|
96
|
+
action.stop("\n✅ Storybook stories have been updated!");
|
|
97
|
+
}
|
|
98
|
+
async getStorybookName(flags) {
|
|
99
|
+
let result = flags.name;
|
|
100
|
+
if (!result) {
|
|
101
|
+
const choice = await inquirer.prompt([
|
|
102
|
+
{
|
|
103
|
+
message: "Enter URL-compatible name for this Storybook instance",
|
|
104
|
+
name: "name",
|
|
105
|
+
type: "input",
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
if (typeof choice.name === "string") {
|
|
109
|
+
result = choice.name;
|
|
163
110
|
}
|
|
164
111
|
}
|
|
165
|
-
|
|
166
|
-
this.error(`
|
|
112
|
+
if (!result) {
|
|
113
|
+
this.error("Parameter `name` is required");
|
|
167
114
|
}
|
|
115
|
+
return slugify(result, { lowercase: true });
|
|
168
116
|
}
|
|
169
|
-
async
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.
|
|
117
|
+
async getDesignSystemId(env, flags) {
|
|
118
|
+
let { designSystemId } = flags;
|
|
119
|
+
if (!designSystemId) {
|
|
120
|
+
designSystemId = await this.promptDesignSystemId(env);
|
|
121
|
+
}
|
|
122
|
+
if (!designSystemId)
|
|
123
|
+
this.error("Parameter `designSystemId` is required");
|
|
124
|
+
return designSystemId;
|
|
125
|
+
}
|
|
126
|
+
async getBrandId(env, flags, designSystemId) {
|
|
127
|
+
let { brandId } = flags;
|
|
128
|
+
if (!brandId) {
|
|
129
|
+
brandId = await this.promptBrandId(env, designSystemId);
|
|
130
|
+
}
|
|
131
|
+
if (!brandId)
|
|
132
|
+
this.error("Brand ID is required");
|
|
133
|
+
return brandId;
|
|
134
|
+
}
|
|
135
|
+
async getStorybookDirectory(flags) {
|
|
136
|
+
const { from } = flags;
|
|
137
|
+
const directoryValidation = this.validateStorybookDirectory(from);
|
|
138
|
+
if (!directoryValidation.isValid) {
|
|
139
|
+
this.error(directoryValidation.error);
|
|
182
140
|
}
|
|
183
|
-
|
|
184
|
-
return name;
|
|
141
|
+
return from;
|
|
185
142
|
}
|
|
186
143
|
createZipFromDirectory(directoryPath) {
|
|
187
144
|
const zip = new AdmZip();
|
|
@@ -247,7 +204,7 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
247
204
|
return JSON.parse(fs.readFileSync(indexJsonPath, "utf8"));
|
|
248
205
|
}
|
|
249
206
|
async uploadArchiveToSignedUrl(input) {
|
|
250
|
-
const { designSystemId,
|
|
207
|
+
const { designSystemId, storybookName, signedUrl, storybookUploadId, zipPath } = input;
|
|
251
208
|
this.log(`Securely uploading ${zipPath} to Supernova...`);
|
|
252
209
|
const progressBar = new cliProgress.SingleBar({
|
|
253
210
|
barCompleteChar: "\u2588",
|
|
@@ -267,7 +224,7 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
267
224
|
"Content-Type": "application/zip",
|
|
268
225
|
designSystemId,
|
|
269
226
|
storybookUploadId,
|
|
270
|
-
...(
|
|
227
|
+
...(storybookName && { name: storybookName }),
|
|
271
228
|
},
|
|
272
229
|
onUploadProgress(progressEvent) {
|
|
273
230
|
const loaded = progressEvent.loaded || 0;
|
|
@@ -283,6 +240,66 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
283
240
|
throw error;
|
|
284
241
|
}
|
|
285
242
|
}
|
|
243
|
+
async waitForPublishing(input) {
|
|
244
|
+
const { apiClient, designSystemId, storybookUploadId } = input;
|
|
245
|
+
const getStatus = async () => {
|
|
246
|
+
const { status } = await apiClient.designSystems.storybookHosting.getUploadStatus(designSystemId, storybookUploadId);
|
|
247
|
+
return status;
|
|
248
|
+
};
|
|
249
|
+
let lastStatus = "Unknown";
|
|
250
|
+
let unknownStatusCount = 0;
|
|
251
|
+
for (let i = 0; unknownStatusCount < 10 && i < 15 * 60; i++) {
|
|
252
|
+
lastStatus = await getStatus();
|
|
253
|
+
if (lastStatus === "Unknown")
|
|
254
|
+
unknownStatusCount++;
|
|
255
|
+
else
|
|
256
|
+
unknownStatusCount = 0;
|
|
257
|
+
if (lastStatus === "Completed" || lastStatus === "Failed")
|
|
258
|
+
break;
|
|
259
|
+
await sleep(1000);
|
|
260
|
+
}
|
|
261
|
+
switch (lastStatus) {
|
|
262
|
+
case "Unknown":
|
|
263
|
+
return this.error("Storybook deployment initialization has timed out");
|
|
264
|
+
case "Failed":
|
|
265
|
+
return this.error("Storybook deployment has failed");
|
|
266
|
+
case "InProgress":
|
|
267
|
+
return this.error("Storybook deployment has timed out");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async importStorybookStories(env, input) {
|
|
271
|
+
const { apiClient, brandPersistentId, designSystemId, storybookDirectory, storybookName, sourceId } = input;
|
|
272
|
+
const sourcesEndpoint = apiClient.designSystems.sources;
|
|
273
|
+
const storybookHostingEndpoint = apiClient.designSystems.storybookHosting;
|
|
274
|
+
const { accessToken } = await storybookHostingEndpoint.getAccessToken(designSystemId, storybookName);
|
|
275
|
+
const storybookUrl = storybookEndpoint(env, designSystemId, storybookName, accessToken);
|
|
276
|
+
try {
|
|
277
|
+
let storiesCount = 0;
|
|
278
|
+
if (sourceId) {
|
|
279
|
+
const sourceUpdateResult = await sourcesEndpoint.updateStorybookImport(designSystemId, "head", {
|
|
280
|
+
payload: this.getIndexJson(storybookDirectory),
|
|
281
|
+
sourceId,
|
|
282
|
+
});
|
|
283
|
+
storiesCount = sourceUpdateResult.storiesCount;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
const { source } = await sourcesEndpoint.create(designSystemId, {
|
|
287
|
+
brandPersistentId,
|
|
288
|
+
description: "CLI",
|
|
289
|
+
indexUrl: storybookUrl,
|
|
290
|
+
payload: this.getIndexJson(storybookDirectory),
|
|
291
|
+
type: "Storybook",
|
|
292
|
+
userUrl: storybookUrl,
|
|
293
|
+
});
|
|
294
|
+
storiesCount = source.storybook.storiesCount;
|
|
295
|
+
}
|
|
296
|
+
this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green);
|
|
297
|
+
this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
this.error(`Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`.red);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
286
303
|
validateStorybookDirectory(directoryPath) {
|
|
287
304
|
if (!fs.existsSync(directoryPath)) {
|
|
288
305
|
return { error: `Directory not found: ${directoryPath}`, isValid: false };
|
|
@@ -1 +1 @@
|
|
|
1
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@sentry/nestjs\"\nimport slugify from \"@sindresorhus/slugify\"\nimport { DTODataSourceStorybook } from \"@supernova-studio/client\"\nimport AdmZip from \"adm-zip\"\nimport axios from \"axios\"\nimport cliProgress from \"cli-progress\"\nimport inquirer from \"inquirer\"\nimport * as fs from \"node:fs\"\nimport path from \"node:path\"\nimport { z, ZodType } from \"zod\"\n\nimport { commonFlags, getTargetEnv, SentryCommand, storybookUrlForEnvironment, TargetEnv } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.js\"\nimport { getApiClient } from \"../utils/index.js\"\n\n// Maximum allowed size for storybook zip file (500MB)\nconst MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024\n\nconst bytesToKB = (bytes: number) => (bytes / 1024).toFixed(2)\nconst bytesToMB = (bytes: number) => (bytes / (1024 * 1024)).toFixed(2)\n\nconst ImportStorybookConfigSchema = z\n .object({\n brandId: z.string().optional(),\n designSystemId: z.string().optional(),\n dir: z.string().optional(),\n name: z.string().optional(),\n sourceId: z.string().optional(),\n versionId: z.string().optional(),\n })\n .transform(data => ({\n ...data,\n }))\n\ntype ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>\n\nconst storybookEndpoint = (\n environment: TargetEnv,\n designSystemId: string,\n name: string,\n accessToken: string,\n): string => {\n const host = storybookUrlForEnvironment(environment)\n const encodedAccessToken = encodeURIComponent(accessToken)\n return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?storybook_jwt=${encodedAccessToken}`\n}\n\nexport default class ImportStorybook extends SentryCommand<ImportStorybookConfig> {\n static override args = {}\n static override description = \"Import storybook static export to Supernova\"\n static override examples = [\"<%= config.bin %> <%= command.id %> import-storybook \"]\n static override flags = {\n ...commonFlags,\n brandId: Flags.string({ char: \"b\", description: \"Import storybooks to brand of\" }),\n designSystemId: Flags.string({ char: \"d\", description: \"Import storybooks to design system of\" }),\n from: Flags.string({\n char: \"f\",\n description: \"Directory with storybook static export to import.\",\n required: true,\n }),\n name: Flags.string({ char: \"n\", description: \"Import storybooks with name of\" }),\n sourceId: Flags.string({ char: \"s\", description: \"Import storybooks to source of\" }),\n }\n\n get commandId(): string {\n return ImportStorybook.id\n }\n\n get configSchema(): ZodType<ImportStorybookConfig> {\n return ImportStorybookConfigSchema\n }\n\n @SentryTraced()\n // eslint-disable-next-line complexity\n public async run(): Promise<void> {\n const startTime = Date.now()\n const { flags } = await this.parse(ImportStorybook)\n\n const env = getTargetEnv()\n const { brandId: bId, designSystemId: dsId, from, name: nameInput, sourceId } = flags\n const name = slugify(await this.askName(nameInput), { lowercase: true })\n let designSystemId = dsId\n let brandId = bId\n\n const apiClient = await getApiClient(env)\n const { designSystems } = apiClient\n const { sources, storybookHosting } = designSystems\n\n if (!designSystemId) {\n designSystemId = await this.getDesignSystemId(env, designSystemId)\n\n if (!designSystemId) {\n this.error(\"Design system ID is required\")\n }\n }\n\n if (!brandId) {\n brandId = await this.getBrandId(env, designSystemId, \"head\")\n\n if (!brandId) {\n this.error(\"Brand ID is required\")\n }\n }\n\n const directoryValidation = this.validateStorybookDirectory(from)\n if (!directoryValidation.isValid) {\n this.error(directoryValidation.error!)\n }\n\n this.log(`Preparing Storybook files from ${from}...`)\n const { sizeBytes, zipPath } = this.createZipFromDirectory(from)\n\n const sizeValidation = this.validateZipSize(zipPath, sizeBytes)\n if (!sizeValidation.isValid) {\n this.error(sizeValidation.error!)\n }\n\n const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, { name })\n\n try {\n await this.uploadArchiveToSignedUrl({ designSystemId, name, signedUrl, storybookUploadId, zipPath })\n this.log(\"✅ Upload complete.\")\n this.log(\"Processing Storybook files...\")\n\n let status\n action.start(\"Deploying Storybook to private Supernova hosting service...\")\n\n let unknownStatusCount = 0\n try {\n do {\n // eslint-disable-next-line no-await-in-loop\n await sleep(1000)\n\n // eslint-disable-next-line no-await-in-loop\n status = await storybookHosting.getUploadStatus(designSystemId, storybookUploadId)\n\n if (status.status === \"Failed\") {\n break\n }\n\n if (status.status === \"Unknown\") {\n unknownStatusCount++\n } else {\n unknownStatusCount = 0\n }\n\n if (unknownStatusCount >= 5) {\n this.error(\"Failed to deploy Storybook: Internal server error\")\n }\n } while (status.status !== \"Completed\" || (status.timestamp && status.timestamp < startTime))\n\n if (status.status === \"Failed\") {\n action.stop(\"\\nFailed to deploy Storybook: Internal server error\")\n } else {\n const { accessToken } = await storybookHosting.getAccessToken(designSystemId, name)\n const storybookUrl = storybookEndpoint(env, designSystemId, name, accessToken)\n\n action.stop(\"\\n✅ Private Storybook deployed successfully!\")\n\n try {\n this.log(`Connecting Storybook as a data source in Supernova...`)\n let storiesCount = 0\n // eslint-disable-next-line max-depth\n if (sourceId) {\n const { storiesCount: updatedStoriesCount } = await sources.updateStorybookImport(\n designSystemId,\n \"head\",\n {\n payload: this.getIndexJson(from),\n sourceId,\n },\n )\n storiesCount = updatedStoriesCount\n } else {\n const { source } = await sources.create(designSystemId, {\n brandPersistentId: brandId,\n description: \"CLI\",\n indexUrl: storybookUrl,\n payload: this.getIndexJson(from),\n type: \"Storybook\",\n userUrl: storybookUrl,\n })\n\n storiesCount = (source as unknown as DTODataSourceStorybook).storybook.storiesCount\n }\n\n this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green)\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`\n .red,\n )\n }\n }\n } catch (error) {\n action.stop(`\\nFailed to deploy Storybook: ${error instanceof Error ? error.message : String(error)}`.red)\n }\n } catch (error) {\n this.error(`Failed to upload Storybook files: ${error instanceof Error ? error.message : String(error)}`)\n }\n }\n\n private async askName(inputedName?: string) {\n if (inputedName) return inputedName\n const choice = await inquirer.prompt([\n {\n message: \"What's storybook name\",\n name: \"name\",\n type: \"input\",\n },\n ])\n if (choice.name === \"exit\") {\n this.log(\"Exiting...\")\n this.exit(0)\n }\n\n const name = choice.name as string\n return name\n }\n\n /**\n * Creates a zip archive from a directory\n * @param directoryPath Path to the directory to zip\n * @returns Path to the created zip file and its size\n */\n private createZipFromDirectory(directoryPath: string): { sizeBytes: number; zipPath: string } {\n const zip = new AdmZip()\n\n let totalFiles = 0\n let processedFiles = 0\n\n const countFiles = (currentPath: string) => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n\n if (stat.isDirectory()) {\n countFiles(filePath)\n } else {\n totalFiles++\n }\n }\n }\n\n countFiles(directoryPath)\n\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Creating zip [{bar}] {percentage}% | {value}/{total} files | Current: {filename}\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n progressBar.start(totalFiles, 0, {\n filename: \"Initializing...\",\n })\n\n const addFilesToZip = (currentPath: string, relativePath = \"\") => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n const displayPath = path.join(relativePath, file)\n\n if (stat.isDirectory()) {\n addFilesToZip(filePath, displayPath)\n } else {\n // Update the progress bar with the current file\n processedFiles++\n progressBar.update(processedFiles, {\n filename:\n displayPath.length > 40 ? \"...\" + displayPath.slice(Math.max(0, displayPath.length - 37)) : displayPath,\n })\n\n zip.addLocalFile(filePath, relativePath)\n }\n }\n }\n\n try {\n addFilesToZip(directoryPath)\n } finally {\n progressBar.stop()\n }\n\n const zipPath = `${directoryPath}.zip`\n zip.writeZip(zipPath)\n\n const sizeBytes = fs.statSync(zipPath).size\n\n return { sizeBytes, zipPath }\n }\n\n private getIndexJson(directoryPath: string) {\n const indexJsonPath = path.join(directoryPath, \"index.json\")\n if (!fs.existsSync(indexJsonPath)) {\n return \"{}\"\n }\n\n return JSON.parse(fs.readFileSync(indexJsonPath, \"utf8\"))\n }\n\n /**\n * Uploads the zip archive to the provided signed URL\n */\n private async uploadArchiveToSignedUrl(input: {\n designSystemId: string\n name?: string\n signedUrl: string\n storybookUploadId: string\n zipPath: string\n }): Promise<void> {\n const { designSystemId, name, signedUrl, storybookUploadId, zipPath } = input\n this.log(`Securely uploading ${zipPath} to Supernova...`)\n\n // Create a new progress bar\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Uploading |{bar}| {percentage}% || {value}/{total} kB\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n const fileStream = fs.createReadStream(zipPath)\n const stats = fs.statSync(zipPath)\n const fileSize = stats.size\n const fileSizeKB = Number.parseFloat(bytesToKB(fileSize))\n\n // Start the progress bar\n progressBar.start(fileSizeKB, 0)\n\n try {\n await axios.put(signedUrl, fileStream, {\n headers: {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/zip\",\n designSystemId,\n storybookUploadId,\n ...(name && { name }),\n },\n onUploadProgress(progressEvent) {\n const loaded = progressEvent.loaded || 0\n const loadedKB = Number.parseFloat(bytesToKB(loaded))\n progressBar.update(loadedKB)\n },\n })\n\n // Complete the progress bar\n progressBar.update(fileSizeKB)\n progressBar.stop()\n } catch (error) {\n // Make sure to stop the progress bar if there's an error\n progressBar.stop()\n throw error\n }\n }\n\n /**\n * Validates if a directory is a valid storybook static export\n * @param directoryPath Path to the storybook directory\n * @returns An object indicating if the directory is valid and an error message if not\n */\n private validateStorybookDirectory(directoryPath: string): { error?: string; isValid: boolean } {\n if (!fs.existsSync(directoryPath)) {\n return { error: `Directory not found: ${directoryPath}`, isValid: false }\n }\n\n if (!fs.statSync(directoryPath).isDirectory()) {\n return { error: `Not a directory: ${directoryPath}`, isValid: false }\n }\n\n // Check for essential storybook files\n const requiredFiles = [\"index.html\", \"iframe.html\"]\n const missingFiles = requiredFiles.filter(file => !fs.existsSync(path.join(directoryPath, file)))\n\n if (missingFiles.length > 0) {\n return {\n error: `Directory does not appear to be a valid Storybook export. Missing files: ${missingFiles.join(\", \")}`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n\n /**\n * Validates if a zip file size is within the allowed limits\n * @param zipPath Path to the zip file\n * @param sizeBytes Size of the zip file in bytes\n * @returns An object indicating if the zip is valid and an error message if not\n */\n private validateZipSize(zipPath: string, sizeBytes: number): { error?: string; isValid: boolean } {\n if (sizeBytes > MAX_ZIP_SIZE_BYTES) {\n // Delete the zip file if it's too large\n try {\n fs.unlinkSync(zipPath)\n } catch {\n // Ignore errors during cleanup\n }\n\n return {\n error: `Zip file is too large: ${bytesToMB(sizeBytes)}MB. Maximum allowed size is ${bytesToMB(MAX_ZIP_SIZE_BYTES)}MB`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"storybook-import.js","sourceRoot":"","sources":["../../src/commands/storybook-import.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,OAAO,MAAM,uBAAuB,CAAA;AAE3C,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAA;AAEhC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,0BAA0B,EAAa,MAAM,mBAAmB,CAAA;AACnH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,MAAM,kBAAkB,GA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CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YAC9C,OAAO,EAAE,KAAK,EAAE,oBAAoB,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;QACvE,CAAC;QAGD,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;QACnD,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjG,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO;gBACL,KAAK,EAAE,4EAA4E,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAC5G,OAAO,EAAE,KAAK;aACf,CAAA;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;IAQO,eAAe,CAAC,OAAe,EAAE,SAAiB;QACxD,IAAI,SAAS,GAAG,kBAAkB,EAAE,CAAC;YAEnC,IAAI,CAAC;gBACH,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;YACxB,CAAC;YAAC,MAAM,CAAC;YAET,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,0BAA0B,SAAS,CAAC,SAAS,CAAC,+BAA+B,SAAS,CAAC,kBAAkB,CAAC,IAAI;gBACrH,OAAO,EAAE,KAAK;aACf,CAAA;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;;AAjZY;IADZ,YAAY,EAAE;;;;0CA6Cd","sourcesContent":["import { Flags } from \"@oclif/core\"\nimport { action } from \"@oclif/core/ux\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport slugify from \"@sindresorhus/slugify\"\nimport { DTODataSourceStorybook, SupernovaApiClient } from \"@supernova-studio/client\"\nimport AdmZip from \"adm-zip\"\nimport axios from \"axios\"\nimport cliProgress from \"cli-progress\"\nimport inquirer from \"inquirer\"\nimport * as fs from \"node:fs\"\nimport path from \"node:path\"\nimport { z, ZodType } from \"zod\"\n\nimport { commonFlags, getTargetEnv, SentryCommand, storybookUrlForEnvironment, TargetEnv } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.js\"\nimport { getApiClient } from \"../utils/index.js\"\n\n// Maximum allowed size for storybook zip file (500MB)\nconst MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024\n\nconst bytesToKB = (bytes: number) => (bytes / 1024).toFixed(2)\nconst bytesToMB = (bytes: number) => (bytes / (1024 * 1024)).toFixed(2)\n\nconst ImportStorybookConfigSchema = z.object({\n brandId: z.string().optional(),\n designSystemId: z.string().optional(),\n from: z.string(),\n name: z.string().optional(),\n sourceId: z.string().optional(),\n versionId: z.string().optional(),\n})\n\ntype ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>\n\nconst storybookEndpoint = (\n environment: TargetEnv,\n designSystemId: string,\n name: string,\n accessToken: string,\n): string => {\n const host = storybookUrlForEnvironment(environment)\n const encodedAccessToken = encodeURIComponent(accessToken)\n return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?storybook_jwt=${encodedAccessToken}`\n}\n\nexport default class ImportStorybook extends SentryCommand<ImportStorybookConfig> {\n static override args = {}\n static override description = \"Import storybook static export to Supernova\"\n static override examples = [\"<%= config.bin %> <%= command.id %> import-storybook \"]\n static override flags = {\n ...commonFlags,\n brandId: Flags.string({ char: \"b\", description: \"Import storybooks to brand of\" }),\n designSystemId: Flags.string({ char: \"d\", description: \"Import storybooks to design system of\" }),\n from: Flags.string({\n char: \"f\",\n description: \"Directory with storybook static export to import.\",\n required: true,\n }),\n name: Flags.string({ char: \"n\", description: \"Import storybooks with name of\" }),\n sourceId: Flags.string({ char: \"s\", description: \"Import storybooks to source of\" }),\n }\n\n get commandId(): string {\n return ImportStorybook.id\n }\n\n get configSchema(): ZodType<ImportStorybookConfig> {\n return ImportStorybookConfigSchema\n }\n\n @SentryTraced()\n public async run(): Promise<void> {\n const { flags } = await this.parse(ImportStorybook)\n\n const env = getTargetEnv()\n const { sourceId } = flags\n\n const storybookDirectory = await this.getStorybookDirectory(flags)\n const storybookName = await this.getStorybookName(flags)\n const designSystemId = await this.getDesignSystemId(env, flags)\n const brandPersistentId = await this.getBrandId(env, flags, designSystemId)\n\n const apiClient = await getApiClient(env)\n const { designSystems } = apiClient\n const { storybookHosting } = designSystems\n\n this.log(`Preparing Storybook files from ${storybookDirectory}...`)\n const { sizeBytes, zipPath } = this.createZipFromDirectory(storybookDirectory)\n\n const sizeValidation = this.validateZipSize(zipPath, sizeBytes)\n if (!sizeValidation.isValid) {\n this.error(sizeValidation.error!)\n }\n\n const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, {\n name: storybookName,\n })\n\n await this.uploadArchiveToSignedUrl({ designSystemId, storybookName, signedUrl, storybookUploadId, zipPath })\n this.log(\"✅ Upload complete.\")\n\n action.start(\"Deploying Storybook to private Supernova hosting service...\")\n await this.waitForPublishing({ apiClient, designSystemId, storybookUploadId })\n action.stop(\"\\n✅ Private Storybook deployed successfully!\")\n\n action.start(\"Updating Storybook stories...\")\n await this.importStorybookStories(env, {\n apiClient,\n designSystemId,\n brandPersistentId,\n sourceId,\n storybookDirectory,\n storybookName,\n })\n action.stop(\"\\n✅ Storybook stories have been updated!\")\n }\n\n //\n // Argument parsing\n //\n\n private async getStorybookName(flags: ImportStorybookConfig) {\n let result = flags.name\n\n if (!result) {\n const choice = await inquirer.prompt([\n {\n message: \"Enter URL-compatible name for this Storybook instance\",\n name: \"name\",\n type: \"input\",\n },\n ])\n\n if (typeof choice.name === \"string\") {\n result = choice.name\n }\n }\n\n if (!result) {\n this.error(\"Parameter `name` is required\")\n }\n\n return slugify(result, { lowercase: true })\n }\n\n private async getDesignSystemId(env: TargetEnv, flags: ImportStorybookConfig) {\n let { designSystemId } = flags\n\n if (!designSystemId) {\n designSystemId = await this.promptDesignSystemId(env)\n }\n\n if (!designSystemId) this.error(\"Parameter `designSystemId` is required\")\n\n return designSystemId\n }\n\n private async getBrandId(env: TargetEnv, flags: ImportStorybookConfig, designSystemId: string) {\n let { brandId } = flags\n\n if (!brandId) {\n brandId = await this.promptBrandId(env, designSystemId)\n }\n\n if (!brandId) this.error(\"Brand ID is required\")\n\n return brandId\n }\n\n private async getStorybookDirectory(flags: ImportStorybookConfig) {\n const { from } = flags\n\n const directoryValidation = this.validateStorybookDirectory(from)\n if (!directoryValidation.isValid) {\n this.error(directoryValidation.error)\n }\n\n return from\n }\n\n //\n // Upload to hosting\n //\n\n /**\n * Creates a zip archive from a directory\n * @param directoryPath Path to the directory to zip\n * @returns Path to the created zip file and its size\n */\n private createZipFromDirectory(directoryPath: string): { sizeBytes: number; zipPath: string } {\n const zip = new AdmZip()\n\n let totalFiles = 0\n let processedFiles = 0\n\n const countFiles = (currentPath: string) => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n\n if (stat.isDirectory()) {\n countFiles(filePath)\n } else {\n totalFiles++\n }\n }\n }\n\n countFiles(directoryPath)\n\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Creating zip [{bar}] {percentage}% | {value}/{total} files | Current: {filename}\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n progressBar.start(totalFiles, 0, {\n filename: \"Initializing...\",\n })\n\n const addFilesToZip = (currentPath: string, relativePath = \"\") => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n const displayPath = path.join(relativePath, file)\n\n if (stat.isDirectory()) {\n addFilesToZip(filePath, displayPath)\n } else {\n // Update the progress bar with the current file\n processedFiles++\n progressBar.update(processedFiles, {\n filename:\n displayPath.length > 40 ? \"...\" + displayPath.slice(Math.max(0, displayPath.length - 37)) : displayPath,\n })\n\n zip.addLocalFile(filePath, relativePath)\n }\n }\n }\n\n try {\n addFilesToZip(directoryPath)\n } finally {\n progressBar.stop()\n }\n\n const zipPath = `${directoryPath}.zip`\n zip.writeZip(zipPath)\n\n const sizeBytes = fs.statSync(zipPath).size\n\n return { sizeBytes, zipPath }\n }\n\n private getIndexJson(directoryPath: string) {\n const indexJsonPath = path.join(directoryPath, \"index.json\")\n if (!fs.existsSync(indexJsonPath)) {\n return \"{}\"\n }\n\n return JSON.parse(fs.readFileSync(indexJsonPath, \"utf8\"))\n }\n\n /**\n * Uploads the zip archive to the provided signed URL\n */\n private async uploadArchiveToSignedUrl(input: {\n designSystemId: string\n signedUrl: string\n storybookName?: string\n storybookUploadId: string\n zipPath: string\n }): Promise<void> {\n const { designSystemId, storybookName, signedUrl, storybookUploadId, zipPath } = input\n this.log(`Securely uploading ${zipPath} to Supernova...`)\n\n // Create a new progress bar\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Uploading |{bar}| {percentage}% || {value}/{total} kB\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n const fileStream = fs.createReadStream(zipPath)\n const stats = fs.statSync(zipPath)\n const fileSize = stats.size\n const fileSizeKB = Number.parseFloat(bytesToKB(fileSize))\n\n // Start the progress bar\n progressBar.start(fileSizeKB, 0)\n\n try {\n await axios.put(signedUrl, fileStream, {\n headers: {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/zip\",\n designSystemId,\n storybookUploadId,\n ...(storybookName && { name: storybookName }),\n },\n onUploadProgress(progressEvent) {\n const loaded = progressEvent.loaded || 0\n const loadedKB = Number.parseFloat(bytesToKB(loaded))\n progressBar.update(loadedKB)\n },\n })\n\n // Complete the progress bar\n progressBar.update(fileSizeKB)\n progressBar.stop()\n } catch (error) {\n // Make sure to stop the progress bar if there's an error\n progressBar.stop()\n throw error\n }\n }\n\n private async waitForPublishing(input: {\n apiClient: SupernovaApiClient\n designSystemId: string\n storybookUploadId: string\n }): Promise<void> {\n const { apiClient, designSystemId, storybookUploadId } = input\n\n const getStatus = async () => {\n const { status } = await apiClient.designSystems.storybookHosting.getUploadStatus(\n designSystemId,\n storybookUploadId,\n )\n return status\n }\n\n let lastStatus: Awaited<ReturnType<typeof getStatus>> = \"Unknown\"\n let unknownStatusCount = 0\n\n // Wait for publishing to complete\n // Do 15 * 60 tries roughly correspond to at least 15 minutes\n for (let i = 0; unknownStatusCount < 10 && i < 15 * 60; i++) {\n lastStatus = await getStatus()\n\n // Unknown status means the upload hasn't been picked up yet, we tolerate it for very limited amount of time\n if (lastStatus === \"Unknown\") unknownStatusCount++\n else unknownStatusCount = 0\n\n if (lastStatus === \"Completed\" || lastStatus === \"Failed\") break\n\n await sleep(1000)\n }\n\n // React to publishing status\n switch (lastStatus) {\n case \"Unknown\":\n return this.error(\"Storybook deployment initialization has timed out\")\n case \"Failed\":\n return this.error(\"Storybook deployment has failed\")\n case \"InProgress\":\n return this.error(\"Storybook deployment has timed out\")\n }\n }\n\n private async importStorybookStories(\n env: TargetEnv,\n input: {\n apiClient: SupernovaApiClient\n brandPersistentId: string\n designSystemId: string\n sourceId: string | undefined\n storybookDirectory: string\n storybookName: string\n },\n ) {\n const { apiClient, brandPersistentId, designSystemId, storybookDirectory, storybookName, sourceId } = input\n\n const sourcesEndpoint = apiClient.designSystems.sources\n const storybookHostingEndpoint = apiClient.designSystems.storybookHosting\n\n const { accessToken } = await storybookHostingEndpoint.getAccessToken(designSystemId, storybookName)\n const storybookUrl = storybookEndpoint(env, designSystemId, storybookName, accessToken)\n\n try {\n let storiesCount = 0\n if (sourceId) {\n const sourceUpdateResult = await sourcesEndpoint.updateStorybookImport(designSystemId, \"head\", {\n payload: this.getIndexJson(storybookDirectory),\n sourceId,\n })\n storiesCount = sourceUpdateResult.storiesCount\n } else {\n const { source } = await sourcesEndpoint.create(designSystemId, {\n brandPersistentId,\n description: \"CLI\",\n indexUrl: storybookUrl,\n payload: this.getIndexJson(storybookDirectory),\n type: \"Storybook\",\n userUrl: storybookUrl,\n })\n\n storiesCount = (source as unknown as DTODataSourceStorybook).storybook.storiesCount\n }\n\n this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green)\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`.red,\n )\n }\n }\n\n /**\n * Validates if a directory is a valid storybook static export\n * @param directoryPath Path to the storybook directory\n * @returns An object indicating if the directory is valid and an error message if not\n */\n private validateStorybookDirectory(directoryPath: string): { error: string; isValid: false } | { isValid: true } {\n if (!fs.existsSync(directoryPath)) {\n return { error: `Directory not found: ${directoryPath}`, isValid: false }\n }\n\n if (!fs.statSync(directoryPath).isDirectory()) {\n return { error: `Not a directory: ${directoryPath}`, isValid: false }\n }\n\n // Check for essential storybook files\n const requiredFiles = [\"index.html\", \"iframe.html\"]\n const missingFiles = requiredFiles.filter(file => !fs.existsSync(path.join(directoryPath, file)))\n\n if (missingFiles.length > 0) {\n return {\n error: `Directory does not appear to be a valid Storybook export. Missing files: ${missingFiles.join(\", \")}`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n\n /**\n * Validates if a zip file size is within the allowed limits\n * @param zipPath Path to the zip file\n * @param sizeBytes Size of the zip file in bytes\n * @returns An object indicating if the zip is valid and an error message if not\n */\n private validateZipSize(zipPath: string, sizeBytes: number): { error?: string; isValid: boolean } {\n if (sizeBytes > MAX_ZIP_SIZE_BYTES) {\n // Delete the zip file if it's too large\n try {\n fs.unlinkSync(zipPath)\n } catch {\n // Ignore errors during cleanup\n }\n\n return {\n error: `Zip file is too large: ${bytesToMB(sizeBytes)}MB. Maximum allowed size is ${bytesToMB(MAX_ZIP_SIZE_BYTES)}MB`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n}\n"]}
|
|
@@ -11,8 +11,8 @@ export declare abstract class BaseCommand<T extends object> extends Command {
|
|
|
11
11
|
abstract get commandId(): string;
|
|
12
12
|
abstract get configSchema(): z.ZodType<T>;
|
|
13
13
|
protected apiClient(env: TargetEnv): Promise<SupernovaApiClient>;
|
|
14
|
-
protected
|
|
15
|
-
protected
|
|
14
|
+
protected promptBrandId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string>;
|
|
15
|
+
protected promptDesignSystemId(env: TargetEnv): Promise<string>;
|
|
16
16
|
protected getVersionId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string>;
|
|
17
17
|
protected getWorkspaceId(env: TargetEnv, workspaceId?: string): Promise<string>;
|
|
18
18
|
parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-command.d.ts","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAG5D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAK5C,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,OAAO;IACjE,SAAS,CAAC,aAAa,gBAA8B;IACrD,OAAO,CAAC,eAAe,CAAgD;IAEvE,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAA;IAChC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,C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,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyBxE,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,SAAS,EAChF,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACxB,IAAI,CAAC,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAOjC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;YAI7C,MAAM;IAapB,OAAO,CAAC,qBAAqB;CAS9B"}
|
|
@@ -14,25 +14,16 @@ export class BaseCommand extends Command {
|
|
|
14
14
|
}
|
|
15
15
|
return client;
|
|
16
16
|
}
|
|
17
|
-
async
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (brdIds.length === 1) {
|
|
26
|
-
return brdIds[0].id;
|
|
27
|
-
}
|
|
28
|
-
return this.prompt("Select a brand:", brdIds.map(brand => ({
|
|
29
|
-
name: brand.name,
|
|
30
|
-
value: brand.id,
|
|
31
|
-
})));
|
|
17
|
+
async promptBrandId(env, designSystemId, versionId) {
|
|
18
|
+
const client = await this.apiClient(env);
|
|
19
|
+
const brandsEndpoint = client.designSystems.versions.brands;
|
|
20
|
+
const { brands } = await brandsEndpoint.list(designSystemId, versionId ?? "head");
|
|
21
|
+
const options = brands.map(b => ({ name: b.meta.name, value: b.persistentId }));
|
|
22
|
+
if (options.length === 1)
|
|
23
|
+
return options[0].value;
|
|
24
|
+
return this.prompt("Select a brand:", options);
|
|
32
25
|
}
|
|
33
|
-
async
|
|
34
|
-
if (designSystemId)
|
|
35
|
-
return designSystemId;
|
|
26
|
+
async promptDesignSystemId(env) {
|
|
36
27
|
const { designSystems: client } = await this.apiClient(env);
|
|
37
28
|
const { designSystems, workspaces } = await client.listUserDesignSystems();
|
|
38
29
|
const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMrC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,MAAM,SAAS,GAAG,CAAC,IAA8B,EAAE,EAAE,CACnD,IAAI,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAErE,MAAM,OAAgB,WAA8B,SAAQ,OAAO;IACvD,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA;IAC7C,eAAe,GAAuC,IAAI,GAAG,EAAE,CAAA;IAK7D,KAAK,CAAC,SAAS,CAAC,GAAc;QACtC,IAAI,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAA;YAChC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACvC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,GAAc,EACd,cAAsB,EACtB,SAAiB,EACjB,OAAgB;QAEhB,IAAI,OAAO;YAAE,OAAO,OAAO,CAAA;QAC3B,MAAM,EACJ,aAAa,EAAE,EACb,QAAQ,EAAE,EAAE,MAAM,EAAE,GACrB,GACF,GAAG,MA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AC,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;gBACtD,OAAO;gBACP,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,MAAM;aACb;SACF,CAAC,CAAA;QAEF,OAAO,MAAM,CAAC,QAAkB,CAAA;IAClC,CAAC;IAEO,qBAAqB,CAAC,GAA4B;QACxD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpB,IAAI,KAAK,KAAK,SAAS;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACzC,OAAO,GAAG,CAAA;QACZ,CAAC,EACD,EAA6B,CAC9B,CAAA;IACH,CAAC;CACF","sourcesContent":["import { Command } from \"@oclif/core\"\nimport { Input, ParserOutput } from \"@oclif/core/interfaces\"\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport { ArgOutput, FlagOutput } from \"@oclif/core/lib/interfaces/parser.js\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { ConfigService } from \"../utils/config.service.js\"\nimport { getApiClient } from \"../utils/index.js\"\nimport { TargetEnv } from \"./environment.js\"\n\nconst hasAccess = (role?: DTODesignSystem[\"role\"]) =>\n role && [\"Admin\", \"Contributor\", \"Creator\", \"Owner\"].includes(role)\n\nexport abstract class BaseCommand<T extends object> extends Command {\n protected configService = ConfigService.getInstance()\n private apiClientForEnv: Map<TargetEnv, SupernovaApiClient> = new Map()\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient(env: TargetEnv): Promise<SupernovaApiClient> {\n let client = this.apiClientForEnv.get(env)\n if (!client) {\n client = await getApiClient(env)\n this.apiClientForEnv.set(env, client)\n }\n\n return client\n }\n\n protected async getBrandId(\n env: TargetEnv,\n designSystemId: string,\n versionId: string,\n brandId?: string,\n ): Promise<string> {\n if (brandId) return brandId\n const {\n designSystems: {\n versions: { brands },\n },\n } = await this.apiClient(env)\n const brdIds = (await brands.list(designSystemId, versionId)).brands.map(\n ({ meta: { name }, persistentId: id }) => ({\n id,\n name,\n }),\n )\n\n if (brdIds.length === 1) {\n return brdIds[0].id\n }\n\n return this.prompt(\n \"Select a brand:\",\n brdIds.map(brand => ({\n name: brand.name,\n value: brand.id,\n })),\n )\n }\n\n protected async getDesignSystemId(env: TargetEnv, designSystemId?: string): Promise<string> {\n if (designSystemId) return designSystemId\n const { designSystems: client } = await this.apiClient(env)\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient(env)).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(env: TargetEnv, workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient(env)\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n const parsed = await super.parse(options, argv)\n const fileConfig = this.configService.getCommandConfig(this.commandId, this.configSchema)\n parsed.flags = { ...fileConfig, ...parsed.flags }\n return parsed\n }\n\n protected saveConfig(config: Record<string, unknown>): void {\n this.configService.updateCommandConfig(this.commandId, this.removeUndefinedValues(config))\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n\n private removeUndefinedValues(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.entries(obj).reduce(\n (acc, [key, value]) => {\n if (value !== undefined) acc[key] = value\n return acc\n },\n {} as Record<string, unknown>,\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMrC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,MAAM,SAAS,GA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CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QACzF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;QACjD,OAAO,MAAM,CAAA;IACf,CAAC;IAES,UAAU,CAAC,MAA+B;QAClD,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5F,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,OAA0C;QAC9E,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;YACnC;gBACE,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;gBACtD,OAAO;gBACP,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,MAAM;aACb;SACF,CAAC,CAAA;QAEF,OAAO,MAAM,CAAC,QAAkB,CAAA;IAClC,CAAC;IAEO,qBAAqB,CAAC,GAA4B;QACxD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpB,IAAI,KAAK,KAAK,SAAS;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACzC,OAAO,GAAG,CAAA;QACZ,CAAC,EACD,EAA6B,CAC9B,CAAA;IACH,CAAC;CACF","sourcesContent":["import { Command } from \"@oclif/core\"\nimport { Input, ParserOutput } from \"@oclif/core/interfaces\"\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport { ArgOutput, FlagOutput } from \"@oclif/core/lib/interfaces/parser.js\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { ConfigService } from \"../utils/config.service.js\"\nimport { getApiClient } from \"../utils/index.js\"\nimport { TargetEnv } from \"./environment.js\"\n\nconst hasAccess = (role?: DTODesignSystem[\"role\"]) =>\n role && [\"Admin\", \"Contributor\", \"Creator\", \"Owner\"].includes(role)\n\nexport abstract class BaseCommand<T extends object> extends Command {\n protected configService = ConfigService.getInstance()\n private apiClientForEnv: Map<TargetEnv, SupernovaApiClient> = new Map()\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient(env: TargetEnv): Promise<SupernovaApiClient> {\n let client = this.apiClientForEnv.get(env)\n if (!client) {\n client = await getApiClient(env)\n this.apiClientForEnv.set(env, client)\n }\n\n return client\n }\n\n protected async promptBrandId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string> {\n const client = await this.apiClient(env)\n const brandsEndpoint = client.designSystems.versions.brands\n\n const { brands } = await brandsEndpoint.list(designSystemId, versionId ?? \"head\")\n\n const options = brands.map(b => ({ name: b.meta.name, value: b.persistentId }))\n if (options.length === 1) return options[0].value\n\n return this.prompt(\"Select a brand:\", options)\n }\n\n protected async promptDesignSystemId(env: TargetEnv): Promise<string> {\n const { designSystems: client } = await this.apiClient(env)\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient(env)).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(env: TargetEnv, workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient(env)\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n const parsed = await super.parse(options, argv)\n const fileConfig = this.configService.getCommandConfig(this.commandId, this.configSchema)\n parsed.flags = { ...fileConfig, ...parsed.flags }\n return parsed\n }\n\n protected saveConfig(config: Record<string, unknown>): void {\n this.configService.updateCommandConfig(this.commandId, this.removeUndefinedValues(config))\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n\n private removeUndefinedValues(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.entries(obj).reduce(\n (acc, [key, value]) => {\n if (value !== undefined) acc[key] = value\n return acc\n },\n {} as Record<string, unknown>,\n )\n }\n}\n"]}
|
package/oclif.manifest.json
CHANGED