Skip to content

Commit dcef5ea

Browse files
committed
feat(contentful-export): Exprot Drafts
1 parent c5556e5 commit dcef5ea

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

dist/run-contentful-export.js

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function runContentfulExport(usageParams) {
4949
opts.sourceSpace = opts.sourceSpace || usageParams.spaceId;
5050
opts.sourceManagementToken = opts.sourceManagementToken || usageParams.managementToken;
5151
}
52+
if (opts.includeDrafts) {
53+
opts.deliveryHost = 'preview.contentful.com';
54+
opts.sourceDeliveryToken = opts.previewToken;
55+
}
5256
var clients = (0, _createClients2.default)(opts);
5357
return (0, _getFullSourceSpace2.default)({
5458
managementClient: clients.source.management,

dist/usageParams.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ var opts = yargs.version(packageFile.version || 'Version only available on insta
1212
describe: 'Management API token for the space to be exported.',
1313
type: 'string',
1414
demand: true
15+
}).option('preview-token', {
16+
describe: 'Preview API token for the space to be exported.',
17+
type: 'string',
18+
demand: true
1519
}).option('export-dir', {
1620
describe: 'Defines the path for storing the export json file (default path is the current directory)',
1721
type: 'string'
1822
}).option('download-assets', {
1923
describe: 'With this flags assets will also be downloaded',
2024
type: 'boolean'
2125
}).option('max-allowed-limit', {
22-
describe: 'how many item per page per request default 1000',
26+
describe: 'How many item per page per request default 1000',
2327
type: 'number'
28+
}).options('include-drafts', {
29+
describe: 'Export Drafts entiries',
30+
type: 'boolean'
2431
}).config('config', 'Configuration file with required values').check(function (argv) {
2532
if (!argv.spaceId) {
2633
log.error('Please provide --space-id to be used to export \n' + 'For more info See: https://www.npmjs.com/package/contentful-export');
@@ -30,6 +37,15 @@ var opts = yargs.version(packageFile.version || 'Version only available on insta
3037
log.error('Please provide --management-token to be used for export \n' + 'For more info See: https://www.npmjs.com/package/contentful-export');
3138
process.exit(1);
3239
}
40+
if (argv.includeDrafts && !argv.previewToken) {
41+
log.error('Please provide a preview API token to be able to get draft or set --include-drafts false');
42+
process.exit(1);
43+
}
44+
if (!argv.includeDrafts && argv.previewToken) {
45+
log.error('Please make sure to specify --include-drafts to be able to get drafts');
46+
process.exit(1);
47+
}
48+
3349
return true;
3450
}).argv;
3551

lib/run-contentful-export.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export default function runContentfulExport (usageParams) {
1717
opts.sourceSpace = opts.sourceSpace || usageParams.spaceId
1818
opts.sourceManagementToken = opts.sourceManagementToken || usageParams.managementToken
1919
}
20+
if (opts.includeDrafts) {
21+
opts.deliveryHost = 'preview.contentful.com'
22+
opts.sourceDeliveryToken = opts.previewToken
23+
}
2024
const clients = createClients(opts)
2125
return getFullSourceSpace({
2226
managementClient: clients.source.management,

lib/usageParams.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const opts = yargs
1515
type: 'string',
1616
demand: true
1717
})
18+
.option('preview-token', {
19+
describe: 'Preview API token for the space to be exported.',
20+
type: 'string',
21+
demand: true
22+
})
1823
.option('export-dir', {
1924
describe: 'Defines the path for storing the export json file (default path is the current directory)',
2025
type: 'string'
@@ -24,9 +29,13 @@ const opts = yargs
2429
type: 'boolean'
2530
})
2631
.option('max-allowed-limit', {
27-
describe: 'how many item per page per request default 1000',
32+
describe: 'How many item per page per request default 1000',
2833
type: 'number'
2934
})
35+
.options('include-drafts', {
36+
describe: 'Export Drafts entiries',
37+
type: 'boolean'
38+
})
3039
.config('config', 'Configuration file with required values')
3140
.check(function (argv) {
3241
if (!argv.spaceId) {
@@ -41,6 +50,15 @@ const opts = yargs
4150
)
4251
process.exit(1)
4352
}
53+
if (argv.includeDrafts && !argv.previewToken) {
54+
log.error('Please provide a preview API token to be able to get draft or set --include-drafts false')
55+
process.exit(1)
56+
}
57+
if (!argv.includeDrafts && argv.previewToken) {
58+
log.error('Please make sure to specify --include-drafts to be able to get drafts')
59+
process.exit(1)
60+
}
61+
4462
return true
4563
})
4664
.argv

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"contentful",
3535
"contentful-export"
3636
],
37-
"author": "Contentful <opensource@contentful.com>",
37+
"author": "Khaled Garbaya <khaled@contentful.com>",
3838
"license": "MIT",
3939
"bugs": {
4040
"url": "https://github.com/contentful/contentful-export/issues"
@@ -43,7 +43,7 @@
4343
"bluebird": "^3.3.3",
4444
"fs-extra": "^0.30.0",
4545
"request": "^2.78.0",
46-
"contentful-batch-libs": "4.5.0",
46+
"contentful-batch-libs": "4.7.0",
4747
"json-stringify-safe": "^5.0.1",
4848
"lodash": "^4.0.0",
4949
"npmlog": "^4.0.0",

0 commit comments

Comments
 (0)