-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.11.0
- Loading branch information
Showing
536 changed files
with
9,089 additions
and
100,832 deletions.
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
14 changes: 14 additions & 0 deletions
14
contentful/content-management/helpers/validate-environment.js
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,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; | ||
} |
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,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() |
Oops, something went wrong.