Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding namespace path and create dest path if it doesn't exist

  • Loading branch information...
commit 7b94cb08aaa820ca91619468b84cf137329d7926 1 parent 4a5a155
@serby authored
Showing with 31 additions and 6 deletions.
  1. +28 −3 lib/compact.js
  2. +3 −3 package.json
View
31 lib/compact.js
@@ -1,5 +1,6 @@
var path = require('path')
, fs = require('fs')
+ , mkdirp = require('mkdirp')
, async = require('async')
, _ = require('underscore')
, parser = require("uglify-js").parser
@@ -13,16 +14,18 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
}
if (!path.existsSync(destinationPath)) {
- throw new Error('Invalid destination path \'' + destinationPath + '\'');
+ mkdirp(destinationPath);
+ //throw new Error('Invalid destination path \'' + destinationPath + '\'');
}
+
var namespaces = Object.create(null)
, namespaceGroupsCache = {}
, compressOperationCache = {};
webPath = webPath || '';
- function addNamespace(name) {
+ function addNamespace(name, namespaceSourcePath) {
if (!name) {
throw new Error('Invalid namespace');
@@ -44,7 +47,26 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
if (!namespace.javascriptFiles) {
namespace.javascriptFiles = [];
}
- namespace.javascriptFiles.push(path.normalize(sourcePath + '/' + filePath));
+
+ var paths = [
+ path.normalize(namespaceSourcePath + '/' + filePath),
+ path.normalize(sourcePath + '/' + filePath),
+ path.normalize(filePath)
+ ];
+
+ var jsPath;
+ for (var i = 0; i < paths.length; i++) {
+ if (path.existsSync(paths[i])) {
+ jsPath = paths[i];
+ continue;
+ }
+ }
+
+ if (jsPath === undefined) {
+ throw new Error('Unable to find \'' + filePath + '\'');
+ }
+
+ namespace.javascriptFiles.push(jsPath);
return namespace;
}
@@ -69,6 +91,9 @@ module.exports.createCompact = function(sourcePath, destinationPath, webPath) {
}
targetNamespaces.forEach(function(namespace) {
+ if (!namespaces[namespace]) {
+ callback(new Error('Unknown namespace \'' + namespace + '\'. Ensure you provide a namespace that has been defined with \'addNamespace()\''));
+ }
javascriptFiles = javascriptFiles.concat(namespaces[namespace].javascriptFiles);
});
View
6 package.json
@@ -2,7 +2,7 @@
"author": "Paul Serby <paul@serby.net>",
"name": "compact",
"description": "A JavaScript and CSS compacting middleware for express",
- "version": "0.0.1",
+ "version": "0.0.2",
"repository": {
"type": "git",
"url": "git://github.com/serby/compact.git"
@@ -17,12 +17,12 @@
"dependencies": {
"underscore": "~1.3",
"async": "~0.1",
- "uglify-js": "~1.2"
+ "uglify-js": "~1.2",
+ "mkdirp": "~0.3"
},
"devDependencies": {
"mocha": "*",
"should": "*",
- "mkdirp": "~0.3",
"async": "~0.1",
"asyncjs": "~0.0"
}
Please sign in to comment.
Something went wrong with that request. Please try again.