-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
90 lines (71 loc) · 2.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* jshint node: true */
'use strict';
var chalk = require('chalk');
var analyzePath = require('./lib/helpers/analyze-path');
var logFile = require('./lib/helpers/log-file-stats');
var path = require('path');
var AssetSizesCommand = require('./lib/commands/asset-sizes');
var shimApp = require('./lib/shim-app');
var shimAddonModel = require('./lib/shim-addon-model');
module.exports = {
name: 'ember-cli-asset-sizes-shim',
/*
We override default commands to add tracing flags and expose them to the environment
*/
includedCommands: function() {
return {
'asset-sizes': AssetSizesCommand
}
},
/*
Make sure this returns false before publishing
*/
isDevelopingAddon: function() {
return false;
},
/*
We use output ready to do the analysis so that we have access to the final build as well.
*/
outputReady: function(result) {
var assetCache = this.app.__cacheForAssetStats;
// bail if the user didn't wan't us to log or trace anything
if (!assetCache.isActive) {
return;
}
// asset analytics
console.log(chalk.white('\nAsset Analytics') + chalk.grey('\n––––––––––––––––––––––––––––'));
assetCache._options.root = this.project.root;
assetCache.analyze();
if (assetCache._options.logAssets) {
console.log(chalk.white('\nFinal Build Analytics\n=================='));
var logs = [];
analyzePath(result.directory, result.directory, function(info) {
logs.push(info);
}, { minify: false });
logs.sort(function compare(a, b) {
if (a.stats.size > b.stats.size) {
return -1;
}
if (a.stats.size < b.stats.size) {
return 1;
}
// a must be equal to b
return 0;
});
logs.forEach(function(log) {
logFile(log);
});
}
},
init: function() {
if (this._super && this._super.apply) {
this._super.apply(this, arguments);
}
var pathToApp = path.join(this.project.root, 'node_modules/ember-cli/lib/broccoli/ember-app');
var pathToAddonModel = path.join(this.project.root, 'node_modules/ember-cli/lib/models/addon');
var EmberApp = require(pathToApp);
var Addon = require(pathToAddonModel);
var assetCache = shimApp(EmberApp);
shimAddonModel(Addon, assetCache);
}
};