Created
June 12, 2022 13:36
-
-
Save CodeMaster7000/ca29f5b388f4640af7632c55700f844a to your computer and use it in GitHub Desktop.
A program to remove comments from all of your JavaScript files. Note that you must have the 'glob' module installed in order for this program to work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs") | |
const strip = require("strip-comments") | |
const prettier = require("prettier") | |
var glob = require("glob") | |
try { | |
glob("**/*.js", { ignore: "**/node_modules/**" }, function (error, files) { | |
files.forEach((element) => { | |
var file = fs.openSync(element, "r+") | |
var data = fs.readFileSync(file, "utf8") | |
const strings = strip(data) | |
const pretty = prettier.format(strings, { semi: false, parser: "babel" }) | |
fs.writeFileSync(element, pretty) | |
console.log('Comments Removed from ' + element) | |
}) | |
}) | |
} catch (error) { | |
console.log(error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment