forked from TooBug/TooSolo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toosolo.js
executable file
·115 lines (76 loc) · 2.48 KB
/
toosolo.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
var path = require('path'),
Q = require('q'),
config = require(path.resolve(process.cwd() + '/config.json')),
util = require('./lib/util.js'),
coreParser = require('./lib/coreparser.js'),
pluginName = process.argv.length>=2 ? process.argv[2] : '';
init();
function init(){
Q.longStackSupport = true;
var dfd = Q.when();
global.tooSolo = {};
if(!config.skinPath){
config.skinPath = path.join(__dirname,'./skin');
}
if(!config.globalPath){
config.globalPath = path.join(config.sourcePath,'./global');
}
if(!config.blogPath){
config.blogPath = path.join(config.sourcePath,'./blogs');
}
global.tooSolo.config = config;
dfd = dfd.then(function(){
console.log('\n==================== Solo 2.0 ====================\n');
});
if(pluginName){ //如果指定了插件名字,则调用对应插件
dfd = dfd.then(function(){
require('./lib/plugins'+pluginName)();
});
}else{
dfd = dfd.then(coreParser.parse).then(_dealParserPlugins).then(_dealPagePlugins);
}
dfd = dfd.then(function(){
console.log('\n=================== 博客构建完成 ===================\n');
});
}
function _dealParserPlugins(){
var parserPluginFileList = util.readdirSyncRecursive(path.join(__dirname,'./lib/parserplugins')),
plugins = [],
pluginsDfd = Q.when(),
thisDfd = Q.defer();
parserPluginFileList.forEach(function(plugin){
if(config.disabledParserPlugins && config.disabledParserPlugins.indexOf(plugin.replace(/\.js$/,'')) > -1)return;
if(/\.js$/.test(plugin)){
var pluginName = plugin.replace(/\.js$/,'');
plugins[pluginName] = require('./lib/parserplugins/'+plugin);
pluginsDfd = pluginsDfd.then(plugins[pluginName]);
}
});
pluginsDfd.then(function(){
thisDfd.resolve();
}).fail(function(error){
console.log(error);
})
return thisDfd.promise;
}
function _dealPagePlugins(dfd){
var pagePluginFileList = util.readdirSyncRecursive(path.join(__dirname,'./lib/pageplugins')),
plugins = [],
pluginsDfd = Q.when(),
thisDfd = Q.defer();
pagePluginFileList.forEach(function(plugin){
if(config.disabledPagePlugins && config.disabledPagePlugins.indexOf(plugin.replace(/\.js$/,'')) > -1)return;
if(/\.js$/.test(plugin)){
var pluginName = plugin.replace(/\.js$/,'');
plugins[pluginName] = require('./lib/pageplugins/'+plugin);
pluginsDfd = pluginsDfd.then(plugins[pluginName]);
}
});
pluginsDfd.then(function(){
thisDfd.resolve();
}).fail(function(error){
console.log(error);
});
return thisDfd.promise;
}