@lmjs/cli 1.0.31 → 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,6 +1,12 @@
1
1
  const axios = require("axios").default;
2
2
  const path = require("path");
3
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();
4
10
 
5
11
  const BEA_Libs = {
6
12
  BEACSS: "https://s.beacdn.com/beacss/latest",
@@ -10,41 +16,8 @@ const BEA_Libs = {
10
16
  exports.getAllFiles = getAllFiles;
11
17
  exports.ucwords = ucwords;
12
18
 
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(" var ", " ;var ");
18
- // st[key] = st[key].replace(" let ", " ;let ");
19
- // st[key] = st[key].replace(" const ", " ;const ");
20
- st[key] = st[key].replace(/(\t)/g, "");
21
- st[key] = st[key].replace(/\s\s+/g, " ");
22
- }
23
- return st;
24
- }
25
-
26
- function getAllFiles(dirPath, 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);
45
- }
46
-
47
- exports.getConfig = function () {
19
+ exports.getConfig = getConfig;
20
+ function getConfig() {
48
21
  config = {
49
22
  version: "1.0.0.1",
50
23
  server: {
@@ -88,7 +61,9 @@ exports.getConfig = function () {
88
61
  config = JSON.parse(fs.readFileSync(configPath, { encoding: "utf8" }));
89
62
  }
90
63
  return config;
91
- };
64
+ }
65
+
66
+ var config = getConfig();
92
67
 
93
68
  function ucwords(str) {
94
69
  return (str + "").replace(/^([a-z])|\s+([a-z])/g, function ($1) {
@@ -110,7 +85,7 @@ function rd(d) {
110
85
  }
111
86
  exports.rd = rd;
112
87
 
113
- exports.create = function (conf) {
88
+ function create(conf) {
114
89
  let t =
115
90
  conf.type == "v" || conf.type == "s" || conf.type == "c" ? conf.type : "p";
116
91
  let n =
@@ -260,7 +235,74 @@ exports.create = function (conf) {
260
235
  fs.writeFileSync(filePath, html5);
261
236
  }
262
237
  }
263
- };
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
+ }
264
306
 
265
307
  function copyDir(src, dest, projectName) {
266
308
  try {
@@ -359,3 +401,337 @@ var API = {
359
401
  },
360
402
  };
361
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.31",
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",
@@ -37,7 +35,7 @@
37
35
  "lumen bea"
38
36
  ],
39
37
  "dependencies": {
40
- "@lmjs/core": "^1.0.3"
38
+ "@lmjs/core": "^1.0.5"
41
39
  },
42
40
  "engines": {
43
41
  "node": ">=12.0.0"
@@ -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,398 +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
- var UglifyJS = require("uglify-js");
10
-
11
- exports.processCommand = processCommands;
12
- exports.startServer = startServer;
13
-
14
- const BEA_Libs = {
15
- BEACSS: "https://s.beacdn.com/beacss/latest",
16
- BEAJS: "https://s.beacdn.com/beajs/latest",
17
- };
18
-
19
- function processCommands(cmd) {
20
- var command = cmd ? cmd : process.argv[2];
21
- if (command == "run" || command == "serve") {
22
- startServer();
23
- } else if (command == "create" || command == "update") {
24
- let c = process.argv.slice(3, process.argv.length);
25
- let t = fcs.lw(c[0]);
26
- fcs.create({
27
- type: t[0] == "-" ? t.split("-").join("") : t,
28
- name: t[0] == "-" ? c.slice(1, c.length) : c,
29
- });
30
- } else if (command == "purge") {
31
- axios
32
- .get(BEA_Libs.BEAJS, {})
33
- .then((beajs) => {
34
- axios.get(BEA_Libs.BEACSS, {}).then((beacss) => {
35
- var filePath = `${process.cwd()}` + path.sep;
36
- let stylesFile =
37
- filePath +
38
- path.sep +
39
- "src" +
40
- path.sep +
41
- "css" +
42
- path.sep +
43
- `bea.css`;
44
- var libsPath =
45
- `${__dirname}` +
46
- path.sep +
47
- `lib` +
48
- path.sep +
49
- `files` +
50
- path.sep +
51
- `libs`;
52
- fcs.cd(libsPath);
53
- fs.writeFileSync(libsPath + path.sep + "bea.js", String(beajs.data));
54
- fs.writeFileSync(
55
- libsPath + path.sep + "bea.css",
56
- String(beacss.data)
57
- );
58
- if (fs.existsSync(stylesFile)) {
59
- fs.writeFileSync(
60
- filePath +
61
- path.sep +
62
- "src" +
63
- path.sep +
64
- "js" +
65
- path.sep +
66
- "bea.js",
67
- String(beajs.data)
68
- );
69
- fs.writeFileSync(
70
- filePath +
71
- path.sep +
72
- "src" +
73
- path.sep +
74
- "css" +
75
- path.sep +
76
- "bea.css",
77
- String(beacss.data)
78
- );
79
- }
80
- console.log("Successfully Purged!");
81
- });
82
- })
83
- .catch((err) => {
84
- console.log("Purge Failed!");
85
- });
86
- } else if (command == "build") {
87
- let cmds = process.argv;
88
- buildProject(cmds);
89
- } else {
90
- console.log("LumenJS CLI's command not found!");
91
- }
92
- }
93
-
94
- var API = fcs.API;
95
-
96
- async function buildProject(cmds) {
97
- import("ora").then(async ({ default: ora, oraPromise: oraPromise }) => {
98
- const spinner = ora({
99
- text: "Started Building Project For Production..",
100
- color: "green",
101
- });
102
-
103
- spinner
104
- .succeed("Started Building Project For Production")
105
- .start("Gathering Required Resources..");
106
-
107
- var projectPath = `${process.cwd()}`;
108
- var dest = projectPath + path.sep + "dist";
109
-
110
- let _views = fcs.getAllFiles(
111
- `${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep
112
- );
113
- let _tpls = fcs.getAllFiles(
114
- `${process.cwd()}` + path.sep + `src` + path.sep + `tpls` + path.sep
115
- );
116
- var config = fcs.getConfig();
117
-
118
- var indexCode = fs.readFileSync(
119
- projectPath + path.sep + `src` + path.sep + "index.html",
120
- "utf8"
121
- );
122
-
123
- var beaCSSCode = fs.readFileSync(
124
- projectPath + path.sep + `src` + path.sep + "css" + path.sep + "bea.css",
125
- "utf8"
126
- );
127
- var indexJs = fs.readFileSync(
128
- projectPath + path.sep + `src` + path.sep + "index.js",
129
- "utf8"
130
- );
131
-
132
- let vt =
133
- `
134
- var _vcData = {
135
- "views": ` +
136
- JSON.stringify(_views) +
137
- `,
138
- "tpls": ` +
139
- JSON.stringify(_tpls) +
140
- `
141
- };
142
- `;
143
- vt += " " + String(indexJs);
144
- let f1 = await axios.get("https://s.beacdn.com/beajs/f1", {});
145
-
146
- spinner
147
- .succeed("Gathering Required Resources")
148
- .start("Signing & Securing App..");
149
-
150
- let r = await API.post("https://www.beaapis.com/1/beajs", {
151
- data: {
152
- apis: JSON.stringify(config.apis),
153
- js: vt,
154
- },
155
- });
156
-
157
- let token_ = r.token;
158
- let js_ = "";
159
-
160
- var js2 =
161
- `
162
- exports.config = ` +
163
- JSON.stringify(config) +
164
- `;
165
- `;
166
- let configData = UglifyJS.minify(js2, {
167
- mangle: {
168
- reserved: ["_vcdata", "_ws"],
169
- },
170
- output: {
171
- beautify: true,
172
- },
173
- });
174
-
175
- if (cmds.indexOf("--serverless") >= 0) {
176
- js_ +=
177
- `
178
- var _beaTn = "` +
179
- token_ +
180
- `";
181
- `;
182
- }
183
- js_ += String(f1.data) + " " + r.js;
184
-
185
- let js__ = UglifyJS.minify(js_, {
186
- mangle: {
187
- toplevel: true,
188
- reserved: ["_vcdata", "_ws"],
189
- },
190
- });
191
-
192
- if (token_ == "") {
193
- spinner.fail("Error getting a unique token for production!");
194
- spinner.fail("Build Failed! Try again later.");
195
- return;
196
- }
197
-
198
- spinner.succeed("Signing & Securing App").start("Packing & Cleaning...");
199
- fcs.rd(dest);
200
-
201
- spinner.succeed("Packing & Cleaning").start("Writing Files...");
202
- let buildPath = `build`;
203
- if (cmds.indexOf("--serverless") >= 0) {
204
- buildPath = `build_serverless`;
205
-
206
- fcs.copyDir(
207
- `${__dirname}` +
208
- path.sep +
209
- `lib` +
210
- path.sep +
211
- `files` +
212
- path.sep +
213
- buildPath,
214
- dest
215
- );
216
- fcs.copyDir(projectPath + path.sep + "src", dest, "_beajsBuild");
217
- fcs.cd(dest + path.sep + "js");
218
- fcs.cd(dest + path.sep + "css");
219
- fcs.cd(dest + path.sep + "images");
220
-
221
- fcs.copyDir(
222
- projectPath + path.sep + "src" + path.sep + "js",
223
- dest + path.sep + "js",
224
- "_beajsBuild"
225
- );
226
- fcs.copyDir(
227
- projectPath + path.sep + "src" + path.sep + "css",
228
- dest + path.sep + "css",
229
- "_beajsBuild"
230
- );
231
- fcs.copyDir(
232
- projectPath + path.sep + "src" + path.sep + "images",
233
- dest + path.sep + "images",
234
- "_beajsBuild"
235
- );
236
-
237
- fs.writeFileSync(
238
- dest + path.sep + "js" + path.sep + "bea.js",
239
- String(js__.code)
240
- );
241
- fs.writeFileSync(
242
- dest + path.sep + "css" + path.sep + "bea.css",
243
- String(beaCSSCode)
244
- );
245
- fs.writeFileSync(
246
- dest + path.sep + "index.html",
247
- String(indexCode)
248
- .split('<script src="/index.js" type="text/javascript"></script>')
249
- .join("")
250
- .split("/js/bea.js")
251
- .join("/js/bea.js?v" + new Date().getTime())
252
- .split("/css/styles.css")
253
- .join("/css/styles.css?v" + new Date().getTime())
254
- .split("/css/bea.css")
255
- .join("/css/bea.css?v" + new Date().getTime())
256
- );
257
- } else {
258
- fcs.copyDir(
259
- `${__dirname}` +
260
- path.sep +
261
- `lib` +
262
- path.sep +
263
- `files` +
264
- path.sep +
265
- buildPath,
266
- dest
267
- );
268
- fcs.copyDir(
269
- projectPath + path.sep + "src",
270
- dest + path.sep + "src",
271
- "_beajsBuild"
272
- );
273
- fcs.cd(dest + path.sep + "src" + path.sep + "js");
274
- fcs.cd(dest + path.sep + "src" + path.sep + "css");
275
- fcs.cd(dest + path.sep + "src" + path.sep + "images");
276
-
277
- let appFile = projectPath + path.sep + `src` + path.sep + "app.js";
278
- if (fs.existsSync(appFile)) {
279
- var appCode = fs.readFileSync(appFile, "utf8");
280
- var serverJsCode = fs.readFileSync(
281
- `${__dirname}` +
282
- path.sep +
283
- `lib` +
284
- path.sep +
285
- `files` +
286
- path.sep +
287
- buildPath +
288
- path.sep +
289
- "server.js",
290
- "utf8"
291
- );
292
- fs.writeFileSync(
293
- dest + path.sep + "server.js",
294
- String(serverJsCode).split("//APP_HOLDER").join(appCode)
295
- );
296
- fs.unlinkSync(dest + path.sep + "src" + path.sep + "app.js");
297
- }
298
-
299
- fcs.copyDir(
300
- projectPath + path.sep + "src" + path.sep + "js",
301
- dest + path.sep + "src" + path.sep + "js",
302
- "_beajsBuild"
303
- );
304
- fcs.copyDir(
305
- projectPath + path.sep + "src" + path.sep + "css",
306
- dest + path.sep + "src" + path.sep + "css",
307
- "_beajsBuild"
308
- );
309
- fcs.copyDir(
310
- projectPath + path.sep + "src" + path.sep + "images",
311
- dest + path.sep + "src" + path.sep + "images",
312
- "_beajsBuild"
313
- );
314
-
315
- fs.writeFileSync(
316
- dest + path.sep + "src" + path.sep + "js" + path.sep + "bea.js",
317
- String(String(js__.code))
318
- );
319
- fs.writeFileSync(
320
- dest + path.sep + "src" + path.sep + "css" + path.sep + "bea.css",
321
- String(beaCSSCode)
322
- );
323
- fs.writeFileSync(
324
- dest + path.sep + "src" + path.sep + "index.html",
325
- String(indexCode)
326
- .split('<script src="/index.js" type="text/javascript"></script>')
327
- .join("")
328
- );
329
- fs.writeFileSync(dest + path.sep + "config.js", String(configData.code));
330
- }
331
-
332
- if (cmds.indexOf("--deploy") >= 0) {
333
- spinner.succeed("Writing Files").start("Uploading To Server..");
334
- const _config = {
335
- user: config.ftp.username,
336
- // Password optional, prompted if none given
337
- password: config.ftp.password,
338
- host: config.ftp.host,
339
- port: config.ftp.port,
340
- localRoot: dest,
341
- remoteRoot: config.ftp.remotePath,
342
- include: ["*", "**/*", ".*"], // this would upload everything except dot files
343
- // include: ["*.js", "dist/*", ".*"],
344
- // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
345
- exclude: config.ftp.ignore,
346
- // delete ALL existing files at destination before uploading, if true
347
- deleteRemote: false,
348
- // Passive mode is forced (EPSV command is not sent)
349
- forcePasv: true,
350
- // use sftp or ftp
351
- sftp: false,
352
- };
353
- // console.log(_config);
354
-
355
- ftpDeploy.deploy(_config, function (err, res) {
356
- if (err) {
357
- console.log(err);
358
- } else {
359
- spinner.succeed("Finished Uploading To Server");
360
- spinner.succeed("Done");
361
- }
362
- });
363
- ftpDeploy.on("uploading", function (data) {
364
- spinner.start(
365
- parseFloat(
366
- ((data.transferredFileCount * 100) / data.totalFilesCount).toFixed(
367
- 2
368
- )
369
- ) +
370
- "% " +
371
- "Uploading " +
372
- data.filename +
373
- " "
374
- );
375
- });
376
- // ftpDeploy.on("uploaded", function (data) {
377
- // console.log(data); // same data as uploading event
378
- // });
379
- // ftpDeploy.on("log", function (data) {
380
- // console.log(data); // same data as uploading event
381
- // });
382
- // ftpDeploy.on("upload-error", function (data) {
383
- // console.log(data.err); // data will also include filename, relativePath, and other goodies
384
- // });
385
- } else spinner.succeed("Writing Files").succeed("Done");
386
- });
387
- }
388
-
389
- function startServer() {
390
- nodemon({
391
- script: path.join(__dirname.toString(), "lib", "app.js"),
392
- ext: "view,js,css,json,tpl,html",
393
- watch: ["src/", "config.json"],
394
- });
395
- nodemon.on("restart", (files) => {
396
- console.log(files);
397
- });
398
- }