diff --git a/package.json b/package.json index 6a7e3471f..f59630c19 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "library for turn-based games", "repository": "https://github.com/nicolodavis/boardgame.io", "scripts": { - "start": "bash ./scripts/dev.sh", - "dev:client": "(cd examples/react-web; npm start)", + "start": "node scripts/install-web.js && npx concurrently npm:dev:server npm:dev:client", + "dev:client": "cd examples && cd react-web && npm start", "dev:server": "cross-env NODE_ENV=development nodemon -w src -w examples -e js,ts --exec babel-node --extensions '.ts,.js' --ignore 'src/**/*.test.ts' --presets @babel/preset-env examples/react-web/server.js", "build": "cross-env BABEL_ENV=rollup rollup --config rollup.npm.js", "benchmark": "babel-node --presets @babel/preset-env benchmark/index.js", diff --git a/scripts/dev.sh b/scripts/dev.sh deleted file mode 100644 index 2f0eb5e5b..000000000 --- a/scripts/dev.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# Copyright 2017 The boardgame.io Authors -# -# Use of this source code is governed by a MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. - -set -e - -if [ ! -d examples/react-web/node_modules ]; then - (cd examples/react-web; npm install) -fi - -npx concurrently npm:dev:server npm:dev:client diff --git a/scripts/install-web.js b/scripts/install-web.js new file mode 100644 index 000000000..92b00fb28 --- /dev/null +++ b/scripts/install-web.js @@ -0,0 +1,35 @@ +/* + * Copyright 2019 The boardgame.io Authors + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT. + */ + +const path = require('path'); +const { spawnSync } = require('child_process'); +const { existsSync } = require('fs'); + +const projectRoot = path.resolve(__dirname, '../'); +const webExamplePath = path.resolve(projectRoot, './examples/react-web'); +const modulesPath = path.resolve(webExamplePath, './node_modules'); + +const hasModules = existsSync(modulesPath); + +if (!hasModules) { + installDependencies(); +} + +console.log('Starting the application...'); + +function installDependencies() { + const isWindowsOs = process.platform === 'win32'; + const npmCommand = isWindowsOs ? 'npm.cmd' : 'npm'; + + console.log('Installing web dependencies...'); + + spawnSync(npmCommand, ['install'], { + cwd: webExamplePath, + stdio: 'inherit', + }); +}