forked from BackburnerJS/backburner.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
143 lines (136 loc) · 3.5 KB
/
ember-cli-build.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
/* globals module, require */
'use strict';
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const Rollup = require('broccoli-rollup');
const path = require('path');
const typescript = require('broccoli-typescript-compiler').typescript;
const buble = require('rollup-plugin-buble');
const fs = require('fs');
const SOURCE_MAPPING_DATA_URL = '//# sourceMap' + 'pingURL=data:application/json;base64,';
module.exports = function () {
const src = new MergeTrees([
new Funnel(path.dirname(require.resolve('@types/qunit/package')), {
destDir: 'qunit',
include: [ 'index.d.ts' ]
}),
new Funnel(__dirname + '/lib', {
destDir: 'lib'
}),
new Funnel(__dirname + '/tests', {
destDir: 'tests'
})
]);
const compiled = typescript(src, {
tsconfig: {
compilerOptions: {
baseUrl: '.',
inlineSourceMap: true,
inlineSources: true,
module: 'es2015',
moduleResolution: 'node',
paths: {
backburner: ['lib/index.ts']
},
strictNullChecks: true,
target: 'es2015'
},
files: ['qunit/index.d.ts', 'lib/index.ts', 'tests/index.ts']
}
});
const backburner = new Rollup(compiled, {
rollup: {
input: 'lib/index.js',
output: {
file: 'es6/backburner.js',
format: 'es',
sourcemap: true
},
format: 'es',
plugins: [
loadWithInlineMap()
]
}
});
return new MergeTrees([
backburner,
new Rollup(compiled, {
rollup: {
input: 'lib/index.js',
plugins: [
loadWithInlineMap(),
buble()
],
output: [{
file: 'named-amd/backburner.js',
exports: 'named',
format: 'amd',
moduleId: 'backburner',
sourcemap: true
}, {
file: 'backburner.js',
format: 'cjs',
sourcemap: true
}]
}
}),
new Rollup(compiled, {
annotation: 'named-amd/tests.js',
rollup: {
input: 'tests/index.js',
external: ['backburner'],
plugins: [
loadWithInlineMap(),
buble()
],
output: [{
file: 'named-amd/tests.js',
format: 'amd',
moduleId: 'backburner-tests',
sourcemap: true
}]
}
}),
new Funnel(path.dirname(require.resolve('qunitjs')), {
annotation: 'tests/qunit.{js,css}',
destDir: 'tests',
files: ['qunit.css', 'qunit.js']
}),
new Funnel(path.dirname(require.resolve('loader.js')), {
annotation: 'tests/loader.js',
destDir: 'tests',
files: ['loader.js']
}),
new Funnel(__dirname + '/tests', {
destDir: 'tests',
files: ['index.html']
})
], {
annotation: 'dist'
});
};
function loadWithInlineMap() {
return {
load: function (id) {
var code = fs.readFileSync(id, 'utf8');
var result = {
code: code,
map: null
};
var index = code.lastIndexOf(SOURCE_MAPPING_DATA_URL);
if (index === -1) {
return result;
}
result.code = code.slice(0, index);
result.map = parseSourceMap(code.slice(index + SOURCE_MAPPING_DATA_URL.length));
result.file = id;
console.log(id);
console.log(result.map.sources);
console.log(result.map.sourcesContent.map((c) => !!c));
return result;
}
};
}
function parseSourceMap(base64) {
return JSON.parse(new Buffer(base64, 'base64').toString('utf8'));
}