Skip to content

Commit dff557a

Browse files
committed
Fix webhook pull
1 parent 630e1c5 commit dff557a

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

bin/pull.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
git fetch &&
4+
git reset --hard origin/master &&
5+
npm install &&
6+
npm run build

src/backend/common/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ const execute = (command, cwd, { stdout = process.stdout, stderr = process.stder
1212
if (stderr) child.stderr.pipe(stderr);
1313
});
1414

15+
const spawn = (command, args, cwd, { stdout = process.stdout, stderr = process.stderr } = {}) => new Promise((resolve, reject) => {
16+
if (!cwd) return reject(new Error('CWD Not Specified'));
17+
const child = child_process.spawn(command, args, { cwd });
18+
child.on('close', code => code ? reject(new Error(`Process exited with code: ${code}`)) : resolve());
19+
if (stdout) child.stdout.pipe(stdout);
20+
if (stderr) child.stderr.pipe(stderr);
21+
});
22+
1523
const createKey = name => name.toLowerCase().replace(/ /g, '-');
1624

1725
const listFiles = dirPath => fs.readdirSync(dirPath).filter(fileName => !fileName.startsWith('.'));
1826

1927
export {
2028
execute,
29+
spawn,
2130
createKey,
2231
listFiles,
2332
};

src/backend/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import bodyParser from 'body-parser';
66
import * as controllers from '/controllers';
77
import { ClientError, ForbiddenError, NotFoundError, UnauthorizedError } from '/common/error';
88
import webhook from '/common/webhook';
9-
import { execute } from '/common/util';
9+
import { spawn } from '/common/util';
1010

1111
const app = express();
1212
app.use(morgan('tiny'));
@@ -34,13 +34,7 @@ const rootPath = path.resolve(__dirname, '..', '..');
3434
webhook.on('algorithm-visualizer', event => {
3535
switch (event) {
3636
case 'push':
37-
execute([
38-
'git fetch',
39-
'git reset --hard origin/master',
40-
'npm install',
41-
'npm run build',
42-
'pm2 startOrRestart ./pm2.config.js',
43-
].join(' && '), rootPath);
37+
spawn('sh', ['./bin/pull.sh'], rootPath).then(() => process.exit(0));
4438
break;
4539
}
4640
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy