From 571e5e718ab5394d0c58f413990a6a1ac5f1648e Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Tue, 19 Nov 2019 18:02:34 +0100 Subject: [PATCH 1/4] feat : add bash script to generate used ports --- package-lock.json | 4 ++-- package.json | 2 +- server.sh | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 server.sh diff --git a/package-lock.json b/package-lock.json index 28445bea..a733afa4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4302,7 +4302,7 @@ "dependencies": { "readable-stream": { "version": "2.3.6", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -7363,7 +7363,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, "requires": { diff --git a/package.json b/package.json index 30712c3b..7ca1c7ee 100755 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "https://github.com/BeAPI/beapi-frontend-framework" }, "scripts": { - "start": "node_modules/.bin/concurrently -k -n \"Webpack,PHP Server\" -p \"[{name}]\" -c \"green, blue\" \"node_modules/.bin/webpack --mode=development --watch\" \"php -S localhost:9090\"", + "start": "node_modules/.bin/concurrently -k -n \"Webpack,PHP Server\" -p \"[{name}]\" -c \"green, blue\" \"node_modules/.bin/webpack --mode=development --watch\" \"sh server.sh\"", "build:dev": "node_modules/.bin/webpack --mode=development && npm run icon && npm run favicon", "build:prod": "npm run clean && node_modules/.bin/webpack --mode=production && npm run icon && npm run favicon", "build": "npm run clean && node_modules/.bin/webpack --mode=production && npm run build:dev", diff --git a/server.sh b/server.sh new file mode 100644 index 00000000..2cfdacc0 --- /dev/null +++ b/server.sh @@ -0,0 +1,19 @@ +#!/bin/bash +PORT=9090 +BSPORT=3000 + +while [ -n "$(lsof -Pi :${PORT} -sTCP:LISTEN -t)" ]; do + ((PORT++)) +done + +while [ -n "$(lsof -Pi :${BSPORT} -sTCP:LISTEN -t)" ]; do + ((BSPORT += 2)) +done + +echo "BS will run on port ${BSPORT}" + +echo $PORT > ".port" +echo $BSPORT > ".bs-port" + +echo "Server is running on port ${PORT} and BrowserSync on port ${BSPORT}" +php -S localhost:${PORT} \ No newline at end of file From 6cc3bc15b2621870171ca7d2136a2fd7ac71d441 Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Tue, 19 Nov 2019 18:03:03 +0100 Subject: [PATCH 2/4] ci : add .port and bs-port to gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 76da1c0a..10e01abf 100644 --- a/.gitignore +++ b/.gitignore @@ -73,4 +73,8 @@ dist/ src/conf-img/*.csv ### yarn -yarn.lock \ No newline at end of file +yarn.lock + +### config +.port +.bs-port \ No newline at end of file From aa4eb0841129ab472bb15fb90ca95d3b6929db08 Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Tue, 19 Nov 2019 18:03:58 +0100 Subject: [PATCH 3/4] feat (webpack) : add dynamic ports from port files --- webpack.config.js | 12 +++++++++++- webpack.settings.js | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 8fa235fb..05918f4c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,4 @@ +const fs = require('fs') const config = require('./webpack.settings') const BrowserSyncPlugin = require('browser-sync-webpack-plugin') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin @@ -8,7 +9,15 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin') const SoundsPlugin = require('sounds-webpack-plugin') const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const WebpackProgressOraPlugin = require('webpack-progress-ora-plugin') +const getServerPort = function(portFile, defaultPort) { + try { + require('fs').accessSync(portFile, fs.R_OK | fs.W_OK) + return parseInt(fs.readFileSync(portFile, 'utf8')) + } catch (e) { + return defaultPort + } +} const webpackConfig = { entry: config.entry, output: { @@ -168,7 +177,8 @@ module.exports = (env, argv) => { }), new BrowserSyncPlugin( { - proxy: 'http://[::1]:' + config.port, + port: getServerPort('./.bs-port', 3000), + proxy: 'http://[::1]:' + getServerPort('./.port', 9090), files: [ { match: config.refresh, diff --git a/webpack.settings.js b/webpack.settings.js index ca3c1128..d9b4b52b 100755 --- a/webpack.settings.js +++ b/webpack.settings.js @@ -6,7 +6,6 @@ module.exports = { 'editor-style': './src/scss/editor-style.scss', }, assetsPath: path.resolve(__dirname, 'dist/assets'), - port: 9090, dev: process.env.NODE_ENV === 'dev', refresh: [ 'dist/**/*.php', From 99a5ba3a9f64944fec9a9b1c3817eb44f996f09b Mon Sep 17 00:00:00 2001 From: Milan Ricoul Date: Wed, 20 Nov 2019 10:37:20 +0100 Subject: [PATCH 4/4] refactor (webpack) : getServerPort method --- webpack.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 05918f4c..b10a7000 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,13 +9,13 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin') const SoundsPlugin = require('sounds-webpack-plugin') const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const WebpackProgressOraPlugin = require('webpack-progress-ora-plugin') -const getServerPort = function(portFile, defaultPort) { +const getServerPort = function(portFile) { try { require('fs').accessSync(portFile, fs.R_OK | fs.W_OK) return parseInt(fs.readFileSync(portFile, 'utf8')) } catch (e) { - return defaultPort + return false } } const webpackConfig = { @@ -177,8 +177,8 @@ module.exports = (env, argv) => { }), new BrowserSyncPlugin( { - port: getServerPort('./.bs-port', 3000), - proxy: 'http://[::1]:' + getServerPort('./.port', 9090), + port: getServerPort('./.bs-port') || 3000, + proxy: 'http://[::1]:' + (getServerPort('./.port') || 9090), files: [ { match: config.refresh,