From a9ae14a1113393eb165efc7f2abd458a1e79b290 Mon Sep 17 00:00:00 2001 From: branberry Date: Fri, 29 Sep 2023 12:32:45 -0500 Subject: [PATCH] [DOP-4033]: Add oas-page-build and persistence module --- Dockerfile.local | 4 +-- src/commands/src/shared/next-gen-deploy.ts | 0 src/commands/src/shared/next-gen-stage.ts | 16 +++++++---- src/commands/src/shared/oas-page-build.ts | 22 +++++++++++++++ src/commands/src/shared/persistence-module.ts | 28 +++++++++++++++++++ src/entrypoints/localApp.ts | 5 ++-- 6 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/commands/src/shared/next-gen-deploy.ts create mode 100644 src/commands/src/shared/oas-page-build.ts create mode 100644 src/commands/src/shared/persistence-module.ts diff --git a/Dockerfile.local b/Dockerfile.local index a2e72d57c..d707e1725 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -2,7 +2,7 @@ FROM arm64v8/ubuntu:20.04 ARG NPM_BASE_64_AUTH ARG NPM_EMAIL ARG SNOOTY_PARSER_VERSION=0.14.9 -ARG SNOOTY_FRONTEND_VERSION=0.14.16 +ARG SNOOTY_FRONTEND_VERSION=0.14.18 ARG MUT_VERSION=0.10.7 ARG REDOC_CLI_VERSION=1.2.2 ARG NPM_BASE_64_AUTH @@ -101,4 +101,4 @@ RUN mkdir repos && chmod 755 repos EXPOSE 3000 -CMD ["node", "--enable-source-maps", "dist/entrypoints/localApp.js"] \ No newline at end of file +CMD ["node", "dist/entrypoints/localApp.js"] \ No newline at end of file diff --git a/src/commands/src/shared/next-gen-deploy.ts b/src/commands/src/shared/next-gen-deploy.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/commands/src/shared/next-gen-stage.ts b/src/commands/src/shared/next-gen-stage.ts index d9fe44cbf..2beb2650e 100644 --- a/src/commands/src/shared/next-gen-stage.ts +++ b/src/commands/src/shared/next-gen-stage.ts @@ -1,25 +1,29 @@ -import { checkIfPatched, executeCliCommand, getCommitHash, getPatchId, getRepoDir } from '../helpers'; +import { checkIfPatched, executeCliCommand, getCommitBranch, getCommitHash, getPatchId, getRepoDir } from '../helpers'; interface StageParams { repoName: string; mutPrefix: string; projectName: string; bucketName: string; + url: string; } -export async function nextGenStage({ repoName, mutPrefix, projectName, bucketName }: StageParams) { +export async function nextGenStage({ repoName, mutPrefix, projectName, bucketName, url }: StageParams) { const repoDir = getRepoDir(repoName); - const hasPatch = await checkIfPatched(repoDir); + const [hasPatch, commitBranch] = await Promise.all([checkIfPatched(repoDir), getCommitBranch(repoDir)]); + + let hostedAtUrl = `${url}/${mutPrefix}/${process.env.USER}/${commitBranch}/`; const commandArgs = ['public', bucketName, '--stage']; if (hasPatch && projectName !== mutPrefix) { const [commitHash, patchId] = await Promise.all([getCommitHash(repoDir), getPatchId(repoDir)]); commandArgs.push(`--prefix="${commitHash}/${patchId}/${mutPrefix}"`); + hostedAtUrl = `${url}/${commitHash}/${patchId}/${mutPrefix}/${process.env.USER}/${commitBranch}/`; } - const result = await executeCliCommand({ command: 'mut-publish', args: commandArgs }); - - return result; + const { stdout } = await executeCliCommand({ command: 'mut-publish', args: commandArgs }); + const resultMessage = `${stdout}\n Hosted at ${hostedAtUrl}`; + return resultMessage; } diff --git a/src/commands/src/shared/oas-page-build.ts b/src/commands/src/shared/oas-page-build.ts new file mode 100644 index 000000000..f90d1fbf2 --- /dev/null +++ b/src/commands/src/shared/oas-page-build.ts @@ -0,0 +1,22 @@ +import { executeCliCommand } from '../helpers'; + +interface OasPageBuildParams { + bundlePath: string; + repoDir: string; + siteUrl: string; +} + +export async function oasPageBuild({ bundlePath, repoDir, siteUrl }: OasPageBuildParams) { + const { stdout } = await executeCliCommand({ + command: 'node', + args: [ + `${process.cwd()}/modules/oas-page-builder/dist/index.js`, + '--output', + `${repoDir}/public`, + '--redoc', + `${process.cwd()}/redoc/cli/index.js`, + '--site-url', + siteUrl, + ], + }); +} diff --git a/src/commands/src/shared/persistence-module.ts b/src/commands/src/shared/persistence-module.ts new file mode 100644 index 000000000..292bb0ef7 --- /dev/null +++ b/src/commands/src/shared/persistence-module.ts @@ -0,0 +1,28 @@ +import { executeCliCommand } from '../helpers'; + +interface PersistenceModuleParams { + bundlePath: string; + jobId: string; + repoOwner?: string; +} +export async function persistenceModule({ + bundlePath, + jobId, + repoOwner = 'docs-builder-bot', +}: PersistenceModuleParams) { + const { stdout } = await executeCliCommand({ + command: 'node', + args: [ + `${process.cwd()}/modules/persistence/dist/index.js`, + '--unhandled-rejections=strict', + '--path', + bundlePath, + '--githubUser', + repoOwner, + '--jobId', + jobId, + ], + }); + + return stdout; +} diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index d3544e2d2..c33250efc 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -5,7 +5,7 @@ import { nextGenHtml } from '../commands/src/shared/next-gen-html'; async function localApp() { const repoDir = path.join(process.cwd(), '/repos'); - const repoName = 'docs-java'; + const repoName = 'docs-landing'; await executeCliCommand({ command: 'git', @@ -27,7 +27,8 @@ async function localApp() { console.log(nextGenHtmlRes.stdout); console.log('next-gen-html complete'); - while (true) {} + + console.log('Begin next-gen-stage...'); } localApp();