]>
git.r.bdr.sh - rbdr/blog/blob - lib/remote.js
d8f73f9325daf2be886495e9efd952e50ed459c9
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
) {
14 await
writeFile(remoteConfig
, remote
);
17 async
remove(remoteConfig
) {
18 await
rm(remoteConfig
, { force: true })
21 async
syncUp(remoteConfig
, blogDirectory
) {
22 this._executeMethodOnStrategy(remoteConfig
, 'syncUp', blogDirectory
);
25 async
syncDown(remoteConfig
, blogDirectory
) {
26 this._executeMethodOnStrategy(remoteConfig
, 'syncDown', blogDirectory
);
29 async
_executeMethodOnStrategy(remoteConfig
, method
, blogDirectory
) {
30 const remote
= await
this._ensureConfiguration(remoteConfig
);
32 for (const strategy
of internals
.strategies
) {
33 if (strategy
.canHandle(remote
)) {
34 await strategy
[method
](remote
, blogDirectory
);
39 async
_ensureConfiguration(remoteConfig
) {
41 const configuration
= await
readFile(remoteConfig
, { encoding: 'utf8' });
45 throw new Error(internals
.strings
.configurationNotFound
);