-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
78 lines (66 loc) · 1.74 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
require('coffee-script');
var jade = require('jade');
var path = require('path');
var fs = require('fs');
var async = require('async');
var renderBlog = require('./blog');
var watchr = require('watchr');
process.chdir(__dirname);
var projectsDir = 'projects';
var jadeFile = 'index.jade';
var outputFile = 'index.html';
var contribFile = 'contrib.json';
var rssFile = 'rss.xml';
var blogdir = path.join(__dirname, 'blog')
var options = {
title: 'anode@microsoft',
projects: enumerateProjects(),
contrib: readContrib(),
};
function build() {
console.time("build");
console.info('Building...');
return async.series([
function(cb) {
return renderBlog(blogdir, options.contrib, function(err, blog) {
if (err) return cb(err);
options.blog = blog.posts;
// write rss.xml
return fs.writeFile(rssFile, blog.rss, cb);
});
},
function(cb) {
return jade.renderFile(jadeFile, options, function(err, html) {
if (err) return cb(err);
return fs.writeFile(outputFile, html, function(err) {
if (err) return cb(err);
return cb();
});
});
}
], function(err) {
if (err) console.error(err);
else console.timeEnd('build');
});
}
build();
if (process.argv[2] === '--watch' ||
process.argv[2] === '-w') {
console.log('Watching', jadeFile, 'for changes...');
watchr.watch(__dirname, function(e) {
build();
});
}
else {
console.log('Run with -w or --watch to watch stay up and build on changes');
}
function enumerateProjects() {
return fs.readdirSync(projectsDir).map(function(file) {
if (path.extname(file) !== '.json') return; // take only .json files
var p = path.join(projectsDir, file);
return JSON.parse(fs.readFileSync(p));
});
}
function readContrib() {
return JSON.parse(fs.readFileSync(contribFile));
}