This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathember-cli-build.js
97 lines (85 loc) · 2.68 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
'use strict';
let merge = require('broccoli-merge-trees');
let stew = require('broccoli-stew');
let BroccoliCachingWriter = require('broccoli-caching-writer');
let ecmarkup = require('ecmarkup');
let fs = require('fs-extra');
let path = require('path');
function readFile(path) {
return Promise.resolve(fs.readFileSync(path, 'utf8'));
}
// TODO: extract to broccoli-ecmarkup
class EcmarkupProcessor extends BroccoliCachingWriter {
constructor(sourceNode, options) {
super([sourceNode], options);
this.options = options;
}
build() {
let inputPath = this.inputPaths[0];
let outputPath = this.outputPath;
return ecmarkup.build(
path.join(inputPath, this.options.inputFile),
readFile,
{}
).then((spec) => {
if (spec === true) {
throw new Error("Source files contained an error");
}
let specPath = path.join(outputPath, this.options.inputFile);
fs.writeFileSync(specPath, spec.toHTML(), 'utf8');
if (this.options.cssFile) {
let ecmarkupPath = require.resolve('ecmarkup');
fs.copySync(
path.join(ecmarkupPath, '../../css/elements.css'),
path.join(outputPath, this.options.cssFile)
);
fs.copySync(
path.join(ecmarkupPath, '../../js/ecmarkup.js'),
path.join(outputPath, 'ecmarkup.js')
);
fs.copySync(
path.join(ecmarkupPath, '../../js/findLocalReferences.js'),
path.join(outputPath, 'findLocalReferences.js')
);
fs.copySync(
path.join(ecmarkupPath, '../../js/menu.js'),
path.join(outputPath, 'menu.js')
);
fs.copySync(
path.join(inputPath, 'highlight.pack.js'),
path.join(outputPath, 'highlight.pack.js')
);
fs.copySync(
path.join(inputPath, 'hl.css'),
path.join(outputPath, 'hl.css')
)
}
});
}
}
// TODO: use broccoli-inject-livereload
function injectLiveReloadSnippet(sourceNode) {
return stew.map(sourceNode, '*.html', function(contents) {
let snippet = [
"<!-- livereload snippet -->",
"<script>document.write('<script src=\"http://'",
" + (location.host || 'localhost').split(':')[0]",
" + ':" + 35729 + "/livereload.js?snipver=1\"><\\/script>')",
"</script>",
""
].join('\n');
return contents.replace(/<\/body>/, function (w) {
return snippet + w;
});
});
}
module.exports = function() {
let ecmarkupOutput = new EcmarkupProcessor('src', {
inputFile: 'index.html',
cssFile: 'ecmarkup.css'
});
if (process.env.EMBER_ENV !== 'production') {
ecmarkupOutput = injectLiveReloadSnippet(ecmarkupOutput);
}
return ecmarkupOutput;
};