Skip to content

Instantly share code, notes, and snippets.

@ghedamat
Created May 22, 2014 23:24
Show Gist options
  • Save ghedamat/d5f1a62f70b2c9c452c3 to your computer and use it in GitHub Desktop.
Save ghedamat/d5f1a62f70b2c9c452c3 to your computer and use it in GitHub Desktop.
ember-cli assets fingerprint test

notes

this is just a simple test to add basic fingerprinting functionality to ember-cli

the replace is currently done in a particularly ugly way and needs to be heavily improved

// default ember-cli brocfile
var fingerprint = require('broccoli-fingerprint');
//Example with default options
var tree = app.toTree();
tree = fingerprint(tree, {
encoding:'utf8'
, separator: '-'
, keepOriginal: false
, extensions: ['js', 'css']
});
var replace = require('broccoli-replace');
var fs = require('fs');
var path = require('path');
tree = replace(tree, {
files: [
'index.html'
],
patterns: [{
match: /app.js/g,
replacement: function(){
var dir = fs.readdirSync(tree.inputTree.tmpDestDir + "/assets");
dir = dir.filter(function(e){
return e.match(/app-.*\.js/);
});
return dir[0];
}},
{
match: /app.css/g,
replacement: function(){
var dir = fs.readdirSync(tree.inputTree.tmpDestDir + "/assets");
dir = dir.filter(function(e){
return e.match(/app-.*\.css/);
});
return dir[0];
}}
]
});
module.exports = tree;
{
"name": "tha",
"version": "0.0.0",
"private": true,
"directories": {
"doc": "doc",
"test": "test"
},
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
}, "repository": "https://github.com/stefanpenner/ember-cli",
"engines": {
"node": ">= 0.10.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"ember-cli": "0.0.28",
"originate": "0.1.5",
"broccoli-ember-hbs-template-compiler": "^1.5.0",
"loom-generators-ember-appkit": "^1.1.1",
"express": "^4.1.1",
"body-parser": "^1.2.0",
"broccoli-fingerprint ": "git+https://github.com/ghedamat/broccoli-fingerprint#mattia/preserve-assets-path", "broccoli-replace ": "^0.1.6",
"glob": "^3.2.9"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment