Skip to content

Commit

Permalink
License check
Browse files Browse the repository at this point in the history
  • Loading branch information
j3lte committed Nov 22, 2023
1 parent 2b6bf1f commit 6af7bf3
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Check linting
run: deno lint

- name: Check license
run: deno run check:license

- name: Tests
run: deno task test

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © CaffCode 2023. All Rights Reserved.
Copyright © J.W. Lagendijk 2023. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tasks": {
"check:license": "deno run -A ./scripts/check-license.ts --check",
"format": "deno fmt ./src/",
"lint": "deno lint ./src/",
"test": "deno test --coverage=.coverage",
Expand Down
4 changes: 4 additions & 0 deletions dev_deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export {
assertEquals,
assertRejects,
Expand All @@ -6,3 +8,5 @@ export {
export { emptyDir } from "https://deno.land/std@0.207.0/fs/mod.ts";
export { MockFetch } from "https://deno.land/x/deno_mock_fetch@1.0.1/mod.ts";
export { resolvesNext, stub } from "https://deno.land/std@0.207.0/testing/mock.ts";
export { walk } from "https://deno.land/std@0.207.0/fs/walk.ts";
export { globToRegExp } from "https://deno.land/std@0.207.0/path/glob.ts";
2 changes: 2 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export * from "./src/mod.ts";
61 changes: 61 additions & 0 deletions scripts/check-license.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { globToRegExp, walk } from "../dev_deps.ts";

const EXTENSIONS = [".ts"];
const EXCLUDED_DIRS = ["cov"];

const ROOT = new URL("../", import.meta.url);
const CHECK = Deno.args.includes("--check");
const CURRENT_YEAR = new Date().getFullYear();
const RX_COPYRIGHT = new RegExp(
`// Copyright ([0-9]{4}) J.W. Lagendijk\\. All rights reserved\\. MIT license\\.\n`,
);
const COPYRIGHT = `// Copyright ${CURRENT_YEAR} J.W. Lagendijk. All rights reserved. MIT license.`;

let failed = false;

for await (
const { path } of walk(ROOT, {
exts: EXTENSIONS,
skip: [
...EXCLUDED_DIRS.map((path) => globToRegExp(path)),
/node_modules/,
/npm/,
/script/,
/_local_testing\.ts/,
],
includeDirs: false,
})
) {
const content = await Deno.readTextFile(path);
const match = content.match(RX_COPYRIGHT);

if (!match) {
if (CHECK) {
console.error(`Missing copyright header: ${path}`);
failed = true;
} else {
const contentWithCopyright = COPYRIGHT + "\n" + content;
await Deno.writeTextFile(path, contentWithCopyright);
console.log("Copyright header automatically added to " + path);
}
} else if (parseInt(match[1]) !== CURRENT_YEAR) {
if (CHECK) {
console.error(`Incorrect copyright year: ${path}`);
failed = true;
} else {
const index = match.index ?? 0;
const contentWithoutCopyright = content.replace(match[0], "");
const contentWithCopyright = contentWithoutCopyright.substring(0, index) +
COPYRIGHT + "\n" + contentWithoutCopyright.substring(index);
await Deno.writeTextFile(path, contentWithCopyright);
console.log("Copyright header automatically updated in " + path);
}
}
}

if (failed) {
console.info(`Copyright header should be "${COPYRIGHT}"`);
Deno.exit(1);
}
2 changes: 2 additions & 0 deletions src/deno/Pastebin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { AbstractPastebin } from "../lib/Pastebin.ts";
import { ICreatePasteFileOptions, ICreatePasteTextOptions } from "../lib/interfaces.ts";

Expand Down
1 change: 1 addition & 0 deletions src/lib/Pastebin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ENDPOINTS = {
const formatTypeArr: FormatType[] = [
"4cs", "6502acme", "6502kickass", "6502tasm", "abap", "actionscript", "actionscript3", "ada", "aimms", "algol68", "apache", "applescript", "apt_sources", "arduino", "arm", "asm", "asp", "asymptote", "autoconf", "autohotkey", "autoit", "avisynth", "awk", "bascomavr", "bash", "basic4gl", "dos", "bibtex", "b3d", "blitzbasic", "bmx", "bnf", "boo", "bf", "c", "csharp", "c_winapi", "cpp", "cpp-winapi", "cpp-qt", "c_loadrunner", "caddcl", "cadlisp", "ceylon", "cfdg", "c_mac", "chaiscript", "chapel", "cil", "clojure", "klonec", "klonecpp", "cmake", "cobol", "coffeescript", "cfm", "css", "cuesheet", "d", "dart", "dcl", "dcpu16", "dcs", "delphi", "oxygene", "diff", "div", "dot", "e", "ezt", "ecmascript", "eiffel", "email", "epc", "erlang", "euphoria", "fsharp", "falcon", "filemaker", "fo", "f1", "fortran", "freebasic", "freeswitch", "gambas", "gml", "gdb", "gdscript", "genero", "genie", "gettext", "go", "godot-glsl", "groovy", "gwbasic", "haskell", "haxe", "hicest", "hq9plus", "html4strict", "html5", "icon", "idl", "ini", "inno", "intercal", "io", "ispfpanel", "j", "java", "java5", "javascript", "jcl", "jquery", "json", "julia", "kixtart", "kotlin", "ksp", "latex", "ldif", "lb", "lsl2", "lisp", "llvm", "locobasic", "logtalk", "lolcode", "lotusformulas", "lotusscript", "lscript", "lua", "m68k", "magiksf", "make", "mapbasic", "markdown", "matlab", "mercury", "metapost", "mirc", "mmix", "mk-61", "modula2", "modula3", "68000devpac", "mpasm", "mxml", "mysql", "nagios", "netrexx", "newlisp", "nginx", "nim", "nsis", "oberon2", "objeck", "objc", "ocaml", "ocaml-brief", "octave", "pf", "glsl", "oorexx", "oobas", "oracle8", "oracle11", "oz", "parasail", "parigp", "pascal", "pawn", "pcre", "per", "perl", "perl6", "phix", "php", "php-brief", "pic16", "pike", "pixelbender", "pli", "plsql", "postgresql", "postscript", "povray", "powerbuilder", "powershell", "proftpd", "progress", "prolog", "properties", "providex", "puppet", "purebasic", "pycon", "python", "pys60", "q", "qbasic", "qml", "rsplus", "racket", "rails", "rbs", "rebol", "reg", "rexx", "robots", "roff", "rpmspec", "ruby", "gnuplot", "rust", "sas", "scala", "scheme", "scilab", "scl", "sdlbasic", "smalltalk", "smarty", "spark", "sparql", "sqf", "sql", "sshconfig", "standardml", "stonescript", "sclang", "swift", "systemverilog", "tsql", "tcl", "teraterm", "texgraph", "thinbasic", "typescript", "typoscript", "unicon", "uscript", "upc", "urbi", "vala", "vbnet", "vbscript", "vedit", "verilog", "vhdl", "vim", "vb", "visualfoxpro", "visualprolog", "whitespace", "whois", "winbatch", "xbasic", "xml", "xojo", "xorg_conf", "xpp", "yaml", "yara", "z80", "zxbasic" ];
const expirationTimeArr: string[] = Object.values(ExpirationTime);
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export abstract class AbstractPastebin {
#config: IPastebinOptions;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Scraper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { Evt as Event, to as toEvent } from "https://deno.land/x/evt@v2.5.3/mod.ts";

const ENDPOINTS = {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export interface IPastebinOptions {
api_dev_key?: null | string;
api_user_key?: null | string;
Expand Down
2 changes: 2 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export * from "./deno/Pastebin.ts";
export * from "./lib/Scraper.ts";
export * from "./lib/interfaces.ts";
2 changes: 2 additions & 0 deletions src/node/Pastebin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { AbstractPastebin } from "../lib/Pastebin.ts";
import { ICreatePasteFileOptions, ICreatePasteTextOptions } from "../lib/interfaces.ts";

Expand Down
2 changes: 2 additions & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

export * from "./Pastebin.ts";
export * from "../lib/Scraper.ts";
export * from "../lib/interfaces.ts";
2 changes: 2 additions & 0 deletions test/Pastebin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { assertEquals, assertRejects, MockFetch, resolvesNext, stub } from "../dev_deps.ts";
import { ExpirationTime, IPastebinOptions, Pastebin, PrivacyLevel } from "../mod.ts";

Expand Down
2 changes: 2 additions & 0 deletions test/Scraper.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

import { assertEquals, assertRejects, assertThrows, MockFetch } from "../dev_deps.ts";
import { Scraper } from "../mod.ts";

Expand Down

0 comments on commit 6af7bf3

Please sign in to comment.