-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
63 lines (52 loc) · 1.44 KB
/
index.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
// Requirements
var path = require('path');
var wintersmith = require('wintersmith');
// Default settings
var settings = {
configFile: 'config.json',
hostname: 'localhost',
port: 3000
};
// Helper function for errors
function errorMessage(message) {
throw new Error(message);
}
// Helper function for loading Wintersmith envs
function loadEnvironment(){
// Load config file path from settings
var file = settings.configFile;
// Emit error for unsupported file types
if (['.json'].indexOf(path.extname(file)) === -1) {
errorMessage('File ' + file + ' is not supported. Expected .json file.');
}
// Load and return Wintersmith environment
return wintersmith(file);
}
function wintersmithBuild(callback){
// Try to load environment
var env = loadEnvironment();
// Build site
env.build(function(error) {
if (error) {
errorMessage(error);
}
callback();
});
}
function wintersmithPreview(){
// Try to load environment
var env = loadEnvironment();
// Override env settings
env.config.hostname = settings.hostname;
env.config.port = settings.port;
// Run in preview mode
env.preview(function(error) {
if (error) {
errorMessage(error);
}
});
}
// Export module settings and functions
module.exports.settings = settings;
module.exports.build = wintersmithBuild;
module.exports.preview = wintersmithPreview;