biz-a-cli 1.0.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.
Files changed (2) hide show
  1. package/bin/index.js +90 -0
  2. package/package.json +18 -0
package/bin/index.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ const yargs = require("yargs");
4
+ const axios = require("axios");
5
+ const fs = require("fs").promises;
6
+
7
+ const vm= require("vm");
8
+ const { option, number } = require("yargs");
9
+
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
+ .option("s", {alias:"server", describe:"Server URL", type:"string", demandOption:true})
15
+ .option("i", {alias:"dbindex", describe:"database index", type:number, demandOption:true})
16
+ .argv;
17
+
18
+ const sendFile = async (filename, data)=>{
19
+ const url = `http://${options.server}:212/fina/rest/TOrmMethod/%22setTemplate%22`
20
+
21
+ const param = {_parameters: [options.dbindex, filename, data]};
22
+ //console.log(`url:${url}`);
23
+ //console.log(param);
24
+ return await axios.post(url, param);
25
+ }
26
+
27
+ function getParam(funcName){
28
+ var params = funcName.split('(');
29
+ return params[1].split(')')[0].split(',');
30
+ }
31
+
32
+ function replacer(key,value){
33
+ if (typeof value == 'function'){
34
+ let arr = value.toString().replace(/(\r\n|\n|\r)/gm,"°").split("°");
35
+ if (arr.length < 3) throw 'Function must be minimal 3 lines';
36
+ return [
37
+ 'window.Function',
38
+ getParam( arr[0] ),
39
+ arr.slice( 1, arr.length-1 )
40
+ ];
41
+ } else {
42
+ return value;
43
+ }
44
+ }
45
+
46
+ const readTemplateFile= async (filename)=>{
47
+ const data = await fs.readFile(filename);
48
+ const ext = filename.split('.');
49
+
50
+ if (ext[ext.length-1] == 'js'){
51
+ const vmResult = vm.runInThisContext(data);
52
+ const result = JSON.stringify(vmResult(), replacer);
53
+
54
+ //console.log(result);
55
+ return Buffer.from(result).toString('hex');
56
+ //console.log(result);
57
+
58
+ } else {
59
+ return Buffer.from(data).toString('hex');
60
+ //return JSON.stringify(JSON.parse(data));
61
+ }
62
+ }
63
+
64
+ const loopFiles = async (dir) =>{
65
+ try{
66
+ const files = await fs.readdir(dir);
67
+ for (const file of files){
68
+ //const p = path.join(dir, file);
69
+ const stat = await fs.stat(file);
70
+
71
+ if (stat.isFile()) {
72
+
73
+ const data = await readTemplateFile(file);
74
+
75
+
76
+ //console.log(data.toString('hex'));
77
+ const res = await sendFile(file, data.toString('hex'));
78
+ if (res.data.success){
79
+ console.log(`file: ${file} uploaded`);
80
+ } else {
81
+ console.error(res.data.error);
82
+ }
83
+ }
84
+ }
85
+ } catch (e){
86
+ console.error(e.response && e.response.data ? e.response.data: e);
87
+ }
88
+ }
89
+
90
+ loopFiles('./');
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "biz-a-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "bin/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "Imamatek",
10
+ "license": "ISC",
11
+ "bin": {
12
+ "uploadbiza": "./bin/index.js"
13
+ },
14
+ "dependencies": {
15
+ "axios": "^0.27.2",
16
+ "yargs": "^17.4.1"
17
+ }
18
+ }