How to use the assetgraph/lib/assetGraphConditions.parse function in assetgraph

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 / 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 assetgraph / assetgraph-builder / lib / transforms / cloneForEachConditionValue.js View on Github external
'data-assetgraph-conditions',
                assetGraphConditions.stringify(htmlSystemJsConditionals)
              );
              clonedHtmlAsset.markDirty();
            }
            const targetUrl = htmlAsset.url.replace(
              /(\.\w+)?$/,
              '.' + conditionValue + '$1'
            );
            clonedHtmlAsset.url = targetUrl;

            for (const relation of assetGraph.findRelations({
              from: clonedHtmlAsset
            })) {
              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) {
                  if (value === conditionValue) {
                    delete dataSystemJsConditions[key];
                    if (Object.keys(dataSystemJsConditions).length === 0) {
                      relation.node.removeAttribute(
                        'data-assetgraph-conditions'
                      );
                    } else {
                      relation.node.setAttribute(
github assetgraph / assetgraph-builder / lib / transforms / cloneForEachConditionValue.js View on Github external
}
          }
        }
        let conditionValues =
          (options.conditions && options.conditions[splitCondition]) ||
          Object.keys(isSeenByConditionValue);
        if (typeof conditionValues === 'string') {
          conditionValues = [conditionValues];
        }
        if (conditionValues.length > 0) {
          for (const conditionValue of conditionValues) {
            const clonedHtmlAsset = htmlAsset.clone();
            const documentElement = clonedHtmlAsset.parseTree.documentElement;
            if (documentElement) {
              const htmlSystemJsConditionals =
                assetGraphConditions.parse(documentElement) || {};
              htmlSystemJsConditionals[splitCondition] = conditionValue;
              documentElement.setAttribute(
                'data-assetgraph-conditions',
                assetGraphConditions.stringify(htmlSystemJsConditionals)
              );
              clonedHtmlAsset.markDirty();
            }
            const targetUrl = htmlAsset.url.replace(
              /(\.\w+)?$/,
              '.' + conditionValue + '$1'
            );
            clonedHtmlAsset.url = targetUrl;

            for (const relation of assetGraph.findRelations({
              from: clonedHtmlAsset
            })) {

assetgraph

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

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages