Skip to content

Commit

Permalink
modify output url
Browse files Browse the repository at this point in the history
  • Loading branch information
boaosady committed Sep 15, 2017
1 parent 2ced4f5 commit 6bf18b3
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ program
.option('-j, --project [name]', 'set the project name', 'Project')
.option('-r, --copyright [name]', 'set the copyright name', 'WeDoctor Group')
.option('-d, --debug [bool]', 'if true, the output.json file will gen', false)
.option('--verbose [bool]', 'show logs', false)
.parse(process.argv);

let baseClasses = program.base.length || ['PMLResponseModelBaseHD', 'PMLModelBase'],
Expand Down Expand Up @@ -70,9 +69,7 @@ function processTable(table, classMeta) {
if(rowIsTable){
// 进入这个方法,说明上一行标识这一行是子类
rowIsTable = false;
// return processTable($(tr).children("td").children(".table-wrap"), complexProperty);
// 有时候文档把子表格写在了第二个 td 里...
return processTable($(tr).find(".table-wrap").eq(0), complexProperty);
return processTable($(tr).children("td").children(".table-wrap"), complexProperty);
}
let tds = $(tr).children('td');
let nameMatch = /[a-z]+/ig.exec(tds.eq(0).text());
Expand All @@ -81,15 +78,9 @@ function processTable(table, classMeta) {
let isComplexObj = dataKeys.includes(nameMatch[0]); // 包含预设子类关键字, 理解为复杂对象
// 记录属性名, 类型, 注释等
let pname = tds.eq(0).text().trim();
let ptype = tds.eq(2).text().trim().toLowerCase();
let isArray = ptype == 'list';
// 有时关键字对应的不是一个类或数组
// 有时关键字对应的是数组, 但是是原生对象(尚未支持))
// 上述情况都不需要额外生成一个类
if(isComplexObj && isPrimaryType(ptype)) isComplexObj = false;
let ptype = tds.eq(2).text().trim();
let isArray = ptype.toLowerCase() == 'list';
if(isComplexObj) ptype = nameFactory.next().value;
// 经过处理后, pytyp出现为空, 或仍为list, 打印一下当前行看下问题
if(ptype == 'list' || ptype.length == 0) console.log($(tr).html(), tds.eq(2).text(), isPrimaryType(ptype), isComplexObj);
let assume_type = assumeVarType(ptype, isArray, ptype);
let prop = {
"name": pname,
Expand All @@ -108,7 +99,7 @@ function processTable(table, classMeta) {
props.push(prop);
}); // end of basetable > tr > foreach
contentJSON.push({"isRoot": isRoot, "className": modelName,"baseName": baseName, "props": props});
if(program.verbose) console.log("生成模型:", modelName)
console.log("生成模型:", modelName)
}
})().catch(console.log);

Expand All @@ -124,12 +115,6 @@ async function readFile(filename) {
return await fs.readFile(fullpath, 'utf8').catch(console.log);
}

// 是否基本类型
function isPrimaryType(typestr) {
typestr = typestr.toLowerCase().trim();
return ['int', 'integer', 'long', 'string', 'bool', 'boolean'].includes(typestr);
}

/**
* 根据关键字推断类型
* @prarm str: 关键字
Expand All @@ -143,12 +128,10 @@ function assumeVarType(str, isArray, model) {
let l_str = str.toLowerCase(),
model_type = str, // 类型
var_type = str; // 字段
// if(l_str.includes('string')) model_type = "NSString *";
// 暂时把bool也算作字符串
if(['bool', 'boolean', 'string'].includes(l_str)) model_type = "NSString *";
if(l_str.includes('string')) model_type = "NSString *";
else if(['int', 'integer', 'long'].findIndex(v=>(new RegExp(v,'ig')).test(l_str)) >= 0) model_type = "NSInteger";
else {
console.log("====user defined type: =====", str);
console.log("====undefined type: =====", str);
model_type = model + " *";
}
var_type = isArray ? "NSArray<"+model_type+"> *" : model_type;;
Expand All @@ -171,7 +154,7 @@ async function parseTemplate(data) {
h_content = await fs.readFile(getPath('template.h'), 'utf8').catch(console.log),
m_content1 = await fs.readFile(getPath('template.m'), 'utf8').catch(console.log),
m_content2 = await fs.readFile(getPath('templatebase.m'), 'utf8').catch(console.log);
let out_folder = "output";
let out_folder = "scripts/output";
await fs.emptyDir(out_folder); // 创建/清空输出文件夹
for(let model of data) {
let m_content = model.isRoot ? m_content2 : m_content1;
Expand Down

0 comments on commit 6bf18b3

Please sign in to comment.