]> git.r.bdr.sh - rbdr/blog/blame - lib/remotes/git.js
Add generator
[rbdr/blog] / lib / remotes / git.js
CommitLineData
6cd62e79
RBR
1import { exec } from 'child_process';
2import { promisify } from 'util';
c5cbbd38
RBR
3
4const internals = {
5 // Promisified functions
10a76a5b 6 exec: promisify(exec)
c5cbbd38
RBR
7};
8
6cd62e79 9export default {
c5cbbd38 10 canHandle() {
f91c2b4f 11
c5cbbd38
RBR
12 // For the future: actually check if it's a valid git url
13 return true;
14 },
15
16 async syncUp(remote, blogDirectory) {
bd8c1fa2 17
a5315f49 18 await internals.exec(`cd ${blogDirectory} && git init -b main`);
f91c2b4f
RBR
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`);
c5cbbd38
RBR
22 },
23
24 async syncDown(remote, blogDirectory) {
bd8c1fa2 25
a5315f49 26 await internals.exec(`cd ${blogDirectory} && git init -b main`);
b0c3bb91
RBR
27 try {
28 await internals.exec(`cd ${blogDirectory} && git checkout .`);
29 }
30 catch {}
10a76a5b 31
f91c2b4f
RBR
32 await internals.exec(`cd ${blogDirectory} && git clean . -f`);
33 await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`);
c5cbbd38 34 }
10a76a5b 35};