This repository was archived by the owner on Nov 13, 2023. It is now read-only.
forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaderChecks.ts
More file actions
54 lines (44 loc) · 1.74 KB
/
headerChecks.ts
File metadata and controls
54 lines (44 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { renderParseError, validate } from "./header-parser";
import * as path from "path";
import * as fs from "fs";
import { scripts, scriptsPath, scriptFileExtensions, mainFilenames, printFilePath } from "./utils";
function checkScripts () {
const errorMessages: string[] = [];
let packagesHaveError = 0;
for (const script of scripts) {
const scriptPath = path.resolve(scriptsPath, script);
const scriptFiles = fs.readdirSync(scriptPath).filter(name => scriptFileExtensions.includes(path.extname(name)));
const mainFiles = scriptFiles.filter(x => mainFilenames.includes(x));
let hasError = false;
if (mainFiles.length < 1) {
errorMessages.push(`${printFilePath(scriptPath)} does not have one of the following files: ${mainFilenames.join(', ')}`);
hasError = true;
packagesHaveError++;
continue;
};
for (const file of mainFiles) {
const fullpath = path.resolve(scriptPath, file);
const content = fs.readFileSync(fullpath).toString();
const parseError = validate(content);
if (!!parseError) {
errorMessages.push(`${printFilePath(fullpath)} ${renderParseError(parseError)}`);
hasError = true;
};
};
hasError ? packagesHaveError++ : null;
};
return { errorMessages, packagesHaveError };
};
function printMessages (messages: string[], packagesHaveError: number) {
console.log(`Found ${messages.length} errors in ${packagesHaveError} scripts.`);
for (const message of messages) {
console.error(message);
}
};
// main entry
export function execute () {
const results = checkScripts();
printMessages(results.errorMessages, results.packagesHaveError);
const statusCode = results.errorMessages.length > 0 ? 1 : 0;
return statusCode;
};