]>
git.r.bdr.sh - rbdr/blog/blob - lib/remote.js
8b29c4e6f6bf7d91d3c97ac9fea39f0aa1d4fbbc
1 const { readFile
, rm
, writeFile
} = require('fs/promises');
5 configurationNotFound: 'Remote configuration not set, consult help for more info.'
8 require('./remotes/git')
13 async
add(remoteConfig
, remote
) {
15 await
writeFile(remoteConfig
, remote
);
18 async
remove(remoteConfig
) {
20 await
rm(remoteConfig
, { force: true })
23 async
syncUp(remoteConfig
, blogDirectory
) {
25 await
this._executeMethodOnStrategy(remoteConfig
, 'syncUp', blogDirectory
);
28 async
syncDown(remoteConfig
, blogDirectory
) {
30 await
this._executeMethodOnStrategy(remoteConfig
, 'syncDown', blogDirectory
);
33 async
_executeMethodOnStrategy(remoteConfig
, method
, blogDirectory
) {
35 const remote
= await
this._ensureConfiguration(remoteConfig
);
37 for (const strategy
of internals
.strategies
) {
38 if (strategy
.canHandle(remote
)) {
39 await strategy
[method
](remote
, blogDirectory
);
44 async
_ensureConfiguration(remoteConfig
) {
47 const configuration
= await
readFile(remoteConfig
, { encoding: 'utf8' });
51 throw new Error(internals
.strings
.configurationNotFound
);