@supernovaio/cli-next 2.0.19 → 2.0.21

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.
@@ -103,7 +103,7 @@ export default class ImportStorybook extends SentryCommand {
103
103
  const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, { name });
104
104
  try {
105
105
  await this.uploadArchiveToSignedUrl({ designSystemId, name, signedUrl, storybookUploadId, zipPath });
106
- this.log("✅ Upload complete.".green);
106
+ this.log("✅ Upload complete.");
107
107
  this.log("Processing Storybook files...");
108
108
  let status;
109
109
  action.start("Deploying Storybook to private Supernova hosting service...");
@@ -122,16 +122,16 @@ export default class ImportStorybook extends SentryCommand {
122
122
  unknownStatusCount = 0;
123
123
  }
124
124
  if (unknownStatusCount >= 5) {
125
- this.error("Failed to deploy Storybook: Internal server error".red);
125
+ this.error("Failed to deploy Storybook: Internal server error");
126
126
  }
127
127
  } while (status.status !== "Completed" || (status.timestamp && status.timestamp < startTime));
128
128
  if (status.status === "Failed") {
129
- action.stop("\nFailed to deploy Storybook: Internal server error".red);
129
+ action.stop("\nFailed to deploy Storybook: Internal server error");
130
130
  }
131
131
  else {
132
132
  const { accessToken } = await storybookHosting.getAccessToken(designSystemId, name);
133
133
  const storybookUrl = storybookEndpoint(env, designSystemId, name, accessToken);
134
- action.stop("\n✅ Private Storybook deployed successfully!".green);
134
+ action.stop("\n✅ Private Storybook deployed successfully!");
135
135
  try {
136
136
  this.log(`Connecting Storybook as a data source in Supernova...`);
137
137
  let storiesCount = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"import-storybook.js","sourceRoot":"","sources":["../../src/commands/import-storybook.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,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ourcesContent":["import { Flags } from \"@oclif/core\"\nimport { action } from \"@oclif/core/ux\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport slugify from \"@sindresorhus/slugify\"\nimport { DTODataSourceStorybook } from \"@supernova-studio/client\"\nimport AdmZip from \"adm-zip\"\nimport axios from \"axios\"\nimport cliProgress from \"cli-progress\"\nimport inquirer from \"inquirer\"\nimport * as fs from \"node:fs\"\nimport path from \"node:path\"\nimport { z, ZodType } from \"zod\"\n\nimport { commonFlags, getTargetEnv, SentryCommand, storybookUrlForEnvironment, TargetEnv } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.js\"\nimport { getApiClient } from \"../utils/index.js\"\n\n// Maximum allowed size for storybook zip file (500MB)\nconst MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024\n\nconst bytesToKB = (bytes: number) => (bytes / 1024).toFixed(2)\nconst bytesToMB = (bytes: number) => (bytes / (1024 * 1024)).toFixed(2)\n\nconst ImportStorybookConfigSchema = z\n .object({\n brandId: z.string().optional(),\n designSystemId: z.string().optional(),\n dir: z.string().optional(),\n name: z.string().optional(),\n sourceId: z.string().optional(),\n versionId: z.string().optional(),\n })\n .transform(data => ({\n ...data,\n }))\n\ntype ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>\n\nconst storybookEndpoint = (\n environment: TargetEnv,\n designSystemId: string,\n name: string,\n accessToken: string,\n): string => {\n const host = storybookUrlForEnvironment(environment)\n const encodedAccessToken = encodeURIComponent(accessToken)\n return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?storybook_jwt=${encodedAccessToken}`\n}\n\nexport default class ImportStorybook extends SentryCommand<ImportStorybookConfig> {\n static override args = {}\n static override description = \"Import storybook static export to Supernova\"\n static override examples = [\n \"<%= config.bin %> <%= command.id %> import-storybook --designSystemId=123 --dir ./storybook-static.zip\",\n ]\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 dir: Flags.string({\n char: \"d\",\n default: \"./storybook-static\",\n description: \"Directory with storybook static export to import.\",\n }),\n name: Flags.string({ char: \"a\", description: \"Import storybooks with name of\" }),\n sourceId: Flags.string({ char: \"s\", description: \"Import storybooks to source of\" }),\n }\n\n get commandId(): string {\n return ImportStorybook.id\n }\n\n get configSchema(): ZodType<ImportStorybookConfig> {\n return ImportStorybookConfigSchema\n }\n\n @SentryTraced()\n // eslint-disable-next-line complexity\n public async run(): Promise<void> {\n const startTime = Date.now()\n const { flags } = await this.parse(ImportStorybook)\n\n const env = getTargetEnv()\n const { brandId: bId, designSystemId: dsId, dir, name: nameInput, sourceId } = flags\n const name = slugify(await this.askName(nameInput), { lowercase: true })\n let designSystemId = dsId\n let brandId = bId\n\n const apiClient = await getApiClient(env)\n const { designSystems } = apiClient\n const { sources, storybookHosting } = designSystems\n\n if (!designSystemId) {\n designSystemId = await this.getDesignSystemId(env, designSystemId)\n\n if (!designSystemId) {\n this.error(\"Design system ID is required\")\n }\n\n this.saveConfig({ designSystemId })\n }\n\n if (!brandId) {\n brandId = await this.getBrandId(env, designSystemId, \"head\")\n\n if (!brandId) {\n this.error(\"Brand ID is required\")\n }\n\n this.saveConfig({ brandId })\n }\n\n const directoryValidation = this.validateStorybookDirectory(dir)\n if (!directoryValidation.isValid) {\n this.error(directoryValidation.error!)\n }\n\n this.log(`Preparing Storybook files from ${dir}...`)\n const { sizeBytes, zipPath } = this.createZipFromDirectory(dir)\n\n const sizeValidation = this.validateZipSize(zipPath, sizeBytes)\n if (!sizeValidation.isValid) {\n this.error(sizeValidation.error!)\n }\n\n const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, { name })\n\n try {\n await this.uploadArchiveToSignedUrl({ designSystemId, name, signedUrl, storybookUploadId, zipPath })\n this.log(\"✅ Upload complete.\".green)\n this.log(\"Processing Storybook files...\")\n\n let status\n action.start(\"Deploying Storybook to private Supernova hosting service...\")\n\n let unknownStatusCount = 0\n try {\n do {\n // eslint-disable-next-line no-await-in-loop\n await sleep(1000)\n\n // eslint-disable-next-line no-await-in-loop\n status = await storybookHosting.getUploadStatus(designSystemId, storybookUploadId)\n\n if (status.status === \"Failed\") {\n break\n }\n\n if (status.status === \"Unknown\") {\n unknownStatusCount++\n } else {\n unknownStatusCount = 0\n }\n\n if (unknownStatusCount >= 5) {\n this.error(\"Failed to deploy Storybook: Internal server error\".red)\n }\n } while (status.status !== \"Completed\" || (status.timestamp && status.timestamp < startTime))\n\n if (status.status === \"Failed\") {\n action.stop(\"\\nFailed to deploy Storybook: Internal server error\".red)\n } else {\n const { accessToken } = await storybookHosting.getAccessToken(designSystemId, name)\n const storybookUrl = storybookEndpoint(env, designSystemId, name, accessToken)\n\n action.stop(\"\\n✅ Private Storybook deployed successfully!\".green)\n\n try {\n this.log(`Connecting Storybook as a data source in Supernova...`)\n let storiesCount = 0\n // eslint-disable-next-line max-depth\n if (sourceId) {\n const { storiesCount: updatedStoriesCount } = await sources.updateStorybookImport(\n designSystemId,\n \"head\",\n {\n payload: this.getIndexJson(dir),\n sourceId,\n },\n )\n storiesCount = updatedStoriesCount\n } else {\n const { source } = await sources.create(designSystemId, {\n brandPersistentId: brandId,\n description: \"CLI\",\n indexUrl: storybookUrl,\n payload: this.getIndexJson(dir),\n type: \"Storybook\",\n userUrl: storybookUrl,\n })\n storiesCount = (source as unknown as DTODataSourceStorybook).storybook.storiesCount\n this.saveConfig({ sourceId: source.id })\n }\n\n this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green)\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`\n .red,\n )\n }\n }\n } catch (error) {\n action.stop(`\\nFailed to deploy Storybook: ${error instanceof Error ? error.message : String(error)}`.red)\n }\n } catch (error) {\n this.error(`Failed to upload Storybook files: ${error instanceof Error ? error.message : String(error)}`)\n }\n }\n\n private async askName(inputedName?: string) {\n if (inputedName) return inputedName\n const choice = await inquirer.prompt([\n {\n message: \"What's storybook name\",\n name: \"name\",\n type: \"input\",\n },\n ])\n if (choice.name === \"exit\") {\n this.log(\"Exiting...\")\n this.exit(0)\n }\n\n const name = choice.name as string\n this.saveConfig({ name })\n return name\n }\n\n /**\n * Creates a zip archive from a directory\n * @param directoryPath Path to the directory to zip\n * @returns Path to the created zip file and its size\n */\n private createZipFromDirectory(directoryPath: string): { sizeBytes: number; zipPath: string } {\n const zip = new AdmZip()\n\n let totalFiles = 0\n let processedFiles = 0\n\n const countFiles = (currentPath: string) => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n\n if (stat.isDirectory()) {\n countFiles(filePath)\n } else {\n totalFiles++\n }\n }\n }\n\n countFiles(directoryPath)\n\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Creating zip [{bar}] {percentage}% | {value}/{total} files | Current: {filename}\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n progressBar.start(totalFiles, 0, {\n filename: \"Initializing...\",\n })\n\n const addFilesToZip = (currentPath: string, relativePath = \"\") => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n const displayPath = path.join(relativePath, file)\n\n if (stat.isDirectory()) {\n addFilesToZip(filePath, displayPath)\n } else {\n // Update the progress bar with the current file\n processedFiles++\n progressBar.update(processedFiles, {\n filename:\n displayPath.length > 40 ? \"...\" + displayPath.slice(Math.max(0, displayPath.length - 37)) : displayPath,\n })\n\n zip.addLocalFile(filePath, relativePath)\n }\n }\n }\n\n try {\n addFilesToZip(directoryPath)\n } finally {\n progressBar.stop()\n }\n\n const zipPath = `${directoryPath}.zip`\n zip.writeZip(zipPath)\n\n const sizeBytes = fs.statSync(zipPath).size\n\n return { sizeBytes, zipPath }\n }\n\n private getIndexJson(directoryPath: string) {\n const indexJsonPath = path.join(directoryPath, \"index.json\")\n if (!fs.existsSync(indexJsonPath)) {\n return \"{}\"\n }\n\n return JSON.parse(fs.readFileSync(indexJsonPath, \"utf8\"))\n }\n\n /**\n * Uploads the zip archive to the provided signed URL\n */\n private async uploadArchiveToSignedUrl(input: {\n designSystemId: string\n name?: string\n signedUrl: string\n storybookUploadId: string\n zipPath: string\n }): Promise<void> {\n const { designSystemId, name, signedUrl, storybookUploadId, zipPath } = input\n this.log(`Securely uploading ${zipPath} to Supernova...`)\n\n // Create a new progress bar\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Uploading |{bar}| {percentage}% || {value}/{total} kB\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n const fileStream = fs.createReadStream(zipPath)\n const stats = fs.statSync(zipPath)\n const fileSize = stats.size\n const fileSizeKB = Number.parseFloat(bytesToKB(fileSize))\n\n // Start the progress bar\n progressBar.start(fileSizeKB, 0)\n\n try {\n await axios.put(signedUrl, fileStream, {\n headers: {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/zip\",\n designSystemId,\n storybookUploadId,\n ...(name && { name }),\n },\n onUploadProgress(progressEvent) {\n const loaded = progressEvent.loaded || 0\n const loadedKB = Number.parseFloat(bytesToKB(loaded))\n progressBar.update(loadedKB)\n },\n })\n\n // Complete the progress bar\n progressBar.update(fileSizeKB)\n progressBar.stop()\n } catch (error) {\n // Make sure to stop the progress bar if there's an error\n progressBar.stop()\n throw error\n }\n }\n\n /**\n * Validates if a directory is a valid storybook static export\n * @param directoryPath Path to the storybook directory\n * @returns An object indicating if the directory is valid and an error message if not\n */\n private validateStorybookDirectory(directoryPath: string): { error?: string; isValid: boolean } {\n if (!fs.existsSync(directoryPath)) {\n return { error: `Directory not found: ${directoryPath}`, isValid: false }\n }\n\n if (!fs.statSync(directoryPath).isDirectory()) {\n return { error: `Not a directory: ${directoryPath}`, isValid: false }\n }\n\n // Check for essential storybook files\n const requiredFiles = [\"index.html\", \"iframe.html\"]\n const missingFiles = requiredFiles.filter(file => !fs.existsSync(path.join(directoryPath, file)))\n\n if (missingFiles.length > 0) {\n return {\n error: `Directory does not appear to be a valid Storybook export. Missing files: ${missingFiles.join(\", \")}`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n\n /**\n * Validates if a zip file size is within the allowed limits\n * @param zipPath Path to the zip file\n * @param sizeBytes Size of the zip file in bytes\n * @returns An object indicating if the zip is valid and an error message if not\n */\n private validateZipSize(zipPath: string, sizeBytes: number): { error?: string; isValid: boolean } {\n if (sizeBytes > MAX_ZIP_SIZE_BYTES) {\n // Delete the zip file if it's too large\n try {\n fs.unlinkSync(zipPath)\n } catch {\n // Ignore errors during cleanup\n }\n\n return {\n error: `Zip file is too large: ${bytesToMB(sizeBytes)}MB. Maximum allowed size is ${bytesToMB(MAX_ZIP_SIZE_BYTES)}MB`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n}\n"]}
1
+ {"version":3,"file":"import-storybook.js","sourceRoot":"","sources":["../../src/commands/import-storybook.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,OAAO,MAAM,uBAAuB,CAAA;AAE3C,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAA;AAEhC,OAA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AAa,CAAC,CAAA;QACnD,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjG,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO;gBACL,KAAK,EAAE,4EAA4E,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAC5G,OAAO,EAAE,KAAK;aACf,CAAA;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;IAQO,eAAe,CAAC,OAAe,EAAE,SAAiB;QACxD,IAAI,SAAS,GAAG,kBAAkB,EAAE,CAAC;YAEnC,IAAI,CAAC;gBACH,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;YACxB,CAAC;YAAC,MAAM,CAAC;YAET,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,0BAA0B,SAAS,CAAC,SAAS,CAAC,+BAA+B,SAAS,CAAC,kBAAkB,CAAC,IAAI;gBACrH,OAAO,EAAE,KAAK;aACf,CAAA;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;;AA5VY;IAFZ,YAAY,EAAE;;;;0CAqId","sourcesContent":["import { Flags } from \"@oclif/core\"\nimport { action } from \"@oclif/core/ux\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport slugify from \"@sindresorhus/slugify\"\nimport { DTODataSourceStorybook } from \"@supernova-studio/client\"\nimport AdmZip from \"adm-zip\"\nimport axios from \"axios\"\nimport cliProgress from \"cli-progress\"\nimport inquirer from \"inquirer\"\nimport * as fs from \"node:fs\"\nimport path from \"node:path\"\nimport { z, ZodType } from \"zod\"\n\nimport { commonFlags, getTargetEnv, SentryCommand, storybookUrlForEnvironment, TargetEnv } from \"../types/index.js\"\nimport { sleep } from \"../utils/common.js\"\nimport { getApiClient } from \"../utils/index.js\"\n\n// Maximum allowed size for storybook zip file (500MB)\nconst MAX_ZIP_SIZE_BYTES = 500 * 1024 * 1024\n\nconst bytesToKB = (bytes: number) => (bytes / 1024).toFixed(2)\nconst bytesToMB = (bytes: number) => (bytes / (1024 * 1024)).toFixed(2)\n\nconst ImportStorybookConfigSchema = z\n .object({\n brandId: z.string().optional(),\n designSystemId: z.string().optional(),\n dir: z.string().optional(),\n name: z.string().optional(),\n sourceId: z.string().optional(),\n versionId: z.string().optional(),\n })\n .transform(data => ({\n ...data,\n }))\n\ntype ImportStorybookConfig = z.infer<typeof ImportStorybookConfigSchema>\n\nconst storybookEndpoint = (\n environment: TargetEnv,\n designSystemId: string,\n name: string,\n accessToken: string,\n): string => {\n const host = storybookUrlForEnvironment(environment)\n const encodedAccessToken = encodeURIComponent(accessToken)\n return `${host}/design-systems/${designSystemId}/alias/${name}/index.html?storybook_jwt=${encodedAccessToken}`\n}\n\nexport default class ImportStorybook extends SentryCommand<ImportStorybookConfig> {\n static override args = {}\n static override description = \"Import storybook static export to Supernova\"\n static override examples = [\n \"<%= config.bin %> <%= command.id %> import-storybook --designSystemId=123 --dir ./storybook-static.zip\",\n ]\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 dir: Flags.string({\n char: \"d\",\n default: \"./storybook-static\",\n description: \"Directory with storybook static export to import.\",\n }),\n name: Flags.string({ char: \"a\", description: \"Import storybooks with name of\" }),\n sourceId: Flags.string({ char: \"s\", description: \"Import storybooks to source of\" }),\n }\n\n get commandId(): string {\n return ImportStorybook.id\n }\n\n get configSchema(): ZodType<ImportStorybookConfig> {\n return ImportStorybookConfigSchema\n }\n\n @SentryTraced()\n // eslint-disable-next-line complexity\n public async run(): Promise<void> {\n const startTime = Date.now()\n const { flags } = await this.parse(ImportStorybook)\n\n const env = getTargetEnv()\n const { brandId: bId, designSystemId: dsId, dir, name: nameInput, sourceId } = flags\n const name = slugify(await this.askName(nameInput), { lowercase: true })\n let designSystemId = dsId\n let brandId = bId\n\n const apiClient = await getApiClient(env)\n const { designSystems } = apiClient\n const { sources, storybookHosting } = designSystems\n\n if (!designSystemId) {\n designSystemId = await this.getDesignSystemId(env, designSystemId)\n\n if (!designSystemId) {\n this.error(\"Design system ID is required\")\n }\n\n this.saveConfig({ designSystemId })\n }\n\n if (!brandId) {\n brandId = await this.getBrandId(env, designSystemId, \"head\")\n\n if (!brandId) {\n this.error(\"Brand ID is required\")\n }\n\n this.saveConfig({ brandId })\n }\n\n const directoryValidation = this.validateStorybookDirectory(dir)\n if (!directoryValidation.isValid) {\n this.error(directoryValidation.error!)\n }\n\n this.log(`Preparing Storybook files from ${dir}...`)\n const { sizeBytes, zipPath } = this.createZipFromDirectory(dir)\n\n const sizeValidation = this.validateZipSize(zipPath, sizeBytes)\n if (!sizeValidation.isValid) {\n this.error(sizeValidation.error!)\n }\n\n const { signedUrl, storybookUploadId } = await storybookHosting.getSignedUploadUrl(designSystemId, { name })\n\n try {\n await this.uploadArchiveToSignedUrl({ designSystemId, name, signedUrl, storybookUploadId, zipPath })\n this.log(\"✅ Upload complete.\")\n this.log(\"Processing Storybook files...\")\n\n let status\n action.start(\"Deploying Storybook to private Supernova hosting service...\")\n\n let unknownStatusCount = 0\n try {\n do {\n // eslint-disable-next-line no-await-in-loop\n await sleep(1000)\n\n // eslint-disable-next-line no-await-in-loop\n status = await storybookHosting.getUploadStatus(designSystemId, storybookUploadId)\n\n if (status.status === \"Failed\") {\n break\n }\n\n if (status.status === \"Unknown\") {\n unknownStatusCount++\n } else {\n unknownStatusCount = 0\n }\n\n if (unknownStatusCount >= 5) {\n this.error(\"Failed to deploy Storybook: Internal server error\")\n }\n } while (status.status !== \"Completed\" || (status.timestamp && status.timestamp < startTime))\n\n if (status.status === \"Failed\") {\n action.stop(\"\\nFailed to deploy Storybook: Internal server error\")\n } else {\n const { accessToken } = await storybookHosting.getAccessToken(designSystemId, name)\n const storybookUrl = storybookEndpoint(env, designSystemId, name, accessToken)\n\n action.stop(\"\\n✅ Private Storybook deployed successfully!\")\n\n try {\n this.log(`Connecting Storybook as a data source in Supernova...`)\n let storiesCount = 0\n // eslint-disable-next-line max-depth\n if (sourceId) {\n const { storiesCount: updatedStoriesCount } = await sources.updateStorybookImport(\n designSystemId,\n \"head\",\n {\n payload: this.getIndexJson(dir),\n sourceId,\n },\n )\n storiesCount = updatedStoriesCount\n } else {\n const { source } = await sources.create(designSystemId, {\n brandPersistentId: brandId,\n description: \"CLI\",\n indexUrl: storybookUrl,\n payload: this.getIndexJson(dir),\n type: \"Storybook\",\n userUrl: storybookUrl,\n })\n storiesCount = (source as unknown as DTODataSourceStorybook).storybook.storiesCount\n this.saveConfig({ sourceId: source.id })\n }\n\n this.log(`✅ Imported ${storiesCount} component stories into Supernova!`.green)\n this.log(`🔒 Access your Storybook at: ${storybookUrl}`.green)\n } catch (error) {\n this.error(\n `Failed to connect Storybook as data source: ${error instanceof Error ? error.message : String(error)}`\n .red,\n )\n }\n }\n } catch (error) {\n action.stop(`\\nFailed to deploy Storybook: ${error instanceof Error ? error.message : String(error)}`.red)\n }\n } catch (error) {\n this.error(`Failed to upload Storybook files: ${error instanceof Error ? error.message : String(error)}`)\n }\n }\n\n private async askName(inputedName?: string) {\n if (inputedName) return inputedName\n const choice = await inquirer.prompt([\n {\n message: \"What's storybook name\",\n name: \"name\",\n type: \"input\",\n },\n ])\n if (choice.name === \"exit\") {\n this.log(\"Exiting...\")\n this.exit(0)\n }\n\n const name = choice.name as string\n this.saveConfig({ name })\n return name\n }\n\n /**\n * Creates a zip archive from a directory\n * @param directoryPath Path to the directory to zip\n * @returns Path to the created zip file and its size\n */\n private createZipFromDirectory(directoryPath: string): { sizeBytes: number; zipPath: string } {\n const zip = new AdmZip()\n\n let totalFiles = 0\n let processedFiles = 0\n\n const countFiles = (currentPath: string) => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n\n if (stat.isDirectory()) {\n countFiles(filePath)\n } else {\n totalFiles++\n }\n }\n }\n\n countFiles(directoryPath)\n\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Creating zip [{bar}] {percentage}% | {value}/{total} files | Current: {filename}\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n progressBar.start(totalFiles, 0, {\n filename: \"Initializing...\",\n })\n\n const addFilesToZip = (currentPath: string, relativePath = \"\") => {\n const files = fs.readdirSync(currentPath)\n\n for (const file of files) {\n const filePath = path.join(currentPath, file)\n const stat = fs.statSync(filePath)\n const displayPath = path.join(relativePath, file)\n\n if (stat.isDirectory()) {\n addFilesToZip(filePath, displayPath)\n } else {\n // Update the progress bar with the current file\n processedFiles++\n progressBar.update(processedFiles, {\n filename:\n displayPath.length > 40 ? \"...\" + displayPath.slice(Math.max(0, displayPath.length - 37)) : displayPath,\n })\n\n zip.addLocalFile(filePath, relativePath)\n }\n }\n }\n\n try {\n addFilesToZip(directoryPath)\n } finally {\n progressBar.stop()\n }\n\n const zipPath = `${directoryPath}.zip`\n zip.writeZip(zipPath)\n\n const sizeBytes = fs.statSync(zipPath).size\n\n return { sizeBytes, zipPath }\n }\n\n private getIndexJson(directoryPath: string) {\n const indexJsonPath = path.join(directoryPath, \"index.json\")\n if (!fs.existsSync(indexJsonPath)) {\n return \"{}\"\n }\n\n return JSON.parse(fs.readFileSync(indexJsonPath, \"utf8\"))\n }\n\n /**\n * Uploads the zip archive to the provided signed URL\n */\n private async uploadArchiveToSignedUrl(input: {\n designSystemId: string\n name?: string\n signedUrl: string\n storybookUploadId: string\n zipPath: string\n }): Promise<void> {\n const { designSystemId, name, signedUrl, storybookUploadId, zipPath } = input\n this.log(`Securely uploading ${zipPath} to Supernova...`)\n\n // Create a new progress bar\n const progressBar = new cliProgress.SingleBar(\n {\n barCompleteChar: \"\\u2588\",\n barIncompleteChar: \"\\u2591\",\n format: \"Uploading |{bar}| {percentage}% || {value}/{total} kB\",\n hideCursor: true,\n },\n cliProgress.Presets.shades_classic,\n )\n\n const fileStream = fs.createReadStream(zipPath)\n const stats = fs.statSync(zipPath)\n const fileSize = stats.size\n const fileSizeKB = Number.parseFloat(bytesToKB(fileSize))\n\n // Start the progress bar\n progressBar.start(fileSizeKB, 0)\n\n try {\n await axios.put(signedUrl, fileStream, {\n headers: {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/zip\",\n designSystemId,\n storybookUploadId,\n ...(name && { name }),\n },\n onUploadProgress(progressEvent) {\n const loaded = progressEvent.loaded || 0\n const loadedKB = Number.parseFloat(bytesToKB(loaded))\n progressBar.update(loadedKB)\n },\n })\n\n // Complete the progress bar\n progressBar.update(fileSizeKB)\n progressBar.stop()\n } catch (error) {\n // Make sure to stop the progress bar if there's an error\n progressBar.stop()\n throw error\n }\n }\n\n /**\n * Validates if a directory is a valid storybook static export\n * @param directoryPath Path to the storybook directory\n * @returns An object indicating if the directory is valid and an error message if not\n */\n private validateStorybookDirectory(directoryPath: string): { error?: string; isValid: boolean } {\n if (!fs.existsSync(directoryPath)) {\n return { error: `Directory not found: ${directoryPath}`, isValid: false }\n }\n\n if (!fs.statSync(directoryPath).isDirectory()) {\n return { error: `Not a directory: ${directoryPath}`, isValid: false }\n }\n\n // Check for essential storybook files\n const requiredFiles = [\"index.html\", \"iframe.html\"]\n const missingFiles = requiredFiles.filter(file => !fs.existsSync(path.join(directoryPath, file)))\n\n if (missingFiles.length > 0) {\n return {\n error: `Directory does not appear to be a valid Storybook export. Missing files: ${missingFiles.join(\", \")}`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n\n /**\n * Validates if a zip file size is within the allowed limits\n * @param zipPath Path to the zip file\n * @param sizeBytes Size of the zip file in bytes\n * @returns An object indicating if the zip is valid and an error message if not\n */\n private validateZipSize(zipPath: string, sizeBytes: number): { error?: string; isValid: boolean } {\n if (sizeBytes > MAX_ZIP_SIZE_BYTES) {\n // Delete the zip file if it's too large\n try {\n fs.unlinkSync(zipPath)\n } catch {\n // Ignore errors during cleanup\n }\n\n return {\n error: `Zip file is too large: ${bytesToMB(sizeBytes)}MB. Maximum allowed size is ${bytesToMB(MAX_ZIP_SIZE_BYTES)}MB`,\n isValid: false,\n }\n }\n\n return { isValid: true }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Interfaces } from "@oclif/core";
2
2
  import { Input, ParserOutput } from "@oclif/core/interfaces";
3
3
  import { ArgOutput, FlagOutput } from "@oclif/core/lib/interfaces/parser.js";
4
4
  import { SupernovaApiClient } from "@supernova-studio/client";
@@ -6,6 +6,10 @@ import { z } from "zod";
6
6
  import { ConfigService } from "../utils/config.service.js";
7
7
  import { TargetEnv } from "./environment.js";
8
8
  export declare abstract class BaseCommand<T extends object> extends Command {
9
+ static commonFlags: {
10
+ help: Interfaces.BooleanFlag<void>;
11
+ };
12
+ static get flags(): Interfaces.FlagInput;
9
13
  protected configService: ConfigService;
10
14
  private apiClientForEnv;
11
15
  abstract get commandId(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"base-command.d.ts","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAG5D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;A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E,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyBxE,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,SAAS,EAChF,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACxB,IAAI,CAAC,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAOjC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;YAI7C,MAAM;IAapB,OAAO,CAAC,qBAAqB;CAS9B"}
@@ -1,9 +1,19 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Flags } from "@oclif/core";
2
2
  import inquirer from "inquirer";
3
3
  import { ConfigService } from "../utils/config.service.js";
4
4
  import { getApiClient } from "../utils/index.js";
5
5
  const hasAccess = (role) => role && ["Admin", "Contributor", "Creator", "Owner"].includes(role);
6
6
  export class BaseCommand extends Command {
7
+ static commonFlags = {
8
+ help: Flags.help({ char: "h" }),
9
+ };
10
+ static get flags() {
11
+ const childFlags = super.flags ?? {};
12
+ return {
13
+ ...this.commonFlags,
14
+ ...childFlags,
15
+ };
16
+ }
7
17
  configService = ConfigService.getInstance();
8
18
  apiClientForEnv = new Map();
9
19
  async apiClient(env) {
@@ -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,IAA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A;QACZ,CAAC,EACD,EAA6B,CAC9B,CAAA;IACH,CAAC;CACF","sourcesContent":["import { Command } from \"@oclif/core\"\nimport { Input, ParserOutput } from \"@oclif/core/interfaces\"\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport { ArgOutput, FlagOutput } from \"@oclif/core/lib/interfaces/parser.js\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { ConfigService } from \"../utils/config.service.js\"\nimport { getApiClient } from \"../utils/index.js\"\nimport { TargetEnv } from \"./environment.js\"\n\nconst hasAccess = (role?: DTODesignSystem[\"role\"]) =>\n role && [\"Admin\", \"Contributor\", \"Creator\", \"Owner\"].includes(role)\n\nexport abstract class BaseCommand<T extends object> extends Command {\n protected configService = ConfigService.getInstance()\n private apiClientForEnv: Map<TargetEnv, SupernovaApiClient> = new Map()\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient(env: TargetEnv): Promise<SupernovaApiClient> {\n let client = this.apiClientForEnv.get(env)\n if (!client) {\n client = await getApiClient(env)\n this.apiClientForEnv.set(env, client)\n }\n\n return client\n }\n\n protected async getBrandId(\n env: TargetEnv,\n designSystemId: string,\n versionId: string,\n brandId?: string,\n ): Promise<string> {\n if (brandId) return brandId\n const {\n designSystems: {\n versions: { brands },\n },\n } = await this.apiClient(env)\n const brdIds = (await brands.list(designSystemId, versionId)).brands.map(\n ({ meta: { name }, persistentId: id }) => ({\n id,\n name,\n }),\n )\n\n if (brdIds.length === 1) {\n return brdIds[0].id\n }\n\n return this.prompt(\n \"Select a brand:\",\n brdIds.map(brand => ({\n name: brand.name,\n value: brand.id,\n })),\n )\n }\n\n protected async getDesignSystemId(env: TargetEnv, designSystemId?: string): Promise<string> {\n if (designSystemId) return designSystemId\n const { designSystems: client } = await this.apiClient(env)\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient(env)).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(env: TargetEnv, workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient(env)\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n const parsed = await super.parse(options, argv)\n const fileConfig = this.configService.getCommandConfig(this.commandId, this.configSchema)\n parsed.flags = { ...fileConfig, ...parsed.flags }\n return parsed\n }\n\n protected saveConfig(config: Record<string, unknown>): void {\n this.configService.updateCommandConfig(this.commandId, this.removeUndefinedValues(config))\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n\n private removeUndefinedValues(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.entries(obj).reduce(\n (acc, [key, value]) => {\n if (value !== undefined) acc[key] = value\n return acc\n },\n {} as Record<string, unknown>,\n )\n }\n}\n"]}
1
+ {"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAc,MAAM,aAAa,CAAA;AAMxD,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,MAAM,SAAS,GAAG,CAAC,IAA8B,EAAE,EAAE,CACnD,IAAI,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAErE,MAAM,OAAgB,WAA8B,SAAQ,OAAO;IACjE,MAAM,CAAC,WAAW,GAAG;QACnB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;KAChC,CAAA;IAED,MAAM,KAAK,KAAK;QACd,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAA;QACpC,OAAO;YACL,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,UAAU;SACd,CAAA;IACH,CAAC;IAES,a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Ef,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QACzF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;QACjD,OAAO,MAAM,CAAA;IACf,CAAC;IAES,UAAU,CAAC,MAA+B;QAClD,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5F,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,OAA0C;QAC9E,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;YACnC;gBACE,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;gBACtD,OAAO;gBACP,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,MAAM;aACb;SACF,CAAC,CAAA;QAEF,OAAO,MAAM,CAAC,QAAkB,CAAA;IAClC,CAAC;IAEO,qBAAqB,CAAC,GAA4B;QACxD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpB,IAAI,KAAK,KAAK,SAAS;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACzC,OAAO,GAAG,CAAA;QACZ,CAAC,EACD,EAA6B,CAC9B,CAAA;IACH,CAAC","sourcesContent":["import { Command, Flags, Interfaces } 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 static commonFlags = {\n help: Flags.help({ char: \"h\" }),\n }\n\n static get flags(): Interfaces.FlagInput {\n const childFlags = super.flags ?? {}\n return {\n ...this.commonFlags,\n ...childFlags,\n }\n }\n\n protected configService = ConfigService.getInstance()\n private apiClientForEnv: Map<TargetEnv, SupernovaApiClient> = new Map()\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient(env: TargetEnv): Promise<SupernovaApiClient> {\n let client = this.apiClientForEnv.get(env)\n if (!client) {\n client = await getApiClient(env)\n this.apiClientForEnv.set(env, client)\n }\n\n return client\n }\n\n protected async getBrandId(\n env: TargetEnv,\n designSystemId: string,\n versionId: string,\n brandId?: string,\n ): Promise<string> {\n if (brandId) return brandId\n const {\n designSystems: {\n versions: { brands },\n },\n } = await this.apiClient(env)\n const brdIds = (await brands.list(designSystemId, versionId)).brands.map(\n ({ meta: { name }, persistentId: id }) => ({\n id,\n name,\n }),\n )\n\n if (brdIds.length === 1) {\n return brdIds[0].id\n }\n\n return this.prompt(\n \"Select a brand:\",\n brdIds.map(brand => ({\n name: brand.name,\n value: brand.id,\n })),\n )\n }\n\n protected async getDesignSystemId(env: TargetEnv, designSystemId?: string): Promise<string> {\n if (designSystemId) return designSystemId\n const { designSystems: client } = await this.apiClient(env)\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(env: TargetEnv, designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient(env)).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(env: TargetEnv, workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient(env)\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n const parsed = await super.parse(options, argv)\n const fileConfig = this.configService.getCommandConfig(this.commandId, this.configSchema)\n parsed.flags = { ...fileConfig, ...parsed.flags }\n return parsed\n }\n\n protected saveConfig(config: Record<string, unknown>): void {\n this.configService.updateCommandConfig(this.commandId, this.removeUndefinedValues(config))\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n\n private removeUndefinedValues(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.entries(obj).reduce(\n (acc, [key, value]) => {\n if (value !== undefined) acc[key] = value\n return acc\n },\n {} as Record<string, unknown>,\n )\n }\n}\n"]}
@@ -427,5 +427,5 @@
427
427
  ]
428
428
  }
429
429
  },
430
- "version": "2.0.19"
430
+ "version": "2.0.21"
431
431
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@supernovaio/cli-next",
3
3
  "description": "Supernova.io Command Line Interface",
4
- "version": "2.0.19",
4
+ "version": "2.0.21",
5
5
  "author": "Supernova.io",
6
6
  "bin": {
7
7
  "supernova-next": "./bin/run"