1 | const Metalsmith = require('metalsmith');
|
2 | const changed = require('./');
|
3 | const nodeStatic = require('node-static');
|
4 | const livereload = require('metalsmith-livereload');
|
5 | const watch = require('glob-watcher');
|
6 | const open = require('open');
|
7 |
|
8 | const DIR = __dirname + '/test/fixtures/';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const build = (clean = false) => (done) => {
|
14 | console.log(`Building. clean: ${clean}.`);
|
15 | Metalsmith(DIR)
|
16 | .clean(clean)
|
17 | .use(changed())
|
18 |
|
19 | .use(livereload({ debug: true }))
|
20 | .build((err, files) => {
|
21 | let filenames = Object.keys(files).join(', ');
|
22 | console.log('Built: ' + filenames);
|
23 | done(err);
|
24 | });
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | var serve = new nodeStatic.Server(DIR + 'build');
|
31 | require('http').createServer((req, res) => {
|
32 | req.addListener('end', () => serve.serve(req, res));
|
33 | req.resume();
|
34 | }).listen(8080);
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | watch(DIR + 'src/**/*', { ignoreInitial: false }, build(false));
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | setTimeout(() => open('http://localhost:8080'), 1000);
|