From 2e88f2358526962f990ca674d139bbd3d98aa3ec Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Mon, 16 Sep 2024 14:18:49 -0700 Subject: [PATCH] [Admin] Update script to bypass user prompt when run from GitHub Action (#2060) * [Admin] Update script to bypass user prompt when run from GitHub Action * Updates based on feedback --- generate-docs/GenerateDocs.sh | 9 ++++++- generate-docs/scripts/preprocessor.ts | 39 +++++++++++++++++---------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/generate-docs/GenerateDocs.sh b/generate-docs/GenerateDocs.sh index 8115254e46..f1f7698c7e 100644 --- a/generate-docs/GenerateDocs.sh +++ b/generate-docs/GenerateDocs.sh @@ -1,5 +1,12 @@ #!/bin/bash +while getopts b: flag +do + case "${flag}" in + b) bypassPrompt=${OPTARG};; + esac +done + if [ -e "build-log.txt" ]; then rm build-log.txt fi @@ -35,7 +42,7 @@ npm install pushd scripts npm install npm run build -node preprocessor.js +node preprocessor.js $bypassPrompt popd diff --git a/generate-docs/scripts/preprocessor.ts b/generate-docs/scripts/preprocessor.ts index 82e211d2b7..67f9f429a7 100644 --- a/generate-docs/scripts/preprocessor.ts +++ b/generate-docs/scripts/preprocessor.ts @@ -6,21 +6,30 @@ import * as path from "path"; import * as fsx from 'fs-extra'; tryCatch(async () => { - // ---- - // Display prompts - // ---- - console.log('\n\n'); + const args = process.argv.slice(2); + let sourceChoice; - console.log('\n'); - const sourceChoice = await promptFromList({ - message: `What is the source of the Office-js TypeScript definition files that should be used to generate the docs?`, - choices: [ - { name: "DefinitelyTyped (optimized rebuild)", value: "DT" }, - { name: "DefinitelyTyped (full rebuild)", value: "DT+" }, - { name: "CDN (if available)", value: "CDN" }, - { name: "Local files [generate-docs\\script-inputs\\*.d.ts]", value: "Local" } - ] - }); + // Bypass the prompt - for use with the GitHub Action. + if (args.length > 0 && args[0] !== null && args[0].trim().length > 0) { + console.log("Bypassing source choice prompt."); + sourceChoice = args[0].trim(); + } else { + // ---- + // Display prompts + // ---- + console.log('\n\n'); + + console.log('\n'); + sourceChoice = await promptFromList({ + message: `What is the source of the Office-js TypeScript definition files that should be used to generate the docs?`, + choices: [ + { name: "DefinitelyTyped (optimized rebuild)", value: "DT" }, + { name: "DefinitelyTyped (full rebuild)", value: "DT+" }, + { name: "CDN (if available)", value: "CDN" }, + { name: "Local files [generate-docs\\script-inputs\\*.d.ts]", value: "Local" } + ] + }); + } let urlToCopyOfficeJsFrom = ""; @@ -48,6 +57,8 @@ tryCatch(async () => { // to avoid being redirected to the EDOG environment on corpnet. // If we ever want to generate not just public d.ts but also "office-with-first-party.d.ts", // replace the filename. + default: + throw new Error(`Invalid prompt selection: ${sourceChoice}`); } console.log("\nStarting preprocessor script...\n");