@lmjs/cli 1.0.29 → 1.0.30

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.
Files changed (2) hide show
  1. package/lib/fcs.js +315 -207
  2. package/package.json +1 -1
package/lib/fcs.js CHANGED
@@ -1,253 +1,361 @@
1
- const axios = require('axios').default;
2
- const path = require('path');
1
+ const axios = require("axios").default;
2
+ const path = require("path");
3
3
  const fs = require("fs");
4
4
 
5
5
  const BEA_Libs = {
6
- "BEACSS": "https://s.beacdn.com/beacss/latest",
7
- "BEAJS": "https://s.beacdn.com/beajs/latest"
6
+ BEACSS: "https://s.beacdn.com/beacss/latest",
7
+ BEAJS: "https://s.beacdn.com/beajs/latest",
8
8
  };
9
9
 
10
10
  exports.getAllFiles = getAllFiles;
11
11
  exports.ucwords = ucwords;
12
12
 
13
13
  function _mini(st) {
14
- for (const key in st) {
15
- st[key] = st[key].replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, "");
16
- st[key] = st[key].replace(/(\r?\n|\n)/g, "");
17
- st[key] = st[key].replace(/(\t)/g, "");
18
- st[key] = st[key].replace(/\s\s+/g, " ");
19
- }
20
- return st;
14
+ for (const key in st) {
15
+ st[key] = st[key].replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, "");
16
+ st[key] = st[key].replace(/(\r?\n|\n)/g, "");
17
+ st[key] = st[key].replace(/(\t)/g, "");
18
+ st[key] = st[key].replace(/\s\s+/g, " ");
19
+ st[key] = st[key].replace(" var ", " ;var ");
20
+ st[key] = st[key].replace(" let ", " ;let ");
21
+ st[key] = st[key].replace(" const ", " ;const ");
21
22
  }
23
+ return st;
24
+ }
22
25
 
23
26
  function getAllFiles(dirPath, arrayOfFiles) {
24
- files = fs.readdirSync(dirPath)
25
- arrayOfFiles = arrayOfFiles || {}
26
- files.forEach(function (file) {
27
- if (fs.statSync(dirPath + path.sep + file).isDirectory()) {
28
- arrayOfFiles = getAllFiles(dirPath + path.sep + file, arrayOfFiles)
29
- } else {
30
- let filePath = path.join(dirPath, path.sep, file);
31
- let fileKey = Buffer.from((filePath.split(`${process.cwd()}` + path.sep).join("")).split("\\").join("/")).toString('base64');
32
- arrayOfFiles[fileKey] = fs.readFileSync(filePath, { encoding: 'utf8' });
33
- }
34
- });
35
- return _mini(arrayOfFiles);
27
+ files = fs.readdirSync(dirPath);
28
+ arrayOfFiles = arrayOfFiles || {};
29
+ files.forEach(function (file) {
30
+ if (fs.statSync(dirPath + path.sep + file).isDirectory()) {
31
+ arrayOfFiles = getAllFiles(dirPath + path.sep + file, arrayOfFiles);
32
+ } else {
33
+ let filePath = path.join(dirPath, path.sep, file);
34
+ let fileKey = Buffer.from(
35
+ filePath
36
+ .split(`${process.cwd()}` + path.sep)
37
+ .join("")
38
+ .split("\\")
39
+ .join("/")
40
+ ).toString("base64");
41
+ arrayOfFiles[fileKey] = fs.readFileSync(filePath, { encoding: "utf8" });
42
+ }
43
+ });
44
+ return _mini(arrayOfFiles);
36
45
  }
37
46
 
38
47
  exports.getConfig = function () {
39
- config = {
40
- "version": "1.0.0.1",
41
- "server": {
42
- "host": "127.0.0.1",
43
- "port": "3000",
44
- "ssl": {
45
- "enabled": false,
46
- "key": "/key.pem",
47
- "cert": "/certificate.cer"
48
- }
48
+ config = {
49
+ version: "1.0.0.1",
50
+ server: {
51
+ host: "127.0.0.1",
52
+ port: "3000",
53
+ ssl: {
54
+ enabled: false,
55
+ key: "/key.pem",
56
+ cert: "/certificate.cer",
57
+ },
58
+ },
59
+ apis: [
60
+ {
61
+ baseURL: "https://www.beaapis.com/1",
62
+ headers: {
63
+ "X-BEA-Application-ID": "YOUR_APPLICATION_ID",
64
+ "X-BEA-Authorization": "YOUR_REST_API_KEY",
49
65
  },
50
- "apis": [
51
- {
52
- "baseURL": "https://www.beaapis.com/1",
53
- "headers": {
54
- "X-BEA-Application-ID": "YOUR_APPLICATION_ID",
55
- "X-BEA-Authorization": "YOUR_REST_API_KEY"
56
- }
57
- }
58
- ],
59
- "ftp": {
60
- "host": "ftp_host",
61
- "username": "ftp_username",
62
- "password": "ftp_password",
63
- "remotePath": "/",
64
- "concurrency": 4,
65
- "protocol": "ftp",
66
- "port": 21,
67
- "ignore": [],
68
- "syncOption": {
69
- "delete": false,
70
- "ignoreExisting": false,
71
- "skipCreate": false,
72
- "update": true
73
- },
74
- "connectTimeout": 30000
75
- }
76
- };
77
- let configPath = process.cwd() + path.sep + `config.json`;
78
- if (fs.existsSync(configPath)) {
79
- config = JSON.parse(fs.readFileSync(configPath, { encoding: 'utf8' }));
80
- }
81
- return config;
66
+ },
67
+ ],
68
+ ftp: {
69
+ host: "ftp_host",
70
+ username: "ftp_username",
71
+ password: "ftp_password",
72
+ remotePath: "/",
73
+ concurrency: 4,
74
+ protocol: "ftp",
75
+ port: 21,
76
+ ignore: [],
77
+ syncOption: {
78
+ delete: false,
79
+ ignoreExisting: false,
80
+ skipCreate: false,
81
+ update: true,
82
+ },
83
+ connectTimeout: 30000,
84
+ },
85
+ };
86
+ let configPath = process.cwd() + path.sep + `config.json`;
87
+ if (fs.existsSync(configPath)) {
88
+ config = JSON.parse(fs.readFileSync(configPath, { encoding: "utf8" }));
89
+ }
90
+ return config;
82
91
  };
83
92
 
84
93
  function ucwords(str) {
85
- return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
86
- return $1.toUpperCase();
87
- });
94
+ return (str + "").replace(/^([a-z])|\s+([a-z])/g, function ($1) {
95
+ return $1.toUpperCase();
96
+ });
97
+ }
98
+ function lw(s) {
99
+ return s.toString().toLowerCase();
88
100
  }
89
- function lw(s) { return s.toString().toLowerCase(); }
90
101
  exports.lw = lw;
91
102
 
92
103
  function cd(d) {
93
- if (!fs.existsSync(d)) fs.mkdirSync(d);
104
+ if (!fs.existsSync(d)) fs.mkdirSync(d);
94
105
  }
95
106
  exports.cd = cd;
96
107
 
97
108
  function rd(d) {
98
- if (fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
109
+ if (fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
99
110
  }
100
111
  exports.rd = rd;
101
112
 
102
113
  exports.create = function (conf) {
103
- let t = (conf.type == "v" || conf.type == "s" || conf.type == "c") ? conf.type : "p";
104
- let n = (conf.type == "v" || conf.type == "s" || conf.type == "c") ? lw(conf.name[0]) : conf.name.join(" ");
105
- if (t == "p") {
106
- var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
107
- var getLibs = false;
108
- require('dns').resolve('www.google.com', function (err) {
109
- if (!err) {
110
- if (!fs.existsSync(libsPath + path.sep + "bea.js")) getLibs = true;
111
- }
112
- if (getLibs) {
113
- axios.get(BEA_Libs.BEAJS, {})
114
- .then((beajs) => {
115
- axios.get(BEA_Libs.BEACSS, {})
116
- .then((beacss) => {
117
-
118
- var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
119
- cd(libsPath);
120
- fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs.data));
121
- fs.writeFileSync(libsPath + path.sep + "bea.css", String(beacss.data));
122
-
123
- var filePath = `${process.cwd()}` + path.sep;
124
- copyDir(`${__dirname}` + path.sep + `files` + path.sep + `project`, filePath, n);
125
- cd(filePath + path.sep + "src");
126
- cd(filePath + path.sep + "src" + path.sep + "css");
127
- cd(filePath + path.sep + "src" + path.sep + "images");
128
- cd(filePath + path.sep + "src" + path.sep + "js");
129
- let stylesFile = filePath + path.sep + "src" + path.sep + "css" + path.sep + `styles.css`;
130
- let faviconFile = filePath + path.sep + "src" + path.sep + `favicon.ico`;
131
- if (!fs.existsSync(stylesFile)) fs.writeFileSync(stylesFile, String(""));
132
- if (!fs.existsSync(faviconFile)) fs.writeFileSync(faviconFile, String(""));
133
-
134
- fs.writeFileSync(filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(beajs.data));
135
- fs.writeFileSync(filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beacss.data));
136
- });
137
- }).catch(err => {
138
- // Handle error
139
- });
140
- } else {
141
- var filePath = `${process.cwd()}` + path.sep;
142
- copyDir(`${__dirname}` + path.sep + `files` + path.sep + `project`, filePath, n);
143
- cd(filePath + path.sep + "src");
144
- cd(filePath + path.sep + "src" + path.sep + "css");
145
- cd(filePath + path.sep + "src" + path.sep + "images");
146
- cd(filePath + path.sep + "src" + path.sep + "js");
147
- let stylesFile = filePath + path.sep + "src" + path.sep + "css" + path.sep + `styles.css`;
148
- let faviconFile = filePath + path.sep + "src" + path.sep + `favicon.ico`;
149
- if (!fs.existsSync(stylesFile)) fs.writeFileSync(stylesFile, String(""));
150
- if (!fs.existsSync(faviconFile)) fs.writeFileSync(faviconFile, String(""));
151
-
152
- let beajs = Buffer.from(fs.readFileSync(libsPath + path.sep + "bea.js").toString());
153
- let beacss = Buffer.from(fs.readFileSync(libsPath + path.sep + "bea.css").toString());
154
-
155
- fs.writeFileSync(filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js", String(beajs));
156
- fs.writeFileSync(filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css", String(beacss));
157
- }
158
- });
114
+ let t =
115
+ conf.type == "v" || conf.type == "s" || conf.type == "c" ? conf.type : "p";
116
+ let n =
117
+ conf.type == "v" || conf.type == "s" || conf.type == "c"
118
+ ? lw(conf.name[0])
119
+ : conf.name.join(" ");
120
+ if (t == "p") {
121
+ var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
122
+ var getLibs = false;
123
+ require("dns").resolve("www.google.com", function (err) {
124
+ if (!err) {
125
+ if (!fs.existsSync(libsPath + path.sep + "bea.js")) getLibs = true;
126
+ }
127
+ if (getLibs) {
128
+ axios
129
+ .get(BEA_Libs.BEAJS, {})
130
+ .then((beajs) => {
131
+ axios.get(BEA_Libs.BEACSS, {}).then((beacss) => {
132
+ var libsPath =
133
+ `${__dirname}` + path.sep + `files` + path.sep + `libs`;
134
+ cd(libsPath);
135
+ fs.writeFileSync(
136
+ libsPath + path.sep + "bea.js",
137
+ String(beajs.data)
138
+ );
139
+ fs.writeFileSync(
140
+ libsPath + path.sep + "bea.css",
141
+ String(beacss.data)
142
+ );
143
+
144
+ var filePath = `${process.cwd()}` + path.sep;
145
+ copyDir(
146
+ `${__dirname}` + path.sep + `files` + path.sep + `project`,
147
+ filePath,
148
+ n
149
+ );
150
+ cd(filePath + path.sep + "src");
151
+ cd(filePath + path.sep + "src" + path.sep + "css");
152
+ cd(filePath + path.sep + "src" + path.sep + "images");
153
+ cd(filePath + path.sep + "src" + path.sep + "js");
154
+ let stylesFile =
155
+ filePath +
156
+ path.sep +
157
+ "src" +
158
+ path.sep +
159
+ "css" +
160
+ path.sep +
161
+ `styles.css`;
162
+ let faviconFile =
163
+ filePath + path.sep + "src" + path.sep + `favicon.ico`;
164
+ if (!fs.existsSync(stylesFile))
165
+ fs.writeFileSync(stylesFile, String(""));
166
+ if (!fs.existsSync(faviconFile))
167
+ fs.writeFileSync(faviconFile, String(""));
168
+
169
+ fs.writeFileSync(
170
+ filePath +
171
+ path.sep +
172
+ "src" +
173
+ path.sep +
174
+ "js" +
175
+ path.sep +
176
+ "bea.js",
177
+ String(beajs.data)
178
+ );
179
+ fs.writeFileSync(
180
+ filePath +
181
+ path.sep +
182
+ "src" +
183
+ path.sep +
184
+ "css" +
185
+ path.sep +
186
+ "bea.css",
187
+ String(beacss.data)
188
+ );
189
+ });
190
+ })
191
+ .catch((err) => {
192
+ // Handle error
193
+ });
194
+ } else {
195
+ var filePath = `${process.cwd()}` + path.sep;
196
+ copyDir(
197
+ `${__dirname}` + path.sep + `files` + path.sep + `project`,
198
+ filePath,
199
+ n
200
+ );
201
+ cd(filePath + path.sep + "src");
202
+ cd(filePath + path.sep + "src" + path.sep + "css");
203
+ cd(filePath + path.sep + "src" + path.sep + "images");
204
+ cd(filePath + path.sep + "src" + path.sep + "js");
205
+ let stylesFile =
206
+ filePath +
207
+ path.sep +
208
+ "src" +
209
+ path.sep +
210
+ "css" +
211
+ path.sep +
212
+ `styles.css`;
213
+ let faviconFile =
214
+ filePath + path.sep + "src" + path.sep + `favicon.ico`;
215
+ if (!fs.existsSync(stylesFile))
216
+ fs.writeFileSync(stylesFile, String(""));
217
+ if (!fs.existsSync(faviconFile))
218
+ fs.writeFileSync(faviconFile, String(""));
219
+
220
+ let beajs = Buffer.from(
221
+ fs.readFileSync(libsPath + path.sep + "bea.js").toString()
222
+ );
223
+ let beacss = Buffer.from(
224
+ fs.readFileSync(libsPath + path.sep + "bea.css").toString()
225
+ );
226
+
227
+ fs.writeFileSync(
228
+ filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js",
229
+ String(beajs)
230
+ );
231
+ fs.writeFileSync(
232
+ filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css",
233
+ String(beacss)
234
+ );
235
+ }
236
+ });
237
+ } else {
238
+ let file = t == "s" ? "sub_view.view" : t == "c" ? "tpl.tpl" : "view.view";
239
+ let ident = t == "s" ? "SubView" : t == "c" ? "Template" : "View";
240
+ let dir = t == "c" ? "tpls" : "views";
241
+ let ext = t == "c" ? "tpl" : "view";
242
+ let html5 = Buffer.from(
243
+ fs
244
+ .readFileSync(`${__dirname}` + path.sep + `files` + path.sep + file)
245
+ .toString()
246
+ .split("[" + ident + "Name" + "]")
247
+ .join(ucwords(n))
248
+ );
249
+ var filePath =
250
+ `${process.cwd()}` +
251
+ path.sep +
252
+ `src` +
253
+ path.sep +
254
+ dir +
255
+ path.sep +
256
+ `${n}.${ext}`;
257
+ if (fs.existsSync(filePath)) {
258
+ console.log(ident + " already exists:", filePath);
159
259
  } else {
160
- let file = t == "s" ? "sub_view.view" : (t == "c" ? "tpl.tpl" : "view.view");
161
- let ident = t == "s" ? "SubView" : (t == "c" ? "Template" : "View");
162
- let dir = t == "c" ? "tpls" : "views";
163
- let ext = t == "c" ? "tpl" : "view";
164
- let html5 = Buffer.from(fs.readFileSync(`${__dirname}` + path.sep + `files` + path.sep + file).toString().split("[" + ident + 'Name' + "]").join(ucwords(n)));
165
- var filePath = `${process.cwd()}` + path.sep + `src` + path.sep + dir + path.sep + `${n}.${ext}`;
166
- if (fs.existsSync(filePath)) {
167
- console.log(ident + " already exists:", filePath);
168
- } else {
169
- fs.writeFileSync(filePath, html5);
170
- }
260
+ fs.writeFileSync(filePath, html5);
171
261
  }
172
- }
262
+ }
263
+ };
173
264
 
174
265
  function copyDir(src, dest, projectName) {
175
- try {
176
- const entries = fs.readdirSync(src, { encoding: 'utf8', withFileTypes: true });
177
-
178
- cd(dest);
179
-
180
- for (let entry of entries) {
181
- const srcPath = path.join(src.toString(), entry.name.toString());
182
- const destPath = path.join(dest.toString(), entry.name.toString());
183
- if (entry.isDirectory()) {
184
- if (projectName == "_beajsBuild") {
185
- if (entry.name != "tpls" && entry.name != "views" && entry.name != "css" && entry.name != "js") copyDir(srcPath, destPath, projectName);
186
- }
187
- else copyDir(srcPath, destPath, projectName);
188
- } else {
189
- if (projectName == "_beajsBuild") {
190
- if (projectName == "_beajsBuild" && (entry.name != "index.js" && entry.name != "index.html"))
191
- fs.copyFileSync(srcPath, destPath);
192
- } else {
193
- if (!fs.existsSync(destPath)) {
194
- if (projectName) {
195
- if (entry.name == "index.html") {
196
- let html5 = Buffer.from(fs.readFileSync(srcPath).toString().split("[ProjectName]").join(ucwords(projectName)));
197
- fs.writeFileSync(destPath, html5);
198
- } else fs.copyFileSync(srcPath, destPath);
199
- } else fs.copyFileSync(srcPath, destPath);
200
- } else {
201
- console.log("File already exists:", destPath);
202
- }
203
- }
204
- }
266
+ try {
267
+ const entries = fs.readdirSync(src, {
268
+ encoding: "utf8",
269
+ withFileTypes: true,
270
+ });
271
+
272
+ cd(dest);
273
+
274
+ for (let entry of entries) {
275
+ const srcPath = path.join(src.toString(), entry.name.toString());
276
+ const destPath = path.join(dest.toString(), entry.name.toString());
277
+ if (entry.isDirectory()) {
278
+ if (projectName == "_beajsBuild") {
279
+ if (
280
+ entry.name != "tpls" &&
281
+ entry.name != "views" &&
282
+ entry.name != "css" &&
283
+ entry.name != "js"
284
+ )
285
+ copyDir(srcPath, destPath, projectName);
286
+ } else copyDir(srcPath, destPath, projectName);
287
+ } else {
288
+ if (projectName == "_beajsBuild") {
289
+ if (
290
+ projectName == "_beajsBuild" &&
291
+ entry.name != "index.js" &&
292
+ entry.name != "index.html"
293
+ )
294
+ fs.copyFileSync(srcPath, destPath);
295
+ } else {
296
+ if (!fs.existsSync(destPath)) {
297
+ if (projectName) {
298
+ if (entry.name == "index.html") {
299
+ let html5 = Buffer.from(
300
+ fs
301
+ .readFileSync(srcPath)
302
+ .toString()
303
+ .split("[ProjectName]")
304
+ .join(ucwords(projectName))
305
+ );
306
+ fs.writeFileSync(destPath, html5);
307
+ } else fs.copyFileSync(srcPath, destPath);
308
+ } else fs.copyFileSync(srcPath, destPath);
309
+ } else {
310
+ console.log("File already exists:", destPath);
311
+ }
205
312
  }
206
- } catch (e) {
207
- console.log(e);
313
+ }
208
314
  }
315
+ } catch (e) {
316
+ console.log(e);
317
+ }
209
318
  }
210
319
  exports.copyDir = copyDir;
211
320
 
212
321
  function validURL(string) {
213
- let url;
214
- try {
215
- url = new URL(string);
216
- } catch (_) {
217
- return false;
218
- }
219
- return url.protocol === "http:" || url.protocol === "https:";
322
+ let url;
323
+ try {
324
+ url = new URL(string);
325
+ } catch (_) {
326
+ return false;
327
+ }
328
+ return url.protocol === "http:" || url.protocol === "https:";
220
329
  }
221
330
 
222
331
  exports.validURL = validURL;
223
332
 
224
- var API =
225
- {
226
- get: async function (u, d, h, a) {
227
- return await this.req(u, d, h, "GET", a);
228
- },
229
- put: async function (u, d, h, a) {
230
- return await this.req(u, d, h, "PUT", a);
231
- },
232
- post: async function (u, d, h, a) {
233
- return await this.req(u, d, h, "POST", a);
234
- },
235
- delete: async function (u, d, h, a) {
236
- return await this.req(u, d, h, "DELETE", a);
237
- },
238
- patch: async function (u, d, h, a) {
239
- return await this.req(u, d, h, "PATCH", a);
240
- },
241
- req: async function (u, d, h, m, a) {
242
- let res = await axios({
243
- method: m.toString().toLowerCase(),
244
- url: validURL(u) ? u : (config.apis[a ?? 0].baseURL + u),
245
- data: d ?? {},
246
- headers: h ?? config.apis[a ?? 0].headers,
247
- maxContentLength: 100000000,
248
- maxBodyLength: 1000000000
249
- });
250
- return res.data;
251
- }
333
+ var API = {
334
+ get: async function (u, d, h, a) {
335
+ return await this.req(u, d, h, "GET", a);
336
+ },
337
+ put: async function (u, d, h, a) {
338
+ return await this.req(u, d, h, "PUT", a);
339
+ },
340
+ post: async function (u, d, h, a) {
341
+ return await this.req(u, d, h, "POST", a);
342
+ },
343
+ delete: async function (u, d, h, a) {
344
+ return await this.req(u, d, h, "DELETE", a);
345
+ },
346
+ patch: async function (u, d, h, a) {
347
+ return await this.req(u, d, h, "PATCH", a);
348
+ },
349
+ req: async function (u, d, h, m, a) {
350
+ let res = await axios({
351
+ method: m.toString().toLowerCase(),
352
+ url: validURL(u) ? u : config.apis[a ?? 0].baseURL + u,
353
+ data: d ?? {},
354
+ headers: h ?? config.apis[a ?? 0].headers,
355
+ maxContentLength: 100000000,
356
+ maxBodyLength: 1000000000,
357
+ });
358
+ return res.data;
359
+ },
252
360
  };
253
- exports.API = API;
361
+ exports.API = API;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmjs/cli",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
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": {