assets-include
Advanced tools
Comparing version 0.7.0 to 1.0.0
@@ -0,5 +1,16 @@ | ||
[1.0.0 / 2014-03-05](https://github.com/GoalSmashers/assets-include/compare/v0.7.0...v1.0.0) | ||
================== | ||
* Adds JSHint linter and fixes all warnings. | ||
* Adds project's Readme with CLI / lib documentation. | ||
* Adds TravisCI configuration. | ||
* Defaults `root` option to `./public` under config's dir. | ||
* Drops compatibility with node.js 0.6. | ||
* Removes optimist in favor to commander for CLI options parsing. | ||
* Updates assets-expander dependency to 1.0.x. | ||
0.7.0 / 2013-08-12 | ||
================== | ||
* Adds async/defer option to scripts. | ||
* Adds async/defer option to scripts. | ||
@@ -9,3 +20,3 @@ 0.6.2 / 2012-08-15 | ||
* Added crossorigin attribute to link/script when using asset hosts. | ||
* Added crossorigin attribute to link/script when using asset hosts. | ||
@@ -15,3 +26,3 @@ 0.6.1 / 2012-08-09 | ||
* Fixed getting inline assets with cache boosters and asset hosts. | ||
* Fixed getting inline assets with cache boosters and asset hosts. | ||
@@ -21,3 +32,3 @@ 0.6.0 / 2012-08-09 | ||
* Added support for asset hosts (-a ... or assetHosts via API). | ||
* Added support for asset hosts (-a ... or assetHosts via API). | ||
@@ -27,3 +38,3 @@ 0.5.0 / 2012-08-07 | ||
* Adds Windows support with all tests fixed. | ||
* Adds Windows support with all tests fixed. | ||
@@ -33,4 +44,4 @@ 0.4.0 / 2012-08-03 | ||
* Fallback for path.existsSync in node 0.6.x. | ||
* Restricting support to node >= 0.6.0. | ||
* Fallback for path.existsSync in node 0.6.x. | ||
* Restricting support to node >= 0.6.0. | ||
@@ -40,3 +51,3 @@ 0.3.1 / 2012-07-04 | ||
* Fixed inline bundles with cache boosters. | ||
* Fixed inline bundles with cache boosters. | ||
@@ -46,4 +57,4 @@ 0.3.0 / 2012-07-03 | ||
* Added support for new cache boosters created by assets-packager 0.5+. | ||
* Supports cache boosters via -s option from command line. | ||
* Added support for new cache boosters created by assets-packager 0.5+. | ||
* Supports cache boosters via -s option from command line. | ||
@@ -53,3 +64,3 @@ 0.2.1 / 2012-06-19 | ||
* Fixed link tag for CSS type. | ||
* Fixed link tag for CSS type. | ||
@@ -59,5 +70,5 @@ 0.2.0 / 2012-06-19 | ||
* Added list mode - include.list(locator) - for getting a flat list of files with mtime. | ||
* Refactored #group to use #list and some more internals. | ||
* Added binary list option (-l). | ||
* Added list mode - include.list(locator) - for getting a flat list of files with mtime. | ||
* Refactored #group to use #list and some more internals. | ||
* Added binary list option (-l). | ||
@@ -67,3 +78,3 @@ 0.1.1 / 2012-06-19 | ||
* Fixed processing absolute paths. | ||
* Fixed processing absolute paths. | ||
@@ -73,2 +84,2 @@ 0.1.0 / 2012-06-18 | ||
* First version - expanding unbundled, bundled, and inline assets based on YAML config file. | ||
* First version - expanding unbundled, bundled, and inline assets based on YAML config file. |
@@ -1,1 +0,1 @@ | ||
module.exports = require("./lib/include"); | ||
module.exports = require('./lib/include'); |
@@ -1,81 +0,151 @@ | ||
var AssetsExpander = require('assets-expander'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
existsSync = fs.existsSync || path.existsSync; | ||
(function() { | ||
var AssetsExpander = require('assets-expander'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var isWindows = process.platform == 'win32'; | ||
var isWindows = process.platform == 'win32'; | ||
var AssetsInclude = function(pathToConfig, options) { | ||
this.options = options; | ||
this.pathToConfig = pathToConfig; | ||
this.rootPath = process.cwd(); | ||
this.hostsIterator = this._hostsIterator(this.options.assetHosts); | ||
function rewriteSlashes(pathWithStamp) { | ||
return isWindows ? pathWithStamp.replace(/\\/g, '/') : pathWithStamp; | ||
} | ||
if (this.options.root.indexOf(this.rootPath) != 0) | ||
this.options.root = path.normalize(path.join(this.rootPath, this.options.root)); | ||
function assetFragment(assetPathWithMTime, bundleInfo, options) { | ||
var crossOrigin = assetPathWithMTime.indexOf('//') === 0 ? ' crossorigin' : ''; | ||
var loadingMode = options.loadingMode ? | ||
' ' + /(async|defer)/.exec(options.loadingMode)[0] : | ||
''; | ||
if (this.options.cacheBoosters) { | ||
var cacheFile = path.join(this.rootPath, path.dirname(pathToConfig), '.' + path.basename(pathToConfig) + '.json'); | ||
if (existsSync(cacheFile)) | ||
this.cacheInfo = JSON.parse(fs.readFileSync(cacheFile, 'utf8')); | ||
switch(bundleInfo.typeExt) { | ||
case 'css': | ||
case 'less': | ||
return ['<link', ' href="', assetPathWithMTime, '"', ' media="screen"', | ||
' rel="stylesheet', (bundleInfo.typeExt == 'less' ? '/less' : ''), '"', | ||
crossOrigin, '/>'].join(''); | ||
case 'js': | ||
return ['<script', ' src="', assetPathWithMTime, '"', | ||
crossOrigin, loadingMode, '></script>'].join(''); | ||
} | ||
} | ||
}; | ||
AssetsInclude.prototype = { | ||
group: function(locator) { | ||
var self = this, | ||
bundleInfo = this._bundleInfo(locator); | ||
function bundledPath(root, bundleInfo) { | ||
return path.join(root, bundleInfo.type, 'bundled', bundleInfo.group + '.' + bundleInfo.typeExt); | ||
} | ||
function hostsIterator(hostsDefinition) { | ||
if (!hostsDefinition) | ||
return null; | ||
return { | ||
next: function() { | ||
if (!this.cycleList) { | ||
var cycleList = []; | ||
if (hostsDefinition.indexOf('[') > -1) { | ||
var start = hostsDefinition.indexOf('['); | ||
var end = hostsDefinition.indexOf(']'); | ||
var pattern = hostsDefinition.substring(start + 1, end); | ||
pattern.split(',').forEach(function(version) { | ||
cycleList.push(hostsDefinition.replace(/\[([^\]])+\]/, version)); | ||
}); | ||
} else { | ||
cycleList = [hostsDefinition]; | ||
} | ||
this.cycleList = cycleList; | ||
this.index = 0; | ||
} | ||
if (this.index == this.cycleList.length) this.index = 0; | ||
return this.cycleList[this.index++]; | ||
} | ||
}; | ||
} | ||
function bundleInfo(locator) { | ||
var firstSlashIndex = locator.indexOf('/'); | ||
var lastDotIndex = locator.lastIndexOf('.'); | ||
return { | ||
type: locator.substring(0, firstSlashIndex), | ||
typeExt: locator.substring(lastDotIndex + 1), | ||
group: locator.substring(firstSlashIndex + 1, lastDotIndex) | ||
}; | ||
} | ||
var AssetsInclude = function(pathToConfig, options) { | ||
var configDir = path.dirname(pathToConfig); | ||
this.options = options || {}; | ||
this.pathToConfig = pathToConfig; | ||
this.rootPath = process.cwd(); | ||
this.hostsIterator = hostsIterator(this.options.assetHosts); | ||
this.options.root = this.options.root || path.join(configDir, 'public'); | ||
if (this.options.root.indexOf(this.rootPath) !== 0) | ||
this.options.root = path.normalize(path.join(this.rootPath, this.options.root)); | ||
if (this.options.cacheBoosters) { | ||
var cacheFile = path.join(this.rootPath, configDir, '.' + path.basename(pathToConfig) + '.json'); | ||
if (fs.existsSync(cacheFile)) | ||
this.cacheInfo = JSON.parse(fs.readFileSync(cacheFile, 'utf8')); | ||
} | ||
}; | ||
AssetsInclude.prototype.group = function(locator) { | ||
var self = this; | ||
var info = bundleInfo(locator); | ||
return this.list(locator) | ||
.map(function(assetPathWithMTime) { | ||
return self._assetFragment(assetPathWithMTime, bundleInfo); | ||
return assetFragment(assetPathWithMTime, info, self.options); | ||
}) | ||
.join(''); | ||
}, | ||
}; | ||
list: function(locator) { | ||
var self = this, | ||
bundleInfo = this._bundleInfo(locator), | ||
es = function(pathWithStamp) { // escape slashes | ||
return isWindows ? pathWithStamp.replace(/\\/g, '/') : pathWithStamp; | ||
}; | ||
AssetsInclude.prototype.list = function(locator) { | ||
var self = this; | ||
var info = bundleInfo(locator); | ||
if (this.options.bundled) { | ||
return [es(self._assetPathWithStamp(self._bundledPath(bundleInfo), bundleInfo))]; | ||
var assetPath = bundledPath(this.options.root, info); | ||
return [rewriteSlashes(self.assetPathWithStamp(assetPath, info))]; | ||
} else { | ||
var expanderOptions = { | ||
root: this.options.root, | ||
type: bundleInfo.typeExt | ||
type: info.typeExt | ||
}; | ||
// TODO: We should be sharing one instance of AssetsExpander but it does not allow passing 'typeExt' to processGroup | ||
return new AssetsExpander(this.pathToConfig, expanderOptions) | ||
.processGroup(bundleInfo.type, bundleInfo.group) | ||
.processGroup(info.type, info.group, {}) | ||
.map(function(assetPath) { | ||
return es(self._assetPathWithStamp(assetPath, bundleInfo)); | ||
return rewriteSlashes(self.assetPathWithStamp(assetPath, info)); | ||
}); | ||
} | ||
}, | ||
}; | ||
inline: function(locator) { | ||
AssetsInclude.prototype.inline = function(locator) { | ||
if (!this.options.bundled) | ||
return this.group(locator); | ||
var bundleInfo = this._bundleInfo(locator), | ||
data = ''; | ||
var info = bundleInfo(locator); | ||
var data = ''; | ||
var bundlePath = bundledPath(this.options.root, info); | ||
if (this.options.bundled && this.cacheInfo) { | ||
var pathWithStamp = this._assetPathWithStamp(this._bundledPath(bundleInfo), bundleInfo, true); | ||
var pathWithStamp = this.assetPathWithStamp(bundlePath, info, true); | ||
data = fs.readFileSync(path.join(this.options.root, pathWithStamp), 'utf-8'); | ||
} else { | ||
data = fs.readFileSync(this._bundledPath(bundleInfo), 'utf-8'); | ||
data = fs.readFileSync(bundlePath, 'utf-8'); | ||
} | ||
switch (bundleInfo.typeExt) { | ||
switch (info.typeExt) { | ||
case 'css': | ||
return "<style type=\"text/css\">" + data + "</style>"; | ||
return '<style type="text/css">' + data + '</style>'; | ||
case 'js': | ||
return "<script>" + data + "</script>"; | ||
return '<script>' + data + '</script>'; | ||
} | ||
}, | ||
}; | ||
_assetPathWithStamp: function(assetPath, bundleInfo, skipHosts) { | ||
AssetsInclude.prototype.assetPathWithStamp = function(assetPath, bundleInfo, skipHosts) { | ||
var hostPrefix = this.hostsIterator && !skipHosts ? '//' + this.hostsIterator.next() : ''; | ||
@@ -86,75 +156,13 @@ var relativePath = assetPath.replace(this.options.root, ''); | ||
var cacheStamp = this.cacheInfo[bundleInfo.type + '/' + bundleInfo.group]; | ||
return hostPrefix + relativePath.replace(/\.(css|js)/, '-' + cacheStamp + ".$1"); | ||
return hostPrefix + relativePath.replace(/\.(css|js)/, '-' + cacheStamp + '.$1'); | ||
} else { | ||
var mtime = assetPath.indexOf(this.rootPath) == 0 ? | ||
var mtime = assetPath.indexOf(this.rootPath) === 0 ? | ||
fs.statSync(assetPath).mtime.getTime() : | ||
fs.statSync(path.join(this.rootPath, assetPath)).mtime.getTime(); | ||
return hostPrefix + relativePath + "?" + mtime; | ||
return hostPrefix + relativePath + '?' + mtime; | ||
} | ||
}, | ||
}; | ||
_assetFragment: function(assetPathWithMTime, bundleInfo) { | ||
var crossOrigin = assetPathWithMTime.indexOf('//') == 0 ? ' crossorigin' : ''; | ||
var loadingMode = this.options.loadingMode ? | ||
' ' + /(async|defer)/.exec(this.options.loadingMode)[0] : | ||
''; | ||
switch(bundleInfo.typeExt) { | ||
case 'css': | ||
case 'less': | ||
return ["<link", " href=\"", assetPathWithMTime, "\"", " media=\"screen\"", | ||
" rel=\"stylesheet", (bundleInfo.typeExt == 'less' ? '/less' : ''), "\"", | ||
crossOrigin, "/>"].join(''); | ||
case 'js': | ||
return ["<script", " src=\"", assetPathWithMTime, "\"", | ||
crossOrigin, loadingMode, "></script>"].join(''); | ||
} | ||
}, | ||
_bundledPath: function(bundleInfo) { | ||
return path.join(this.options.root, bundleInfo.type, 'bundled', bundleInfo.group + '.' + bundleInfo.typeExt); | ||
}, | ||
_hostsIterator: function(hostsDefinition) { | ||
if (!hostsDefinition) return null; | ||
return { | ||
next: function() { | ||
if (!this.cycleList) { | ||
var cycleList = []; | ||
if (hostsDefinition.indexOf('[') > -1) { | ||
var start = hostsDefinition.indexOf('['); | ||
var end = hostsDefinition.indexOf(']'); | ||
var pattern = hostsDefinition.substring(start + 1, end); | ||
pattern.split(',').forEach(function(version) { | ||
cycleList.push(hostsDefinition.replace(/\[([^\]])+\]/, version)); | ||
}); | ||
} else { | ||
cycleList = [hostsDefinition]; | ||
} | ||
this.cycleList = cycleList; | ||
this.index = 0; | ||
} | ||
if (this.index == this.cycleList.length) this.index = 0; | ||
return this.cycleList[this.index++]; | ||
} | ||
}; | ||
}, | ||
_bundleInfo: function(locator) { | ||
var firstSlashIndex = locator.indexOf('/'), | ||
lastDotIndex = locator.lastIndexOf('.'); | ||
return { | ||
type: locator.substring(0, firstSlashIndex), | ||
typeExt: locator.substring(lastDotIndex + 1), | ||
group: locator.substring(firstSlashIndex + 1, lastDotIndex) | ||
}; | ||
} | ||
}; | ||
module.exports = AssetsInclude; | ||
module.exports = AssetsInclude; | ||
})(); |
{ | ||
"name": "assets-include", | ||
"version": "1.0.0", | ||
"author": "GoalSmashers.com <jakub@goalsmashers.com>", | ||
"name": "assets-include", | ||
"description": "Include assets into your views with ease (assets-packager compatible).", | ||
"version": "0.7.0", | ||
"license": "MIT", | ||
"homepage": "https://github.com/GoalSmashers/assets-include", | ||
"repository": { | ||
"url": "" | ||
"type": "git", | ||
"url": "https://github.com/GoalSmashers/assets-include.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/GoalSmashers/assets-include/issues" | ||
}, | ||
"bin": { | ||
"assetsinc": "./bin/assetsinc" | ||
}, | ||
"main": "index.js", | ||
"files": [ | ||
"bin", | ||
"lib", | ||
"History.md", | ||
"index.js", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
"check": "jshint ./bin/assetsinc .", | ||
"prepublish": "jshint ./bin/assetsinc .", | ||
"test": "vows" | ||
}, | ||
"dependencies": { | ||
"assets-expander": "0.4.x", | ||
"optimist": "0.3.x" | ||
"assets-expander": "1.0.x", | ||
"commander": "2.1.x" | ||
}, | ||
"devDependencies": { | ||
"vows": "*" | ||
"jshint": "2.4.x", | ||
"vows": "0.7.x" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.0" | ||
"node": ">=0.8.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
14517
139
1
0
1
80
1
2
7
+ Addedcommander@2.1.x
+ Addedargparse@0.1.16(transitive)
+ Addedassets-expander@1.0.2(transitive)
+ Addedcommander@2.1.0(transitive)
+ Addedesprima@1.0.4(transitive)
+ Addedjs-yaml@3.0.2(transitive)
+ Addedunderscore@1.7.0(transitive)
+ Addedunderscore.string@2.4.0(transitive)
- Removedoptimist@0.3.x
- Removedassets-expander@0.4.1(transitive)
- Removedoptimist@0.3.7(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedassets-expander@1.0.x