Skip to content

Commit b247e2a

Browse files
author
小巡
committed
finished 80%
1 parent 7d4d71a commit b247e2a

File tree

12 files changed

+1145
-1
lines changed

12 files changed

+1145
-1
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 子目录可放子级editorconfig
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
# 缩进配置可改,可选值2或4
7+
indent_size = 4
8+
end_of_line = lf
9+
charset = utf-8
10+
# 避免一些无意义的diff
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
14+
[*.{html,htm,vm,tpl}]
15+
indent_size = 2
16+
insert_final_newline = false
17+
18+
[**.md]
19+
# 考虑markdown的特殊语法
20+
trim_trailing_whitespace = false
21+
insert_final_newline = false
22+
indent_size = 4
23+

.eslintrc

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6,
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"jsx": true,
7+
"experimentalObjectRestSpread": true
8+
}
9+
},
10+
"rules": {
11+
// Possible Errors
12+
"comma-dangle": [
13+
2,
14+
"never"
15+
],
16+
"no-console": 0,
17+
"no-debugger": 1,
18+
"no-extra-semi": 0,
19+
"no-inner-declarations": 2,
20+
"no-regex-spaces": 1,
21+
"valid-typeof": 2,
22+
// Best Practices
23+
"default-case": 1,
24+
"no-eq-null": 2,
25+
"no-implied-eval": 2,
26+
"no-invalid-this": 1,
27+
"no-multi-spaces": [
28+
1,
29+
{
30+
"exceptions": {
31+
"VariableDeclarator": true,
32+
"ImportDeclaration": true
33+
}
34+
}
35+
],
36+
"no-with": 2,
37+
// other
38+
"comma-spacing": [
39+
1,
40+
{
41+
"before": false,
42+
"after": true
43+
}
44+
],
45+
"space-infix-ops": [
46+
2,
47+
{
48+
"int32Hint": true
49+
}
50+
],
51+
"indent": [
52+
2,
53+
2,
54+
{
55+
"SwitchCase": 1
56+
}
57+
],
58+
"linebreak-style": [
59+
2,
60+
"unix"
61+
]
62+
},
63+
"env": {
64+
"es6": true,
65+
"browser": true,
66+
"node": true,
67+
"amd": true,
68+
"commonjs": true,
69+
"jquery": true
70+
},
71+
"globals": {
72+
"$": true,
73+
"_": true,
74+
"jQuery": false,
75+
"Zepto": false,
76+
"Angular": false,
77+
"Backbone": false,
78+
"React": false,
79+
"Highcharts": false,
80+
},
81+
"plugins": [
82+
"react"
83+
],
84+
"extends": [
85+
"eslint:recommended",
86+
"plugin:react/recommended"
87+
]
88+
}

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/dist/*
2+
!/dist/*.html
3+
static
4+
5+
node_modules
6+
# Numerous always-ignore extensions
7+
*.diff
8+
*.err
9+
*.orig
10+
*.log*
11+
*.rej
12+
*.swo
13+
*.swp
14+
*.zip
15+
*.vi
16+
*~
17+
*.sass-cache
18+
19+
# OS or Editor folders
20+
.DS_Store
21+
._*
22+
Thumbs.db
23+
.cache
24+
.project
25+
.settings
26+
.tmproj
27+
*.esproj
28+
nbproject
29+
*.sublime-project
30+
*.sublime-workspace
31+
32+
# Komodo
33+
*.komodoproject
34+
.komodotools
35+
36+
# Folders to ignore
37+
.hg
38+
.svn
39+
.CVS
40+
.idea
41+
git-m

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* Created by yangxun on 16/9/2.
3+
*/

lib/module-content.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Created by yangxun on 16/9/2.
3+
* 记录每个模块解析后的详情信息
4+
* [模块按照node的模块划分法,每个文件即为一个模块]
5+
*/
6+
//var ObjectId = require('./objectid');
7+
8+
function ModuleContent (name, source, options){
9+
this.options = Object.assign({deep: true, basePath: process.cwd()}, options);
10+
this.module = {
11+
//id: ObjectId().toHexString(),
12+
type: 'module', //类型枚举[module,function]
13+
name : name, //名称
14+
depends : [], //依赖的模块
15+
params : [], //属性
16+
functions : [], //方法
17+
exports: [], //提供给外部的接口
18+
source : source //源码
19+
}; //当前解析的模块
20+
this.current = this.module;
21+
this.parserStack = new Stack(); //待解析堆栈
22+
this.parsered = [];
23+
}
24+
25+
ModuleContent.prototype = {
26+
newModule(type, name, source){
27+
return {
28+
type: type,
29+
name : name, //名称
30+
depends : [], //依赖的模块
31+
params : [], //属性
32+
functions : [], //方法
33+
exports: [], //提供给外部的接口
34+
source : source //源码
35+
}
36+
},
37+
addStack(module){
38+
var m = this.parsered.find(item=>{return item.source == module.source});
39+
40+
if(m){
41+
return false;
42+
}
43+
44+
if(this.options.deep == true){
45+
this.parserStack.push(module);
46+
}
47+
else if(module.type != 'module'){
48+
this.parserStack.push(module);
49+
}
50+
return true;
51+
},
52+
setCurrent(module){
53+
this.current = module;
54+
},
55+
next(){
56+
if(this.parserStack.length ==0){
57+
return false;
58+
}
59+
this.current = this.parserStack.pop();
60+
this.parsered.push(this.current);
61+
62+
return true;
63+
}
64+
};
65+
66+
/**
67+
* 堆栈
68+
* @constructor
69+
*/
70+
function Stack(){
71+
this.data = [];
72+
this.length = 0;
73+
}
74+
75+
Stack.prototype.push = function(data){
76+
this.data.push(data);
77+
this.length ++;
78+
};
79+
Stack.prototype.pop = function(){
80+
this.length--;
81+
return this.data.pop();
82+
};
83+
Stack.prototype.length = function(){
84+
return this.length;
85+
};
86+
87+
module.exports = ModuleContent;

0 commit comments

Comments
 (0)