From 42753cfa9b2ca99be03b6ebb8a63acf4667e9018 Mon Sep 17 00:00:00 2001 From: branberry Date: Wed, 11 Oct 2023 08:21:44 -0500 Subject: [PATCH] [DOP-4033]: Add comments --- config/default.json | 1 - .../{execution-helper.ts => dependency-helpers.ts} | 14 +++++++++----- src/commands/src/helpers/index.ts | 14 ++++++++++++++ src/commands/src/shared/next-gen-deploy.ts | 6 ++---- src/entrypoints/localApp.ts | 4 +--- 5 files changed, 26 insertions(+), 13 deletions(-) rename src/commands/src/helpers/{execution-helper.ts => dependency-helpers.ts} (81%) diff --git a/config/default.json b/config/default.json index 64539c7ee..9b0a73341 100644 --- a/config/default.json +++ b/config/default.json @@ -33,7 +33,6 @@ "featureFlagUpdatePages": "false", "featureFlagSearchUI": "false", "gatsbyUseChatbot": "false", - "gatsbyHideUnifiedFooterLocale": "true", "parallel": { "enabled": true, "stg": { diff --git a/src/commands/src/helpers/execution-helper.ts b/src/commands/src/helpers/dependency-helpers.ts similarity index 81% rename from src/commands/src/helpers/execution-helper.ts rename to src/commands/src/helpers/dependency-helpers.ts index fd5037b0e..86dcef4da 100644 --- a/src/commands/src/helpers/execution-helper.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -34,10 +34,13 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } export async function getCliBuildDependencies(repoName: string, projectName: string, baseUrl: string) { + // before we get build dependencies, we need to clone + // the repo await cloneRepo(repoName); const repoDir = getRepoDir(repoName); + // doing these in parallel const commandPromises = [ getCommitHash(repoDir), getCommitBranch(repoDir), @@ -46,12 +49,13 @@ export async function getCliBuildDependencies(repoName: string, projectName: str createEnvProdFile(repoDir, projectName, baseUrl), ]; - const deps = await Promise.all(commandPromises); + const dependencies = await Promise.all(commandPromises); + return { - commitHash: deps[0] as string, - commitBranch: deps[1] as string, - patchId: deps[2] as string | undefined, - hasRedirects: deps[3] as boolean, + commitHash: dependencies[0] as string, + commitBranch: dependencies[1] as string, + patchId: dependencies[2] as string | undefined, + hasRedirects: dependencies[3] as boolean, bundlePath: `${repoDir}/bundle.zip`, repoDir, }; diff --git a/src/commands/src/helpers/index.ts b/src/commands/src/helpers/index.ts index 41076072d..1e8c97122 100644 --- a/src/commands/src/helpers/index.ts +++ b/src/commands/src/helpers/index.ts @@ -111,6 +111,20 @@ export async function executeAndPipeCommands( }); }); } + +/** + * A promisified way to execute CLI commands. This approach uses spawn instead of exec, which + * is a safer way of executing CLI commands. Also, spawn allows us to stream output in real-time. + * @param {string} command: The CLI command we want to execute + * @param {string[] | undefined} args: Arguments we want to provide to the command + * @param {SpawnOptions | undefined} options: Options to configure the spawn process + * @param {fs.WriteStream | undefined} writeStream: A writable stream object to pipe output to. + * For example, we can mimic ls >> directory.txt by creating a WriteStream object to write to + * directory.txt, and then provide the WriteStream so that we can pipe the output from the ls + * command to the WriteStream. + * @returns {Promise} An object containing the CLI output from stdout and stderr. + * stdout is the outputText property, and stderr is the errorText property. + */ export async function executeCliCommand({ command, args = [], diff --git a/src/commands/src/shared/next-gen-deploy.ts b/src/commands/src/shared/next-gen-deploy.ts index 9167f1599..d980e1d1f 100644 --- a/src/commands/src/shared/next-gen-deploy.ts +++ b/src/commands/src/shared/next-gen-deploy.ts @@ -9,14 +9,12 @@ interface NextGenDeployParams { } export async function nextGenDeploy({ bucket, mutPrefix, gitBranch, hasConfigRedirects, url }: NextGenDeployParams) { - // const hasConfigRedirects = await existsAsync(path.join(process.cwd(), 'config/redirects')); - if (hasConfigRedirects && (gitBranch === 'main' || gitBranch === 'master')) { - // mut-redirects config/redirects -o public/.htaccess + // equivalent to: mut-redirects config/redirects -o public/.htaccess await executeCliCommand({ command: 'mut-redirects', args: ['config/redirects', '-o', 'public/.htaccess'] }); } - // yes | mut-publish public ${BUCKET} --prefix="${MUT_PREFIX}" --deploy --deployed-url-prefix=${URL} --json --all-subdirectories ${ARGS}; + // equivalent to: yes | mut-publish public ${BUCKET} --prefix="${MUT_PREFIX}" --deploy --deployed-url-prefix=${URL} --json --all-subdirectories ${ARGS}; const { outputText } = await executeAndPipeCommands( { command: 'yes' }, { diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index 89cfdcbd8..daac509f9 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -1,6 +1,6 @@ import { nextGenParse } from '../commands/src/shared/next-gen-parse'; import { nextGenHtml } from '../commands/src/shared/next-gen-html'; -import { getCliBuildDependencies } from '../commands/src/helpers/execution-helper'; +import { getCliBuildDependencies } from '../commands/src/helpers/dependency-helpers'; import { nextGenStage } from '../commands/src/shared/next-gen-stage'; import { oasPageBuild } from '../commands/src/shared/oas-page-build'; import { persistenceModule } from '../commands/src/shared/persistence-module'; @@ -20,8 +20,6 @@ async function localApp() { baseUrl ); - console.log('Hello'); - console.log('Begin snooty build...'); const snootyBuildRes = await nextGenParse({ repoDir, commitHash, patchId });