UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

124 lines (122 loc) 5.92 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]="9ccd262f-d9ef-5fd7-86ce-fee162b22a5b")}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 sdkTypes from "@supernovaio/sdk"; import { z } from "zod"; import { SentryCommand } from "../types/index.js"; import { sleep } from "../utils/common.js"; import { getWritableVersion } from "../utils/sdk.js"; const PublishDocumentationConfigSchema = z.object({ apiKey: z.string(), awaitPublishJob: z.boolean(), designSystemId: z.string(), dev: z.boolean(), proxyUrl: z.string().url().optional(), target: z.string(), }); export class PublishDocumentation extends SentryCommand { static aliases = ["publish-documentation"]; static description = "Publish latest version of the documentation"; static examples = [`$ @supernovaio/cli publish-documentation --apiKey="{xxx-xxx-xxx}" --designSystemId="{1234}"`]; static flags = { apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }), awaitPublishJob: Flags.boolean({ default: true, description: "Whether to block the process until the publishing is done. " + "Setting the flag to false will exit with success as long as documentation publish was successfully triggered, " + "but before the publish is completed. Setting the flag to true will exit once the publish is complete and will " + "throw if documentation publish is not successful.", }), designSystemId: Flags.string({ description: "Design System to publish the documentation", required: true }), dev: Flags.boolean({ default: false, description: "When enabled, CLI will target dev server", hidden: true }), proxyUrl: Flags.string({ description: "When set, CLI will use provided proxy URL for all requests", hidden: true, required: false, }), target: Flags.string({ default: "Live", description: "Environment to use for publishing: Live or Preview", required: false, }), }; get commandId() { return PublishDocumentation.id; } get configSchema() { return PublishDocumentationConfigSchema; } async run() { const { flags } = await this.parse(PublishDocumentation); const environment = tryParseDocsEnvironment(flags.target); if (!environment) { const supportedEnvs = [sdkTypes.DocumentationEnvironment.live, sdkTypes.DocumentationEnvironment.preview]; this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(", ")}]`); } const { designSystem, id, instance } = await getWritableVersion(flags); this.log(`Queueing documentation publish in ${designSystem.name}...`); let publishJob = await instance.documentation.publishDrafts(id, environment, undefined); this.log(`Documentation queued for publishing`.green); if (!flags.awaitPublishJob) { this.log(`Documentation publish await is disabled, exiting before the publish is finished.`.yellow); return; } this.log(`Waiting for the documentation publish to be finished...`); for (let i = 0; i < 30 * 60; i++) { await sleep(1000); publishJob = await instance.documentation.getDocumentationBuild(designSystem.workspaceId, publishJob.id); if (isJobStatusDone(publishJob.status)) break; } switch (publishJob.status) { case "Success": { this.log("\nDone: Documentation queued for publishing".green); break; } case "Failed": { throw new Error(`Documentation publish failed`); } case "Timeout": { throw new Error(`Documentation publish timed out`); } default: { throw new Error(`Error awaiting publish job`); } } } } __decorate([ SentryTraced(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], PublishDocumentation.prototype, "run", null); function tryParseDocsEnvironment(targetArg) { switch (targetArg.toLowerCase()) { case "live": { return sdkTypes.DocumentationEnvironment.live; } case "preview": { return sdkTypes.DocumentationEnvironment.preview; } default: { return null; } } } function isJobStatusDone(status) { return (status === sdkTypes.ExportBuildStatus.Failed || status === sdkTypes.ExportBuildStatus.Success || status === sdkTypes.ExportBuildStatus.Timeout); } //# sourceMappingURL=publish-documentation.js.map //# debugId=9ccd262f-d9ef-5fd7-86ce-fee162b22a5b