/[sudobot]/branches/6.x/scripts/add-license-comments.js
ViewVC logotype

Contents of /branches/6.x/scripts/add-license-comments.js

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26