fix(scripts): adjust npm run scripts

This commit is contained in:
Mrugesh Mohapatra
2018-09-27 12:28:31 +05:30
parent 12ee5fd431
commit 9aad55f8af
3 changed files with 8 additions and 6 deletions

31
scripts/ensure-env.js Normal file
View File

@@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');
const env = require('../config/env');
const apiPath = path.resolve(__dirname, '../api-server');
const clientPath = path.resolve(__dirname, '../client');
fs.access(`${apiPath}/server/rev-manifest.json`, function(err) {
if (err) {
console.log('\n\ncreating manifest\n\n');
return fs.writeFileSync(`${apiPath}/server/rev-manifest.json`, '{}');
}
console.log('\n\nrev-manifest present\n\n');
return null;
});
fs.access(`${apiPath}/server/resources/pathMigration.json`, err => {
if (err) {
console.log('\n\ncreating pathMigration\n\n');
return fs.writeFileSync(
`${apiPath}/server/resources/pathMigration.json`,
'{}'
);
}
console.log('\n\npathMigration present\n\n');
return null;
});
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));

36
scripts/start-develop.js Normal file
View File

@@ -0,0 +1,36 @@
require('dotenv').config();
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);
function cleanUp() {
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);