-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Sammy-T/config
Create 'copy-config' script
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
backend: | ||
name: custom # Can be 'github' or 'custom' | ||
branch: master | ||
file: 'backend/example.js' # The script to use as a custom backend. Relative to the /cms-config path | ||
# repo: owner-name/repo-name | ||
# app_name: 'My GitHub App Name' # The GitHub app used with the 'github' backend | ||
# client_id: my-client-id # The client id of the GitHub app | ||
# api_root: http://localhost:8788 # The root of the api used to exchange the github token | ||
# auth_endpoint: /api/github/oauth/token # The api endpoint to exchange the auth code for a github token | ||
local_backend: true # Set to 'true' to override the backend with the local backend | ||
custom_actions: 'cms-actions.js' # Configure to include custom actions. Relative to the /cms-config path | ||
|
||
repo_folder: snow-cms # The root folder of the repository | ||
media_folder: 'dev-site/img/uploads' # The repo's media folder | ||
public_folder: '/img/uploads' # The site's media path (Media location when served online or via dev server) | ||
|
||
collections: | ||
- name: 'news' # Used in routes, e.g., /admin/collections/blog | ||
label: 'News' # Used in the UI | ||
folder: 'dev-site/content/news' # The repo path to the folder where documents are stored | ||
create: true # Allow users to create new documents in this collection | ||
slug: '{{year}}{{month}}{{day}}-{{slug}}' # Filename template, e.g., YYYY-MM-DD-title | ||
extension: 'md' # Only 'md' is supported currently | ||
fields: # The fields for each document, usually in front matter | ||
- { label: 'Title', name: 'title', widget: 'string' } | ||
- { label: 'Publish Date', name: 'date', widget: 'datetime', type: 'date', | ||
date_format: 'MM.DD.YYYY', time_format: 'HH:mm', datetime_format: 'MM.DD.YYYY HH:mm' } | ||
- { label: 'Draft', name: 'draft', widget: 'boolean', default: true, required: false } | ||
- { label: 'Body', name: 'body', widget: 'markdown' } | ||
|
||
- name: 'blog' # Used in routes, e.g., /admin/collections/blog | ||
label: 'Blog' # Used in the UI | ||
folder: 'dev-site/content/blog' # The repo path to the folder where documents are stored | ||
create: true # Allow users to create new documents in this collection | ||
slug: '{{year}}{{month}}{{day}}-{{slug}}' # Filename template, e.g., YYYY-MM-DD-title | ||
extension: 'md' # Only 'md' is supported currently | ||
fields: # The fields for each document, usually in front matter | ||
- { label: 'Title', name: 'title', widget: 'string' } | ||
- { label: 'Publish Date', name: 'date', widget: 'datetime', type: 'date', | ||
date_format: 'MM.DD.YYYY', time_format: 'HH:mm', datetime_format: 'MM.DD.YYYY HH:mm' } | ||
- { label: 'Draft', name: 'draft', widget: 'boolean', default: true, required: false } | ||
- { label: 'Body', name: 'body', widget: 'markdown' } | ||
|
||
previews: # Filenames in this section are relative to the /cms-config path | ||
default: main # Default preview name, can also be specified on each collection using a 'preview' attribute | ||
templates: | ||
- { name: 'main', template: 'preview-template.html' } | ||
styles: # Styles will load in listed order | ||
- { name: 'main', files: ['preview-styles.css', 'preview-styles-news.css'] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'dotenv/config'; | ||
import { copyFile, readFile, writeFile } from 'fs/promises'; | ||
|
||
const lockfileName = 'cms-lock.json'; | ||
const lockfilePath = new URL(`../${lockfileName}`, import.meta.url); | ||
|
||
async function readLockfile() { | ||
try { | ||
const contents = await readFile(lockfilePath, { encoding: 'utf8' }); | ||
|
||
return JSON.parse(contents); | ||
} catch(error) { | ||
console.warn('No lockfile found.', error); | ||
return; | ||
} | ||
} | ||
|
||
async function copyConfig() { | ||
try { | ||
// Get the CMS env. | ||
// Fall back to 'prod' if not found. | ||
const cmsEnv = process.env.CMS_ENV ?? 'prod'; | ||
|
||
// Check the custom lockfile | ||
const lock = await readLockfile(); | ||
|
||
// If the lockfile matches the specified env, return early. | ||
if(lock?.cms_env === cmsEnv) { | ||
console.log('CMS lockfile matches.'); | ||
return; | ||
} | ||
|
||
// The env and lockfile don't match | ||
// so copy the specified config. | ||
const sourcePath = `scripts/.config/config-${cmsEnv}.yml`; | ||
const configPath = 'dev-site/cms-config/config.yml'; | ||
|
||
await copyFile(sourcePath, configPath); | ||
console.log(`CMS env '${cmsEnv}'.\nCopied ${sourcePath} => ${configPath}`); | ||
|
||
// Update the lock data | ||
const newLock = { ...lock }; | ||
newLock.cms_env = cmsEnv; | ||
|
||
const data = JSON.stringify(newLock, null, 2); | ||
|
||
// Update the lockfile | ||
await writeFile(lockfileName, data); | ||
} catch(error) { | ||
console.error('CMS copy config error', error); | ||
} | ||
} | ||
|
||
copyConfig(); |