forked from walmartlabs/cookie-cutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-headers.js
32 lines (26 loc) · 961 Bytes
/
fix-headers.js
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
const { readdirSync, lstatSync, readFileSync, writeFileSync } = require("fs");
const { join } = require("path");
const LICENSE = Buffer.from(`/*
Copyright (c) Walmart Inc.
This source code is licensed under the Apache 2.0 license found in the
LICENSE file in the root directory of this source tree.
*/
`);
function traverseDirectory(path) {
for (const file of readdirSync(path)) {
if (lstatSync(join(path, file)).isDirectory() && file !== "node_modules") {
traverseDirectory(join(path, file));
} else if (file.endsWith(".ts") && !file.endsWith(".d.ts")) {
patchHeader(join(path, file));
}
}
}
function patchHeader(path) {
const buffer = readFileSync(path);
const str = buffer.toString();
if (str.indexOf("Copyright (c) Walmart Inc.") === -1) {
writeFileSync(path, LICENSE, { flag: "w" });
writeFileSync(path, buffer, { flag: "a" });
}
}
traverseDirectory(__dirname);