forked from typicode/hotel
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert to default prettier config (#4)
- Loading branch information
Showing
36 changed files
with
1,107 additions
and
1,113 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 +1 @@ | ||
require('../lib/scripts/uninstall')() | ||
require("../lib/scripts/uninstall")(); |
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,10 +1,10 @@ | ||
#!/usr/bin/env node | ||
const pkg = require('../../package.json') | ||
require('please-upgrade-node')(pkg) | ||
const pkg = require("../../package.json"); | ||
require("please-upgrade-node")(pkg); | ||
|
||
const updateNotifier = require('update-notifier') | ||
const sudoBlock = require('sudo-block') | ||
const updateNotifier = require("update-notifier"); | ||
const sudoBlock = require("sudo-block"); | ||
|
||
sudoBlock('\nShould not be run as root, please retry without sudo.\n') | ||
updateNotifier({ pkg }).notify() | ||
require('./')(process.argv) | ||
sudoBlock("\nShould not be run as root, please retry without sudo.\n"); | ||
updateNotifier({ pkg }).notify(); | ||
require("./")(process.argv); |
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,36 +1,36 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const mkdirp = require('mkdirp') | ||
const startup = require('user-startup') | ||
const common = require('../common') | ||
const conf = require('../conf') | ||
const uninstall = require('../scripts/uninstall') | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const mkdirp = require("mkdirp"); | ||
const startup = require("user-startup"); | ||
const common = require("../common"); | ||
const conf = require("../conf"); | ||
const uninstall = require("../scripts/uninstall"); | ||
|
||
module.exports = { | ||
start, | ||
stop | ||
} | ||
}; | ||
|
||
// Start daemon in background | ||
function start() { | ||
const node = process.execPath | ||
const daemonFile = path.join(__dirname, '../daemon') | ||
const startupFile = startup.getFile('chalet') | ||
const node = process.execPath; | ||
const daemonFile = path.join(__dirname, "../daemon"); | ||
const startupFile = startup.getFile("chalet"); | ||
|
||
startup.create('chalet', node, [daemonFile], common.logFile) | ||
startup.create("chalet", node, [daemonFile], common.logFile); | ||
|
||
// Save startup file path in ~/.chalet | ||
// Will be used later by uninstall script | ||
mkdirp.sync(common.chaletDir) | ||
fs.writeFileSync(common.startupFile, startupFile) | ||
mkdirp.sync(common.chaletDir); | ||
fs.writeFileSync(common.startupFile, startupFile); | ||
|
||
console.log(`Started http://localhost:${conf.port}`) | ||
console.log(`Started http://localhost:${conf.port}`); | ||
} | ||
|
||
// Stop daemon | ||
function stop() { | ||
startup.remove('chalet') | ||
startup.remove("chalet"); | ||
// kills process and clean stuff in ~/.chalet | ||
uninstall() | ||
console.log('Stopped') | ||
uninstall(); | ||
console.log("Stopped"); | ||
} |
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,107 +1,107 @@ | ||
const yargs = require('yargs') | ||
const servers = require('./servers') | ||
const run = require('./run') | ||
const daemon = require('./daemon') | ||
const pkg = require('../../package.json') | ||
const yargs = require("yargs"); | ||
const servers = require("./servers"); | ||
const run = require("./run"); | ||
const daemon = require("./daemon"); | ||
const pkg = require("../../package.json"); | ||
|
||
const addOptions = { | ||
name: { | ||
alias: 'n', | ||
describe: 'Server name' | ||
alias: "n", | ||
describe: "Server name" | ||
}, | ||
port: { | ||
alias: 'p', | ||
describe: 'Set PORT environment variable', | ||
alias: "p", | ||
describe: "Set PORT environment variable", | ||
number: true | ||
}, | ||
out: { | ||
alias: 'o', | ||
describe: 'Output file' | ||
alias: "o", | ||
describe: "Output file" | ||
}, | ||
env: { | ||
alias: 'e', | ||
describe: 'Additional environment variables', | ||
alias: "e", | ||
describe: "Additional environment variables", | ||
array: true | ||
}, | ||
xfwd: { | ||
alias: 'x', | ||
describe: 'Adds x-forward headers', | ||
alias: "x", | ||
describe: "Adds x-forward headers", | ||
default: false, | ||
boolean: true | ||
}, | ||
'change-origin': { | ||
alias: 'co', | ||
describe: 'Changes the origin of the host header to the target URL', | ||
"change-origin": { | ||
alias: "co", | ||
describe: "Changes the origin of the host header to the target URL", | ||
default: false, | ||
boolean: true | ||
}, | ||
'http-proxy-env': { | ||
describe: 'Adds HTTP_PROXY environment variable', | ||
"http-proxy-env": { | ||
describe: "Adds HTTP_PROXY environment variable", | ||
default: false, | ||
boolean: true | ||
}, | ||
dir: { | ||
describe: 'Server directory', | ||
describe: "Server directory", | ||
string: true | ||
}, | ||
force: { | ||
alias: 'f', | ||
describe: 'Forces creation of configuration if one already exits', | ||
alias: "f", | ||
describe: "Forces creation of configuration if one already exits", | ||
default: false, | ||
boolean: true | ||
} | ||
} | ||
}; | ||
|
||
module.exports = processArgv => | ||
yargs(processArgv.slice(2)) | ||
.version(pkg.version) | ||
.alias('v', 'version') | ||
.help('h') | ||
.alias('h', 'help') | ||
.alias("v", "version") | ||
.help("h") | ||
.alias("h", "help") | ||
.command( | ||
'add <cmd_or_url> [options]', | ||
'Add server or proxy', | ||
"add <cmd_or_url> [options]", | ||
"Add server or proxy", | ||
yargs => yargs.options(addOptions), | ||
// .demand(1), | ||
argv => servers.add(argv.cmd_or_url, argv) | ||
) | ||
.command( | ||
'run <cmd> [options]', | ||
'Run server and get a temporary local domain', | ||
"run <cmd> [options]", | ||
"Run server and get a temporary local domain", | ||
yargs => { | ||
const runOptions = { ...addOptions } | ||
delete runOptions.out | ||
return yargs.options(runOptions) | ||
const runOptions = { ...addOptions }; | ||
delete runOptions.out; | ||
return yargs.options(runOptions); | ||
// TODO demand(1) ? | ||
}, | ||
argv => run.spawn(argv.cmd, argv) | ||
) | ||
.command( | ||
'rm [options]', | ||
'Remove server or proxy', | ||
"rm [options]", | ||
"Remove server or proxy", | ||
yargs => { | ||
yargs.option('name', { | ||
alias: 'n', | ||
describe: 'Name' | ||
}) | ||
yargs.option("name", { | ||
alias: "n", | ||
describe: "Name" | ||
}); | ||
}, | ||
argv => servers.rm(argv) | ||
) | ||
.command('ls', 'List servers', {}, argv => servers.ls(argv)) | ||
.command('start', 'Start daemon', {}, () => daemon.start()) | ||
.command('stop', 'Stop daemon', {}, () => daemon.stop()) | ||
.example('$0 add --help') | ||
.example('$0 add nodemon') | ||
.example('$0 add npm start') | ||
.command("ls", "List servers", {}, argv => servers.ls(argv)) | ||
.command("start", "Start daemon", {}, () => daemon.start()) | ||
.command("stop", "Stop daemon", {}, () => daemon.stop()) | ||
.example("$0 add --help") | ||
.example("$0 add nodemon") | ||
.example("$0 add npm start") | ||
.example("$0 add 'cmd -p $PORT'") | ||
.example("$0 add 'cmd -p $PORT' --port 4000") | ||
.example("$0 add 'cmd -p $PORT' --out app.log") | ||
.example("$0 add 'cmd -p $PORT' --name app") | ||
.example("$0 add 'cmd -p $PORT' --env PATH") | ||
.example('$0 add http://192.168.1.10 -n app ') | ||
.example('$0 rm') | ||
.example('$0 rm -n app') | ||
.epilog('https://github.com/jeansaad/chalet') | ||
.example("$0 add http://192.168.1.10 -n app ") | ||
.example("$0 rm") | ||
.example("$0 rm -n app") | ||
.epilog("https://github.com/jeansaad/chalet") | ||
.demand(1) | ||
.strict() | ||
.help().argv | ||
.help().argv; |
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,53 +1,53 @@ | ||
const cp = require('child_process') | ||
const getPort = require('get-port') | ||
const servers = require('./servers') | ||
const getCmd = require('../get-cmd') | ||
const cp = require("child_process"); | ||
const getPort = require("get-port"); | ||
const servers = require("./servers"); | ||
const getCmd = require("../get-cmd"); | ||
|
||
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'] | ||
const signals = ["SIGINT", "SIGTERM", "SIGHUP"]; | ||
|
||
module.exports = { | ||
// For testing purpose, allows stubbing cp.spawnSync | ||
_spawnSync(...args) { | ||
cp.spawnSync(...args) | ||
cp.spawnSync(...args); | ||
}, | ||
|
||
// For testing purpose, allows stubbing process.exit | ||
_exit(...args) { | ||
process.exit(...args) | ||
process.exit(...args); | ||
}, | ||
|
||
spawn(cmd, opts = {}) { | ||
const cleanAndExit = (code = 0) => { | ||
servers.rm(opts) | ||
this._exit(code) | ||
} | ||
servers.rm(opts); | ||
this._exit(code); | ||
}; | ||
|
||
const startServer = port => { | ||
const serverAddress = `http://localhost:${port}` | ||
const serverAddress = `http://localhost:${port}`; | ||
|
||
process.env.PORT = port | ||
servers.add(serverAddress, opts) | ||
process.env.PORT = port; | ||
servers.add(serverAddress, opts); | ||
|
||
signals.forEach(signal => process.on(signal, cleanAndExit)) | ||
signals.forEach(signal => process.on(signal, cleanAndExit)); | ||
|
||
const [command, ...args] = getCmd(cmd) | ||
const [command, ...args] = getCmd(cmd); | ||
const { status, error } = this._spawnSync(command, args, { | ||
stdio: 'inherit', | ||
stdio: "inherit", | ||
cwd: process.cwd() | ||
}) | ||
}); | ||
|
||
if (error) throw error | ||
cleanAndExit(status) | ||
} | ||
if (error) throw error; | ||
cleanAndExit(status); | ||
}; | ||
|
||
if (opts.port) { | ||
startServer(opts.port) | ||
startServer(opts.port); | ||
} else { | ||
getPort() | ||
.then(startServer) | ||
.catch(err => { | ||
throw err | ||
}) | ||
throw err; | ||
}); | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.