How to use assetgraph - 10 common examples

To help you get started, we’ve selected a few assetgraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assetgraph / assetgraph-builder / lib / resolvers / index.js View on Github external
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);
        });
    }
});
github assetgraph / assetgraph-builder / lib / transforms / index.js View on Github external
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);
        });
    }
});
github Munter / hyperlink / lib / index.js View on Github external
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
  );
}
github assetgraph / assetgraph-builder / lib / transforms / cloneForEachConditionValue.js View on Github external
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') {
github Munter / hyperlink / lib / index.js View on Github external
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
  );
}
github Munter / hyperlink / lib / index.js View on Github external
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
  );
}
github assetgraph / assetgraph-builder / lib / transforms / postProcessCssImages.js View on Github external
.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({
github Munter / expush / lib / expush.js View on Github external
/*
 * 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'];
github assetgraph / assetgraph-builder / lib / transforms / postProcessCssImages.js View on Github external
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);
github assetgraph / assetgraph-builder / lib / transforms / postProcessCssImages.js View on Github external
.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,

assetgraph

An auto discovery dependency graph based optimization framework for web pages and applications

BSD-3-Clause
Latest version published 8 months ago

Package Health Score

59 / 100
Full package analysis

Similar packages