-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
57 lines (47 loc) · 1.42 KB
/
index.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
'use strict';
var browserSync = require('browser-sync');
var chokidar = require('chokidar');
var spawn = require('child_process').spawn;
var platform = require('elm/platform');
var path = require('path');
var fs = require('fs');
var elmPackage = require(path.join(process.cwd(), 'elm-package'));
var sourceDirectories =
elmPackage['source-directories']
.map(function createGlob(directory) {
return path.join(directory, '**', '*.elm');
});
process.env.ELM_HOME = platform.shareDir;
module.exports = function elmServer(inputFilesArg, optsArg) {
var opts = optsArg || {};
var inputFiles = inputFilesArg instanceof Array ?
inputFilesArg :
[inputFilesArg];
var outputFile =
!opts.output ?
'index.html' :
opts.output;
var watch = opts.watch || path.dirname(outputFile);
var startPath =
opts.startPath ||
(path.extname(outputFile) === '.html' ?
path.basename(outputFile) :
'/');
function elmMake() {
var makeArgs = inputFiles.concat(['--output', outputFile]);
var executablePath = platform.executablePaths['elm-make'];
spawn(executablePath, makeArgs, { stdio: 'inherit' });
}
elmMake();
chokidar
.watch(sourceDirectories, { ignored: /elm-stuff/ })
.on('change', elmMake);
return browserSync({
server: watch,
watchOptions: {
ignored: /(elm-stuff|\.elm)/
},
startPath: startPath,
files: [path.join(watch, '**', '*')]
});
};