Skip to content

Commit

Permalink
v2.11.0 release
Browse files Browse the repository at this point in the history
v2.11.0
  • Loading branch information
jimwashbrook authored Nov 15, 2024
2 parents 3feb15b + 006430a commit 749daa7
Show file tree
Hide file tree
Showing 536 changed files with 9,089 additions and 100,832 deletions.
6 changes: 6 additions & 0 deletions contentful/content-management/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ MANAGEMENT_TOKEN="Contentful management token"
DELIVERY_TOKEN="Contentful delivery token for environment"
SPACE_ID="Contentful space id"
ENVIRONMENT="PlanTech_DevAndTest"

# Path to json file to import
CONTENT_FILE="./some-content.json"

# Skip imports of content models when using importContent
SKIP_CONTENT_MODEL=true
21 changes: 21 additions & 0 deletions contentful/content-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,24 @@ This can be used as a fallback
```bash
npm run crud-operation YYYYMMDD-HHMM-description-of-crud-operation.js
```
____

## Importing Content

- importing content can be achieved using the `import-content` script, which will import content from a json file into a specified environment. The json file should be in the format of the `export-processor` export outputs
- `import-content` uses the `contentful-import` npm package to do the importing


### Usage

1. Setup `.env` (copy `.env.example` and setup fields as necessary)
2. cd into the `content-management` directory
3. Run `npm install`
4. run `node import-content`

Required Environment variables
`CONTENT_FILE`
`SPACE_ID`
`MANAGEMENT_TOKEN`
`ENVIRONMENT` (environmentId default is 'master')
`SKIP_CONTENT_MODEL` (optional, default is false)
14 changes: 14 additions & 0 deletions contentful/content-management/helpers/validate-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function validateEnvironment() {
const allowedEnvironments = ['PlanTech_DevAndTest', 'PlanTech_StagingAndProduction'];
const environment = process.env.ENVIRONMENT;

if (!environment) {
throw new Error('ENVIRONMENT environment variable is not set.');
}

if (!allowedEnvironments.includes(environment)) {
throw new Error(`Invalid Contentful environment`);
}

return environment;
}
31 changes: 31 additions & 0 deletions contentful/content-management/import-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('dotenv').config();

const contentfulImport = require('contentful-import');
const fs = require('fs');
const validateEnvironment = require("./helpers/validate-environment");

async function importContentfulData() {
const options = {
contentFile: process.env.CONTENT_FILE,
spaceId: process.env.SPACE_ID,
managementToken: process.env.MANAGEMENT_TOKEN,
environmentId: process.env.ENVIRONMENT,
skipContentModel: process.env.SKIP_CONTENT_MODEL === 'true' ? true : false
};

validateEnvironment()

if (!fs.existsSync(options.contentFile)) {
throw new Error(`File not found: ${options.contentFile}`);
}

try {
await contentfulImport(options);
console.log(`Import completed successfully from ${options.contentFile}`);
} catch (error) {
console.error('Error during import:', error);
throw error;
}
}

importContentfulData()
Loading

0 comments on commit 749daa7

Please sign in to comment.