forked from metalsmith/metalsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
62 lines (51 loc) · 1.21 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
var async = require('async');
var Metalsmith = require('metalsmith');
var prompt = require('cli-prompt');
var render = require('consolidate').handlebars.render;
/**
* Build.
*/
var metalsmith = Metalsmith(__dirname)
.use(ask)
.use(template)
.build(function(err){
if (err) throw err;
});
/**
* Prompt plugin.
*
* @param {Object} files
* @param {Metalsmith} metalsmith
* @param {Function} done
*/
function ask(files, metalsmith, done){
var prompts = ['name', 'repository', 'description', 'license'];
var metadata = metalsmith.metadata();
async.eachSeries(prompts, run, done);
function run(key, done){
prompt(' ' + key + ': ', function(val){
metadata[key] = val;
done();
});
}
}
/**
* Template in place plugin.
*
* @param {Object} files
* @param {Metalsmith} metalsmith
* @param {Function} done
*/
function template(files, metalsmith, done){
var keys = Object.keys(files);
var metadata = metalsmith.metadata();
async.each(keys, run, done);
function run(file, done){
var str = files[file].contents.toString();
render(str, metadata, function(err, res){
if (err) return done(err);
files[file].contents = new Buffer(res);
done();
});
}
}