assetgraph
Advanced tools
Comparing version 0.3.44 to 0.4.0
@@ -6,3 +6,2 @@ #!/usr/bin/env node | ||
var AssetGraph = require('../lib/AssetGraph'), | ||
transforms = AssetGraph.transforms, | ||
seq = require('seq'), | ||
@@ -14,14 +13,15 @@ commandLineOptions = require('optimist') | ||
new AssetGraph().queue( | ||
transforms.loadAssets(commandLineOptions._), | ||
transforms.populate(), | ||
transforms.minifyAssets(), | ||
function (assetGraph) { | ||
new AssetGraph() | ||
.loadAssets(commandLineOptions._) | ||
.populate() | ||
.minifyAssets() | ||
.queue(function (assetGraph) { | ||
var javaScriptsInOrder = assetGraph.collectAssetsPostOrder(assetGraph.findAssets({isInitial: true})[0]); | ||
assetGraph.findRelations({type: 'JavaScriptOneInclude'}).forEach(function (relation) { | ||
relation.detach(); | ||
}); | ||
console.log('javascript:' + assetGraph.collectAssetsPostOrder(assetGraph.findAssets({isInitial: true})[0]).map(function (javaScriptAsset) { | ||
console.log('javascript:' + javaScriptsInOrder.map(function (javaScriptAsset) { | ||
return javaScriptAsset.text; | ||
}).join(';') + ';void(null)'); | ||
} | ||
).run(); | ||
}) | ||
.run(); |
@@ -6,3 +6,2 @@ #!/usr/bin/env node | ||
urlTools = require('../lib/util/urlTools'), | ||
transforms = AssetGraph.transforms, | ||
commandLineOptions = require('optimist') | ||
@@ -16,10 +15,13 @@ .usage("$0 [--root <urlOrDirectory>] [--updatehtml] <inputHtmlFileName>\n\n" + | ||
new AssetGraph({root: commandLineOptions.root}).queue( | ||
transforms.loadAssets(commandLineOptions._.map(urlTools.fsFilePathToFileUrl)), | ||
transforms.populate({ | ||
new AssetGraph({root: commandLineOptions.root}) | ||
.loadAssets(commandLineOptions._.map(urlTools.fsFilePathToFileUrl)) | ||
.populate({ | ||
followRelations: {to: {url: /^file:/}, type: AssetGraph.query.not('HtmlAnchor')} | ||
}), | ||
transforms.addCacheManifest({type: 'Html'}), | ||
transforms.writeAssetsToDisc({type: 'CacheManifest', incoming: {from: {type: 'Html', isInitial: true}}}), | ||
commandLineOptions.updatehtml && transforms.writeAssetsToDisc({type: 'Html', isInitial: true}) | ||
).run(); | ||
}) | ||
.addCacheManifest({type: 'Html'}) | ||
.writeAssetsToDisc({type: 'CacheManifest', incoming: {from: {type: 'Html', isInitial: true}}}) | ||
.if(commandLineOptions.updatehtml) | ||
.writeAssetsToDisc({type: 'Html', isInitial: true}) | ||
.endif() | ||
.writeStatsToStderr() | ||
.run(); |
@@ -8,3 +8,2 @@ #!/usr/bin/env node | ||
urlTools = require('../lib/util/urlTools'), | ||
transforms = AssetGraph.transforms, | ||
commandLineOptions = require('optimist') | ||
@@ -15,9 +14,9 @@ .usage('$0 [--root <urlOrDirectory>] [-o <outputCssFileName>] <inputCssFileName>') | ||
new AssetGraph({root: commandLineOptions.root}).queue( | ||
transforms.loadAssets(commandLineOptions._.map(urlTools.fsFilePathToFileUrl)), | ||
transforms.populate({ | ||
new AssetGraph({root: commandLineOptions.root}) | ||
.loadAssets(commandLineOptions._.map(urlTools.fsFilePathToFileUrl)) | ||
.populate({ | ||
followRelations: {type: 'CssImage'} | ||
}), | ||
transforms.inlineRelations({type: 'CssImage'}), | ||
function(assetGraph) { | ||
}) | ||
.inlineRelations({type: 'CssImage'}) | ||
.run(function (err, assetGraph) { | ||
var initialCssAsset = assetGraph.findAssets({isInitial: true})[0]; | ||
@@ -29,3 +28,2 @@ if (commandLineOptions.o) { | ||
} | ||
} | ||
).run(); | ||
}); |
#!/usr/bin/env node | ||
var AssetGraph = require('../lib/AssetGraph'), | ||
transforms = AssetGraph.transforms; | ||
var AssetGraph = require('../lib/AssetGraph'); | ||
AssetGraph({root: './'}).queue( | ||
transforms.loadAssets('*.html'), | ||
transforms.populate({ | ||
AssetGraph({root: './'}) | ||
.loadAssets('*.html') | ||
.populate({ | ||
followRelations: {to: {url: /^file:/}}, | ||
@@ -15,2 +14,2 @@ onError: function (err, assetGraph, asset) { | ||
}) | ||
).run(); | ||
.run(); |
#!/usr/bin/env node | ||
var AssetGraph = require('../lib/AssetGraph'), | ||
transforms = AssetGraph.transforms; | ||
var AssetGraph = require('../lib/AssetGraph'); | ||
AssetGraph({root: __dirname + '/inlineImages'}).queue( | ||
transforms.loadAssets('*.html'), | ||
transforms.populate(), | ||
transforms.inlineRelations({type: ['HtmlImage', 'CssImage']}), | ||
transforms.writeAssetsToStdout({type: 'Html'}) | ||
).run(); | ||
AssetGraph({root: __dirname + '/inlineImages'}) | ||
.loadAssets('*.html') | ||
.populate() | ||
.inlineRelations({type: ['HtmlImage', 'CssImage']}) | ||
.writeAssetsToStdout({type: 'Html'}) | ||
.run(); |
@@ -50,3 +50,3 @@ /** | ||
this.root = urlTools.fsDirToFileUrl(process.cwd()); | ||
} else if (!/^[a-z0-9]+:/.test(this.root)) { // No protocol, assume local file system path | ||
} else if (!/^[a-z0-9\+]+:/.test(this.root)) { // No protocol, assume local file system path | ||
this.root = urlTools.fsDirToFileUrl(this.root); | ||
@@ -68,2 +68,3 @@ } else { | ||
}; | ||
this._transformContexts = [{transforms: [], callbacks: []}]; | ||
}; | ||
@@ -75,3 +76,2 @@ | ||
AssetGraph.relations = require('./relations'); | ||
AssetGraph.transforms = require('./transforms'); | ||
AssetGraph.query = require('./query'); | ||
@@ -91,2 +91,7 @@ AssetGraph.resolvers = require('./resolvers'); | ||
/** | ||
* Avoid instanceof checks: | ||
*/ | ||
isAssetGraph: true, | ||
/** | ||
* assetGraph.addAsset(asset) | ||
@@ -351,3 +356,3 @@ * ========================== | ||
* Will throw an error if the base asset for any relation couldn't be found. | ||
* | ||
* @return {AssetGraph} The AssetGraph instance (chaining-friendly). | ||
@@ -410,4 +415,3 @@ * @api public | ||
// Transforms: | ||
runTransform: function (transform, cb) { | ||
_runTransform: function (transform, cb) { | ||
var that = this, | ||
@@ -437,45 +441,99 @@ startTime = new Date(), | ||
_proceedWithNextTransform: function () { | ||
var that = this; | ||
if (!that._transformQueue) { | ||
that._transformQueue = []; | ||
// Implicitly create a new TransformQueue: | ||
if: function (condition) { | ||
return new TransformQueue(this).if(condition); | ||
} | ||
}); | ||
function TransformQueue(assetGraph) { | ||
if (assetGraph) { | ||
this.assetGraph = assetGraph; | ||
} | ||
this.transforms = []; | ||
this.conditions = []; | ||
} | ||
TransformQueue.prototype = { | ||
queue: function () { // ... | ||
if (!this.conditions.length || this.conditions[this.conditions.length - 1]) { | ||
Array.prototype.push.apply(this.transforms, arguments); | ||
} | ||
return this; | ||
}, | ||
run: function (assetGraph, cb) { | ||
if (assetGraph && assetGraph.isAssetGraph) { | ||
this.assetGraph = assetGraph; | ||
} else if (typeof assetGraph === 'function') { | ||
cb = assetGraph; | ||
} | ||
this._proceed(cb); | ||
}, | ||
if: function (condition) { | ||
this.conditions.push(condition); | ||
return this; | ||
}, | ||
endif: function () { | ||
this.conditions.pop(); | ||
return this; | ||
}, | ||
_proceed: function (cb) { | ||
var that = this, | ||
nextTransform; | ||
// Skip past falsy transforms: | ||
while (that._transformQueue.length && !that._transformQueue[0]) { | ||
that._transformQueue.shift(); | ||
} | ||
if (that._transformQueue.length) { | ||
that.runTransform(that._transformQueue.shift(), function (err) { | ||
do { | ||
nextTransform = that.transforms.shift(); | ||
} while (!nextTransform && that.transforms.length); | ||
if (nextTransform) { | ||
that.assetGraph._runTransform(nextTransform, function (err) { | ||
if (err) { | ||
if (that._onComplete) { | ||
that._onComplete(err); | ||
if (cb) { | ||
cb(err); | ||
} else { | ||
that.emit('error', err); | ||
that.assetGraph.emit('error', err); | ||
} | ||
} else { | ||
that._proceedWithNextTransform(); | ||
that._proceed(cb); | ||
} | ||
}); | ||
} else { | ||
if (that._onComplete) { | ||
that._onComplete(null, that); | ||
} | ||
} else if (cb) { | ||
cb(null, that.assetGraph); | ||
} | ||
}, | ||
} | ||
}; | ||
queue: function () { // ... | ||
if (!this._transformQueue) { | ||
this._transformQueue = []; | ||
} | ||
Array.prototype.push.apply(this._transformQueue, arguments); | ||
AssetGraph.transforms = {}; | ||
AssetGraph.registerTransform = function (functionOrFileName, name) { | ||
if (typeof functionOrFileName === 'function') { | ||
name = name || functionOrFileName.name; | ||
AssetGraph.transforms[name] = functionOrFileName; | ||
} else { | ||
// File name | ||
name = name || Path.basename(functionOrFileName, '.js'); | ||
functionOrFileName = Path.resolve(process.cwd(), functionOrFileName); // Absolutify if not already absolute | ||
AssetGraph.transforms.__defineGetter__(name, function () { | ||
return require(functionOrFileName); | ||
}); | ||
} | ||
TransformQueue.prototype[name] = function () { // ... | ||
this.queue(AssetGraph.transforms[name].apply(this, arguments)); | ||
return this; | ||
}, | ||
}; | ||
// Make assetGraph.<transformName>(options) a shorthand for creating a new TransformQueue: | ||
AssetGraph.prototype[name] = function () { // ... | ||
var transformQueue = new TransformQueue(this); | ||
return transformQueue[name].apply(transformQueue, arguments); | ||
}; | ||
}; | ||
run: function (cb) { | ||
this._onComplete = cb; | ||
this._proceedWithNextTransform(); | ||
return this; | ||
} | ||
// Register ./transforms/*: | ||
require('fs').readdirSync(Path.resolve(__dirname, 'transforms')).forEach(function (fileName) { | ||
AssetGraph.registerTransform(Path.resolve(__dirname, 'transforms', fileName)); | ||
}); | ||
module.exports = AssetGraph; |
@@ -5,3 +5,3 @@ { | ||
"repository": "git://github.com/One-com/assetgraph.git", | ||
"version": "0.3.44", | ||
"version": "0.4.0", | ||
"maintainers": [ | ||
@@ -8,0 +8,0 @@ { |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
343023
7153
128
930