]> git.r.bdr.sh - rbdr/blog/blame - lib/remotes/git.js
Add rudimentary sync support
[rbdr/blog] / lib / remotes / git.js
CommitLineData
c5cbbd38
RBR
1const { exec } = require('child_process');
2const { debuglog, promisify } = require('util');
3
4const internals = {
5 // Promisified functions
6 exec: promisify(exec),
7
8 debuglog: debuglog('blog'),
9};
10
11module.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 await internals.exec(`cd ${blogDirectory} && git init`);
19 await internals.exec(`cd ${blogDirectory} && git add .`);
20 await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`);
21 await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`);
22 },
23
24 async syncDown(remote, blogDirectory) {
25 await internals.exec(`cd ${blogDirectory} && git init`);
26 await internals.exec(`cd ${blogDirectory} && git checkout .`);
27 await internals.exec(`cd ${blogDirectory} && git clean . -f`);
28 await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`);
29 }
30}