@lmjs/cli 1.0.32 → 1.0.33

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