fix: Use npm-run-all to run the develop command

This commit is contained in:
Bouncey
2019-01-09 14:10:21 +00:00
committed by mrugesh mohapatra
parent 79af29dd2b
commit 62da8d31e2
3 changed files with 4 additions and 52 deletions

6
package-lock.json generated
View File

@ -9647,12 +9647,6 @@
} }
} }
}, },
"tree-kill": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.0.tgz",
"integrity": "sha512-DlX6dR0lOIRDFxI0mjL9IYg6OTncLm/Zt+JiBhE5OlFcAR8yc9S7FFXU9so0oda47frdM/JFsk7UjNt9vscKcg==",
"dev": true
},
"trim-newlines": { "trim-newlines": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-2.0.0.tgz", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-2.0.0.tgz",

View File

@ -5,14 +5,15 @@
"postinstall": "npm run bootstrap", "postinstall": "npm run bootstrap",
"bootstrap": "lerna bootstrap", "bootstrap": "lerna bootstrap",
"clean": "lerna clean", "clean": "lerna clean",
"develop": "npm-run-all -s ensure-env start-develop", "develop": "npm-run-all -s ensure-env && npm-run-all -p start-develop-server start-develop-client",
"ensure-env": "cross-env DEBUG=fcc:* node ./tools/scripts/ensure-env.js", "ensure-env": "cross-env DEBUG=fcc:* node ./tools/scripts/ensure-env.js",
"lint": "echo 'Warning: TODO - Define Linting with fixing.'", "lint": "echo 'Warning: TODO - Define Linting with fixing.'",
"lint:api": "eslint api-server --ignore-pattern 'api-server/node_modules/**/*.js'", "lint:api": "eslint api-server --ignore-pattern 'api-server/node_modules/**/*.js'",
"seed": "npm-run-all -p seed:*", "seed": "npm-run-all -p seed:*",
"seed:challenges": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedChallenges", "seed:challenges": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedChallenges",
"seed:auth-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser", "seed:auth-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
"start-develop": "node ./tools/scripts/start-develop.js", "start-develop-client": "cd ./client && node ./node_modules/gatsby-cli develop",
"start-develop-server": "cd ./api-server && node development-entry.js",
"pretest": "npm-run-all -s test:lint", "pretest": "npm-run-all -s test:lint",
"test": "npm-run-all -p test:*", "test": "npm-run-all -p test:*",
"test:lint": "echo 'Warning: TODO - Define Linting tests.'", "test:lint": "echo 'Warning: TODO - Define Linting tests.'",
@ -38,7 +39,6 @@
"ora": "^3.0.0", "ora": "^3.0.0",
"readdirp-walk": "^1.6.0", "readdirp-walk": "^1.6.0",
"shortid": "^2.2.14", "shortid": "^2.2.14",
"slugg": "^1.2.1", "slugg": "^1.2.1"
"tree-kill": "^1.2.0"
} }
} }

View File

@ -1,42 +0,0 @@
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
const { spawn } = require('child_process');
const kill = require('tree-kill');
const spawnOpts = {
stdio: 'inherit',
shell: true
};
const loopback = spawn(
'cd',
['./api-server', '&&', 'node development-entry.js'],
spawnOpts
);
const gatsby = spawn('cd', ['./client', '&&', 'npm run develop'], spawnOpts);
let cleanupCalled = false;
function cleanUp() {
if (cleanupCalled) {
return null;
}
cleanupCalled = true;
console.log(`
Killing processes...
`);
const promises = [
kill(loopback.pid, 'SIGINT', () => Promise.resolve()),
kill(gatsby.pid, 'SIGINT', () => Promise.resolve())
];
return Promise.all(promises).then(() => {
console.log(`
All processes have exited
`);
});
}
process.on('exit', cleanUp);
process.on('SIGINT', cleanUp);
process.on('SIGUSR1', cleanUp);
process.on('SIGUSR2', cleanUp);