]>
git.r.bdr.sh - rbdr/blog/blob - lib/remote.js
780ea91ba3493d6d46360179aa546b6e23d49e1a
1 import { readFile
, writeFile
} from 'fs/promises';
2 import { rmIfExists
} from './utils.js';
4 import GitStrategy
from './remotes/git.js';
8 configurationNotFound: 'Remote configuration not set, consult help for more info.'
16 async
add(remoteConfig
, remote
) {
18 await
writeFile(remoteConfig
, remote
);
21 async
remove(remoteConfig
) {
23 await
rmIfExists(remoteConfig
);
26 async
syncUp(remoteConfig
, blogDirectory
) {
28 await
this._executeMethodOnStrategy(remoteConfig
, 'syncUp', blogDirectory
);
31 async
syncDown(remoteConfig
, blogDirectory
) {
33 await
this._executeMethodOnStrategy(remoteConfig
, 'syncDown', blogDirectory
);
36 async
_executeMethodOnStrategy(remoteConfig
, method
, blogDirectory
) {
38 const remote
= await
this._ensureConfiguration(remoteConfig
);
40 for (const strategy
of internals
.strategies
) {
41 if (strategy
.canHandle(remote
)) {
42 await strategy
[method
](remote
, blogDirectory
);
47 async
_ensureConfiguration(remoteConfig
) {
50 const configuration
= await
readFile(remoteConfig
, { encoding: 'utf8' });
54 throw new Error(internals
.strings
.configurationNotFound
);