forked from tildeio/rsvp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brocfile.js
135 lines (122 loc) · 3.14 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
'use strict';
/* jshint node:true, undef:true, unused:true */
const Rollup = require('broccoli-rollup');
const Babel = require('broccoli-babel-transpiler');
const merge = require('broccoli-merge-trees');
const funnel = require('broccoli-funnel');
const uglify = require('broccoli-uglify-js');
const version = require('git-repo-version');
const watchify = require('broccoli-watchify');
const concat = require('broccoli-concat');
const stew = require('broccoli-stew');
const env = stew.env;
const map = stew.map;
const lib = funnel('lib', { destDir: 'lib' });
const testDir = funnel('test', { destDir: 'test' });
const testFiles = funnel('test', {
files: ['index.html','worker.js'],
destDir: 'test'
});
const mocha = funnel('node_modules/mocha', {
files: ['mocha.css','mocha.js'],
destDir: 'test'
});
const es5 = new Babel(lib, {
plugins: [
'transform-es2015-arrow-functions',
'transform-es2015-computed-properties',
'transform-es2015-shorthand-properties',
'transform-es2015-template-literals',
'transform-es2015-parameters',
'transform-es2015-destructuring',
'transform-es2015-spread',
'transform-es2015-block-scoping',
'transform-es2015-constants',
['transform-es2015-classes', { loose: true }],
'babel6-plugin-strip-class-callcheck'
]
});
// build RSVP itself
const rsvp = new Rollup(es5, {
rollup: {
input: 'lib/rsvp.js',
output: [
{
format: 'umd',
name: 'RSVP',
file: 'rsvp.js',
sourcemap: 'inline'
},
{
format: 'es',
file: 'rsvp.es.js',
sourcemap: 'inline'
}
]
}
});
const rsvpES6 = new Rollup(lib, {
rollup: {
input: 'lib/rsvp.js',
output: [
{
format: 'es',
file: 'es6/rsvp.es.js',
sourcemap: 'inline'
}
]
}
});
const testBundle = watchify(merge([
funnel(rsvp, { destDir: 'test' }),
testDir
]), {
browserify: { debug: true, entries: ['./test/index.js'] }
});
const header = map(
funnel('config', { files: ['versionTemplate.txt'], destDir: 'config' }),
content => content.replace(/VERSION_PLACEHOLDER_STRING/, version())
);
function concatAs(tree, outputFile) {
return concat(merge([tree, header]), {
headerFiles: ['config/versionTemplate.txt'],
inputFiles: ['rsvp.js'],
outputFile: outputFile
});
}
function production(dist, header) {
let result;
env('production', () => {
result = uglify(concatAs(dist, 'rsvp.min.js'), {
compress: {
negate_iife: false,
sequences: false
},
mangle: true
});
})
return result;
}
function development(dist, header) {
return concatAs(dist, 'rsvp.js');
}
module.exports = merge([
merge([
production(rsvp, header),
development(rsvp, header),
concat(merge([rsvp, header]), {
headerFiles: ['config/versionTemplate.txt'],
inputFiles: ['rsvp.es.js'],
outputFile: 'rsvp.es.js'
}),
concat(merge([rsvpES6, header]), {
headerFiles: ['config/versionTemplate.txt'],
inputFiles: ['es6/rsvp.es.js'],
outputFile: 'es6/rsvp.es.js'
})
].filter(Boolean)),
// test stuff
testFiles,
mocha,
funnel(testBundle, { destDir: 'test' })
]);