@lmjs/cli 1.0.42 → 1.0.43
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/lib/app.js +20 -16
- package/lib/check-version.js +2 -3
- package/lib/fcs.js +21 -10
- package/package.json +2 -2
package/lib/app.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
var fs = require('fs');
|
|
2
|
-
const axios = require('axios').default;
|
|
3
2
|
const path = require("path");
|
|
4
|
-
|
|
5
3
|
const express = require('express');
|
|
6
4
|
var compression = require('compression');
|
|
7
5
|
const app = express();
|
|
@@ -65,18 +63,17 @@ wss.on('connection', (ws) => {
|
|
|
65
63
|
let pata = data.payload;
|
|
66
64
|
let __data = pata['data'];
|
|
67
65
|
let _body = pata['body'];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
66
|
+
var resa = await API.req(_body['path'], __data, _body['headers'], _body['method'], _body['api'], true);
|
|
67
|
+
let res = await resa.text();
|
|
68
|
+
try {
|
|
69
|
+
res = JSON.parse(res);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
}
|
|
74
72
|
_data.payload = (_body['full']) ? {
|
|
75
|
-
"headers":
|
|
76
|
-
"data": res
|
|
77
|
-
} : res
|
|
73
|
+
"headers": resa.headers,
|
|
74
|
+
"data": res
|
|
75
|
+
} : res;
|
|
78
76
|
ws.send(JSON.stringify(_data));
|
|
79
|
-
|
|
80
77
|
} catch (e) {
|
|
81
78
|
_data.payload = { "code": 108, "error": e.message, "type": "RequestError" };
|
|
82
79
|
ws.send(JSON.stringify(_data));
|
|
@@ -91,10 +88,11 @@ wss.on('connection', (ws) => {
|
|
|
91
88
|
|
|
92
89
|
}
|
|
93
90
|
});
|
|
94
|
-
});
|
|
91
|
+
}).on('error', (e) => { });
|
|
95
92
|
|
|
96
93
|
global.app = app;
|
|
97
|
-
|
|
94
|
+
var fetch = fcs.fetch;
|
|
95
|
+
global.fetch = fetch;
|
|
98
96
|
global.wss = wss;
|
|
99
97
|
global.fs = fs;
|
|
100
98
|
global.path = path;
|
|
@@ -120,8 +118,14 @@ app.post('*', function (req, res) {
|
|
|
120
118
|
return;
|
|
121
119
|
});
|
|
122
120
|
|
|
123
|
-
server.listen(config.server.port, function () {
|
|
124
|
-
|
|
121
|
+
server.listen(config.server.port > 0 ? config.server.port : 0, function (err) {
|
|
122
|
+
cl(`LumenJS server running at http://${config.server.host}:${config.server.port > 0 && server.address().port == config.server.port ? config.server.port : server.address().port}/`);
|
|
125
123
|
_views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
126
124
|
_tpls = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `tpls` + path.sep);
|
|
125
|
+
}).on('error', (e) => {
|
|
126
|
+
if (e.code === 'EADDRINUSE') {
|
|
127
|
+
cl('Port ' + config.server.port + ' is already in use..');
|
|
128
|
+
server.close();
|
|
129
|
+
server.listen(0);
|
|
130
|
+
}
|
|
127
131
|
});
|
package/lib/check-version.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const semver = require('semver');
|
|
3
|
-
const axios = require('axios').default;
|
|
4
3
|
const path = require('path');
|
|
5
4
|
const fs = require("fs");
|
|
6
5
|
const fcs = require("./fcs.js");
|
|
@@ -13,9 +12,9 @@ if (!semver.satisfies(m[0].toString(), '>=12')) {
|
|
|
13
12
|
console.log("Node version should be minimum 12.0.0");
|
|
14
13
|
process.exit(1);
|
|
15
14
|
} else {
|
|
16
|
-
|
|
15
|
+
fcs.API.get(BEA_Libs.BEAJS, {})
|
|
17
16
|
.then((beajs) => {
|
|
18
|
-
|
|
17
|
+
fcs.API.get(BEA_Libs.BEACSS, {})
|
|
19
18
|
.then((beacss) => {
|
|
20
19
|
var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
|
|
21
20
|
fcs.cd(libsPath);
|
package/lib/fcs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const nodemon = require("nodemon");
|
|
@@ -16,6 +16,7 @@ const BEA_Libs = {
|
|
|
16
16
|
exports.getAllFiles = getAllFiles;
|
|
17
17
|
exports.ucwords = ucwords;
|
|
18
18
|
|
|
19
|
+
exports.fetch = fetch;
|
|
19
20
|
exports.getConfig = getConfig;
|
|
20
21
|
function getConfig() {
|
|
21
22
|
config = {
|
|
@@ -100,10 +101,10 @@ function create(conf) {
|
|
|
100
101
|
if (!fs.existsSync(libsPath + path.sep + "bea.js")) getLibs = true;
|
|
101
102
|
}
|
|
102
103
|
if (getLibs) {
|
|
103
|
-
|
|
104
|
+
API
|
|
104
105
|
.get(BEA_Libs.BEAJS, {})
|
|
105
106
|
.then((beajs) => {
|
|
106
|
-
|
|
107
|
+
API.get(BEA_Libs.BEACSS, {}).then((beacss) => {
|
|
107
108
|
var libsPath =
|
|
108
109
|
`${__dirname}` + path.sep + `files` + path.sep + `libs`;
|
|
109
110
|
cd(libsPath);
|
|
@@ -379,16 +380,24 @@ var API = {
|
|
|
379
380
|
patch: async function (u, d, h, a) {
|
|
380
381
|
return await this.req(u, d, h, "PATCH", a);
|
|
381
382
|
},
|
|
382
|
-
req: async function (u, d, h, m, a) {
|
|
383
|
-
|
|
383
|
+
req: async function (u, d, h, m, a, f) {
|
|
384
|
+
var urled = validURL(u) ? u : config.apis[a ?? 0].baseURL + u;
|
|
385
|
+
if (m.toString().toLowerCase() == 'get') {
|
|
386
|
+
if (urled.indexOf('?') > -1) urled = urled + "&" + new URLSearchParams(d ?? {});
|
|
387
|
+
else urled = urled + "?" + new URLSearchParams(d ?? {});
|
|
388
|
+
}
|
|
389
|
+
let resa = await fetch(urled, {
|
|
384
390
|
method: m.toString().toLowerCase(),
|
|
385
|
-
|
|
386
|
-
data: d ?? {},
|
|
391
|
+
body: m.toString().toLowerCase() == 'get' ? null : JSON.stringify(d ?? {}),
|
|
387
392
|
headers: h ?? config.apis[a ?? 0].headers,
|
|
388
|
-
maxContentLength: 100000000,
|
|
389
|
-
maxBodyLength: 1000000000,
|
|
390
393
|
});
|
|
391
|
-
return
|
|
394
|
+
if (f) return resa;
|
|
395
|
+
let res = await resa.text();
|
|
396
|
+
try {
|
|
397
|
+
return JSON.parse(res);
|
|
398
|
+
} catch (e) {
|
|
399
|
+
return res;
|
|
400
|
+
}
|
|
392
401
|
},
|
|
393
402
|
};
|
|
394
403
|
exports.API = API;
|
|
@@ -455,6 +464,8 @@ function processCommands(cmd) {
|
|
|
455
464
|
} else if (command == "build") {
|
|
456
465
|
let cmds = process.argv;
|
|
457
466
|
_bp(cmds);
|
|
467
|
+
} else if (command == "-v" || command == "-version") {
|
|
468
|
+
console.log("LumenJS version " + require('../package.json').version);
|
|
458
469
|
} else {
|
|
459
470
|
console.log("LumenJS CLI's command not found!");
|
|
460
471
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"description": "Command line interface for super fast LumenJS development. LumenJS is a tiny robust reactive javascript framework for building scalable and high-performant web applications and web user interfaces, be it simple or complex, with standard HTML, CSS and JavaScript",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lm": "./bin/commands.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"lumen bea"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@lmjs/core": "^1.0.
|
|
38
|
+
"@lmjs/core": "^1.0.7"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=12.0.0"
|