@lmjs/cli 1.0.21 → 1.0.22
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/index.js +55 -49
- package/lib/files/build/func.js +85 -49
- package/lib/files/build/package.json +1 -1
- package/lib/files/build/server.js +32 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -155,54 +155,6 @@ async function buildProject(cmds) {
|
|
|
155
155
|
fs.writeFileSync(dest + path.sep + "js" + path.sep + "bea.js", String(zode.code));
|
|
156
156
|
fs.writeFileSync(dest + path.sep + "css" + path.sep + "bea.css", String(beaCSSCode));
|
|
157
157
|
fs.writeFileSync(dest + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join("").split('/js/bea.js').join("/js/bea.js?v" + new Date().getTime()).split('/css/styles.css').join("/css/styles.css?v" + new Date().getTime()).split('/css/bea.css').join("/css/bea.css?v" + new Date().getTime()));
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (cmds.indexOf('--deploy') >= 0) {
|
|
161
|
-
spinner.succeed('Writing Files').start('Uploading To Server..');
|
|
162
|
-
const _config = {
|
|
163
|
-
user: config.ftp.username,
|
|
164
|
-
// Password optional, prompted if none given
|
|
165
|
-
password: config.ftp.password,
|
|
166
|
-
host: config.ftp.host,
|
|
167
|
-
port: config.ftp.port,
|
|
168
|
-
localRoot: dest,
|
|
169
|
-
remoteRoot: config.ftp.remotePath,
|
|
170
|
-
include: ["*", "**/*", ".*"], // this would upload everything except dot files
|
|
171
|
-
// include: ["*.js", "dist/*", ".*"],
|
|
172
|
-
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
|
|
173
|
-
exclude: config.ftp.ignore,
|
|
174
|
-
// delete ALL existing files at destination before uploading, if true
|
|
175
|
-
deleteRemote: false,
|
|
176
|
-
// Passive mode is forced (EPSV command is not sent)
|
|
177
|
-
forcePasv: true,
|
|
178
|
-
// use sftp or ftp
|
|
179
|
-
sftp: false,
|
|
180
|
-
};
|
|
181
|
-
// console.log(_config);
|
|
182
|
-
|
|
183
|
-
ftpDeploy.deploy(_config, function (err, res) {
|
|
184
|
-
if (err) {
|
|
185
|
-
console.log(err);
|
|
186
|
-
} else {
|
|
187
|
-
spinner.succeed("Finished Uploading To Server");
|
|
188
|
-
spinner.succeed("Done");
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
ftpDeploy.on("uploading", function (data) {
|
|
192
|
-
spinner.start(parseFloat(((data.transferredFileCount) * 100 / data.totalFilesCount).toFixed(2)) + '% ' + 'Uploading ' + data.filename + ' ');
|
|
193
|
-
});
|
|
194
|
-
// ftpDeploy.on("uploaded", function (data) {
|
|
195
|
-
// console.log(data); // same data as uploading event
|
|
196
|
-
// });
|
|
197
|
-
// ftpDeploy.on("log", function (data) {
|
|
198
|
-
// console.log(data); // same data as uploading event
|
|
199
|
-
// });
|
|
200
|
-
// ftpDeploy.on("upload-error", function (data) {
|
|
201
|
-
// console.log(data.err); // data will also include filename, relativePath, and other goodies
|
|
202
|
-
// });
|
|
203
|
-
|
|
204
|
-
} else
|
|
205
|
-
spinner.succeed('Writing Files').succeed("Done");
|
|
206
158
|
} else {
|
|
207
159
|
fcs.copyDir(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath, dest);
|
|
208
160
|
fcs.copyDir(projectPath + path.sep + "src", dest + path.sep + "src", "_beajsBuild");
|
|
@@ -210,6 +162,14 @@ async function buildProject(cmds) {
|
|
|
210
162
|
fcs.cd(dest + path.sep + "src" + path.sep + "css");
|
|
211
163
|
fcs.cd(dest + path.sep + "src" + path.sep + "images");
|
|
212
164
|
|
|
165
|
+
let appFile = projectPath + path.sep + `src` + path.sep + "app.js";
|
|
166
|
+
if (fs.existsSync(appFile)) {
|
|
167
|
+
var appCode = fs.readFileSync(appFile, "utf8");
|
|
168
|
+
var serverJsCode = fs.readFileSync(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath + path.sep + "server.js", "utf8");
|
|
169
|
+
fs.writeFileSync(dest + path.sep + "server.js", String(serverJsCode).split('//APP_HOLDER').join(appCode));
|
|
170
|
+
fs.unlinkSync(dest + path.sep + "src" + path.sep + "app.js");
|
|
171
|
+
}
|
|
172
|
+
|
|
213
173
|
// fcs.copyDir(projectPath + path.sep + `src` + path.sep + `css`, dest + path.sep + "src" + path.sep + "css");
|
|
214
174
|
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "js", dest + path.sep + "src" + path.sep + "js", "_beajsBuild");
|
|
215
175
|
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "css", dest + path.sep + "src" + path.sep + "css", "_beajsBuild");
|
|
@@ -220,9 +180,55 @@ async function buildProject(cmds) {
|
|
|
220
180
|
fs.writeFileSync(dest + path.sep + "src" + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join(""));
|
|
221
181
|
fs.writeFileSync(dest + path.sep + "config.js", String(zode2.code));
|
|
222
182
|
|
|
223
|
-
spinner.succeed('Writing Files').succeed("Done");
|
|
224
183
|
}
|
|
225
184
|
|
|
185
|
+
if (cmds.indexOf('--deploy') >= 0) {
|
|
186
|
+
spinner.succeed('Writing Files').start('Uploading To Server..');
|
|
187
|
+
const _config = {
|
|
188
|
+
user: config.ftp.username,
|
|
189
|
+
// Password optional, prompted if none given
|
|
190
|
+
password: config.ftp.password,
|
|
191
|
+
host: config.ftp.host,
|
|
192
|
+
port: config.ftp.port,
|
|
193
|
+
localRoot: dest,
|
|
194
|
+
remoteRoot: config.ftp.remotePath,
|
|
195
|
+
include: ["*", "**/*", ".*"], // this would upload everything except dot files
|
|
196
|
+
// include: ["*.js", "dist/*", ".*"],
|
|
197
|
+
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
|
|
198
|
+
exclude: config.ftp.ignore,
|
|
199
|
+
// delete ALL existing files at destination before uploading, if true
|
|
200
|
+
deleteRemote: false,
|
|
201
|
+
// Passive mode is forced (EPSV command is not sent)
|
|
202
|
+
forcePasv: true,
|
|
203
|
+
// use sftp or ftp
|
|
204
|
+
sftp: false,
|
|
205
|
+
};
|
|
206
|
+
// console.log(_config);
|
|
207
|
+
|
|
208
|
+
ftpDeploy.deploy(_config, function (err, res) {
|
|
209
|
+
if (err) {
|
|
210
|
+
console.log(err);
|
|
211
|
+
} else {
|
|
212
|
+
spinner.succeed("Finished Uploading To Server");
|
|
213
|
+
spinner.succeed("Done");
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
ftpDeploy.on("uploading", function (data) {
|
|
217
|
+
spinner.start(parseFloat(((data.transferredFileCount) * 100 / data.totalFilesCount).toFixed(2)) + '% ' + 'Uploading ' + data.filename + ' ');
|
|
218
|
+
});
|
|
219
|
+
// ftpDeploy.on("uploaded", function (data) {
|
|
220
|
+
// console.log(data); // same data as uploading event
|
|
221
|
+
// });
|
|
222
|
+
// ftpDeploy.on("log", function (data) {
|
|
223
|
+
// console.log(data); // same data as uploading event
|
|
224
|
+
// });
|
|
225
|
+
// ftpDeploy.on("upload-error", function (data) {
|
|
226
|
+
// console.log(data.err); // data will also include filename, relativePath, and other goodies
|
|
227
|
+
// });
|
|
228
|
+
|
|
229
|
+
} else
|
|
230
|
+
spinner.succeed('Writing Files').succeed("Done");
|
|
231
|
+
|
|
226
232
|
});
|
|
227
233
|
|
|
228
234
|
}
|
package/lib/files/build/func.js
CHANGED
|
@@ -1,66 +1,102 @@
|
|
|
1
|
-
const axios = require(
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const express = require(
|
|
4
|
-
var compression = require(
|
|
1
|
+
const axios = require("axios").default;
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const express = require("express");
|
|
4
|
+
var compression = require("compression");
|
|
5
5
|
const app = express();
|
|
6
|
-
const server = require(
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
6
|
+
const server = require("http").createServer(app);
|
|
7
|
+
|
|
8
|
+
var WebSocketServer = require("ws").Server;
|
|
9
|
+
var wss = new WebSocketServer({ server: server, path: "/" });
|
|
10
|
+
|
|
11
|
+
var cookieParser = require("cookie-parser");
|
|
12
|
+
var expressSession = require("express-session");
|
|
13
|
+
const bodyParser = require("body-parser");
|
|
14
|
+
var multer = require("multer");
|
|
15
|
+
const config = require("./config").config;
|
|
13
16
|
var upload = multer();
|
|
14
17
|
let session = expressSession({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
secret: "lumenjs",
|
|
19
|
+
resave: true,
|
|
20
|
+
saveUninitialized: true,
|
|
21
|
+
cookie: { maxAge: 9999000 },
|
|
19
22
|
});
|
|
20
23
|
|
|
21
|
-
function validURL(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'(\\#[-a-z\\d_]*)?$', 'i');
|
|
28
|
-
return !!pattern.test(str);
|
|
24
|
+
function validURL(string) {
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(string);
|
|
28
|
+
} catch (_) {
|
|
29
|
+
return false;
|
|
29
30
|
}
|
|
31
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.validURL = validURL;
|
|
30
35
|
|
|
31
36
|
exports.config = config;
|
|
32
37
|
exports.server = function () {
|
|
33
|
-
|
|
38
|
+
return server;
|
|
34
39
|
};
|
|
35
40
|
exports.app = function () {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
app.use(cookieParser());
|
|
42
|
+
app.use(session);
|
|
43
|
+
app.use(compression());
|
|
44
|
+
app.use(express.static(path.join(__dirname, "./src")));
|
|
45
|
+
app.set("etag", false);
|
|
46
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
|
47
|
+
app.use(bodyParser.json());
|
|
48
|
+
app.use(bodyParser.raw());
|
|
49
|
+
app.use(upload.array());
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
wss.on("connection", (ws) => {
|
|
52
|
+
ws.on("message", async (message) => {
|
|
53
|
+
try {
|
|
54
|
+
const buffer = Buffer.from(message);
|
|
55
|
+
const data = JSON.parse(buffer.toString());
|
|
56
|
+
|
|
57
|
+
if (data.hasOwnProperty("e")) {
|
|
58
|
+
var _data = {
|
|
59
|
+
e: data.e,
|
|
60
|
+
_iter: data._iter,
|
|
61
|
+
payload: {},
|
|
62
|
+
};
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
socket.on("request", async function (_data, _body, cb) {
|
|
64
|
+
if (data.e == "request") {
|
|
52
65
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
let pata = data.payload;
|
|
67
|
+
let __data = pata["data"];
|
|
68
|
+
let _body = pata["body"];
|
|
69
|
+
let res = await axios({
|
|
70
|
+
method: _body["method"].toString().toLowerCase(),
|
|
71
|
+
url: fcs.validURL(_body["path"])
|
|
72
|
+
? _body["path"]
|
|
73
|
+
: config.apis[_body["api"] ?? 0].baseURL + _body["path"],
|
|
74
|
+
data: __data ?? {},
|
|
75
|
+
headers:
|
|
76
|
+
_body["headers"] ?? config.apis[_body["api"] ?? 0].headers,
|
|
77
|
+
});
|
|
78
|
+
_data.payload = _body["full"]
|
|
79
|
+
? {
|
|
80
|
+
headers: res.headers,
|
|
81
|
+
data: res.data,
|
|
82
|
+
}
|
|
83
|
+
: res.data;
|
|
84
|
+
ws.send(JSON.stringify(_data));
|
|
60
85
|
} catch (e) {
|
|
61
|
-
|
|
86
|
+
_data.payload = {
|
|
87
|
+
code: 108,
|
|
88
|
+
error: e.message,
|
|
89
|
+
type: "RequestError",
|
|
90
|
+
};
|
|
91
|
+
ws.send(JSON.stringify(_data));
|
|
62
92
|
}
|
|
63
|
-
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
ws.send(JSON.stringify(_data));
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {}
|
|
64
99
|
});
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
});
|
|
101
|
+
return app;
|
|
102
|
+
};
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const axios = require("axios").default;
|
|
2
3
|
const func = require('./func');
|
|
3
4
|
const app = func.app();
|
|
4
5
|
const server = func.server();
|
|
5
6
|
var config = func.config;
|
|
6
7
|
|
|
8
|
+
var API =
|
|
9
|
+
{
|
|
10
|
+
get: async function (u, d, h, a) {
|
|
11
|
+
return await this.req(u, d, h, "GET", a);
|
|
12
|
+
},
|
|
13
|
+
put: async function (u, d, h, a) {
|
|
14
|
+
return await this.req(u, d, h, "PUT", a);
|
|
15
|
+
},
|
|
16
|
+
post: async function (u, d, h, a) {
|
|
17
|
+
return await this.req(u, d, h, "POST", a);
|
|
18
|
+
},
|
|
19
|
+
delete: async function (u, d, h, a) {
|
|
20
|
+
return await this.req(u, d, h, "DELETE", a);
|
|
21
|
+
},
|
|
22
|
+
patch: async function (u, d, h, a) {
|
|
23
|
+
return await this.req(u, d, h, "PATCH", a);
|
|
24
|
+
},
|
|
25
|
+
req: async function (u, d, h, m, a) {
|
|
26
|
+
let res = await axios({
|
|
27
|
+
method: m.toString().toLowerCase(),
|
|
28
|
+
url: func.validURL(u) ? u : (config.apis[a ?? 0].baseURL + u),
|
|
29
|
+
data: d ?? {},
|
|
30
|
+
headers: h ?? config.apis[a ?? 0].headers
|
|
31
|
+
});
|
|
32
|
+
return res.data;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//APP_HOLDER
|
|
37
|
+
|
|
7
38
|
app.get('/', (req, res) => {
|
|
8
39
|
res.sendFile(path.join(__dirname, './src/index.html'));
|
|
9
40
|
});
|
|
@@ -23,5 +54,5 @@ app.post('*', function (req, res) {
|
|
|
23
54
|
});
|
|
24
55
|
|
|
25
56
|
server.listen(config.server.port, function () {
|
|
26
|
-
console.log(`
|
|
57
|
+
console.log(`LumenJS client server running at http://${config.server.host}:${config.server.port}/`);
|
|
27
58
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "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
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|