Navigation Menu

Skip to content

Commit

Permalink
完成neinoparse的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng committed Mar 17, 2017
1 parent 1b387d6 commit 3ea8520
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/nei/builder.js
Expand Up @@ -19,6 +19,7 @@ let logger = require('../util/logger');
let mockDataWork = require('../fb-modules/util/mock_data_worker');
let neiDbConst = require('../fb-modules/config/db.json');
let dsUtil = require('./ds.util');
let NeiNoParse = require('./nei.no.parse');
let PbxProj = require('./mobile.oc.pbx.js');
require('./handlebars.util');

Expand Down Expand Up @@ -56,6 +57,7 @@ class Builder extends EventEmitter {
delete this.ds.spec;
delete this.ds.datatypeEnums;
this.injectHandlebars(this.spec.docs);
this.neiNoParse = this.getNoPassRule(this.spec.docs, this.options.config.outputRoot);
// 先找配置文件
this.findConfigs();
// 将一些 config 信息设置到传给模板的数据中
Expand Down Expand Up @@ -347,7 +349,9 @@ class Builder extends EventEmitter {
});
}
let file = _path.normalize(`${dir}/${filename}`);
let content = this.compileInVm(doc.content || '', data);
let content;

content = this.compileInVm(doc.content || '', data);
this.output(file, content);
});
};
Expand Down Expand Up @@ -400,8 +404,12 @@ class Builder extends EventEmitter {
break;
}
let file = _path.normalize(`${dir}/${filename}`);
let content = doc.content;
content = this.compileInVm(content, this.data);
let content;
if(this.neiNoParse && this.neiNoParse.dontParse(file)){
content = doc.content;
}else {
content = this.compileInVm(doc.content || '', this.data);
}
this.output(file, content);
}
break;
Expand Down Expand Up @@ -633,6 +641,17 @@ class Builder extends EventEmitter {
message: '输出: %s'
});
}

getNoPassRule(docs, root) {
let ruleFile = docs.filter((doc)=>{
return doc.name == '.neinoparse';
});
if(ruleFile.length == 0)return null;
if(ruleFile.length > 1) logger.log('debug', {
message: "更目录下存在大于一份.neinoparse文件"
});
return new NeiNoParse(ruleFile[0].content, root);
}
}

module.exports = Builder;
Expand Down
22 changes: 22 additions & 0 deletions lib/nei/nei.no.parse.js
@@ -0,0 +1,22 @@
let path = require('path');
let minimatch = require("minimatch");

/**
* NEI忽略文件解析功能实现
*/
class NeiNoParse{
constructor(ruleContent, root){
this.rules = ruleContent.split('\n').filter(r=>{return r!=""});
this.root = root;
}

dontParse(filePath){
let relativePath = path.relative(this.root, filePath);
let result = this.rules.some(rule=>{
return minimatch(relativePath, rule);
});
return result;
}
}
module.exports = NeiNoParse;

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -44,6 +44,7 @@
"handlebars": "^4.0.5",
"http-proxy": "^1.14.0",
"istextorbinary": "^2.1.0",
"minimatch": "^3.0.3",
"mockjs": "^1.0.1-beta3",
"path-to-regexp": "^1.5.3",
"xcode": "^0.9.0"
Expand Down
5 changes: 5 additions & 0 deletions rmTestSpec.sh
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
cd `dirname $0`
cd testSpec
rm -rf ./*

0 comments on commit 3ea8520

Please sign in to comment.