@lmjs/cli 1.0.42 → 1.0.44

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 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
- let res = await axios({
69
- method: _body['method'].toString().toLowerCase(),
70
- url: fcs.validURL(_body['path']) ? _body['path'] : (config.apis[_body['api'] ?? 0].baseURL + _body['path']),
71
- data: __data ?? {},
72
- headers: _body['headers'] ?? config.apis[_body['api'] ?? 0].headers
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": res.headers,
76
- "data": res.data
77
- } : res.data;
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
- global.axios = axios;
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
- console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
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
  });
@@ -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
- axios.get(BEA_Libs.BEAJS, {})
15
+ fcs.API.get(BEA_Libs.BEAJS, {})
17
16
  .then((beajs) => {
18
- axios.get(BEA_Libs.BEACSS, {})
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 axios = require("axios").default;
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
- axios
104
+ API
104
105
  .get(BEA_Libs.BEAJS, {})
105
106
  .then((beajs) => {
106
- axios.get(BEA_Libs.BEACSS, {}).then((beacss) => {
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);
@@ -363,6 +364,22 @@ function validURL(string) {
363
364
 
364
365
  exports.validURL = validURL;
365
366
 
367
+
368
+ let getPairs = (obj, keys = []) =>
369
+ Object.entries(obj).reduce((pairs, [key, value]) => {
370
+ if (typeof value === 'object')
371
+ pairs.push(...getPairs(value, [...keys, key]));
372
+ else
373
+ pairs.push([[...keys, key], value]);
374
+ return pairs;
375
+ }, []);
376
+
377
+ function pairIt(obj) {
378
+ return getPairs(obj).map(([[key0, ...keysRest], value]) =>
379
+ `${key0}${keysRest.map(a => `[${a}]`).join('')}=${value}`)
380
+ .join('&');
381
+ }
382
+
366
383
  var API = {
367
384
  get: async function (u, d, h, a) {
368
385
  return await this.req(u, d, h, "GET", a);
@@ -379,16 +396,26 @@ var API = {
379
396
  patch: async function (u, d, h, a) {
380
397
  return await this.req(u, d, h, "PATCH", a);
381
398
  },
382
- req: async function (u, d, h, m, a) {
383
- let res = await axios({
399
+ req: async function (u, d, h, m, a, f) {
400
+
401
+ var urled = validURL(u) ? u : config.apis[a ?? 0].baseURL + u;
402
+ if (m.toString().toLowerCase() == 'get') {
403
+ if (urled.indexOf('?') > -1) urled = urled + "&" + pairIt(d ?? {});
404
+ else urled = urled + "?" + pairIt(d ?? {});
405
+ }
406
+ let resa = await fetch(urled, {
384
407
  method: m.toString().toLowerCase(),
385
- url: validURL(u) ? u : config.apis[a ?? 0].baseURL + u,
386
- data: d ?? {},
408
+ body: m.toString().toLowerCase() == 'get' ? null : JSON.stringify(d ?? {}),
387
409
  headers: h ?? config.apis[a ?? 0].headers,
388
- maxContentLength: 100000000,
389
- maxBodyLength: 1000000000,
390
410
  });
391
- return res.data;
411
+
412
+ if (f) return resa;
413
+ let res = await resa.text();
414
+ try {
415
+ return JSON.parse(res);
416
+ } catch (e) {
417
+ return res;
418
+ }
392
419
  },
393
420
  };
394
421
  exports.API = API;
@@ -455,6 +482,8 @@ function processCommands(cmd) {
455
482
  } else if (command == "build") {
456
483
  let cmds = process.argv;
457
484
  _bp(cmds);
485
+ } else if (command == "-v" || command == "-version") {
486
+ console.log("LumenJS version " + require('../package.json').version);
458
487
  } else {
459
488
  console.log("LumenJS CLI's command not found!");
460
489
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmjs/cli",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
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.6"
38
+ "@lmjs/core": "^1.0.7"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=12.0.0"