From b3f0aa9506b1dbae9eaed07eb5393ba6604c2e14 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Tue, 12 Dec 2023 14:49:35 +0100 Subject: [PATCH] Code for handling tsconfig file not found has also been streamlined for consistency and readability. --- lib/index.js | 35 +++++++++++++++++++++++------------ src/index.ts | 41 +++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/index.js b/lib/index.js index a4d978a..b0333cd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26043,9 +26043,19 @@ async function run() { * const args = ['arg1', 'arg2', 'arg3']; */ const args = []; + /** + * The log level to use + * Possible values: Verbose, Debug, Info, Warn, Error, None + */ if ((0, core_1.getInput)('logLevel')) { args.push('--logLevel', (0, core_1.getInput)('logLevel')); } + /** + * The path to the source directory + */ + const srcPath = (0, path_1.join)(GITHUB_WORKSPACE, source_dir); + (0, core_1.info)('📂 Source directory: ' + srcPath); + args.push(srcPath); /** * The base path of the package to be documented. * Since the base path is relative to the current working directory, @@ -26059,27 +26069,28 @@ async function run() { args.push('--basePath', GITHUB_WORKSPACE); } /** - * The path to the source directory + * The output directory for the generated documentation. */ - const srcPath = (0, path_1.join)(GITHUB_WORKSPACE, source_dir); - (0, core_1.info)('📂 Source directory: ' + srcPath); - args.push(srcPath); if (output_dir) { args.push('--out', (0, path_1.join)(GITHUB_WORKSPACE, output_dir)); } /** - * the path to the tsconfig file, needed to resolve entry points and other options. Defaults to ./{action folder}/tsconfig.json + * The path to the tsconfig file, needed to resolve entry points and other options. + * typedoc will search for the tsconfig file in the action directory, so we have to point it to the workspace folder + * Defaults to ./{action folder}/tsconfig.json + * * https://typedoc.org/options/input/#resolve-(default) */ + let tsConfigPath = GITHUB_WORKSPACE; if (tsconfig) { - const tsConfigPath = (0, path_1.join)(GITHUB_WORKSPACE, tsconfig); - if ((0, node_fs_1.existsSync)(tsConfigPath)) { - (0, core_1.setFailed)('⛔️ Config file does not exist'); - return; - } - const configPath = (0, path_1.join)(GITHUB_WORKSPACE, tsconfig); - args.push('--tsconfig', configPath); + tsConfigPath = (0, path_1.join)(GITHUB_WORKSPACE, tsconfig); + } + if ((0, node_fs_1.existsSync)(tsConfigPath)) { + (0, core_1.setFailed)('⛔️ Tsconfig file not found'); + return; } + const configPath = (0, path_1.join)(GITHUB_WORKSPACE, tsconfig); + args.push('--tsconfig', configPath); if (options) { const configPath = (0, path_1.join)(GITHUB_WORKSPACE, options); args.push('--options', configPath); diff --git a/src/index.ts b/src/index.ts index 774c26b..552a7fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,11 +115,21 @@ async function run(): Promise { */ const args: string[] = [] - + /** + * The log level to use + * Possible values: Verbose, Debug, Info, Warn, Error, None + */ if (getInput('logLevel')) { args.push('--logLevel', getInput('logLevel')) } + /** + * The path to the source directory + */ + const srcPath: string = join(GITHUB_WORKSPACE, source_dir) + info('📂 Source directory: ' + srcPath) + args.push(srcPath) + /** * The base path of the package to be documented. * Since the base path is relative to the current working directory, @@ -133,31 +143,30 @@ async function run(): Promise { } /** - * The path to the source directory + * The output directory for the generated documentation. */ - const srcPath: string = join(GITHUB_WORKSPACE, source_dir) - info('📂 Source directory: ' + srcPath) - args.push(srcPath) - if (output_dir) { args.push('--out', join(GITHUB_WORKSPACE, output_dir)) } - /** - * the path to the tsconfig file, needed to resolve entry points and other options. Defaults to ./{action folder}/tsconfig.json + * The path to the tsconfig file, needed to resolve entry points and other options. + * typedoc will search for the tsconfig file in the action directory, so we have to point it to the workspace folder + * Defaults to ./{action folder}/tsconfig.json + * * https://typedoc.org/options/input/#resolve-(default) */ + let tsConfigPath: string = GITHUB_WORKSPACE; if (tsconfig) { - const tsConfigPath = join(GITHUB_WORKSPACE, tsconfig) - if (existsSync(tsConfigPath)) { - setFailed('⛔️ Config file does not exist') - return - } - - const configPath = join(GITHUB_WORKSPACE, tsconfig) - args.push('--tsconfig', configPath) + tsConfigPath = join(GITHUB_WORKSPACE, tsconfig) } + if (existsSync(tsConfigPath)) { + setFailed('⛔️ Tsconfig file not found') + return + } + + const configPath = join(GITHUB_WORKSPACE, tsconfig) + args.push('--tsconfig', configPath) if (options) { const configPath = join(GITHUB_WORKSPACE, options)