Skip to content

Commit

Permalink
Moved list of options out into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Jun 24, 2017
1 parent a75425f commit c783001
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 42 deletions.
49 changes: 7 additions & 42 deletions bin/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const nodeVersion = require('node-version')
const pkg = require('../package')
const listening = require('../lib/listening')
const serverHandler = require('../lib/server')
const { options, minimist } = require('../lib/options')

// Throw an error if node version is too low
if (nodeVersion.major < 6) {
Expand All @@ -34,49 +35,13 @@ if (process.env.NODE_ENV !== 'production' && pkg.dist) {
updateNotifier({ pkg }).notify()
}

args
.option('port', 'Port to listen on', process.env.PORT || 5000)
.option(
'cache',
'Time in milliseconds for caching files in the browser',
3600
)
.option('single', 'Serve single page apps with only one index.html')
.option('unzipped', 'Disable GZIP compression')
.option('ignore', 'Files and directories to ignore')
.option('auth', 'Serve behind basic auth')
.option(
'cors',
'Setup * CORS headers to allow requests from any origin',
false
)
.option('silent', `Don't log anything to the console`)
.option(['n', 'clipless'], `Don't copy address to clipboard`, false)
.option('open', 'Open local address in browser', false)

const flags = args.parse(process.argv, {
minimist: {
alias: {
a: 'auth',
C: 'cors',
S: 'silent',
s: 'single',
u: 'unzipped',
n: 'clipless',
o: 'open'
},
boolean: [
'auth',
'cors',
'silent',
'single',
'unzipped',
'clipless',
'open'
]
}
})
// Register the list of options
args.options(options)

// And initialize `args`
const flags = args.parse(process.argv, { minimist })

// Figure out the content directory
const directory = args.sub[0]

// Don't log anything to the console if silent mode is enabled
Expand Down
60 changes: 60 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
exports.options = [
{
name: 'port',
description: 'Port to listen on',
defaultValue: process.env.PORT || 5000
},
{
name: 'cache',
description: 'Time in milliseconds for caching files in the browser',
defaultValue: 3600
},
{
name: 'single',
description: 'Serve single page apps with only one index.html'
},
{
name: 'unzipped',
description: 'Disable GZIP compression'
},
{
name: 'ignore',
description: 'Files and directories to ignore'
},
{
name: 'auth',
description: 'Serve behind basic auth'
},
{
name: 'cors',
description: 'Setup * CORS headers to allow requests from any origin',
defaultValue: false
},
{
name: 'silent',
description: `Don't log anything to the console`
},
{
name: ['n', 'clipless'],
description: `Don't copy address to clipboard`,
defaultValue: false
},
{
name: 'open',
description: 'Open local address in browser',
defaultValue: false
}
]

exports.minimist = {
alias: {
a: 'auth',
C: 'cors',
S: 'silent',
s: 'single',
u: 'unzipped',
n: 'clipless',
o: 'open'
},
boolean: ['auth', 'cors', 'silent', 'single', 'unzipped', 'clipless', 'open']
}

0 comments on commit c783001

Please sign in to comment.