Skip to content

Instantly share code, notes, and snippets.

@AndrewThian
Created August 5, 2019 02:48
Show Gist options
  • Save AndrewThian/01ead1a8301ff63e946a3a840af32fc7 to your computer and use it in GitHub Desktop.
Save AndrewThian/01ead1a8301ff63e946a3a840af32fc7 to your computer and use it in GitHub Desktop.
const argv = require('minimist')(process.argv.slice(2));
const stats = require('./sass-colors');
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: fs.createReadStream(argv.f),
console: false,
});
const testcases = Object.keys(stats);
let file = '';
let currentMatcher = null;
const handleMatcher = (line) => {
return testcases.some((v) => {
const truthy = line.indexOf(v) >= 0;
if (truthy) currentMatcher = v;
return truthy;
});
};
rl.on('line', (line) => {
if (handleMatcher(line)) {
const parsedLine = line.replace(currentMatcher, stats[currentMatcher]);
file += `${parsedLine} /*${currentMatcher}*/\n`;
} else {
file += `${line}\n`;
}
});
rl.on('close', () => {
console.log(file);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment