binhend 1.1.0 → 1.1.1
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_api/routes/test/bb.js +1 -1
- package/example_api/routes/test/index.js +1 -1
- package/example_api/routes/test/some.js +1 -1
- package/example_api/routes/test.js +5 -1
- package/example_api/routes/testa.js +1 -1
- package/example_webcomp/components/common/InputText.js +11 -1
- package/example_webcomp/components/common/Link.js +1 -1
- package/example_webcomp/components/common/Link2.js +1 -1
- package/example_webcomp/components/index.js +9 -1
- package/example_webcomp/components/layouts/AppMainLayout.js +1 -1
- package/example_webcomp/components/layouts/AppToDos.js +7 -5
- package/example_webcomp/{public/common → components/layouts}/Link.js +5 -6
- package/example_webcomp/components/layouts/PageContent.js +1 -1
- package/example_webcomp/components/layouts/PageHeader.js +2 -2
- package/example_webcomp/components/layouts/ToDoItem.js +3 -2
- package/example_webcomp/components/styles/temp.css +4 -1
- package/package.json +1 -1
- package/src/binh.js +20 -207
- package/src/binh.server.app.js +70 -0
- package/src/binh.server.config.js +79 -0
- package/src/binh.web.builder.js +72 -0
- package/src/code.js +70 -15
- package/src/component.js +1 -1
- package/src/cryptography.js +6 -1
- package/example_webcomp/public/AnUserInterface.js +0 -0
- package/example_webcomp/public/common/InputText.js +0 -17
- package/example_webcomp/public/common/Link2.js +0 -13
- package/example_webcomp/public/index.html +0 -18
- package/example_webcomp/public/index.js +0 -6
- package/example_webcomp/public/layouts/AppMainLayout.js +0 -96
- package/example_webcomp/public/layouts/AppToDos.js +0 -100
- package/example_webcomp/public/layouts/PageContent.js +0 -29
- package/example_webcomp/public/layouts/PageHeader.js +0 -52
- package/example_webcomp/public/layouts/ToDoItem.js +0 -30
- package/example_webcomp/public/services/AnyService.js +0 -8
- package/example_webcomp/public/services/ServiceToDos.js +0 -46
- package/example_webcomp/public/styles/ToDoItemStyle.js +0 -44
- package/example_webcomp/public/styles/ToDoItemStyle2.js +0 -9
- package/example_webcomp/public/styles/temp.css +0 -4
- package/example_webcomp/public/styles/todo.css +0 -31
- package/example_webcomp/public/styles/todo.css.js +0 -9
- package/testa.js +0 -28
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
const { get } = binh
|
|
1
|
+
const { get } = binh.router(module);
|
|
2
|
+
|
|
3
|
+
get('/', function(req, res) {
|
|
4
|
+
res.json({ path:'/', dir: __dirname, file: __filename });
|
|
5
|
+
});
|
|
2
6
|
|
|
3
7
|
get('/bb', function(req, res) {
|
|
4
8
|
res.json({ path:'/bb', dir: __dirname, file: __filename });
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
|
|
2
|
+
require('./../services/ServiceToDos').as('Toto');
|
|
3
|
+
|
|
2
4
|
function main() {
|
|
5
|
+
// var addTodoItem = Toto.debounce('add', 1500, true);
|
|
6
|
+
|
|
7
|
+
// setTimeout(function() {
|
|
8
|
+
// addTodoItem('over 10kms');
|
|
9
|
+
// }, 10000);
|
|
10
|
+
|
|
3
11
|
var inputbox = input({ type: 'text', placeholder: 'Enter to-do item' });
|
|
12
|
+
|
|
13
|
+
var submit = inputbox.action('submit');
|
|
4
14
|
|
|
5
15
|
inputbox.on('keypress', function (event) {
|
|
6
16
|
if (event.key === "Enter") {
|
|
7
|
-
|
|
17
|
+
submit(inputbox.element.value);
|
|
8
18
|
}
|
|
9
19
|
});
|
|
10
20
|
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
|
|
2
|
+
Binh.script('https://cdn.jsdelivr.net/gh/jquery/jquery@3.5.1/dist/jquery.min.js', function() {
|
|
3
|
+
Binh.link('https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css');
|
|
4
|
+
Binh.script('https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js');
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
Binh.Router.onload(function() {
|
|
8
|
+
console.log('#### ON ROUTING !!!');
|
|
9
|
+
});
|
|
10
|
+
|
|
2
11
|
Binh({
|
|
3
12
|
'': '/layouts/AppMainLayout.js',
|
|
4
13
|
'/todos': '/layouts/AppToDos.js'
|
|
5
14
|
});
|
|
6
|
-
|
|
@@ -19,4 +19,4 @@ function AppMainLayout() {
|
|
|
19
19
|
return MainLayout;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
binh.ui(module, AppMainLayout, ['div'], ['https://code.jquery.com/jquery-3.7.0.min.js']);
|
|
22
|
+
binh.ui(module, AppMainLayout, ['div'], ['https://code.jquery.com/jquery-3.7.0.min.js', 'https://code.jquery.com/jquery-3.7.0.min.js']);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
require('./PageHeader');
|
|
3
3
|
// require('./ToDoItem');
|
|
4
4
|
require('./../common/InputText');
|
|
5
|
-
require('
|
|
5
|
+
require('./Link');
|
|
6
|
+
require('./../services/ServiceToDos').as('Dodo');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
function main() {
|
|
9
|
-
var
|
|
10
|
-
var
|
|
10
|
+
var ServiceToDos = Dodo;
|
|
11
|
+
// var PageHeader = Binh.ui('/layouts/PageHeader.js');
|
|
12
|
+
var ToDoItem = Binh.ui('/layouts/ToDoItem.js');
|
|
11
13
|
// var addTodoItem = ServiceToDos.does('add');
|
|
12
14
|
// var addTodoItem = ServiceToDos.debounce('add', 1500); // trailing only
|
|
13
15
|
var addTodoItem = ServiceToDos.debounce('add', 1500, true); // both leading & trailing
|
|
@@ -44,4 +46,4 @@ function main() {
|
|
|
44
46
|
return maindiv;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
binh.ui(module, main, ['div', 'span']);
|
|
49
|
+
binh.ui(module, main, ['div', 'span'], ['https://code.jquery.com/jquery-3.7.0.min.js']);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
!function(){
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
function Link() {
|
|
4
|
+
var { a } = Binh.element('a');
|
|
5
5
|
|
|
6
6
|
var text = arguments[0];
|
|
7
7
|
var path = arguments[1];
|
|
@@ -11,7 +11,6 @@ Binh.ui(function Link() {
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
return link;
|
|
14
|
-
}
|
|
15
|
-
|
|
14
|
+
}
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
binh.ui(module, Link);
|
|
@@ -4,14 +4,15 @@ require('./../styles/ToDoItemStyle2');
|
|
|
4
4
|
// require('../styles/todo.css.js');
|
|
5
5
|
|
|
6
6
|
function main(props) {
|
|
7
|
-
// var ToDoItemStyle =
|
|
7
|
+
// var ToDoItemStyle = Binh.style('/styles/todo.css');
|
|
8
8
|
|
|
9
9
|
var todoitem = div({ style: 'margin: 3px;' });
|
|
10
|
+
var removeToDoItem = todoitem.action('remove');
|
|
10
11
|
|
|
11
12
|
var remove_button = span({ class: 'btn-remove' })('X');
|
|
12
13
|
|
|
13
14
|
remove_button.on('click', function() {
|
|
14
|
-
|
|
15
|
+
removeToDoItem(props.id);
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
todoitem(span(props.text), span('-------'), remove_button);
|
package/package.json
CHANGED
package/src/binh.js
CHANGED
|
@@ -1,159 +1,18 @@
|
|
|
1
|
-
const crypto = require('crypto');
|
|
2
|
-
const cluster = require('cluster');
|
|
3
|
-
const os = require('os');
|
|
4
1
|
const path = require('path');
|
|
5
|
-
|
|
6
|
-
const { ConfigLoader } = require('./configuration');
|
|
7
|
-
const { HTTPS } = require('./https');
|
|
8
|
-
const { Server } = require('./server');
|
|
9
|
-
const { APIs, Router } = require('./api');
|
|
10
|
-
const Component = require('./component');
|
|
11
|
-
|
|
12
2
|
const Crypto = require('./cryptography');
|
|
13
3
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
function generateId() {
|
|
17
|
-
crypto.randomUUID({ disableEntropyCache: true });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function defaultConfigLoader(loader) {
|
|
21
|
-
loader.object(process.env);
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
loader.file('.env');
|
|
25
|
-
}
|
|
26
|
-
catch(e) {}
|
|
4
|
+
const { HTTPS } = require('./https');
|
|
5
|
+
const { ConfigLoader } = require('./configuration');
|
|
27
6
|
|
|
28
|
-
|
|
29
|
-
}
|
|
7
|
+
const { ServerApp } = require('./binh.server.app');
|
|
8
|
+
const { ServerConfig } = require('./binh.server.config');
|
|
9
|
+
const { WebBuilder } = require('./binh.web.builder');
|
|
30
10
|
|
|
31
11
|
function Binh() {
|
|
32
|
-
var
|
|
33
|
-
forkcount = 0,
|
|
34
|
-
rootpath = require.main.path;
|
|
35
|
-
|
|
36
|
-
var config = {}, loadConfigs = null, groupLoadConfigs = [], configloader = new ConfigLoader(config);
|
|
37
|
-
|
|
38
|
-
var binh = function(module_path) {
|
|
39
|
-
return module_path == undefined ? module.exports : require(path.join(rootpath, module_path));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
binh.path = function(any_path = '') {
|
|
43
|
-
return path.join(rootpath, any_path);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
binh.config = function(key) {
|
|
47
|
-
if (typeof key !== 'string') return config;
|
|
48
|
-
|
|
49
|
-
if (config.hasOwnProperty(key)) return config[key];
|
|
50
|
-
|
|
51
|
-
var pointer = config, keys = key.split('.'), length = keys.length;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
for (var i = 0; i < length; i++) {
|
|
55
|
-
pointer = pointer[keys[i]];
|
|
56
|
-
}
|
|
57
|
-
return pointer;
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
binh.config.reload = function() {
|
|
65
|
-
return new Promise(function(resolve) {
|
|
66
|
-
var loader = new ConfigLoader(config);
|
|
67
|
-
|
|
68
|
-
groupLoadConfigs.forEach(function(loadConfigs) {
|
|
69
|
-
if (loadConfigs instanceof Function) {
|
|
70
|
-
loadConfigs(loader);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
loader.done(resolve);
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
binh.config.loader = function() {
|
|
79
|
-
return new ConfigLoader(config);
|
|
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
|
-
|
|
132
|
-
global.binh = binh;
|
|
133
|
-
global.config = binh.config;
|
|
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
|
-
|
|
150
|
-
this.rootpath = function(path) {
|
|
151
|
-
rootpath = typeof path === 'string' ? path : require.main.path;
|
|
152
|
-
return this;
|
|
153
|
-
};
|
|
12
|
+
var rootpath = require.main.path;
|
|
154
13
|
|
|
155
14
|
this.id = function(id) {
|
|
156
|
-
binh.id = id == undefined ?
|
|
15
|
+
binh.id = id == undefined ? Crypto.randomUUID() : JSON.stringify(id);
|
|
157
16
|
return this;
|
|
158
17
|
};
|
|
159
18
|
|
|
@@ -162,74 +21,28 @@ function Binh() {
|
|
|
162
21
|
return this;
|
|
163
22
|
};
|
|
164
23
|
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
loadConfigs = module;
|
|
168
|
-
loadConfigs(configloader);
|
|
169
|
-
}
|
|
170
|
-
else if (typeof module === 'string') {
|
|
171
|
-
loadConfigs = binh(module);
|
|
172
|
-
loadConfigs(configloader);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
loadConfigs = defaultConfigLoader;
|
|
176
|
-
loadConfigs(configloader);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
groupLoadConfigs.push(loadConfigs);
|
|
180
|
-
|
|
24
|
+
this.rootpath = function(path) {
|
|
25
|
+
rootpath = typeof path === 'string' ? path : require.main.path;
|
|
181
26
|
return this;
|
|
182
27
|
};
|
|
183
28
|
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
forkcount = Math.max(0, number >= 0 ? number : maxcpus + number);
|
|
187
|
-
return _this;
|
|
188
|
-
},
|
|
189
|
-
max: function() {
|
|
190
|
-
forkcount = maxcpus;
|
|
191
|
-
return _this;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
this.api = function(api_path) {
|
|
196
|
-
this.api.value = path.join(rootpath, api_path);
|
|
197
|
-
return this;
|
|
29
|
+
this.getRootpath = function() {
|
|
30
|
+
return rootpath;
|
|
198
31
|
};
|
|
199
32
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.port.value = port;
|
|
203
|
-
}
|
|
204
|
-
else if (typeof port === 'string') {
|
|
205
|
-
this.port.value = binh.config(port);
|
|
206
|
-
}
|
|
207
|
-
return this;
|
|
33
|
+
function binh(modulePath) {
|
|
34
|
+
return modulePath == undefined ? module.exports : require(path.join(rootpath, modulePath));
|
|
208
35
|
};
|
|
209
36
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
for (var i = 0; i < forkcount; i++) {
|
|
213
|
-
cluster.fork();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
launch(callback);
|
|
218
|
-
}
|
|
37
|
+
binh.path = function(anyPath = '') {
|
|
38
|
+
return path.join(rootpath, anyPath);
|
|
219
39
|
};
|
|
220
40
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
new Server({
|
|
224
|
-
port: _this.port.value,
|
|
225
|
-
api: APIs(_this.api.value),
|
|
226
|
-
web: _this.web.value,
|
|
227
|
-
callback: callback,
|
|
228
|
-
configs: configs
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
}
|
|
41
|
+
ServerApp(binh, this, ServerConfig(binh, this));
|
|
42
|
+
WebBuilder(binh, this);
|
|
232
43
|
|
|
44
|
+
global.binh = binh;
|
|
45
|
+
global.config = binh.config;
|
|
233
46
|
}
|
|
234
47
|
|
|
235
|
-
module.exports = { Binh, HTTPS, ConfigLoader, Crypto
|
|
48
|
+
module.exports = { Binh, HTTPS, ConfigLoader, Crypto };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const cluster = require('cluster');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { Server } = require('./server');
|
|
6
|
+
const { APIs, Router } = require('./api');
|
|
7
|
+
|
|
8
|
+
const maxcpus = os.cpus().length;
|
|
9
|
+
|
|
10
|
+
function ServerApp(binh, Binh, configloader) {
|
|
11
|
+
var forkcount = 0,
|
|
12
|
+
rootpath = Binh.getRootpath();
|
|
13
|
+
|
|
14
|
+
binh.router = function(module) {
|
|
15
|
+
return Router(module);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Binh.api = function(api_path) {
|
|
19
|
+
Binh.api.value = path.join(rootpath, api_path);
|
|
20
|
+
return Binh;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Binh.cluster = {
|
|
24
|
+
fork: function(number) {
|
|
25
|
+
forkcount = Math.max(0, number >= 0 ? number : maxcpus + number);
|
|
26
|
+
return Binh;
|
|
27
|
+
},
|
|
28
|
+
max: function() {
|
|
29
|
+
forkcount = maxcpus;
|
|
30
|
+
return Binh;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
Binh.port = function(port) {
|
|
35
|
+
if (typeof port === 'number') {
|
|
36
|
+
Binh.port.value = port;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof port === 'string') {
|
|
39
|
+
Binh.port.value = binh.config(port);
|
|
40
|
+
}
|
|
41
|
+
return Binh;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Binh.start = function(callback) {
|
|
45
|
+
if (forkcount > 0 && cluster.isMaster) {
|
|
46
|
+
for (var i = 0; i < forkcount; i++) {
|
|
47
|
+
cluster.fork();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
launch(callback);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function launch(callback) {
|
|
56
|
+
configloader.done(function(configs) {
|
|
57
|
+
new Server({
|
|
58
|
+
port: Binh.port.value,
|
|
59
|
+
api: APIs(Binh.api.value),
|
|
60
|
+
web: Binh.web.value,
|
|
61
|
+
callback: callback,
|
|
62
|
+
configs: configs
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
ServerApp
|
|
70
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
const { ConfigLoader } = require('./configuration');
|
|
3
|
+
|
|
4
|
+
function ServerConfig(binh, Binh) {
|
|
5
|
+
|
|
6
|
+
var config = {}, loadConfigs = null, groupLoadConfigs = [], configloader = new ConfigLoader(config);
|
|
7
|
+
|
|
8
|
+
binh.config = function(key) {
|
|
9
|
+
if (typeof key !== 'string') return config;
|
|
10
|
+
|
|
11
|
+
if (config.hasOwnProperty(key)) return config[key];
|
|
12
|
+
|
|
13
|
+
var pointer = config, keys = key.split('.'), length = keys.length;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
for (var i = 0; i < length; i++) {
|
|
17
|
+
pointer = pointer[keys[i]];
|
|
18
|
+
}
|
|
19
|
+
return pointer;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
binh.config.reload = function() {
|
|
27
|
+
return new Promise(function(resolve) {
|
|
28
|
+
var loader = new ConfigLoader(config);
|
|
29
|
+
|
|
30
|
+
groupLoadConfigs.forEach(function(loadConfigs) {
|
|
31
|
+
if (loadConfigs instanceof Function) {
|
|
32
|
+
loadConfigs(loader);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
loader.done(resolve);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
binh.config.loader = function() {
|
|
41
|
+
return new ConfigLoader(config);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Binh.config = function(module) {
|
|
45
|
+
if (module instanceof Function) {
|
|
46
|
+
loadConfigs = module;
|
|
47
|
+
loadConfigs(configloader);
|
|
48
|
+
}
|
|
49
|
+
else if (typeof module === 'string') {
|
|
50
|
+
loadConfigs = binh(module);
|
|
51
|
+
loadConfigs(configloader);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
loadConfigs = defaultConfigLoader;
|
|
55
|
+
loadConfigs(configloader);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
groupLoadConfigs.push(loadConfigs);
|
|
59
|
+
|
|
60
|
+
return Binh;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return configloader;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function defaultConfigLoader(loader) {
|
|
67
|
+
loader.object(process.env);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
loader.file('.env');
|
|
71
|
+
}
|
|
72
|
+
catch(e) {}
|
|
73
|
+
|
|
74
|
+
loader.cli();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
ServerConfig
|
|
79
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const Component = require('./component');
|
|
5
|
+
|
|
6
|
+
function WebBuilder(binh, Binh) {
|
|
7
|
+
binh.ui = function(amodule, component, htmltags, links) {
|
|
8
|
+
component.htmltags = htmltags;
|
|
9
|
+
component.links = links;
|
|
10
|
+
binh.bundle('ui', amodule, component);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
binh.service = function(amodule, component, links) {
|
|
14
|
+
component.links = links;
|
|
15
|
+
binh.bundle('service', amodule, component);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
binh.style = function(amodule, component) {
|
|
19
|
+
binh.bundle('style', amodule, component);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
binh.css = function(amodule, cssFilename) {
|
|
23
|
+
var cssFilePath = cssFilename && path.join(amodule.path, cssFilename) || amodule.filename.replace(/.js$/, '');
|
|
24
|
+
var content = require('fs').readFileSync(cssFilePath, { encoding: 'utf8', flag: 'r' });
|
|
25
|
+
content = content.replace(/\s+/g, ' ');
|
|
26
|
+
var component = new Function(`return ${JSON.stringify(content)};`);
|
|
27
|
+
binh.bundle('style', amodule, component);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
binh.bundle = function(type, amodule, component) {
|
|
31
|
+
if (!(component instanceof Function)) return;
|
|
32
|
+
|
|
33
|
+
component.type = type;
|
|
34
|
+
component.filename = amodule.filename;
|
|
35
|
+
component.constructor = Component;
|
|
36
|
+
component.module = amodule;
|
|
37
|
+
component.as = alias;
|
|
38
|
+
component.vars = {};
|
|
39
|
+
|
|
40
|
+
amodule.exports = component;
|
|
41
|
+
|
|
42
|
+
amodule.children.forEach(function(child) {
|
|
43
|
+
child = child.exports;
|
|
44
|
+
if (child.constructor !== Component) return;
|
|
45
|
+
if (child.alias) component.vars[child.filename] = child.alias;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function alias(name) {
|
|
50
|
+
this.alias = name;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Binh.web = function(buildpath, sourcepath) {
|
|
54
|
+
if (typeof buildpath !== 'string') return this;
|
|
55
|
+
|
|
56
|
+
var rootpath = Binh.getRootpath(),
|
|
57
|
+
destination = path.join(rootpath, buildpath);
|
|
58
|
+
|
|
59
|
+
if (typeof sourcepath === 'string') {
|
|
60
|
+
var source = path.join(rootpath, sourcepath);
|
|
61
|
+
Component.generate(source, destination);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Binh.web.value = destination;
|
|
65
|
+
|
|
66
|
+
return Binh;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
WebBuilder
|
|
72
|
+
};
|