Skip to content

Commit

Permalink
Merge pull request #35 from aaronshaf/feature/open-browser
Browse files Browse the repository at this point in the history
Add --open argument to open default browser with GUI on start (fix #23)
  • Loading branch information
aaronshaf committed Jul 16, 2018
2 parents e0edf95 + 72a2b20 commit d086b01
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export DYNAMO_ENDPOINT=http://localhost:8000
dynamodb-admin
```

Options:
- --open - opens server URL in a default browser on start

# Use as a library in your project

```
Expand Down
23 changes: 22 additions & 1 deletion bin/dynamodb-admin.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
#!/usr/bin/env node

const ArgumentParser = require('argparse').ArgumentParser
const opn = require('opn')
const packageJson = require('../package.json')

const { createServer } = require('../lib/backend')

if (process.env.NODE_ENV === 'production') {
console.error(clc.red('Do not run this in production!'))
process.exit(1)
}

const parser = new ArgumentParser({
description: packageJson.description,
version: packageJson.version,
})

parser.addArgument(['-o', '--open'], {
action: 'storeTrue',
help: 'Open server URL in default browser on start',
})

const args = parser.parseArgs()

console.log('dynamodb-admin')

const app = createServer();
const port = process.env.PORT || 8001
const server = app.listen(port);
server.on('listening', () => {
const address = server.address();
console.log(` listening on http://0.0.0.0:${address.port}`);
const url = `http://0.0.0.0:${address.port}`;
console.log(` listening on ${url}`);

if (args.open) {
opn(url)
}
});

17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/aaronshaf/dynamodb-viewer#readme",
"dependencies": {
"argparse": "^1.0.10",
"aws-sdk": "^2.273.1",
"body-parser": "^1.18.3",
"cli-color": "^1.2.0",
Expand All @@ -31,7 +32,8 @@
"es6-promisify": "^6.0.0",
"es7-object-polyfill": "0.0.7",
"express": "^4.16.3",
"lodash": "^4.17.10"
"lodash": "^4.17.10",
"opn": "^5.3.0"
},
"devDependencies": {
"jest-cli": "^23.4.0"
Expand Down

0 comments on commit d086b01

Please sign in to comment.