From f90f70d86a05032dc04388275d7d944fce6adfd7 Mon Sep 17 00:00:00 2001 From: ivvist Date: Thu, 11 Jan 2024 14:18:03 +0100 Subject: [PATCH] CI: Add unit tests for web-portals --- checkSources.js | 17 ++++++++--------- dist/index.js | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/checkSources.js b/checkSources.js index 98ac77b..d9f8ded 100644 --- a/checkSources.js +++ b/checkSources.js @@ -28,17 +28,16 @@ const getSourceFiles = function (dir, ignore, files_) { } const detectLanguage = function (ignore) { - let sourceFiles = getSourceFiles('.', ignore) - if (fs.existsSync('go.mod')) return "go" - sourceFiles.forEach(file => { - if (path.extname(file) === ".go") return "go" - }) - sourceFiles.forEach(file => { - if (path.extname(file) === ".js") return "node_js" - }) - return "unknown" + if (fs.existsSync('go.mod')) return "go" + let sourceFiles = getSourceFiles('.', ignore) + for (const file of sourceFiles) { + if (path.extname(file) === ".go") return "go" + if (/\.[jt]sx?/.test(path.extname(file))) return "node_js" + } + return "unknown" } + const getFirstComment = function (file) { let content = fs.readFileSync(file, 'utf8') let m = content.match(/^(\s|\/\/[^\n]*\n|\/\*([^*]|\*(?!\/))*\*\/)*/) diff --git a/dist/index.js b/dist/index.js index ec3133b..ce04c2f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,17 +34,16 @@ const getSourceFiles = function (dir, ignore, files_) { } const detectLanguage = function (ignore) { - let sourceFiles = getSourceFiles('.', ignore) - if (fs.existsSync('go.mod')) return "go" - sourceFiles.forEach(file => { - if (path.extname(file) === ".go") return "go" - }) - sourceFiles.forEach(file => { - if (path.extname(file) === ".js") return "node_js" - }) - return "unknown" + if (fs.existsSync('go.mod')) return "go" + let sourceFiles = getSourceFiles('.', ignore) + for (const file of sourceFiles) { + if (path.extname(file) === ".go") return "go" + if (/\.[jt]sx?/.test(path.extname(file))) return "node_js" + } + return "unknown" } + const getFirstComment = function (file) { let content = fs.readFileSync(file, 'utf8') let m = content.match(/^(\s|\/\/[^\n]*\n|\/\*([^*]|\*(?!\/))*\*\/)*/)