Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var _ = require('lodash');
// Start with AssetGraph's built-in resolvers:
_.extend(exports, require('assetgraph').resolvers);
// Install getters for all resolvers in this directory:
require('fs').readdirSync(__dirname).forEach(function (fileName) {
if (/\.js$/.test(fileName) && fileName !== 'index.js') {
exports.__defineGetter__(fileName.replace(/\.js$/, ''), function () {
return require('./' + fileName);
});
}
});
var _ = require('underscore');
// Start with AssetGraph's built-in transforms:
var builtIn = require('assetgraph').transforms;
Object.keys(builtIn).forEach(function (transformName) {
exports.__defineGetter__(transformName, function () {
return builtIn[transformName];
});
});
// Install getters for all transforms in this directory:
require('fs').readdirSync(__dirname).forEach(function (fileName) {
if (/\.js$/.test(fileName) && fileName !== 'index.js') {
exports.__defineGetter__(fileName.replace(/\.js$/, ''), function () {
return require('./' + fileName);
});
}
});
function checkCompatibility(asset, Class) {
if (typeof Class === 'undefined') {
Class = AssetGraph.Asset;
} else if (typeof Class === 'string') {
Class = AssetGraph[Class];
}
return (
asset instanceof Class ||
!asset._type ||
Class.prototype instanceof AssetGraph[asset._type] ||
!!(asset.isImage && Class === AssetGraph.Image) || // Svg is modelled as a subclass of Xml, not Image
!!(asset.isImage && Class === AssetGraph.Font) // Svg can be used as a font as well
);
}
return function cloneForEachConditionValue(assetGraph) {
// Discover all condition values:
for (const splitCondition of splitConditions) {
const isSeenByConditionValue = {};
for (const htmlAsset of assetGraph.findAssets({
type: 'Html',
isInline: false,
...queryObj
})) {
for (const relation of assetGraph.findRelations({ from: htmlAsset })) {
const dataSystemJsConditions =
relation.node && assetGraphConditions.parse(relation.node);
if (dataSystemJsConditions) {
let key = splitCondition + '.js|default';
let value = dataSystemJsConditions[key];
if (!value) {
key = splitCondition + '|default';
value = dataSystemJsConditions[key];
}
if (value) {
isSeenByConditionValue[value] = true;
}
}
}
let conditionValues =
(options.conditions && options.conditions[splitCondition]) ||
Object.keys(isSeenByConditionValue);
if (typeof conditionValues === 'string') {
function checkCompatibility(asset, Class) {
if (typeof Class === 'undefined') {
Class = AssetGraph.Asset;
} else if (typeof Class === 'string') {
Class = AssetGraph[Class];
}
return (
asset instanceof Class ||
!asset._type ||
Class.prototype instanceof AssetGraph[asset._type] ||
!!(asset.isImage && Class === AssetGraph.Image) || // Svg is modelled as a subclass of Xml, not Image
!!(asset.isImage && Class === AssetGraph.Font) // Svg can be used as a font as well
);
}
function checkCompatibility(asset, Class) {
if (typeof Class === 'undefined') {
Class = AssetGraph.Asset;
} else if (typeof Class === 'string') {
Class = AssetGraph[Class];
}
return (
asset instanceof Class ||
!asset._type ||
Class.prototype instanceof AssetGraph[asset._type] ||
!!(asset.isImage && Class === AssetGraph.Image) || // Svg is modelled as a subclass of Xml, not Image
!!(asset.isImage && Class === AssetGraph.Font) // Svg can be used as a font as well
);
}
.parEach(function (imageInfo, i) {
var processedAsset = new AssetGraph.assets.Png({
rawSrc: this.vars[i]
});
processedAsset.url = urlTools.resolveUrl(assetGraph.root, processedAsset.id + processedAsset.defaultExtension);
assetGraph.addAsset(processedAsset);
imageInfo.incomingRelations.forEach(function (incomingRelation) {
var style = incomingRelation.cssRule.style;
style.removeProperty(postProcessPropertyName);
if (imageInfo.ie6) {
// Designates that the processed image should only be used in IE6
// Keep the original relation and use the underscore hack for getting
// IE6 to fetch the processed version:
if (('_' + incomingRelation.propertyName) in style) {
throw new Error("transforms.postProcessCssImages: Underscore hack already in use in Css rule");
}
style.setProperty('_' + incomingRelation.propertyName, 'url(...)', style.getPropertyPriority(incomingRelation.propertyName));
var relation = new AssetGraph.relations.CssImage({
/*
* expush
* https://github.com/Munter/expush
*
* Copyright (c) 2014 Peter Müller
* Licensed under the MIT license.
*/
'use strict';
var fs = require('fs'),
app = require('express')(),
spdy = require('spdy'),
async = require('async'),
AssetGraph = require('assetgraph'),
query = AssetGraph.query,
mime = require('mime'),
root = process.cwd(),
chalk = require('chalk'),
assetGraph = new AssetGraph({root: root + '/'});
// Self signed certs
var options = {
key: fs.readFileSync(__dirname + '/../keys/server.key'),
cert: fs.readFileSync(__dirname + '/../keys/server.crt'),
ca: fs.readFileSync(__dirname + '/../keys/server.csr')
};
function sendAsset(asset, req, res, next) {
var contentType = mime.types[asset.extension.substr(1) || 'application/octet-stream'],
etag = '"' + asset.md5Hex + '"',
ifNoneMatchHeaderValue = req.headers['if-none-match'];
imageInfo.incomingRelations.forEach(function (incomingRelation) {
var style = incomingRelation.cssRule.style;
style.removeProperty(postProcessPropertyName);
if (imageInfo.ie6) {
// Designates that the processed image should only be used in IE6
// Keep the original relation and use the underscore hack for getting
// IE6 to fetch the processed version:
if (('_' + incomingRelation.propertyName) in style) {
throw new Error("transforms.postProcessCssImages: Underscore hack already in use in Css rule");
}
style.setProperty('_' + incomingRelation.propertyName, 'url(...)', style.getPropertyPriority(incomingRelation.propertyName));
var relation = new AssetGraph.relations.CssImage({
propertyName: '_' + incomingRelation.propertyName,
cssRule: incomingRelation.cssRule,
from: incomingRelation.from,
to: processedAsset
});
assetGraph.addRelation(relation, 'after', incomingRelation);
relation.refreshHref();
} else {
// All browsers should see the processed version, replace the old relation:
var relation = new AssetGraph.relations.CssImage({
propertyName: incomingRelation.propertyName,
cssRule: incomingRelation.cssRule,
from: incomingRelation.from,
to: processedAsset
});
assetGraph.addRelation(relation, 'after', incomingRelation);
.parEach(function (imageInfo, i) {
var processedAsset = new AssetGraph.assets.Png({
rawSrc: this.vars[i]
});
processedAsset.url = urlTools.resolveUrl(assetGraph.root, processedAsset.id + processedAsset.defaultExtension);
assetGraph.addAsset(processedAsset);
imageInfo.incomingRelations.forEach(function (incomingRelation) {
var style = incomingRelation.cssRule.style;
style.removeProperty(postProcessPropertyName);
if (imageInfo.ie6) {
// Designates that the processed image should only be used in IE6
// Keep the original relation and use the underscore hack for getting
// IE6 to fetch the processed version:
if (('_' + incomingRelation.propertyName) in style) {
throw new Error("transforms.postProcessCssImages: Underscore hack already in use in Css rule");
}
style.setProperty('_' + incomingRelation.propertyName, 'url(...)', style.getPropertyPriority(incomingRelation.propertyName));
var relation = new AssetGraph.relations.CssImage({
propertyName: '_' + incomingRelation.propertyName,
cssRule: incomingRelation.cssRule,
from: incomingRelation.from,