Skip to content

Commit

Permalink
feat(summary): adds table about what to import and a duration time to…
Browse files Browse the repository at this point in the history
… the end
  • Loading branch information
axe312ger committed Apr 7, 2017
1 parent c100370 commit 7ffa949
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
6 changes: 3 additions & 3 deletions bin/contentful-import
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ var log = require('npmlog')
var runContentfulImport = require('../dist/index')
var usageParams = require('../dist/usageParams')

log.info('Contentful Import Tool')
log.info('Importing data ...')
log.info('import', 'Contentful Import Tool')
log.info('import', 'Importing data ...')

runContentfulImport(usageParams)
.then((result) => {
process.exit(0)
})
.catch(function (err) {
log.error('', 'Failed within\n', err)
log.error('import', 'Failed within\n', err)
process.exit(1)
})
45 changes: 40 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import getTransformedDestinationResponse from './get-transformed-destination-res
import log from 'npmlog'
import fs from 'fs'
import { resolve } from 'path'
import { startCase } from 'lodash'
import Table from 'cli-table2'
import moment from 'moment'

const summary = {}

export default function runContentfulImport (usageParams) {
const defaultOpts = {
Expand All @@ -15,6 +20,8 @@ export default function runContentfulImport (usageParams) {
skipContentPublishing: false
}

summary.startTime = moment()

const configFile = usageParams.config
? require(resolve(process.cwd(), usageParams.config))
: {}
Expand Down Expand Up @@ -91,13 +98,41 @@ export default function runContentfulImport (usageParams) {
skipContentModel: opts.skipContentModel,
skipContentPublishing: opts.skipContentPublishing
})
.then((responses) => {
log.info('Successfully Imported all data')
return true
})
})
.then((response) => {
log.info('import', 'Finished importing all data')

const infoTable = new Table()

infoTable.push([{colSpan: 2, content: 'The following entities were imported'}])

Object.keys(opts.content).forEach((type) => {
if (opts.skipLocales && type === 'locales') {
return
}

if (opts.skipContentModel && type === 'contentTypes') {
return
}

if (opts.contentModelOnly && !(['contentTypes', 'locales'].includes(type))) {
return
}

infoTable.push([startCase(type), opts.content[type].length])
})

console.log(infoTable.toString())

const durationHuman = summary.startTime.fromNow(true)
const durationSeconds = moment().diff(summary.startTime, 'seconds')

log.info('import', `The import took ${durationHuman} (${durationSeconds}s)`)

return response
})
.catch((err) => {
log.error(err)
log.error('import', err)
throw err
})
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
},
"dependencies": {
"bluebird": "^3.3.3",
"cli-table2": "^0.2.0",
"contentful-batch-libs": "^5.3.0",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.0.0",
"moment": "^2.18.1",
"npmlog": "^4.0.0",
"yargs": "^7.0.2"
},
Expand Down
19 changes: 18 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,15 @@ cli-cursor@^1.0.1, cli-cursor@^1.0.2:
dependencies:
restore-cursor "^1.0.1"

cli-table2@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/cli-table2/-/cli-table2-0.2.0.tgz#2d1ef7f218a0e786e214540562d4bd177fe32d97"
dependencies:
lodash "^3.10.1"
string-width "^1.0.1"
optionalDependencies:
colors "^1.1.2"

cli-width@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a"
Expand Down Expand Up @@ -919,6 +928,10 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

colors@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"

combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
Expand Down Expand Up @@ -2399,7 +2412,7 @@ lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

lodash@^3.6.0:
lodash@^3.10.1, lodash@^3.6.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

Expand Down Expand Up @@ -2533,6 +2546,10 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
dependencies:
minimist "0.0.8"

moment@^2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

ms@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
Expand Down

0 comments on commit 7ffa949

Please sign in to comment.