-
Notifications
You must be signed in to change notification settings - Fork 86
/
ember-cli-build.js
138 lines (127 loc) · 3.3 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
/* eslint-env node */
const path = require("path");
const Rollup = require("broccoli-rollup");
const funnel = require("broccoli-funnel");
const merge = require("broccoli-merge-trees");
const replace = require("broccoli-string-replace");
const typescript = require("broccoli-typescript-compiler").default;
const sourcemaps = require("rollup-plugin-sourcemaps");
const BroccoliPlugin = require("broccoli-plugin");
const fs = require("fs");
const TreeSync = require("tree-sync");
const glob = require("glob");
class JsImportFix extends BroccoliPlugin {
constructor(input) {
super([input], {
persistentOutputFlag: true,
needsCacheFlag: false
});
}
build() {
const inputPath = this.inputPaths[0];
const outputPath = this.outputPath;
if (this.treeSync === undefined) {
this.treeSync = new TreeSync(inputPath, outputPath);
}
this.treeSync.sync();
glob.sync("**/*.js", { cwd: outputPath }).forEach(js => {
const file = path.join(outputPath, js);
let src = fs.readFileSync(file, "utf8");
src = src.replace(/(^import[^'"]+['"]\.[^'"]+)(['"])/gm, "$1.js$2");
fs.writeFileSync(file, src);
});
}
}
const debugTree = require("broccoli-debug").buildDebugCallback(
"route-recognizer"
);
module.exports = function() {
const libTs = replace(
funnel("lib", {
include: ["**/*.ts"],
destDir: "lib"
}),
{
files: ["lib/route-recognizer.ts"],
pattern: {
match: /VERSION_STRING_PLACEHOLDER/g,
replacement: require("./package").version
}
}
);
const testsTs = funnel("tests", {
include: ["**/*.ts"],
destDir: "tests"
});
const ts = debugTree(merge([libTs, testsTs]), "ts");
const js = debugTree(
new JsImportFix(
typescript(ts, {
annotation: "compile route-recognizer.ts",
buildPath: "",
workingPath: __dirname
})
),
"compiled"
);
// rollup needs the source for sourcesContent
// and we need sourcesContent since broccoli
// does not serve source
const jsAndTs = merge([js, ts]);
const rollup = debugTree(
new Rollup(jsAndTs, {
annotation: "route-recognizer.js",
rollup: {
input: "dist/lib/route-recognizer.js",
plugins: [sourcemaps()],
output: [
{
file: "dist/route-recognizer.es.js",
format: "es",
sourcemap: true
},
{
file: "dist/route-recognizer.js",
format: "umd",
sourcemap: true,
"amd.id": "route-recognizer",
name: "RouteRecognizer"
}
]
}
}),
"rollup"
);
const dist = funnel(merge([js, rollup]), {
getDestinationPath(relative) {
if (relative.startsWith("dist/")) {
return relative.slice(5);
}
return relative;
}
});
return merge(
[
dist,
debugTree(
funnel("tests", {
annotation: "tests/index.html",
files: ["index.html"],
destDir: "tests"
}),
"testsIndex"
),
debugTree(
funnel(path.dirname(require.resolve("qunit")), {
annotation: "tests/qunit.{js,css}",
files: ["qunit.css", "qunit.js"],
destDir: "tests"
}),
"qunit"
)
],
{
annotation: "dist"
}
);
};