hexo-cli 1.0.2版本
loadModule
hexo.js中定义了context.js,用来实例化hexo对象。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 return findPkg(cwd, args).then(function(path) {
if (!path) return;
hexo.base_dir = path;
return loadModule(path, args).catch(function() {
log.error('Local hexo not found in %s', chalk.magenta(tildify(path)));
log.error('Try running: \'npm install hexo --save\'');
process.exit(2);
});
}).then(function(mod) {
//加载完hexo模块把实例赋给hexo
if (mod) hexo = mod;
log = hexo.log;
//注册help init version
require('./console')(hexo);
return hexo.init();
})
hexo.init()
1 | Hexo.prototype.init = function(){ |
require('../plugins/console')(this);
会加载plugins/console目录下的index.js文件,1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20module.exports = function(ctx){
var console = ctx.extend.console;
console.register('clean', 'Removed generated files and cache.', require('./clean'));
console.register('config', 'Get or set configurations.', {
usage: '[name] [value]',
arguments: [
{name: 'name', desc: 'Setting name. Leave it blank if you want to show all configurations.'},
{name: 'value', desc: 'New value of a setting. Leave it blank if you just want to show a single configuration.'}
]
}, require('./config'));
console.register('deploy', 'Deploy your website.', {
options: [
{name: '--setup', desc: 'Setup without deployment'},
{name: '-g, --generate', desc: 'Generate before deployment'}
]
}, require('./deploy'));
}
首先获取ctx.extend.console
,其实就是extend目录下的index.js文件中定义的
1 | exports.Console = require('./console'); |