biz-a-cli 2.0.0 → 2.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/bin/index.js CHANGED
@@ -8,19 +8,15 @@ const vm= require("vm");
8
8
  const { option, number } = require("yargs");
9
9
 
10
10
  const options = yargs
11
- //.usage("Usage: -c <company name> -p <password> -s <server url>")
12
- //.option("c", {alias:"name", describe: "Company Name", type:"string", demandOption:true})
13
- //.option("p", {alias:"password", describe:"Password", type: "string", demandOption: true})
14
11
  .option("s", {alias:"server", describe:"Server URL", type:"string", demandOption:true})
15
12
  .option("i", {alias:"dbindex", describe:"database index", type:number, demandOption:true})
13
+ .option("d", {alias:"dir", describe:"Directory", type:"string", demandOption:false})
16
14
  .argv;
17
15
 
18
16
  const sendFile = async (filename, data)=>{
19
17
  const url = `http://${options.server}:212/fina/rest/TOrmMethod/%22setTemplate%22`
20
18
 
21
19
  const param = {_parameters: [options.dbindex, filename, data]};
22
- //console.log(`url:${url}`);
23
- //console.log(param);
24
20
  return await axios.post(url, param);
25
21
  }
26
22
 
@@ -48,9 +44,16 @@ const readTemplateFile= async (filename)=>{
48
44
  const ext = filename.split('.');
49
45
 
50
46
  if (ext[ext.length-1] == 'js'){
51
- const vmResult = vm.runInThisContext(data);
52
- const result = JSON.stringify(vmResult(), replacer);
53
-
47
+ let result;
48
+ try{
49
+ const vmResult = vm.runInThisContext(data);
50
+ result = JSON.stringify(vmResult(), replacer);
51
+ } catch(ReferenceError) {
52
+ const fn = `file://${process.cwd()}\\${filename}`;
53
+ const lib = await import(fn);
54
+ result = JSON.stringify(lib.default(), replacer);
55
+ }
56
+
54
57
  //console.log(result);
55
58
  return Buffer.from(result).toString('hex');
56
59
  //console.log(result);
@@ -66,6 +69,8 @@ const loopFiles = async (dir) =>{
66
69
  const files = await fs.readdir(dir);
67
70
  for (const file of files){
68
71
  //const p = path.join(dir, file);
72
+ if (file == 'package.json' || file == 'package-lock.json') continue;
73
+
69
74
  const stat = await fs.stat(file);
70
75
 
71
76
  if (stat.isFile()) {
package/bin/proxy.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ const express = require('express');
4
+ const cors = require('cors');
5
+ const app = express();
6
+ const proxyCtl = require('../../biz-a/proxyController');
7
+ const { option, number } = require("yargs");
8
+ const yargs = require('yargs');
9
+
10
+
11
+ const options = yargs
12
+ .option('p', {alias:'port', describe:'Port to use', type:'string', demandOption:false})
13
+ .argv;
14
+
15
+ app.use(cors());
16
+
17
+ app.use('/proxy', proxyCtl.proxy);
18
+
19
+ const port = 3000;
20
+
21
+ app.listen((options.port || port), () => {
22
+ console.log(`Biz-A is listening at ${process.env.HOST || 'http://localhost'}:${options.port || port} `);
23
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz-a-cli",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {
@@ -9,10 +9,13 @@
9
9
  "author": "Imamatek",
10
10
  "license": "ISC",
11
11
  "bin": {
12
- "uploadbiza": "./bin/index.js"
12
+ "uploadbiza": "./bin/index.js",
13
+ "proxy": "./bin/proxy.js"
13
14
  },
14
15
  "dependencies": {
15
16
  "axios": "^0.27.2",
17
+ "cors": "^2.8.5",
18
+ "express": "^4.18.2",
16
19
  "yargs": "^17.4.1"
17
20
  }
18
21
  }