]>
Commit | Line | Data |
---|---|---|
1 | const { exec } = require('child_process'); | |
2 | const { debuglog, promisify } = require('util'); | |
3 | ||
4 | const internals = { | |
5 | // Promisified functions | |
6 | exec: promisify(exec), | |
7 | ||
8 | debuglog: debuglog('blog'), | |
9 | }; | |
10 | ||
11 | module.exports = { | |
12 | canHandle() { | |
13 | // For the future: actually check if it's a valid git url | |
14 | return true; | |
15 | }, | |
16 | ||
17 | async syncUp(remote, blogDirectory) { | |
18 | let output = null; | |
19 | ||
20 | output = await internals.exec(`cd ${blogDirectory} && git init`); | |
21 | internals.debuglog(output.stderr); | |
22 | ||
23 | output = await internals.exec(`cd ${blogDirectory} && git add .`); | |
24 | internals.debuglog(output.stderr); | |
25 | ||
26 | output = await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`); | |
27 | internals.debuglog(output.stderr); | |
28 | ||
29 | output = await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`); | |
30 | internals.debuglog(output.stderr); | |
31 | }, | |
32 | ||
33 | async syncDown(remote, blogDirectory) { | |
34 | let output = null; | |
35 | ||
36 | output = await internals.exec(`cd ${blogDirectory} && git init`); | |
37 | internals.debuglog(output.stderr); | |
38 | ||
39 | output = await internals.exec(`cd ${blogDirectory} && git checkout .`); | |
40 | internals.debuglog(output.stderr); | |
41 | ||
42 | output = await internals.exec(`cd ${blogDirectory} && git clean . -f`); | |
43 | internals.debuglog(output.stderr); | |
44 | ||
45 | output = await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`); | |
46 | internals.debuglog(output.stderr); | |
47 | } | |
48 | } |