Skip to content
Browse files

Adding debug support

  • Loading branch information...
1 parent 4876ad1 commit 42c6c3899a42cff29f7d41cb43f3aa65ab36da0a @serby committed
Showing with 36 additions and 11 deletions.
  1. +36 −11 lib/compact.js
View
47 lib/compact.js
@@ -6,24 +6,28 @@ var path = require('path')
, parser = require("uglify-js").parser
, uglifyer = require("uglify-js").uglify;
-module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
+module.exports.createCompact = function(options) {
+ options = _.extend({
+ webPath: '',
+ debug: false
+ }, options);
- if (!path.existsSync(sourcePath)) {
- throw new Error('Invalid source path \'' + sourcePath + '\'');
+ if (!path.existsSync(options.srcPath)) {
+ throw new Error('Invalid source path \'' + options.srcPath + '\'');
}
- if (!path.existsSync(destinationPath)) {
- mkdirp(destinationPath);
- //throw new Error('Invalid destination path \'' + destinationPath + '\'');
+ if (!path.existsSync(options.destPath)) {
+ mkdirp(options.destPath);
}
-
var namespaces = Object.create(null)
, namespaceGroupsCache = {}
, compressOperationCache = {};
- webPath = webPath || '';
+ function getNamespace(name) {
+ return namespaces[name];
+ }
function addNamespace(name, namespaceSourcePath) {
@@ -50,7 +54,7 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
var paths = [
path.normalize(namespaceSourcePath + '/' + filePath),
- path.normalize(sourcePath + '/' + filePath),
+ path.normalize(options.srcPath + '/' + filePath),
path.normalize(filePath)
];
@@ -82,8 +86,8 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
, compactFilename = targetNamespaces.map(function(namespace) {
return namespace;
}).join('-') + '.js'
- , outputFilename = destinationPath + '/' + compactFilename
- , compactedWebPath = path.normalize(webPath + '/' + compactFilename);
+ , outputFilename = options.destPath + '/' + compactFilename
+ , compactedWebPath = path.normalize(options.webPath + '/' + compactFilename);
// Only compress and write 'compactFilename' once
if (compressOperationCache[compactFilename]) {
@@ -123,7 +127,28 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
return uglifyer.gen_code(ast);
}
+ function copyFile(src, callback) {
+ require('util').pump(fs.createReadStream(src),
+ fs.createWriteStream(options.destPath + '/' + path.basename(src)), function(error) {
+ callback(error, path.normalize(options.webPath + '/' + path.basename(src)));
+ });
+ }
+
+ function processNamespaceGroupsForDebug(namespaceGroups, callback) {
+ var files = [];
+ var res = namespaceGroups.forEach(function(namespace) {
+ files = files.concat(getNamespace(namespace).javascriptFiles);
+ });
+ async.map(files, copyFile, function(error, results) {
+ callback(undefined, results);
+ });
+ }
+
+
function processNamespaceGroups(namespaceGroups, callback) {
+ if (options.debug) {
+ return processNamespaceGroupsForDebug(namespaceGroups, callback);
+ }
var hash = namespaceGroups.join('|');
if (!namespaceGroupsCache[hash]) {
async.map(namespaceGroups, compressAndWriteJavascript, function(error, results) {

0 comments on commit 42c6c38

Please sign in to comment.
Something went wrong with that request. Please try again.