X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/c5cbbd3835ccd509179504cdf7d5e74356d7dca5..172f4c8807d44ebe38c7f227b7fdc2d6a9dbe323:/lib/remote.js?ds=sidebyside diff --git a/lib/remote.js b/lib/remote.js deleted file mode 100644 index d8f73f9..0000000 --- a/lib/remote.js +++ /dev/null @@ -1,48 +0,0 @@ -const { readFile, rm, writeFile } = require('fs/promises'); - -const internals = { - strings: { - configurationNotFound: 'Remote configuration not set, consult help for more info.' - }, - strategies: [ - require('./remotes/git') - ] -}; - -module.exports = { - async add(remoteConfig, remote) { - await writeFile(remoteConfig, remote); - }, - - async remove(remoteConfig) { - await rm(remoteConfig, { force: true }) - }, - - async syncUp(remoteConfig, blogDirectory) { - this._executeMethodOnStrategy(remoteConfig, 'syncUp', blogDirectory); - }, - - async syncDown(remoteConfig, blogDirectory) { - this._executeMethodOnStrategy(remoteConfig, 'syncDown', blogDirectory); - }, - - async _executeMethodOnStrategy(remoteConfig, method, blogDirectory) { - const remote = await this._ensureConfiguration(remoteConfig); - - for (const strategy of internals.strategies) { - if (strategy.canHandle(remote)) { - await strategy[method](remote, blogDirectory); - } - } - }, - - async _ensureConfiguration(remoteConfig) { - try { - const configuration = await readFile(remoteConfig, { encoding: 'utf8' }); - return configuration; - } - catch { - throw new Error(internals.strings.configurationNotFound); - } - } -}