Skip to content

Commit

Permalink
Adding a build api.
Browse files Browse the repository at this point in the history
  • Loading branch information
doctyper committed Jun 3, 2013
1 parent e74492b commit 8ed5889
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* jshint node: true */
module.exports = function (opts, callback) {
"use strict";

opts = opts || {};

var grunt = require("grunt");
var fs = require("fs");
var cp = require("child_process");

var Gruntfile = require("../Gruntfile")(grunt);
var settings = grunt.config();

var verbose = (opts.verbose !== false);
delete opts.verbose;

if (typeof opts !== "undefined") {
var configPath = "./config-all.json";

if (fs.existsSync(configPath)) {
var modernizrConfig = grunt.file.readJSON(configPath);

for (var key in opts) {
modernizrConfig[key] = opts[key];
}

grunt.file.write(configPath, JSON.stringify(modernizrConfig, null, 2));
}
}

var build = cp.spawn("grunt", ["build"], {
stdio: verbose ? "inherit" : [0, "pipe", 2]
});

build.on("exit", function (code) {
var uglify = settings.uglify || {};
var source = uglify.dist.src[0];
var dest = uglify.dist.dest;

if (source && dest && typeof callback === "function") {
callback.call(grunt, {
code: grunt.file.read(source),
min: grunt.file.read(dest)
});
}

process.exit(code);
});
};
8 changes: 8 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* jshint node: true */
"use strict";

var grunt = require("grunt");

module.exports = {
build: require("./build")
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"scripts": {
"test": "grunt test"
},
"main": "./lib/cli",
"repository": {
"type": "git",
"url": "git://github.com/Modernizr/Modernizr.git"
Expand Down

0 comments on commit 8ed5889

Please sign in to comment.