X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/bd8c1fa2774b98b22939d60c06a06525691867ce..9eac24780006862171b85858b40db0f29f494e76:/lib/remote.js 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;