Skip to content

Instantly share code, notes, and snippets.

@snichme
Last active December 21, 2015 22:58
Show Gist options
  • Save snichme/6378477 to your computer and use it in GitHub Desktop.
Save snichme/6378477 to your computer and use it in GitHub Desktop.
Example grunt task for Cram.js
module.exports = function(grunt) {
'use strict';
grunt.registerMultiTask('cram', 'Cram runner for grunt', function() {
// Cram failed, tell grunt
function fail (ex) {
grunt.fail.warn('cram failed: ', ex && ex.message || ex);
if (ex && ex.stack) console.log(ex.stack);
}
// If no config file was supplied, search for it in 'standard' places
function findConfigfiles (root) {
['app/index.html', 'app/run.js'].reduce(function(configFiles, file) {
if(path.exists(file)) configFiles.push(file)
return configFiles;
}, []);
}
var cram = require("cram/api"), // Maybe /api isn't the best, other alternative could be /cli
done = this.done(), // Enable grunt async task
options = this.options({ // Merge given options with defaults
appRoot: '',
output: '',
configFiles: null,
includes: [],
excludes: []
}),
configFiles = options.configFiles || findConfigfiles(config.appRoot);
if(configFiles.length === 0) fail("No config file given");
// Cram the code!
cram(configFiles, options).then(done, fail);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment