X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/c5cbbd3835ccd509179504cdf7d5e74356d7dca5..f24ecd569d1945fbbdf18fad9398ea338d8eb2c6:/lib/remote.js?ds=sidebyside diff --git a/lib/remote.js b/lib/remote.js index d8f73f9..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) { - 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) { + 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;