|
| 1 | +/* |
| 2 | + * NoScript - a Firefox extension for whitelist driven safe JavaScript execution |
| 3 | + * |
| 4 | + * Copyright (C) 2005-2026 Giorgio Maone <https://maone.net> |
| 5 | + * |
| 6 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify it under |
| 9 | + * the terms of the GNU General Public License as published by the Free Software |
| 10 | + * Foundation, either version 3 of the License, or (at your option) any later |
| 11 | + * version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along with |
| 18 | + * this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +const fs = require('fs'); |
| 22 | +const path = require('path'); |
| 23 | + |
| 24 | +const decomment = require('decomment'); |
| 25 | + |
| 26 | +const dir = process.argv[2]; |
| 27 | + |
| 28 | +if (!dir) { |
| 29 | + console.error('Please provide a directory path!'); |
| 30 | + process.exit(1); |
| 31 | +} |
| 32 | + |
| 33 | +function processSource(s) { |
| 34 | + return decomment( |
| 35 | + s, { space: true, tolerant: true } |
| 36 | + ); |
| 37 | +} |
| 38 | + |
| 39 | +function processDir(dir) { |
| 40 | + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
| 41 | + const { name } = entry; |
| 42 | + const entryPath = path.join(dir, name); |
| 43 | + if (entry.isDirectory()) { |
| 44 | + processDir(entryPath); |
| 45 | + } else if (entry.isFile() && path.extname(name) == ".js") { |
| 46 | + try { |
| 47 | + console.log(`Processing ${entryPath}...`); |
| 48 | + fs.writeFileSync(entryPath, processSource( |
| 49 | + fs.readFileSync(entryPath, 'utf8') |
| 50 | + )); |
| 51 | + console.log(`Done processing ${entryPath}...`); |
| 52 | + } catch (err) { |
| 53 | + console.error(`Error processing ${entryPath}:`, err.message); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +processDir(dir); |
0 commit comments