Skip to content

Commit

Permalink
Merge pull request #1184 from contentstack/staging
Browse files Browse the repository at this point in the history
Merge staging to main
  • Loading branch information
aman19K authored Dec 4, 2023
2 parents 2ae415d + 4267f6b commit 2bebf8b
Show file tree
Hide file tree
Showing 44 changed files with 359 additions and 611 deletions.
240 changes: 180 additions & 60 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.2.1 darwin-arm64 node-v21.1.0
@contentstack/cli-audit/1.3.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^3.8.4",
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.3.16 darwin-arm64 node-v21.1.0
@contentstack/cli-auth/1.3.17 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.6.2 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-bootstrap/1.7.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.6.3",
"version": "1.7.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -17,9 +17,9 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.6.3",
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.16 darwin-arm64 node-v21.1.0
@contentstack/cli-cm-branches/1.0.18 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.17",
"version": "1.0.18",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { cliux } from '@contentstack/cli-utilities';
import { cliux, formatTime, formatDate } from '@contentstack/cli-utilities';
import { entryCreateScript } from './entry-create-script';
import { entryUpdateScript } from './entry-update-script';
import { entryCreateUpdateScript } from './entry-create-update-script';
Expand Down Expand Up @@ -74,9 +74,7 @@ export function getContentTypeMergeStatus(status) {
export function createMergeScripts(contentType: CreateMergeScriptsProps, mergeJobUID: string, content?: any) {
const date = new Date();
const rootFolder = 'merge_scripts';
const fileCreatedAt = `${date.getFullYear()}${
date.getMonth().toString.length === 1 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
}${date.getUTCDate()}${date.getHours()}${date.getMinutes()}${date.getSeconds()}`;
const fileCreatedAt = `${formatDate(date)}${formatTime(date)}`;
const mergeScriptsSlug = `merge_scripts_${mergeJobUID}_${fileCreatedAt}`;

const fullPath = `${rootFolder}/${mergeScriptsSlug}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.3.14 darwin-arm64 node-v21.1.0
@contentstack/cli-cm-bulk-publish/1.3.15 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"dotenv": "^16.1.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.7.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-clone/1.8.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.7.1",
"version": "1.8.0",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@contentstack/cli-cm-export": "~1.10.1",
"@contentstack/cli-cm-import": "~1.11.1",
"@contentstack/cli-cm-export": "~1.10.2",
"@contentstack/cli-cm-import": "~1.12.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"@colors/colors": "^1.5.0",
"async": "^3.2.4",
"chalk": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"format": "eslint src/**/*.ts --fix"
},
"dependencies": {
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"contentstack": "^3.10.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-config/1.4.14 darwin-arm64 node-v21.1.0
@contentstack/cli-config/1.4.15 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"chalk": "^4.1.0",
"fast-csv": "^4.3.6",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.10.1 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-export/1.10.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-export",
"description": "Contentstack CLI plugin to export content from stack",
"version": "1.10.1",
"version": "1.10.2",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
const managementTokenAlias = exportCmdFlags['management-token-alias'] || exportCmdFlags['alias'];

if (managementTokenAlias) {
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`);
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`) || {};
config.management_token = token;
config.apiKey = apiKey;
if (!config.management_token) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.11.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-import/1.12.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
9 changes: 5 additions & 4 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.11.1",
"version": "1.12.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.7",
"@contentstack/cli-utilities": "~1.5.8",
"@contentstack/management": "~1.12.0",
"@oclif/core": "^2.9.3",
"axios": "^1.6.0",
Expand All @@ -21,7 +21,8 @@
"mkdirp": "^1.0.4",
"promise-limit": "^2.7.0",
"tslib": "^2.4.1",
"winston": "^3.7.2"
"winston": "^3.7.2",
"uuid": "^9.0.0"
},
"devDependencies": {
"@oclif/test": "^1.2.6",
Expand Down Expand Up @@ -97,4 +98,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default class ImportCommand extends Command {
'replace-existing': flags.boolean({
required: false,
description: 'Replaces the existing module in the target stack.',
dependsOn: ['module'],
}),
'skip-existing': flags.boolean({
required: false,
Expand Down
16 changes: 3 additions & 13 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentstackClient, HttpClient } from '@contentstack/cli-utilities';
import { addLocale, ContentstackClient } from '@contentstack/cli-utilities';

import startModuleImport from './modules';
import startJSModuleImport from './modules-js';
Expand Down Expand Up @@ -26,19 +26,9 @@ class ModuleImporter {

// Temporarily adding this api call to verify management token has read and write permissions
// TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side
const httpClient = new HttpClient({
headers: { api_key: this.importConfig.apiKey, authorization: this.importConfig.management_token },
});

const { data } = await httpClient.post(`https://${this.importConfig.host}/v3/locales`, {
locale: {
name: 'English',
code: 'en-us',
},
});

if (data.error_code === 161) {
throw new Error(data.error_message);
if (this.importConfig.management_token) {
await addLocale(this.importConfig.apiKey, this.importConfig.management_token, this.importConfig.host);
}

if (!this.importConfig.master_locale) {
Expand Down
40 changes: 35 additions & 5 deletions packages/contentstack-import/src/import/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import isEmpty from 'lodash/isEmpty';
import uniq from 'lodash/uniq';
import { existsSync } from 'node:fs';
import includes from 'lodash/includes';
import { v4 as uuid } from 'uuid';
import { resolve as pResolve, join } from 'node:path';
import { FsUtility } from '@contentstack/cli-utilities';

import config from '../../config';
import { log, formatError } from '../../utils';
import { log, formatError, formatDate } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
import { ModuleClassParams } from '../../types';

Expand All @@ -28,6 +29,7 @@ export default class ImportAssets extends BaseClass {
private assetsUidMap: Record<string, unknown> = {};
private assetsUrlMap: Record<string, unknown> = {};
private assetsFolderMap: Record<string, unknown> = {};
private rootFolder: { uid: string; name: string; parent_uid: string; created_at: string };

constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
super({ importConfig, stackAPIClient });
Expand Down Expand Up @@ -227,6 +229,9 @@ export default class ImportAssets extends BaseClass {

if (asset.parent_uid) {
asset.parent_uid = this.assetsFolderMap[asset.parent_uid];
} else if (this.importConfig.replaceExisting) {
// adds the root folder as parent for all assets in the root level
asset.parent_uid = this.assetsFolderMap[this.rootFolder.uid];
}

apiOptions.apiData = asset;
Expand Down Expand Up @@ -304,23 +309,48 @@ export default class ImportAssets extends BaseClass {
* @returns {Array<Record<string, any>>} Array<Record<string, any>>
*/
constructFolderImportOrder(folders: any): Array<Record<string, any>> {
let parentUid: unknown[] = [];
let parentUIds: unknown[] = [];

// NOTE: Read root folder
const importOrder = filter(folders, { parent_uid: null }).map(({ uid, name, parent_uid, created_at }) => {
parentUid.push(uid);
parentUIds.push(uid);
return { uid, name, parent_uid, created_at };
});

while (!isEmpty(parentUid)) {
while (!isEmpty(parentUIds)) {
// NOTE: Read nested folders every iteration until we find empty folders
parentUid = filter(folders, ({ parent_uid }) => includes(parentUid, parent_uid)).map(
parentUIds = filter(folders, ({ parent_uid }) => includes(parentUIds, parent_uid)).map(
({ uid, name, parent_uid, created_at }) => {
importOrder.push({ uid, name, parent_uid, created_at });
return uid;
},
);
}

if (this.importConfig.replaceExisting) {
// Note: adds a root folder to distinguish latest asset uploads
// Todo: This temporary approach should be updated with asset and folder overwrite strategy, which follows
// folder overwrite
// 1. Create folder trees, 2. Export all target stack folders, 3.Match the source to target folders and create a list of existing folders
// 4. Replace existing folders
// Asset overwrite
// 1. Search asset with title + filename + type
// 2. if there are multiple assets fetched with same query, then check the parent uid against mapper created while importing folders
// 3. Replace matched assets
this.rootFolder = {
uid: uuid(),
name: `Import-${formatDate()}`,
parent_uid: null,
created_at: null,
};
filter(importOrder, (folder, index) => {
if (!folder.parent_uid) {
importOrder.splice(index, 1, { ...folder, parent_uid: this.rootFolder.uid });
}
});
// NOTE: Adds root folder
importOrder.unshift(this.rootFolder);
}
return importOrder;
}
}
Loading

0 comments on commit 2bebf8b

Please sign in to comment.