Skip to content

Commit

Permalink
Merge pull request #6 from AtidaTech/release-0.1.5
Browse files Browse the repository at this point in the history
Release 0.1.5
  • Loading branch information
fciacchi authored Jun 7, 2023
2 parents e68875a + 3e8db75 commit 603690a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ Or, if using [yarn 🔗](https://yarnpkg.com/lang/en/):
yarn add contentful-cli-export
```

> Similarly, if you are using [Bun 🔗](https://bun.sh), just run `bun add contentful-cli-export`
> Similarly, if you are using [Bun 🔗](https://bun.sh), just run<br />`bun add contentful-cli-export`
### Requirements

* `node` >= 14.0.0
* `npm` >= 8.5.5
* `contentful-management` >= 7.50.0
* `contentful-export` >= 7.18.7
* [contentful-lib-helpers](https://www.npmjs.com/package/contentful-lib-helpers) >= 1.9.0
* [contentful-lib-helpers](https://www.npmjs.com/package/contentful-lib-helpers) >= 0.1.10

### Set-up

Expand Down
46 changes: 18 additions & 28 deletions contentful-cli-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DEFAULT_EXPORT_DIR = 'export/'
envValues?.CMS_MANAGEMENT_TOKEN ?? PLACEHOLDER_MANAGEMENT_TOKEN
const cmsSpaceId = envValues?.CMS_SPACE_ID ?? PLACEHOLDER_SPACE_ID
const cmsMaxEntries =
parseInt(envValues?.CMS_MAX_ALLOWED_LIMIT) ?? DEFAULT_ALLOWED_LIMIT
parseInt(envValues?.CMS_MAX_ALLOWED_LIMIT, 10) ?? DEFAULT_ALLOWED_LIMIT
const cmsExportDir = envValues?.CMS_EXPORT_DIR ?? DEFAULT_EXPORT_DIR

const initialSettings = await parseArguments(
Expand Down Expand Up @@ -101,23 +101,21 @@ async function parseArguments(
const parsedArgs = minimist(process.argv.slice(2))
await checkArgs(parsedArgs)

let environmentId = null
const spaceId = parsedArgs['space-id'] ?? cmsSpaceId
const managementToken =
parsedArgs['management-token'] ?? parsedArgs['mt'] ?? cmsManagementToken
const maxEntries = parsedArgs['max-allowed-limit'] ?? cmsMaxEntries
const {
'space-id': spaceId = cmsSpaceId,
'management-token': managementToken = parsedArgs['mt'] ??
cmsManagementToken,
'max-allowed-limit': maxEntries = cmsMaxEntries
} = parsedArgs

const rootDestinationFolder = await getDestinationFolder(
rootFolder,
cmsExportDir,
parsedArgs
)

if (
parsedArgs.hasOwnProperty('from') ||
parsedArgs.hasOwnProperty('environment-id')
) {
environmentId = parsedArgs.from ?? parsedArgs['environment-id']
} else {
const environmentId = parsedArgs.from || parsedArgs['environment-id']
if (!environmentId) {
console.error('@@/ERROR: An environment-id should be specified')
process.exit(1)
}
Expand Down Expand Up @@ -160,24 +158,14 @@ async function parseArguments(
* @throws {Error} If both 'management-token' and 'mt' options are specified.
*/
async function checkArgs(parsedArgs) {
if (
(parsedArgs.hasOwnProperty('from') &&
parsedArgs.hasOwnProperty('environment-id')) ||
!(
parsedArgs.hasOwnProperty('from') ||
parsedArgs.hasOwnProperty('environment-id')
)
) {
if (!(Boolean(parsedArgs.from) ^ Boolean(parsedArgs['environment-id']))) {
console.error(
"@@/ERROR: Only one of the two options '--environment-id' or '--from' should be specified"
)
process.exit(1)
}

if (
parsedArgs.hasOwnProperty('management-token') &&
parsedArgs.hasOwnProperty('mt')
) {
if (Boolean(parsedArgs['management-token']) && Boolean(parsedArgs.mt)) {
console.error(
"@@/ERROR: Only one of the two options '--management-token' or '--mt' can be specified"
)
Expand All @@ -192,7 +180,7 @@ async function checkArgs(parsedArgs) {
* @param {string} cmsExportDir - The CMS Default Export Directory.
* @param {Object} parsedArgs - The object that contains the parsed command line arguments.
*
* @returns {Promise<object>} An object containing the evaluated destination folder and a flag indicating whether a custom folder was used.
* @returns {Promise<string>} The path of the evaluated destination folder.
* @property {string} destinationFolder - The destination folder for the export.
*
* @throws {Error} If the destination folder does not exist or is not accessible.
Expand Down Expand Up @@ -251,8 +239,6 @@ async function extractOptions(initialSettings) {
const exportDirname = rootFolder + defaultExportName + '/'
const mainFolder = isCompressed ? rootFolder : exportDirname

fileSystem.mkdirSync(exportDirname)

let contentFile = defaultExportName + '.json'
let logFilePath = mainFolder + defaultExportName + '.log'

Expand All @@ -266,8 +252,10 @@ async function extractOptions(initialSettings) {
))
) {
console.error(
"@@/ERROR: Unable to retrieve Destination environment '" +
"@@/ERROR: Unable to retrieve Destination environment-id '" +
initialSettings?.environmentId +
"' for space-id '" +
initialSettings?.spaceId +
"'!"
)
console.error(
Expand All @@ -276,6 +264,8 @@ async function extractOptions(initialSettings) {
process.exit(1)
}

fileSystem.mkdirSync(exportDirname)

console.log(
'##/INFO: Export of space-id "' +
initialSettings?.spaceId +
Expand Down
23 changes: 10 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentful-cli-export",
"version": "0.1.4",
"version": "0.1.5",
"type": "module",
"description": "Contentful CLI Export Environment",
"homepage": "https://github.com/AtidaTech/contentful-cli-export",
Expand Down Expand Up @@ -31,10 +31,10 @@
"lint-fix": "node_modules/eslint/bin/eslint.js --resolve-plugins-relative-to ./ --ext js,mjs,cjs,jsx,ts,tsx ./contentful-cli-export.js --fix"
},
"dependencies": {
"contentful-management": ">7.50.0",
"contentful-lib-helpers": ">=0.1.9",
"contentful-export": ">=7.18.7",
"adm-zip": "^0.5.9",
"contentful-export": ">=7.18.7",
"contentful-lib-helpers": ">=0.1.10",
"contentful-management": ">7.50.0",
"dateformat": "^4.6.3",
"dotenv": ">=10.0.0",
"fs": "0.0.1-security",
Expand All @@ -43,7 +43,6 @@
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.54.1",
"dotenv": "^16.0.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
Expand Down

0 comments on commit 603690a

Please sign in to comment.