forked from metalsmith/metalsmith.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
74 lines (63 loc) · 1.38 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
var basename = require('path').basename;
var Component = require('component-builder');
var extname = require('path').extname;
var inPlace = require('metalsmith-in-place');
var layouts = require('metalsmith-layouts');
var markdown = require('metalsmith-markdown');
var metadata = require('metalsmith-metadata');
var Metalsmith = require('metalsmith');
var mkdir = require('mkdirp');
var myth = require('myth');
var write = require('fs').writeFileSync;
/**
* Expose `build`.
*/
module.exports = build;
/**
* Build with Metalsmith and Component.
*
* @param {Function} fn(err)
*/
function build(fn){
/**
* Component.
*/
var c = new Component(__dirname)
c.copyAssetsTo('build');
c.development();
c.addSourceURLs();
c.copyFiles();
/**
* Metalsmith.
*/
var m = Metalsmith(__dirname);
m.use(metadata({
plugins: 'plugins.json',
examples: 'examples.json'
}));
m.use(inPlace({
engine: 'swig',
pattern: '**/*.md'
}));
m.use(markdown({
smartypants: true,
smartLists: true
}));
m.use(layouts({
engine: 'swig',
directory: './'
}));
/**
* Build.
*/
m.build(function(err, res) {
if (err) return fn(err);
c.build(function(err, res) {
if (err) return fn(err);
mkdir('build');
write('build/build.js', res.require + res.js);
write('build/build.css', myth(res.css));
fn(err, res);
});
});
}