From: Ruben Beltran del Rio Date: Fri, 9 Dec 2022 17:07:29 +0000 (+0100) Subject: Fixes for remote setup X-Git-Tag: 5.0.0~14 X-Git-Url: https://git.r.bdr.sh/rbdr/blog/commitdiff_plain/bd8c1fa2774b98b22939d60c06a06525691867ce?ds=inline Fixes for remote setup --- diff --git a/lib/blog.js b/lib/blog.js index ba9ae53..0b291df 100644 --- a/lib/blog.js +++ b/lib/blog.js @@ -76,8 +76,10 @@ module.exports = class Blog { } catch {}; await this._shift(); - await this._ensurePostsDirectoryExists(join(this.postsDirectory, '0')); - await this.update(postLocation); + const firstDirectory = join(this.postsDirectory, '0'); + await rm(firstDirectory, { recursive: true, force: true }); + await this._ensurePostsDirectoryExists(firstDirectory); + await this._update(postLocation); } /** @@ -96,18 +98,7 @@ module.exports = class Blog { await this.syncDown(); } catch {}; - const metadata = await this._getMetadata(); - await this._ensurePostsDirectoryExists(); - await this._copyPost(postLocation); - await this._writeMetadata(metadata); - - await this._archive(postLocation); - - await this.generate(); - try { - await this.syncUp(); - } - catch {}; + const metadata = await this._update(); } /** @@ -206,7 +197,9 @@ module.exports = class Blog { * @instance */ async syncDown() { + internals.debuglog('Pulling remote state'); await Remote.syncDown(this.remoteConfig, this.blogDirectory) + internals.debuglog('Pulled remote state'); } /** @@ -218,9 +211,30 @@ module.exports = class Blog { * @instance */ async syncUp() { + internals.debuglog('Pushing remote state'); await Remote.syncUp(this.remoteConfig, this.blogDirectory) + internals.debuglog('Pushed remote state'); } + // Adds the passed path to slot 0, and generates files. + + async _update(postLocation) { + + const metadata = await this._getMetadata(); + await this._ensurePostsDirectoryExists(); + await this._copyPost(postLocation); + await this._writeMetadata(metadata); + + await this._archive(postLocation); + + await this.generate(); + try { + await this.syncUp(); + } + catch {}; + } + + // Parses Gemini for each page, copies assets and generates index. async generate() { diff --git a/lib/remote.js b/lib/remote.js index d8f73f9..569cd25 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -19,11 +19,11 @@ module.exports = { }, async syncUp(remoteConfig, blogDirectory) { - this._executeMethodOnStrategy(remoteConfig, 'syncUp', blogDirectory); + await this._executeMethodOnStrategy(remoteConfig, 'syncUp', blogDirectory); }, async syncDown(remoteConfig, blogDirectory) { - this._executeMethodOnStrategy(remoteConfig, 'syncDown', blogDirectory); + await this._executeMethodOnStrategy(remoteConfig, 'syncDown', blogDirectory); }, async _executeMethodOnStrategy(remoteConfig, method, blogDirectory) { diff --git a/lib/remotes/git.js b/lib/remotes/git.js index d8e0cfd..7a67462 100644 --- a/lib/remotes/git.js +++ b/lib/remotes/git.js @@ -15,16 +15,34 @@ module.exports = { }, async syncUp(remote, blogDirectory) { - await internals.exec(`cd ${blogDirectory} && git init`); - await internals.exec(`cd ${blogDirectory} && git add .`); - await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`); - await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`); + let output = null; + + output = await internals.exec(`cd ${blogDirectory} && git init`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git add .`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git commit --allow-empty -m blog-sync-up-${Date.now()}`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git push ${remote} main --force`); + internals.debuglog(output.stderr); }, async syncDown(remote, blogDirectory) { - await internals.exec(`cd ${blogDirectory} && git init`); - await internals.exec(`cd ${blogDirectory} && git checkout .`); - await internals.exec(`cd ${blogDirectory} && git clean . -f`); - await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`); + let output = null; + + output = await internals.exec(`cd ${blogDirectory} && git init`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git checkout .`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git clean . -f`); + internals.debuglog(output.stderr); + + output = await internals.exec(`cd ${blogDirectory} && git pull ${remote} main`); + internals.debuglog(output.stderr); } }