-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.js
executable file
·84 lines (65 loc) · 1.8 KB
/
site.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
79
80
81
82
83
84
module.exports = Site;
var steps = ['initialize','prepare','execute','finalize'];
var path = require('path');
var staticPlugin = require('./plugins/static');
var layoutsPlugin = require('./plugins/layouts');
var pagesPlugin = require('./plugins/pages');
var stylesPlugin = require('./plugins/styles');
var SiteProto = Site.prototype;
function Site () {
if(!(this instanceof Site)) return new Site;
this.$plugins = [];
this.defaultLayout = 'layout';
this.out = 'site';
this.src = 'src';
this.call( require('./extenders/default') )
.addPlugin( staticPlugin() )
.addPlugin( layoutsPlugin() )
.addPlugin( pagesPlugin() )
.addPlugin( stylesPlugin() )
;
}
/* ---- ---- ---- ---- ---- ---- ---- */
SiteProto.generate = function () {
var site = this;
steps.forEach(function(step) {
console.log(step);
site.$plugins.forEach(function (plugin) {
var fn;
if((fn = plugin[step])) {
console.log('-----' + plugin.name );
fn(site);
}
});
});
}
SiteProto.CWD = function (i) {
if(! arguments.length ) {
return this.cwd;
}
this.cwd = i;
return this;
}
SiteProto.addPlugin = function(plugin) {
this.$plugins.push(plugin);
if(plugin.register) {
plugin.register(this);
}
return this;
}
SiteProto.loadConfig = function () {
var cfgPath = path.resolve(this.cwd,'fidalgo.config.js');
require(cfgPath)(this);
console.log('loadingConfig', cfgPath);
return this;
}
SiteProto.srcPath = function () {
return path.resolve(this.cwd, this.src);
}
SiteProto.outPath = function () {
return path.resolve(this.cwd, this.out);
}
SiteProto.call = function (fn) {
fn(this);
return this;
}