Skip to content

Commit 25b4fa2

Browse files
committed
2.2.0
2 parents 53ae672 + 36e35e5 commit 25b4fa2

File tree

11 files changed

+98
-50
lines changed

11 files changed

+98
-50
lines changed

build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require('de-builder')({
1+
require("de-builder")({
22
forever:{
33
enabled: false
44
},
55
type: 2
6-
});
6+
});

build/exit/index.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ Exit = class Exit {
1414
}
1515

1616
listeners() {
17-
this.readInput();
1817
process.on("exit", this.exit);
1918
process.on("SIGINT", this.sigint);
2019
process.on("SIGTERM", this.sigterm);
2120
process.on("command", this.command);
2221
return process.on("uncaughtException", this.uncaughtException);
2322
}
2423

25-
readInput() {
26-
// Set encoding
27-
process.stdin.setEncoding("utf8");
28-
// Listen for terminal user input (leaves the process running too)
29-
return process.stdin.on("data", function(command) {
30-
// Send terminal command through the application - Remove the \n from the command
31-
return process.emit("command", command.slice(0, -1));
32-
});
33-
}
34-
3524
exit(code) {
3625
this.server.vent.emit("terminate:child");
3726
return log.info(this.server.config.title, "Exit:", code);

build/server/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Server = class Server {
2626
this.config.fullTitle = "Live Development Environment";
2727
// Set title of the process
2828
process.title = this.pkg.name;
29-
// Determin application environment
30-
this.env = process.argv[2] === "-prod" ? "production" : "development";
29+
// Check all provided arguments
30+
this.argv();
3131
// Set the value of debug messages logged
3232
log.set({
3333
debug: {
@@ -65,6 +65,32 @@ Server = class Server {
6565
};
6666
}
6767

68+
argv() {
69+
var arg, i, len, ref, run;
70+
// Default values
71+
this.env = "development";
72+
this.run = true;
73+
ref = process.argv;
74+
for (i = 0, len = ref.length; i < len; i++) {
75+
arg = ref[i];
76+
if (arg[0] !== "-") {
77+
continue;
78+
}
79+
if (arg === "-prod") {
80+
this.env = "production";
81+
this.run = false;
82+
continue;
83+
}
84+
if (arg === "-run") {
85+
run = true;
86+
}
87+
}
88+
if (run) {
89+
// Ensure the order of -prod and -run does not matter
90+
return this.run = true;
91+
}
92+
}
93+
6894
};
6995

7096
module.exports = Server;

build/tasks/forever.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Forever = class Forever {
5555

5656
start() {
5757
var entry, src;
58+
// Prevent running the script so the process can close when finished
59+
if (!this.server.run) {
60+
return;
61+
}
5862
// Determin the src directory
5963
src = this.server.folders.build.server;
6064
if (this.server.config.type === 2) {

build/tasks/watch.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ Watch = class Watch {
3838
// Start watch
3939
log.info(`${this.server.config.title} - Watch`, "~ Night gathers, and now my watch begins ~");
4040
// Start the chokidar the file wachter
41-
return chokidar.watch(this.server.config.src, {
41+
this.watcher = chokidar.watch(this.server.config.src, {
4242
ignored: /[\/\\]\./
43-
}).on("add", this.add).on("change", this.change).on("unlink", this.unlink).on("ready", this.ready);
43+
});
44+
return this.watcher.on("add", this.add).on("change", this.change).on("unlink", this.unlink).on("ready", this.ready);
4445
}
4546

4647
add(file) {
@@ -88,12 +89,20 @@ Watch = class Watch {
8889
return fs.unlink(this.server.root + path.sep + remove, function(e) {});
8990
}
9091

91-
ready() {
92+
async ready() {
9293
this.init = true;
9394
// Notify
9495
log.info(`${this.server.config.title} - Watch`, `Ready: ${this.count.first} files initially added`);
9596
// Watch has found all files
96-
return this.server.vent.emit("watch:init");
97+
this.server.vent.emit("watch:init");
98+
// When NOT running do no conitnue watching for file changes either
99+
if (this.server.run) {
100+
return;
101+
}
102+
// Close all file watching
103+
await this.watcher.close();
104+
// Notify
105+
return log.info(`${this.server.config.title} - Watch`, "And Now My Watch Is Ended");
97106
}
98107

99108
increase(count) {

install.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
// --------------------------------------------------
44
"use strict"
55

6-
var fs = require('fs');
7-
var log = require('de-logger');
8-
var path = require('path');
9-
var config = require('de-builder/build/server/config');
6+
var fs = require("fs");
7+
var log = require("de-logger");
8+
var path = require("path");
9+
var config = require(["de-builder","build","server","config"].join(path.sep));
1010

1111
// File content
12-
var file = "require('de-builder')("+JSON.stringify(config, null, '\t')+");";
12+
var file = "require(\"de-builder\")("+JSON.stringify(config, null, "\t")+");";
1313

1414
// File name
1515
var name = "build.js";
1616

1717
// File location
18-
var location = path.resolve('../../'+name);
18+
var location = path.resolve(["..","..",name].join(path.sep));
1919

2020
fs.exists(location, function(exists) {
2121

22-
// Only create file if it doesn't exists yet
23-
if (exists) { return log.info('LDE - Install', 'build.js file already exists'); }
22+
// Only create file if it does not exists yet
23+
if (exists) { return log.info("LDE - Install", "build.js file already exists"); }
2424

2525
// Create build.js file
2626
fs.writeFile(location, file, function (err) {
2727
if (!err) { return; }
28-
log.warn('LDE - Install', 'Couldn\'t create build.js file');
29-
log.error('LDE - Install', err);
28+
log.error("LDE - Install", "Couldn\"t create build.js file");
29+
log.error("LDE - Install", err);
3030
});
31-
});
31+
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "de-builder",
3-
"version": "2.1.6",
3+
"version": "2.2.0",
44
"description": "A Live Development Environment",
55
"main": "build/app.js",
66
"author": "Dexter Esajas <dexter@dexterous-solutions.io>",
@@ -20,7 +20,7 @@
2020
"socket.io-client": "^4.5.3"
2121
},
2222
"devDependencies": {
23-
"de-builder": "^2.1.5"
23+
"de-builder": "^2.1.6"
2424
},
2525
"repository": {
2626
"type": "git",

src/exit/index.coffee

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,13 @@ class Exit
1212

1313
listeners: ->
1414

15-
@readInput()
16-
1715
process.on "exit", @exit
1816
process.on "SIGINT", @sigint
1917
process.on "SIGTERM", @sigterm
2018
process.on "command", @command
2119
process.on "uncaughtException", @uncaughtException
2220

2321

24-
readInput: ->
25-
26-
# Set encoding
27-
process.stdin.setEncoding "utf8"
28-
29-
# Listen for terminal user input (leaves the process running too)
30-
process.stdin.on "data", (command) ->
31-
32-
# Send terminal command through the application - Remove the \n from the command
33-
process.emit "command", command.slice 0, -1
34-
35-
3622
exit: (code) =>
3723

3824
@server.vent.emit "terminate:child"

src/server/index.coffee

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class Server
2929
# Set title of the process
3030
process.title = @pkg.name
3131

32-
# Determin application environment
33-
@env = if process.argv[2] is "-prod" then "production" else "development"
32+
# Check all provided arguments
33+
@argv()
3434

3535
# Set the value of debug messages logged
3636
log.set debug: display: @config.debug
@@ -72,5 +72,26 @@ class Server
7272
@config.build+path.sep+seperated.join path.sep
7373

7474

75+
argv: ->
76+
77+
# Default values
78+
@env = "development"
79+
@run = true
80+
81+
for arg in process.argv
82+
83+
continue if arg[0] isnt "-"
84+
85+
if arg is "-prod"
86+
@env = "production"
87+
@run = false
88+
continue
89+
90+
run = true if arg is "-run"
91+
92+
# Ensure the order of -prod and -run does not matter
93+
@run = true if run
94+
95+
7596

7697
module.exports = Server

src/tasks/forever.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class Forever
5050

5151
start: ->
5252

53+
# Prevent running the script so the process can close when finished
54+
return if not @server.run
55+
5356
# Determin the src directory
5457
src = @server.folders.build.server
5558
src = @server.folders.build.index if @server.config.type is 2

0 commit comments

Comments
 (0)