forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brocfile.js
199 lines (176 loc) · 5.11 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
/* jshint node: true */
var es6 = require('broccoli-es6-module-transpiler');
var PackageResolver = require('es6-module-transpiler-package-resolver');
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 amdBuild = require('./lib/amd-build');
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 yuidoc = require('broccoli-yuidoc');
var replace = require('broccoli-replace');
var stew = require('broccoli-stew');
var path = require('path');
var fs = require('fs');
var jscsTree = require('broccoli-jscs');
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'
});
tree = removeSourceMappingURL(tree);
var uglified = moveFile(uglify(tree, {mangle: true}),{
srcFile: name + '.prod.js',
destFile: '/' + name + '.min.js'
});
return merge([uglified, tree], {overwrite: true});
}
function testTree(packageName){
var test = pickFiles('packages/' + packageName + '/tests', {
srcDir: '/',
files: [ '**/*.js' ],
destDir: '/' + packageName
});
var jshinted = jshint('packages/' + packageName + '/', {
jshintrcPath: path.join(__dirname, '.jshintrc')
});
jshinted = wrap(jshinted, {
wrapper: [ "if (!QUnit.urlParams.nojshint) {\n", "\n}"],
});
jshinted = pickFiles(jshinted, {
files: ['{lib,tests}/**/*.js'],
srcDir: '/',
destDir: '/' + packageName + '-jshint'
});
return merge([jshinted, test]);
}
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/addon"
],
"exclude": "vendor",
"outdir": "docs/build"
}
}
});
// Excludes tests files from package path
function package(packagePath, vendorPath) {
vendorPath = vendorPath || 'packages/';
return pickFiles(vendorPath + packagePath, {
files: [ 'lib/**/*.js' ],
srcDir: '/',
destDir: '/' + packagePath
});
}
function packageAddon(packagePath, vendorPath) {
return stew.rename(pickFiles(vendorPath + packagePath, {
files: [ '**/*.js' ],
srcDir: '/addon',
destDir: '/' + packagePath + '/lib'
}), 'index.js', 'main.js');
}
var packages = merge([
packageAddon('ember-inflector', 'node_modules/'),
package('ember-data'),
package('activemodel-adapter'),
package('ember')
]);
var globalBuild;
// Bundle formatter for smaller payload
if (env === 'production') {
globalBuild = es6(packages, {
inputFiles: ['ember-data'],
output: '/ember-data.js',
resolvers: [PackageResolver],
formatter: 'bundle'
});
} else {
// Use AMD for faster rebuilds in dev
globalBuild = amdBuild(packages);
}
var testFiles = merge([
testTree('ember-data'),
testTree('activemodel-adapter')
]);
if (env === 'production'){
testFiles = es3SafeRecast(testFiles);
}
testFiles = concat(testFiles, {
inputFiles: ['**/*.js'],
separator: '\n',
wrapInEval: true,
wrapInFunction: true,
outputFile: '/ember-data-tests.js'
});
var testRunner = pickFiles('tests', {
srcDir: '/',
files: [ '**/*' ],
destDir: '/'
});
var bower = pickFiles('bower_components', {
srcDir: '/',
destDir: '/bower_components'
});
var configurationFiles = pickFiles('config/package-manager-files', {
srcDir: '/',
destDir: '/',
files: [ '**/*.json' ]
});
function versionStamp(tree) {
return replace(tree, {
files: ['**/*'],
patterns: [{
match: /VERSION_STRING_PLACEHOLDER/g,
replacement: version
}]
});
}
function removeSourceMappingURL(tree) {
return replace(tree, {
files: ['**/*'],
patterns: [{
match: /\/\/(.*)sourceMappingURL=(.*)/g,
replacement: ''
}]
});
}
configurationFiles = versionStamp(configurationFiles);
var jscsFiles = jscsTree("packages");
var trees = [
testFiles,
testRunner,
bower,
configurationFiles,
jscsFiles
];
if (env === 'production') {
globalBuild = versionStamp(globalBuild);
globalBuild = es3SafeRecast(globalBuild);
var minifiedGlobals = minify(globalBuild, 'ember-data');
trees.push(yuidocTree);
trees.push(minifiedGlobals);
}
trees.push(globalBuild);
module.exports = merge(trees, {overwrite: true});