-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 1.76 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
'use strict';
const addon = require('ember-cli/lib/models/addon');
const Helper = require('./lib/utils/helper');
const heimdallLogger = require('heimdalljs-logger');
const logger = heimdallLogger('ember-cli-prebuild-addon');
const TREES_TO_NOT_PREBUILD = ['app', 'styles', 'public', 'test-support'];
const path = require('path');
const fs = require('fs');
module.exports = {
name: 'ember-cli-prebuild-addon',
includedCommands() {
return require('./lib/commands');
},
init() {
this._super.init && this._super.init.apply(this, arguments);
const origTreeFor = addon.prototype.treeFor;
addon.prototype.treeFor = function(treeType) {
let addonCacheKey = this.cacheKeyForTree(treeType);
let cachedItem = _treeCache.getItem(addonCacheKey)
if(cachedItem) {
return cachedItem;
}
if (!TREES_TO_NOT_PREBUILD.includes(treeType) && ((this.app && this.app.options.overrideIsDevelopingAddon === true) || !this.isDevelopingAddon()) ) {
const addonVersion = this.pkg.version ? this.pkg.version : '';
let targetGroup = this.project.targets.browsers;
let prebuildPath = this.app && this.app.prebuildPath;
prebuildPath = Helper.getPrebuiltPath(prebuildPath, this._packageInfo.realPath);
const prebuiltTree = Helper.getPreBuiltDirForTargetGroup(targetGroup, addonVersion, prebuildPath)
if(fs.existsSync(path.join(prebuiltTree, treeType))) {
logger.info(`Returning ${treeType} tree for ${this.name}`);
console.log(`**** Returning ${treeType} tree for ${this.name}`);
if (addonCacheKey) {
_treeCache.setItem(addonCacheKey, prebuiltTree);
}
return prebuiltTree;
}
}
return origTreeFor.call(this, treeType);
}
},
};