@lmjs/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.
- package/README.md +75 -0
- package/bin/commands.js +2 -0
- package/index.js +178 -0
- package/lib/app.js +116 -0
- package/lib/check-version.js +29 -0
- package/lib/fcs.js +254 -0
- package/lib/files/build/func.js +66 -0
- package/lib/files/build/package.json +31 -0
- package/lib/files/build/server.js +27 -0
- package/lib/files/build/src/favicon.ico +0 -0
- package/lib/files/build/src/robots.txt +4 -0
- package/lib/files/build/src/sitemap.xml +9 -0
- package/lib/files/build_serverless/.htaccess +15 -0
- package/lib/files/build_serverless/favicon.ico +0 -0
- package/lib/files/build_serverless/robots.txt +4 -0
- package/lib/files/build_serverless/sitemap.xml +9 -0
- package/lib/files/comp.tpl +1 -0
- package/lib/files/project/config.json +51 -0
- package/lib/files/project/src/404.html +250 -0
- package/lib/files/project/src/comps/comp1.tpl +1 -0
- package/lib/files/project/src/index.html +48 -0
- package/lib/files/project/src/index.js +15 -0
- package/lib/files/project/src/views/about.view +14 -0
- package/lib/files/project/src/views/contact.view +14 -0
- package/lib/files/project/src/views/home.view +13 -0
- package/lib/files/project/src/views/widgets/footer.view +0 -0
- package/lib/files/project/src/views/widgets/header.view +13 -0
- package/lib/files/project/src/views/widgets/nav.view +0 -0
- package/lib/files/sub_view.view +8 -0
- package/lib/files/view.view +14 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# LumenJS Reactive JavaScript Framework
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
<a href="https://lumen.bea.com.lb/" target="_blank">LumenJS Documentation</a>
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
LumenJS comes along with MobiusCSS library which is a utility-first CSS framework packed with grid and table sectioning systems and classes like g, mt20, pv100, c and sq that can be composed to build any design, directly in your markup.
|
|
9
|
+
<a href="https://mobius.bea.com.lb/" target="_blank">MobiusCSS Documentation</a>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
Using npm:
|
|
15
|
+
```
|
|
16
|
+
npm install -g @lumen.js/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## USAGE
|
|
22
|
+
Create A New Project
|
|
23
|
+
```
|
|
24
|
+
lu create My Project Name
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Run The Project
|
|
30
|
+
```
|
|
31
|
+
lu serve
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Create A View
|
|
37
|
+
```
|
|
38
|
+
lu create -v myview
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Create A Sub View
|
|
44
|
+
```
|
|
45
|
+
lu create -s mysubview
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Create A Component Template
|
|
51
|
+
```
|
|
52
|
+
lu create -c mycomponent
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
Purge Offline Cache Files (For Offline Usage)
|
|
58
|
+
```
|
|
59
|
+
lu purge
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Build A Dist For Production Version + NodeJs Server
|
|
65
|
+
```
|
|
66
|
+
lu build
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Build A Dist For Production Version without NodeJs Server
|
|
72
|
+
```
|
|
73
|
+
lu build --no-server
|
|
74
|
+
```
|
|
75
|
+
|
package/bin/commands.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
const nodemon = require('nodemon');
|
|
2
|
+
const axios = require('axios').default;
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
// const { exec } = require("child_process");
|
|
6
|
+
const fcs = require("./lib/fcs.js");
|
|
7
|
+
var UglifyJS = require('uglify-js');
|
|
8
|
+
|
|
9
|
+
exports.processCommand = processCommands;
|
|
10
|
+
exports.startServer = startServer;
|
|
11
|
+
|
|
12
|
+
const BEA_Libs = {
|
|
13
|
+
"BEACSS": "https://s.beacdn.com/beacss/latest",
|
|
14
|
+
"BEAJS": "https://s.beacdn.com/beajs/latest"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function processCommands(cmd) {
|
|
18
|
+
var command = cmd ? cmd : process.argv[2];
|
|
19
|
+
if (command == "run" || command == "serve") {
|
|
20
|
+
startServer();
|
|
21
|
+
} else if (command == "create" || command == "update") {
|
|
22
|
+
let c = process.argv.slice(3, process.argv.length);
|
|
23
|
+
let t = fcs.lw(c[0]);
|
|
24
|
+
fcs.create({
|
|
25
|
+
"type": t[0] == "-" ? t.split("-").join("") : t,
|
|
26
|
+
"name": t[0] == "-" ? c.slice(1, c.length) : c
|
|
27
|
+
});
|
|
28
|
+
} else if (command == "purge") {
|
|
29
|
+
axios.get(BEA_Libs.BEAJS, {})
|
|
30
|
+
.then((beajs) => {
|
|
31
|
+
axios.get(BEA_Libs.BEACSS, {})
|
|
32
|
+
.then((beacss) => {
|
|
33
|
+
var filePath = `${process.cwd()}` + path.sep;
|
|
34
|
+
let stylesFile = filePath + path.sep + "src" + path.sep + "css" + path.sep + `bea.css`;
|
|
35
|
+
var libsPath = `${__dirname}` + path.sep + `lib` + path.sep + `files` + path.sep + `libs`;
|
|
36
|
+
fcs.cd(libsPath);
|
|
37
|
+
fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs.data));
|
|
38
|
+
fs.writeFileSync(libsPath + path.sep + "bea.css", String(beacss.data));
|
|
39
|
+
if (fs.existsSync(stylesFile)) {
|
|
40
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(beajs.data));
|
|
41
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beacss.data));
|
|
42
|
+
}
|
|
43
|
+
console.log("Successfully Purged!");
|
|
44
|
+
});
|
|
45
|
+
}).catch(err => {
|
|
46
|
+
console.log("Purge Failed!");
|
|
47
|
+
});
|
|
48
|
+
} else if (command == "build") {
|
|
49
|
+
let cmds = process.argv;
|
|
50
|
+
buildProject(cmds);
|
|
51
|
+
} else {
|
|
52
|
+
console.log("LumenJS CLI's command not found!");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var API = fcs.API;
|
|
57
|
+
|
|
58
|
+
async function buildProject(cmds) {
|
|
59
|
+
var projectPath = `${process.cwd()}`;
|
|
60
|
+
var dest = projectPath + path.sep + 'dist';
|
|
61
|
+
|
|
62
|
+
let _views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
63
|
+
let _comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
64
|
+
var config = fcs.getConfig();
|
|
65
|
+
|
|
66
|
+
var indexCode = fs.readFileSync(projectPath + path.sep + `src` + path.sep + "index.html", "utf8");
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
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
|
+
|
|
73
|
+
if (cmds.indexOf('--no-server') >= 0) {
|
|
74
|
+
var beaCode = "";
|
|
75
|
+
|
|
76
|
+
let r = await API.post("/beajs", {
|
|
77
|
+
"data": JSON.stringify(config.apis)
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let token_ = r.token;
|
|
81
|
+
|
|
82
|
+
if (token_ == "") {
|
|
83
|
+
console.log("Error in making a unique token for your project!")
|
|
84
|
+
|
|
85
|
+
console.log("Error in making a build! Try again later.")
|
|
86
|
+
return;
|
|
87
|
+
} else {
|
|
88
|
+
// make the build happen :)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
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
|
+
var _vcData = {
|
|
102
|
+
"views": `+ JSON.stringify(_views) + `,
|
|
103
|
+
"comps": `+ JSON.stringify(_comps) + `
|
|
104
|
+
};
|
|
105
|
+
`;
|
|
106
|
+
beaCode += `
|
|
107
|
+
` + beaCode2 + `
|
|
108
|
+
`;
|
|
109
|
+
var js2 = `
|
|
110
|
+
exports.config = `+ JSON.stringify(config) + `;
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
let zode = UglifyJS.minify(beaCode, {
|
|
114
|
+
mangle: {
|
|
115
|
+
reserved: ['_vcdata']
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
let zode2 = UglifyJS.minify(js2, {
|
|
119
|
+
mangle: {
|
|
120
|
+
reserved: ['_vcdata']
|
|
121
|
+
},
|
|
122
|
+
output: {
|
|
123
|
+
beautify: true
|
|
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");
|
|
139
|
+
|
|
140
|
+
// fcs.copyDir(projectPath + path.sep + `src` + path.sep + `css`, dest + path.sep + "css");
|
|
141
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "js", dest + path.sep + "js", "_beajsBuild");
|
|
142
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "css", dest + path.sep + "css", "_beajsBuild");
|
|
143
|
+
fcs.copyDir(projectPath + path.sep + "src" + path.sep + "images", dest + path.sep + "images", "_beajsBuild");
|
|
144
|
+
|
|
145
|
+
fs.writeFileSync(dest + path.sep + "js" + path.sep + "bea.js", String(zode.code));
|
|
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
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function startServer() {
|
|
169
|
+
nodemon({
|
|
170
|
+
script: path.join(__dirname.toString(), 'lib', 'app.js'), ext: "view,js,css,json,tpl,html", watch: [
|
|
171
|
+
"src/",
|
|
172
|
+
"config.json"
|
|
173
|
+
]
|
|
174
|
+
});
|
|
175
|
+
nodemon.on('restart', (files) => {
|
|
176
|
+
console.log(files);
|
|
177
|
+
});
|
|
178
|
+
}
|
package/lib/app.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
const axios = require('axios').default;
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const express = require('express');
|
|
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();
|
|
20
|
+
const fcs = require("./fcs.js");
|
|
21
|
+
|
|
22
|
+
let session = expressSession({
|
|
23
|
+
secret: 'keyboardcat',
|
|
24
|
+
resave: true,
|
|
25
|
+
saveUninitialized: true,
|
|
26
|
+
cookie: { maxAge: 9999000 }
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
var config = fcs.getConfig();
|
|
30
|
+
var _views = {};
|
|
31
|
+
var _comps = {};
|
|
32
|
+
|
|
33
|
+
app.use(compression());
|
|
34
|
+
app.use(cookieParser());
|
|
35
|
+
app.use(session);
|
|
36
|
+
app.use('/', express.static(`${process.cwd()}` + path.sep + `src`));
|
|
37
|
+
app.set('etag', false);
|
|
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
|
+
});
|
|
46
|
+
|
|
47
|
+
io.on('connection', function (socket) {
|
|
48
|
+
socket.on("request", async function (_data, _body, cb) {
|
|
49
|
+
try {
|
|
50
|
+
let res = await axios({
|
|
51
|
+
method: _data['method'].toString().toLowerCase(),
|
|
52
|
+
url: fcs.validURL(_data['path']) ? _data['path'] : (config.apis[_data['api'] ?? 0].baseURL + _data['path']),
|
|
53
|
+
data: _body ?? {},
|
|
54
|
+
headers: _data['headers'] ?? config.apis[_data['api'] ?? 0].headers
|
|
55
|
+
});
|
|
56
|
+
cb(res.data);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
cb({ "code": 108, "error": e.message, "type": "RequestError" });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
socket.on("getview", function (msg, cb) {
|
|
62
|
+
try {
|
|
63
|
+
cb(_views[msg]);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
socket.on("getcomp", function (msg, cb) {
|
|
68
|
+
try {
|
|
69
|
+
cb(_comps[msg]);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
socket.on("getfiles", function (cb) {
|
|
74
|
+
try {
|
|
75
|
+
cb({
|
|
76
|
+
"views": _views,
|
|
77
|
+
"comps": _comps
|
|
78
|
+
});
|
|
79
|
+
} catch (e) {
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
global.app = app;
|
|
86
|
+
global.axios = axios;
|
|
87
|
+
global.io = io;
|
|
88
|
+
global.fs = fs;
|
|
89
|
+
global.path = path;
|
|
90
|
+
|
|
91
|
+
var API = fcs.API;
|
|
92
|
+
global.API = API;
|
|
93
|
+
|
|
94
|
+
if(fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`)){
|
|
95
|
+
require(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
app.get('*', function (req, res) {
|
|
99
|
+
let nodes = req.params[0].split("/");
|
|
100
|
+
if (nodes.length) nodes.shift();
|
|
101
|
+
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`);
|
|
102
|
+
return;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
app.post('*', function (req, res) {
|
|
106
|
+
let nodes = req.params[0].split("/");
|
|
107
|
+
if (nodes.length) nodes.shift();
|
|
108
|
+
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`);
|
|
109
|
+
return;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
server.listen(config.server.port, function () {
|
|
113
|
+
console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
|
|
114
|
+
_views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
115
|
+
_comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
116
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const semver = require('semver')
|
|
3
|
+
const axios = require('axios').default;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const fcs = require("./fcs.js");
|
|
7
|
+
const BEA_Libs = {
|
|
8
|
+
"BEACSS": "https://s.beacdn.com/beacss/latest",
|
|
9
|
+
"BEAJS": "https://s.beacdn.com/beajs/latest"
|
|
10
|
+
};
|
|
11
|
+
const m = process.version.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
12
|
+
if (!semver.satisfies(m[0].toString(), '>=12')) {
|
|
13
|
+
console.log("Node version should be minimum 12.0.0");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
} else {
|
|
16
|
+
axios.get(BEA_Libs.BEAJS, {})
|
|
17
|
+
.then((beajs) => {
|
|
18
|
+
axios.get(BEA_Libs.BEACSS, {})
|
|
19
|
+
.then((beacss) => {
|
|
20
|
+
var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
|
|
21
|
+
fcs.cd(libsPath);
|
|
22
|
+
fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs.data));
|
|
23
|
+
fs.writeFileSync(libsPath + path.sep + "bea.css", String(beacss.data));
|
|
24
|
+
console.log("Successfully Purged!");
|
|
25
|
+
});
|
|
26
|
+
}).catch(err => {
|
|
27
|
+
console.log("Purge Failed!");
|
|
28
|
+
});
|
|
29
|
+
}
|
package/lib/fcs.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
const axios = require('axios').default;
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
const BEA_Libs = {
|
|
6
|
+
"BEACSS": "https://s.beacdn.com/beacss/latest",
|
|
7
|
+
"BEAJS": "https://s.beacdn.com/beajs/latest"
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.getAllFiles = getAllFiles;
|
|
11
|
+
exports.ucwords = ucwords;
|
|
12
|
+
|
|
13
|
+
function getAllFiles(dirPath, arrayOfFiles) {
|
|
14
|
+
files = fs.readdirSync(dirPath)
|
|
15
|
+
arrayOfFiles = arrayOfFiles || {}
|
|
16
|
+
files.forEach(function (file) {
|
|
17
|
+
if (fs.statSync(dirPath + path.sep + file).isDirectory()) {
|
|
18
|
+
arrayOfFiles = getAllFiles(dirPath + path.sep + file, arrayOfFiles)
|
|
19
|
+
} else {
|
|
20
|
+
let filePath = path.join(dirPath, path.sep, file);
|
|
21
|
+
let fileKey = Buffer.from((filePath.split(`${process.cwd()}` + path.sep).join("")).split("\\").join("/")).toString('base64');
|
|
22
|
+
arrayOfFiles[fileKey] = fs.readFileSync(filePath, { encoding: 'utf8' });
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return arrayOfFiles;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.getConfig = function () {
|
|
29
|
+
config = {
|
|
30
|
+
"version": "1.0.0.1",
|
|
31
|
+
"server": {
|
|
32
|
+
"host": "127.0.0.1",
|
|
33
|
+
"port": "3000",
|
|
34
|
+
"ssl": {
|
|
35
|
+
"enabled": false,
|
|
36
|
+
"key": "/key.pem",
|
|
37
|
+
"cert": "/certificate.cer"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"project_info": {
|
|
41
|
+
"Title": "PROJECT_TITLE",
|
|
42
|
+
"Description": "PROJECT_DESCRIPTION",
|
|
43
|
+
"Keywords": "website,search,tags,goes,here",
|
|
44
|
+
"WebsiteURL": "https://www.example.com/",
|
|
45
|
+
"Favicon": "/images/favicon.ico",
|
|
46
|
+
"SocialMedia": {
|
|
47
|
+
"LI": "https://www.linkedin.com/",
|
|
48
|
+
"IG": "https://www.instagram.com/",
|
|
49
|
+
"FB": "https://www.facebook.com/"
|
|
50
|
+
},
|
|
51
|
+
"MetaTags": {
|
|
52
|
+
"og:url": "https://www.example.com/",
|
|
53
|
+
"og:title": "PROJECT_TITLE",
|
|
54
|
+
"og:type": "business.business",
|
|
55
|
+
"og:site_name": "PROJECT_TITLE",
|
|
56
|
+
"fb:admins": "592515154",
|
|
57
|
+
"fb:app_id": "138025696270006",
|
|
58
|
+
"og:description": "PROJECT_TITLE",
|
|
59
|
+
"og:image": "/images/example.png",
|
|
60
|
+
"business:contact_data:street_address": "Street Address.",
|
|
61
|
+
"business:contact_data:locality": "Tripoli",
|
|
62
|
+
"business:contact_data:postal_code": "1300",
|
|
63
|
+
"business:contact_data:country_name": "Lebanon",
|
|
64
|
+
"business:contact_data:email": "info@example.com",
|
|
65
|
+
"business:contact_data:phone_number": "+96171299411",
|
|
66
|
+
"business:contact_data:fax_number": "+96171299411",
|
|
67
|
+
"business:contact_data:website": "https://www.example.com/"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"apis": [
|
|
71
|
+
{
|
|
72
|
+
"baseURL": "https://api.backendadmin.com/1",
|
|
73
|
+
"headers": {
|
|
74
|
+
"X-BEA-Application-ID": "YOUR_APPLICATION_ID",
|
|
75
|
+
"X-BEA-Authorization": "YOUR_REST_API_KEY"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
let configPath = process.cwd() + path.sep + `config.json`;
|
|
81
|
+
if (fs.existsSync(configPath)) {
|
|
82
|
+
config = JSON.parse(fs.readFileSync(configPath, { encoding: 'utf8' }));
|
|
83
|
+
}
|
|
84
|
+
return config;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function ucwords(str) {
|
|
88
|
+
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
|
|
89
|
+
return $1.toUpperCase();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function lw(s) { return s.toString().toLowerCase(); }
|
|
93
|
+
exports.lw = lw;
|
|
94
|
+
|
|
95
|
+
function cd(d) {
|
|
96
|
+
if (!fs.existsSync(d)) fs.mkdirSync(d);
|
|
97
|
+
}
|
|
98
|
+
exports.cd = cd;
|
|
99
|
+
|
|
100
|
+
function rd(d) {
|
|
101
|
+
if (fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
|
|
102
|
+
}
|
|
103
|
+
exports.rd = rd;
|
|
104
|
+
|
|
105
|
+
exports.create = function (conf) {
|
|
106
|
+
let t = (conf.type == "v" || conf.type == "s" || conf.type == "c") ? conf.type : "p";
|
|
107
|
+
let n = (conf.type == "v" || conf.type == "s" || conf.type == "c") ? lw(conf.name[0]) : conf.name.join(" ");
|
|
108
|
+
if (t == "p") {
|
|
109
|
+
var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
|
|
110
|
+
var getLibs = false;
|
|
111
|
+
require('dns').resolve('www.google.com', function (err) {
|
|
112
|
+
if (!err) {
|
|
113
|
+
if (!fs.existsSync(libsPath + path.sep + "bea.js")) getLibs = true;
|
|
114
|
+
}
|
|
115
|
+
if (getLibs) {
|
|
116
|
+
axios.get(BEA_Libs.BEAJS, {})
|
|
117
|
+
.then((beajs) => {
|
|
118
|
+
axios.get(BEA_Libs.BEACSS, {})
|
|
119
|
+
.then((beacss) => {
|
|
120
|
+
|
|
121
|
+
var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
|
|
122
|
+
cd(libsPath);
|
|
123
|
+
fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs.data));
|
|
124
|
+
fs.writeFileSync(libsPath + path.sep + "bea.css", String(beacss.data));
|
|
125
|
+
|
|
126
|
+
var filePath = `${process.cwd()}` + path.sep;
|
|
127
|
+
copyDir(`${__dirname}` + path.sep + `files` + path.sep + `project`, filePath, n);
|
|
128
|
+
cd(filePath + path.sep + "src");
|
|
129
|
+
cd(filePath + path.sep + "src" + path.sep + "css");
|
|
130
|
+
cd(filePath + path.sep + "src" + path.sep + "images");
|
|
131
|
+
cd(filePath + path.sep + "src" + path.sep + "js");
|
|
132
|
+
let stylesFile = filePath + path.sep + "src" + path.sep + "css" + path.sep + `styles.css`;
|
|
133
|
+
let faviconFile = filePath + path.sep + "src" + path.sep + `favicon.ico`;
|
|
134
|
+
if (!fs.existsSync(stylesFile)) fs.writeFileSync(stylesFile, String(""));
|
|
135
|
+
if (!fs.existsSync(faviconFile)) fs.writeFileSync(faviconFile, String(""));
|
|
136
|
+
|
|
137
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(beajs.data));
|
|
138
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beacss.data));
|
|
139
|
+
});
|
|
140
|
+
}).catch(err => {
|
|
141
|
+
// Handle error
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
var filePath = `${process.cwd()}` + path.sep;
|
|
145
|
+
copyDir(`${__dirname}` + path.sep + `files` + path.sep + `project`, filePath, n);
|
|
146
|
+
cd(filePath + path.sep + "src");
|
|
147
|
+
cd(filePath + path.sep + "src" + path.sep + "css");
|
|
148
|
+
cd(filePath + path.sep + "src" + path.sep + "images");
|
|
149
|
+
cd(filePath + path.sep + "src" + path.sep + "js");
|
|
150
|
+
let stylesFile = filePath + path.sep + "src" + path.sep + "css" + path.sep + `styles.css`;
|
|
151
|
+
let faviconFile = filePath + path.sep + "src" + path.sep + `favicon.ico`;
|
|
152
|
+
if (!fs.existsSync(stylesFile)) fs.writeFileSync(stylesFile, String(""));
|
|
153
|
+
if (!fs.existsSync(faviconFile)) fs.writeFileSync(faviconFile, String(""));
|
|
154
|
+
|
|
155
|
+
let beajs = Buffer.from(fs.readFileSync(libsPath + path.sep + "bea.js").toString());
|
|
156
|
+
let beacss = Buffer.from(fs.readFileSync(libsPath + path.sep + "bea.css").toString());
|
|
157
|
+
|
|
158
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(beajs));
|
|
159
|
+
fs.writeFileSync(filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beacss));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
let file = t == "s" ? "sub_view.view" : (t == "c" ? "comp.tpl" : "view.view");
|
|
164
|
+
let ident = t == "s" ? "SubView" : (t == "c" ? "Component" : "View");
|
|
165
|
+
let dir = t == "c" ? "comps" : "views";
|
|
166
|
+
let ext = t == "c" ? "tpl" : "view";
|
|
167
|
+
let html5 = Buffer.from(fs.readFileSync(`${__dirname}` + path.sep + `files` + path.sep + file).toString().split("[" + ident + 'Name' + "]").join(ucwords(n)));
|
|
168
|
+
var filePath = `${process.cwd()}` + path.sep + `src` + path.sep + dir + path.sep + `${n}.${ext}`;
|
|
169
|
+
if (fs.existsSync(filePath)) {
|
|
170
|
+
console.log(ident + " already exists:", filePath);
|
|
171
|
+
} else {
|
|
172
|
+
fs.writeFileSync(filePath, html5);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function copyDir(src, dest, projectName) {
|
|
178
|
+
try {
|
|
179
|
+
const entries = fs.readdirSync(src, { encoding: 'utf8', withFileTypes: true });
|
|
180
|
+
|
|
181
|
+
cd(dest);
|
|
182
|
+
|
|
183
|
+
for (let entry of entries) {
|
|
184
|
+
const srcPath = path.join(src.toString(), entry.name.toString());
|
|
185
|
+
const destPath = path.join(dest.toString(), entry.name.toString());
|
|
186
|
+
if (entry.isDirectory()) {
|
|
187
|
+
if (projectName == "_beajsBuild") {
|
|
188
|
+
if (entry.name != "comps" && entry.name != "views" && entry.name != "css" && entry.name != "js") copyDir(srcPath, destPath, projectName);
|
|
189
|
+
}
|
|
190
|
+
else copyDir(srcPath, destPath, projectName);
|
|
191
|
+
} else {
|
|
192
|
+
if (projectName == "_beajsBuild") {
|
|
193
|
+
if (projectName == "_beajsBuild" && (entry.name != "index.js" && entry.name != "index.html"))
|
|
194
|
+
fs.copyFileSync(srcPath, destPath);
|
|
195
|
+
} else {
|
|
196
|
+
if (!fs.existsSync(destPath)) {
|
|
197
|
+
if (projectName) {
|
|
198
|
+
if (entry.name == "index.html") {
|
|
199
|
+
let html5 = Buffer.from(fs.readFileSync(srcPath).toString().split("[ProjectName]").join(ucwords(projectName)));
|
|
200
|
+
fs.writeFileSync(destPath, html5);
|
|
201
|
+
} else fs.copyFileSync(srcPath, destPath);
|
|
202
|
+
} else fs.copyFileSync(srcPath, destPath);
|
|
203
|
+
} else {
|
|
204
|
+
console.log("File already exists:", destPath);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.log(e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.copyDir = copyDir;
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
function validURL(str) {
|
|
217
|
+
var pattern = new RegExp('^(https?:\\/\\/)?' +
|
|
218
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
|
|
219
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' +
|
|
220
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
|
|
221
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' +
|
|
222
|
+
'(\\#[-a-z\\d_]*)?$', 'i');
|
|
223
|
+
return !!pattern.test(str);
|
|
224
|
+
}
|
|
225
|
+
exports.validURL = validURL;
|
|
226
|
+
|
|
227
|
+
var API =
|
|
228
|
+
{
|
|
229
|
+
get: async function (u, d, h, a) {
|
|
230
|
+
return await this.req(u, d, h, "GET", a);
|
|
231
|
+
},
|
|
232
|
+
put: async function (u, d, h, a) {
|
|
233
|
+
return await this.req(u, d, h, "PUT", a);
|
|
234
|
+
},
|
|
235
|
+
post: async function (u, d, h, a) {
|
|
236
|
+
return await this.req(u, d, h, "POST", a);
|
|
237
|
+
},
|
|
238
|
+
delete: async function (u, d, h, a) {
|
|
239
|
+
return await this.req(u, d, h, "DELETE", a);
|
|
240
|
+
},
|
|
241
|
+
patch: async function (u, d, h, a) {
|
|
242
|
+
return await this.req(u, d, h, "PATCH", a);
|
|
243
|
+
},
|
|
244
|
+
req: async function (u, d, h, m, a) {
|
|
245
|
+
let res = await axios({
|
|
246
|
+
method: m.toString().toLowerCase(),
|
|
247
|
+
url: validURL(u) ? u : (config.apis[a ?? 0].baseURL + u),
|
|
248
|
+
data: d ?? {},
|
|
249
|
+
headers: h ?? config.apis[a ?? 0].headers
|
|
250
|
+
});
|
|
251
|
+
return res.data;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
exports.API = API;
|