Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
Created June 12, 2022 13:36
Show Gist options
  • Save CodeMaster7000/ca29f5b388f4640af7632c55700f844a to your computer and use it in GitHub Desktop.
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.
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