Skip to content

Commit 70cb79d

Browse files
cachrismanKhaledgarbaya
authored andcommitted
feat: Add saveFile boolean option
1 parent 528ead5 commit 70cb79d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Options:
5454
5555
--error-log-file Full path to the error log file [string]
5656
57+
--save-file Save the export as a json file [boolean] [default: true]
58+
5759
--config An optional configuration JSON file containing all the
5860
options for a single run
5961
```
@@ -105,6 +107,7 @@ var options = {
105107
managementToken: '{content_management_api_key}',
106108
maxAllowedItems: 100,
107109
errorLogFile: 'filename',
110+
saveFile: false
108111
...
109112
}
110113
spaceExport(options)

lib/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default function runContentfulExport (usageParams) {
1616
skipContentModel: false,
1717
skipContent: false,
1818
skipWebhooks: false,
19-
maxAllowedLimit: 1000
19+
maxAllowedLimit: 1000,
20+
saveFile: true
2021
}
2122

2223
const configFile = usageParams.config
@@ -97,10 +98,12 @@ export default function runContentfulExport (usageParams) {
9798
})
9899
})
99100
.then((response) => {
100-
fs.existsSync(opts.exportDir) || fs.mkdirSync(opts.exportDir)
101-
const responseFile = `${opts.exportDir}/contentful-export-${clients.source.spaceId}-${Date.now()}.json`
102-
log.info('Writing space data to json file at : ' + responseFile)
103-
fs.writeFileSync(responseFile, jsonStringifySafe(response, null, 4))
101+
if (opts.saveFile) {
102+
fs.existsSync(opts.exportDir) || fs.mkdirSync(opts.exportDir)
103+
const responseFile = `${opts.exportDir}/contentful-export-${clients.source.spaceId}-${Date.now()}.json`
104+
log.info('Writing space data to json file at : ' + responseFile)
105+
fs.writeFileSync(responseFile, jsonStringifySafe(response, null, 4))
106+
}
104107
return response
105108
})
106109
.catch((err) => {

lib/usageParams.js

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export default yargs
6262
describe: 'Full path to the error log file',
6363
type: 'string'
6464
})
65+
.option('save-file', {
66+
describe: 'Save the export as a json file',
67+
type: 'boolean',
68+
default: true
69+
})
6570
.config('config', 'An optional configuration JSON file containing all the options for a single run')
6671
.check(function (argv) {
6772
if (!argv.spaceId) {

0 commit comments

Comments
 (0)