UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

110 lines (108 loc) 5.29 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]="9e68811c-22b2-58b8-a201-50badbf98e54")}catch(e){}}(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Flags } from "@oclif/core"; import { SentryTraced } from "@sentry/nestjs"; import { createRequire } from "node:module"; import { z } from "zod"; import { apiUrlForEnvironment, commonFlags, getTargetEnv, SentryCommand } from "../types/index.js"; const require = createRequire(import.meta.url); const sdkProvider = require("@supernovaio/sdk"); const DescribeWorkspaceConfigSchema = z .object({ apiKey: z.string(), proxyUrl: z.string().url().optional(), workspaceId: z.string(), }) .transform(data => ({ ...data, })); export class DescribeWorkspaces extends SentryCommand { static aliases = ["describe-workspaces"]; static description = "Describe structure of all workspaces and design systems available under those workspaces available for specified API key"; static examples = [`$ @supernovaio/cli describe-workspaces --apiKey="{xxx-xxx-xxx}"`]; static flags = { ...commonFlags, apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }), proxyUrl: Flags.string({ description: "When set, CLI will use provided proxy URL for all requests", hidden: true, required: false, }), }; get commandId() { return DescribeWorkspaces.id; } get configSchema() { return DescribeWorkspaceConfigSchema; } async getWorkspaces(flags) { if (!flags.apiKey || flags.apiKey.length === 0) { throw new Error(`API key must not be empty`); } const apiUrl = apiUrlForEnvironment(getTargetEnv()); const sdkInstance = new sdkProvider.Supernova(flags.apiKey, { apiUrl, }); const user = await sdkInstance.me.me(); const workspaces = await sdkInstance.workspaces.workspaces(user.id); return { instance: sdkInstance, workspaces, }; } async run() { const { flags } = await this.parse(DescribeWorkspaces); const { instance, workspaces } = await this.getWorkspaces(flags); this.log(`\n`); for (const workspace of workspaces) { const designSystems = await instance.designSystems.designSystems(workspace.id); this.log(`↳ Workspace "${workspace.profile.name}", id: ${workspace.id}`.magenta); for (const designSystem of designSystems) { this.log(` ↳ Design system "${designSystem.name}", id: ${designSystem.id}`.cyan); const version = await instance.versions.getActiveVersion(designSystem.id); if (!version) { this.log(`Design system ${designSystem.id} active version not found or not available under provided API key`); continue; } const id = { designSystemId: designSystem.id, versionId: version.id }; const brands = await instance.brands.getBrands(id); const themes = await instance.tokens.getTokenThemes(id); for (const brand of brands) { this.log(` ↳ Brand: "${brand.name}", id: ${brand.id}`); const brandThemes = themes.filter(t => t.brandId === brand.id); if (brandThemes.length > 0) { for (const theme of brandThemes) { this.log(` ↳ Theme: "${theme.name}", id: ${theme.id}`.gray); } } else { this.log(` ↳ No themes defined in this brand`.gray); } } } } this.log("\nDone".green); } } __decorate([ SentryTraced(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], DescribeWorkspaces.prototype, "getWorkspaces", null); __decorate([ SentryTraced(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], DescribeWorkspaces.prototype, "run", null); //# sourceMappingURL=describe-workspaces.js.map //# debugId=9e68811c-22b2-58b8-a201-50badbf98e54