Skip to content

Instantly share code, notes, and snippets.

@bguiz
Last active August 29, 2015 13:57
Show Gist options
  • Save bguiz/9926259 to your computer and use it in GitHub Desktop.
Save bguiz/9926259 to your computer and use it in GitHub Desktop.
Modernizr 3.0 command line
/*globals console, process, __dirname */
var modernizr = require('./lib/cli');
var fs = require('fs');
var args = process.argv.slice(2);
console.log('CLI arguments:', args);
if (args.length < 3) {
console.error('Expects three arguments: config, output, minifiedOutput');
process.exit(1);
}
var fileNames = {
config: args[0],
output: args[1],
minifiedOutput: args[2]
};
//Read config file, and parse as JSON
var configFile = __dirname + '/' + fileNames.config;
fs.readFile(configFile, function(err, data) {
if (err) {
console.error('Failed to read config file:', configFile);
process.exit(2);
}
var config;
try {
config = JSON.parse(data);
} catch (x) {
console.error('Failed to parse config file as valid JSON');
process.exit(3);
}
//invoke the modernizr build step + write outputs to file
modernizr.build(config, function(result) {
var outputFile = __dirname + '/' + fileNames.output;
fs.writeFile(outputFile, result.code, function(err) {
if (err) {
console.error('Failed to write to output file:', err);
}
});
var minifiedOutputFile = __dirname + '/' + fileNames.minifiedOutput;
fs.writeFile(minifiedOutputFile, result.min, function(err) {
if (err) {
console.error('Failed to write to minified output file:', err);
}
});
});
});

Modernizr 3.0 command line

Want to use the Modernizer 3.0 (still in pre-release) via the command line?

Just plonk this file in the root of the directory where you have modernizr checked out, and run it

Sample usage

git clone git@github.com:Modernizr/Modernizr.git modernizr
cd modernizr
wget https://gist.githubusercontent.com/bguiz/9926259/raw/README.md #plonked. `curl` works too.
cp ./lib/config-all.json ./config-custom.json
#edit config-custom.json
node modernizr-cli.js config-custom.json modernizr-custom.js modernizr-custom.min.js
@patrickkettner
Copy link

Thanks a ton for writing this up!

@bguiz
Copy link
Author

bguiz commented Apr 3, 2014

@patrickkettner pleasure - glad it helped!

@bguiz
Copy link
Author

bguiz commented Apr 10, 2014

Turned this into a command line utility: modernizr-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment