Socket
Socket
Sign inDemoInstall

assets-expander

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-expander - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

lib/core.js

57

History.md

@@ -0,5 +1,14 @@

[1.0.0 / 2014-02-25](https://github.com/GoalSmashers/assets-expander/compare/v0.5.0...v1.0.0)
==================
* Drops node 0.6 support in favour to node 0.10.
* Drops our private build of yaml.js in favour to js-yaml.
* Removes Makefile and test.bat and adds cross-platform test runner via `npm test`.
* Fixes code formatting following JSHint guidelines. Adds `npm run check`.
* Adds code formatting checks on prepublish step.
0.5.0 / 2012-09-06
==================
* Added ability to override stylesheets/javascripts directories via 'path' option to #processGroup method.
* Added ability to override stylesheets/javascripts directories via 'path' option to #processGroup method.

@@ -9,3 +18,3 @@ 0.4.1 / 2012-08-07

* Fixed Yaml comments parsing on Windows.
* Fixed Yaml comments parsing on Windows.

@@ -15,4 +24,4 @@ 0.4.0 / 2012-08-06

* Added full windows support with tests.
* Patched yaml.js to support CRLF line endings.
* Added full windows support with tests.
* Patched yaml.js to support CRLF line endings.

@@ -22,4 +31,4 @@ 0.3.1 / 2012-08-02

* Added direct path to vows dependency.
* Added fs.existsSync fallback to get rid of 0.8 warnings.
* Added direct path to vows dependency.
* Added fs.existsSync fallback to get rid of 0.8 warnings.

@@ -29,3 +38,3 @@ 0.3.0 / 2012-07-09

* Removed 'rightjs' dependency as it's an overkill to use it.
* Removed 'rightjs' dependency as it's an overkill to use it.

@@ -35,3 +44,3 @@ 0.2.3 / 2012-06-17

* Fixed error classes (missing name which affects instanceof).
* Fixed error classes (missing name which affects instanceof).

@@ -41,5 +50,5 @@ 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.
* Fixed tests (no assert.length).
* Added exceptions in case of unknown group/type or YAML syntax.
* Fixed dev dependencies.

@@ -49,3 +58,3 @@ 0.2.1 / 2011-04-15

* Fixes expanding folder/prefix* wildcard paths.
* Fixes expanding folder/prefix* wildcard paths.

@@ -55,3 +64,3 @@ 0.2.0 / 2011-04-07

* **type** property (denoting file extension, e.g. 'css') is now passed to processGroup method allowing reuse of single AssetsExpander instance for finding various types of files.
* **type** property (denoting file extension, e.g. 'css') is now passed to processGroup method allowing reuse of single AssetsExpander instance for finding various types of files.

@@ -61,5 +70,5 @@ 0.1.2 / 2011-04-05

* Fixed repeating entries when processing groups.
* Fixed processing wildcard attributes with extra characters, e.g. 'abstract-*'.
* Fixed parsing lists elements.
* Fixed repeating entries when processing groups.
* Fixed processing wildcard attributes with extra characters, e.g. 'abstract-*'.
* Fixed parsing lists elements.

@@ -69,3 +78,3 @@ 0.1.1 / 2011-04-03

* Added support for dashes (-) in YAML files.
* Added support for dashes (-) in YAML files.

@@ -75,8 +84,8 @@ 0.1.0 / 2011-03-26

* First version of assets-expander library.
* Implemented assets expanding from YAML files.
* Implemented expanding:
* simple list - 'asset1,asset2,asset3'
* wildcard flat lists - 'asset*'
* wildcard multi-level lists - '\*\*/\*'
* single level sublists - 'folder/[asset1,asset2,asset3]'
* First version of assets-expander library.
* Implemented assets expanding from YAML files.
* Implemented expanding:
* simple list - 'asset1,asset2,asset3'
* wildcard flat lists - 'asset*'
* wildcard multi-level lists - '\*\*/\*'
* single level sublists - 'folder/[asset1,asset2,asset3]'

@@ -1,1 +0,1 @@

module.exports = require("./lib/assets");
module.exports = require('./lib/assets');

@@ -1,16 +0,25 @@

var fs = require('fs'),
path = require('path'),
yaml = require('../vendor/yaml'),
existsSync = fs.existsSync || path.existsSync;
/**
* assets-expander - https://github.com/GoalSmashers/assets-expander
* Released under the terms of MIT license
*
* Copyright (C) 2011-2014 GoalSmashers.com
*/
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
require('./core');
var AssetsExpander = function(pathToYaml, options) {
if (!pathToYaml) return;
this.options = options;
this.sortingFix = /0\.8\./.test(process.versions.node);
try {
this.yamlSource = yaml.eval(fs.readFileSync(pathToYaml, 'utf-8'));
} catch (e) {
throw new AssetsExpander.YamlSyntaxError(e.toString());
if (pathToYaml) {
try {
this.yamlSource = yaml.safeLoad(fs.readFileSync(pathToYaml, 'utf-8'));
} catch (e) {
throw new AssetsExpander.YamlSyntaxError(e);
}
}
this.options = options;
};

@@ -33,5 +42,6 @@

var matches = [];
var prefix;
if (asset.indexOf('**/*') > -1) {
var prefix = asset.substring(0, asset.indexOf('**/*'));
prefix = asset.substring(0, asset.indexOf('**/*'));
self._scanDir(path.join(root, prefix), '*', true, options.type).forEach(function(matched) {

@@ -41,3 +51,3 @@ matches.push(matched);

} else if (asset.indexOf('*') > -1) {
var prefix = '';
prefix = '';
if (asset.indexOf('/') > -1) {

@@ -52,3 +62,3 @@ prefix = asset.substring(0, asset.lastIndexOf('/'));

var expanded = path.join(root, asset) + '.' + options.type;
if (existsSync(expanded)) matches.push(expanded);
if (fs.existsSync(expanded)) matches.push(expanded);
}

@@ -67,3 +77,2 @@

}
group.split(',').forEach(function(asset) {

@@ -83,11 +92,11 @@ expandAsset(root, asset).forEach(function(expanded) {

if (!this.yamlSource[type])
throw new AssetsExpander.UnknownTypeError("Unknown type: '" + type + "'");
throw new AssetsExpander.UnknownTypeError('Unknown type: \'' + type + '\'');
if (!this.yamlSource[type][name])
throw new AssetsExpander.UnknownGroupError("Unknown group: '" + name + "' for type '" + type + "'");
throw new AssetsExpander.UnknownGroupError('Unknown group: \'' + name + '\' for type \'' + type + '\'');
var definition = this.yamlSource[type][name],
assets = [],
options = Object.merge(Object.clone(this.options), localOptions || {}),
self = this;
var definition = this.yamlSource[type][name];
var assets = [];
var options = Object.merge(Object.clone(this.options), localOptions || {});
var self = this;

@@ -120,7 +129,7 @@ options.root = path.join(options.root, localOptions.path || type);

_scanDir: function(root, pathToDir, recursive, extension) {
var pattern = new RegExp('^' + pathToDir.replace(/\*/, '.*'), 'g'),
extPattern = new RegExp(extension + '$'),
dirs = [],
matches = [],
self = this;
var pattern = new RegExp('^' + pathToDir.replace(/\*/, '.*'), 'g');
var extPattern = new RegExp(extension + '$');
var dirs = [];
var matches = [];
var self = this;

@@ -137,2 +146,5 @@ fs.readdirSync(path.join(root, path.dirname(pathToDir))).forEach(function(match) {

if (this.sortingFix)
matches = matches.sort();
if (recursive) {

@@ -150,3 +162,3 @@ dirs.forEach(function(dir) {

AssetsExpander.YamlSyntaxError = function(message) {
AssetsExpander.YamlSyntaxError = function(e) {
Error.call(this);

@@ -156,5 +168,7 @@ Error.captureStackTrace(this, this.constructor);

this.name = 'YamlSyntaxError';
this.message = message;
this.message = e.message;
return this;
};
AssetsExpander.YamlSyntaxError.prototype.__proto__ = Error.prototype;
AssetsExpander.YamlSyntaxError.prototype = new Error();

@@ -167,4 +181,6 @@ AssetsExpander.UnknownGroupError = function(message) {

this.message = message;
return this;
};
AssetsExpander.UnknownGroupError.prototype.__proto__ = Error.prototype;
AssetsExpander.UnknownGroupError.prototype = new Error();

@@ -177,37 +193,7 @@ AssetsExpander.UnknownTypeError = function(message) {

this.message = message;
return this;
};
AssetsExpander.UnknownTypeError.prototype.__proto__ = Error.prototype;
AssetsExpander.UnknownTypeError.prototype = new Error();
module.exports = AssetsExpander;
// Core extensions
Array.prototype.unique = function() {
var uniques = [];
this.forEach(function(value) {
if (uniques.indexOf(value) == -1)
uniques.push(value);
});
return uniques;
};
Object.each = function(object, callback, scope) {
for (var key in object) {
callback.call(scope, key, object[key]);
}
};
Object.clone = function(object) {
var clone = {};
Object.each(object, function(key, value) {
clone[key] = value;
});
return clone;
};
Object.merge = function(object1, object2) {
var target = Object.clone(object1);
Object.each(object2, function(key, value) {
target[key] = value;
});
return target;
};
{
"name": "assets-expander",
"version": "1.0.0",
"author": "Jakub Pawlowicz <jakub@goalsmashers.com> (http://twitter.com/GoalSmashers)",
"description": "A well-tested Assets expander - specify assets graph in YAML file and easily expand them into a linear list",
"keywords": ["css", "javascript", "assets", "yaml"],
"description": "A well-tested tool for expanding any files structure defined in YAML file into a flat list of files",
"license": "MIT",
"keywords": [
"css",
"javascript",
"assets",
"yaml"
],
"homepage": "http://github.com/GoalSmashers/assets-expander",

@@ -11,13 +18,44 @@ "repository": {

},
"version": "0.5.0",
"bugs": {
"url": "https://github.com/GoalSmashers/assets-expander/issues"
},
"main": "index.js",
"files": [
"lib",
"History.md",
"index.js",
"LICENSE"
],
"scripts": {
"test": "node_modules/.bin/vows test/*-test.js"
"check": "jshint .",
"prepublish": "jshint .",
"test": "vows"
},
"devDependencies": {
"vows": "*"
"js-yaml": "3.0.x",
"jshint": "2.4.x",
"vows": "0.7.x"
},
"jshintConfig": {
"browser": false,
"camelcase": true,
"curly": false,
"eqeqeq": false,
"eqnull": true,
"immed": true,
"indent": 2,
"latedef": true,
"multistr": false,
"noarg": true,
"node": true,
"plusplus": false,
"quotmark": "single",
"strict": false,
"trailing": true,
"undef": true,
"unused": true
},
"engines": {
"node": ">=0.6.0"
"node": ">=0.8.0"
}
}
}
[![build status](https://secure.travis-ci.org/GoalSmashers/assets-expander.png)](http://travis-ci.org/GoalSmashers/assets-expander)
## What is assets-expander? ##
assets-expander is a node.js library for expanding list(s) of files defined in YAML file into a flat list(s) of files.
Assets-expander is a node.js library that turns a glob-like declarations from YAML file into a list of files.
Just see below for examples.

@@ -16,8 +17,12 @@ ## Usage ##

var expander = new AssetsExpander('assets.yml', { root: 'path/to/public/dir' });
expander.processGroup('stylesheets', 'public') // gets a flat list of assets in public group
expander.processGroup('javascripts', 'public') // gets a flat list of assets in public group
### How to define assets.yml file? ###
It depends what files you want to have in *public* group, but in general the file should look something like this.
Just go with something like:
javascripts:
public:
vendor: 'undescore,modernizr'
public: '**/*'
stylesheets:

@@ -28,3 +33,10 @@ public:

Then if you have the following directory structure:
javascripts
- vendor
- underscore.js
- modernizr.js
- public
- main.js
- fallback.js
stylesheets

@@ -36,8 +48,12 @@ - reset.css

executing the code above will get you a list of full paths to these 4 files:
then running the following code will give you the files you need:
['.../stylesheets/reset.css', '.../stylesheets/shared.css', '.../stylesheets/base.css', '.../stylesheets/home.css']
> expander.processGroup('stylesheets', 'public')
> ['stylesheets/reset.css', 'stylesheets/shared.css', 'stylesheets/base.css', 'stylesheets/home.css']
> expander.processGroup('javascripts', 'public')
> ['javascripts/vendor/underscore.js', 'javascripts/vendor/modernizr.js', 'javascripts/public/main.js', 'javascripts/public/fallback.js']
## License ##
Assets-expander is released under the MIT license.
Assets-expander is released under the MIT license.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc