@lmjs/cli 1.0.50 → 2.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.
Files changed (45) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +5 -16
  3. package/dist/bin/commands.js +2 -0
  4. package/dist/lib/app.js +3 -0
  5. package/dist/lib/check-version.js +2 -0
  6. package/dist/lib/fcs.js +11 -0
  7. package/{lib → dist/lib}/files/build_serverless/.htaccess +0 -0
  8. package/{lib/files/build/src → dist/lib/files/build_serverless}/favicon.ico +0 -0
  9. package/{lib/files/build/src → dist/lib/files/build_serverless}/robots.txt +0 -0
  10. package/{lib/files/build/src → dist/lib/files/build_serverless}/sitemap.xml +0 -0
  11. package/dist/lib/files/layout.layout +4 -0
  12. package/dist/lib/files/libs/bea.css +1 -0
  13. package/dist/lib/files/libs/lm-with-plugins.js +539 -0
  14. package/dist/lib/files/libs/lm.js +30 -0
  15. package/dist/lib/files/libs/lumenjs-plugins.css +2822 -0
  16. package/{lib → dist/lib}/files/project/config.json +1 -1
  17. package/dist/lib/files/project/package.json +6 -0
  18. package/{lib → dist/lib}/files/project/src/404.html +1 -1
  19. package/{lib → dist/lib}/files/project/src/index.html +3 -3
  20. package/dist/lib/files/project/src/index.js +1 -0
  21. package/dist/lib/files/project/src/layouts/default.layout +4 -0
  22. package/{lib → dist/lib}/files/project/src/views/home.view +2 -3
  23. package/{lib → dist/lib}/files/sub_view.view +0 -0
  24. package/dist/lib/files/view.view +13 -0
  25. package/dist/lib/npm-bundle.js +1 -0
  26. package/dist/lib/plugins-esbuild-plugin.js +3 -0
  27. package/package.json +37 -19
  28. package/bin/commands.js +0 -2
  29. package/lib/app.js +0 -132
  30. package/lib/check-version.js +0 -28
  31. package/lib/fcs.js +0 -804
  32. package/lib/files/build/func.js +0 -102
  33. package/lib/files/build/package.json +0 -31
  34. package/lib/files/build/server.js +0 -58
  35. package/lib/files/build_serverless/favicon.ico +0 -0
  36. package/lib/files/build_serverless/robots.txt +0 -4
  37. package/lib/files/build_serverless/sitemap.xml +0 -9
  38. package/lib/files/project/src/index.js +0 -15
  39. package/lib/files/project/src/tpls/tpl1.tpl +0 -1
  40. package/lib/files/project/src/views/widgets/footer.view +0 -0
  41. package/lib/files/project/src/views/widgets/header.view +0 -0
  42. package/lib/files/project/src/views/widgets/nav.view +0 -0
  43. package/lib/files/tpl.tpl +0 -1
  44. package/lib/files/view.view +0 -14
  45. /package/{lib → dist/lib}/files/project/src/images/lumenjs.svg +0 -0
package/lib/fcs.js DELETED
@@ -1,804 +0,0 @@
1
- const fetch = require('node-fetch');
2
- const path = require("path");
3
- const fs = require("fs");
4
- const nodemon = require("nodemon");
5
-
6
- var _min = require("html-minifier").minify;
7
-
8
- const _FD = require("ftp-deploy");
9
- const _fD = new _FD();
10
-
11
- const BEA_Libs = {
12
- BEACSS: "https://s.beacdn.com/beacss/latest",
13
- BEAJS: "https://s.beacdn.com/beajs/latest",
14
- };
15
-
16
- exports.getAllFiles = getAllFiles;
17
- exports.ucwords = ucwords;
18
-
19
- exports.fetch = fetch;
20
- exports.getConfig = getConfig;
21
- function getConfig() {
22
- config = {
23
- version: "1.0.0.1",
24
- server: {
25
- host: "127.0.0.1",
26
- port: "3000",
27
- ssl: {
28
- enabled: false,
29
- key: "/key.pem",
30
- cert: "/certificate.cer",
31
- },
32
- },
33
- apis: [
34
- {
35
- baseURL: "https://www.beaapis.com/1",
36
- headers: {
37
- "X-BEA-Application-ID": "YOUR_APPLICATION_ID",
38
- "X-BEA-Authorization": "YOUR_REST_API_KEY",
39
- },
40
- },
41
- ],
42
- ftp: {
43
- host: "ftp_host",
44
- username: "ftp_username",
45
- password: "ftp_password",
46
- remotePath: "/",
47
- concurrency: 4,
48
- protocol: "ftp",
49
- port: 21,
50
- ignore: [],
51
- syncOption: {
52
- delete: false,
53
- ignoreExisting: false,
54
- skipCreate: false,
55
- update: true,
56
- },
57
- connectTimeout: 30000,
58
- },
59
- };
60
- let configPath = process.cwd() + path.sep + `config.json`;
61
- if (fs.existsSync(configPath)) {
62
- config = JSON.parse(fs.readFileSync(configPath, { encoding: "utf8" }));
63
- }
64
- return config;
65
- }
66
-
67
- var config = getConfig();
68
-
69
- function ucwords(str) {
70
- return (str + "").replace(/^([a-z])|\s+([a-z])/g, function ($1) {
71
- return $1.toUpperCase();
72
- });
73
- }
74
- function lw(s) {
75
- return s.toString().toLowerCase();
76
- }
77
- exports.lw = lw;
78
-
79
- function cd(d) {
80
- if (!fs.existsSync(d)) fs.mkdirSync(d);
81
- }
82
- exports.cd = cd;
83
-
84
- function rd(d) {
85
- if (fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
86
- }
87
- exports.rd = rd;
88
-
89
- function create(conf) {
90
- let t =
91
- conf.type == "v" || conf.type == "s" || conf.type == "t" ? conf.type : "p";
92
- let n =
93
- conf.type == "v" || conf.type == "s" || conf.type == "t"
94
- ? lw(conf.name[0])
95
- : conf.name.join(" ");
96
- if (t == "p") {
97
- var libsPath = `${__dirname}` + path.sep + `files` + path.sep + `libs`;
98
- var getLibs = false;
99
- require("dns").resolve("www.google.com", function (err) {
100
- if (!err) {
101
- if (!fs.existsSync(libsPath + path.sep + "bea.js")) getLibs = true;
102
- }
103
- if (getLibs) {
104
- API
105
- .get(BEA_Libs.BEAJS, {})
106
- .then((beajs) => {
107
- API.get(BEA_Libs.BEACSS, {}).then((beacss) => {
108
- var libsPath =
109
- `${__dirname}` + path.sep + `files` + path.sep + `libs`;
110
- cd(libsPath);
111
- fs.writeFileSync(
112
- libsPath + path.sep + "bea.js",
113
- String(beajs.data)
114
- );
115
- fs.writeFileSync(
116
- libsPath + path.sep + "bea.css",
117
- String(beacss.data)
118
- );
119
-
120
- var filePath = `${process.cwd()}` + path.sep;
121
- copyDir(
122
- `${__dirname}` + path.sep + `files` + path.sep + `project`,
123
- filePath,
124
- n
125
- );
126
- cd(filePath + path.sep + "src");
127
- cd(filePath + path.sep + "src" + path.sep + "css");
128
- cd(filePath + path.sep + "src" + path.sep + "images");
129
- cd(filePath + path.sep + "src" + path.sep + "js");
130
- let stylesFile =
131
- filePath +
132
- path.sep +
133
- "src" +
134
- path.sep +
135
- "css" +
136
- path.sep +
137
- `styles.css`;
138
- let faviconFile =
139
- filePath + path.sep + "src" + path.sep + `favicon.ico`;
140
- if (!fs.existsSync(stylesFile))
141
- fs.writeFileSync(stylesFile, String(""));
142
- if (!fs.existsSync(faviconFile))
143
- fs.writeFileSync(faviconFile, String(""));
144
-
145
- fs.writeFileSync(
146
- filePath +
147
- path.sep +
148
- "src" +
149
- path.sep +
150
- "js" +
151
- path.sep +
152
- "bea.js",
153
- String(beajs.data)
154
- );
155
- fs.writeFileSync(
156
- filePath +
157
- path.sep +
158
- "src" +
159
- path.sep +
160
- "css" +
161
- path.sep +
162
- "bea.css",
163
- String(beacss.data)
164
- );
165
- });
166
- })
167
- .catch((err) => {
168
- // Handle error
169
- });
170
- } else {
171
- var filePath = `${process.cwd()}` + path.sep;
172
- copyDir(
173
- `${__dirname}` + path.sep + `files` + path.sep + `project`,
174
- filePath,
175
- n
176
- );
177
- cd(filePath + path.sep + "src");
178
- cd(filePath + path.sep + "src" + path.sep + "css");
179
- cd(filePath + path.sep + "src" + path.sep + "images");
180
- cd(filePath + path.sep + "src" + path.sep + "js");
181
- let stylesFile =
182
- filePath +
183
- path.sep +
184
- "src" +
185
- path.sep +
186
- "css" +
187
- path.sep +
188
- `styles.css`;
189
- let faviconFile =
190
- filePath + path.sep + "src" + path.sep + `favicon.ico`;
191
- if (!fs.existsSync(stylesFile))
192
- fs.writeFileSync(stylesFile, String(""));
193
- if (!fs.existsSync(faviconFile))
194
- fs.writeFileSync(faviconFile, String(""));
195
-
196
- let beajs = Buffer.from(
197
- fs.readFileSync(libsPath + path.sep + "bea.js").toString()
198
- );
199
- let beacss = Buffer.from(
200
- fs.readFileSync(libsPath + path.sep + "bea.css").toString()
201
- );
202
-
203
- fs.writeFileSync(
204
- filePath + path.sep + "src" + path.sep + "js" + path.sep + "bea.js",
205
- String(beajs)
206
- );
207
- fs.writeFileSync(
208
- filePath + path.sep + "src" + path.sep + "css" + path.sep + "bea.css",
209
- String(beacss)
210
- );
211
- }
212
- });
213
- } else {
214
- let file = t == "s" ? "sub_view.view" : t == "t" ? "tpl.tpl" : "view.view";
215
- let ident = t == "s" ? "SubView" : t == "t" ? "Template" : "View";
216
- let dir = t == "t" ? "tpls" : "views";
217
- let ext = t == "t" ? "tpl" : "view";
218
- let html5 = Buffer.from(
219
- fs
220
- .readFileSync(`${__dirname}` + path.sep + `files` + path.sep + file)
221
- .toString()
222
- .split("[" + ident + "Name" + "]")
223
- .join(ucwords(n))
224
- );
225
- var filePath =
226
- `${process.cwd()}` +
227
- path.sep +
228
- `src` +
229
- path.sep +
230
- dir +
231
- path.sep +
232
- `${n}.${ext}`;
233
- if (fs.existsSync(filePath)) {
234
- console.log(ident + " already exists:", filePath);
235
- } else {
236
- fs.writeFileSync(filePath, html5);
237
- }
238
- }
239
- }
240
-
241
- function getAllFiles(dirPath, arrayOfFiles = {}, mini = false) {
242
- files = fs.readdirSync(dirPath);
243
- files.forEach(function (file) {
244
- if (fs.statSync(dirPath + path.sep + file).isDirectory()) {
245
- arrayOfFiles = getAllFiles(dirPath + path.sep + file, arrayOfFiles, mini);
246
- } else {
247
- let filePath = path.join(dirPath, path.sep, file);
248
- let fileKey = Buffer.from(
249
- filePath
250
- .split(`${process.cwd()}` + path.sep)
251
- .join("")
252
- .split("\\")
253
- .join("/")
254
- ).toString("base64");
255
- if (mini) {
256
- var result = _min(fs.readFileSync(filePath, { encoding: "utf8" }), {
257
- removeAttributeQuotes: false,
258
- caseSensitive: true,
259
- collapseWhitespace: true,
260
- collapseInlineTagWhitespace: true,
261
- conservativeCollapse: true,
262
- removeComments: true,
263
- minifyJS: false,
264
- minifyCSS: false,
265
- processConditionalComments: true,
266
- collapseBooleanAttributes: false,
267
- decodeEntities: false,
268
- html5: true,
269
- includeAutoGeneratedTags: true,
270
- keepClosingSlash: true,
271
- maxLineLength: null,
272
- minifyURLs: false,
273
- preserveLineBreaks: false,
274
- preventAttributesEscaping: false,
275
- processScripts: ["text/html"],
276
- quoteCharacter: "",
277
- removeEmptyAttributes: true,
278
- removeEmptyElements: false,
279
- removeOptionalTags: true,
280
- removeRedundantAttributes: true,
281
- removeScriptTypeAttributes: false,
282
- removeStyleLinkTypeAttributes: true,
283
- removeTagWhitespace: false,
284
- sortAttributes: false,
285
- sortClassName: false,
286
- trimCustomFragments: true,
287
- useShortDoctype: true,
288
- continueOnParseError: true
289
- });
290
- } else {
291
- var result = fs.readFileSync(filePath, { encoding: "utf8" });
292
- }
293
- arrayOfFiles[fileKey] = result;
294
- }
295
- });
296
- return arrayOfFiles;
297
- }
298
-
299
- function copyDir(src, dest, projectName) {
300
- try {
301
- const entries = fs.readdirSync(src, {
302
- encoding: "utf8",
303
- withFileTypes: true,
304
- });
305
-
306
- cd(dest);
307
-
308
- for (let entry of entries) {
309
- const srcPath = path.join(src.toString(), entry.name.toString());
310
- const destPath = path.join(dest.toString(), entry.name.toString());
311
- if (entry.isDirectory()) {
312
- if (projectName == "_beajsBuild") {
313
- if (
314
- entry.name != "tpls" &&
315
- entry.name != "views" &&
316
- entry.name != "css" &&
317
- entry.name != "js"
318
- )
319
- copyDir(srcPath, destPath, projectName);
320
- } else copyDir(srcPath, destPath, projectName);
321
- } else {
322
- if (projectName == "_beajsBuild") {
323
- if (
324
- projectName == "_beajsBuild" &&
325
- entry.name != "index.js" &&
326
- entry.name != "index.html"
327
- )
328
- fs.copyFileSync(srcPath, destPath);
329
- } else {
330
- if (!fs.existsSync(destPath)) {
331
- if (projectName) {
332
- if (entry.name == "index.html") {
333
- let html5 = Buffer.from(
334
- fs
335
- .readFileSync(srcPath)
336
- .toString()
337
- .split("[ProjectName]")
338
- .join(ucwords(projectName))
339
- );
340
- fs.writeFileSync(destPath, html5);
341
- } else fs.copyFileSync(srcPath, destPath);
342
- } else fs.copyFileSync(srcPath, destPath);
343
- } else {
344
- console.log("File already exists:", destPath);
345
- }
346
- }
347
- }
348
- }
349
- } catch (e) {
350
- console.log(e);
351
- }
352
- }
353
- exports.copyDir = copyDir;
354
-
355
- function validURL(string) {
356
- let url;
357
- try {
358
- url = new URL(string);
359
- } catch (_) {
360
- return false;
361
- }
362
- return url.protocol === "http:" || url.protocol === "https:";
363
- }
364
-
365
- exports.validURL = validURL;
366
-
367
-
368
- let getPairs = (obj, keys = []) =>
369
- Object.entries(obj).reduce((pairs, [key, value]) => {
370
- if (typeof value === 'object')
371
- pairs.push(...getPairs(value, [...keys, key]));
372
- else
373
- pairs.push([[...keys, key], value]);
374
- return pairs;
375
- }, []);
376
-
377
- function pairIt(obj) {
378
- return getPairs(obj).map(([[key0, ...keysRest], value]) =>
379
- `${key0}${keysRest.map(a => `[${a}]`).join('')}=${value}`)
380
- .join('&');
381
- }
382
-
383
- var API = {
384
- get: async function (u, d, h, a) {
385
- return await this.req(u, d, h, "GET", a);
386
- },
387
- put: async function (u, d, h, a) {
388
- return await this.req(u, d, h, "PUT", a);
389
- },
390
- post: async function (u, d, h, a) {
391
- return await this.req(u, d, h, "POST", a);
392
- },
393
- delete: async function (u, d, h, a) {
394
- return await this.req(u, d, h, "DELETE", a);
395
- },
396
- patch: async function (u, d, h, a) {
397
- return await this.req(u, d, h, "PATCH", a);
398
- },
399
- req: async function (u, d, h, m, a, f) {
400
-
401
- var urled = validURL(u) ? u : config.apis[a ?? 0].baseURL + u;
402
- if (m.toString().toLowerCase() == 'get') {
403
- if (urled.indexOf('?') > -1) urled = urled + "&" + pairIt(d ?? {});
404
- else urled = urled + "?" + pairIt(d ?? {});
405
- }
406
- let resa = await fetch(urled, {
407
- method: m.toString().toLowerCase(),
408
- body: m.toString().toLowerCase() == 'get' ? null : JSON.stringify(d ?? {}),
409
- headers: h ?? config.apis[a ?? 0].headers,
410
- });
411
-
412
- if (f) return resa;
413
- let res = await resa.text();
414
- try {
415
- return JSON.parse(res);
416
- } catch (e) {
417
- return res;
418
- }
419
- },
420
- };
421
- exports.API = API;
422
-
423
- exports.processCommand = processCommands;
424
- exports.startServer = startServer;
425
- exports.create = create;
426
-
427
- function processCommands(cmd) {
428
- var command = cmd ? cmd : process.argv[2];
429
- if (command == "run" || command == "serve") {
430
- startServer();
431
- } else if (command == "create" || command == "update") {
432
- let c = process.argv.slice(3, process.argv.length);
433
- let t = lw(c[0]);
434
- create({
435
- type: t[0] == "-" ? t.split("-").join("") : t,
436
- name: t[0] == "-" ? c.slice(1, c.length) : c,
437
- });
438
- } else if (command == "purge") {
439
- import("ora").then(async ({ default: ora, oraPromise: oraPromise }) => {
440
- const spinner = ora({
441
- color: "green",
442
- });
443
- spinner.start("Purging..");
444
- API.get(BEA_Libs.BEAJS, {})
445
- .then((beajs) => {
446
- spinner.start("Gathering Resources..");
447
- API.get(BEA_Libs.BEACSS, {}).then((beacss) => {
448
- spinner.start("Writing Files...");
449
- var filePath = `${process.cwd()}`;
450
- var libsPath =
451
- `${__dirname}` + path.sep + `files` + path.sep + `libs`;
452
- cd(libsPath);
453
- fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs));
454
- fs.writeFileSync(libsPath + path.sep + "bea.css", String(beacss));
455
- fs.writeFileSync(
456
- filePath +
457
- path.sep +
458
- "src" +
459
- path.sep +
460
- "js" +
461
- path.sep +
462
- "bea.js",
463
- String(beajs)
464
- );
465
- fs.writeFileSync(
466
- filePath +
467
- path.sep +
468
- "src" +
469
- path.sep +
470
- "css" +
471
- path.sep +
472
- "bea.css",
473
- String(beacss)
474
- );
475
- spinner.succeed("Successfully Purged!");
476
- });
477
- })
478
- .catch((err) => {
479
- spinner.fail("Purge Failed!");
480
- });
481
- });
482
- } else if (command == "build") {
483
- let cmds = process.argv;
484
- _bp(cmds);
485
- } else if (command == "-v" || command == "-version") {
486
- console.log("LumenJS version " + require('../package.json').version);
487
- } else {
488
- console.log("LumenJS CLI's command not found!");
489
- }
490
- }
491
-
492
- async function _bp(cmds) {
493
- import("ora").then(async ({ default: ora, oraPromise: oraPromise }) => {
494
- const spinner = ora({
495
- color: "green",
496
- });
497
-
498
- spinner
499
- .succeed("Started Building Project For Production")
500
- .start("Gathering Required Resources..");
501
-
502
- var projectPath = `${process.cwd()}`;
503
- var dest = projectPath + path.sep + "dist";
504
-
505
- let _views = getAllFiles(
506
- `${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep,
507
- {},
508
- true
509
- );
510
- let _tpls = getAllFiles(
511
- `${process.cwd()}` + path.sep + `src` + path.sep + `tpls` + path.sep,
512
- {},
513
- true
514
- );
515
-
516
- var indexCode = fs.readFileSync(
517
- projectPath + path.sep + `src` + path.sep + "index.html",
518
- "utf8"
519
- );
520
-
521
- var beaCSSCode = fs.readFileSync(
522
- projectPath + path.sep + `src` + path.sep + "css" + path.sep + "bea.css",
523
- "utf8"
524
- );
525
- var indexJs = fs.readFileSync(
526
- projectPath + path.sep + `src` + path.sep + "index.js",
527
- "utf8"
528
- );
529
-
530
- let vt =
531
- `
532
- var _vcData = {
533
- "views": ` +
534
- JSON.stringify(_views) +
535
- `,
536
- "tpls": ` +
537
- JSON.stringify(_tpls) +
538
- `
539
- };
540
- `;
541
- vt += " " + String(indexJs);
542
- let f1 = await API.get("https://s.beacdn.com/beajs/f1", {});
543
-
544
- spinner
545
- .succeed("Gathering Required Resources")
546
- .start("Signing & Securing App..");
547
-
548
- let r = await API.post("https://www.beaapis.com/1/beajs", {
549
- data: {
550
- apis: JSON.stringify(config.apis),
551
- js: vt,
552
- },
553
- });
554
-
555
- let token_ = r.token;
556
- let js_ = "";
557
-
558
- var configData =
559
- `
560
- exports.config = ` +
561
- JSON.stringify(config) +
562
- `;
563
- `;
564
-
565
- if (cmds.indexOf("--serverless") >= 0) {
566
- js_ +=
567
- `
568
- var _beaTn = "` +
569
- token_ +
570
- `";
571
- `;
572
- }
573
- js_ += String(f1) + " " + r.js;
574
-
575
- if (token_ == "") {
576
- spinner.fail("Error getting a unique token for production!");
577
- spinner.fail("Build Failed! Try again later.");
578
- return;
579
- }
580
-
581
- spinner.succeed("Signing & Securing App").start("Packing & Cleaning...");
582
- rd(dest);
583
-
584
- spinner.succeed("Packing & Cleaning").start("Writing Files...");
585
- let buildPath = `build`;
586
- if (cmds.indexOf("--serverless") >= 0) {
587
- buildPath = `build_serverless`;
588
-
589
- copyDir(`${__dirname}` + path.sep + `files` + path.sep + buildPath, dest);
590
- copyDir(projectPath + path.sep + "src", dest, "_beajsBuild");
591
- cd(dest + path.sep + "js");
592
- cd(dest + path.sep + "css");
593
- cd(dest + path.sep + "images");
594
-
595
- copyDir(
596
- projectPath + path.sep + "src" + path.sep + "js",
597
- dest + path.sep + "js",
598
- "_beajsBuild"
599
- );
600
- copyDir(
601
- projectPath + path.sep + "src" + path.sep + "css",
602
- dest + path.sep + "css",
603
- "_beajsBuild"
604
- );
605
- copyDir(
606
- projectPath + path.sep + "src" + path.sep + "images",
607
- dest + path.sep + "images",
608
- "_beajsBuild"
609
- );
610
-
611
- fs.writeFileSync(
612
- dest + path.sep + "js" + path.sep + "bea.js",
613
- String(js_)
614
- );
615
- fs.writeFileSync(
616
- dest + path.sep + "css" + path.sep + "bea.css",
617
- String(beaCSSCode)
618
- );
619
-
620
- let _dT = new Date().getTime();
621
- fs.renameSync(
622
- dest + path.sep + "js" + path.sep + "bea.js",
623
- dest + path.sep + "js" + path.sep + "app." + _dT + ".js"
624
- );
625
- fs.renameSync(
626
- dest + path.sep + "css" + path.sep + "bea.css",
627
- dest + path.sep + "css" + path.sep + "app." + _dT + ".css"
628
- );
629
- fs.renameSync(
630
- dest + path.sep + "css" + path.sep + "styles.css",
631
- dest + path.sep + "css" + path.sep + "styles." + _dT + ".css"
632
- );
633
-
634
- fs.writeFileSync(
635
- dest + path.sep + "index.html",
636
- String(indexCode)
637
- .split('<script src="/index.js" type="text/javascript"></script>')
638
- .join("")
639
- .split("/js/bea.js")
640
- .join("/js/app." + _dT + ".js")
641
- .split("/css/styles.css")
642
- .join("/css/styles." + _dT + ".css")
643
- .split("/css/bea.css")
644
- .join("/css/app." + _dT + ".css")
645
- );
646
- } else {
647
- copyDir(`${__dirname}` + path.sep + `files` + path.sep + buildPath, dest);
648
- copyDir(
649
- projectPath + path.sep + "src",
650
- dest + path.sep + "src",
651
- "_beajsBuild"
652
- );
653
- cd(dest + path.sep + "src" + path.sep + "js");
654
- cd(dest + path.sep + "src" + path.sep + "css");
655
- cd(dest + path.sep + "src" + path.sep + "images");
656
-
657
- let appFile = projectPath + path.sep + `src` + path.sep + "app.js";
658
- if (fs.existsSync(appFile)) {
659
- var appCode = fs.readFileSync(appFile, "utf8");
660
- var serverJsCode = fs.readFileSync(
661
- `${__dirname}` +
662
- path.sep +
663
- `files` +
664
- path.sep +
665
- buildPath +
666
- path.sep +
667
- "server.js",
668
- "utf8"
669
- );
670
- fs.writeFileSync(
671
- dest + path.sep + "server.js",
672
- String(serverJsCode).split("//APP_HOLDER").join(appCode)
673
- );
674
- fs.unlinkSync(dest + path.sep + "src" + path.sep + "app.js");
675
- }
676
-
677
- copyDir(
678
- projectPath + path.sep + "src" + path.sep + "js",
679
- dest + path.sep + "src" + path.sep + "js",
680
- "_beajsBuild"
681
- );
682
- copyDir(
683
- projectPath + path.sep + "src" + path.sep + "css",
684
- dest + path.sep + "src" + path.sep + "css",
685
- "_beajsBuild"
686
- );
687
- copyDir(
688
- projectPath + path.sep + "src" + path.sep + "images",
689
- dest + path.sep + "src" + path.sep + "images",
690
- "_beajsBuild"
691
- );
692
-
693
- fs.writeFileSync(
694
- dest + path.sep + "src" + path.sep + "js" + path.sep + "bea.js",
695
- String(js_)
696
- );
697
- fs.writeFileSync(
698
- dest + path.sep + "src" + path.sep + "css" + path.sep + "bea.css",
699
- String(beaCSSCode)
700
- );
701
-
702
-
703
- let _dT = new Date().getTime();
704
- fs.renameSync(
705
- dest + path.sep + "src" + path.sep + "js" + path.sep + "bea.js",
706
- dest + path.sep + "src" + path.sep + "js" + path.sep + "app." + _dT + ".js"
707
- );
708
- fs.renameSync(
709
- dest + path.sep + "src" + path.sep + "css" + path.sep + "bea.css",
710
- dest + path.sep + "src" + path.sep + "css" + path.sep + "app." + _dT + ".css"
711
- );
712
- fs.renameSync(
713
- dest + path.sep + "src" + path.sep + "css" + path.sep + "styles.css",
714
- dest + path.sep + "src" + path.sep + "css" + path.sep + "styles." + _dT + ".css"
715
- );
716
-
717
- fs.writeFileSync(
718
- dest + path.sep + "src" + path.sep + "index.html",
719
- String(indexCode)
720
- .split('<script src="/index.js" type="text/javascript"></script>')
721
- .join("")
722
- .split("/js/bea.js")
723
- .join("/js/app." + _dT + ".js")
724
- .split("/css/styles.css")
725
- .join("/css/styles." + _dT + ".css")
726
- .split("/css/bea.css")
727
- .join("/css/app." + _dT + ".css")
728
- );
729
-
730
- fs.writeFileSync(dest + path.sep + "config.js", String(configData));
731
- }
732
-
733
- if (cmds.indexOf("--deploy") >= 0) {
734
- spinner.succeed("Writing Files").start("Uploading To Server..");
735
- const _config = {
736
- user: config.ftp.username,
737
- // Password optional, prompted if none given
738
- password: config.ftp.password,
739
- host: config.ftp.host,
740
- port: config.ftp.port,
741
- localRoot: dest,
742
- remoteRoot: config.ftp.remotePath,
743
- include: ["*", "**/*", ".*"], // this would upload everything except dot files
744
- // include: ["*.js", "dist/*", ".*"],
745
- // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
746
- exclude: config.ftp.ignore,
747
- // delete ALL existing files at destination before uploading, if true
748
- deleteRemote: false,
749
- // Passive mode is forced (EPSV command is not sent)
750
- forcePasv: true,
751
- // use sftp or ftp
752
- sftp: config.ftp.protocol == 'sftp' ? true : false,
753
- };
754
- // console.log(_config);
755
-
756
- _fD.deploy(_config, function (err, res) {
757
- if (err) {
758
- console.log(err);
759
- } else {
760
- spinner.succeed("Finished Uploading To Server");
761
- spinner.succeed("Done");
762
- }
763
- });
764
- _fD.on("uploading", function (data) {
765
- spinner.start(
766
- parseFloat(
767
- ((data.transferredFileCount * 100) / data.totalFilesCount).toFixed(
768
- 2
769
- )
770
- ) +
771
- "% " +
772
- "Uploading " +
773
- data.filename +
774
- " "
775
- );
776
- });
777
- // _fD.on("uploaded", function (data) {
778
- // console.log(data); // same data as uploading event
779
- // });
780
- // _fD.on("log", function (data) {
781
- // console.log(data); // same data as uploading event
782
- // });
783
- // _fD.on("upload-error", function (data) {
784
- // console.log(data.err); // data will also include filename, relativePath, and other goodies
785
- // });
786
- } else spinner.succeed("Writing Files").succeed("Done");
787
- });
788
- }
789
-
790
- function clear(isSoft) {
791
- process.stdout.write(isSoft ? "\x1B[H\x1B[2J" : "\x1B[2J\x1B[3J\x1B[H\x1Bc");
792
- }
793
-
794
- function startServer() {
795
- clear();
796
- nodemon({
797
- script: path.join(__dirname.toString(), "app.js"),
798
- ext: "view,js,css,json,tpl,html",
799
- watch: ["src/", "config.json"],
800
- });
801
- nodemon.on("restart", (files) => {
802
- console.log(files);
803
- });
804
- }