UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

54 lines (52 loc) 2.59 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="54c5f884-eb28-5fd2-b857-7dc540c0b5f6")}catch(e){}}(); import { createRequire } from "node:module"; import { apiUrlForEnvironment, getTargetEnv } from "../types/environment.js"; import "colors"; const require = createRequire(import.meta.url); const sdkProvider = require("@supernovaio/sdk"); export async function getWritableVersion(flags) { if (!flags.apiKey || flags.apiKey.length === 0) { throw new Error(`API key must not be empty`); } if (!flags.designSystemId || flags.designSystemId.length === 0) { throw new Error(`Design System ID must not be empty`); } const apiUrl = flags.apiUrl && flags.apiUrl.length > 0 ? flags.apiUrl : apiUrlForEnvironment(getTargetEnv()); const instance = new sdkProvider.Supernova(flags.apiKey, { apiUrl, bypassEnvFetch: true, proxyUrl: flags.proxyUrl, }); const designSystem = await instance.designSystems.designSystem(flags.designSystemId); if (!designSystem) { throw new Error(`Design system ${flags.designSystemId} not found or not available under provided API key`); } const version = await instance.versions.getActiveVersion(flags.designSystemId); if (!version) { throw new Error(`Design system ${flags.designSystemId} writable version not found or not available under provided API key`); } const id = { designSystemId: flags.designSystemId, versionId: version.id, workspaceId: designSystem.workspaceId, }; let brand = null; if (flags.brandId) { const brands = await instance.brands.getBrands(id); brand = brands.find(brand => brand.id === flags.brandId || brand.idInVersion === flags.brandId) ?? null; if (!brand) { throw new Error(`Brand ${flags.brandId} not found in specified design system`); } } let theme = null; if (flags.themeId) { const themes = await instance.tokens.getTokenThemes(id); theme = themes.find(theme => theme.id === flags.themeId || theme.idInVersion === flags.themeId) ?? null; if (!theme) { throw new Error(`Theme ${flags.themeId} not found in specified brand`); } } return { brand, designSystem, id, instance, theme, version }; } //# sourceMappingURL=sdk.js.map //# debugId=54c5f884-eb28-5fd2-b857-7dc540c0b5f6