Skip to content

Commit

Permalink
[DOP-4033]: Add oas-page-build and persistence module
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Sep 29, 2023
1 parent 4518c13 commit a9ae14a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,4 +101,4 @@ RUN mkdir repos && chmod 755 repos

EXPOSE 3000

CMD ["node", "--enable-source-maps", "dist/entrypoints/localApp.js"]
CMD ["node", "dist/entrypoints/localApp.js"]
Empty file.
16 changes: 10 additions & 6 deletions src/commands/src/shared/next-gen-stage.ts
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions src/commands/src/shared/oas-page-build.ts
Original file line number Diff line number Diff line change
@@ -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,
],
});
}
28 changes: 28 additions & 0 deletions src/commands/src/shared/persistence-module.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 3 additions & 2 deletions src/entrypoints/localApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();

0 comments on commit a9ae14a

Please sign in to comment.