Skip to content

Commit

Permalink
Redownload the server in dev if the required version has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jan 9, 2019
1 parent 3183205 commit a5c50a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
14 changes: 10 additions & 4 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@types/electron-devtools-installer": "^2.0.2",
"@types/electron-window-state": "^2.0.33",
"@types/lodash": "^4.14.119",
"@types/node": "^10.12.10",
"@types/node-fetch": "^2.1.4",
"@types/react": "^0.14.55",
Expand All @@ -42,10 +43,12 @@
"electron-forge": "^5.2.3",
"electron-prebuilt-compile": "4.0.0",
"httptoolkit-server": "^0.1.1",
"lodash": "^4.17.11",
"node-fetch": "^2.3.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-hot-loader": "^3.0.0-beta.6",
"rimraf": "^2.6.3",
"targz": "^1.0.1",
"ts-node": "^7.0.1",
"tslint": "^5.1.0",
Expand Down
19 changes: 14 additions & 5 deletions setup-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ require('ts-node/register');
const { promisify } = require('util');
const os = require('os');
const fs = require('fs');
const rimraf = require('rimraf');
const insertServer = promisify(require('./src/after-copy-insert-server'));

const canAccess = (file) => promisify(fs.access)(file).then(() => true).catch(() => false);
const deleteDir = promisify(rimraf);

const packageJsonLock = require('./package-lock.json');
const requiredServerVersion = packageJsonLock.dependencies['httptoolkit-server'].version;

// Manually trigger the after-copy hook, to give us an env like the real package
async function setUpDevEnv() {
// Manually trigger the after-copy hook, to give us an env like the real package
const afterCopy = promisify(require('./src/after-copy-insert-server'));
const serverExists = await canAccess('./httptoolkit-server');
const serverVersion = serverExists ? require('./httptoolkit-server/package.json').version : null;

if (!await canAccess('./httptoolkit-server')) {
await afterCopy(__dirname, '', os.platform(), os.arch());
if (serverVersion !== requiredServerVersion) {
if (serverExists) await deleteDir('./httptoolkit-server');
await insertServer(__dirname, '', os.platform(), os.arch());
console.log('Dev setup completed.');
} else {
console.log('Server already downloaded, nothing to do.');
console.log('Correct server already downloaded, nothing to do.');
}
}

Expand Down

0 comments on commit a5c50a2

Please sign in to comment.