-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
247 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// code basis on https://github.com/JacksonTian/fks/blob/master/bin/generate.js | ||
// Thanks to JacksonTian | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8'); | ||
|
||
var getItems = function (str) { | ||
var patt = /([ ]*)-(.*)/g; | ||
var result; | ||
|
||
var list = []; | ||
while ((result = patt.exec(str)) != null) { | ||
list.push({level: result[1].length / 4, content: result[2].trim()}); | ||
} | ||
return list; | ||
}; | ||
|
||
var filter = function (list) { | ||
var j = 0; | ||
var f2e = []; | ||
for (var i = 0; i < list.length; i++) { | ||
var item = list[i]; | ||
if (item.level === 0) { | ||
j = j + 1; | ||
if (j === 2) { | ||
break; | ||
} | ||
} | ||
|
||
f2e.push(item); | ||
} | ||
return f2e; | ||
}; | ||
|
||
var format = function (list) { | ||
var result = []; | ||
for (var i = 0; i < list.length; i++) { | ||
var item = list[i]; | ||
var data = { | ||
id: '' + i, | ||
name: item.content, | ||
level: item.level | ||
}; | ||
result.push(data); | ||
} | ||
return result; | ||
}; | ||
|
||
var items = getItems(readme); | ||
var f2e = filter(items); | ||
var formated = format(f2e); | ||
|
||
var buildTree = function (list) { | ||
var root = null; | ||
for (var i = 0; i < list.length; i++) { | ||
var item = list[i]; | ||
if (root === null) { | ||
root = item; | ||
root.children = []; | ||
} | ||
|
||
var lastLevel0 = root.children; | ||
if (item.level === 1) { | ||
delete item.level; | ||
lastLevel0.push(item); | ||
} | ||
|
||
if (item.level === 2) { | ||
var lastLevel1 = lastLevel0[lastLevel0.length - 1]; | ||
lastLevel1.children = lastLevel1.children || []; | ||
lastLevel1.children.push(item); | ||
} | ||
|
||
if (item.level === 3) { | ||
var lastLevel1Child = lastLevel0[lastLevel0.length - 1].children; | ||
var lastLevel2 = lastLevel1Child[lastLevel1Child.length - 1]; | ||
lastLevel2.children = lastLevel2.children || []; | ||
lastLevel2.children.push(item); | ||
} | ||
delete item.level; | ||
} | ||
return root; | ||
}; | ||
|
||
var tree = buildTree(formated); | ||
fs.writeFileSync(path.join(__dirname, '../data/eks.json'), JSON.stringify(tree, null, ' ')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"id": "0", | ||
"name": "硬件核心(Hardware Core)", | ||
"children": [ | ||
{ | ||
"id": "2", | ||
"name": "CPU" | ||
}, | ||
{ | ||
"id": "3", | ||
"name": "MCU" | ||
}, | ||
{ | ||
"id": "10", | ||
"name": "MPU" | ||
}, | ||
{ | ||
"id": "11", | ||
"name": "DSP" | ||
}, | ||
{ | ||
"id": "13", | ||
"name": "SOC" | ||
}, | ||
{ | ||
"id": "15", | ||
"name": "CPLD" | ||
}, | ||
{ | ||
"id": "18", | ||
"name": "FPGA" | ||
}, | ||
{ | ||
"id": "21", | ||
"name": "DSC" | ||
}, | ||
{ | ||
"id": "27", | ||
"name": "RIP(人体红外)" | ||
}, | ||
{ | ||
"id": "28", | ||
"name": "Temperture(温度)" | ||
}, | ||
{ | ||
"id": "29", | ||
"name": "Light" | ||
}, | ||
{ | ||
"id": "30", | ||
"name": "Motion(运动)" | ||
}, | ||
{ | ||
"id": "31", | ||
"name": "Camera" | ||
}, | ||
{ | ||
"id": "38", | ||
"name": "Switch" | ||
}, | ||
{ | ||
"id": "39", | ||
"name": "Keypad" | ||
}, | ||
{ | ||
"id": "40", | ||
"name": "Relay" | ||
}, | ||
{ | ||
"id": "42", | ||
"name": "Thermistor (热敏电阻)" | ||
}, | ||
{ | ||
"id": "43", | ||
"name": "Varistor(压敏电阻)" | ||
}, | ||
{ | ||
"id": "46", | ||
"name": "电阻排" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node ./bin/generator.js |