binhend 1.0.10 → 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/configuration.js +3 -1
- 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
package/src/component.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
const { readdir, statSync, writeFile, existsSync, mkdirSync, copyFile, readFileSync } = require('fs');
|
|
3
|
+
const { join, dirname, parse } = require('path');
|
|
4
|
+
const CodeFormat = require('./code');
|
|
5
|
+
|
|
6
|
+
// TODO
|
|
7
|
+
// [-] Enhance code by removing sync logics (except for existsSync, mkdirSync): readdir, readFileSync, (statSync?)
|
|
8
|
+
// [-] Able to minify/beautify generated files
|
|
9
|
+
|
|
10
|
+
function generate(source, destination) {
|
|
11
|
+
if (source == undefined) return;
|
|
12
|
+
console.log('[BINHEND][COMPONENT] Start building components from:', source);
|
|
13
|
+
console.log('[BINHEND][COMPONENT] to:', destination);
|
|
14
|
+
processDirectory(source, source, destination);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function processDirectory(root, current, destination) {
|
|
18
|
+
readdir(current, function (error, dirents) {
|
|
19
|
+
if (error) {
|
|
20
|
+
showError('Failed scanning directory', filepath, error);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
dirents.forEach(function (dirent) {
|
|
25
|
+
var filepath = join(current, dirent);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
var stat = statSync(filepath);
|
|
29
|
+
|
|
30
|
+
if (stat.isFile()) {
|
|
31
|
+
var outpath = filepath.replace(root, destination);
|
|
32
|
+
ensureDirectoryExistence(outpath);
|
|
33
|
+
|
|
34
|
+
if (parse(dirent).ext !== '.js') {
|
|
35
|
+
return cloneFile(filepath, outpath);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
var component = require(filepath);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
var content = readFileSync(filepath, { encoding: 'utf8', flag: 'r' });
|
|
43
|
+
var isComponent = content.match(/\s*binh\s*.(ui|service|style)\s*\(\s*module\s*,.*\)/);
|
|
44
|
+
if (isComponent) {
|
|
45
|
+
showError('Failed requiring module', filepath, error);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return cloneFile(filepath, outpath);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!(component instanceof Function) || component.constructor !== Component) {
|
|
52
|
+
return cloneFile(filepath, outpath);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var code = joinCodes(component, root);
|
|
56
|
+
|
|
57
|
+
writeFile(outpath, code, { encoding: 'utf8', flag: 'w' }, function(error) {
|
|
58
|
+
if (error) {
|
|
59
|
+
showError('Failed writing file', filepath, error);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (stat.isDirectory()) {
|
|
65
|
+
processDirectory(root, filepath, destination);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
showError('Failed processing file', filepath, error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function ensureDirectoryExistence(filepath) {
|
|
76
|
+
var dirpath = dirname(filepath);
|
|
77
|
+
if (existsSync(dirpath)) return true;
|
|
78
|
+
ensureDirectoryExistence(dirpath);
|
|
79
|
+
mkdirSync(dirpath);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function joinCodes(component, root) {
|
|
83
|
+
var fullcode = CodeFormat.prequire(component, [
|
|
84
|
+
CodeFormat.dependencies(component, root),
|
|
85
|
+
CodeFormat.htmltags(component)
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
return fullcode;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function cloneFile(filepath, outpath) {
|
|
92
|
+
copyFile(filepath, outpath, function(error) {
|
|
93
|
+
if (error) {
|
|
94
|
+
showError('Failed copying file to', outpath, error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function showError(message, id, error) {
|
|
100
|
+
console.log(`[BINHEND][COMPONENT] ${message}:`, id);
|
|
101
|
+
console.log('[BINHEND][COMPONENT] Error details:', error);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var Component = {
|
|
105
|
+
generate
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
module.exports = Component;
|
package/src/configuration.js
CHANGED
|
@@ -112,7 +112,9 @@ function filter(object, filters) {
|
|
|
112
112
|
|
|
113
113
|
for (var i = 0; i < length; i++) {
|
|
114
114
|
var field = filters[i];
|
|
115
|
-
|
|
115
|
+
if (object.hasOwnProperty(field)) {
|
|
116
|
+
filtered[field] = object[field];
|
|
117
|
+
}
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
return filtered;
|
package/src/server.js
CHANGED
|
@@ -3,10 +3,19 @@ const express = require('express');
|
|
|
3
3
|
function Server(options) {
|
|
4
4
|
const server = express();
|
|
5
5
|
const PORT = options.port || 1300;
|
|
6
|
+
const WEB_DIRECTORY = options.web;
|
|
7
|
+
|
|
8
|
+
if (WEB_DIRECTORY) {
|
|
9
|
+
server.use(express.static(WEB_DIRECTORY));
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
if (options.api instanceof Function) {
|
|
8
13
|
server.use(options.api);
|
|
9
14
|
}
|
|
15
|
+
|
|
16
|
+
if (WEB_DIRECTORY) {
|
|
17
|
+
server.get('/*', (req, res) => res.sendFile('index.html', { root: WEB_DIRECTORY }));
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
server.listen(PORT, function() {
|
|
12
21
|
console.log(`[NODE] Server is listening on http://localhost:${PORT}/`);
|
package/testa.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// const { join, parse } = require('path');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// var path = join('D:\\Codebase\\GitHub\\binhend\\src\\node_modules', 'item');
|
|
5
|
+
|
|
6
|
+
// console.log('D:\\Codebase\\GitHub\\binhend\\src\\node_modules');
|
|
7
|
+
// console.log(path);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// var path2 = join('node_modules', 'item', 'an');
|
|
12
|
+
// console.log(path2);
|
|
13
|
+
|
|
14
|
+
// var path3 = join('node_modules', '');
|
|
15
|
+
// console.log(path3);
|
|
16
|
+
|
|
17
|
+
// var path4 = join('node_modules', 'somthing', 'filename.min.js');
|
|
18
|
+
// console.log(parse(path4).name);
|
|
19
|
+
// console.log(parse(path4).name.replace(/\..*/, ''));
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// const abc = require('./example_webcomp/components/styles/todos.css');
|
|
23
|
+
|
|
24
|
+
var abc = new Function('return 123;');
|
|
25
|
+
|
|
26
|
+
console.log(abc);
|
|
27
|
+
console.log(abc());
|
|
28
|
+
console.log(abc.toString());
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|