aboutsummaryrefslogtreecommitdiff
path: root/lib/remote.js
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 14:17:34 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-03-09 14:17:34 +0100
commit172f4c8807d44ebe38c7f227b7fdc2d6a9dbe323 (patch)
treeb880761cf254fbc668cea0d577d5331a28af67cc /lib/remote.js
parent36a4680d18de012e2e5c732f9db161dafa884344 (diff)
Allow sync up and down
Diffstat (limited to 'lib/remote.js')
-rw-r--r--lib/remote.js57
1 files changed, 0 insertions, 57 deletions
diff --git a/lib/remote.js b/lib/remote.js
deleted file mode 100644
index ad0a4fc..0000000
--- a/lib/remote.js
+++ /dev/null
@@ -1,57 +0,0 @@
-import { readFile, writeFile } from 'fs/promises';
-import { rmIfExists } from './utils.js';
-
-import GitStrategy from './remotes/git.js';
-
-const internals = {
- strings: {
- configurationNotFound: 'Remote configuration not set, consult help for more info.'
- },
- strategies: [
- GitStrategy
- ]
-};
-
-export default {
- async add(remoteConfig, remote) {
-
- await writeFile(remoteConfig, remote);
- },
-
- async remove(remoteConfig) {
-
- 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) {
- 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);
- }
- }
-};