@lmjs/cli 1.0.0 → 1.0.2
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/README.md +26 -9
- package/index.js +147 -80
- package/lib/app.js +236 -92
- package/lib/files/project/config.json +68 -49
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# LumenJS Reactive JavaScript Framework
|
|
2
4
|
|
|
3
5
|
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.
|
|
@@ -13,7 +15,7 @@ LumenJS comes along with MobiusCSS library which is a utility-first CSS framewor
|
|
|
13
15
|
## Installation
|
|
14
16
|
Using npm:
|
|
15
17
|
```
|
|
16
|
-
npm install -g @
|
|
18
|
+
npm install -g @lmjs/cli
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
|
|
@@ -21,55 +23,70 @@ npm install -g @lumen.js/cli
|
|
|
21
23
|
## USAGE
|
|
22
24
|
Create A New Project
|
|
23
25
|
```
|
|
24
|
-
|
|
26
|
+
lm create My Project Name
|
|
25
27
|
```
|
|
28
|
+
You can use lu, lm, or lumen as a command.
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
Run The Project
|
|
30
33
|
```
|
|
31
|
-
|
|
34
|
+
lm serve
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
Create A View
|
|
37
40
|
```
|
|
38
|
-
|
|
41
|
+
lm create -v myview
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
|
|
42
45
|
|
|
43
46
|
Create A Sub View
|
|
44
47
|
```
|
|
45
|
-
|
|
48
|
+
lm create -s mysubview
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
|
|
50
53
|
Create A Component Template
|
|
51
54
|
```
|
|
52
|
-
|
|
55
|
+
lm create -c mycomponent
|
|
53
56
|
```
|
|
54
57
|
|
|
55
58
|
|
|
56
59
|
|
|
57
60
|
Purge Offline Cache Files (For Offline Usage)
|
|
58
61
|
```
|
|
59
|
-
|
|
62
|
+
lm purge
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
|
|
63
66
|
|
|
64
67
|
Build A Dist For Production Version + NodeJs Server
|
|
65
68
|
```
|
|
66
|
-
|
|
69
|
+
lm build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Build A Dist For Production Version + NodeJs Server & Deploy It Directly
|
|
75
|
+
```
|
|
76
|
+
lm build --deploy
|
|
67
77
|
```
|
|
68
78
|
|
|
69
79
|
|
|
70
80
|
|
|
71
81
|
Build A Dist For Production Version without NodeJs Server
|
|
72
82
|
```
|
|
73
|
-
|
|
83
|
+
lm build --serverless
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
Build A Dist For Production Version without NodeJs Server & Deploy It Directly
|
|
89
|
+
```
|
|
90
|
+
lm build --serverless --deploy
|
|
74
91
|
```
|
|
75
92
|
|
package/index.js
CHANGED
|
@@ -2,6 +2,9 @@ const nodemon = require('nodemon');
|
|
|
2
2
|
const axios = require('axios').default;
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require("fs");
|
|
5
|
+
const FtpDeploy = require("ftp-deploy");
|
|
6
|
+
const ftpDeploy = new FtpDeploy();
|
|
7
|
+
|
|
5
8
|
// const { exec } = require("child_process");
|
|
6
9
|
const fcs = require("./lib/fcs.js");
|
|
7
10
|
var UglifyJS = require('uglify-js');
|
|
@@ -56,112 +59,176 @@ function processCommands(cmd) {
|
|
|
56
59
|
var API = fcs.API;
|
|
57
60
|
|
|
58
61
|
async function buildProject(cmds) {
|
|
59
|
-
var projectPath = `${process.cwd()}`;
|
|
60
|
-
var dest = projectPath + path.sep + 'dist';
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
import('ora').then(async ({ default: ora, oraPromise: oraPromise }) => {
|
|
64
|
+
const spinner = ora({
|
|
65
|
+
text: 'Started Building Project For Production..',
|
|
66
|
+
color: 'green'
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
spinner.succeed('Started Building Project For Production').start('Gathering Required Resources..');
|
|
70
|
+
|
|
71
|
+
var projectPath = `${process.cwd()}`;
|
|
72
|
+
var dest = projectPath + path.sep + 'dist';
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
let _views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
75
|
+
let _comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
76
|
+
var config = fcs.getConfig();
|
|
67
77
|
|
|
78
|
+
var indexCode = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "index.html", "utf8");
|
|
68
79
|
|
|
69
80
|
|
|
70
|
-
var beaCSSCode = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "css" + path.sep + "bea.css", "utf8");
|
|
71
|
-
var beaCode2 = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "index.js", "utf8");
|
|
72
81
|
|
|
73
|
-
|
|
82
|
+
var beaCSSCode = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "css" + path.sep + "bea.css", "utf8");
|
|
83
|
+
var beaCode2 = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "index.js", "utf8");
|
|
84
|
+
|
|
85
|
+
var kkk = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "js" + path.sep + "bea.js", "utf8");
|
|
86
|
+
spinner.succeed("Gathering Required Resources");
|
|
74
87
|
var beaCode = "";
|
|
88
|
+
if (cmds.indexOf('--serverless') >= 0) {
|
|
89
|
+
spinner.start('Getting Token From Server..');
|
|
75
90
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
let r = await API.post("/beajs", {
|
|
92
|
+
"data": JSON.stringify(config.apis)
|
|
93
|
+
});
|
|
79
94
|
|
|
80
|
-
|
|
95
|
+
let token_ = r.token;
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
if (token_ == "") {
|
|
98
|
+
spinner.fail("Error getting a unique token for your project!");
|
|
99
|
+
spinner.fail("Build Failed! Try again later.");
|
|
100
|
+
return;
|
|
101
|
+
} else {
|
|
102
|
+
// make the build happen :)
|
|
103
|
+
}
|
|
84
104
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//
|
|
105
|
+
beaCode += `
|
|
106
|
+
var _beaTn = "` + token_ + `";
|
|
107
|
+
`;
|
|
108
|
+
// let kkk = await axios.get(BEA_Libs.BEAJS + "/prod");
|
|
109
|
+
// beaCode += kkk.data;
|
|
89
110
|
}
|
|
111
|
+
beaCode += kkk;
|
|
112
|
+
spinner.start('Packing & Cleaning...');
|
|
90
113
|
|
|
91
114
|
beaCode += `
|
|
92
|
-
let _beaTn = "` + token_ + `";
|
|
93
|
-
`;
|
|
94
|
-
let kkk = await axios.get(BEA_Libs.BEAJS + "/prod");
|
|
95
|
-
beaCode += kkk.data;
|
|
96
|
-
} else {
|
|
97
|
-
var beaCode = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "js" + path.sep + "bea.js", "utf8");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
beaCode += `
|
|
101
115
|
var _vcData = {
|
|
102
116
|
"views": `+ JSON.stringify(_views) + `,
|
|
103
117
|
"comps": `+ JSON.stringify(_comps) + `
|
|
104
118
|
};
|
|
105
119
|
`;
|
|
106
|
-
|
|
120
|
+
beaCode += `
|
|
107
121
|
` + beaCode2 + `
|
|
108
122
|
`;
|
|
109
|
-
|
|
123
|
+
var js2 = `
|
|
110
124
|
exports.config = `+ JSON.stringify(config) + `;
|
|
111
125
|
`;
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
fcs.rd(dest);
|
|
128
|
-
|
|
129
|
-
let buildPath = `build`;
|
|
130
|
-
if (cmds.indexOf('--no-server') >= 0) {
|
|
131
|
-
|
|
132
|
-
buildPath = `build_serverless`;
|
|
133
|
-
|
|
134
|
-
fcs.copyDir(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath, dest);
|
|
135
|
-
fcs.copyDir(projectPath + path.sep + "src", dest, "_beajsBuild");
|
|
136
|
-
fcs.cd(dest + path.sep + "js");
|
|
137
|
-
fcs.cd(dest + path.sep + "css");
|
|
138
|
-
fcs.cd(dest + path.sep + "images");
|
|
127
|
+
let zode = UglifyJS.minify(beaCode, {
|
|
128
|
+
mangle: {
|
|
129
|
+
reserved: ['_vcdata','_ws']
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
let zode2 = UglifyJS.minify(js2, {
|
|
133
|
+
mangle: {
|
|
134
|
+
reserved: ['_vcdata','_ws']
|
|
135
|
+
},
|
|
136
|
+
output: {
|
|
137
|
+
beautify: true
|
|
138
|
+
}
|
|
139
|
+
});
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
fcs.rd(dest);
|
|
142
|
+
|
|
143
|
+
spinner.succeed("Packing & Cleaning").start('Writing Files...');
|
|
144
|
+
let buildPath = `build`;
|
|
145
|
+
if (cmds.indexOf('--serverless') >= 0) {
|
|
146
|
+
|
|
147
|
+
buildPath = `build_serverless`;
|
|
148
|
+
|
|
149
|
+
fcs.copyDir(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath, dest);
|
|
150
|
+
fcs.copyDir(projectPath + path.sep + "src", dest, "_beajsBuild");
|
|
151
|
+
fcs.cd(dest + path.sep + "js");
|
|
152
|
+
fcs.cd(dest + path.sep + "css");
|
|
153
|
+
fcs.cd(dest + path.sep + "images");
|
|
154
|
+
|
|
155
|
+
// fcs.copyDir(projectPath + path.sep + `src` + path.sep + `css`, dest + path.sep + "css");
|
|
156
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "js", dest + path.sep + "js", "_beajsBuild");
|
|
157
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "css", dest + path.sep + "css", "_beajsBuild");
|
|
158
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "images", dest + path.sep + "images", "_beajsBuild");
|
|
159
|
+
|
|
160
|
+
fs.writeFileSync(dest + path.sep + "js" + path.sep + "bea.js", String(zode.code));
|
|
161
|
+
fs.writeFileSync(dest + path.sep + "css" + path.sep + "bea.css", String(beaCSSCode));
|
|
162
|
+
fs.writeFileSync(dest + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join(""));
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
if (cmds.indexOf('--deploy') >= 0) {
|
|
166
|
+
spinner.succeed('Writing Files').start('Uploading To Server..');
|
|
167
|
+
const _config = {
|
|
168
|
+
user: config.ftp.username,
|
|
169
|
+
// Password optional, prompted if none given
|
|
170
|
+
password: config.ftp.password,
|
|
171
|
+
host: config.ftp.host,
|
|
172
|
+
port: config.ftp.port,
|
|
173
|
+
localRoot: dest,
|
|
174
|
+
remoteRoot: config.ftp.remotePath,
|
|
175
|
+
include: ["*", "**/*", ".*"], // this would upload everything except dot files
|
|
176
|
+
// include: ["*.js", "dist/*", ".*"],
|
|
177
|
+
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
|
|
178
|
+
exclude: config.ftp.ignore,
|
|
179
|
+
// delete ALL existing files at destination before uploading, if true
|
|
180
|
+
deleteRemote: false,
|
|
181
|
+
// Passive mode is forced (EPSV command is not sent)
|
|
182
|
+
forcePasv: true,
|
|
183
|
+
// use sftp or ftp
|
|
184
|
+
sftp: false,
|
|
185
|
+
};
|
|
186
|
+
// console.log(_config);
|
|
187
|
+
|
|
188
|
+
ftpDeploy.deploy(_config, function (err, res) {
|
|
189
|
+
if (err) {
|
|
190
|
+
console.log(err);
|
|
191
|
+
} else {
|
|
192
|
+
spinner.succeed("Finished Uploading To Server");
|
|
193
|
+
spinner.succeed("Done");
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
ftpDeploy.on("uploading", function (data) {
|
|
197
|
+
spinner.start(((data.transferredFileCount) * 100 / data.totalFilesCount) + '% ' + 'Uploading ' + data.filename + ' ');
|
|
198
|
+
});
|
|
199
|
+
// ftpDeploy.on("uploaded", function (data) {
|
|
200
|
+
// console.log(data); // same data as uploading event
|
|
201
|
+
// });
|
|
202
|
+
// ftpDeploy.on("log", function (data) {
|
|
203
|
+
// console.log(data); // same data as uploading event
|
|
204
|
+
// });
|
|
205
|
+
// ftpDeploy.on("upload-error", function (data) {
|
|
206
|
+
// console.log(data.err); // data will also include filename, relativePath, and other goodies
|
|
207
|
+
// });
|
|
208
|
+
|
|
209
|
+
} else
|
|
210
|
+
spinner.succeed('Writing Files').succeed("Done");
|
|
211
|
+
} else {
|
|
212
|
+
fcs.copyDir(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath, dest);
|
|
213
|
+
fcs.copyDir(projectPath + path.sep + "src", dest + path.sep + "src", "_beajsBuild");
|
|
214
|
+
fcs.cd(dest + path.sep + "src" + path.sep + "js");
|
|
215
|
+
fcs.cd(dest + path.sep + "src" + path.sep + "css");
|
|
216
|
+
fcs.cd(dest + path.sep + "src" + path.sep + "images");
|
|
217
|
+
|
|
218
|
+
// fcs.copyDir(projectPath + path.sep + `src` + path.sep + `css`, dest + path.sep + "src" + path.sep + "css");
|
|
219
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "js", dest + path.sep + "src" + path.sep + "js", "_beajsBuild");
|
|
220
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "css", dest + path.sep + "src" + path.sep + "css", "_beajsBuild");
|
|
221
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "images", dest + path.sep + "src" + path.sep + "images", "_beajsBuild");
|
|
222
|
+
|
|
223
|
+
fs.writeFileSync(dest + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(zode.code));
|
|
224
|
+
fs.writeFileSync(dest + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beaCSSCode));
|
|
225
|
+
fs.writeFileSync(dest + path.sep + "src" + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join(""));
|
|
226
|
+
fs.writeFileSync(dest + path.sep + "config.js", String(zode2.code));
|
|
227
|
+
|
|
228
|
+
spinner.succeed('Writing Files').succeed("Done");
|
|
229
|
+
}
|
|
144
230
|
|
|
145
|
-
|
|
146
|
-
fs.writeFileSync(dest + path.sep + "css" + path.sep + "bea.css", String(beaCSSCode));
|
|
147
|
-
fs.writeFileSync(dest + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join(""));
|
|
148
|
-
} else {
|
|
149
|
-
fcs.copyDir(`${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + buildPath, dest);
|
|
150
|
-
fcs.copyDir(projectPath + path.sep + "src", dest + path.sep + "src", "_beajsBuild");
|
|
151
|
-
fcs.cd(dest + path.sep + "src" + path.sep + "js");
|
|
152
|
-
fcs.cd(dest + path.sep + "src" + path.sep + "css");
|
|
153
|
-
fcs.cd(dest + path.sep + "src" + path.sep + "images");
|
|
154
|
-
|
|
155
|
-
// fcs.copyDir(projectPath + path.sep + `src` + path.sep + `css`, dest + path.sep + "src" + path.sep + "css");
|
|
156
|
-
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "js", dest + path.sep + "src" + path.sep + "js", "_beajsBuild");
|
|
157
|
-
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "css", dest + path.sep + "src" + path.sep + "css", "_beajsBuild");
|
|
158
|
-
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "images", dest + path.sep + "src" + path.sep + "images", "_beajsBuild");
|
|
159
|
-
|
|
160
|
-
fs.writeFileSync(dest + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(zode.code));
|
|
161
|
-
fs.writeFileSync(dest + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beaCSSCode));
|
|
162
|
-
fs.writeFileSync(dest + path.sep + "src" + path.sep + "index.html", String(indexCode).split('<script src="/index.js" type="text/javascript"></script>').join(""));
|
|
163
|
-
fs.writeFileSync(dest + path.sep + "config.js", String(zode2.code));
|
|
164
|
-
}
|
|
231
|
+
});
|
|
165
232
|
|
|
166
233
|
}
|
|
167
234
|
|
package/lib/app.js
CHANGED
|
@@ -1,116 +1,260 @@
|
|
|
1
1
|
var fs = require('fs');
|
|
2
2
|
const axios = require('axios').default;
|
|
3
3
|
const path = require("path");
|
|
4
|
-
|
|
5
|
-
var compression = require('compression');
|
|
6
|
-
const app = express();
|
|
7
|
-
const server = require('http').createServer(app);
|
|
8
|
-
const io = require('socket.io')(server, {
|
|
9
|
-
// wsEngine: require("eiows").Server,
|
|
10
|
-
// perMessageDeflate: {
|
|
11
|
-
// threshold: 32768
|
|
12
|
-
// },
|
|
13
|
-
maxHttpBufferSize: 400e6
|
|
14
|
-
});
|
|
15
|
-
var cookieParser = require('cookie-parser');
|
|
16
|
-
var expressSession = require('express-session');
|
|
17
|
-
const bodyParser = require('body-parser');
|
|
18
|
-
var multer = require('multer');
|
|
19
|
-
var upload = multer();
|
|
4
|
+
var uws = require('uWebSockets.js');
|
|
20
5
|
const fcs = require("./fcs.js");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resave: true,
|
|
25
|
-
saveUninitialized: true,
|
|
26
|
-
cookie: { maxAge: 9999000 }
|
|
27
|
-
});
|
|
28
|
-
|
|
6
|
+
const mime = require('mime-types');
|
|
7
|
+
var cl = console.log;
|
|
8
|
+
var zlib = require('zlib');
|
|
29
9
|
var config = fcs.getConfig();
|
|
30
10
|
var _views = {};
|
|
31
11
|
var _comps = {};
|
|
12
|
+
function toArrayBuffer(buffer) {
|
|
13
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
14
|
+
}
|
|
15
|
+
uws.App().ws('/*', {
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
app.use(bodyParser.urlencoded({ extended: true }));
|
|
39
|
-
app.use(bodyParser.json());
|
|
40
|
-
app.use(bodyParser.raw());
|
|
41
|
-
app.use(upload.array());
|
|
42
|
-
|
|
43
|
-
io.use(function (socket, next) {
|
|
44
|
-
session(socket.request, socket.request.res, next);
|
|
45
|
-
});
|
|
17
|
+
/* There are many common helper features */
|
|
18
|
+
idleTimeout: 8,
|
|
19
|
+
maxBackpressure: 1024 * 1024,
|
|
20
|
+
maxPayloadLength: 16 * 1024 * 1024,
|
|
21
|
+
compression: uws.SHARED_COMPRESSOR,
|
|
46
22
|
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
/* Handlers */
|
|
24
|
+
open: (ws) => {
|
|
25
|
+
// console.log('A WebSocket connected!');
|
|
26
|
+
ws.subscribe('/home/rat');
|
|
27
|
+
},
|
|
28
|
+
message: async (ws, message, isBinary) => {
|
|
29
|
+
/* Ok is false if backpressure was built up, wait for drain */
|
|
49
30
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
31
|
+
const buffer = Buffer.from(message);
|
|
32
|
+
const data = JSON.parse(buffer.toString());
|
|
33
|
+
|
|
34
|
+
if (data.hasOwnProperty('e')) {
|
|
35
|
+
var _data = {
|
|
36
|
+
"e": data.e,
|
|
37
|
+
"_iter": data._iter,
|
|
38
|
+
"payload": {}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (data.e == "getfiles") {
|
|
42
|
+
_data['payload'] = {
|
|
43
|
+
"views": _views,
|
|
44
|
+
"comps": _comps
|
|
45
|
+
};
|
|
46
|
+
} else if (data.e == "getcomp") {
|
|
47
|
+
_data.payload = _comps[data.payload];
|
|
48
|
+
} else if (data.e == "getview") {
|
|
49
|
+
_data.payload = _views[data.payload];
|
|
50
|
+
} else if (data.e == "request") {
|
|
51
|
+
try {
|
|
52
|
+
let pata = data.payload;
|
|
53
|
+
let __data = pata['data'];
|
|
54
|
+
let _body = pata['body'];
|
|
55
|
+
let res = await axios({
|
|
56
|
+
method: _body['method'].toString().toLowerCase(),
|
|
57
|
+
url: fcs.validURL(_body['path']) ? _body['path'] : (config.apis[_body['api'] ?? 0].baseURL + _body['path']),
|
|
58
|
+
data: __data ?? {},
|
|
59
|
+
headers: _body['headers'] ?? config.apis[_body['api'] ?? 0].headers
|
|
60
|
+
});
|
|
61
|
+
_data.payload = res.data;
|
|
62
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
63
|
+
|
|
64
|
+
} catch (e) {
|
|
65
|
+
_data.payload = { "code": 108, "error": e.message, "type": "RequestError" };
|
|
66
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
67
|
+
// ws.publish('/home/rat', JSON.stringify(_data));
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ws.publish('/home/rat', JSON.stringify(_data));
|
|
73
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
74
|
+
|
|
75
|
+
}
|
|
64
76
|
} catch (e) {
|
|
77
|
+
|
|
65
78
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
},
|
|
80
|
+
drain: (ws) => {
|
|
81
|
+
// console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
|
|
82
|
+
},
|
|
83
|
+
close: (ws, code, message) => {
|
|
84
|
+
// console.log('WebSocket closed');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}).get('/*', async (res, req) => {
|
|
88
|
+
let nodes = req.getUrl().split("/");
|
|
89
|
+
while (nodes[0] == "") nodes.shift();
|
|
90
|
+
let _nodes = JSON.parse(JSON.stringify(nodes));
|
|
91
|
+
let pubDir = `${process.cwd()}` + path.sep + `src`;
|
|
92
|
+
let filePath = "";
|
|
93
|
+
let errorPath = path.sep + '404.html';
|
|
94
|
+
if (nodes[0]) {
|
|
95
|
+
let last = nodes[nodes.length - 1];
|
|
96
|
+
while (_nodes.length) filePath += path.sep + _nodes.shift();
|
|
97
|
+
if (last.indexOf('.') > -1) {
|
|
98
|
+
filePath = fs.existsSync(pubDir + path.sep + filePath) ? filePath : errorPath;
|
|
99
|
+
} else {
|
|
100
|
+
if (!fs.existsSync(pubDir + path.sep + `views` + path.sep + nodes[0] + '.view')) {
|
|
101
|
+
filePath = errorPath;
|
|
102
|
+
} else {
|
|
103
|
+
filePath = path.sep + 'index.html';
|
|
104
|
+
}
|
|
71
105
|
}
|
|
106
|
+
} else filePath = path.sep + 'index.html';
|
|
107
|
+
|
|
108
|
+
// const mime = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
109
|
+
// // res.writeHeader('Content-Type', mime);
|
|
110
|
+
// const stream = fs.createReadStream(pubDir + filePath, { encoding: 'utf8' });
|
|
111
|
+
// stream.on('data', function (chunk) {
|
|
112
|
+
// console.log(chunk);
|
|
113
|
+
// });
|
|
114
|
+
// stream.on("error", () => {
|
|
115
|
+
// // error : file does not exist, etc.
|
|
116
|
+
// res.writeHeader("content-type", "text/plain");
|
|
117
|
+
// // res.statusCode = 404;
|
|
118
|
+
// res.end("ouuups, problem :/");
|
|
119
|
+
// });
|
|
120
|
+
|
|
121
|
+
// // res.writeHeader("content-type", mime);
|
|
122
|
+
// stream.on("open", () => {
|
|
123
|
+
// // good
|
|
124
|
+
// // mime is your font / file mime-type
|
|
125
|
+
// // res.statusCode = 200;
|
|
126
|
+
// stream.pipe(res);
|
|
127
|
+
// });
|
|
128
|
+
// res.end();
|
|
129
|
+
// return;
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
let readStream;
|
|
135
|
+
let paths = req.getUrl();
|
|
136
|
+
const acceptEncoding = req.getHeader('accept-encoding');
|
|
137
|
+
|
|
138
|
+
// at this point you need a way to get the requested file and catch errors if the file does not exist:
|
|
139
|
+
const fileName = pubDir + filePath; // i have some DANGEROUS_PATH_PATTERN test on the path var you must make sure it's safe
|
|
140
|
+
try {
|
|
141
|
+
readStream = toArrayBuffer(fs.readFileSync(fileName)); // toArrayBuffer is a function i got from examples
|
|
142
|
+
} catch (err) {
|
|
143
|
+
readStream = 'Error reading file.. or something';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
readStream = toArrayBuffer(fs.readFileSync(fileName));
|
|
147
|
+
// setting headers and responding: res.aborted must be present
|
|
148
|
+
res.onAborted(() => {
|
|
149
|
+
res.aborted = true;
|
|
72
150
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
151
|
+
// write the headers and respond
|
|
152
|
+
// write the headers and respond
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
res.cork(() => {
|
|
156
|
+
const mimeT = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
157
|
+
res.writeHeader('Content-Type', mimeT);
|
|
158
|
+
// for (let i = 0; i < securityHeaders.length; i++) res.writeHeader(securityHeaders[i].name, securityHeaders[i].value);
|
|
159
|
+
if (!acceptEncoding) acceptEncoding = '';
|
|
160
|
+
if (/\bgzip\b/.test(acceptEncoding)) {
|
|
161
|
+
res.writeHeader('Content-Encoding', 'gzip');
|
|
162
|
+
readStream = zlib.gzipSync(readStream);
|
|
163
|
+
} else if (/\bdeflate\b/.test(acceptEncoding)) {
|
|
164
|
+
res.writeHeader('Content-Encoding', 'deflate');
|
|
165
|
+
readStream = zlib.deflateSync(readStream);
|
|
80
166
|
}
|
|
167
|
+
if (!res.aborted) res.end(readStream);
|
|
81
168
|
});
|
|
169
|
+
|
|
170
|
+
// const mimeType = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
171
|
+
|
|
172
|
+
// if (!res.aborted) {
|
|
173
|
+
// res.writeHeader('Content-Type', mimeType);
|
|
174
|
+
// res.end(fs.readFileSync(pubDir + filePath, "utf8"));
|
|
175
|
+
// }
|
|
176
|
+
return;
|
|
177
|
+
}).any('/*', (res, req) => {
|
|
178
|
+
res.end('Nothing to see here!');
|
|
179
|
+
}).listen(config.server.port * 1, (listenSocket) => {
|
|
180
|
+
if (listenSocket) {
|
|
181
|
+
// for automatic port selection use 0 as port above and we'll get one below this line.
|
|
182
|
+
// port = uws.us_socket_local_port(listenSocket);
|
|
183
|
+
// console.log('Listening to port ' + port);
|
|
184
|
+
console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
|
|
185
|
+
_views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
186
|
+
_comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
187
|
+
} else {
|
|
188
|
+
console.log('Failed to run LumenJS server');
|
|
189
|
+
}
|
|
190
|
+
|
|
82
191
|
});
|
|
192
|
+
// app.use('/', express.static(`${process.cwd()}` + path.sep + `src`));
|
|
83
193
|
|
|
194
|
+
// io.on('connection', function (socket) {
|
|
195
|
+
// socket.on("request", async function (_data, _body, cb) {
|
|
196
|
+
// try {
|
|
197
|
+
// let res = await axios({
|
|
198
|
+
// method: _data['method'].toString().toLowerCase(),
|
|
199
|
+
// url: fcs.validURL(_data['path']) ? _data['path'] : (config.apis[_data['api'] ?? 0].baseURL + _data['path']),
|
|
200
|
+
// data: _body ?? {},
|
|
201
|
+
// headers: _data['headers'] ?? config.apis[_data['api'] ?? 0].headers
|
|
202
|
+
// });
|
|
203
|
+
// cb(res.data);
|
|
204
|
+
// } catch (e) {
|
|
205
|
+
// cb({ "code": 108, "error": e.message, "type": "RequestError" });
|
|
206
|
+
// }
|
|
207
|
+
// });
|
|
208
|
+
// socket.on("getview", function (msg, cb) {
|
|
209
|
+
// try {
|
|
210
|
+
// cb(_views[msg]);
|
|
211
|
+
// } catch (e) {
|
|
212
|
+
// }
|
|
213
|
+
// });
|
|
214
|
+
// socket.on("getcomp", function (msg, cb) {
|
|
215
|
+
// try {
|
|
216
|
+
// cb(_comps[msg]);
|
|
217
|
+
// } catch (e) {
|
|
218
|
+
// }
|
|
219
|
+
// });
|
|
220
|
+
// socket.on("getfiles", function (cb) {
|
|
221
|
+
// try {
|
|
222
|
+
// cb({
|
|
223
|
+
// "views": _views,
|
|
224
|
+
// "comps": _comps
|
|
225
|
+
// });
|
|
226
|
+
// } catch (e) {
|
|
227
|
+
// }
|
|
228
|
+
// });
|
|
229
|
+
// });
|
|
84
230
|
|
|
85
|
-
global.
|
|
86
|
-
global.
|
|
87
|
-
global.
|
|
88
|
-
global.fs = fs;
|
|
89
|
-
global.path = path;
|
|
231
|
+
// global.axios = axios;
|
|
232
|
+
// global.fs = fs;
|
|
233
|
+
// global.path = path;
|
|
90
234
|
|
|
91
|
-
var API = fcs.API;
|
|
92
|
-
global.API = API;
|
|
235
|
+
// var API = fcs.API;
|
|
236
|
+
// global.API = API;
|
|
93
237
|
|
|
94
|
-
if(fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`)){
|
|
95
|
-
|
|
96
|
-
}
|
|
238
|
+
// if(fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`)){
|
|
239
|
+
// require(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`);
|
|
240
|
+
// }
|
|
97
241
|
|
|
98
|
-
app.get('*', function (req, res) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
242
|
+
// app.get('*', function (req, res) {
|
|
243
|
+
// let nodes = req.params[0].split("/");
|
|
244
|
+
// if (nodes.length) nodes.shift();
|
|
245
|
+
// res.sendFile(`${process.cwd()}` + path.sep + `src` + path.sep + ((fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep + nodes[0] + `.view`)) ? 'index' : '404') + `.html`);
|
|
246
|
+
// return;
|
|
247
|
+
// });
|
|
104
248
|
|
|
105
|
-
app.post('*', function (req, res) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
249
|
+
// app.post('*', function (req, res) {
|
|
250
|
+
// let nodes = req.params[0].split("/");
|
|
251
|
+
// if (nodes.length) nodes.shift();
|
|
252
|
+
// res.sendFile(`${process.cwd()}` + path.sep + `src` + path.sep + ((fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep + nodes[0] + `.view`)) ? 'index' : '404') + `.html`);
|
|
253
|
+
// return;
|
|
254
|
+
// });
|
|
111
255
|
|
|
112
|
-
server.listen(config.server.port, function () {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
256
|
+
// server.listen(config.server.port, function () {
|
|
257
|
+
// console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
|
|
258
|
+
// _views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
259
|
+
// _comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
260
|
+
// });
|
|
@@ -1,51 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
2
|
+
"version": "1.0.0.1",
|
|
3
|
+
"server": {
|
|
4
|
+
"host": "127.0.0.1",
|
|
5
|
+
"port": "3000",
|
|
6
|
+
"ssl": {
|
|
7
|
+
"enabled": false,
|
|
8
|
+
"key": "/key.pem",
|
|
9
|
+
"cert": "/certificate.cer"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"project_info": {
|
|
13
|
+
"Title": "PROJECT_TITLE",
|
|
14
|
+
"Description": "PROJECT_DESCRIPTION",
|
|
15
|
+
"Keywords": "website,search,tags,goes,here",
|
|
16
|
+
"WebsiteURL": "https://www.example.com/",
|
|
17
|
+
"Favicon": "/images/favicon.ico",
|
|
18
|
+
"SocialMedia": {
|
|
19
|
+
"LI": "https://www.linkedin.com/",
|
|
20
|
+
"IG": "https://www.instagram.com/",
|
|
21
|
+
"FB": "https://www.facebook.com/"
|
|
22
|
+
},
|
|
23
|
+
"MetaTags": {
|
|
24
|
+
"og:url": "https://www.example.com/",
|
|
25
|
+
"og:title": "PROJECT_TITLE",
|
|
26
|
+
"og:type": "business.business",
|
|
27
|
+
"og:site_name": "PROJECT_TITLE",
|
|
28
|
+
"fb:admins": "592515154",
|
|
29
|
+
"fb:app_id": "138025696270006",
|
|
30
|
+
"og:description": "PROJECT_TITLE",
|
|
31
|
+
"og:image": "/images/example.png",
|
|
32
|
+
"business:contact_data:street_address": "Street Address.",
|
|
33
|
+
"business:contact_data:locality": "Tripoli",
|
|
34
|
+
"business:contact_data:postal_code": "1300",
|
|
35
|
+
"business:contact_data:country_name": "Lebanon",
|
|
36
|
+
"business:contact_data:email": "info@example.com",
|
|
37
|
+
"business:contact_data:phone_number": "+96171299411",
|
|
38
|
+
"business:contact_data:fax_number": "+96171299411",
|
|
39
|
+
"business:contact_data:website": "https://www.example.com/"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"apis": [
|
|
43
|
+
{
|
|
44
|
+
"baseURL": "https://api.backendadmin.com/1",
|
|
45
|
+
"headers": {
|
|
46
|
+
"X-BEA-Application-ID": "YOUR_APPLICATION_ID",
|
|
47
|
+
"X-BEA-Authorization": "YOUR_REST_API_KEY"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"ftp": {
|
|
52
|
+
"host": "ftp_host",
|
|
53
|
+
"username": "ftp_username",
|
|
54
|
+
"password": "ftp_password",
|
|
55
|
+
"remotePath": "/",
|
|
56
|
+
"concurrency": 4,
|
|
57
|
+
"protocol": "ftp",
|
|
58
|
+
"port": 21,
|
|
59
|
+
"ignore": [
|
|
60
|
+
"index.html"
|
|
61
|
+
],
|
|
62
|
+
"syncOption": {
|
|
63
|
+
"delete": false,
|
|
64
|
+
"ignoreExisting": false,
|
|
65
|
+
"skipCreate": false,
|
|
66
|
+
"update": true
|
|
67
|
+
},
|
|
68
|
+
"connectTimeout": 30000
|
|
69
|
+
}
|
|
51
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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": {
|
|
@@ -37,16 +37,14 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"axios": "^0.27.2",
|
|
40
|
-
"cookie-parser": "^1.4.6",
|
|
41
40
|
"cssnano": "^5.1.11",
|
|
42
|
-
"
|
|
43
|
-
"express-session": "^1.17.3",
|
|
44
|
-
"compression": "^1.7.4",
|
|
41
|
+
"ftp-deploy": "^2.4.3",
|
|
45
42
|
"multer": "^1.4.5-lts.1",
|
|
46
43
|
"nodemon": "^2.0.16",
|
|
44
|
+
"ora": "^6.1.2",
|
|
47
45
|
"semver": "^7.3.7",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
46
|
+
"uglify-js": "^3.16.0",
|
|
47
|
+
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.4.0"
|
|
50
48
|
},
|
|
51
49
|
"engines": {
|
|
52
50
|
"node": ">=12.0.0"
|
|
@@ -60,5 +58,9 @@
|
|
|
60
58
|
"name": "BEA Technology Company",
|
|
61
59
|
"email": "info@bea.com.lb"
|
|
62
60
|
},
|
|
63
|
-
"license": "MIT"
|
|
64
|
-
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/bea-company/lmjs-cli.git"
|
|
65
|
+
}
|
|
66
|
+
}
|