Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ orbs:
jobs:
unit:
docker:
- image: cimg/node:18.18.0
- image: cimg/node:20.19.4
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: npm install
key: dependency-cache-{{ checksum "package-lock.json" }}
- run: npm ci --prefer-offline
- run: npm run build
- run: npm run test:unit
integration:
docker:
- image: cimg/node:18.18.0
- image: cimg/node:20.19.4
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run: npm install
key: dependency-cache-{{ checksum "package-lock.json" }}
- run: npm ci --prefer-offline
- run: npm run build
- run: npm run test:integration
release:
Expand All @@ -31,7 +31,7 @@ jobs:
- checkout
- vault/get-secrets: # Loads vault secrets
template-preset: "semantic-release-ecosystem"
- run: npm install
- run: npm ci --prefer-offline
- run: npm run build
- run: npm run semantic-release
workflows:
Expand Down
1 change: 0 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'standard',
'plugin:jest/recommended',
'plugin:@typescript-eslint/recommended' // Recommended TypeScript rules
],
plugins: ['standard', 'promise', '@typescript-eslint'],
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v20
11 changes: 0 additions & 11 deletions jest.config.js

This file was deleted.

28 changes: 9 additions & 19 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import VerboseRenderer from 'listr-verbose-renderer'
import { startCase } from 'lodash'
import PQueue from 'p-queue'

import { displayErrorLog, setupLogging, writeErrorLogFile } from 'contentful-batch-libs/dist/logging'
import { wrapTask } from 'contentful-batch-libs/dist/listr'
import {
displayErrorLog,
setupLogging,
writeErrorLogFile,
wrapTask,
LogMessage
} from 'contentful-batch-libs'

import initClient from './tasks/init-client'
import getDestinationData from './tasks/get-destination-data'
import pushToSpace from './tasks/push-to-space/push-to-space'
import transformSpace from './transform/transform-space'
import { assertDefaultLocale, assertPayload } from './utils/validations'
import parseOptions from './parseOptions'
import { ContentfulMultiError, LogItem } from './utils/errors'
import { ContentfulMultiError } from './utils/errors'

const ONE_SECOND = 1000

Expand Down Expand Up @@ -66,7 +71,7 @@ type RunContentfulImportParams = {
}

async function runContentfulImport (params: RunContentfulImportParams) {
const log: LogItem[] = []
const log: LogMessage[] = []
const options = await parseOptions(params)
const listrOptions = createListrOptions(options)
const requestQueue = new PQueue({
Expand Down Expand Up @@ -223,19 +228,4 @@ async function runContentfulImport (params: RunContentfulImportParams) {
})
}

// We are providing default exports both for CommonJS and ES6 module
// systems here as a workaround, because we have some contraints which
// don't allow us to generate compatibility for both es6 and common js
// otherwise. We originally wanted to set 'esModuleInterop' to false
// to keep compatibility with direct 'require()' calls in JavaScript,
// ensuring that consumers can simply use 'require("package-name")'
// without the '.default'. However, we have a dependency on
// 'cli-table3' that requires 'esModuleInterop' to be set to true for
// its default imports to work. Thats why we just provide both export
// mechanisms.

// Default export for ES6-style imports
export default runContentfulImport

// Export for CommonJS-style imports
module.exports = runContentfulImport
7 changes: 5 additions & 2 deletions lib/parseOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import format from 'date-fns/format'

import { version } from '../package.json'
import { getHeadersConfig } from './utils/headers'
import { proxyStringToObject, agentFromProxy } from 'contentful-batch-libs/dist/proxy'
import addSequenceHeader from 'contentful-batch-libs/dist/add-sequence-header'
import {
proxyStringToObject,
agentFromProxy,
addSequenceHeader
} from 'contentful-batch-libs'
import { parseChunked } from '@discoveryjs/json-ext'

const SUPPORTED_ENTITY_TYPES = [
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/get-destination-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Promise from 'bluebird'

import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { logEmitter } from 'contentful-batch-libs'
import type { AssetProps, ContentTypeProps, EntryProps, LocaleProps, TagProps, WebhookProps } from 'contentful-management'
import { OriginalSourceData } from '../types'
import PQueue from 'p-queue'
Expand Down Expand Up @@ -105,7 +105,7 @@ function getIdBatches (ids) {
return batches
}

function getPagedBatches(totalFetched: number, total: number) {
function getPagedBatches (totalFetched: number, total: number) {
const batches: { skip: number }[] = []
if (totalFetched >= total) {
return batches
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/init-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createClient } from 'contentful-management'

import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { logEmitter } from 'contentful-batch-libs'

function logHandler (level, data) {
logEmitter.emit(level, data)
Expand Down
3 changes: 1 addition & 2 deletions lib/tasks/push-to-space/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import fs from 'fs'
import { join } from 'path'
import { promisify } from 'util'

import getEntityName from 'contentful-batch-libs/dist/get-entity-name'
import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { getEntityName, logEmitter } from 'contentful-batch-libs'
import { ContentfulAssetError, ContentfulEntityError } from '../../utils/errors'

const stat = promisify(fs.stat)
Expand Down
9 changes: 4 additions & 5 deletions lib/tasks/push-to-space/creation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { find } from 'lodash/collection'
import { assign, get, omitBy, omit } from 'lodash/object'

import getEntityName from 'contentful-batch-libs/dist/get-entity-name'
import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { logEmitter, getEntityName } from 'contentful-batch-libs'
import { ContentfulEntityError } from '../../utils/errors'
import { TransformedSourceData, TransformedSourceDataUnion } from '../../types'
import PQueue from 'p-queue'
Expand Down Expand Up @@ -47,7 +46,7 @@ async function createEntitiesWithConcurrency ({ context, entities, destinationEn

if (destinationEntity && skipUpdates) {
creationSuccessNotifier(operation, entity.transformed)
return
return null
}

return requestQueue.add(async () => {
Expand Down Expand Up @@ -125,8 +124,8 @@ async function createEntry ({ entry, target, skipContentModel, destinationEntiti
}
try {
const createdOrUpdatedEntry = await requestQueue.add(() => {
return destinationEntry
? updateDestinationWithSourceData(destinationEntry, entry.transformed)
return destinationEntry
? updateDestinationWithSourceData(destinationEntry, entry.transformed)
: createEntryInDestination(target, contentTypeId, entry.transformed)
})

Expand Down
3 changes: 1 addition & 2 deletions lib/tasks/push-to-space/publishing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import getEntityName from 'contentful-batch-libs/dist/get-entity-name'
import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { logEmitter, getEntityName } from 'contentful-batch-libs'
import { ContentfulEntityError } from '../../utils/errors'
import { ResourcesUnion } from '../../types'
import PQueue from 'p-queue'
Expand Down
5 changes: 2 additions & 3 deletions lib/tasks/push-to-space/push-to-space.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Listr from 'listr'
import verboseRenderer from 'listr-verbose-renderer'

import { logEmitter } from 'contentful-batch-libs/dist/logging'
import { wrapTask } from 'contentful-batch-libs/dist/listr'
import { logEmitter, wrapTask } from 'contentful-batch-libs'

import * as assets from './assets'
import * as creation from './creation'
Expand Down Expand Up @@ -282,7 +281,7 @@ export default function pushToSpace ({
return
}
const assetsToProcess = await creation.createEntities({
context: { target: ctx.environment, type: 'Asset'},
context: { target: ctx.environment, type: 'Asset' },
entities: sourceData.assets,
destinationEntitiesById: destinationDataById.assets,
skipUpdates: skipAssetUpdates,
Expand Down
2 changes: 1 addition & 1 deletion lib/usageParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default yargs
})
.option('upload-assets', {
describe: 'Uses local asset files and uploads them instead of pointing to the URLs of previously uploaded assets. Requires assets-directory',
type: 'boolean',
type: 'boolean'
})
.implies('upload-assets', 'assets-directory')
.option('assets-directory', {
Expand Down
11 changes: 2 additions & 9 deletions lib/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AssetProps, EditorInterfaceProps, EntryProps } from 'contentful-management'

import { LogMessage } from 'contentful-batch-libs'
export class ContentfulAssetError extends Error {
filePath: string
constructor (message: string, filePath: string) {
Expand All @@ -8,13 +8,6 @@ export class ContentfulAssetError extends Error {
}
}

export type LogItem = {
ts: string
level: string
error?: Error
message?: string
}

export class ContentfulValidationError extends Error {
error?: {
sys: { id: string };
Expand All @@ -29,5 +22,5 @@ export class ContentfulEntityError extends Error {
}

export class ContentfulMultiError extends Error {
errors: LogItem[]
errors: LogMessage[]
}
2 changes: 1 addition & 1 deletion lib/utils/validations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { payloadSchema } from './schema'
import getEntityName from 'contentful-batch-libs/dist/get-entity-name'
import { getEntityName } from 'contentful-batch-libs'

const attachEntityName = (details, payload) => {
details.map((detail) => {
Expand Down
Loading