assets-expander
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -0,1 +1,8 @@ | ||
0.2.2 / 2012-06-17 | ||
================== | ||
* Fixed tests (no assert.length). | ||
* Added exceptions in case of unknown group/type or YAML syntax. | ||
* Fixed dev dependencies. | ||
0.2.1 / 2011-04-15 | ||
@@ -2,0 +9,0 @@ ================== |
@@ -7,6 +7,11 @@ var fs = require('fs'), | ||
var AssetsExpander = function(pathToYaml, options) { | ||
if (pathToYaml) { | ||
if (!pathToYaml) return; | ||
try { | ||
this.yamlSource = yaml.eval(fs.readFileSync(pathToYaml).toString()); | ||
this.options = options; | ||
} catch (e) { | ||
throw new AssetsExpander.YamlSyntaxError(e.toString()); | ||
} | ||
this.options = options; | ||
}; | ||
@@ -18,14 +23,14 @@ | ||
}, | ||
groupsFor: function(type) { | ||
return Object.keys(this.yamlSource[type] || {}); | ||
}, | ||
processList: function(mainGroup, options) { | ||
options = options || this.options || {}; | ||
var self = this; | ||
var expandAsset = function(root, asset) { | ||
var matches = []; | ||
if (asset.includes('**/*')) { | ||
@@ -45,9 +50,9 @@ var prefix = asset.substring(0, asset.indexOf('**/*')); | ||
} | ||
return matches; | ||
}; | ||
var expandGroup = function(root, group) { | ||
var groupAssetsExpander = []; | ||
if (group.includes('[')) { | ||
@@ -58,17 +63,23 @@ var tokens = group.split(/[\[\]]/); | ||
} | ||
group.split(',').forEach(function(asset) { | ||
var expanded = expandAsset(root, asset); | ||
if (expanded.length == 0) return; | ||
groupAssetsExpander.push(expanded); | ||
}); | ||
return groupAssetsExpander; | ||
}; | ||
return expandGroup(options.root, mainGroup).flatten().uniq(); | ||
}, | ||
processGroup: function(type, name, localOptions) { | ||
if (!this.yamlSource[type]) | ||
throw new AssetsExpander.UnknownTypeError("Unknown type: '" + type + "'"); | ||
if (!this.yamlSource[type][name]) | ||
throw new AssetsExpander.UnknownGroupError("Unknown group: '" + name + "' for type '" + type + "'"); | ||
var definition = this.yamlSource[type][name], | ||
@@ -78,5 +89,5 @@ assets = [], | ||
self = this; | ||
options.root = path.join(options.root, type); | ||
var processLevel = function(levelDefinition, levelOptions) { | ||
@@ -95,10 +106,10 @@ if (rightjs.isString(levelDefinition)) { | ||
}; | ||
processLevel(definition, options); | ||
return assets.flatten().uniq(); | ||
}, | ||
// private | ||
_scanDir: function(root, pathToDir, recursive, extension) { | ||
@@ -110,7 +121,7 @@ var pattern = new RegExp('^' + pathToDir.replace(/\*/, '.*'), 'g'), | ||
self = this; | ||
fs.readdirSync(path.join(root, path.dirname(pathToDir))).forEach(function(match) { | ||
var fullPath = path.join(root, match), | ||
stat = fs.lstatSync(fullPath); | ||
if (match.match(pattern) && match.match(extPattern) && !stat.isDirectory()) | ||
@@ -121,3 +132,3 @@ matches.push(fullPath); | ||
}); | ||
if (recursive) { | ||
@@ -128,3 +139,3 @@ dirs.forEach(function(dir) { | ||
} | ||
return matches; | ||
@@ -134,2 +145,29 @@ } | ||
AssetsExpander.YamlSyntaxError = function(message) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
}; | ||
AssetsExpander.YamlSyntaxError.prototype.__proto__ = Error.prototype; | ||
AssetsExpander.UnknownGroupError = function(message) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
}; | ||
AssetsExpander.UnknownGroupError.prototype.__proto__ = Error.prototype; | ||
AssetsExpander.UnknownTypeError = function(message) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
}; | ||
AssetsExpander.UnknownTypeError.prototype.__proto__ = Error.prototype; | ||
module.exports = AssetsExpander; |
@@ -11,7 +11,10 @@ { | ||
}, | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"main": "index.js", | ||
"dependencies": { | ||
"rightjs": "2.2.x" | ||
}, | ||
"devDependencies": { | ||
"vows": "*" | ||
} | ||
} |
## What is assets-expander? ## | ||
assets-expander is a node.js library for expanding lists of files defined in YAML file into a flat lists. | ||
assets-expander is a node.js library for expanding list(s) of files defined in YAML file into a flat list(s) of files. | ||
@@ -37,2 +37,4 @@ ## Usage ## | ||
## License ## | ||
Assets-expander is released under the MIT license. |
@@ -25,2 +25,13 @@ var vows = require('vows'), | ||
exports.yamlSuite = vows.describe('incorrect yaml').addBatch({ | ||
'no end line': { | ||
topic: 'broken.yml', | ||
'should give YAML error': function(topic) { | ||
assert.throws(function() { | ||
expanderFor(topic); | ||
}, AssetsExpander.YamlSyntaxError); | ||
} | ||
} | ||
}); | ||
exports.listsSuite = vows.describe('expanding assets').addBatch({ | ||
@@ -39,3 +50,3 @@ 'expand empty': { | ||
'should get array with one element': function(expanded) { | ||
assert.length(expanded, 1); | ||
assert.equal(expanded.length, 1); | ||
}, | ||
@@ -49,3 +60,3 @@ 'should get full path to 1.css': function(expanded) { | ||
'should give array of three files': function(expanded) { | ||
assert.length(expanded, 3); | ||
assert.equal(expanded.length, 3); | ||
}, | ||
@@ -67,3 +78,3 @@ 'should give three files in proper order': function(expanded) { | ||
'should give three assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -80,3 +91,3 @@ 'should give files in natural order': function(expanded) { | ||
'should give three assets': function(expanded) { | ||
assert.length(expanded, 3); | ||
assert.equal(expanded.length, 3); | ||
}, | ||
@@ -92,3 +103,3 @@ 'should give files in natural order': function(expanded) { | ||
'should give 4 assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -105,3 +116,3 @@ 'should give assets in proper order': function(expanded) { | ||
'should give 8 assets': function(expanded) { | ||
assert.length(expanded, 8); | ||
assert.equal(expanded.length, 8); | ||
}, | ||
@@ -122,3 +133,3 @@ 'should give files in proper order': function(expanded) { | ||
'should give 4 assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -135,3 +146,3 @@ 'should give files in proper order': function(expanded) { | ||
'should give 4 assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -148,6 +159,20 @@ 'should give files in proper order': function(expanded) { | ||
exports.groupsSuite = vows.describe('expanding assets groups').addBatch({ | ||
'expand unknown type': { | ||
'should not fail': function(expanded) { | ||
assert.throws(function() { | ||
expanderFor('assets.yml').processGroup('unknown', 'type1', { type: 'css' }); | ||
}, AssetsExpander.UnknownTypeError); | ||
} | ||
}, | ||
'expand unknown group': { | ||
'should not fail': function(expanded) { | ||
assert.throws(function() { | ||
expanderFor('assets.yml').processGroup('stylesheets', 'type1', { type: 'css' }); | ||
}, AssetsExpander.UnknownGroupError); | ||
} | ||
}, | ||
'expanding group #1 from assets.yml': { | ||
topic: group('desktop/public1'), | ||
'should give 5 assets': function(expanded) { | ||
assert.length(expanded, 5); | ||
assert.equal(expanded.length, 5); | ||
}, | ||
@@ -165,3 +190,3 @@ 'should give in proper order': function(expanded) { | ||
'should give 2 assets': function(expanded) { | ||
assert.length(expanded, 2); | ||
assert.equal(expanded.length, 2); | ||
}, | ||
@@ -176,3 +201,3 @@ 'should give in proper order': function(expanded) { | ||
'should give 4 assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -189,3 +214,3 @@ 'should give in proper order': function(expanded) { | ||
'should give 4 assets': function(expanded) { | ||
assert.length(expanded, 4); | ||
assert.equal(expanded.length, 4); | ||
}, | ||
@@ -192,0 +217,0 @@ 'should give in proper order': function(expanded) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
25381
0
683
39
0
1
22
1