|
| 1 | +const yargs = require('yargs') |
| 2 | +const log = require('npmlog') |
| 3 | +const packageFile = require('../package') |
| 4 | + |
| 5 | +const opts = yargs |
| 6 | + .version(packageFile.version || 'Version only available on installed package') |
| 7 | + .usage('Usage: $0 [options]') |
| 8 | + .option('space-id', { |
| 9 | + describe: 'ID of the destination space', |
| 10 | + type: 'string', |
| 11 | + demand: true |
| 12 | + }) |
| 13 | + .option('management-token', { |
| 14 | + describe: 'Management API token for the destination space', |
| 15 | + type: 'string', |
| 16 | + demand: true |
| 17 | + }) |
| 18 | + .option('content-file', { |
| 19 | + describe: 'json file that contains data to be import to your space', |
| 20 | + type: 'string', |
| 21 | + demand: true |
| 22 | + }) |
| 23 | + .config('config', 'Configuration file with required values') |
| 24 | + .check(function (argv) { |
| 25 | + if (!argv.spaceId) { |
| 26 | + log.error('Please provide --space-id to be used to import \n' + |
| 27 | + 'For more info See: https://www.npmjs.com/package/contentful-import' |
| 28 | + ) |
| 29 | + process.exit(1) |
| 30 | + } |
| 31 | + if (!argv.managementToken) { |
| 32 | + log.error('Please provide --management-token to be used for import \n' + |
| 33 | + 'For more info See: https://www.npmjs.com/package/contentful-import' |
| 34 | + ) |
| 35 | + process.exit(1) |
| 36 | + } |
| 37 | + if (!argv.contentFile) { |
| 38 | + log.error('Please provide --content-file to be used for import \n' + |
| 39 | + 'For more info See: https://www.npmjs.com/package/contentful-import' |
| 40 | + ) |
| 41 | + process.exit(1) |
| 42 | + } |
| 43 | + return true |
| 44 | + }) |
| 45 | + .argv |
| 46 | + |
| 47 | +opts.destinationSpace = opts.destinationSpace || opts.spaceId |
| 48 | +opts.sourceManagementToken = opts.sourceManagementToken || opts.managementToken |
| 49 | +opts.exportDir = opts.exportDir || process.cwd() |
| 50 | + |
| 51 | +module.exports = { |
| 52 | + opts: opts, |
| 53 | + errorLogFile: opts.exportDir + '/contentful-import-' + Date.now() + '.log' |
| 54 | +} |
0 commit comments