deno.land / std@0.157.0 / _tools / check_licence.ts

check_licence.ts
نووسراو ببینە
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
55
56
57
58
59
60
// Copyright 2022-2022 the Deno authors. All rights reserved. MIT license.
const EXTENSIONS = [".mjs", ".js", ".ts", ".rs"];const EXCLUDED_PATHS = [ ".git", "node/_module", "dotenv/testdata", "fs/testdata", "http/testdata", "node/_module/cjs", "node/_module/node_modules", "node/_tools", "node/testdata",];
const ROOT = new URL("../", import.meta.url).pathname.slice(0, -1);const FAIL_FAST = Deno.args.includes("--fail-fast");
const COPYRIGHT_REGEX = /\/\/ Copyright \d{4}-\d{4} (the )?Deno authors. All rights reserved. MIT license./;
let shouldFail = false;
function walk(dir: string) { for (const x of Deno.readDirSync(dir)) { const filePath = `${dir}/${x.name}`;
if (x.isDirectory) { walk(filePath); continue; }
const isExcluded = EXCLUDED_PATHS .map((x) => filePath.includes(x)) .some((x) => x); if ( isExcluded || !EXTENSIONS.map((x) => filePath.endsWith(x)).some((x) => x) ) { continue; }
const content = Deno.readTextFileSync(filePath); const hasNotice = content .split("\n") .filter((_, i) => i < 10) .map((x) => COPYRIGHT_REGEX.test(x)) .some((x) => x);
if (!hasNotice) { console.error(`Missing Copyright Notice: ${filePath}`); if (FAIL_FAST) Deno.exit(1); shouldFail = true; } }}
walk(ROOT);if (shouldFail) Deno.exit(1);
std

Version Info

Tagged at
a year ago