Skip to content

Commit 6676d88

Browse files
authored
Merge pull request #2251 from contentstack/feat/dx-3734
Removed deprecated code from import setup plugin
2 parents 4732de8 + 5b8c72e commit 6676d88

17 files changed

Lines changed: 296 additions & 113 deletions

File tree

package-lock.json

Lines changed: 53 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-import-setup/.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"sourceType": "module"
99
},
1010
"extends": [
11-
"oclif-typescript",
1211
"plugin:@typescript-eslint/recommended"
1312
],
1413
"rules": {

packages/contentstack-import-setup/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ USAGE
6969
$ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
7070
7171
FLAGS
72-
-B, --branch=<value> The name of the branch where you want to import your content. If you don't mention the
73-
branch name, then by default the content will be imported to the main branch.
7472
-a, --alias=<value> The management token of the destination stack where you will import the content.
7573
-d, --data-dir=<value> The path or the location in your file system where the content, you intend to import, is
7674
stored. For example, -d "C:\Users\Name\Desktop\cli\content". If the export folder has
7775
branches involved, then the path should point till the particular branch. For example,
7876
“-d "C:\Users\Name\Desktop\cli\content\branch_name"
7977
-k, --stack-api-key=<value> API key of the target stack
78+
--branch=<value> The name of the branch where you want to import your content. If you don't mention the
79+
branch name, then by default the content will be imported to the main branch.
8080
--branch-alias=<value> Specify the branch alias where you want to import your content. If not specified, the
8181
content is imported into the main branch by default.
8282
--module=<option>... [optional] Specify the modules/module to import into the target stack. currently options
@@ -87,11 +87,7 @@ DESCRIPTION
8787
Helps to generate mappers and backup folder for importing (overwriting) specific modules
8888
8989
EXAMPLES
90-
$ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
91-
92-
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
93-
94-
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
90+
$ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name> --branch <branch_name>
9591
```
9692

9793
_See code: [src/commands/cm/stacks/import-setup.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts)_

packages/contentstack-import-setup/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@types/mkdirp": "^1.0.2",
2525
"@types/mocha": "^8.2.3",
2626
"@types/node": "^14.18.63",
27+
"@types/proxyquire": "^1.3.31",
2728
"@types/rewire": "^2.5.30",
2829
"@types/tar": "^6.1.13",
2930
"@types/uuid": "^9.0.8",
@@ -34,6 +35,7 @@
3435
"mocha": "^10.8.2",
3536
"nyc": "^15.1.0",
3637
"oclif": "^4.17.46",
38+
"proxyquire": "^2.1.3",
3739
"rewire": "^9.0.1",
3840
"ts-node": "^10.9.2",
3941
"tsx": "^4.20.3",

packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'node:path';
22
import { Command } from '@contentstack/cli-command';
33
import {
44
messageHandler,
5-
printFlagDeprecation,
65
managementSDKClient,
76
flags,
87
FlagInput,
@@ -21,9 +20,7 @@ export default class ImportSetupCommand extends Command {
2120
);
2221

2322
static examples: string[] = [
24-
`csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
25-
`csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>`,
26-
`csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>`,
23+
`csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name> --branch <branch_name>`,
2724
];
2825

2926
static flags: FlagInput = {
@@ -46,27 +43,25 @@ export default class ImportSetupCommand extends Command {
4643
multiple: true,
4744
}),
4845
branch: flags.string({
49-
char: 'B',
5046
description:
5147
"The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
52-
parse: printFlagDeprecation(['-B'], ['--branch']),
53-
exclusive: ['branch-alias']
48+
exclusive: ['branch-alias'],
5449
}),
5550
'branch-alias': flags.string({
5651
description:
57-
"Specify the branch alias where you want to import your content. If not specified, the content is imported into the main branch by default.",
52+
'Specify the branch alias where you want to import your content. If not specified, the content is imported into the main branch by default.',
5853
exclusive: ['branch'],
5954
}),
6055
};
6156

62-
static aliases: string[] = ['cm:import-setup'];
57+
static aliases: string[] = [];
6358

64-
static usage: string = 'cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]';
59+
static usage = 'cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]';
6560

6661
async run(): Promise<void> {
6762
try {
6863
const { flags } = await this.parse(ImportSetupCommand);
69-
let importSetupConfig = await setupImportConfig(flags);
64+
const importSetupConfig = await setupImportConfig(flags);
7065
// Note setting host to create cma client
7166
importSetupConfig.host = this.cmaHost;
7267
importSetupConfig.region = this.region;

packages/contentstack-import-setup/src/import/import-setup.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { ImportConfig, Modules } from '../types';
22
import { backupHandler, log, setupBranchConfig } from '../utils';
33
import { ContentstackClient } from '@contentstack/cli-utilities';
4-
import { validateBranch } from '../utils';
54

65
export default class ImportSetup {
76
protected config: ImportConfig;
8-
private managementAPIClient: ContentstackClient;
9-
private importConfig: ImportConfig;
10-
private stackAPIClient: any;
7+
private readonly managementAPIClient: ContentstackClient;
8+
private readonly importConfig: ImportConfig;
9+
private readonly stackAPIClient: any;
1110
public dependencyTree: { [key: string]: string[] } = {};
1211

1312
constructor(config: ImportConfig, managementAPIClient: ContentstackClient) {
@@ -35,7 +34,7 @@ export default class ImportSetup {
3534
visited.add(module);
3635
const dependencies: Modules[] = this.config.modules[module]?.dependencies || [];
3736

38-
let allDeps: Modules[] = [...dependencies];
37+
const allDeps: Modules[] = [...dependencies];
3938

4039
for (const dependency of dependencies) {
4140
allDeps.push(...getAllDependencies(dependency as ModulesKey));
@@ -53,7 +52,9 @@ export default class ImportSetup {
5352
this.dependencyTree[module] = allDependencies;
5453

5554
// Mark these dependencies as assigned so they won't be included in later modules
56-
allDependencies.forEach((dep) => assignedDependencies.add(dep));
55+
for (const dep of allDependencies) {
56+
assignedDependencies.add(dep);
57+
}
5758
}
5859
}
5960

@@ -107,7 +108,7 @@ export default class ImportSetup {
107108
await this.generateDependencyTree();
108109
await this.runModuleImports();
109110
} catch (error) {
110-
console.log(error);
111+
log(this.config, `Error during import setup: ${error instanceof Error ? error.message : String(error)}`, 'error');
111112
throw error;
112113
}
113114
}

packages/contentstack-import-setup/src/import/modules/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class AssetImportSetup extends BaseImportSetup {
8989
});
9090

9191
if (chunk) {
92-
let apiContent = orderBy(values(chunk as Record<string, any>[]), '_version');
92+
const apiContent = orderBy(values(chunk as Record<string, any>[]), '_version');
9393

9494
await this.makeConcurrentCall(
9595
{

packages/contentstack-import-setup/src/import/modules/taxonomies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class TaxonomiesImportSetup {
1818
private taxonomiesMapperDirPath: string;
1919
private termsMapperDirPath: string;
2020
private localesFilePath: string;
21-
private isLocaleBasedStructure: boolean = false;
21+
private isLocaleBasedStructure = false;
2222
public taxonomiesMapper: Record<string, unknown> = {};
2323
public termsMapper: Record<string, unknown> = {};
2424
public masterLocaleFilePath: string;

packages/contentstack-import-setup/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface InquirePayload {
6262
name: string;
6363
message: string;
6464
choices?: Array<any>;
65-
transformer?: Function;
65+
transformer?: (...args: any[]) => any;
6666
}
6767

6868
export interface User {

packages/contentstack-import-setup/src/utils/file-helper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mkdirp from 'mkdirp';
44
import * as bigJSON from 'big-json';
55
import { FsUtility, sanitizePath } from '@contentstack/cli-utilities';
66

7-
export const readFileSync = function (filePath: string, parse: boolean = true): any {
7+
export const readFileSync = function (filePath: string, parse = true): any {
88
let data;
99
filePath = path.resolve(sanitizePath(filePath));
1010
if (fs.existsSync(filePath)) {
@@ -87,7 +87,7 @@ export const writeLargeFile = function (filePath: string, data: any): Promise<an
8787
const stringifyStream = bigJSON.createStringifyStream({
8888
body: data,
8989
});
90-
var writeStream = fs.createWriteStream(filePath, 'utf-8');
90+
const writeStream = fs.createWriteStream(filePath, 'utf-8');
9191
stringifyStream.pipe(writeStream);
9292
writeStream.on('finish', () => {
9393
resolve('');
@@ -98,9 +98,9 @@ export const writeLargeFile = function (filePath: string, data: any): Promise<an
9898
});
9999
};
100100

101-
export const makeDirectory = function (dir: string): void {
102-
for (let key in arguments) {
103-
const dirname = path.resolve(arguments[key]);
101+
export const makeDirectory = function (...dirs: string[]): void {
102+
for (const dir of dirs) {
103+
const dirname = path.resolve(dir);
104104
if (!fs.existsSync(dirname)) {
105105
mkdirp.sync(dirname);
106106
}

0 commit comments

Comments
 (0)