Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mekwall committed Jan 2, 2013
0 parents commit d06261e
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
@@ -0,0 +1,13 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
7 changes: 7 additions & 0 deletions .npmignore
@@ -0,0 +1,7 @@
.git*
docs/
examples/
support/
test/
testing.js
.DS_Store
9 changes: 9 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,9 @@
Copyright (c) 2010-2012 Marcus Ekwall

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
@@ -0,0 +1,3 @@
# express-assets

More info coming soon.
62 changes: 62 additions & 0 deletions bin/overseer
@@ -0,0 +1,62 @@
#!/usr/bin/env node

// windows: running "overseer blah" in this folder will invoke WSH, not node.
if (typeof WScript !== "undefined") {
WScript.echo("overseer does not work when run\n"
+"with the Windows Scripting Host\n\n"
+"'cd' to a different directory,\n"
+"or type 'overseer.cmd <args>',\n"
+"or type 'node overseer <args>'.");
WScript.quit(1);
return
}

process.title = "overseer";

// Module deps
const exec = require('child_process').exec;
const program = require('commander');
const pkg = require('../package.json');
const version = pkg.version;
const os = require('os');
const fs = require('fs');
const path = require('path');
const overseer = require('../src/overseer');

// CLI
program
.version(version)
.usage('[options] <file>')
.option('-w, --watch', 'watch for file system changes')
.option('-f, --forks <n>', 'amount of workers to fork')
.option('-P, --port <port>', 'port to listen to')
.option('-H, --hostname <hostname>', 'hostname to listen to')
.option('-E, --env <environment>', 'set environment')
.option('--pidfile <file>', 'pidfile to use')
.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ overseer -w -P 61337 -H localhost -f 4 app.js');
console.log('');
})
.parse(process.argv);

const ENV = program.env || (process.env["NODE_ENV"] || "development");
const PORT = program.port || (process.env["PORT"] || 3000);
const HOST = program.hostname || (process.env["HOSTNAME"] || "0.0.0.0");

// Path
var appFile = program.args.shift();

if (!appFile) {
console.error("Error: Missing file argument. -h for help");
process.exit(0);
}

appFile = path.resolve(appFile);
if (!fs.existsSync(appFile)) {
console.error("Error: %s could not be found.", appFile);
process.exit(0);
}

console.log(appfile);
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
module.exports = require("./src/overseer");
38 changes: 38 additions & 0 deletions package.json
@@ -0,0 +1,38 @@
{
"name": "overseer",
"description": "",
"version": "0.1.0",
"authors": [
{
"name": "Marcus Ekwall",
"email": "marcus.ekwall@gmail.com",
"web": "http://www.writeless.se"
}
],
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/mit-license.php"
}
],
"bugs": {
"url": "git://github.com/mekwall/overseer/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/mekwall/overseer.git"
},
"engines": {
"node": "~0.8.16"
},
"main": "index",
"bin": {
"overseer": "./bin/overseer"
},
"dependencies": {
"cli-color": "~0.2.1",
"keypress": "~0.1.0",
"commander": "~1.1.1",
"watch": "~0.5.1"
}
}
105 changes: 105 additions & 0 deletions src/logger.js
@@ -0,0 +1,105 @@
const clr = require("cli-color");

var logger = {};

logger.timestamp = function(ret) {
var date = (new Date);
var seconds = ""+date.getSeconds();
var minutes = ""+date.getMinutes();
var hours = ""+date.getHours();

if (hours.length === 1) {
hours = "0" + hours;
}

if (minutes.length === 1) {
minutes = "0" + minutes;
}

if (seconds.length === 1) {
seconds = "0" + seconds;
}

if (ret) {
return { hours: hours, minutes: minutes, seconds: seconds };
} else {
process.stdout.write(" "+hours+":"+minutes+" ");
}
}

logger.log = function () {
this.timestamp();
process.stdout.write(clc.white(" log "));
if (this._org && this._org.log) {
this._org.log.apply(this, arguments);
} else {
console.log.apply(console, arguments);
}
};

logger.error = function () {
this.timestamp();
process.stdout.write(clc.red.bold(" error "));
orgcon.error.apply(this, arguments);
if (this._org && this._org.error) {
this._org.error.apply(this, arguments);
} else {
console.error.apply(console, arguments);
}
};

logger.info = function () {
if (ENV !== "development") return;
this.timestamp();
process.stdout.write(clc.cyan(" info "));
if (this._org && this._org.warn) {
this._org.info.apply(this, arguments);
} else {
console.info.apply(console, arguments);
}
};

logger.warn = function () {
this.timestamp();
process.stdout.write(clc.yellow(" warn "));
if (this._org && this._org.warn) {
this._org.warn.apply(this, arguments);
} else {
console.warn.apply(console, arguments);
}
};

logger.debug = function () {
if (ENV !== "development") return;
this.timestamp();
process.stdout.write(clc.yellow.bold(" debug "));
if (this._org && this._org.log) {
this._org.log.apply(this, arguments);
} else {
console.log.apply(console, arguments);
}
};

module.exports = function (org) {
if (org) {
org._org = {
log: org.log,
error: org.error,
info: org.info,
warn: org.warn
};
org._restore = function () {
for (var fn in org._org) {
org[fn] = org._org[f];
}
delete org._org;
delete org._restore;
}

for (var fn in logger) {
org[fn] = logger[fn];
}
return org;
}
return logger;
}
40 changes: 40 additions & 0 deletions src/overseer.js
@@ -0,0 +1,40 @@
// Module dependencies
const pkg = require("../package.json");
const cluster = require("cluster");

// Replace console
console = require("./logger")(console);

// Make sure this is the master
if (!cluster.isMaster) {
console.log("overseer can only be run as master");
process.exit(0);
}

var overseer = {};

overseer.run = function() {
process.stdout.write(banner);
};

// Cool ascii art banner
var banner = "\n"+
" _____ _____ _ __ ___ ___ ___ _ __ \n"+
" / _ \\ \\ / / _ \\ '__/ __|/ _ \\/ _ \\ '__|\n"+
"| (_) \\ V / __/ | \\__ \\ __/ __/ | \n"+
" \\___/ \\_/ \\___|_| |___/\\___|\\___|_| \n"+
" \n";

module.exports = function () {
if (arguments.length) {
if (typeof arguments[0] === "object") {
var options = arguments[0];
} else if (typeof arguments[0] === "string") {
var file = arguments[1];
if (arguments[1] && typeof arguments[1] === "object") {

}
}
}
overseer;
};

0 comments on commit d06261e

Please sign in to comment.