]>
git.r.bdr.sh - rbdr/blog/blob - lib/remote.js
1 const { readFile
, writeFile
} = require('fs/promises');
2 const { rmIfExists
} = require('./utils');
6 configurationNotFound: 'Remote configuration not set, consult help for more info.'
9 require('./remotes/git')
14 async
add(remoteConfig
, remote
) {
16 await
writeFile(remoteConfig
, remote
);
19 async
remove(remoteConfig
) {
21 await
rmIfExists(remoteConfig
);
24 async
syncUp(remoteConfig
, blogDirectory
) {
26 await
this._executeMethodOnStrategy(remoteConfig
, 'syncUp', blogDirectory
);
29 async
syncDown(remoteConfig
, blogDirectory
) {
31 await
this._executeMethodOnStrategy(remoteConfig
, 'syncDown', blogDirectory
);
34 async
_executeMethodOnStrategy(remoteConfig
, method
, blogDirectory
) {
36 const remote
= await
this._ensureConfiguration(remoteConfig
);
38 for (const strategy
of internals
.strategies
) {
39 if (strategy
.canHandle(remote
)) {
40 await strategy
[method
](remote
, blogDirectory
);
45 async
_ensureConfiguration(remoteConfig
) {
48 const configuration
= await
readFile(remoteConfig
, { encoding: 'utf8' });
52 throw new Error(internals
.strings
.configurationNotFound
);