/[sudobot]/trunk/scripts/add-license-comments.js
ViewVC logotype

Contents of /trunk/scripts/add-license-comments.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (show annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: text/javascript
File size: 2480 byte(s)
chore: add trunk
1 #!/usr/bin/env node
2
3 /*
4 * This file is part of SudoBot.
5 *
6 * Copyright (C) 2021-2023 OSN Developers.
7 *
8 * SudoBot is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * SudoBot is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 const fs = require("fs/promises");
23 const path = require("path");
24 const { existsSync } = require("fs");
25
26 const sourceDirectory = path.join(
27 __dirname,
28 existsSync(path.join(__dirname, "src")) ? "." : "../src"
29 );
30
31 const licenseComment = `/*
32 * This file is part of SudoBot.
33 *
34 * Copyright (C) 2021-${new Date().getFullYear()} OSN Developers.
35 *
36 * SudoBot is free software; you can redistribute it and/or modify it
37 * under the terms of the GNU Affero General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or
39 * (at your option) any later version.
40 *
41 * SudoBot is distributed in the hope that it will be useful, but
42 * WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU Affero General Public License for more details.
45 *
46 * You should have received a copy of the GNU Affero General Public License
47 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
48 */`;
49
50 async function addLicenseComment(directory = sourceDirectory) {
51 const files = await fs.readdir(directory);
52
53 for (const file of files) {
54 const filePath = path.join(directory, file);
55 const stat = await fs.lstat(filePath);
56
57 if (stat.isDirectory()) {
58 await addLicenseComment(filePath);
59 continue;
60 }
61
62 if (!file.endsWith(".ts")) {
63 continue;
64 }
65
66 const fileContents = await fs.readFile(filePath, { encoding: "utf-8" });
67
68 if (fileContents.trim().startsWith("/*")) continue;
69
70 console.log("Modifying: ", filePath);
71 await fs.writeFile(filePath, `${licenseComment}\n\n${fileContents}`);
72 }
73 }
74
75 addLicenseComment();

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26