Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: run saber server on 3001 port if 3000 is unavailable #184

Merged
merged 10 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/saber/lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const cac = require('cac')
const getPort = require('get-port')

const cli = cac()

Expand All @@ -11,10 +12,15 @@ cli
.option('--lazy', 'Enable lazy page compilation')
.option('--port <port>', 'Server port', { default: 3000 })
.option('--host <host>', 'Server host', { default: '0.0.0.0' })
.action((cwd = '.', options) => {
.action(async (cwd = '.', options) => {
setNodeEnv('development')

const { host, port, lazy } = options
let { host, port, lazy } = options
host = host ? host : '0.0.0.0'
if (!port) {
port = await getPort({ port: getPort.makeRange(3000, 4000), host })
}
nblthree marked this conversation as resolved.
Show resolved Hide resolved

delete options.host
delete options.port
delete options.lazy
Expand Down Expand Up @@ -57,11 +63,15 @@ cli
cli
.command('serve [app]', 'Serve the output directory')
.option('--host <host>', 'Server host', { default: '0.0.0.0' })
.option('--port <host>', 'Server port', { default: 3000 })
.action((cwd = '.', options) => {
.option('--port <host>', 'Server port')
.action(async (cwd = '.', options) => {
setNodeEnv('production')

const { host, port } = options
let { host, port } = options
if (!port) {
port = await getPort({ port: getPort.makeRange(3000, 4000), host })
}

delete options.host
delete options.port
return require('..')(Object.assign({ cwd, dev: true }, options), {
Expand Down
1 change: 1 addition & 0 deletions packages/saber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devalue": "^1.1.0",
"fast-deep-equal": "^2.0.1",
"file-loader": "^3.0.1",
"get-port": "^5.0.0",
"hash-sum": "^1.0.2",
"joycon": "^2.2.4",
"lodash.merge": "^4.6.1",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5344,6 +5344,13 @@ get-port@^3.2.0:
resolved "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=

get-port@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/get-port/-/get-port-5.0.0.tgz#aa22b6b86fd926dd7884de3e23332c9f70c031a6"
integrity sha512-imzMU0FjsZqNa6BqOjbbW6w5BivHIuQKopjpPqcnx0AVHJQKCxK1O+Ab3OrVXhrekqfVMjwA9ZYu062R+KcIsQ==
dependencies:
type-fest "^0.3.0"

get-set-props@^0.1.0:
version "0.1.0"
resolved "https://registry.npmjs.org/get-set-props/-/get-set-props-0.1.0.tgz#998475c178445686d0b32246da5df8dbcfbe8ea3"
Expand Down Expand Up @@ -11722,6 +11729,11 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

type-fest@^0.3.0:
version "0.3.1"
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"
integrity sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==

type-fest@^0.4.1:
version "0.4.1"
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.4.1.tgz#8bdf77743385d8a4f13ba95f610f5ccd68c728f8"
Expand Down