Skip to content

Commit b1c7fc1

Browse files
committed
added support for branches, global fields
1 parent 51428a6 commit b1c7fc1

File tree

13 files changed

+100
-28
lines changed

13 files changed

+100
-28
lines changed

packages/contentstack-audit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.7.4 darwin-arm64 node-v22.8.0
22+
@contentstack/cli-audit/1.7.4 darwin-arm64 node-v22.2.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND

packages/contentstack-bulk-publish/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-cm-bulk-publish/1.7.0 darwin-arm64 node-v22.2.0
21+
@contentstack/cli-cm-bulk-publish/1.7.1 darwin-arm64 node-v22.2.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-import-setup/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ USAGE
7070
$ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
7171
7272
FLAGS
73+
-B, --branch=<value> The name of the target stack's branch
7374
-a, --alias=<value> alias of the management token
7475
-d, --data-dir=<value> path and location where data is stored
7576
-k, --stack-api-key=<value> API key of the target stack
76-
--modules=<option> [optional] specific module name
77-
<options: content-types|entries|both>
77+
--modules=<option>... [optional] specific module name
78+
<options: global-fields|content-types|entries>
7879
7980
DESCRIPTION
8081
Import content from a stack
@@ -83,7 +84,11 @@ ALIASES
8384
$ csdx cm:import-setup
8485
8586
EXAMPLES
86-
$ csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
87+
$ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
88+
89+
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
90+
91+
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
8792
```
8893

8994
## `csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`
@@ -95,11 +100,12 @@ USAGE
95100
$ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
96101
97102
FLAGS
103+
-B, --branch=<value> The name of the target stack's branch
98104
-a, --alias=<value> alias of the management token
99105
-d, --data-dir=<value> path and location where data is stored
100106
-k, --stack-api-key=<value> API key of the target stack
101-
--modules=<option> [optional] specific module name
102-
<options: content-types|entries|both>
107+
--modules=<option>... [optional] specific module name
108+
<options: global-fields|content-types|entries>
103109
104110
DESCRIPTION
105111
Import content from a stack
@@ -108,7 +114,11 @@ ALIASES
108114
$ csdx cm:import-setup
109115
110116
EXAMPLES
111-
$ csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
117+
$ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
118+
119+
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
120+
121+
$ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
112122
```
113123

114124
_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/src/commands/cm/stacks/import-setup.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export default class ImportSetupCommand extends Command {
1919
static description = messageHandler.parse('Import content from a stack');
2020

2121
static examples: string[] = [
22-
`csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
22+
`csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
23+
`csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>`,
24+
`csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>`,
2325
];
2426

2527
static flags: FlagInput = {
@@ -36,8 +38,14 @@ export default class ImportSetupCommand extends Command {
3638
description: 'alias of the management token',
3739
}),
3840
modules: flags.string({
39-
options: ['content-types', 'entries', 'both'], // only allow the value to be from a discrete set
41+
options: ['global-fields', 'content-types', 'entries'], // only allow the value to be from a discrete set
4042
description: '[optional] specific module name',
43+
multiple: true,
44+
}),
45+
branch: flags.string({
46+
char: 'B',
47+
description: "The name of the target stack's branch",
48+
parse: printFlagDeprecation(['-B'], ['--branch']),
4149
}),
4250
};
4351

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const config: DefaultConfig = {
4747
'global-fields': {
4848
dirName: 'global_fields',
4949
fileName: 'globalfields.json',
50-
dependencies: ['marketplace-apps'],
50+
dependencies: ['extensions', 'marketplace-apps'],
5151
},
5252
'marketplace-apps': {
5353
dirName: 'marketplace_apps',

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Module from 'module';
22
import { ImportConfig, Modules } from '../types';
33
import { backupHandler, log } from '../utils';
44
import { ContentstackClient, formatError } from '@contentstack/cli-utilities';
5+
import { validateBranch } from '../utils';
56

67
export default class ImportSetup {
78
protected config: ImportConfig;
@@ -91,6 +92,10 @@ export default class ImportSetup {
9192
if (backupDir) {
9293
this.config.backupDir = backupDir;
9394
}
95+
if (this.config.branchName) {
96+
await validateBranch(this.stackAPIClient, this.config, this.config.branchName);
97+
}
98+
9499
await this.generateDependencyTree();
95100
await this.runModuleImports();
96101
} catch (error) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as chalk from 'chalk';
2+
import { log, fsUtil } from '../../utils';
3+
import { join } from 'path';
4+
import { ImportConfig, ModuleClassParams } from '../../types';
5+
import BaseImportSetup from './base-setup';
6+
7+
export default class GlobalFieldsImportSetup extends BaseImportSetup {
8+
constructor(options: ModuleClassParams) {
9+
super(options);
10+
}
11+
12+
async start() {
13+
try {
14+
await this.setupDependencies();
15+
log(this.config, `Generate required setup files for global fields`, 'success');
16+
} catch (error) {
17+
log(this.config, `Error generating ${error.message}`, 'error');
18+
}
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import chalk from 'chalk';
2+
import { log } from '../utils';
3+
import { ImportConfig } from 'src/types';
4+
5+
export const validateBranch = async (stackAPIClient: any, config: ImportConfig, branch: any) => {
6+
return new Promise(async (resolve, reject) => {
7+
try {
8+
const data = await stackAPIClient.branch(branch).fetch();
9+
if (data && typeof data === 'object') {
10+
if (data.error_message) {
11+
log(config, chalk.red(data.error_message), 'error');
12+
log(config, chalk.red('No branch found with the name ' + branch), 'error');
13+
reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
14+
} else {
15+
resolve(data);
16+
}
17+
} else {
18+
reject({ message: 'No branch found with the name ' + branch, error: {} });
19+
}
20+
} catch (error) {
21+
log(config, chalk.red('No branch found with the name ' + branch), 'error');
22+
reject({ message: 'No branch found with the name ' + branch, error });
23+
}
24+
});
25+
};

packages/contentstack-import-setup/src/utils/import-config-handler.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,9 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
7878

7979
if (importCmdFlags['branch']) {
8080
config.branchName = importCmdFlags['branch'];
81-
config.branchDir = path.join(sanitizePath(config.contentDir), sanitizePath(config.branchName));
82-
}
83-
84-
const selectedModule = importCmdFlags['modules'] || (await askSelectedModules());
85-
if (selectedModule === 'both') {
86-
config.selectedModules = ['content-types', 'entries'];
87-
} else {
88-
config.selectedModules = [selectedModule];
8981
}
9082

83+
config.selectedModules = importCmdFlags['modules'] || [await askSelectedModules()];
9184
if (importCmdFlags['backup-dir']) {
9285
config.useBackedupDir = importCmdFlags['backup-dir'];
9386
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { fsUtil } from './file-helper';
55
export { default as backupHandler } from './backup-handler';
66
export { log, unlinkFileLogger } from './logger';
77
export * from './log';
8+
export * from './common-helper';

0 commit comments

Comments
 (0)