Skip to content

Commit

Permalink
Implement docs job await
Browse files Browse the repository at this point in the history
  • Loading branch information
artufimtcev committed Nov 8, 2024
1 parent 0ec1e22 commit f551508
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@supernovaio/cli",
"description": "Supernova.io Command Line Interface",
"version": "1.1.1",
"version": "1.1.2",
"author": "Supernova.io",
"homepage": "https://supernova.io/",
"keywords": [
Expand Down
30 changes: 22 additions & 8 deletions src/commands/publish-documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { Command, Flags } from "@oclif/core"
import { Environment, ErrorCode } from "../types/types"
import { getWritableVersion } from "../utils/sdk"
import "colors"
import { DocumentationEnvironment } from "@supernovaio/sdk"
import { DocumentationEnvironment, ExportBuildStatus } from "@supernovaio/sdk"
import { sleep } from "../utils/common"

// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
// MARK: - Definition
Expand Down Expand Up @@ -76,18 +77,25 @@ export class PublishDocumentation extends Command {
}

// Get workspace -> design system –> version
let { instance, id } = await getWritableVersion(flags)
let result = await instance.documentation.publishDrafts(id, environment, {
let { instance, id, designSystem } = await getWritableVersion(flags)
let publishJob = await instance.documentation.publishDrafts(id, environment, {
pagePersistentIds: [],
groupPersistentIds: [],
})

if (result.status === "Success") {
let jobStatus = publishJob.status
while (!isJobStatusDone(jobStatus)) {
await sleep(1000)
const updatedJob = await instance.documentation.getDocumentationBuild(designSystem.workspaceId, publishJob.id)
jobStatus = updatedJob.status
}

if (publishJob.status === "Success") {
this.log("\nDone: Documentation queued for publishing".green)
} else if (result.status === "InProgress") {
this.log("\n Done: Skipped documentation publish as another build is already in progress".green)
} else if (result.status === "Failed") {
throw new Error(`Documentation publish failed with unknown failure`)
} else if (publishJob.status === "Failed") {
throw new Error(`Documentation publish failed`)
} else if (publishJob.status === "Timeout") {
throw new Error(`Documentation publish timed out`)
}
} catch (error) {
// Catch general error
Expand All @@ -109,3 +117,9 @@ function tryParseDocsEnvironment(targetArg: string) {
return null
}
}

function isJobStatusDone(status: ExportBuildStatus): boolean {
return (
status === ExportBuildStatus.Failed || status === ExportBuildStatus.Success || status === ExportBuildStatus.Timeout
)
}
3 changes: 3 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}

0 comments on commit f551508

Please sign in to comment.