-
Notifications
You must be signed in to change notification settings - Fork 11
/
toosolo.js
executable file
·141 lines (108 loc) · 3.18 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
async = require('async'),
commander = require('commander'),
config,
util,
coreParser,
pluginName;
commander
.version('2.0.10')
.usage('[--选项 值]')
.option('-i, --init', '在当前目录初始化TooSolo文件')
.option('-s, --skin', '将默认皮肤复制到当前项目并使用该皮肤')
.parse(process.argv);
init();
function init(){
if (commander.init) {
pluginName = 'init';
}else{
config = require(path.resolve(process.cwd() + '/config.json'));
util = require('./lib/util.js');
coreParser = require('./lib/coreparser.js');
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;
if(commander.skin){
pluginName = 'skin';
}
}
console.log('\n==================== Solo 2.0 ====================\n');
if(pluginName){ //如果指定了插件名字,则调用对应插件
require('./lib/sysplugins/'+pluginName)();
console.log('\n======================= 完成 ======================\n');
}else{
var tasks = [coreParser.parse];
// async.series([])
async.series([coreParser.parse,
_dealParserPlugins,
_dealPagePlugins,
function(){
console.log('\n=================== 博客构建完成 ===================\n');
}]);
// dfd = dfd.then(coreParser.parse).then(_dealParserPlugins).then(_dealPagePlugins);
// dfd = dfd.then(function(){
// console.log('\n=================== 博客构建完成 ===================\n');
// });
}
}
function _dealParserPlugins(callback){
var parserPluginsPath = path.join(__dirname,'./lib/parserplugins');
async.waterfall([function(callback){
fs.readdir(parserPluginsPath,function(err,fileList){
callback(null,fileList);
});
},function(fileList,callback){
var pluginList = [];
fileList.forEach(function(pluginFile){
var pluginName = pluginFile.replace(/\.js$/,'');
var disabledList = config.disabledParserPlugins;
if(!disabledList || disabledList.indexOf(plugin) === -1){
if(/\.js$/.test(pluginFile)){
pluginList.push(require(path.join(parserPluginsPath,pluginName)));
}
};
});
async.series(pluginList,callback)
}],function(err){
if(err){
console.log(err);
}
// console.log('er',err);
callback();
});
}
function _dealPagePlugins(callback){
var pagePluginsPath = path.join(__dirname,'./lib/pageplugins');
async.waterfall([function(callback){
fs.readdir(pagePluginsPath,function(err,fileList){
callback(null,fileList);
});
},function(fileList,callback){
var pluginList = [];
fileList.forEach(function(pluginFile){
var pluginName = pluginFile.replace(/\.js$/,'');
var disabledList = config.disabledPagePlugins;
if(!disabledList || disabledList.indexOf(pluginName) === -1){
if(/\.js$/.test(pluginFile)){
pluginList.push(require(path.join(pagePluginsPath,pluginName)));
}
};
});
async.series(pluginList,callback)
}],function(err){
if(err){
console.log(err);
}
callback();
});
}