Skip to content

Commit

Permalink
started to work on issue5
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Brosset committed Jun 8, 2012
1 parent fd52d70 commit e612f46
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
4 changes: 3 additions & 1 deletion libs/visitorshandler.js
Expand Up @@ -2,6 +2,8 @@ var clone = require("./clone.js");


var phases = {
// Just after the config is loaded (so that visitors can modify it), this is the very first thing executed
onAfterConfigLoaded: "onAfterConfigLoaded",
// At the very start, even before any files have been packaged
onStart: "onStart",
// Before starting to package a set of files together
Expand Down Expand Up @@ -105,7 +107,7 @@ function runVisitorsOnPhase(phase, visitors, args, callback) {
runVisitorsOnPhase(phase, visitors, args, callback);
}].concat(args));
} catch(e) {
logger.logError("Visitor " + visitor.name + " crashed with error: " + e);
logger.logError("Visitor " + visitor.name + " crashed on phase " + phase + "\n\twith error: " + e + "\n\twith arguments: " + args);
runVisitorsOnPhase(phase, visitors, args, callback);
}
}
Expand Down
56 changes: 32 additions & 24 deletions packman.js
Expand Up @@ -23,6 +23,7 @@ require("./libs/logger.js");
var fs = require("fs");
var fu = require("./libs/fileutils.js")();
var configReader = require("./libs/config.js");
var vh = require("./libs/visitorshandler.js");

var argv = require('optimist')
.usage('Usage:\n packman')
Expand Down Expand Up @@ -68,37 +69,44 @@ if(argv.h) {

if(config !== null && Object.keys(config.packages).length > 0) {

var isEnvReady = require("./libs/env.js").prepare(config.destination, config.eraseIfExists);
// TODO: clean this up a bit to do it once rather than in merger.js again
var globalVisitors = vh.getVisitorInstances(config.visitors);
vh.runVisitorsOnPhase(vh.phases.onAfterConfigLoaded, globalVisitors, [config], function() {

if(isEnvReady) {
var allSourceFiles = require("./libs/finder.js").getAllSourceFiles(config.source);
var isEnvReady = require("./libs/env.js").prepare(config.destination, config.eraseIfExists);

if(allSourceFiles.length > 0) {
var resolvedPackages = require("./libs/clone.js").clone(config.packages);
resolvedPackages = require("./libs/resolver.js").resolveFilePaths(resolvedPackages, allSourceFiles);
config.resolvedPackages = resolvedPackages;
if(isEnvReady) {
var allSourceFiles = require("./libs/finder.js").getAllSourceFiles(config.source);

logger.logInfo("Getting started with: source=" + config.source + ", destination=" + config.destination + ", eraseIfExists=" + config.eraseIfExists);
if(allSourceFiles.length > 0) {

var merger = require("./libs/merger.js");
var resolvedPackages = require("./libs/clone.js").clone(config.packages);
resolvedPackages = require("./libs/resolver.js").resolveFilePaths(resolvedPackages, allSourceFiles);
config.resolvedPackages = resolvedPackages;

merger.merge(config, function() {
console.log("");
var time = ((new Date().getTime()) - startTime) / 1000;
if(!argv.w) {
console.log((" packman did it again! Have a great day! (" + time + " sec)").yellow.bold);
}
console.log("");
if(callback) callback();
});
}
logger.logInfo("Getting started with: source=" + config.source + ", destination=" + config.destination + ", eraseIfExists=" + config.eraseIfExists);

var merger = require("./libs/merger.js");

merger.merge(config, function() {
console.log("");
var time = ((new Date().getTime()) - startTime) / 1000;
if(!argv.w) {
console.log((" packman did it again! Have a great day! (" + time + " sec)").yellow.bold);
}
console.log("");
if(callback) callback();
});
}

allFileStats = getAllFileStats(allSourceFiles, config.source);
allFileStats = getAllFileStats(allSourceFiles, config.source);

} else {
logger.logWarning("packman could not prepare the destination directory, there's an existing file at " + config.destination);
logger.logWarning("Make sure you configure the proper destination directory path or set the 'eraseIfExists' config flag to true.");
}

} else {
logger.logWarning("packman could not prepare the destination directory, there's an existing file at " + config.destination);
logger.logWarning("Make sure you configure the proper destination directory path or set the 'eraseIfExists' config flag to true.");
}
});

}
}
Expand Down
11 changes: 7 additions & 4 deletions visitors/uglify.js
Expand Up @@ -17,8 +17,7 @@ function getMinifiedContent(content, path, mangle) {
ast = minifier.ast_squeeze(ast);
return minifier.gen_code(ast);
} catch(e) {
logger.logError("Could not minify file " + path);
logger.logDebug(e.message);
logger.logError("Could not uglify file " + path + ", ", e);
return content;
}
}
Expand All @@ -28,8 +27,12 @@ function getFileNameExtension(fileName) {
}

module.exports.onFileContent = function(callback, config, fileObject) {
if(getFileNameExtension(fileObject.path) === ".js") {
fileObject.content = getMinifiedContent(fileObject.content, fileObject.path, true) + ";";
try {
if(getFileNameExtension(fileObject.path) === ".js") {
fileObject.content = getMinifiedContent(fileObject.content, fileObject.path, true) + ";";
}
} catch(e) {
logger.logError("uglify visitor could not uglify " + fileObject.path, e);
}
callback();
};

1 comment on commit e612f46

@captainbrosset
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to issue #5

Please sign in to comment.