Skip to content

Commit 1b829b8

Browse files
committed
refactor: loadcheckpoint logic
1 parent e66443f commit 1b829b8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/core/index.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,29 @@ export const init = (contentStore, assetStore) => {
119119
})
120120
}
121121

122-
const loadCheckpoint = (checkPointConfig: ICheckpoint, paths: any) => {
123-
if (checkPointConfig?.enabled) {
124-
let checkPoint = readHiddenFile(paths.checkpoint);
125-
if (!checkPoint) {
126-
const checkpointPath = path.join(sanitizePath(__dirname), sanitizePath(checkPointConfig.filePath || ".checkpoint"));
127-
checkPoint = readHiddenFile(checkpointPath);
128-
}
129-
if (checkPoint) {
130-
console.log("Found sync token in checkpoint file:", checkPoint);
131-
Contentstack.sync_token = checkPoint.token;
132-
console.log("Using sync token:", Contentstack.sync_token);
133-
}
122+
const loadCheckpoint = (checkPointConfig: ICheckpoint, paths: any): void => {
123+
if (!checkPointConfig?.enabled) return;
124+
125+
// Try reading checkpoint from primary path
126+
let checkpoint = readHiddenFile(paths.checkpoint);
127+
128+
// Fallback to filePath in config if not found
129+
if (!checkpoint) {
130+
const fallbackPath = path.join(
131+
sanitizePath(__dirname),
132+
sanitizePath(checkPointConfig.filePath || ".checkpoint")
133+
);
134+
checkpoint = readHiddenFile(fallbackPath);
134135
}
135-
}
136+
137+
// Set sync token if checkpoint is found
138+
if (checkpoint) {
139+
console.log("Found sync token in checkpoint file:", checkpoint);
140+
Contentstack.sync_token = checkpoint.token;
141+
console.log("Using sync token:", Contentstack.sync_token);
142+
}
143+
};
144+
136145

137146
function readHiddenFile(filePath: string) {
138147
try {

0 commit comments

Comments
 (0)