Wukong zh CN - fundon/wukong GitHub Wiki
Wukong 是一个静态网站生成器。
- 静态博客
- API文档
- 构建工具
- ... (这货不仅仅只有这些,就看你的手艺。)
当你看到这名字时,你和你的小伙伴别被惊呆了。 为什么取这名,难道作者天天想着空姐。错!你们想太多了。
核心架构借鉴了Koa和Metalsmith.
主要特点
- 中间件,也是Wukong的插件机制
- 生成器,“妈妈再也不担心我写回调函数了 }}}}...”
中间件
分3种类型
- before
处理文件集合(纯文件路径), 在此可以添加一些过滤器等
数据结构:
files = [path, path, ...];
- middle
单个文件处理,读,操作buffer/contents,及其他属性
数据结构,继承自 lib/file.js
file = {
path: String
buffer: Buffer
contents: String
mode: Oct number
stat: Stat
};
- after
处理文件集合,保存文件
数据结构
files = [file, file, ...];
更多
例子,Wukong(__dirname)
// before 中间件
.use(function *(next) {
this.files = this.files.filter(function (p) { return p !== 'index.html'; });
yield next;
}, 'before')
// middle 中间件
.use(function *(next) {
this.file.contents = '"use strict";\n' + this.file.contents;
yield next;
})
// after 中间件
.use(function *(next) {
// 创建一个文件对象
var file = this.wukong.createFile();
var files = this.files;
// 合并所有文件
files.forEach(function (f) {
file.contents += f.contents;
});
this.files = [file];
yield next;
})
.buid()
安装
npm install wukong -g
命令行
wukong -h