forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brocfile.js
204 lines (179 loc) · 5.36 KB
/
Brocfile.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* jshint node: true */
var es6 = require('broccoli-es6-module-transpiler');
var concat = require('broccoli-concat');
var uglify = require('broccoli-uglify-js');
var es3SafeRecast = require('broccoli-es3-safe-recast');
var env = process.env.EMBER_ENV;
var pickFiles = require('broccoli-static-compiler');
var merge = require('broccoli-merge-trees');
var moveFile = require('broccoli-file-mover');
var wrap = require('broccoli-wrap');
var jshint = require('broccoli-jshint');
var defeatureify = require('broccoli-defeatureify');
var version = require('git-repo-version')(10);
var renderTemplate = require('broccoli-render-template');
var yuidoc = require('broccoli-yuidoc');
var replace = require('broccoli-string-replace');
var derequire = require('broccoli-derequire');
function moveFromLibAndMainJS(packageName, vendored){
var root = vendored ? 'bower_components/' + packageName + "/packages/" + packageName + '/lib':
'packages/' + packageName + '/lib';
var tree = pickFiles(root, {
srcDir: '/',
files: [ '**/*.js' ],
destDir: '/' + packageName
});
tree = moveFile(tree, {
srcFile: packageName + '/main.js',
destFile: '/' + packageName + '.js'
});
tree = es6(tree, {moduleName: true});
if (env === 'production'){
tree = es3SafeRecast(tree);
}
return tree;
}
function minify(tree, name){
var config = require('./config/ember-defeatureify');
tree = defeatureify(tree, {
debugStatements: config.options.debugStatements,
enableStripDebug: config.stripDebug
});
tree = moveFile(tree, {
srcFile: name + '.js',
destFile: '/' + name + '.prod.js'
});
var uglified = moveFile(uglify(tree, {mangle: true}),{
srcFile: name + '.prod.js',
destFile: '/' + name + '.min.js'
});
return merge([uglified, tree]);
}
function testTree(libTree, packageName){
var test = pickFiles('packages/' + packageName + '/tests', {
srcDir: '/',
files: [ '**/*.js' ],
destDir: '/'
});
var jshinted = jshint(libTree);
jshinted = wrap(jshinted, {
wrapper: [ "if (!QUnit.urlParams.nojshint) {\n", "\n}"]
});
return merge([jshinted, test]);
}
// Moves the file to .ejs, compiles it, moves it back.
function versionStamp(tree, fileName){
var ejsName = fileName + '.ejs';
tree = moveFile(tree, {
srcFile: fileName,
destFile: '/' + ejsName
});
tree = renderTemplate(tree, {
versionStamp: version
});
return moveFile(tree, {
srcFile: ejsName.replace(/\.ejs$/, '.html'),
destFile: fileName
});
}
var emberDataFiles = moveFromLibAndMainJS('ember-data', false);
var activeModelAdapterFiles = moveFromLibAndMainJS('activemodel-adapter', false);
var emberInflectorFiles = moveFromLibAndMainJS('ember-inflector', true);
var loaderJS = pickFiles('bower_components/loader.js', {
srcDir: '/',
files: [ 'loader.js' ],
destDir: '/'
});
var yuidocTree = yuidoc('packages', {
srcDir: '/',
destDir: 'docs',
yuidoc: {
"name": "The ember-data API",
"description": "The ember-data API: a data persistence library for Ember.js",
"version": version,
"logo": "http://f.cl.ly/items/1A1L432s022u1O1q1V3p/ember%20logo.png",
"url": "https://github.com/emberjs/data",
"options": {
"paths": [
"packages/ember-data/lib",
"packages/activemodel-adapter/lib",
"packages/ember-inflector/lib"
],
"exclude": "vendor",
"outdir": "docs/build"
}
}
});
var libFiles = merge([
emberInflectorFiles,
emberDataFiles,
activeModelAdapterFiles
]);
var testFiles = merge([
testTree(emberDataFiles, 'ember-data'),
testTree(activeModelAdapterFiles, 'activemodel-adapter')
]);
var namedAMDBuild = concat(libFiles, {
inputFiles: ['**/*.js'],
separator: '\n',
outputFile: '/ember-data.named-amd.js'
});
var globalBuild = concat(merge([libFiles, loaderJS]), {
inputFiles: ['loader.js', '**/*.js'],
separator: '\n',
outputFile: '/ember-data.js'
});
globalBuild = wrap(globalBuild, {
wrapper: [ "(function(global){\n", "\n global.DS = requireModule('ember-data')['default'];\n })(this);"]
});
globalBuild = versionStamp(globalBuild, 'ember-data.js');
namedAMDBuild = versionStamp(namedAMDBuild, 'ember-data.named-amd.js');
if (env === 'production'){
testFiles = es3SafeRecast(testFiles);
}
testFiles = concat(testFiles, {
inputFiles: ['**/*.js'],
separator: '\n',
wrapInEval: true,
wrapInFunction: true,
outputFile: '/tests.js'
});
var testRunner = pickFiles('tests', {
srcDir: '/',
inputFiles: [ '**/*' ],
destDir: '/'
});
var bower = pickFiles('bower_components', {
srcDir: '/',
inputFiles: [ '**/*' ],
destDir: '/bower_components'
});
var configurationFiles = pickFiles('config/package_manager_files', {
srcDir: '/',
destDir: '/',
inputFiles: [ '**/*' ]
});
configurationFiles = replace(configurationFiles, {
files: [ 'bower.json', 'component.json', 'package.json' ],
pattern: {
match: /VERSION_STRING_PLACEHOLDER/g,
replacement: version
}
});
var trees = [
testFiles,
namedAMDBuild,
testRunner,
bower,
configurationFiles
];
if (env === 'production') {
globalBuild = derequire(globalBuild);
var minifiedAMD = minify(namedAMDBuild, 'ember-data.named-amd');
var minifiedGlobals = minify(globalBuild, 'ember-data');
trees.push(yuidocTree);
trees.push(minifiedAMD);
trees.push(minifiedGlobals);
}
trees.push(globalBuild);
module.exports = merge(trees);