These are chat archives for assetgraph/assetgraph

23rd
Nov 2016
Peter Müller
@Munter
Nov 23 2016 14:43
@papandreou I'd like to use seespee, but really I'm only interested in the generated hashes for inline styles and scritps. Would it make sense to add an option to seespee to do that, or should I rather reimplement it myself?
I'd also like to be able to access each directive separately instead of having to match out the relevant hashes
Peter Müller
@Munter
Nov 23 2016 15:11
I see I can get at the directives by querying the graph and accessing the parsetrees of the policies
Peter Müller
@Munter
Nov 23 2016 15:37
ok, most of seespee does thingI don't seem to need, since I can make assumptions it can't. Wrote a script to get the relevant stuff for me:
const AssetGraph = require('assetgraph');

const graph = new AssetGraph({ root: './dist' });

graph
  .logEvents()
  .loadAssets('index.production.html')
  .queue(function addMissingPolicy(assetGraph) {
    // Add ContentSecurityPolicy in order to update it later
    const htmlAsset = assetGraph.findAssets({ type: 'Html', isInitial: true })[0];
    const cspRelation = new assetGraph.HtmlContentSecurityPolicy({
      to: new assetGraph.ContentSecurityPolicy({
        text: ''
      })
    });

    assetGraph.addAsset(cspRelation.to);

    cspRelation.attach(htmlAsset);
  })
  .reviewContentSecurityPolicy({ type: 'Html', isInitial: true }, { update: true })
  .then(assetGraph => {
    const cspAssets = assetGraph.findAssets({ type: 'ContentSecurityPolicy' });

    const parseTrees = cspAssets
      .map(policy => policy.parseTree);

    console.log(parseTrees);
  });
Andreas Lind
@papandreou
Nov 23 2016 15:52
Would be easy enough to add that as a separate mode. PR welcome :)