From e15497e0a2bb7ee68caed2f700d658ae61e9eb4c Mon Sep 17 00:00:00 2001 From: chad Date: Tue, 23 May 2023 12:10:56 -0500 Subject: [PATCH] test: added test to ensure doc-check isn't done on windows (#1273) --- src/document-check.js | 87 +++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/src/document-check.js b/src/document-check.js index 5a4e3abdb..eba44ed36 100644 --- a/src/document-check.js +++ b/src/document-check.js @@ -26,56 +26,61 @@ const tasks = new Listr( * @param {Task} task */ task: async (ctx, task) => { - const configPath = './tsconfig-doc-check.aegir.json' + const isWindows = process.platform === 'win32' - let userTSConfig = {} - let markdownFiles = ['README.md'] + if (!isWindows) { + const configPath = './tsconfig-doc-check.aegir.json' - if (ctx.tsConfigPath && ctx.tsConfigPath !== '.') { - userTSConfig = readJson(`${ctx.tsConfigPath}/tsconfig.json`) - } else { - userTSConfig = readJson(fromRoot('tsconfig.json')) - } + let userTSConfig = {} + let markdownFiles = ['README.md'] - if (ctx.inputFiles) { - markdownFiles = await globby(ctx.inputFiles) - } + if (ctx.tsConfigPath && ctx.tsConfigPath !== '.') { + userTSConfig = readJson(`${ctx.tsConfigPath}/tsconfig.json`) + } else { + userTSConfig = readJson(fromRoot('tsconfig.json')) + } + + if (ctx.inputFiles) { + markdownFiles = await globby(ctx.inputFiles) + } - try { - fs.writeJsonSync( - configPath, - merge.apply({ concatArrays: true }, [ - userTSConfig, - { - compilerOptions: { - target: 'esnext', - module: 'esnext', - noImplicitAny: true, - noEmit: true + try { + fs.writeJsonSync( + configPath, + merge.apply({ concatArrays: true }, [ + userTSConfig, + { + compilerOptions: { + target: 'esnext', + module: 'esnext', + noImplicitAny: true, + noEmit: true + } } - } - ]) - ) + ]) + ) - const results = await compileSnippets({ markdownFiles, project: configPath }) + const results = await compileSnippets({ markdownFiles, project: configPath }) - results.forEach((result) => { - if (result.error) { - process.exitCode = 1 - console.log(kleur.red().bold(`Error compiling example code block ${result.index} in file ${result.file}:`)) - console.log(formatError(result.error)) - console.log(kleur.blue().bold('Original code:')) - console.log(formatCode(result.snippet, result.linesWithErrors)) - } - }) - } catch (err) { - console.log('Error in trying to compile Typescript code', err) - } finally { - fs.removeSync(configPath) - fs.removeSync(fromRoot('dist', 'tsconfig-doc-check.aegir.tsbuildinfo')) + results.forEach((result) => { + if (result.error) { + process.exitCode = 1 + console.log(kleur.red().bold(`Error compiling example code block ${result.index} in file ${result.file}:`)) + console.log(formatError(result.error)) + console.log(kleur.blue().bold('Original code:')) + console.log(formatCode(result.snippet, result.linesWithErrors)) + } + }) + } catch (err) { + console.log('Error in trying to compile Typescript code', err) + } finally { + fs.removeSync(configPath) + fs.removeSync(fromRoot('dist', 'tsconfig-doc-check.aegir.tsbuildinfo')) + } + } else { + console.log(kleur.red('The underlying plugin used for TS-doc checks currently does not support Windows OS (See Github issue https://github.com/bbc/typescript-docs-verifier/issues/26). Skipping document check.')) } } - } ], {