-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
81 lines (74 loc) · 1.95 KB
/
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
const Metalsmith = require('metalsmith')
const layouts = require('metalsmith-layouts')
const assets = require('metalsmith-assets')
const rootpath = require('metalsmith-rootpath')
const debug = require('metalsmith-debug')
const inPlace = require('metalsmith-in-place')
const sass = require('metalsmith-sass')
const liveReload = require('metalsmith-livereload')
const helpers = require('metalsmith-register-helpers')
const nodeStatic = require('node-static');
const watch = require('glob-watcher');
const isDev = !!process.env.DEV
const build = (done) => {
console.log('building')
let builder =
Metalsmith(__dirname)
.source('./src')
.destination('./docs')
.clean(true)
.use(rootpath())
.use(helpers())
.use(layouts({
engine: 'handlebars',
partials: 'partials'
}))
.use(sass({
outputDir: 'css/',
includePaths: [ 'node_modules/foundation-sites/scss/' ]
}))
.use(inPlace())
.use(debug())
.use(assets({
source: './img',
destination: './img'
}))
.use(assets({
source: './graphics',
destination: './graphics'
}))
.use(assets({
source: './bower_components',
destination: './bower_components'
}))
.use(assets({
source: './root-files',
destination: './'
}))
if (isDev)
builder = builder.use(liveReload({ debug: true }))
builder.build(function(err, files) {
console.log('build done')
done(err);
});
}
if (isDev) {
/**
* Serve files.
*/
var serve = new nodeStatic.Server(__dirname + '/docs');
require('http').createServer((req, res) => {
req.addListener('end', () => serve.serve(req, res));
req.resume();
}).listen(8080);
/**
* Watch files.
*/
watch([
__dirname + '/layouts/*',
__dirname + '/src/**/*',
__dirname + '/partials/*'
], { ignoreInitial: false }, build);
} else {
build((err) => { if (err) throw err })
}