forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brocfile.js
174 lines (154 loc) · 4.51 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
/* 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-string-replace');
var path = require('path');
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], {overwrite: true});
}
function testTree(packageName){
var test = pickFiles('packages/' + packageName + '/tests', {
srcDir: '/',
files: [ '**/*.js' ],
destDir: '/' + packageName
});
var jshinted = jshint('packages/' + packageName + '/lib', {
jshintrcPath: path.join(__dirname, '.jshintrc')
});
jshinted = wrap(jshinted, {
wrapper: [ "if (!QUnit.urlParams.nojshint) {\n", "\n}"],
});
jshinted = pickFiles(jshinted, {
files: ['**/*.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/lib"
],
"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
});
}
var packages = merge([
package('ember-inflector', 'bower_components/ember-inflector/packages/'),
package('ember-data'),
package('activemodel-adapter')
]);
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: '/',
inputFiles: [ '**/*' ],
destDir: '/'
});
var bower = pickFiles('bower_components', {
srcDir: '/',
inputFiles: [ '**/*' ],
destDir: '/bower_components'
});
var configurationFiles = pickFiles('config/package_manager_files', {
srcDir: '/',
destDir: '/',
files: [ '**/*.json' ]
});
function versionStamp(tree){
return replace(tree, {
files: ['**/*'],
pattern: {
match: /VERSION_STRING_PLACEHOLDER/g,
replacement: version
}
});
}
configurationFiles = versionStamp(configurationFiles);
var trees = [
testFiles,
testRunner,
bower,
configurationFiles
];
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});