forked from ember-cli/ember-resolver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
110 lines (86 loc) · 2.64 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*jshint node:true*/
'use strict';
var VersionChecker = require('ember-cli-version-checker');
var Funnel = require('broccoli-funnel');
var MergeTrees = require('broccoli-merge-trees');
var renameMap = {
'src/main.js': 'app.js',
'src/resolver.js': 'resolver.js',
'src/ui/styles/app.css': 'styles/app.css',
'src/ui/index.html': 'index.html'
};
module.exports = {
name: 'dangerously-set-unified-resolver',
isDevelopingAddon: function() {
return true
},
included: function() {
this._super.included.apply(this, arguments);
var checker = new VersionChecker(this);
var dep = checker.for('ember-cli', 'npm');
if (dep.lt('2.0.0')) {
this.monkeyPatchVendorFiles();
}
this.app.import('vendor/ember-resolver/legacy-shims.js');
},
treeForApp() {
var srcTree = new Funnel('src', {
destDir: 'src'
});
var appTree = new Funnel('app');
var unifiedTree = new MergeTrees([appTree, srcTree]);
var withAppCompatibility = new Funnel(unifiedTree, {
getDestinationPath: function getDestinationPath(relativePath) {
return renameMap[relativePath] || relativePath;
}
});
return withAppCompatibility;
},
monkeyPatchVendorFiles: function() {
var filesToAppend = this.app.legacyFilesToAppend;
var legacyResolverIndex = filesToAppend.indexOf(this.app.bowerDirectory + '/ember-resolver/dist/modules/ember-resolver.js');
if (legacyResolverIndex > -1) {
filesToAppend.splice(legacyResolverIndex, 1);
}
},
treeForApp() {
var srcTree = new Funnel('src', {
destDir: 'src'
});
var appTree = new Funnel('app');
var unifiedTree = new MergeTrees([appTree, srcTree]);
var withAppCompatibility = new Funnel(unifiedTree, {
getDestinationPath: function getDestinationPath(relativePath) {
return renameMap[relativePath] || relativePath;
}
});
return withAppCompatibility;
},
/**
* Ember CLI treats 'templates' differently than the rest of app. Here
* we tell it where our templates are.
*/
treeForTemplates() {
return new Funnel('src', {
include: ['**/*.hbs'],
destDir: 'src'
});
var appTree = new Funnel('app');
var unifiedTree = new MergeTrees([appTree, srcTree]);
return unifiedTree;
},
/**
* Ember CLI puts all templates in a hard-coded 'templates' directory so
* we have to move them.
*/
postprocessTree(type, tree) {
if (type === 'template') {
return new Funnel(tree, {
getDestinationPath: function getDestinationPath(relativePath) {
return relativePath.replace('templates/src/', 'src/');
}
});
}
return tree;
}
};