Skip to content

Commit 476b17b

Browse files
committed
Move manifest file name definition
1 parent 0ba9420 commit 476b17b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/events-listener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Vault, TAbstractFile, TFolder } from "obsidian";
2-
import MetadataStore from "./metadata-store";
2+
import MetadataStore, { MANIFEST_FILE_NAME } from "./metadata-store";
33
import { GitHubSyncSettings } from "./settings/settings";
44
import Logger from "./logger";
55

@@ -132,7 +132,7 @@ export default class EventsListener {
132132
}
133133

134134
private isSyncable(filePath: string) {
135-
if (filePath === `${this.vault.configDir}/github-sync-metadata.json`) {
135+
if (filePath === `${this.vault.configDir}/${MANIFEST_FILE_NAME}`) {
136136
// Manifest file must always be synced
137137
return true;
138138
} else if (

src/metadata-store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Vault, normalizePath } from "obsidian";
22

3+
export const MANIFEST_FILE_NAME = "github-sync-metadata.json" as const;
4+
35
/**
46
* A file metadata.
57
* Store info that makes easier to track a file locally and in the remote repo.
@@ -42,7 +44,7 @@ export default class MetadataStore {
4244

4345
constructor(private vault: Vault) {
4446
this.metadataFile = normalizePath(
45-
`${this.vault.configDir}/github-sync-metadata.json`,
47+
`${this.vault.configDir}/${MANIFEST_FILE_NAME}`,
4648
);
4749
}
4850

src/sync-manager.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import GithubClient, {
44
NewTreeRequestItem,
55
RepoContent,
66
} from "./github/client";
7-
import MetadataStore, { FileMetadata, Metadata } from "./metadata-store";
7+
import MetadataStore, {
8+
FileMetadata,
9+
Metadata,
10+
MANIFEST_FILE_NAME,
11+
} from "./metadata-store";
812
import EventsListener from "./events-listener";
913
import { GitHubSyncSettings } from "./settings/settings";
1014
import Logger from "./logger";
@@ -93,7 +97,7 @@ export default class SyncManager {
9397
// So we create a the manifest file as the first commit, since we're going
9498
// to create that in any case right after this.
9599
await this.client.createFile(
96-
`${this.vault.configDir}/github-sync-metadata.json`,
100+
`${this.vault.configDir}/${MANIFEST_FILE_NAME}`,
97101
"",
98102
"Initial commit",
99103
);
@@ -144,7 +148,7 @@ export default class SyncManager {
144148
if (
145149
this.settings.syncConfigDir &&
146150
filePath.startsWith(this.vault.configDir) &&
147-
filePath !== `${this.vault.configDir}/github-sync-metadata.json`
151+
filePath !== `${this.vault.configDir}/${MANIFEST_FILE_NAME}`
148152
) {
149153
// Include files in the config dir only if the user has enabled it.
150154
// The metadata file must always be synced.
@@ -239,7 +243,7 @@ export default class SyncManager {
239243
async sync() {
240244
await this.logger.info("Starting sync");
241245
const { files, sha: treeSha } = await this.client.getRepoContent();
242-
const manifest = files[`${this.vault.configDir}/github-sync-metadata.json`];
246+
const manifest = files[`${this.vault.configDir}/${MANIFEST_FILE_NAME}`];
243247

244248
if (manifest === undefined) {
245249
await this.logger.error("Remote manifest is missing", { files, treeSha });
@@ -512,8 +516,7 @@ export default class SyncManager {
512516
return actions.filter((action: SyncAction) => {
513517
return (
514518
!action.filePath.startsWith(this.vault.configDir) ||
515-
action.filePath ===
516-
`${this.vault.configDir}/github-sync-metadata.json`
519+
action.filePath === `${this.vault.configDir}/${MANIFEST_FILE_NAME}`
517520
);
518521
});
519522
}
@@ -536,8 +539,8 @@ export default class SyncManager {
536539
this.metadataStore.save();
537540

538541
// Update manifest in list of new tree items
539-
delete treeFiles[`${this.vault.configDir}/github-sync-metadata.json`].sha;
540-
treeFiles[`${this.vault.configDir}/github-sync-metadata.json`].content =
542+
delete treeFiles[`${this.vault.configDir}/${MANIFEST_FILE_NAME}`].sha;
543+
treeFiles[`${this.vault.configDir}/${MANIFEST_FILE_NAME}`].content =
541544
JSON.stringify(this.metadataStore.data);
542545

543546
// Create the new tree
@@ -639,9 +642,9 @@ export default class SyncManager {
639642
// Must be the first time we run, initialize the metadata store
640643
// with itself and all files in the vault.
641644
this.metadataStore.data.files[
642-
`${this.vault.configDir}/github-sync-metadata.json`
645+
`${this.vault.configDir}/${MANIFEST_FILE_NAME}`
643646
] = {
644-
path: `${this.vault.configDir}/github-sync-metadata.json`,
647+
path: `${this.vault.configDir}/${MANIFEST_FILE_NAME}`,
645648
sha: null,
646649
dirty: false,
647650
justDownloaded: false,
@@ -708,7 +711,7 @@ export default class SyncManager {
708711

709712
// Remove all them from the metadata store
710713
files.forEach((filePath: string) => {
711-
if (filePath === `${this.vault.configDir}/github-sync-metadata.json`) {
714+
if (filePath === `${this.vault.configDir}/${MANIFEST_FILE_NAME}`) {
712715
// We don't want to remove the metadata file even if it's in the config dir
713716
return;
714717
}

0 commit comments

Comments
 (0)