Skip to content

Instantly share code, notes, and snippets.

@amoshydra
Last active December 11, 2018 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amoshydra/f0a79123fd184088e7e674333d0fc191 to your computer and use it in GitHub Desktop.
Save amoshydra/f0a79123fd184088e7e674333d0fc191 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const glob = require('glob');
module.exports = (options = {}) => {
const collector = {};
const stuffs = glob.sync(options.inputGlob)
.map(filepath => fs.readFileSync(filepath, { encoding: 'utf8' }))
.join('\n')
// Collect then remove import syntax
.replace(/@import url\([^;]+\);/g, (match) => {
collector[match] = true;
return '';
})
;
// Concatenate import syntax at the top of the file
const output = Object.keys(collector).join('\n') + stuffs;
fs.writeFileSync(options.output, output, { encoding: 'utf8' });
};
// Quick hack: If this file is being run directly as a node script, then execute the function immediately
if (__filename.includes(process.argv[1])) {
module.exports({
inputGlob: process.argv[2],
output: process.argv[3],
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment