diff --git a/framework/agility/agility.config.js b/framework/agility/agility.config.js index adb9d7fd5..4ea96118e 100644 --- a/framework/agility/agility.config.js +++ b/framework/agility/agility.config.js @@ -11,14 +11,17 @@ const agilityConfig = { }; const getSyncClient = ({ isPreview, isDevelopmentMode }) => { - let cachePath = `node_modules/@agility/content-sync/cache/${ + + const rootPath = process.cwd() + + let cachePath = `${rootPath}/.next/cache/agility/${ isPreview ? "preview" : "live" }`; - if (!isDevelopmentMode) { - //we are in prod and need to use a different directory that Vercel understands - cachePath = `/tmp/agilitycache/${isPreview ? "preview" : "live"}`; - } +// if (!isDevelopmentMode) { +// //we are in prod and need to use a different directory that Vercel understands +// cachePath = `/tmp/agilitycache/${isPreview ? "preview" : "live"}`; +// } console.log(`Agility CMS => Content cache path is ${cachePath}`); const apiKey = isPreview diff --git a/framework/agility/agility.sync.js b/framework/agility/agility.sync.js index 593b0ddc4..cf8641161 100644 --- a/framework/agility/agility.sync.js +++ b/framework/agility/agility.sync.js @@ -22,6 +22,27 @@ const runSync = async () => { await agilitySyncClient.runSync(); } +const syncAll = async () => { + + //sync preview mode + let agilitySyncClient = getSyncClient({ isPreview: true, isDevelopmentMode: false }) + if (! agilitySyncClient) { + console.log("Agility CMS => Sync client could not be accessed.") + return; + } + + await agilitySyncClient.runSync(); + + //sync production mode + agilitySyncClient = getSyncClient({ isPreview: false, isDevelopmentMode: false }) + if (! agilitySyncClient) { + console.log("Agility CMS => Sync client could not be accessed.") + return; + } + + await agilitySyncClient.runSync(); +} + const clearSync = async () => { const agilitySyncClient = getSyncClient({ isPreview: true, isDevelopmentMode: true }) @@ -42,6 +63,10 @@ if (process.argv[2]) { //run the sync return runSync() + } else if (process.argv[2] === "sync-all") { + //sync both staging and live content + return syncAll() + } } diff --git a/package.json b/package.json index 790de9f12..2ba95549b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "nextjs-commerce", "version": "1.0.0", "scripts": { - "dev": "next dev", + "dev": "next dev", + "prebuild": "node framework/agility/agility.sync.js sync-all", "build": "next build", "start": "next start", "analyze": "BUNDLE_ANALYZE=both yarn build",