Skip to content

Commit acb48bf

Browse files
committed
feat(usageParams): Capture commandline params
1 parent 9ccbeb9 commit acb48bf

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
try {
2+
module.exports = require('./dist/run-contentful-import').default
3+
} catch (err) {
4+
if (err.code === 'MODULE_NOT_FOUND') {
5+
require('babel-register')
6+
module.exports = require('./lib/run-contentful-import').default
7+
} else {
8+
console.log(err)
9+
process.exit(1)
10+
}
11+
}

lib/run-contentful-import.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import fs from 'fs'
2+
import Promise from 'bluebird'
3+
var log = require('npmlog')
4+
5+
Promise.promisifyAll(fs)
6+
export default function runContentfulImport(usageParams) {
7+
8+
}

lib/usageParams.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)