binhend 1.5.7 → 1.5.8
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/bin/commands/create-frontend.js +18 -0
- package/bin/index.js +32 -30
- package/bin/templates/frontend/.env +1 -0
- package/bin/templates/frontend/build.js +17 -0
- package/bin/templates/frontend/config.js +6 -0
- package/bin/templates/frontend/server.js +11 -0
- package/bin/templates/frontend/src/App.js +6 -0
- package/bin/templates/frontend/src/index.html +15 -0
- package/bin/templates/frontend/src/main.js +4 -0
- package/dest/.env +1 -0
- package/dest/build/module/App.js +11 -0
- package/dest/build/module/Hmm.js +7 -0
- package/dest/build/module/index.html +15 -0
- package/dest/build/module/index.js +9 -0
- package/dest/build/module/main.js +9 -0
- package/dest/build/web/App.js +1 -0
- package/dest/build/web/Hmm.js +0 -0
- package/dest/build/web/index.html +15 -0
- package/dest/build/web/index.js +4 -0
- package/dest/build/web/main.js +4 -0
- package/dest/build.dev.js +24 -0
- package/dest/build.js +19 -0
- package/dest/build.prod.js +13 -0
- package/dest/config.js +6 -0
- package/dest/index.dev.js +15 -0
- package/dest/index.js +29 -0
- package/dest/index.prod.js +13 -0
- package/dest/server.js +27 -0
- package/dest/src/App.js +6 -0
- package/dest/src/Hmm.js +0 -0
- package/dest/src/index.html +15 -0
- package/dest/src/index.js +4 -0
- package/dest/src/main.js +4 -0
- package/package.json +3 -2
- package/src/binh.server.config.js +5 -4
- package/src/server.js +1 -1
- package/bin/frontend.js +0 -3
- /package/bin/{backend.js → commands/create-backend.js} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
module.exports = (args) => {
|
|
6
|
+
try {
|
|
7
|
+
var currentDirectory = process.cwd(), // directory path where the command is executed
|
|
8
|
+
destinationPath = path.join(currentDirectory, args[0] || 'frontend'),
|
|
9
|
+
sourcePath = path.join(__dirname, '../templates/frontend');
|
|
10
|
+
|
|
11
|
+
console.log('[BINHEND][CODEGEN] Generate front-end structure:', destinationPath);
|
|
12
|
+
fs.cpSync(sourcePath, destinationPath, {recursive: true});
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error('[BINHEND][CODEGEN] Error generating front-end structure!');
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
package/bin/index.js
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const commandMap = {
|
|
4
|
+
create: {
|
|
5
|
+
backend: () => require('./commands/create-backend'),
|
|
6
|
+
frontend: () => require('./commands/create-frontend'),
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
var command = commandMap,
|
|
11
|
+
args = process.argv.slice(2); // remove first 2 args in list: <path-to-nodejs> and <path-to-this-CLI-program-file>
|
|
12
|
+
|
|
13
|
+
while (args.length) {
|
|
14
|
+
var arg = args[0];
|
|
15
|
+
|
|
16
|
+
if (command.hasOwnProperty(arg)) {
|
|
17
|
+
command = command[arg];
|
|
18
|
+
args.shift();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (command instanceof Function) {
|
|
26
|
+
command()(args);
|
|
27
|
+
}
|
|
28
|
+
else if (command?.default instanceof Function) {
|
|
29
|
+
command.default()(args);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log('Unknown command...');
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
const handler = map[command];
|
|
28
|
-
|
|
29
|
-
if (handler) handler();
|
|
30
|
-
else console.log('Unknown command...');
|
|
31
|
-
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
port=1234
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { Binh } = require('binhend');
|
|
2
|
+
|
|
3
|
+
const app = new Binh();
|
|
4
|
+
|
|
5
|
+
app.config('config.js', afterLoadedConfigs); // import module from path './config.js' to run and load configs
|
|
6
|
+
|
|
7
|
+
function afterLoadedConfigs(configs) {
|
|
8
|
+
const options = {
|
|
9
|
+
source: 'src',
|
|
10
|
+
module: 'build/module',
|
|
11
|
+
web: 'build/web'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
configs.env === 'prod' ? app.webBundle(options).minify() : app.webLazy(options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = app;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const app = require('./build');
|
|
2
|
+
|
|
3
|
+
app.cors(); // no input => use default middleware for CORS settings
|
|
4
|
+
|
|
5
|
+
app.port('port'); // get value from config via key 'port'
|
|
6
|
+
|
|
7
|
+
app.start((server, configs) => {
|
|
8
|
+
console.log('[BINHEND][SERVER] Loaded configs:', configs);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
module.exports = app;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Binhjs App</title>
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<script src="https://binhjs.pages.dev/dist/binh.min.js"></script>
|
|
10
|
+
<script src="/main.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body></body>
|
|
14
|
+
|
|
15
|
+
</html>
|
package/dest/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
port=1234
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var { context, tag, svg, script, require, css } = binh.context(module, require);
|
|
2
|
+
binh.component(context, ui, service, style);
|
|
3
|
+
var ui = null, service = null, style = null;
|
|
4
|
+
|
|
5
|
+
tag('h1');
|
|
6
|
+
|
|
7
|
+
function ui() {
|
|
8
|
+
return h1('Hello World');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
;binh.final(module);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Binhjs App</title>
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<script src="https://binhjs.pages.dev/dist/binh.min.js"></script>
|
|
10
|
+
<script src="/main.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body></body>
|
|
14
|
+
|
|
15
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){var n,e=window.Binh;e.els=e.element("h1"),n=e.els.h1,e.ui(function(){return n("Hello World")})}();
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Binhjs App</title>
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<script src="https://binhjs.pages.dev/dist/binh.min.js"></script>
|
|
10
|
+
<script src="/main.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body></body>
|
|
14
|
+
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Binh } = require('binhend');
|
|
4
|
+
|
|
5
|
+
var app = new Binh();
|
|
6
|
+
|
|
7
|
+
app.webLazy({
|
|
8
|
+
source: 'src',
|
|
9
|
+
module: 'build/module',
|
|
10
|
+
web: 'build/web'
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// app.cors().port(1234).start();
|
|
14
|
+
|
|
15
|
+
module.exports = app;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// module.exports = (app) => {
|
|
19
|
+
// app.webLazy({
|
|
20
|
+
// source: 'src',
|
|
21
|
+
// module: 'build/module',
|
|
22
|
+
// web: 'build/web'
|
|
23
|
+
// });
|
|
24
|
+
// };
|
package/dest/build.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// const { Binh } = require('binhend');
|
|
2
|
+
|
|
3
|
+
const { Binh } = require('../src/binh');
|
|
4
|
+
|
|
5
|
+
const app = new Binh();
|
|
6
|
+
|
|
7
|
+
app.config('config.js', afterLoadedConfigs); // import middleware from path './config.js' to run and load configs
|
|
8
|
+
|
|
9
|
+
function afterLoadedConfigs(configs) {
|
|
10
|
+
const options = {
|
|
11
|
+
source: 'src',
|
|
12
|
+
module: 'build/module',
|
|
13
|
+
web: 'build/web'
|
|
14
|
+
};
|
|
15
|
+
console.log("configs.env === 'prod'", configs.env === 'prod');
|
|
16
|
+
configs.env === 'prod' ? app.webBundle(options).minify(true) : app.webLazy(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = app;
|
package/dest/config.js
ADDED
package/dest/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { Binh } = require('binhend');
|
|
2
|
+
|
|
3
|
+
var app = new Binh();
|
|
4
|
+
|
|
5
|
+
app.webBundle({
|
|
6
|
+
source: 'src',
|
|
7
|
+
module: 'build/module',
|
|
8
|
+
web: 'build/web'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// app.config('config.js') // execute middleware to load configs
|
|
12
|
+
// .cors()
|
|
13
|
+
// .port('port') // get value from config via key 'port'
|
|
14
|
+
// .start((server, configs) => {
|
|
15
|
+
// console.log('configs', configs);
|
|
16
|
+
// });
|
|
17
|
+
|
|
18
|
+
app.cors();
|
|
19
|
+
|
|
20
|
+
app.config('config.js'); // execute middleware to load configs
|
|
21
|
+
|
|
22
|
+
app.port('port'); // get value from config via key 'port'
|
|
23
|
+
|
|
24
|
+
app.start((server, configs) => {
|
|
25
|
+
console.log('configs', configs);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = app;
|
package/dest/server.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// const { Binh } = require('binhend');
|
|
2
|
+
// const { Binh } = require('../src/binh');
|
|
3
|
+
|
|
4
|
+
// var app = new Binh();
|
|
5
|
+
|
|
6
|
+
// app.config('config.js', (configs) => { // run middleware to load configs
|
|
7
|
+
// const options = {
|
|
8
|
+
// source: 'src',
|
|
9
|
+
// module: 'build/module',
|
|
10
|
+
// web: 'build/web'
|
|
11
|
+
// };
|
|
12
|
+
|
|
13
|
+
// configs.env === 'prod' ? app.webBundle(options) : app.webLazy(options);
|
|
14
|
+
// });
|
|
15
|
+
|
|
16
|
+
const app = require('./build');
|
|
17
|
+
|
|
18
|
+
app.cors();
|
|
19
|
+
|
|
20
|
+
app.port('port'); // get value from config via key 'port'
|
|
21
|
+
|
|
22
|
+
app.start((server, configs) => {
|
|
23
|
+
console.log('configs', configs);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
module.exports = app;
|
package/dest/src/App.js
ADDED
package/dest/src/Hmm.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Binhjs App</title>
|
|
7
|
+
<meta charset="utf-8">
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<script src="https://binhjs.pages.dev/dist/binh.min.js"></script>
|
|
10
|
+
<script src="/main.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body></body>
|
|
14
|
+
|
|
15
|
+
</html>
|
package/dest/src/main.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "binhend",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Nguyen Duc Binh",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
13
|
"example-api": "node example_api PORT=5555",
|
|
14
14
|
"example-webcomp": "node example_webcomp",
|
|
15
|
-
"example-web2": "node example_web2"
|
|
15
|
+
"example-web2": "node example_web2",
|
|
16
|
+
"server": "node dest/server.js env=dev"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"express": "^4.17.1",
|
|
@@ -41,20 +41,21 @@ function ServerConfig(binh, Binh) {
|
|
|
41
41
|
return new ConfigLoader(config);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
Binh.config = function(module) {
|
|
44
|
+
Binh.config = function(module, doneCallback) {
|
|
45
45
|
if (module instanceof Function) {
|
|
46
46
|
loadConfigs = module;
|
|
47
|
-
loadConfigs(configloader);
|
|
48
47
|
}
|
|
49
48
|
else if (typeof module === 'string') {
|
|
50
49
|
loadConfigs = binh(module);
|
|
51
|
-
loadConfigs(configloader);
|
|
52
50
|
}
|
|
53
51
|
else {
|
|
54
52
|
loadConfigs = defaultConfigLoader;
|
|
55
|
-
loadConfigs(configloader);
|
|
56
53
|
}
|
|
57
54
|
|
|
55
|
+
loadConfigs(configloader);
|
|
56
|
+
|
|
57
|
+
if (doneCallback instanceof Function) configloader.done(doneCallback);
|
|
58
|
+
|
|
58
59
|
groupLoadConfigs.push(loadConfigs);
|
|
59
60
|
|
|
60
61
|
return Binh;
|
package/src/server.js
CHANGED
|
@@ -40,7 +40,7 @@ function Server(options) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
server.listen(PORT, function() {
|
|
43
|
-
console.log(`[
|
|
43
|
+
console.log(`[BINHEND][SERVER] Server is listening on http://localhost:${PORT}/`);
|
|
44
44
|
|
|
45
45
|
if (options.callback instanceof Function) {
|
|
46
46
|
options.callback(server, options.configs);
|
package/bin/frontend.js
DELETED
|
File without changes
|