diff --git a/install.sh b/install.sh index c90256b4d2..7055db733c 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ echo 'Installing Contentstack CLI' npm install || { echo -e '\e[31mFailed to install root dependencies.' && exit 1; } npx lerna clean -y npx lerna bootstrap -npx lerna run pack || { echo -e '\e[31mInstallable tarball creation failed.' && exit 1; } +npx lerna run prepack || { echo -e '\e[31mInstallable tarball creation failed.' && exit 1; } echo 'Installtion, Done!!!' cd packages/contentstack ./bin/run --help diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index df16644f39..e80b1b59e6 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -5,8 +5,8 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-export": "^1.0.0", "@contentstack/cli-command": "^1.0.0", + "@contentstack/cli-cm-export": "^1.0.0", "@contentstack/cli-utilities": "^1.0.0", "@contentstack/management": "^1.3.0", "@oclif/command": "^1.8.16", @@ -69,4 +69,4 @@ "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-import/<%- commandPath %>" }, "repository": "https://github.com/contentstack/cli" -} +} \ No newline at end of file diff --git a/packages/contentstack-import/src/lib/import/entries.js b/packages/contentstack-import/src/lib/import/entries.js index f174a09a70..a6f5978fcd 100755 --- a/packages/contentstack-import/src/lib/import/entries.js +++ b/packages/contentstack-import/src/lib/import/entries.js @@ -685,7 +685,35 @@ importEntries.prototype = { locale: lang, error: error, }); - return rejectUpdatedUids(error); + if (error) { + addlogs( + config, + chalk.red( + 'Entry Uid: ' + + entry.uid + + ' of Content Type: ' + + ctUid + + ' failed to update in locale: ' + + lang + + error.message, + ), + 'error', + ); + addlogs( + config, + chalk.red( + 'Entry Uid: ' + + entry.uid + + ' of Content Type: ' + + ctUid + + ' failed to update in locale: ' + + lang + + error.errorMessage, + ), + 'error', + ); + } + return resolveUpdatedUids(); }); }); }, @@ -704,7 +732,19 @@ importEntries.prototype = { .catch(function (error) { // error while executing entry in batch addlogs(config, chalk.red('Failed re-post entries at batch no: ' + (index + 1)), 'error'); - throw error; + if (error) { + addlogs( + config, + chalk.red('Failed re-post entries at batch no: ' + (index + 1) + error.message), + 'error', + ); + addlogs( + config, + chalk.red('Failed re-post entries at batch no: ' + (index + 1) + error.errorMessage), + 'error', + ); + } + // throw error; }); }, { @@ -726,16 +766,34 @@ importEntries.prototype = { // error while updating entries with references addlogs( config, - chalk.red( - "Failed while importing entries of Content Type: '" + - ctUid + - "' in language: '" + - lang + - "' successfully!", - ), + chalk.red("Failed while importing entries of Content Type: '" + ctUid + "' in language: '" + lang), 'error', ); - throw error; + if (error) { + addlogs( + config, + chalk.red( + "Failed while importing entries of Content Type: '" + + ctUid + + "' in language: '" + + lang + + error.message, + ), + 'error', + ); + addlogs( + config, + chalk.red( + "Failed while importing entries of Content Type: '" + + ctUid + + "' in language: '" + + lang + + error.errorMessage, + ), + 'error', + ); + } + // throw error; }); }, { diff --git a/packages/contentstack-import/src/lib/util/lookupReplaceAssets.js b/packages/contentstack-import/src/lib/util/lookupReplaceAssets.js index 867d64b571..69262351d4 100644 --- a/packages/contentstack-import/src/lib/util/lookupReplaceAssets.js +++ b/packages/contentstack-import/src/lib/util/lookupReplaceAssets.js @@ -59,12 +59,12 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe } // added rich_text_type field check because some marketplace extensions also // have data_type has json - if (schema[i].data_type === "json" && schema[i].field_metadata.rich_text_type) { - parent.push(schema[i].uid) + if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { + parent.push(schema[i].uid); // findFileUrls(schema[i], entry, assetUrls) - findAssetIdsFromJsonRte(data.entry, data.content_type.schema) + findAssetIdsFromJsonRte(data.entry, data.content_type.schema); // maybe only one of these checks would be enough - parent.pop() + parent.pop(); } } }; @@ -75,11 +75,11 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe case 'blocks': { if (entry[ctSchema[i].uid]) { if (ctSchema[i].multiple) { - entry[ctSchema[i].uid].forEach(e => { - let key = Object.keys(e).pop() - let subBlock = ctSchema[i].blocks.filter(e => e.uid === key).pop() - findAssetIdsFromJsonRte(e[key], subBlock.schema) - }) + entry[ctSchema[i].uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = ctSchema[i].blocks.filter((e) => e.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); } } break; @@ -88,11 +88,11 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe case 'group': { if (entry[ctSchema[i].uid]) { if (ctSchema[i].multiple) { - entry[ctSchema[i].uid].forEach(e => { - findAssetIdsFromJsonRte(e, ctSchema[i].schema) - }) + entry[ctSchema[i].uid].forEach((e) => { + findAssetIdsFromJsonRte(e, ctSchema[i].schema); + }); } else { - findAssetIdsFromJsonRte(entry[ctSchema[i].uid], ctSchema[i].schema) + findAssetIdsFromJsonRte(entry[ctSchema[i].uid], ctSchema[i].schema); } } break; @@ -100,11 +100,11 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe case 'json': { if (entry[ctSchema[i].uid] && ctSchema[i].field_metadata.rich_text_type) { if (ctSchema[i].multiple) { - entry[ctSchema[i].uid].forEach(jsonRteData => { - gatherJsonRteAssetIds(jsonRteData) - }) + entry[ctSchema[i].uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); } else { - gatherJsonRteAssetIds(entry[ctSchema[i].uid]) + gatherJsonRteAssetIds(entry[ctSchema[i].uid]); } } break; @@ -112,22 +112,22 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe } } } - + function gatherJsonRteAssetIds(jsonRteData) { - jsonRteData.children.forEach(element => { + jsonRteData.children.forEach((element) => { if (element.type) { switch (element.type) { case 'a': case 'p': { if (element.children && element.children.length > 0) { - gatherJsonRteAssetIds(element) + gatherJsonRteAssetIds(element); } break; } case 'reference': { - if (Object.keys(element.attrs).length > 0 && element.attrs.type === "asset") { + if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') { if (assetUids.indexOf(element.attrs['asset-uid']) === -1) { - assetUids.push(element.attrs['asset-uid']) + assetUids.push(element.attrs['asset-uid']); } // assets references inserted as link inside entry reference inserted as link did not have asset-link property // instead it had an 'href' property. I haven't seen 'asset-link' and 'href' together yet @@ -135,22 +135,22 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe // (element.attrs['asset-link']) ? assetUrls.push(element.attrs['asset-link']) : assetUrls.push(element.attrs['asset-link']) if (element.attrs['asset-link']) { if (assetUrls.indexOf(element.attrs['asset-link']) === -1) { - assetUrls.push(element.attrs['asset-link']) + assetUrls.push(element.attrs['asset-link']); } } else if (element.attrs['href']) { if (assetUrls.indexOf(element.attrs['href']) === -1) { - assetUrls.push(element.attrs['href']) + assetUrls.push(element.attrs['href']); } } } if (element.children && element.children.length > 0) { - gatherJsonRteAssetIds(element) + gatherJsonRteAssetIds(element); } break; } } } - }) + }); } find(data.content_type.schema, data.entry); @@ -162,7 +162,7 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe assetUrls.forEach(function (assetUrl) { var mappedAssetUrl = mappedAssetUrls[assetUrl]; if (typeof mappedAssetUrl !== 'undefined') { - entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + entry = entry.replace(new RegExp(escapeUrl(assetUrl), 'img'), mappedAssetUrl); matchedUrls.push(mappedAssetUrl); } else { unmatchedUrls.push(assetUrl); @@ -299,3 +299,10 @@ function updateFileFields(objekt, parent, pos, mappedAssetUids, matchedUids, unm parent[pos] = _.compact(objekt); } } + +function escapeUrl(assetUrl) { + if (typeof assetUrl !== 'string') { + throw new TypeError('url should be a string ' + assetUrl); + } + return assetUrl.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'); +} diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 08c49d027c..e81b576cc6 100644 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -21,8 +21,9 @@ "lint": "eslint src/**/*.ts" }, "dependencies": { + "@contentstack/cli-utilities": "^1.0.0", + "@contentstack/cli-command": "^1.0.0", "@contentstack/cli-auth": "^1.0.0", - "@contentstack/cli-cm-bootstrap": "^1.0.7", "@contentstack/cli-cm-bulk-publish": "^1.0.0", "@contentstack/cli-cm-clone": "^1.0.0", "@contentstack/cli-cm-export": "^1.0.0", @@ -30,10 +31,9 @@ "@contentstack/cli-cm-import": "^1.0.0", "@contentstack/cli-cm-migrate-rte": "^1.0.5", "@contentstack/cli-cm-seed": "^1.0.11", - "@contentstack/cli-command": "^1.0.0", + "@contentstack/cli-cm-bootstrap": "^1.0.7", "@contentstack/cli-config": "^1.0.0", "@contentstack/cli-migration": "^1.0.0", - "@contentstack/cli-utilities": "^1.0.0", "@contentstack/management": "^1.3.0", "@oclif/command": "^1.8.16", "@oclif/config": "^1.18.3",