diff --git a/README.md b/README.md index 9c30869..0ae736e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Vehicle energy consumption and production simulator. This tool has been created The easiest way is to use the [online simulator](https://vhelio.org/simulateur-vhelio/). -You can also download the latest pre-built stand-alone version and open `www/vhelio-simulator.html` in your web browser. The program will run in your browser, but won't communicate with any server, this is a purely local application. +You can also download the latest pre-built stand-alone version and open `vhelio-simulator.html` in your web browser. The program will run in your browser, but won't communicate with any server, this is a purely local application. ## Building from source @@ -20,6 +20,6 @@ Then go in the `simulator` folder and run this command: `npm install`. This will ### Build -Execute `build.sh` on Linux, or `build.bat` on Windows. +Execute `npm run build` from the `simulator` directory. -That's it, you can now open `www/vhelio-simulator.html` in your browser. +That's it, you can now open `simulator/www/vhelio-simulator.html` in your browser. diff --git a/simulator/build.bat b/simulator/build.bat deleted file mode 100644 index c49c59f..0000000 --- a/simulator/build.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off - -pushd src -node ../tools/embed.js -node ../node_modules/typescript/lib/tsc.js -node ../tools/purify.js -popd diff --git a/simulator/build.sh b/simulator/build.sh deleted file mode 100755 index 55c64db..0000000 --- a/simulator/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -cd src -node ../tools/embed.js -../node_modules/typescript/bin/tsc -node ../tools/purify.js diff --git a/simulator/package.json b/simulator/package.json index d544fae..c1bfc83 100644 --- a/simulator/package.json +++ b/simulator/package.json @@ -7,6 +7,9 @@ "url": "https://gitea.youb.fr/youen/vhelio-simulator.git", "directory": "simulator" }, + "scripts": { + "build": "node tools/build.js" + }, "dependencies": {}, "devDependencies": { "purify-css": "^1.2.5", diff --git a/simulator/tools/build.js b/simulator/tools/build.js new file mode 100644 index 0000000..3b601d8 --- /dev/null +++ b/simulator/tools/build.js @@ -0,0 +1,25 @@ +let child_process = require('child_process'); + +let toolsDir = __dirname; +let srcDir = toolsDir + "/../src"; +let nodeModulesDir = toolsDir + "/../node_modules"; + +let commands = [ + () => child_process.fork(toolsDir + '/embed.js'), + () => child_process.fork(nodeModulesDir + '/typescript/lib/tsc.js', {'cwd': srcDir}), + () => child_process.fork(toolsDir + '/purify.js', {'cwd': srcDir}) +]; + +let commandIdx = 0; + +function executeCommand(commandIdx) { + let process = commands[commandIdx](); + process.on('close', (exitCode) => { + if(exitCode != 0) throw "Command " + commands[commandIdx] + " failed with code " + exitCode; + commandIdx += 1; + if(commandIdx == commands.length) return; + executeCommand(commandIdx); + }); +} + +executeCommand(commandIdx); diff --git a/simulator/tools/embed.js b/simulator/tools/embed.js index d84809e..7834235 100644 --- a/simulator/tools/embed.js +++ b/simulator/tools/embed.js @@ -47,5 +47,9 @@ function embedCsv(src, dst) { }); } -embedSvg('../data/climate-zones-map.svg', 'climate-zones-map.svg.ts'); -embedCsv('../data/climate-zones-data.csv', 'climate-zones-data.ts'); +let toolsDir = __dirname; +let dataDir = toolsDir + "/../data"; +let srcDir = toolsDir + "/../src"; + +embedSvg(dataDir+'/climate-zones-map.svg', srcDir+'/climate-zones-map.svg.ts'); +embedCsv(dataDir+'/climate-zones-data.csv', srcDir+'/climate-zones-data.ts');