binhend 1.5.7 → 1.5.9

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.
@@ -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
- // console.log('Welcome to the binh!');
3
- // console.log('process.argv', process.argv);
4
-
5
- const argves = process.argv;
6
- const command = argves[2];
7
-
8
- // switch (command) {
9
- // case 'backend':
10
- // console.log('Generate back-end structure...');
11
- // break;
12
-
13
- // case 'frontend':
14
- // console.log('Generate front-end structure...');
15
- // break;
16
-
17
- // default:
18
- // console.log('Unknown command...');
19
- // break;
20
- // }
21
-
22
- const map = {
23
- backend: require('./backend'),
24
- frontend: require('./frontend'),
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,6 @@
1
+ const path = require('path');
2
+
3
+ module.exports = function(loader) {
4
+ loader.file(path.join(__dirname, '.env'));
5
+ loader.cli();
6
+ };
@@ -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,6 @@
1
+
2
+ tag('h1');
3
+
4
+ function ui() {
5
+ return h1('Hello World');
6
+ }
@@ -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,4 @@
1
+
2
+ Binh({
3
+ '': '/App.js'
4
+ });
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
7
7
  "license": "UNLICENSED",
8
8
  "bin": {
9
- "binh": "./bin/index.js"
9
+ "binhend": "./bin/index.js"
10
10
  },
11
11
  "scripts": {
12
12
  "test": "echo \"Error: no test specified\" && exit 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;
@@ -9,8 +9,8 @@ const BeautifyJS = require('js-beautify/js');
9
9
  function processEachFile({ source: sourceRootPath, web: outputRootPath, module: stageRootPath, external: externalPath }, buildCodeMethod, callbackDone) {
10
10
  if (sourceRootPath == undefined || outputRootPath == undefined) return;
11
11
  stageRootPath = stageRootPath || outputRootPath;
12
- console.info('[BINHEND][COMPONENT] Build web components from:', stageRootPath);
13
- console.info('[BINHEND][COMPONENT] to:', outputRootPath);
12
+ console.info('[BINHEND][WEB-BUILD] Build web components from:', stageRootPath);
13
+ console.info('[BINHEND][WEB-BUILD] to:', outputRootPath);
14
14
 
15
15
  var ref = {};
16
16
  externalPath = typeof externalPath === 'string' ? `/${externalPath}/` : null;
@@ -81,9 +81,9 @@ function onComplete(done, callback) {
81
81
  function cloneFile(filepath, outpath) {
82
82
  copyFile(filepath, outpath, function(error) {
83
83
  if (error) {
84
- console.error(`[BINHEND][COMPONENT] Failed copying file from:`, filepath);
85
- console.error(`[BINHEND][COMPONENT] to:`, outpath);
86
- console.error('[BINHEND][COMPONENT] Error details:', error);
84
+ console.error(`[BINHEND][WEB-BUILD] Failed copying file from:`, filepath);
85
+ console.error(`[BINHEND][WEB-BUILD] to:`, outpath);
86
+ console.error('[BINHEND][WEB-BUILD] Error details:', error);
87
87
  }
88
88
  });
89
89
  }
@@ -144,8 +144,8 @@ function isSameContent(filePath, content) {
144
144
  }
145
145
 
146
146
  function printError(message, id, error) {
147
- console.error(`[BINHEND][COMPONENT] ${message}:`, id);
148
- console.error('[BINHEND][COMPONENT] Error details:', error);
147
+ console.error(`[BINHEND][WEB-BUILD] ${message}:`, id);
148
+ console.error('[BINHEND][WEB-BUILD] Error details:', error);
149
149
  }
150
150
 
151
151
  module.exports = {
@@ -10,8 +10,8 @@ var ui = null, service = null, style = null;\r\n\r\n`;
10
10
 
11
11
  function generate(sourceRootPath, outputRootPath, callbackDone) {
12
12
  if (sourceRootPath == undefined || outputRootPath == undefined) return;
13
- console.info('[BINHEND][COMPONENT] Format files from:', sourceRootPath);
14
- console.info('[BINHEND][COMPONENT] to:', outputRootPath);
13
+ console.info('[BINHEND][WEB-BUILD] Format files from:', sourceRootPath);
14
+ console.info('[BINHEND][WEB-BUILD] to:', outputRootPath);
15
15
 
16
16
  scanNestedFiles(sourceRootPath, (file, done) => {
17
17
  if (done) return callbackDone instanceof Function ? callbackDone() : null;
package/src/component.js CHANGED
@@ -9,8 +9,8 @@ const CodeFormat = require('./code');
9
9
 
10
10
  function generate(source, destination) {
11
11
  if (source == undefined) return;
12
- console.log('[BINHEND][COMPONENT] Start building components from:', source);
13
- console.log('[BINHEND][COMPONENT] to:', destination);
12
+ console.log('[BINHEND][WEB-BUILD] Start building components from:', source);
13
+ console.log('[BINHEND][WEB-BUILD] to:', destination);
14
14
  processDirectory(source, source, destination);
15
15
  }
16
16
 
@@ -97,8 +97,8 @@ function cloneFile(filepath, outpath) {
97
97
  }
98
98
 
99
99
  function showError(message, id, error) {
100
- console.log(`[BINHEND][COMPONENT] ${message}:`, id);
101
- console.log('[BINHEND][COMPONENT] Error details:', error);
100
+ console.log(`[BINHEND][WEB-BUILD] ${message}:`, id);
101
+ console.log('[BINHEND][WEB-BUILD] Error details:', error);
102
102
  }
103
103
 
104
104
  var Component = {
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(`[NODE] Server is listening on http://localhost:${PORT}/`);
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
@@ -1,3 +0,0 @@
1
- module.exports = () => {
2
- console.log('Generate front-end structure...');
3
- };
File without changes