Comparing version 0.1.5 to 0.2.0
@@ -33,30 +33,44 @@ #!/usr/bin/env node | ||
if (_[0] === 'add' && _[1]) { | ||
return servers.add(_[1], argv) | ||
} | ||
// Need to rely on a callback because daemon.stop is asynchronous | ||
function run (cb) { | ||
if (_[0] === 'add' && _[1]) { | ||
servers.add(_[1], argv) | ||
return cb() | ||
} | ||
if (_[0] === 'rm') { | ||
return servers.rm(_[1]) | ||
} | ||
if (_[0] === 'rm') { | ||
servers.rm(_[1]) | ||
return cb() | ||
} | ||
if (_[0] === 'ls') { | ||
return servers.ls() | ||
} | ||
if (_[0] === 'ls') { | ||
servers.ls() | ||
return cb() | ||
} | ||
if (_[0] === 'start') { | ||
return daemon.start() | ||
} | ||
if (_[0] === 'start') { | ||
daemon.start() | ||
return cb() | ||
} | ||
if (_[0] === 'stop') { | ||
return daemon.stop() | ||
} | ||
if (_[0] === 'stop') { | ||
// Asynchronous command | ||
daemon.stop(cb) | ||
return | ||
} | ||
if (_[0] === 'autostart') { | ||
return autostart.create() | ||
} | ||
if (_[0] === 'autostart') { | ||
autostart.create() | ||
return cb() | ||
} | ||
if (_[0] === 'rm-autostart') { | ||
return autostart.remove() | ||
if (_[0] === 'rm-autostart') { | ||
autostart.remove() | ||
return cb() | ||
} | ||
yargs.showHelp() | ||
} | ||
yargs.showHelp() | ||
console.log() | ||
run(console.log) |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var mkdirp = require('mkdirp'); | ||
var tildify = require('tildify'); | ||
var untildify = require('untildify'); | ||
@@ -39,4 +40,4 @@ | ||
var platform = os.platform(); | ||
console.log('Create autostart script'); | ||
console.log('Create', file[platform]); | ||
console.log(' Create ' + tildify(file[platform])); | ||
mkdirp.sync(path.dirname(file[platform])); | ||
@@ -48,2 +49,4 @@ fs.writeFileSync(file[platform], data[platform]); | ||
} | ||
console.log(' Created startup script '); | ||
} | ||
@@ -53,4 +56,4 @@ | ||
var platform = os.platform(); | ||
console.log('Remove autostart script'); | ||
console.log('Remove', file[platform]); | ||
console.log(' Remove ' + tildify(file[platform])); | ||
if (fs.existsSync(file[platform])) fs.unlinkSync(file[platform]); | ||
@@ -61,2 +64,4 @@ | ||
} | ||
console.log(' Removed autostart script'); | ||
} |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var got = require('got'); | ||
var tildify = require('tildify'); | ||
var untildify = require('untildify'); | ||
@@ -20,7 +21,5 @@ var spawn = require('child_process').spawn; | ||
function start() { | ||
console.log('Start daemon'); | ||
// Open ~/.hotel/daemon.log | ||
var daemonLog = untildify('~/.hotel/daemon.log'); | ||
console.log('Create', daemonLog); | ||
console.log(' Create ' + tildify(daemonLog)); | ||
var out = fs.openSync(daemonLog, 'w'); | ||
@@ -31,3 +30,3 @@ | ||
var node = process.execPath; | ||
console.log('Spawn ' + node + ' ' + daemonFile); | ||
console.log(' Spawn ' + tildify(node) + ' ' + tildify(daemonFile)); | ||
spawn(node, [daemonFile], { | ||
@@ -39,16 +38,17 @@ stdio: ['ignore', out, out], | ||
// Started | ||
console.log('Started'); | ||
console.log(' Started http://localhost:' + conf.port); | ||
} | ||
// Stop daemon using killURL | ||
function stop() { | ||
console.log('Stop daemon'); | ||
function stop(cb) { | ||
got.post(killURL, function (err) { | ||
// Assume it's not running | ||
if (err) return console.log('Not running'); | ||
// Stopped | ||
console.log('Stopped'); | ||
if (err) { | ||
// Assume it's not running | ||
console.log(' Not running'); | ||
} else { | ||
// Stopped | ||
console.log(' Stopped daemon'); | ||
} | ||
cb(); | ||
}); | ||
} |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var common = require('../common'); | ||
var conf = require('../conf'); | ||
@@ -20,15 +21,16 @@ module.exports = { | ||
function getId(id) { | ||
return id || path.basename(process.cwd()); | ||
function getId(name) { | ||
return name || path.basename(process.cwd()); | ||
} | ||
function getServerFile(id) { | ||
return '' + serversDir + '/' + getId(id) + '.json'; | ||
return '' + serversDir + '/' + id + '.json'; | ||
} | ||
function add(cmd, opts) { | ||
var file = getServerFile(opts.n); | ||
var id = getId(opts.n); | ||
var file = getServerFile(id); | ||
var obj = { | ||
cmd: cmd, | ||
cwd: process.cwd() | ||
cwd: process.cwd(), | ||
cmd: cmd | ||
}; | ||
@@ -42,40 +44,29 @@ | ||
console.log('Create ' + file); | ||
var data = JSON.stringify(obj); | ||
var data = JSON.stringify(obj, null, 2); | ||
console.log(' Create ' + tildify(file)); | ||
fs.writeFileSync(file, data); | ||
console.log(' Added http://localhost:' + conf.port + '/' + id); | ||
} | ||
function rm(id) { | ||
fs.unlink(getServerFile(id), function () {}); | ||
function rm(name) { | ||
var id = getId(name); | ||
var file = getServerFile(id); | ||
console.log(' Remove ' + tildify(file)); | ||
console.log(' Removed'); | ||
fs.unlink(file, function () {}); | ||
} | ||
function ls() { | ||
var files = fs.readdirSync(serversDir); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var list = fs.readdirSync(serversDir).map(function (file) { | ||
var id = path.basename(file, '.json'); | ||
var serverFile = getServerFile(id); | ||
var server = JSON.parse(fs.readFileSync(serverFile)); | ||
return ' ' + tildify(server.cwd) + '$ ' + server.cmd + '\n' + (' http://localhost:' + conf.port + '/' + id); | ||
}).join('\n\n'); | ||
try { | ||
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var file = _step.value; | ||
var id = path.basename(file, '.json'); | ||
var serverFile = getServerFile(id); | ||
var server = JSON.parse(fs.readFileSync(serverFile)); | ||
console.log('' + id + ' - ' + tildify(server.cwd) + ' - ' + server.cmd); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator['return']) { | ||
_iterator['return'](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
console.log(list); | ||
} |
@@ -17,6 +17,2 @@ 'use strict'; | ||
function version(req, res) { | ||
res.send(pkg.version); | ||
} | ||
function kill(req, res) { | ||
@@ -72,5 +68,5 @@ res.end(); | ||
router.get('/', index).get('/version', version).get('/:id', redirect).post('/kill', kill); | ||
router.get('/', index).get('/:id', redirect).post('/kill', kill); | ||
return router; | ||
}; |
{ | ||
"name": "hotel", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "Easily start, stop and access your servers from the browser", | ||
@@ -10,7 +10,8 @@ "main": "lib", | ||
"prepublish": "npm test", | ||
"daemon": "nodemon --exec babel-node -- src/daemon", | ||
"standard": " standard src/**/*.js test/**/*.js", | ||
"test": "npm run build && npm run standard && mocha --compilers js:babel/register", | ||
"install": "node bin/install", | ||
"uninstall": "node bin/uninstall", | ||
"standard": " standard bin src/**/*.js test/**/*.js", | ||
"build": "babel src --out-dir lib --copy-files", | ||
"test": "npm run build && npm run standard && mocha --compilers js:babel/register", | ||
"uninstall": "node bin stop" | ||
"daemon": "nodemon --exec babel-node -- src/daemon" | ||
}, | ||
@@ -23,3 +24,7 @@ "repository": { | ||
"dev", | ||
"utility" | ||
"utility", | ||
"process", | ||
"manager", | ||
"local", | ||
"server" | ||
], | ||
@@ -26,0 +31,0 @@ "author": "Typicode <typicode@gmail.com>", |
# hotel [![](https://img.shields.io/travis/typicode/hotel.svg)](https://travis-ci.org/typicode/hotel) [![](https://badge.fury.io/js/hotel.svg)](https://www.npmjs.com/package/hotel) | ||
Easily start, stop and access your local servers from the browser. | ||
Start, stop and access your local servers from the browser <3 | ||
![](https://rawgit.com/typicode/hotel/master/screenshot.png) | ||
__Install__ | ||
@@ -16,19 +14,14 @@ | ||
```bash | ||
~/node-app$ hotel add nodemon | ||
~/html-app$ hotel add 'serve -p $PORT' | ||
~/express$ hotel add nodemon | ||
~/static$ hotel add 'serve -p $PORT' | ||
``` | ||
if you're using [nvm](https://github.com/creationix/nvm) or similar, add `-e PATH` (i.e. `hotel add nodemon -e PATH`). | ||
Your servers can now be accessed, started and stopped from [localhost:2000](http://localhost:2000). | ||
__Start hotel__ | ||
![](https://rawgit.com/typicode/hotel/master/screenshot.png) | ||
```bash | ||
~$ hotel start | ||
~$ hotel autostart # Create an autostart script (recommended) | ||
``` | ||
As a shortcut, you can also directly go to `localhost:2000/<name>` to start and access a server. | ||
Your servers can now be accessed, started and stopped from [localhost:2000](http://localhost:2000). | ||
_If you're using [nvm](https://github.com/creationix/nvm) or similar, add `-e PATH` (i.e. `hotel add nodemon -e PATH`)._ | ||
No need to open a terminal (works on OS X, Linux and Windows). | ||
## Usage | ||
@@ -35,0 +28,0 @@ |
{ | ||
"optOut": false, | ||
"lastUpdateCheck": 1432989369623 | ||
"lastUpdateCheck": 1433298889861 | ||
} |
@@ -1,1 +0,8 @@ | ||
{"cmd":"node index.js","cwd":"/Users/sonic/d/hotel/test/app","out":"output.log","env":{"PATH":"/Users/sonic/.nvm/versions/node/v0.12.0/lib/node_modules/npm/bin/node-gyp-bin:/Users/sonic/d/hotel/node_modules/.bin:/Users/sonic/.nvm/versions/node/v0.12.0/lib/node_modules/npm/bin/node-gyp-bin:/Users/sonic/d/hotel/node_modules/.bin:/Users/sonic/.rbenv/shims:/Users/sonic/.rbenv/bin:/Users/sonic/.nvm/versions/node/v0.12.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/sonic/go/bin"}} | ||
{ | ||
"cwd": "/home/sonic/d/hotel/test/app", | ||
"cmd": "node index.js", | ||
"out": "output.log", | ||
"env": { | ||
"PATH": "/home/sonic/.nvm/versions/node/v0.12.4/lib/node_modules/npm/bin/node-gyp-bin:/home/sonic/d/hotel/node_modules/.bin:/home/sonic/.nvm/versions/node/v0.12.4/lib/node_modules/npm/bin/node-gyp-bin:/home/sonic/d/hotel/node_modules/.bin:/home/sonic/.nvm/versions/node/v0.12.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" | ||
} | ||
} |
@@ -13,3 +13,3 @@ process.env.HOME = `${__dirname}/home` | ||
let timeout = process.env.TRAVIS ? 8000 : 4000 | ||
let timeout = process.env.TRAVIS ? 10000 : 5000 | ||
@@ -22,5 +22,15 @@ // Used to give some time to the system and commands | ||
function hotel (cmd) { | ||
return cp.execSync(`node ${__dirname}/../${pkg.bin} ${cmd}`, { | ||
// Execute hotel cmd | ||
let out = cp.execSync(`node ${__dirname}/../${pkg.bin} ${cmd}`, { | ||
cwd: `${__dirname}/app` | ||
}).toString() | ||
// Log output | ||
// .replace() used to enhance tests readability | ||
console.log(out | ||
.replace(/\n /g, '\n ') | ||
.replace(/\n$/, '')) | ||
// Return output | ||
return out | ||
} | ||
@@ -42,3 +52,3 @@ | ||
describe('hotel start', () => { | ||
describe('$ hotel start', () => { | ||
@@ -128,3 +138,3 @@ before(done => { | ||
describe('hotel stop', () => { | ||
describe('$ hotel stop', () => { | ||
@@ -131,0 +141,0 @@ before((done) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
293557
27
677
94
1