This commit is contained in:
Joel Varty 2021-01-18 09:23:25 -05:00
parent 914d75dc8d
commit 3906917161
3 changed files with 35 additions and 6 deletions

View File

@ -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

View File

@ -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()
}
}

View File

@ -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",