diff --git a/bin/contentful-import b/bin/contentful-import index f7865ecc..69dcef50 100755 --- a/bin/contentful-import +++ b/bin/contentful-import @@ -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) }) diff --git a/lib/index.js b/lib/index.js index bae4b9d6..c9e98898 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = { @@ -15,6 +20,8 @@ export default function runContentfulImport (usageParams) { skipContentPublishing: false } + summary.startTime = moment() + const configFile = usageParams.config ? require(resolve(process.cwd(), usageParams.config)) : {} @@ -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 }) } diff --git a/package.json b/package.json index e4644139..2733eb1b 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/yarn.lock b/yarn.lock index ef52cdb9..6f9c79b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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"