Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added exportMinified to builder module

  • Loading branch information...
commit 3af5ebadd75e510a7f8a6ceffa99af710aef9705 1 parent f63e6ca
@caolan caolan authored
Showing with 40 additions and 4 deletions.
  1. +38 −2 lib/builder.js
  2. +2 −2 test/test-builder.js
View
40 lib/builder.js
@@ -1,5 +1,13 @@
-var jsp = require("../deps/UglifyJS/lib/parse-js"),
- pro = require("../deps/UglifyJS/lib/process");
+/**
+ * Module dependencies
+ */
+
+var jsp = require('../deps/UglifyJS/lib/parse-js'),
+ pro = require('../deps/UglifyJS/lib/process'),
+ util = require('./util'),
+ git = require('./git'),
+ fs = require('fs'),
+ _path = require('path');
/**
@@ -16,3 +24,31 @@ exports.minify = function (source) {
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
return pro.gen_code(ast); // compressed code here
};
+
+
+/**
+ * Exports all blobs below path for a give tag, commit or branch to
+ * output_dir as minified js.
+ *
+ * @param {String} wd
+ * @param {String} treeish
+ * @param {String} path
+ * @param {String} output_dir
+ * @param {Function} callback
+ * @api public
+ */
+
+exports.exportMinified = function (wd, treeish, path, output_dir, callback) {
+ git.eachBlob(wd, treeish, path, function (blob, cb) {
+
+ var min = exports.minify(blob.data);
+ var filename = _path.join(output_dir, blob.path);
+ var dirname = _path.dirname(filename);
+
+ util.ensureDir(dirname, function (err) {
+ if (err) return cb(err);
+ fs.writeFile(filename, min, cb);
+ });
+
+ }, callback);
+};
View
4 test/test-builder.js
@@ -1,6 +1,6 @@
var builder = require('../lib/builder'),
- jsp = require("../deps/UglifyJS/lib/parse-js"),
- pro = require("../deps/UglifyJS/lib/process");
+ jsp = require('../deps/UglifyJS/lib/parse-js'),
+ pro = require('../deps/UglifyJS/lib/process');
exports['minify'] = function (test) {
Please sign in to comment.
Something went wrong with that request. Please try again.