diff --git a/bin/pangolin-core.js b/bin/pangolin-core.js index ba83000d..ab9ad1dc 100755 --- a/bin/pangolin-core.js +++ b/bin/pangolin-core.js @@ -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 diff --git a/lib/commands/dev.js b/lib/commands/dev.js index a48c01d3..96234556 100644 --- a/lib/commands/dev.js +++ b/lib/commands/dev.js @@ -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') @@ -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' @@ -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 }) } }) diff --git a/package-lock.json b/package-lock.json index 5a4bd156..5a53d3f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9880,6 +9880,14 @@ "mimic-fn": "^1.0.0" } }, + "open": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/open/-/open-6.0.0.tgz", + "integrity": "sha512-/yb5mVZBz7mHLySMiSj2DcLtMBbFPJk5JBKEkHVZFxZAPzeg3L026O0T+lbdz1B2nyDnkClRSwRQJdeVUIF7zw==", + "requires": { + "is-wsl": "^1.1.0" + } + }, "opener": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.1.tgz", @@ -10977,15 +10985,15 @@ "integrity": "sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==" }, "prism-themes": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/prism-themes/-/prism-themes-1.0.1.tgz", - "integrity": "sha512-tRYOqg2tT5/eB++iX+rqRnqESkCKuoV+0PrUiGKdWMr5lApd/hwfu+72Hi0OS50wmcuIty3GB1HrRqoBD+Cpfg==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/prism-themes/-/prism-themes-1.1.0.tgz", + "integrity": "sha512-xBkflbKbstGGasW3P68KQzAuObLQeH//I5mn37jKVHVDrRLp4Xct/n8F/tV5h+CKIMa3nDAZ2q0bt8ItSiS72A==", "dev": true }, "prismjs": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.15.0.tgz", - "integrity": "sha512-Lf2JrFYx8FanHrjoV5oL8YHCclLQgbJcVZR+gikGGMqz6ub5QVWDTM6YIwm3BuPxM/LOV+rKns3LssXNLIf+DA==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.16.0.tgz", + "integrity": "sha512-OA4MKxjFZHSvZcisLGe14THYsug/nF6O1f0pAJc0KN0wTyAcLqmsbE+lTGKSpyh+9pEW57+k6pg2AfYR+coyHA==", "requires": { "clipboard": "^2.0.0" } @@ -13703,9 +13711,9 @@ } }, "webpack-chain": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/webpack-chain/-/webpack-chain-5.2.3.tgz", - "integrity": "sha512-4s4X02RiiPKz3v9LwSCTNUyieY8EOfj0DflUC2ySUvtj2/IWH+ai9Orz07uYiQ4l/knR5U88Q9Nty3Oay6OGGw==", + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/webpack-chain/-/webpack-chain-5.2.4.tgz", + "integrity": "sha512-3g0uIbzM/EWnmf52bYhB5IZeBZiw5g9vNqF4iTBEqabpxGxcv+Aj9oL4Cvr19ujOsv/HPvpRFRPLZ/aylv10Wg==", "requires": { "deepmerge": "^1.5.2", "javascript-stringify": "^2.0.0" diff --git a/package.json b/package.json index 5f777ab9..12769a33 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,9 @@ "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", @@ -73,7 +73,7 @@ "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", @@ -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" }, diff --git a/test/project/pangolin.config.js b/test/project/pangolin.config.js index bbf0a696..e666b269 100644 --- a/test/project/pangolin.config.js +++ b/test/project/pangolin.config.js @@ -24,8 +24,6 @@ */ // module.exports = { // devServer: { -// open: true, -// browser: 'firefox', // port: 1337 // } // }