X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/bd8c1fa2774b98b22939d60c06a06525691867ce..467390bc032585f28da6203f891764f4a66c33b7:/lib/remote.js?ds=sidebyside diff --git a/lib/remote.js b/lib/remote.js index 569cd25..373958f 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -1,4 +1,5 @@ -const { readFile, rm, writeFile } = require('fs/promises'); +const { readFile, writeFile } = require('fs/promises'); +const { rmIfExists } = require('./utils'); const internals = { strings: { @@ -11,22 +12,27 @@ const internals = { module.exports = { async add(remoteConfig, remote) { + await writeFile(remoteConfig, remote); }, async remove(remoteConfig) { - await rm(remoteConfig, { force: true }) + + await rmIfExists(remoteConfig); }, async syncUp(remoteConfig, blogDirectory) { + await this._executeMethodOnStrategy(remoteConfig, 'syncUp', blogDirectory); }, async syncDown(remoteConfig, blogDirectory) { + await this._executeMethodOnStrategy(remoteConfig, 'syncDown', blogDirectory); }, async _executeMethodOnStrategy(remoteConfig, method, blogDirectory) { + const remote = await this._ensureConfiguration(remoteConfig); for (const strategy of internals.strategies) { @@ -37,6 +43,7 @@ module.exports = { }, async _ensureConfiguration(remoteConfig) { + try { const configuration = await readFile(remoteConfig, { encoding: 'utf8' }); return configuration;