提交 dff557a9 编写于 作者: J Jason Park

Fix webhook pull

上级 630e1c51
#!/usr/bin/env bash
git fetch &&
git reset --hard origin/master &&
npm install &&
npm run build
...@@ -12,12 +12,21 @@ const execute = (command, cwd, { stdout = process.stdout, stderr = process.stder ...@@ -12,12 +12,21 @@ const execute = (command, cwd, { stdout = process.stdout, stderr = process.stder
if (stderr) child.stderr.pipe(stderr); if (stderr) child.stderr.pipe(stderr);
}); });
const spawn = (command, args, cwd, { stdout = process.stdout, stderr = process.stderr } = {}) => new Promise((resolve, reject) => {
if (!cwd) return reject(new Error('CWD Not Specified'));
const child = child_process.spawn(command, args, { cwd });
child.on('close', code => code ? reject(new Error(`Process exited with code: ${code}`)) : resolve());
if (stdout) child.stdout.pipe(stdout);
if (stderr) child.stderr.pipe(stderr);
});
const createKey = name => name.toLowerCase().replace(/ /g, '-'); const createKey = name => name.toLowerCase().replace(/ /g, '-');
const listFiles = dirPath => fs.readdirSync(dirPath).filter(fileName => !fileName.startsWith('.')); const listFiles = dirPath => fs.readdirSync(dirPath).filter(fileName => !fileName.startsWith('.'));
export { export {
execute, execute,
spawn,
createKey, createKey,
listFiles, listFiles,
}; };
...@@ -6,7 +6,7 @@ import bodyParser from 'body-parser'; ...@@ -6,7 +6,7 @@ import bodyParser from 'body-parser';
import * as controllers from '/controllers'; import * as controllers from '/controllers';
import { ClientError, ForbiddenError, NotFoundError, UnauthorizedError } from '/common/error'; import { ClientError, ForbiddenError, NotFoundError, UnauthorizedError } from '/common/error';
import webhook from '/common/webhook'; import webhook from '/common/webhook';
import { execute } from '/common/util'; import { spawn } from '/common/util';
const app = express(); const app = express();
app.use(morgan('tiny')); app.use(morgan('tiny'));
...@@ -34,13 +34,7 @@ const rootPath = path.resolve(__dirname, '..', '..'); ...@@ -34,13 +34,7 @@ const rootPath = path.resolve(__dirname, '..', '..');
webhook.on('algorithm-visualizer', event => { webhook.on('algorithm-visualizer', event => {
switch (event) { switch (event) {
case 'push': case 'push':
execute([ spawn('sh', ['./bin/pull.sh'], rootPath).then(() => process.exit(0));
'git fetch',
'git reset --hard origin/master',
'npm install',
'npm run build',
'pm2 startOrRestart ./pm2.config.js',
].join(' && '), rootPath);
break; break;
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册