Skip to content

Instantly share code, notes, and snippets.

@nikoloza
Last active September 12, 2016 09:59
Show Gist options
  • Save nikoloza/3b5acb1e55d8e305e881 to your computer and use it in GitHub Desktop.
Save nikoloza/3b5acb1e55d8e305e881 to your computer and use it in GitHub Desktop.
Clean Vigour CSS from unwanted properties
var fs = require('fs')
var LineByLine = require('line-by-line')
var bundle = 'bundle.css'
var _bundle = '_bundle.css'
var file = 'new.less'
var _file = '_new.less'
var cleanRegEx = /^((\s+)?((\.|\@|\d).+|color|background|border|a|html|body|div|section|div|body|section|img|thumb|\:\:).+|((\s+)?\}))/m
var emptyRegEx = /^((.+\,\n)+)?(.+\{)(\n+|\s+)\}\n?/gm
var resetRegEx = /\/\*\s(file.+reset)(\n|.)+(file.+variables.+)/gm
fs.exists(file, (exists) => {
if (exists) fs.unlink(file)
fs.writeFile(file, '')
})
fs.exists(_file, (exists) => {
if (exists) fs.unlink(_file)
fs.writeFile(_file, '')
})
fs.exists(_bundle, (exists) => {
if (exists) fs.unlink(_bundle)
fs.writeFile(_bundle, '')
})
fs.readFile(bundle, 'utf8', (err, data) => {
if (err) throw err
var result = data.replace(resetRegEx, '')
fs.writeFile(_bundle, result)
var bundleLines = new LineByLine(_bundle)
bundleLines.on('line', (line) => {
if (cleanRegEx.test(line)) {
fs.appendFileSync(_file, `${line}\n`)
}
})
bundleLines.on('end', () => {
fs.readFile(_file, 'utf8', (err, data) => {
if (err) throw err
var result = data.replace(emptyRegEx, '').replace(emptyRegEx, '')
fs.appendFileSync(file, `body.vijf {\n ${result} \n}`, 'utf8')
fs.unlink(_file)
fs.unlink(_bundle)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment