binhend 1.0.11 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example_webcomp/components/AnUserInterface.js +0 -0
- package/example_webcomp/components/common/InputText.js +14 -0
- package/example_webcomp/components/common/Link.js +16 -0
- package/example_webcomp/components/common/Link2.js +13 -0
- package/example_webcomp/components/index.html +18 -0
- package/example_webcomp/components/index.js +6 -0
- package/example_webcomp/components/layouts/AppMainLayout.js +22 -0
- package/example_webcomp/components/layouts/AppToDos.js +47 -0
- package/example_webcomp/components/layouts/PageContent.js +25 -0
- package/example_webcomp/components/layouts/PageHeader.js +49 -0
- package/example_webcomp/components/layouts/ToDoItem.js +25 -0
- package/example_webcomp/components/services/AnyService.js +6 -0
- package/example_webcomp/components/services/ServiceToDos.js +42 -0
- package/example_webcomp/components/styles/ToDoItemStyle.js +40 -0
- package/example_webcomp/components/styles/ToDoItemStyle2.js +2 -0
- package/example_webcomp/components/styles/temp.css +4 -0
- package/example_webcomp/components/styles/todo.css +31 -0
- package/example_webcomp/components/styles/todo.css.js +2 -0
- package/example_webcomp/config.js +13 -0
- package/example_webcomp/index.js +10 -0
- package/example_webcomp/public/AnUserInterface.js +0 -0
- package/example_webcomp/public/common/InputText.js +17 -0
- package/example_webcomp/public/common/Link.js +17 -0
- package/example_webcomp/public/common/Link2.js +13 -0
- package/example_webcomp/public/index.html +18 -0
- package/example_webcomp/public/index.js +6 -0
- package/example_webcomp/public/layouts/AppMainLayout.js +96 -0
- package/example_webcomp/public/layouts/AppToDos.js +100 -0
- package/example_webcomp/public/layouts/PageContent.js +29 -0
- package/example_webcomp/public/layouts/PageHeader.js +52 -0
- package/example_webcomp/public/layouts/ToDoItem.js +30 -0
- package/example_webcomp/public/services/AnyService.js +8 -0
- package/example_webcomp/public/services/ServiceToDos.js +46 -0
- package/example_webcomp/public/styles/ToDoItemStyle.js +44 -0
- package/example_webcomp/public/styles/ToDoItemStyle2.js +9 -0
- package/example_webcomp/public/styles/temp.css +4 -0
- package/example_webcomp/public/styles/todo.css +31 -0
- package/example_webcomp/public/styles/todo.css.js +9 -0
- package/package.json +12 -2
- package/src/binh.js +68 -1
- package/src/code.js +88 -0
- package/src/component.js +108 -0
- package/src/server.js +9 -0
- package/testa.js +28 -0
- /package/{example → example_api}/config.js +0 -0
- /package/{example → example_api}/index.js +0 -0
- /package/{example → example_api}/routes/test/bb.js +0 -0
- /package/{example → example_api}/routes/test/index.js +0 -0
- /package/{example → example_api}/routes/test/some.js +0 -0
- /package/{example → example_api}/routes/test.js +0 -0
- /package/{example → example_api}/routes/testa.js +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
var InputText = Binh.ui('/common/InputText.js', function main() {
|
|
4
|
+
var inputbox = input({ type: 'text', placeholder: 'Enter to-do item' });
|
|
5
|
+
|
|
6
|
+
inputbox.on('keypress', function (event) {
|
|
7
|
+
if (event.key === "Enter") {
|
|
8
|
+
inputbox.does('submit', inputbox.element.value);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return inputbox;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
var ServiceToDos = Binh.service('/services/ServiceToDos.js', function(define, state, http) {
|
|
16
|
+
var todos = state.as('todos');
|
|
17
|
+
|
|
18
|
+
todos.schema(function(resolve) {
|
|
19
|
+
new http(api('get'))
|
|
20
|
+
.get(function(response) {
|
|
21
|
+
resolve(parseResponse(response));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function handleResponse(response) {
|
|
26
|
+
todos.set(parseResponse(response));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseResponse(response) {
|
|
30
|
+
var todoitems = [];
|
|
31
|
+
|
|
32
|
+
Object.keys(response).forEach(function(key) {
|
|
33
|
+
var each = response[key];
|
|
34
|
+
todoitems.push({ id: key, text: each.text });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return todoitems;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
define('add', function(value) {
|
|
41
|
+
new http(api('add'))
|
|
42
|
+
.body({ text: value })
|
|
43
|
+
.post(handleResponse);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
define('remove', function(id) {
|
|
47
|
+
new http(api('remove'))
|
|
48
|
+
.body({ id: id })
|
|
49
|
+
.post(handleResponse);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function api(relative_url) {
|
|
53
|
+
return 'https://todolist-of-binh.fly.dev/todos/' + relative_url;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Binh.ui(function main() {
|
|
58
|
+
var PageHeader = this.ui('/layouts/PageHeader.js');
|
|
59
|
+
var ToDoItem = this.ui('/layouts/ToDoItem.js');
|
|
60
|
+
// var addTodoItem = ServiceToDos.does('add');
|
|
61
|
+
// var addTodoItem = ServiceToDos.debounce('add', 1500); // trailing only
|
|
62
|
+
var addTodoItem = ServiceToDos.debounce('add', 1500, true); // both leading & trailing
|
|
63
|
+
// var addTodoItem = ServiceToDos.debounce('add', 1500, true, true); // leading only
|
|
64
|
+
// var addTodoItem = ServiceToDos.throttle('add', 1500);
|
|
65
|
+
// var addTodoItem = ServiceToDos.once('add', 1500);
|
|
66
|
+
|
|
67
|
+
var inputbox = InputText().when('submit', addTodoItem);
|
|
68
|
+
|
|
69
|
+
var todolist = div({ class: 'todo-items' });
|
|
70
|
+
|
|
71
|
+
todolist.subscribe('todos', function(data) {
|
|
72
|
+
todolist.empty();
|
|
73
|
+
data.forEach(function(datum) {
|
|
74
|
+
todolist(
|
|
75
|
+
ToDoItem(datum).when('remove', ServiceToDos.instant('remove'))
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
var maindiv = div({ class: 'container' });
|
|
81
|
+
var left_section = div({ id: 'left-section' })('left section')(PageHeader);
|
|
82
|
+
var right_section = div({ id: 'right-section' })('right section');
|
|
83
|
+
|
|
84
|
+
maindiv(
|
|
85
|
+
left_section,
|
|
86
|
+
right_section(
|
|
87
|
+
div('To-Do List'),
|
|
88
|
+
inputbox,
|
|
89
|
+
todolist
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return maindiv;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var div = Binh.el('div'),
|
|
97
|
+
span = Binh.el('span'),
|
|
98
|
+
input = Binh.el('input');
|
|
99
|
+
|
|
100
|
+
}();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.ui(function PageContent() {
|
|
4
|
+
var { Router } = Binh;
|
|
5
|
+
|
|
6
|
+
var PageContent = div({ id: 'page-content' });
|
|
7
|
+
|
|
8
|
+
PageContent(
|
|
9
|
+
new Router({
|
|
10
|
+
'': div('default work!'),
|
|
11
|
+
'/abc': div('abc work!'),
|
|
12
|
+
'/haha': trans('haha work!')
|
|
13
|
+
})
|
|
14
|
+
)
|
|
15
|
+
(
|
|
16
|
+
function (thisEl) {
|
|
17
|
+
setTimeout(function() {
|
|
18
|
+
console.log('>>> Page Content:', thisEl);
|
|
19
|
+
}, 1000);
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return PageContent;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
var div = Binh.el('div'),
|
|
27
|
+
trans = Binh.el('trans');
|
|
28
|
+
|
|
29
|
+
}();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.ui(function PageHeader() {
|
|
4
|
+
var Link = this.ui('/common/Link2.js');
|
|
5
|
+
|
|
6
|
+
var PageHeader = div({ id: 'page-header' });
|
|
7
|
+
|
|
8
|
+
PageHeader(
|
|
9
|
+
div({ class: 'container' })(
|
|
10
|
+
div({ class: 'row' })(
|
|
11
|
+
nav({ class: 'navbar navbar-default' })(
|
|
12
|
+
div({ class: 'container-fluid' })([
|
|
13
|
+
div({ class: 'navbar-header' })(
|
|
14
|
+
a({ class: 'navbar-brand', href: '#' })(
|
|
15
|
+
'Website Name'
|
|
16
|
+
)
|
|
17
|
+
),
|
|
18
|
+
ul({ class: 'nav navbar-nav' })(
|
|
19
|
+
li({ class: 'active' })(
|
|
20
|
+
Link('Home', '/')
|
|
21
|
+
),
|
|
22
|
+
li(
|
|
23
|
+
Link('Abc', '/abc')
|
|
24
|
+
),
|
|
25
|
+
li(
|
|
26
|
+
Link('Haha', '/haha')
|
|
27
|
+
),
|
|
28
|
+
li(
|
|
29
|
+
a('Page 3')
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
])
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
),
|
|
36
|
+
function (thisEl) {
|
|
37
|
+
setTimeout(function() {
|
|
38
|
+
console.log('>>> Page Header:', thisEl);
|
|
39
|
+
}, 1000);
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return PageHeader;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var div = Binh.el('div'),
|
|
47
|
+
nav = Binh.el('nav'),
|
|
48
|
+
ul = Binh.el('ul'),
|
|
49
|
+
li = Binh.el('li'),
|
|
50
|
+
a = Binh.el('a');
|
|
51
|
+
|
|
52
|
+
}();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
var ToDoItemStyle2 = Binh.style('/styles/ToDoItemStyle2.js', function anonymous(
|
|
4
|
+
) {
|
|
5
|
+
return "@charset \"utf-8\"; @import url(\"/styles/temp.css\"); /* .btn-remove { color: blue; margin-left: '15px'; } */ @media (min-width: 800px) { .btn-remove { color: red; margin-left: '15px'; } } @keyframes slidein { from { transform: translateX(0%); } to { transform: translateX(100%); } } @page { size: 8.5in 9in; margin-top: 4in; }";
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
Binh.ui(function main(props) {
|
|
9
|
+
// var ToDoItemStyle = this.style('/styles/todo.css');
|
|
10
|
+
|
|
11
|
+
var todoitem = div({ style: 'margin: 3px;' });
|
|
12
|
+
|
|
13
|
+
var remove_button = span({ class: 'btn-remove' })('X');
|
|
14
|
+
|
|
15
|
+
remove_button.on('click', function() {
|
|
16
|
+
todoitem.does('remove', props.id);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
todoitem(span(props.text), span('-------'), remove_button);
|
|
20
|
+
|
|
21
|
+
// return todoitem.style(ToDoItemStyle);
|
|
22
|
+
// return todoitem.style('styles/todo.css');
|
|
23
|
+
return todoitem.style(ToDoItemStyle2);
|
|
24
|
+
// return todoitem.style(todo);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
var div = Binh.el('div'),
|
|
28
|
+
span = Binh.el('span');
|
|
29
|
+
|
|
30
|
+
}();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.service(function(define, state, http) {
|
|
4
|
+
var todos = state.as('todos');
|
|
5
|
+
|
|
6
|
+
todos.schema(function(resolve) {
|
|
7
|
+
new http(api('get'))
|
|
8
|
+
.get(function(response) {
|
|
9
|
+
resolve(parseResponse(response));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function handleResponse(response) {
|
|
14
|
+
todos.set(parseResponse(response));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseResponse(response) {
|
|
18
|
+
var todoitems = [];
|
|
19
|
+
|
|
20
|
+
Object.keys(response).forEach(function(key) {
|
|
21
|
+
var each = response[key];
|
|
22
|
+
todoitems.push({ id: key, text: each.text });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return todoitems;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
define('add', function(value) {
|
|
29
|
+
new http(api('add'))
|
|
30
|
+
.body({ text: value })
|
|
31
|
+
.post(handleResponse);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
define('remove', function(id) {
|
|
35
|
+
new http(api('remove'))
|
|
36
|
+
.body({ id: id })
|
|
37
|
+
.post(handleResponse);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function api(relative_url) {
|
|
41
|
+
return 'https://todolist-of-binh.fly.dev/todos/' + relative_url;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.style(function(css) {
|
|
4
|
+
// css('@charset "utf-8";');
|
|
5
|
+
|
|
6
|
+
css(`@import url("styles/temp.css");`);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
css('.btn-remove', [
|
|
10
|
+
'color: purple;',
|
|
11
|
+
'margin-left: 10px'
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
css(
|
|
15
|
+
`@media (min-width: 800px) {
|
|
16
|
+
.btn-remove {
|
|
17
|
+
color: red;
|
|
18
|
+
margin-left: '15px';
|
|
19
|
+
}
|
|
20
|
+
}`
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
css(`
|
|
24
|
+
@keyframes slidein {
|
|
25
|
+
from {
|
|
26
|
+
transform: translateX(0%);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
to {
|
|
30
|
+
transform: translateX(100%);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
|
|
35
|
+
css(`
|
|
36
|
+
@page {
|
|
37
|
+
size: 8.5in 9in;
|
|
38
|
+
margin-top: 4in;
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
}();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.style(function anonymous(
|
|
4
|
+
) {
|
|
5
|
+
return "@charset \"utf-8\"; @import url(\"/styles/temp.css\"); /* .btn-remove { color: blue; margin-left: '15px'; } */ @media (min-width: 800px) { .btn-remove { color: red; margin-left: '15px'; } } @keyframes slidein { from { transform: translateX(0%); } to { transform: translateX(100%); } } @page { size: 8.5in 9in; margin-top: 4in; }";
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
}();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@charset "utf-8";
|
|
2
|
+
|
|
3
|
+
@import url("/styles/temp.css");
|
|
4
|
+
|
|
5
|
+
/* .btn-remove {
|
|
6
|
+
color: blue;
|
|
7
|
+
margin-left: '15px';
|
|
8
|
+
} */
|
|
9
|
+
|
|
10
|
+
@media (min-width: 800px) {
|
|
11
|
+
|
|
12
|
+
.btn-remove {
|
|
13
|
+
color: red;
|
|
14
|
+
margin-left: '15px';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@keyframes slidein {
|
|
19
|
+
from {
|
|
20
|
+
transform: translateX(0%);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
to {
|
|
24
|
+
transform: translateX(100%);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@page {
|
|
29
|
+
size: 8.5in 9in;
|
|
30
|
+
margin-top: 4in;
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
!function(){
|
|
2
|
+
|
|
3
|
+
Binh.style(function anonymous(
|
|
4
|
+
) {
|
|
5
|
+
return "@charset \"utf-8\"; @import url(\"/styles/temp.css\"); /* .btn-remove { color: blue; margin-left: '15px'; } */ @media (min-width: 800px) { .btn-remove { color: red; margin-left: '15px'; } } @keyframes slidein { from { transform: translateX(0%); } to { transform: translateX(100%); } } @page { size: 8.5in 9in; margin-top: 4in; }";
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
}();
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "binhend",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Nguyen Duc Binh",
|
|
7
7
|
"license": "UNLICENSED",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
-
"example": "
|
|
10
|
+
"example-api": "nodemon example_api PORT=5555",
|
|
11
|
+
"example-webcomp": "nodemon example_webcomp"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"express": "^4.17.1"
|
|
14
15
|
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"nodemon": "^2.0.20"
|
|
18
|
+
},
|
|
19
|
+
"nodemonConfig": {
|
|
20
|
+
"ignore": [
|
|
21
|
+
"example_webcomp/public/**"
|
|
22
|
+
],
|
|
23
|
+
"delay": 2500
|
|
24
|
+
},
|
|
15
25
|
"engines": {
|
|
16
26
|
"node": ">= 16.17.1"
|
|
17
27
|
}
|
package/src/binh.js
CHANGED
|
@@ -7,6 +7,7 @@ const { ConfigLoader } = require('./configuration');
|
|
|
7
7
|
const { HTTPS } = require('./https');
|
|
8
8
|
const { Server } = require('./server');
|
|
9
9
|
const { APIs, Router } = require('./api');
|
|
10
|
+
const Component = require('./component');
|
|
10
11
|
|
|
11
12
|
const Crypto = require('./cryptography');
|
|
12
13
|
|
|
@@ -78,9 +79,74 @@ function Binh() {
|
|
|
78
79
|
return new ConfigLoader(config);
|
|
79
80
|
};
|
|
80
81
|
|
|
82
|
+
binh.ui = function(amodule, component, htmltags, links) {
|
|
83
|
+
component.htmltags = htmltags;
|
|
84
|
+
component.links = links;
|
|
85
|
+
binh.bundle('ui', amodule, component);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
binh.service = function(amodule, component, links) {
|
|
89
|
+
component.links = links;
|
|
90
|
+
binh.bundle('service', amodule, component);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
binh.style = function(amodule, component) {
|
|
94
|
+
binh.bundle('style', amodule, component);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
binh.css = function(amodule, cssFilename) {
|
|
98
|
+
var cssFilePath = cssFilename && path.join(amodule.path, cssFilename) || amodule.filename.replace(/.js$/, '');
|
|
99
|
+
var content = require('fs').readFileSync(cssFilePath, { encoding: 'utf8', flag: 'r' });
|
|
100
|
+
content = content.replace(/\s+/g, ' ');
|
|
101
|
+
var component = new Function(`return ${JSON.stringify(content)};`);
|
|
102
|
+
binh.bundle('style', amodule, component);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
binh.bundle = function(type, amodule, component) {
|
|
106
|
+
if (!(component instanceof Function)) return;
|
|
107
|
+
|
|
108
|
+
var dependencies = {};
|
|
109
|
+
handleDependencies(dependencies, amodule.children);
|
|
110
|
+
|
|
111
|
+
component.type = type;
|
|
112
|
+
component.dependencies = dependencies;
|
|
113
|
+
component.path = amodule.filename;
|
|
114
|
+
component.constructor = Component;
|
|
115
|
+
|
|
116
|
+
amodule.exports = component;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function handleDependencies(dependencies, children) {
|
|
120
|
+
children.forEach(function(child) {
|
|
121
|
+
if (dependencies[child.filename]) return;
|
|
122
|
+
|
|
123
|
+
var component = child.exports;
|
|
124
|
+
|
|
125
|
+
if (component.constructor === Component) {
|
|
126
|
+
dependencies[child.filename] = component;
|
|
127
|
+
handleDependencies(dependencies, child.children);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
81
132
|
global.binh = binh;
|
|
82
133
|
global.config = binh.config;
|
|
83
134
|
|
|
135
|
+
this.web = function(buildpath, sourcepath) {
|
|
136
|
+
if (typeof buildpath !== 'string') return this;
|
|
137
|
+
|
|
138
|
+
var destination = path.join(rootpath, buildpath);
|
|
139
|
+
|
|
140
|
+
this.web.value = destination;
|
|
141
|
+
|
|
142
|
+
if (typeof sourcepath === 'string') {
|
|
143
|
+
var source = path.join(rootpath, sourcepath);
|
|
144
|
+
Component.generate(source, destination);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return this;
|
|
148
|
+
};
|
|
149
|
+
|
|
84
150
|
this.rootpath = function(path) {
|
|
85
151
|
rootpath = typeof path === 'string' ? path : require.main.path;
|
|
86
152
|
return this;
|
|
@@ -127,7 +193,7 @@ function Binh() {
|
|
|
127
193
|
};
|
|
128
194
|
|
|
129
195
|
this.api = function(api_path) {
|
|
130
|
-
this.api.value
|
|
196
|
+
this.api.value = path.join(rootpath, api_path);
|
|
131
197
|
return this;
|
|
132
198
|
};
|
|
133
199
|
|
|
@@ -157,6 +223,7 @@ function Binh() {
|
|
|
157
223
|
new Server({
|
|
158
224
|
port: _this.port.value,
|
|
159
225
|
api: APIs(_this.api.value),
|
|
226
|
+
web: _this.web.value,
|
|
160
227
|
callback: callback,
|
|
161
228
|
configs: configs
|
|
162
229
|
});
|
package/src/code.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
const { parse } = require('path');
|
|
3
|
+
|
|
4
|
+
function dependencies(component, root) {
|
|
5
|
+
var code = '', dependencies = component.dependencies;
|
|
6
|
+
|
|
7
|
+
for (var filepath in dependencies) {
|
|
8
|
+
var url = filepath.replace(root, '').replace(/\\/g, '/');
|
|
9
|
+
|
|
10
|
+
var name = parse(filepath).name.replace(/-/g, '').replace(/\W.*/, '');
|
|
11
|
+
|
|
12
|
+
var dependency = dependencies[filepath];
|
|
13
|
+
|
|
14
|
+
code += `var ${name} = Binh.${dependency.type}('${url}', ${dependency.toString()});\r\n\r\n`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
code += `Binh.${component.type}(${component.toString()});\r\n`
|
|
18
|
+
|
|
19
|
+
return code;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function htmltags(component) {
|
|
23
|
+
var code = '', list = [],
|
|
24
|
+
tags = distinctValues(component, 'htmltags');
|
|
25
|
+
|
|
26
|
+
tags.forEach(function(tag) {
|
|
27
|
+
list.push(`${tag} = Binh.el('${tag}')`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (list.length) {
|
|
31
|
+
code = `var ${list.join(',\r\n')};`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
code += code ? '\r\n' : '';
|
|
35
|
+
|
|
36
|
+
return code;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function prequire(component, codes) {
|
|
40
|
+
var code = '', links = distinctValues(component, 'links');
|
|
41
|
+
|
|
42
|
+
if (links.length) {
|
|
43
|
+
code = `Binh.requires(['${links.join("','")}'], function() {\r\n\r\n${codes.join('\r\n')}\r\n});`;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
code = IIF(codes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return code;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function IIF(codes) {
|
|
53
|
+
return `!function(){\r\n\r\n${codes.join('\r\n')}\r\n}();`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function distinctValues(component, key) {
|
|
57
|
+
var arrays = [component[key]],
|
|
58
|
+
dependencies = component.dependencies;
|
|
59
|
+
|
|
60
|
+
for (var filepath in dependencies) {
|
|
61
|
+
arrays.push(dependencies[filepath][key]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return uniquefy(arrays);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function uniquefy(arrays) {
|
|
68
|
+
var map = {};
|
|
69
|
+
|
|
70
|
+
if (!(arrays instanceof Array)) return;
|
|
71
|
+
|
|
72
|
+
arrays.forEach(function(array) {
|
|
73
|
+
if (!(array instanceof Array)) return;
|
|
74
|
+
|
|
75
|
+
array.forEach(function(value) {
|
|
76
|
+
map[value] = true;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return Object.keys(map);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
dependencies,
|
|
85
|
+
htmltags,
|
|
86
|
+
prequire,
|
|
87
|
+
IIF
|
|
88
|
+
};
|