Skip to content

DX | 30-06-2025 | Release #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// scripts/clean.js
const fs = require("fs");
const path = require("path");
const rimraf = require("rimraf");
const config = require("./config/all");
const { merge } = require("lodash");

// Set application's environment
const env = process.env.NODE_ENV || config.environment || "development";

let envConfig;
if (fs.existsSync(path.join(__dirname, "config", env + ".js"))) {
envConfig = require(path.join(__dirname, "config", env));
} else {
envConfig = require(path.join(__dirname, "config", "development"));
}

const appConfig = merge(config, envConfig);

const pathsToDelete = [".ledger", ".token", "unprocessible"];

// Preserve .checkpoint only if explicitly set in the configuration
if (!appConfig.checkpoint?.preserve) {
pathsToDelete.push(".checkpoint");
}

pathsToDelete.forEach((fileOrDir) => {
const fullPath = path.join(__dirname, fileOrDir);
if (fs.existsSync(fullPath)) {
rimraf.sync(fullPath);
console.log("Deleted:", fileOrDir);
} else {
console.log("Not found (skipped):", fileOrDir);
}
});
5 changes: 5 additions & 0 deletions config/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ const config = {
},
},
],
checkpoint: {
enabled: false, // Set to true if you want to enable checkpoint
filePath: ".checkpoint",
preserve: false // Set to true if you want to preserve the checkpoint file during clean operation
},
}

module.exports = config
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ if (fs.existsSync(path.join(__dirname, "config", env + ".js"))) {

const appConfig = _.merge(config, envConfig);

// Optional checkpoint reading
if (appConfig.checkpoint?.enabled) {
const checkpointPath = path.join(__dirname, appConfig.checkpoint.filePath || ".checkpoint");
const checkPoint = readHiddenFile(checkpointPath);
if (checkPoint) {
console.log("Found sync token in checkpoint file:", checkPoint);
appConfig.contentstack.sync_token = checkPoint.token;
console.log("Using sync token:", appConfig.contentstack.sync_token);
}
}

datasyncManager.setConfig(appConfig);
datasyncManager.setAssetStore(assetStore);
datasyncManager.setContentStore(contentStore);
Expand All @@ -45,3 +56,16 @@ datasyncManager
.catch((error) => {
console.error(error);
});

function readHiddenFile(filePath) {
try {
if (!fs.existsSync(filePath)) {
console.error("File does not exist:", filePath);
return;
}
const data = fs.readFileSync(filePath, "utf8");
return JSON.parse(data);
} catch (err) {
console.error("Error reading file:", err?.message);
}
}
Loading
Loading