Skip to content

Commit

Permalink
feat: Move browser open from config to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed Mar 27, 2019
1 parent 5f65150 commit cf30f49
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
7 changes: 5 additions & 2 deletions bin/pangolin-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ program
program
.command('dev')
.description('Start development server')
.action(() => {
require('../lib/commands/dev')()
.option('-o, --open [browser]', 'Open in default or specific browser')
.action(env => {
require('../lib/commands/dev')({
open: env.open
})
})

program
Expand Down
12 changes: 7 additions & 5 deletions lib/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const generateConfig = require('../config/generate')
const generateImports = require('../utils/generate-imports')
const getPort = require('../utils/get-port')
const normalizePath = require('../utils/normalize-path')
const opn = require('opn')
const open = require('open')
const path = require('path')
const store = require('../store')
const WebSocket = require('ws')
Expand All @@ -12,8 +12,10 @@ const WebpackDevServer = require('webpack-dev-server')

/**
* Start development server
* @param {Object} options Options
* @param {Boolean|String} options.open Open in browser
*/
module.exports = async function () {
module.exports = async function (options) {
process.env.NODE_ENV = 'development'
process.env.PANGOLIN_ENV = 'dev'

Expand Down Expand Up @@ -52,9 +54,9 @@ module.exports = async function () {
const server = new WebpackDevServer(compiler, devServerOptions)

server.listen(serverPort, serverHost, () => {
// Open web browser if config option is set
if (store.state.config.devServer.open) {
opn(serverURL, { app: store.state.config.devServer.browser })
// Open web browser if flag is set
if (options.open) {
open(serverURL, { app: typeof options.open === 'string' && options.open })
}
})

Expand Down
26 changes: 17 additions & 9 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.9.3",
"nunjucks": "^3.2.0",
"opn": "^5.5.0",
"open": "^6.0.0",
"postcss-loader": "^3.0.0",
"prismjs": "^1.15.0",
"prismjs": "^1.16.0",
"sass-loader": "^7.0.1",
"style-loader": "^0.23.0",
"stylelint": "^9.10.1",
"stylelint-codeframe-formatter": "^1.0.4",
"stylelint-webpack-plugin": "^0.10.1",
"webpack": "^4.29.6",
"webpack-bundle-analyzer": "^3.1.0",
"webpack-chain": "^5.2.3",
"webpack-chain": "^5.2.4",
"webpack-dev-server": "^3.2.1",
"webpack-merge": "^4.2.1",
"webpackbar": "^3.0.3",
Expand All @@ -92,7 +92,7 @@
"focus-trap": "^5.0.0",
"nyc": "^13.3.0",
"postcss-custom-properties": "^8.0.6",
"prism-themes": "^1.0.1",
"prism-themes": "^1.1.0",
"sanitize.css": "^8.0.0",
"standard-version": "^5.0.2"
},
Expand Down
2 changes: 0 additions & 2 deletions test/project/pangolin.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
// module.exports = {
// devServer: {
// open: true,
// browser: 'firefox',
// port: 1337
// }
// }
Expand Down

0 comments on commit cf30f49

Please sign in to comment.