@supernovaio/cli-next 2.1.1 → 2.2.1
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/describe-workspaces.d.ts.map +1 -1
- package/dist/commands/describe-workspaces.js.map +1 -1
- package/dist/commands/publish-documentation.d.ts.map +1 -1
- package/dist/commands/publish-documentation.js.map +1 -1
- package/dist/commands/storybook-import.d.ts +8 -11
- package/dist/commands/storybook-import.d.ts.map +1 -1
- package/dist/commands/storybook-import.js +41 -32
- package/dist/commands/storybook-import.js.map +1 -1
- package/dist/hooks/prerun/load-config.d.ts.map +1 -1
- package/dist/hooks/prerun/load-config.js +0 -11
- package/dist/hooks/prerun/load-config.js.map +1 -1
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js.map +1 -1
- package/dist/types/base-command.d.ts +7 -11
- package/dist/types/base-command.d.ts.map +1 -1
- package/dist/types/base-command.js +18 -33
- package/dist/types/base-command.js.map +1 -1
- package/dist/types/config.d.ts +54 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +15 -0
- package/dist/types/config.js.map +1 -0
- package/dist/utils/common.js +1 -1
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.service.d.ts +4 -9
- package/dist/utils/config.service.d.ts.map +1 -1
- package/dist/utils/config.service.js +21 -38
- package/dist/utils/config.service.js.map +1 -1
- package/oclif.manifest.json +1 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe-workspaces.d.ts","sourceRoot":"","sources":["../../src/commands/describe-workspaces.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAEhC,OAAO,EAAmD,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAQlG,UAAU,uBAAuB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd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AC,EAAE,CAAC,CAAA;gBAClD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;gBACvD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,IAAI,CAAC,GAAG,CAAC,iBAAiB,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;oBACzD,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,EAAE,CAAC,CAAA;oBAC9D,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAE3B,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;4BAChC,IAAI,CAAC,GAAG,CAAC,mBAAmB,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;wBAClE,CAAC;oBACH,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,GAAG,CAAC,yCAAyC,CAAC,IAAI,CAAC,CAAA;oBAC1D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;;AA/DK;IADL,YAAY,EAAE;;;;uDAsBd;AAGK;IADL,YAAY,EAAE;;;;6CAwCd","sourcesContent":["//\n// describe-workspaces.ts\n// Supernova CLI\n//\n// Created by Jiri Trecak.\n// Copyright © Supernova.io. All rights reserved.\n//\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Imports\n\nimport { Flags } from \"@oclif/core\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport * as sdkTypes from \"@supernovaio/sdk\"\nimport { createRequire } from \"node:module\"\nimport { z, ZodType } from \"zod\"\n\nimport { apiUrlForEnvironment, commonFlags, getTargetEnv, SentryCommand } from \"../types/index.js\"\n\nconst require = createRequire(import.meta.url)\nconst sdkProvider = require(\"@supernovaio/sdk\") as typeof sdkTypes\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Definition\n\ninterface DescribeWorkspacesFlags {\n apiKey: string\n proxyUrl?: string\n}\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Configuration\n\nconst DescribeWorkspaceConfigSchema = z\n .object({\n apiKey: z.string(),\n proxyUrl: z.string().url().optional(),\n workspaceId: z.string(),\n })\n .transform(data => ({\n ...data,\n }))\n\ntype DescribeWorkspaceConfig = z.infer<typeof DescribeWorkspaceConfigSchema>\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Tool implementation\n\n/** Command that describes the structure of provided design system */\nexport class DescribeWorkspaces extends SentryCommand<DescribeWorkspaceConfig> {\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command configuration\n\n // How this command can be run\n static aliases: [\"describe-workspaces\"]\n // Command help description\n static description =\n \"Describe structure of all workspaces and design systems available under those workspaces available for specified API key\"\n // Examples how to use the command\n static examples = [`$ @supernovaio/cli describe-workspaces --apiKey=\"{xxx-xxx-xxx}\"`]\n // Static flags to enable / disable features\n static flags = {\n ...commonFlags,\n apiKey: Flags.string({ description: \"API key to use for accessing Supernova instance\", required: true }),\n proxyUrl: Flags.string({\n description: \"When set, CLI will use provided proxy URL for all requests\",\n hidden: true,\n required: false,\n }),\n }\n\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command runtime\n\n get commandId(): string {\n return DescribeWorkspaces.id\n }\n\n get configSchema(): ZodType<DescribeWorkspaceConfig> {\n return DescribeWorkspaceConfigSchema\n }\n\n @SentryTraced()\n async getWorkspaces(flags: DescribeWorkspacesFlags): Promise<{\n instance: sdkTypes.Supernova\n workspaces: Array<sdkTypes.Workspace>\n }> {\n if (!flags.apiKey || flags.apiKey.length === 0) {\n throw new Error(`API key must not be empty`)\n }\n\n // Create instance for prod / dev\n const apiUrl = apiUrlForEnvironment(getTargetEnv())\n const sdkInstance = new sdkProvider.Supernova(flags.apiKey, {\n apiUrl,\n bypassEnvFetch: true,\n proxyUrl: flags.proxyUrl,\n })\n const user = await sdkInstance.me.me()\n const workspaces = await sdkInstance.workspaces.workspaces(user.id)\n return {\n instance: sdkInstance,\n workspaces,\n }\n }\n\n @SentryTraced()\n async run(): Promise<void> {\n const { flags } = await this.parse(DescribeWorkspaces)\n\n // Get workspaces\n const { instance, workspaces } = await this.getWorkspaces(flags)\n this.log(`\\n`)\n\n for (const workspace of workspaces) {\n // Get design systems and log\n const designSystems = await instance.designSystems.designSystems(workspace.id)\n this.log(`↳ Workspace \"${workspace.profile.name}\", id: ${workspace.id}`.magenta)\n for (const designSystem of designSystems) {\n this.log(` ↳ Design system \"${designSystem.name}\", id: ${designSystem.id}`.cyan)\n\n const version = await instance.versions.getActiveVersion(designSystem.id)\n if (!version) {\n this.log(`Design system ${designSystem.id} active version not found or not available under provided API key`)\n continue\n }\n\n const id: sdkTypes.RemoteVersionIdentifier = { designSystemId: designSystem.id, versionId: version.id }\n const brands = await instance.brands.getBrands(id)\n const themes = await instance.tokens.getTokenThemes(id)\n for (const brand of brands) {\n this.log(` ↳ Brand: \"${brand.name}\", id: ${brand.id}`)\n const brandThemes = themes.filter(t => t.brandId === brand.id)\n if (brandThemes.length > 0) {\n // eslint-disable-next-line max-depth\n for (const theme of brandThemes) {\n this.log(` ↳ Theme: \"${theme.name}\", id: ${theme.id}`.gray)\n }\n } else {\n this.log(` ↳ No themes defined in this brand`.gray)\n }\n }\n }\n }\n\n this.log(\"\\nDone\".green)\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-documentation.d.ts","sourceRoot":"","sources":["../../src/commands/publish-documentation.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAUjD,QAAA,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;EAOpC,CAAA;AAEF,KAAK,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAMlF,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,0BAA0B,CAAC;IAKjF,MAAM,CAAC,OAAO,EAAE,CAAC,uBAAuB,CAAC,CAAA;IAEzC,MAAM,CAAC,WAAW,SAAgD;IAElE,MAAM,CAAC,QAAQ,WAAkG;IAEjH,MAAM,CAAC,KAAK;;;;;;;MAsBX;IAKD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,OAAO,CAAC,0BAA0B,CAAC,CAEtD;IAGK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"publish-documentation.d.ts","sourceRoot":"","sources":["../../src/commands/publish-documentation.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAUjD,QAAA,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;EAOpC,CAAA;AAEF,KAAK,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAMlF,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,0BAA0B,CAAC;IAKjF,MAAM,CAAC,OAAO,EAAE,CAAC,uBAAuB,CAAC,CAAA;IAEzC,MAAM,CAAC,WAAW,SAAgD;IAElE,MAAM,CAAC,QAAQ,WAAkG;I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AO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,MAAkC;IACzD,OAAO,CACL,MAAM,KAAK,QAAQ,CAAC,iBAAiB,CAAC,MAAM;QAC5C,MAAM,KAAK,QAAQ,CAAC,iBAAiB,CAAC,OAAO;QAC7C,MAAM,KAAK,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAC9C,CAAA;AACH,CAAC","sourcesContent":["//\n// publish-documentation.ts\n// Supernova CLI\n//\n// Created by Jiri Trecak.\n// Copyright © Supernova.io. All rights reserved.\n//\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Imports\n\nimport { Flags } from \"@oclif/core\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport * as sdkTypes from \"@supernovaio/sdk\"\nimport { z, ZodType } from \"zod\"\n\nimport { SentryCommand } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.js\"\nimport { getWritableVersion } from \"../utils/sdk.js\"\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Definition\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Configuration\n\nconst PublishDocumentationConfigSchema = z.object({\n apiKey: z.string(),\n awaitPublishJob: z.boolean(),\n designSystemId: z.string(),\n dev: z.boolean(),\n proxyUrl: z.string().url().optional(),\n target: z.string(),\n})\n\ntype PublishDocumentationConfig = z.infer<typeof PublishDocumentationConfigSchema>\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Tool implementation\n\n/** Command that publishes documentation */\nexport class PublishDocumentation extends SentryCommand<PublishDocumentationConfig> {\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command configuration\n\n // How this command can be run\n static aliases: [\"publish-documentation\"]\n // Command help description\n static description = \"Publish latest version of the documentation\"\n // Examples how to use the command\n static examples = [`$ @supernovaio/cli publish-documentation --apiKey=\"{xxx-xxx-xxx}\" --designSystemId=\"{1234}\"`]\n // Static flags to enable / disable features\n static flags = {\n apiKey: Flags.string({ description: \"API key to use for accessing Supernova instance\", required: true }),\n awaitPublishJob: Flags.boolean({\n default: true,\n description:\n \"Whether to block the process until the publishing is done. \" +\n \"Setting the flag to false will exit with success as long as documentation publish was successfully triggered, \" +\n \"but before the publish is completed. Setting the flag to true will exit once the publish is complete and will \" +\n \"throw if documentation publish is not successful.\",\n }),\n designSystemId: Flags.string({ description: \"Design System to publish the documentation\", required: true }),\n dev: Flags.boolean({ default: false, description: \"When enabled, CLI will target dev server\", hidden: true }),\n proxyUrl: Flags.string({\n description: \"When set, CLI will use provided proxy URL for all requests\",\n hidden: true,\n required: false,\n }),\n target: Flags.string({\n default: \"Live\",\n description: \"Environment to use for publishing: Live or Preview\",\n required: false,\n }),\n }\n\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command runtime\n\n get commandId(): string {\n return PublishDocumentation.id\n }\n\n get configSchema(): ZodType<PublishDocumentationConfig> {\n return PublishDocumentationConfigSchema\n }\n\n @SentryTraced()\n async run(): Promise<void> {\n const { flags } = await this.parse(PublishDocumentation)\n\n const environment = tryParseDocsEnvironment(flags.target)\n if (!environment) {\n const supportedEnvs = [sdkTypes.DocumentationEnvironment.live, sdkTypes.DocumentationEnvironment.preview]\n this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(\", \")}]`)\n }\n\n // Get workspace -> design system –> version\n const { designSystem, id, instance } = await getWritableVersion(flags)\n\n this.log(`Queueing documentation publish in ${designSystem.name}...`)\n\n let publishJob = await instance.documentation.publishDrafts(id, environment, {\n groupPersistentIds: [],\n pagePersistentIds: [],\n })\n\n this.log(`Documentation queued for publishing`.green)\n\n if (!flags.awaitPublishJob) {\n this.log(`Documentation publish await is disabled, exiting before the publish is finished.`.yellow)\n return\n }\n\n this.log(`Waiting for the documentation publish to be finished...`)\n\n // Timeout is roughly 30 minutes\n for (let i = 0; i < 30 * 60; i++) {\n await sleep(1000)\n publishJob = await instance.documentation.getDocumentationBuild(designSystem.workspaceId, publishJob.id)\n if (isJobStatusDone(publishJob.status)) break\n }\n\n switch (publishJob.status) {\n case \"Success\": {\n this.log(\"\\nDone: Documentation queued for publishing\".green)\n\n break\n }\n\n case \"Failed\": {\n throw new Error(`Documentation publish failed`)\n }\n\n case \"Timeout\": {\n throw new Error(`Documentation publish timed out`)\n }\n\n default: {\n throw new Error(`Error awaiting publish job`)\n }\n }\n }\n}\n\nfunction tryParseDocsEnvironment(targetArg: string) {\n switch (targetArg.toLowerCase()) {\n case \"live\": {\n return sdkTypes.DocumentationEnvironment.live\n }\n\n case \"preview\": {\n return sdkTypes.DocumentationEnvironment.preview\n }\n\n default: {\n return null\n }\n }\n}\n\nfunction isJobStatusDone(status: sdkTypes.ExportBuildStatus): boolean {\n return (\n status === sdkTypes.ExportBuildStatus.Failed ||\n status === sdkTypes.ExportBuildStatus.Success ||\n status === sdkTypes.ExportBuildStatus.Timeout\n )\n}\n"]}
|
|
@@ -3,24 +3,21 @@ import { SentryCommand } from "../types/index.js";
|
|
|
3
3
|
declare const ImportStorybookConfigSchema: z.ZodObject<{
|
|
4
4
|
brandId: z.ZodOptional<z.ZodString>;
|
|
5
5
|
designSystemId: z.ZodOptional<z.ZodString>;
|
|
6
|
-
from: z.ZodString
|
|
6
|
+
from: z.ZodOptional<z.ZodString>;
|
|
7
7
|
name: z.ZodOptional<z.ZodString>;
|
|
8
8
|
sourceId: z.ZodOptional<z.ZodString>;
|
|
9
|
-
versionId: z.ZodOptional<z.ZodString>;
|
|
10
9
|
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
from: string;
|
|
12
|
-
name?: string | undefined;
|
|
13
10
|
designSystemId?: string | undefined;
|
|
14
|
-
versionId?: string | undefined;
|
|
15
|
-
brandId?: string | undefined;
|
|
16
11
|
sourceId?: string | undefined;
|
|
17
|
-
|
|
18
|
-
from: string;
|
|
12
|
+
brandId?: string | undefined;
|
|
19
13
|
name?: string | undefined;
|
|
14
|
+
from?: string | undefined;
|
|
15
|
+
}, {
|
|
20
16
|
designSystemId?: string | undefined;
|
|
21
|
-
versionId?: string | undefined;
|
|
22
|
-
brandId?: string | undefined;
|
|
23
17
|
sourceId?: string | undefined;
|
|
18
|
+
brandId?: string | undefined;
|
|
19
|
+
name?: string | undefined;
|
|
20
|
+
from?: string | undefined;
|
|
24
21
|
}>;
|
|
25
22
|
type ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>;
|
|
26
23
|
export default class ImportStorybook extends SentryCommand<ImportStorybookConfig> {
|
|
@@ -30,7 +27,7 @@ export default class ImportStorybook extends SentryCommand<ImportStorybookConfig
|
|
|
30
27
|
static flags: {
|
|
31
28
|
brandId: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
29
|
designSystemId: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
33
|
-
from: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
+
from: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
31
|
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
32
|
sourceId: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
36
33
|
};
|
|
@@ -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;
|
|
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;AAGhC,OAAO,EAAe,aAAa,EAAyC,MAAM,mBAAmB,CAAA;AASrG,QAAA,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;EAM/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;;;;;;MAUpB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAEjD;IAGY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YA6DnB,gBAAgB;YAwBhB,iBAAiB;YAYjB,UAAU;YAYV,qBAAqB;IAqBnC,OAAO,CAAC,sBAAsB;IA0E9B,OAAO,CAAC,YAAY;YAYN,wBAAwB;YAuDxB,iBAAiB;YA2CjB,sBAAsB;IAuDpC,OAAO,CAAC,0BAA0B;IA6BlC,OAAO,CAAC,eAAe;CAiBxB"}
|
|
@@ -18,24 +18,22 @@ import inquirer from "inquirer";
|
|
|
18
18
|
import * as fs from "node:fs";
|
|
19
19
|
import path from "node:path";
|
|
20
20
|
import { z } from "zod";
|
|
21
|
-
import { commonFlags,
|
|
21
|
+
import { commonFlags, SentryCommand, storybookUrlForEnvironment } from "../types/index.js";
|
|
22
22
|
import { sleep } from "../utils/common.js";
|
|
23
|
-
import { getApiClient } from "../utils/index.js";
|
|
24
23
|
const MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024;
|
|
25
24
|
const bytesToKB = (bytes) => (bytes / 1024).toFixed(2);
|
|
26
25
|
const bytesToMB = (bytes) => (bytes / (1024 * 1024)).toFixed(2);
|
|
27
26
|
const ImportStorybookConfigSchema = z.object({
|
|
28
27
|
brandId: z.string().optional(),
|
|
29
28
|
designSystemId: z.string().optional(),
|
|
30
|
-
from: z.string(),
|
|
29
|
+
from: z.string().optional(),
|
|
31
30
|
name: z.string().optional(),
|
|
32
31
|
sourceId: z.string().optional(),
|
|
33
|
-
versionId: z.string().optional(),
|
|
34
32
|
});
|
|
35
33
|
const storybookEndpoint = (environment, designSystemId, name, accessToken) => {
|
|
36
34
|
const host = storybookUrlForEnvironment(environment);
|
|
37
35
|
const encodedAccessToken = encodeURIComponent(accessToken);
|
|
38
|
-
return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?
|
|
36
|
+
return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?authorization=${encodedAccessToken}`;
|
|
39
37
|
};
|
|
40
38
|
export default class ImportStorybook extends SentryCommand {
|
|
41
39
|
static args = {};
|
|
@@ -48,7 +46,6 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
48
46
|
from: Flags.string({
|
|
49
47
|
char: "f",
|
|
50
48
|
description: "Directory with storybook static export to import.",
|
|
51
|
-
required: true,
|
|
52
49
|
}),
|
|
53
50
|
name: Flags.string({ char: "n", description: "Import storybooks with name of" }),
|
|
54
51
|
sourceId: Flags.string({ char: "s", description: "Import storybooks to source of" }),
|
|
@@ -60,17 +57,15 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
60
57
|
return ImportStorybookConfigSchema;
|
|
61
58
|
}
|
|
62
59
|
async run() {
|
|
63
|
-
const { flags } = await this.parse(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
const env = getTargetEnv();
|
|
60
|
+
const { flags } = await this.parse();
|
|
61
|
+
const config = this.configService.get();
|
|
62
|
+
const storybookConfig = config?.storybook ?? {};
|
|
68
63
|
const { sourceId } = flags;
|
|
69
|
-
const storybookDirectory = await this.getStorybookDirectory(flags);
|
|
70
|
-
const storybookName = await this.getStorybookName(flags);
|
|
71
|
-
const designSystemId = await this.getDesignSystemId(
|
|
72
|
-
const brandPersistentId = await this.getBrandId(
|
|
73
|
-
const apiClient = await
|
|
64
|
+
const storybookDirectory = await this.getStorybookDirectory(flags, storybookConfig);
|
|
65
|
+
const storybookName = await this.getStorybookName(flags, storybookConfig);
|
|
66
|
+
const designSystemId = await this.getDesignSystemId(flags, storybookConfig);
|
|
67
|
+
const brandPersistentId = await this.getBrandId(flags, storybookConfig, designSystemId);
|
|
68
|
+
const apiClient = await this.apiClient();
|
|
74
69
|
const { designSystems } = apiClient;
|
|
75
70
|
const { storybookHosting } = designSystems;
|
|
76
71
|
this.log(`Preparing Storybook files from ${storybookDirectory}...`);
|
|
@@ -88,7 +83,7 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
88
83
|
await this.waitForPublishing({ apiClient, designSystemId, storybookUploadId });
|
|
89
84
|
action.stop("\n✅ Private Storybook deployed successfully!");
|
|
90
85
|
action.start("Updating Storybook stories...");
|
|
91
|
-
await this.importStorybookStories(
|
|
86
|
+
const { sourceId: finalSourceId } = await this.importStorybookStories({
|
|
92
87
|
apiClient,
|
|
93
88
|
designSystemId,
|
|
94
89
|
brandPersistentId,
|
|
@@ -97,13 +92,22 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
97
92
|
storybookName,
|
|
98
93
|
});
|
|
99
94
|
action.stop("\n✅ Storybook stories have been updated!");
|
|
95
|
+
this.configService.update({
|
|
96
|
+
storybook: {
|
|
97
|
+
designSystemId,
|
|
98
|
+
from: storybookDirectory,
|
|
99
|
+
name: storybookName,
|
|
100
|
+
brandId: brandPersistentId,
|
|
101
|
+
sourceId: finalSourceId,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
100
104
|
}
|
|
101
|
-
async getStorybookName(flags) {
|
|
102
|
-
let result = flags.name;
|
|
105
|
+
async getStorybookName(flags, config) {
|
|
106
|
+
let result = flags.name ?? config.name;
|
|
103
107
|
if (!result) {
|
|
104
108
|
const choice = await inquirer.prompt([
|
|
105
109
|
{
|
|
106
|
-
message: "Enter
|
|
110
|
+
message: "Enter name of your storybook instance (it will be part of the URL)",
|
|
107
111
|
name: "name",
|
|
108
112
|
type: "input",
|
|
109
113
|
},
|
|
@@ -117,26 +121,28 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
117
121
|
}
|
|
118
122
|
return slugify(result, { lowercase: true });
|
|
119
123
|
}
|
|
120
|
-
async getDesignSystemId(
|
|
121
|
-
let
|
|
124
|
+
async getDesignSystemId(flags, config) {
|
|
125
|
+
let designSystemId = flags.designSystemId ?? config.designSystemId;
|
|
122
126
|
if (!designSystemId) {
|
|
123
|
-
designSystemId = await this.promptDesignSystemId(
|
|
127
|
+
designSystemId = await this.promptDesignSystemId();
|
|
124
128
|
}
|
|
125
129
|
if (!designSystemId)
|
|
126
130
|
this.error("Parameter `designSystemId` is required");
|
|
127
131
|
return designSystemId;
|
|
128
132
|
}
|
|
129
|
-
async getBrandId(
|
|
130
|
-
let
|
|
133
|
+
async getBrandId(flags, config, designSystemId) {
|
|
134
|
+
let brandId = flags.brandId ?? config.brandId;
|
|
131
135
|
if (!brandId) {
|
|
132
|
-
brandId = await this.promptBrandId(
|
|
136
|
+
brandId = await this.promptBrandId(designSystemId);
|
|
133
137
|
}
|
|
134
138
|
if (!brandId)
|
|
135
|
-
this.error("
|
|
139
|
+
this.error("Parameter `brandId` is required");
|
|
136
140
|
return brandId;
|
|
137
141
|
}
|
|
138
|
-
async getStorybookDirectory(flags) {
|
|
139
|
-
const
|
|
142
|
+
async getStorybookDirectory(flags, config) {
|
|
143
|
+
const from = flags.from ?? config.from;
|
|
144
|
+
if (!from)
|
|
145
|
+
this.error("Parameter `from` is required");
|
|
140
146
|
const directoryValidation = this.validateStorybookDirectory(from);
|
|
141
147
|
if (!directoryValidation.isValid) {
|
|
142
148
|
this.error(directoryValidation.error);
|
|
@@ -270,12 +276,13 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
270
276
|
return this.error("Storybook deployment has timed out");
|
|
271
277
|
}
|
|
272
278
|
}
|
|
273
|
-
async importStorybookStories(
|
|
274
|
-
const { apiClient, brandPersistentId, designSystemId, storybookDirectory, storybookName
|
|
279
|
+
async importStorybookStories(input) {
|
|
280
|
+
const { apiClient, brandPersistentId, designSystemId, storybookDirectory, storybookName } = input;
|
|
281
|
+
let { sourceId } = input;
|
|
275
282
|
const sourcesEndpoint = apiClient.designSystems.sources;
|
|
276
283
|
const storybookHostingEndpoint = apiClient.designSystems.storybookHosting;
|
|
277
284
|
const { accessToken } = await storybookHostingEndpoint.getAccessToken(designSystemId, storybookName);
|
|
278
|
-
const storybookUrl = storybookEndpoint(env, designSystemId, storybookName, accessToken);
|
|
285
|
+
const storybookUrl = storybookEndpoint(this.env, designSystemId, storybookName, accessToken);
|
|
279
286
|
try {
|
|
280
287
|
let storiesCount = 0;
|
|
281
288
|
if (sourceId) {
|
|
@@ -295,9 +302,11 @@ export default class ImportStorybook extends SentryCommand {
|
|
|
295
302
|
userUrl: storybookUrl,
|
|
296
303
|
});
|
|
297
304
|
storiesCount = source.storybook.storiesCount;
|
|
305
|
+
sourceId = source.id;
|
|
298
306
|
}
|
|
299
307
|
this.log(`✅ Imported ${storiesCount} component stories into Supernova!`);
|
|
300
308
|
this.log(`🔒 Access your Storybook at: ${storybookUrl}`);
|
|
309
|
+
return { sourceId };
|
|
301
310
|
}
|
|
302
311
|
catch (error) {
|
|
303
312
|
this.error(`Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1 +1 @@
|
|
|
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,gBAA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AC,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;;AArZY;IADZ,YAAY,EAAE;;;;0CAiDd","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 if (true as unknown) {\n throw new Error(`Test`)\n }\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!`)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`)\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`,\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"]}
|
|
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;AAGhC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,0BAA0B,EAAa,MAAM,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QO,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;;AA9ZY;IADZ,YAAY,EAAE;;;;0CAwDd","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 { SupernovaConfigStorybook } from \"../types/config.js\"\nimport { commonFlags, SentryCommand, storybookUrlForEnvironment, TargetEnv } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.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().optional(),\n name: z.string().optional(),\n sourceId: 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?authorization=${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 }),\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()\n const config = this.configService.get()\n const storybookConfig = config?.storybook ?? {}\n\n const { sourceId } = flags\n\n const storybookDirectory = await this.getStorybookDirectory(flags, storybookConfig)\n const storybookName = await this.getStorybookName(flags, storybookConfig)\n const designSystemId = await this.getDesignSystemId(flags, storybookConfig)\n const brandPersistentId = await this.getBrandId(flags, storybookConfig, designSystemId)\n\n const apiClient = await this.apiClient()\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 const { sourceId: finalSourceId } = await this.importStorybookStories({\n apiClient,\n designSystemId,\n brandPersistentId,\n sourceId,\n storybookDirectory,\n storybookName,\n })\n action.stop(\"\\n✅ Storybook stories have been updated!\")\n\n this.configService.update({\n storybook: {\n designSystemId,\n from: storybookDirectory,\n name: storybookName,\n brandId: brandPersistentId,\n sourceId: finalSourceId,\n },\n })\n }\n\n //\n // Argument parsing\n //\n\n private async getStorybookName(flags: ImportStorybookConfig, config: SupernovaConfigStorybook) {\n let result = flags.name ?? config.name\n\n if (!result) {\n const choice = await inquirer.prompt([\n {\n message: \"Enter name of your storybook instance (it will be part of the URL)\",\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(flags: ImportStorybookConfig, config: SupernovaConfigStorybook) {\n let designSystemId = flags.designSystemId ?? config.designSystemId\n\n if (!designSystemId) {\n designSystemId = await this.promptDesignSystemId()\n }\n\n if (!designSystemId) this.error(\"Parameter `designSystemId` is required\")\n\n return designSystemId\n }\n\n private async getBrandId(flags: ImportStorybookConfig, config: SupernovaConfigStorybook, designSystemId: string) {\n let brandId = flags.brandId ?? config.brandId\n\n if (!brandId) {\n brandId = await this.promptBrandId(designSystemId)\n }\n\n if (!brandId) this.error(\"Parameter `brandId` is required\")\n\n return brandId\n }\n\n private async getStorybookDirectory(flags: ImportStorybookConfig, config: SupernovaConfigStorybook) {\n const from = flags.from ?? config.from\n if (!from) this.error(\"Parameter `from` is required\")\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(input: {\n apiClient: SupernovaApiClient\n brandPersistentId: string\n designSystemId: string\n sourceId: string | undefined\n storybookDirectory: string\n storybookName: string\n }): Promise<{ sourceId: string }> {\n const { apiClient, brandPersistentId, designSystemId, storybookDirectory, storybookName } = input\n let { 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(this.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 sourceId = source.id\n }\n\n this.log(`✅ Imported ${storiesCount} component stories into Supernova!`)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`)\n\n return { sourceId }\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`,\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../../src/hooks/prerun/load-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../../src/hooks/prerun/load-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAKlC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,QAAQ,CAqBxB,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import * as console from "node:console";
|
|
2
2
|
import { BaseCommand } from "../../types/index.js";
|
|
3
|
-
import { ConfigService } from "../../utils/config.service.js";
|
|
4
3
|
const hook = async function ({ Command }) {
|
|
5
4
|
if (Command && Command.prototype instanceof BaseCommand) {
|
|
6
|
-
const { commandId, configSchema } = new Command();
|
|
7
5
|
try {
|
|
8
|
-
const configService = ConfigService.getInstance();
|
|
9
|
-
const fileConfig = configService.getCommandConfig(commandId, configSchema);
|
|
10
|
-
if (Command.flags) {
|
|
11
|
-
for (const [flagName, flagDef] of Object.entries(Command.flags)) {
|
|
12
|
-
if (flagDef.required && fileConfig && flagName in fileConfig && fileConfig[flagName] !== undefined) {
|
|
13
|
-
flagDef.required = false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
6
|
}
|
|
18
7
|
catch {
|
|
19
8
|
console.log("Cannot apply configuration from .supernova.json");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../../src/hooks/prerun/load-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../../src/hooks/prerun/load-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,MAAM,IAAI,GAAmB,KAAK,WAAW,EAAE,OAAO,EAAE;IACtD,IAAI,OAAO,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE,CAAC;QAExD,IAAI,CAAC;QAcL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED,eAAe,IAAI,CAAA","sourcesContent":["import { Hook } from \"@oclif/core\"\nimport * as console from \"node:console\"\n\nimport { BaseCommand } from \"../../types/index.js\"\n\nconst hook: Hook<\"prerun\"> = async function ({ Command }) {\n if (Command && Command.prototype instanceof BaseCommand) {\n // const { commandId, configSchema } = new (Command as never)()\n try {\n // const configService = ConfigService.getInstance()\n // const fileConfig = configService.getCommandConfig(commandId, configSchema) as {\n // [key: string]: boolean | number | string | undefined\n // }\n // if (Command.flags) {\n // for (const [flagName, flagDef] of Object.entries(Command.flags)) {\n // If the flag is marked as required but exists in config\n // if (flagDef.required && fileConfig && flagName in fileConfig && fileConfig[flagName] !== undefined) {\n // // Make it not required since we'll use the config value\n // flagDef.required = false\n // }\n // }\n // }\n } catch {\n console.log(\"Cannot apply configuration from .supernova.json\")\n }\n }\n}\n\nexport default hook\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,EAAkD,MAAM,EAAwB,MAAM,mBAAmB,CAAA;AAEhH,qBAAa,WAAW;IAET,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM;;;;IAkB1D,mBAAmB,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,EAAkD,MAAM,EAAwB,MAAM,mBAAmB,CAAA;AAEhH,qBAAa,WAAW;IAET,oBAAoB,CAAC,GAAG,EAAE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,aAAa,EAAE,YAAY;aAC5B,CAAC;YACF,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,EAAE,MAAM;SACf,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,MAAM,EACJ,MAAM,EAAE,EAAE,MAAM,EAAE,GACnB,GAAG,0BAA0B,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;QAC3D,OAAO,EAAE,GAAG,MAAM,EAAE,YAAY,EAAE,CAAA;IACpC,CAAC;IAGM,KAAK,CAAC,KAAa,IAAI;QAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACzB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAjFc;IADZ,YAAY,EAAE;;;;uDAgBd;AAGY;IADZ,YAAY,EAAE;;;;sDA4Bd;AAGY;IADZ,YAAY,EAAE;;;;+CA0Bd;AAGM;IADN,YAAY,EAAE;;;;wCAKd","sourcesContent":["import { SentryTraced } from \"@sentry/nestjs\"\nimport fetch from \"node-fetch\"\n\nimport { authUrlForEnvironment, TargetEnv } from \"../types/environment.js\"\nimport { AuthResponseSchema, RefreshTokenResponseSchema, Tokens, TokensResponseSchema } from \"../types/login.js\"\n\nexport class AuthService {\n @SentryTraced()\n public async getAuthUrlFromServer(env: TargetEnv, codeChallenge: string) {\n const {\n result: { authorizeUrl, readKey },\n } = await fetch(authUrlForEnvironment(env), {\n body: JSON.stringify({\n codeChallenge,\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n })\n .then(res => res.json())\n .then(async data => AuthResponseSchema.parse(data))\n return { authorizeUrl, readKey }\n }\n\n @SentryTraced()\n public async getTokensFromServer(env: TargetEnv, verifier: string, readKey: string): Promise<Tokens | undefined> {\n let success = false\n let tokens: Tokens | undefined\n let repeatCounts = 300 // five minutes\n while (!success && repeatCounts-- > 0) {\n success = await fetch(`${authUrlForEnvironment(env)}?read_key=${readKey}&code_verifier=${verifier}`)\n .then(response => {\n if (!response.ok) {\n throw new Error(\"Network response was not ok\")\n }\n\n return response.json()\n })\n .then(async data => {\n const body = TokensResponseSchema.parse(data)\n if (body.result.status === \"Success\") {\n tokens = body.result.tokens\n return true\n }\n\n await this.sleep()\n\n return false\n })\n }\n\n return tokens\n }\n\n @SentryTraced()\n public async refreshToken(env: TargetEnv, refreshToken?: string): Promise<Tokens | undefined> {\n if (!refreshToken) return undefined\n\n const authUrl = `${authUrlForEnvironment(env)}/token`\n const response = await fetch(authUrl, {\n body: JSON.stringify({\n // eslint-disable-next-line camelcase\n grant_type: \"refresh_token\",\n // eslint-disable-next-line camelcase\n refresh_token: refreshToken,\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n })\n\n if (!response.ok) {\n return undefined\n }\n\n const {\n result: { tokens },\n } = RefreshTokenResponseSchema.parse(await response.json())\n return { ...tokens, refreshToken }\n }\n\n @SentryTraced()\n public sleep(ms: number = 5000) {\n return new Promise(resolve => {\n setTimeout(resolve, ms)\n })\n }\n}\n"]}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { Command } from "@oclif/core";
|
|
2
|
-
import { Input, ParserOutput } from "@oclif/core/interfaces";
|
|
3
|
-
import { ArgOutput, FlagOutput } from "@oclif/core/lib/interfaces/parser.js";
|
|
4
2
|
import { SupernovaApiClient } from "@supernova-studio/client";
|
|
5
3
|
import { z } from "zod";
|
|
6
4
|
import { ConfigService } from "../utils/config.service.js";
|
|
7
5
|
import { TargetEnv } from "./environment.js";
|
|
8
6
|
export declare abstract class BaseCommand<T extends object> extends Command {
|
|
7
|
+
protected env: TargetEnv;
|
|
9
8
|
protected configService: ConfigService;
|
|
10
|
-
private
|
|
9
|
+
private _apiClient;
|
|
11
10
|
abstract get commandId(): string;
|
|
12
11
|
abstract get configSchema(): z.ZodType<T>;
|
|
13
|
-
protected apiClient(
|
|
14
|
-
protected promptBrandId(
|
|
15
|
-
protected promptDesignSystemId(
|
|
16
|
-
protected getVersionId(
|
|
17
|
-
protected getWorkspaceId(
|
|
18
|
-
parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A>>;
|
|
19
|
-
protected saveConfig(config: Record<string, unknown>): void;
|
|
12
|
+
protected apiClient(): Promise<SupernovaApiClient>;
|
|
13
|
+
protected promptBrandId(designSystemId: string, versionId?: string): Promise<string>;
|
|
14
|
+
protected promptDesignSystemId(): Promise<string>;
|
|
15
|
+
protected getVersionId(designSystemId: string, versionId?: string): Promise<string>;
|
|
16
|
+
protected getWorkspaceId(workspaceId?: string): Promise<string>;
|
|
20
17
|
private prompt;
|
|
21
|
-
private removeUndefinedValues;
|
|
22
18
|
}
|
|
23
19
|
//# sourceMappingURL=base-command.d.ts.map
|
|
@@ -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,
|
|
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,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAgB,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAK1D,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,OAAO;IACjE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAiB;IACzC,SAAS,CAAC,aAAa,gBAA8B;IACrD,OAAO,CAAC,UAAU,CAAgC;IAElD,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAA;IAChC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;cAEzB,SAAS;cAQT,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAY1E,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;cAwCvC,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAqBzE,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAyBvD,MAAM;CAYrB"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { Command } from "@oclif/core";
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
|
+
import { getApiClient } from "../utils/api-client.js";
|
|
3
4
|
import { ConfigService } from "../utils/config.service.js";
|
|
4
|
-
import {
|
|
5
|
+
import { getTargetEnv } from "./environment.js";
|
|
5
6
|
const hasAccess = (role) => role && ["Admin", "Contributor", "Creator", "Owner"].includes(role);
|
|
6
7
|
export class BaseCommand extends Command {
|
|
8
|
+
env = getTargetEnv();
|
|
7
9
|
configService = ConfigService.getInstance();
|
|
8
|
-
|
|
9
|
-
async apiClient(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return client;
|
|
10
|
+
_apiClient;
|
|
11
|
+
async apiClient() {
|
|
12
|
+
if (this._apiClient)
|
|
13
|
+
return this._apiClient;
|
|
14
|
+
const apiClient = await getApiClient(this.env);
|
|
15
|
+
this._apiClient = apiClient;
|
|
16
|
+
return apiClient;
|
|
16
17
|
}
|
|
17
|
-
async promptBrandId(
|
|
18
|
-
const client = await this.apiClient(
|
|
18
|
+
async promptBrandId(designSystemId, versionId) {
|
|
19
|
+
const client = await this.apiClient();
|
|
19
20
|
const brandsEndpoint = client.designSystems.versions.brands;
|
|
20
21
|
const { brands } = await brandsEndpoint.list(designSystemId, versionId ?? "head");
|
|
21
22
|
const options = brands.map(b => ({ name: b.meta.name, value: b.persistentId }));
|
|
@@ -23,8 +24,8 @@ export class BaseCommand extends Command {
|
|
|
23
24
|
return options[0].value;
|
|
24
25
|
return this.prompt("Select a brand:", options);
|
|
25
26
|
}
|
|
26
|
-
async promptDesignSystemId(
|
|
27
|
-
const { designSystems: client } = await this.apiClient(
|
|
27
|
+
async promptDesignSystemId() {
|
|
28
|
+
const { designSystems: client } = await this.apiClient();
|
|
28
29
|
const { designSystems, workspaces } = await client.listUserDesignSystems();
|
|
29
30
|
const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]));
|
|
30
31
|
const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {
|
|
@@ -54,10 +55,10 @@ export class BaseCommand extends Command {
|
|
|
54
55
|
value: id,
|
|
55
56
|
})));
|
|
56
57
|
}
|
|
57
|
-
async getVersionId(
|
|
58
|
+
async getVersionId(designSystemId, versionId) {
|
|
58
59
|
if (versionId)
|
|
59
60
|
return versionId;
|
|
60
|
-
const { versions } = (await this.apiClient(
|
|
61
|
+
const { versions } = (await this.apiClient()).designSystems;
|
|
61
62
|
const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({
|
|
62
63
|
id,
|
|
63
64
|
name,
|
|
@@ -70,10 +71,10 @@ export class BaseCommand extends Command {
|
|
|
70
71
|
value: wrk.id,
|
|
71
72
|
})));
|
|
72
73
|
}
|
|
73
|
-
async getWorkspaceId(
|
|
74
|
+
async getWorkspaceId(workspaceId) {
|
|
74
75
|
if (workspaceId)
|
|
75
76
|
return workspaceId;
|
|
76
|
-
const { workspaces } = await this.apiClient(
|
|
77
|
+
const { workspaces } = await this.apiClient();
|
|
77
78
|
const wrks = (await workspaces.list()).membership.map(({ workspace: { id, profile: { name }, }, }) => ({ id, name }));
|
|
78
79
|
if (wrks.length === 1) {
|
|
79
80
|
return wrks[0].id;
|
|
@@ -83,15 +84,6 @@ export class BaseCommand extends Command {
|
|
|
83
84
|
value: wrk.id,
|
|
84
85
|
})));
|
|
85
86
|
}
|
|
86
|
-
async parse(options, argv) {
|
|
87
|
-
const parsed = await super.parse(options, argv);
|
|
88
|
-
const fileConfig = this.configService.getCommandConfig(this.commandId, this.configSchema);
|
|
89
|
-
parsed.flags = { ...fileConfig, ...parsed.flags };
|
|
90
|
-
return parsed;
|
|
91
|
-
}
|
|
92
|
-
saveConfig(config) {
|
|
93
|
-
this.configService.updateCommandConfig(this.commandId, this.removeUndefinedValues(config));
|
|
94
|
-
}
|
|
95
87
|
async prompt(message, choices) {
|
|
96
88
|
const choice = await inquirer.prompt([
|
|
97
89
|
{
|
|
@@ -103,12 +95,5 @@ export class BaseCommand extends Command {
|
|
|
103
95
|
]);
|
|
104
96
|
return choice.selected;
|
|
105
97
|
}
|
|
106
|
-
removeUndefinedValues(obj) {
|
|
107
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
108
|
-
if (value !== undefined)
|
|
109
|
-
acc[key] = value;
|
|
110
|
-
return acc;
|
|
111
|
-
}, {});
|
|
112
|
-
}
|
|
113
98
|
}
|
|
114
99
|
//# sourceMappingURL=base-command.js.map
|
|
@@ -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,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M,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"]}
|
|
1
|
+
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAa,MAAM,kBAAkB,CAAA;AAE1D,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,GAAG,GAAc,YAAY,EAAE,CAAA;IAC/B,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA;IAC7C,UAAU,CAAgC;IAKxC,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC,UAAU,CAAA;QAE3C,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,OAAO,SAAS,CAAA;IAClB,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,cAAsB,EAAE,SAAkB;QACtE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QACrC,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAA;QAE3D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,c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,IAAI,CAAC,MAAM,CAChB,qBAAqB,EACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACf,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,EAAE;SACd,CAAC,CAAC,CACJ,CAAA;IACH,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;CACF","sourcesContent":["import { Command } from \"@oclif/core\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { getApiClient } from \"../utils/api-client.js\"\nimport { ConfigService } from \"../utils/config.service.js\"\nimport { getTargetEnv, 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 env: TargetEnv = getTargetEnv()\n protected configService = ConfigService.getInstance()\n private _apiClient: SupernovaApiClient | undefined\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient() {\n if (this._apiClient) return this._apiClient\n\n const apiClient = await getApiClient(this.env)\n this._apiClient = apiClient\n return apiClient\n }\n\n protected async promptBrandId(designSystemId: string, versionId?: string): Promise<string> {\n const client = await this.apiClient()\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(): Promise<string> {\n const { designSystems: client } = await this.apiClient()\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(designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient()).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(workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient()\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 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"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SupernovaConfigStorybook: z.ZodObject<{
|
|
3
|
+
designSystemId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
4
|
+
sourceId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
5
|
+
brandId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
6
|
+
name: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
7
|
+
from: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
designSystemId?: string | undefined;
|
|
10
|
+
sourceId?: string | undefined;
|
|
11
|
+
brandId?: string | undefined;
|
|
12
|
+
name?: string | undefined;
|
|
13
|
+
from?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
designSystemId?: unknown;
|
|
16
|
+
sourceId?: unknown;
|
|
17
|
+
brandId?: unknown;
|
|
18
|
+
name?: unknown;
|
|
19
|
+
from?: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
export declare const SupernovaConfig: z.ZodCatch<z.ZodObject<{
|
|
22
|
+
storybook: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
23
|
+
designSystemId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
24
|
+
sourceId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
25
|
+
brandId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
26
|
+
name: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
27
|
+
from: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
designSystemId?: string | undefined;
|
|
30
|
+
sourceId?: string | undefined;
|
|
31
|
+
brandId?: string | undefined;
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
from?: string | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
designSystemId?: unknown;
|
|
36
|
+
sourceId?: unknown;
|
|
37
|
+
brandId?: unknown;
|
|
38
|
+
name?: unknown;
|
|
39
|
+
from?: unknown;
|
|
40
|
+
}>>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
storybook?: {
|
|
43
|
+
designSystemId?: string | undefined;
|
|
44
|
+
sourceId?: string | undefined;
|
|
45
|
+
brandId?: string | undefined;
|
|
46
|
+
name?: string | undefined;
|
|
47
|
+
from?: string | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
storybook?: unknown;
|
|
51
|
+
}>>;
|
|
52
|
+
export type SupernovaConfigStorybook = z.infer<typeof SupernovaConfigStorybook>;
|
|
53
|
+
export type SupernovaConfig = z.infer<typeof SupernovaConfig>;
|
|
54
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;EAMnC,CAAA;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIhB,CAAA;AAEZ,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAC/E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const safeString = z.string().optional().catch(undefined);
|
|
3
|
+
export const SupernovaConfigStorybook = z.object({
|
|
4
|
+
designSystemId: safeString,
|
|
5
|
+
sourceId: safeString,
|
|
6
|
+
brandId: safeString,
|
|
7
|
+
name: safeString,
|
|
8
|
+
from: safeString,
|
|
9
|
+
});
|
|
10
|
+
export const SupernovaConfig = z
|
|
11
|
+
.object({
|
|
12
|
+
storybook: SupernovaConfigStorybook.optional().catch(undefined),
|
|
13
|
+
})
|
|
14
|
+
.catch({});
|
|
15
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AAEzD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,cAAc,EAAE,UAAU;IAC1B,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;CACjB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,SAAS,EAAE,wBAAwB,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;CAChE,CAAC;KACD,KAAK,CAAC,EAAE,CAAC,CAAA","sourcesContent":["import { z } from \"zod\"\n\nconst safeString = z.string().optional().catch(undefined)\n\nexport const SupernovaConfigStorybook = z.object({\n designSystemId: safeString,\n sourceId: safeString,\n brandId: safeString,\n name: safeString,\n from: safeString,\n})\n\nexport const SupernovaConfig = z\n .object({\n storybook: SupernovaConfigStorybook.optional().catch(undefined),\n })\n .catch({})\n\nexport type SupernovaConfigStorybook = z.infer<typeof SupernovaConfigStorybook>\nexport type SupernovaConfig = z.infer<typeof SupernovaConfig>\n"]}
|
package/dist/utils/common.js
CHANGED
package/dist/utils/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["export async function sleep(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms)\n })\n}\n"]}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type Config = {
|
|
3
|
-
commands: Record<string, object>;
|
|
4
|
-
global: Record<string, object>;
|
|
5
|
-
};
|
|
1
|
+
import { SupernovaConfig } from "../types/config.js";
|
|
6
2
|
export declare class ConfigService {
|
|
7
3
|
private static instance;
|
|
8
4
|
private configCache;
|
|
9
5
|
private readonly configPath;
|
|
10
6
|
private constructor();
|
|
11
7
|
static getInstance(): ConfigService;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
updateCommandConfig(commandId: string, config: Record<string, unknown>): void;
|
|
8
|
+
get(): SupernovaConfig | null;
|
|
9
|
+
update(configUpdate: Partial<SupernovaConfig>): void;
|
|
10
|
+
private write;
|
|
16
11
|
}
|
|
17
12
|
//# sourceMappingURL=config.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../src/utils/config.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../src/utils/config.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAIpD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IAEnC,OAAO;WAIO,WAAW,IAAI,aAAa;IAQnC,GAAG,IAAI,eAAe,GAAG,IAAI;IAmB7B,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAS3D,OAAO,CAAC,KAAK;CAQd"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
3
|
+
import { SupernovaConfig } from "../types/config.js";
|
|
4
|
+
const configFileName = "supernova.json";
|
|
5
5
|
export class ConfigService {
|
|
6
6
|
static instance;
|
|
7
7
|
configCache = null;
|
|
8
8
|
configPath;
|
|
9
9
|
constructor() {
|
|
10
|
-
|
|
11
|
-
this.configPath = possiblePaths.find(path => fs.existsSync(path)) || possiblePaths[0];
|
|
10
|
+
this.configPath = join(process.cwd(), configFileName);
|
|
12
11
|
}
|
|
13
12
|
static getInstance() {
|
|
14
13
|
if (!ConfigService.instance) {
|
|
@@ -16,37 +15,32 @@ export class ConfigService {
|
|
|
16
15
|
}
|
|
17
16
|
return ConfigService.instance;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
const config = this.loadConfig();
|
|
21
|
-
const commandConfig = config.commands[commandId];
|
|
22
|
-
if (commandConfig) {
|
|
23
|
-
try {
|
|
24
|
-
return schema.parse(commandConfig);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (error instanceof z.ZodError) {
|
|
28
|
-
throw new TypeError(`Invalid configuration for command ${commandId}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {};
|
|
33
|
-
}
|
|
34
|
-
loadConfig() {
|
|
18
|
+
get() {
|
|
35
19
|
if (this.configCache)
|
|
36
20
|
return this.configCache;
|
|
21
|
+
if (!fs.existsSync(this.configPath))
|
|
22
|
+
return null;
|
|
37
23
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
const configString = fs.readFileSync(this.configPath, "utf8");
|
|
25
|
+
const configJson = JSON.parse(configString);
|
|
26
|
+
const configParseResult = SupernovaConfig.safeParse(configJson);
|
|
27
|
+
if (configParseResult.success) {
|
|
28
|
+
this.configCache = configParseResult.data;
|
|
42
29
|
}
|
|
30
|
+
return this.configCache;
|
|
43
31
|
}
|
|
44
32
|
catch (error) {
|
|
45
|
-
throw new Error(`
|
|
33
|
+
throw new Error(`Could not read ${configFileName} file: ${error.message}`);
|
|
46
34
|
}
|
|
47
|
-
return { commands: {}, global: {} };
|
|
48
35
|
}
|
|
49
|
-
|
|
36
|
+
update(configUpdate) {
|
|
37
|
+
const fullConfig = {
|
|
38
|
+
...this.get(),
|
|
39
|
+
...configUpdate,
|
|
40
|
+
};
|
|
41
|
+
this.write(fullConfig);
|
|
42
|
+
}
|
|
43
|
+
write(config) {
|
|
50
44
|
try {
|
|
51
45
|
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2));
|
|
52
46
|
this.configCache = config;
|
|
@@ -55,16 +49,5 @@ export class ConfigService {
|
|
|
55
49
|
throw new Error(`Error saving config: ${error.message}`);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
|
-
updateCommandConfig(commandId, config) {
|
|
59
|
-
const fullConfig = this.loadConfig();
|
|
60
|
-
if (!fullConfig.commands) {
|
|
61
|
-
fullConfig.commands = {};
|
|
62
|
-
}
|
|
63
|
-
fullConfig.commands[commandId] = {
|
|
64
|
-
...fullConfig.commands[commandId],
|
|
65
|
-
...config,
|
|
66
|
-
};
|
|
67
|
-
this.saveConfig(fullConfig);
|
|
68
|
-
}
|
|
69
52
|
}
|
|
70
53
|
//# sourceMappingURL=config.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.service.js","sourceRoot":"","sources":["../../src/utils/config.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.service.js","sourceRoot":"","sources":["../../src/utils/config.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAEvC,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,CAAe;IAC9B,WAAW,GAA2B,IAAI,CAAA;IACjC,UAAU,CAAQ;IAEnC;QACE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAA;IACvD,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAA;QAC9C,CAAC;QAED,OAAO,aAAa,CAAC,QAAQ,CAAA;IAC/B,CAAC;IAEM,GAAG;QACR,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAA;QAC7C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;YAAE,OAAO,IAAI,CAAA;QAEhD,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;YAC3C,MAAM,iBAAiB,GAAG,eAAe,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;YAE/D,IAAI,iBAAiB,CAAC,OAAO,EAAE,CAAC;gBAC9B,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAA;YAC3C,CAAC;YAED,OAAO,IAAI,CAAC,WAAW,CAAA;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,cAAc,UAAW,KAA6B,CAAC,OAAO,EAAE,CAAC,CAAA;QACrG,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,YAAsC;QAClD,MAAM,UAAU,GAAG;YACjB,GAAG,IAAI,CAAC,GAAG,EAAE;YACb,GAAG,YAAY;SAChB,CAAA;QAED,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,CAAC;IAEO,KAAK,CAAC,MAAuB;QACnC,IAAI,CAAC;YACH,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAClE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,wBAAyB,KAA6B,CAAC,OAAO,EAAE,CAAC,CAAA;QACnF,CAAC;IACH,CAAC;CACF","sourcesContent":["import * as fs from \"node:fs\"\nimport { join } from \"node:path\"\n\nimport { SupernovaConfig } from \"../types/config.js\"\n\nconst configFileName = \"supernova.json\"\n\nexport class ConfigService {\n private static instance: ConfigService\n private configCache: SupernovaConfig | null = null\n private readonly configPath: string\n\n private constructor() {\n this.configPath = join(process.cwd(), configFileName)\n }\n\n public static getInstance(): ConfigService {\n if (!ConfigService.instance) {\n ConfigService.instance = new ConfigService()\n }\n\n return ConfigService.instance\n }\n\n public get(): SupernovaConfig | null {\n if (this.configCache) return this.configCache\n if (!fs.existsSync(this.configPath)) return null\n\n try {\n const configString = fs.readFileSync(this.configPath, \"utf8\")\n const configJson = JSON.parse(configString)\n const configParseResult = SupernovaConfig.safeParse(configJson)\n\n if (configParseResult.success) {\n this.configCache = configParseResult.data\n }\n\n return this.configCache\n } catch (error) {\n throw new Error(`Could not read ${configFileName} file: ${(error as { message: string }).message}`)\n }\n }\n\n public update(configUpdate: Partial<SupernovaConfig>): void {\n const fullConfig = {\n ...this.get(),\n ...configUpdate,\n }\n\n this.write(fullConfig)\n }\n\n private write(config: SupernovaConfig): void {\n try {\n fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2))\n this.configCache = config\n } catch (error) {\n throw new Error(`Error saving config: ${(error as { message: string }).message}`)\n }\n }\n}\n"]}
|
package/oclif.manifest.json
CHANGED
|
@@ -288,7 +288,6 @@
|
|
|
288
288
|
"char": "f",
|
|
289
289
|
"description": "Directory with storybook static export to import.",
|
|
290
290
|
"name": "from",
|
|
291
|
-
"required": true,
|
|
292
291
|
"hasDynamicHelp": false,
|
|
293
292
|
"multiple": false,
|
|
294
293
|
"type": "option"
|
|
@@ -427,5 +426,5 @@
|
|
|
427
426
|
]
|
|
428
427
|
}
|
|
429
428
|
},
|
|
430
|
-
"version": "2.
|
|
429
|
+
"version": "2.2.1"
|
|
431
430
|
}
|