Add proper license

This commit is contained in:
Vanilagy
2025-06-27 13:14:11 +02:00
parent bc201ca265
commit a3d73228e2
52 changed files with 806 additions and 37 deletions
+12 -15
View File
@@ -1,10 +1,7 @@
import ts from 'typescript';
import * as fs from 'node:fs';
function checkDocblocks(filePath: string): {
success: boolean;
missingDocblocks: { name: string; kind: string; line: number; reason: string }[];
} {
const checkDocblocks = (filePath: string) => {
const program = ts.createProgram([filePath], {});
const sourceFile = program.getSourceFile(filePath);
const checker = program.getTypeChecker();
@@ -15,7 +12,7 @@ function checkDocblocks(filePath: string): {
const missingDocblocks: { name: string; kind: string; line: number; reason: string }[] = [];
function checkNode(node: ts.Node) {
const checkNode = (node: ts.Node) => {
if (
ts.isInterfaceDeclaration(node)
|| ts.isClassDeclaration(node)
@@ -40,7 +37,7 @@ function checkDocblocks(filePath: string): {
const docStatus = checkDocumentationContent(declSymbol, declaration);
if (docStatus.hasProblem) {
const name = declaration.name.getText(sourceFile);
const line = sourceFile!.getLineAndCharacterOfPosition(declaration.getStart()).line + 1;
const line = sourceFile.getLineAndCharacterOfPosition(declaration.getStart()).line + 1;
missingDocblocks.push({
name,
kind: 'variable',
@@ -69,7 +66,7 @@ function checkDocblocks(filePath: string): {
}
}
const line = sourceFile!.getLineAndCharacterOfPosition(node.getStart()).line + 1;
const line = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
if (!symbol) {
const jsDocNodes = ts.getJSDocCommentsAndTags(node);
@@ -105,9 +102,9 @@ function checkDocblocks(filePath: string): {
}
ts.forEachChild(node, checkNode);
}
};
function checkDocumentationContent(symbol: ts.Symbol, node: ts.Node): { hasProblem: boolean; reason: string } {
const checkDocumentationContent = (symbol: ts.Symbol, node: ts.Node) => {
const docComments = symbol.getDocumentationComment(checker);
if (docComments.length === 0) {
const jsDocNodes = ts.getJSDocCommentsAndTags(node);
@@ -129,9 +126,9 @@ function checkDocblocks(filePath: string): {
}
return { hasProblem: false, reason: '' };
}
};
function checkJSDocContent(jsDocNodes: readonly ts.Node[]): { hasProblem: boolean; reason: string } {
const checkJSDocContent = (jsDocNodes: readonly ts.Node[]) => {
if (jsDocNodes.length === 0) {
return { hasProblem: true, reason: 'No docblock found' };
}
@@ -154,7 +151,7 @@ function checkDocblocks(filePath: string): {
}
return { hasProblem: true, reason: 'Docblock contains only modifiers' };
}
};
if (sourceFile) {
checkNode(sourceFile);
@@ -164,9 +161,9 @@ function checkDocblocks(filePath: string): {
success: missingDocblocks.length === 0,
missingDocblocks,
};
}
};
function main() {
const main = () => {
const args = process.argv.slice(2);
if (args.length !== 1) {
@@ -201,6 +198,6 @@ function main() {
console.error('Error:', error);
process.exit(1);
}
}
};
main();
+42
View File
@@ -0,0 +1,42 @@
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const LICENSE_HEADER = `/*
* Copyright (c) 2025-present, Vanilagy and contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/`;
const missingFiles: string[] = [];
const checkFile = (filePath: string) => {
const content = fs.readFileSync(filePath, 'utf8');
if (!content.startsWith(LICENSE_HEADER)) {
missingFiles.push(filePath);
}
};
const checkDirectory = (dirPath: string) => {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
checkDirectory(fullPath);
} else if (entry.name.endsWith('.ts')) {
checkFile(fullPath);
}
}
};
checkDirectory(path.join(__dirname, '..', 'src'));
if (missingFiles.length > 0) {
console.error('Files missing license header:');
missingFiles.forEach(file => console.error(` ${file}`));
process.exit(1);
}