forked from machty/emblem.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrocfile.js
177 lines (143 loc) · 4.77 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
var ModuleTranspiler = require('broccoli-es6modules');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var concat = require('broccoli-concat');
var replace = require('broccoli-replace');
var peg = require('broccoli-pegjs-import');
var es6to5 = require('broccoli-6to5-transpiler');
var broccoliStew = require('broccoli-stew');
var broccoliCoffee = require('broccoli-coffee');
var injectLivereload = require('broccoli-inject-livereload');
var package = require('./package.json');
var pegjsImport = require('pegjs-import');
var outputDir = '/';
// Turn ES6 to ES5, without module transpilation
function transpileES6(tree){
return es6to5(tree, {
blacklist: ['es6.modules', 'useStrict']
});
}
function buildSrcTree(){
var lib = new Funnel('lib', {
exclude: ['**/*.rb', '**/*.pegjs'],
destDir: outputDir + 'emblem'
});
lib = replaceVersion(lib, ['emblem/main.js'] );
lib = broccoliStew.mv(lib, 'emblem/main.js', 'emblem.js');
lib = transpileES6(lib);
return lib;
}
function replaceVersion(tree, files){
return replace(tree, {
files: files,
patterns: [ {
match: /VERSION_STRING_PLACEHOLDER/,
replacement: package.version,
} ]
});
}
function buildPegTree(){
var pegTree = new Funnel('lib', {
include: ['*.pegjs'],
destDir: outputDir + 'emblem'
});
pegTree = peg(pegTree, {
peg: pegjsImport,
wrapper: function (src, parser) {
return ['/*jshint newcap: false, laxbreak: true */',
"import { generateBuilder } from './ast-builder';",
"import { INDENT_SYMBOL, DEDENT_SYMBOL, UNMATCHED_DEDENT_SYMBOL, TERM_SYMBOL } from './preprocessor';",
'var Parser = ' + parser + ';',
'var parse = Parser.parse, ParserSyntaxError = Parser.SyntaxError;',
'export {ParserSyntaxError, parse};',
'export default parse;'].join('\n');
}
});
return pegTree;
}
function buildDistTree(srcTree){
var amdTree = new ModuleTranspiler(srcTree, {format: 'amd'});
var cjsTree = new ModuleTranspiler(srcTree, {format: 'cjs'});
cjsTree = broccoliStew.mv(cjsTree, outputDir + '/cjs');
amdTree = concat(amdTree, {
inputFiles: ['**/*.js'],
outputFile: outputDir + 'emblem.amd.js',
wrapInFunction: false
});
return mergeTrees([amdTree, cjsTree]);
}
function buildSrcDepsTree(){
var stringScannerTree = new Funnel('node_modules/StringScanner/lib', {
include: ['StringScanner.js']
});
var header = 'var module = {};\n';
var footer = 'export default module.exports;';
return concat(stringScannerTree, {
inputFiles: ['StringScanner.js'],
outputFile: outputDir + 'string-scanner.js',
header: header,
footer: footer,
wrapInFunction: false
});
}
function buildTestTree(){
// all test code files
var testTree = new Funnel('tests', {
include: ['**/*.js', '**/*.coffee']
});
// all test asset files
var testAssetsTree = new Funnel('tests', {
exclude: ['**/*.js', '**/*.coffee']
});
testAssetsTree = mergeTrees([testAssetsTree, buildTestSupportTree()]);
// rewrite .coffee files to .js files
testTree = broccoliCoffee(testTree, {bare:true});
// turn es6 to es5, without modules
testTree = transpileES6(testTree);
// transpile modules to amd
var amdTestTree = new ModuleTranspiler(testTree, { format: 'amd' });
// combine AMD files
amdTestTree = concat(amdTestTree, {
inputFiles: ['**/*.js'],
outputFile: outputDir + 'emblem-tests.amd.js',
wrapInFunction: false
});
var cjsTestTree = new ModuleTranspiler(testTree, { format: 'cjs' });
cjsTestTree = broccoliStew.mv(cjsTestTree, outputDir + 'cjs/tests');
testTree = mergeTrees([amdTestTree, testAssetsTree]);
// put tests in 'tests/'
testTree = broccoliStew.mv(testTree, outputDir + 'tests');
return mergeTrees([ cjsTestTree, testTree ]);
}
function buildTestSupportTree(){
var qUnitTree = new Funnel('bower_components/qunit', {
srcDir: 'qunit',
destDir: 'qunit'
});
var loaderTree = new Funnel('bower_components', {
srcDir: 'loader.js',
destDir: 'loader.js',
include: ['loader.js']
});
var handlebarsTree = new Funnel('node_modules/handlebars/dist', {
include: ['handlebars.js'],
destDir: 'handlebars'
});
var jQueryTree = new Funnel('bower_components/jquery/dist', {
include: ['jquery.js'],
destDir: 'jquery'
});
var emberTree = new Funnel('bower_components/ember', {
include: ['ember.js'],
destDir: 'ember'
});
return mergeTrees([
qUnitTree, loaderTree, handlebarsTree, jQueryTree, emberTree]);
}
var srcTree = mergeTrees(
[buildSrcTree(), buildPegTree(), buildSrcDepsTree()]
);
var distTree = buildDistTree(srcTree);
var testTree = buildTestTree();
testTree = injectLivereload(testTree);
module.exports = mergeTrees( [distTree, testTree] );