forked from seajs/seajs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d23850
commit bb6332f
Showing
2 changed files
with
33 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var print = require('util').print; | ||
var spawn = require('child_process').spawn; | ||
var static = require('node-static'); | ||
|
||
var fs = require('fs') | ||
var http = require('http') | ||
var print = require('util').print | ||
var spawn = require('child_process').spawn | ||
var Static = require('node-static') | ||
|
||
|
||
function createServer(dir, cmd) { | ||
dir = dir || '.'; | ||
dir = dir || '.' | ||
|
||
// Server Start | ||
var file = new static.Server(fs.realpathSync(dir)); | ||
var file = new Static.Server(fs.realpathSync(dir)) | ||
|
||
var server = http.createServer(function(request, response) { | ||
request.addListener('end', function() { | ||
file.serve(request, response); | ||
}).resume(); | ||
}); | ||
request.addListener('end',function() { | ||
file.serve(request, response) | ||
}).resume() | ||
}) | ||
|
||
server.listen(9012, function() { | ||
if (cmd) { | ||
var args = cmd.split(' '); | ||
var args = cmd.split(' ') | ||
args = args.map(function(arg) { | ||
return arg.trim(); | ||
}); | ||
return arg.trim() | ||
}) | ||
args = args.filter(function(arg) { | ||
return arg.length; | ||
}); | ||
var runner = spawn(args[0], args.slice(1)); | ||
return arg.length | ||
}) | ||
var runner = spawn(args[0], args.slice(1)) | ||
runner.stdout.on('data', function(data) { | ||
print(data.valueOf()); | ||
}); | ||
print(data.valueOf()) | ||
}) | ||
runner.on('exit', function(code) { | ||
if (code === 127) { | ||
print(cmd + ' not available'); | ||
print(cmd + ' not available') | ||
} | ||
server.close(); | ||
process.exit(code); | ||
}); | ||
server.close() | ||
process.exit(code) | ||
}) | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
var dir = process.argv[2] || '.'; | ||
var cmd = process.argv.slice(3); | ||
createServer(dir, cmd.join(' ')); | ||
var dir = process.argv[2] || '.' | ||
var cmd = process.argv.slice(3) | ||
createServer(dir, cmd.join(' ')) |