]>
git.r.bdr.sh - rbdr/blog/blob - lib/remote.js
569cd254daf02dad73df75fb502b4730b8db5bfc
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 await
this._executeMethodOnStrategy(remoteConfig
, 'syncUp', blogDirectory
);
25 async
syncDown(remoteConfig
, blogDirectory
) {
26 await
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
);