biz-a-cli 2.0.1 → 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
@@ -10,6 +10,7 @@ const { option, number } = require("yargs");
10
10
  const options = yargs
11
11
  .option("s", {alias:"server", describe:"Server URL", type:"string", demandOption:true})
12
12
  .option("i", {alias:"dbindex", describe:"database index", type:number, demandOption:true})
13
+ .option("d", {alias:"dir", describe:"Directory", type:"string", demandOption:false})
13
14
  .argv;
14
15
 
15
16
  const sendFile = async (filename, data)=>{
@@ -43,9 +44,16 @@ const readTemplateFile= async (filename)=>{
43
44
  const ext = filename.split('.');
44
45
 
45
46
  if (ext[ext.length-1] == 'js'){
46
- const vmResult = vm.runInThisContext(data);
47
- const result = JSON.stringify(vmResult(), replacer);
48
-
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
+
49
57
  //console.log(result);
50
58
  return Buffer.from(result).toString('hex');
51
59
  //console.log(result);
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.1",
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
  }