@contentstack/cli-config 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,33 +1,57 @@
1
- @contentstack/cli-config
2
- ===
1
+ # @contentstack/cli-config
3
2
 
4
3
  The config namespace contains all the commands that you will need to configure the CLI as per your requirements. Contentstack currently supports three regions: North America, Europe and Azure North America. [Configure the CLI documentation](https://www.contentstack.com/docs/developers/cli/configure-the-cli)
5
4
 
6
5
  [![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
7
6
 
8
7
  <!-- toc -->
8
+ * [@contentstack/cli-config](#contentstackcli-config)
9
9
  * [Usage](#usage)
10
10
  * [Commands](#commands)
11
11
  <!-- tocstop -->
12
+
12
13
  # Usage
14
+
13
15
  <!-- usage -->
14
16
  ```sh-session
15
17
  $ npm install -g @contentstack/cli-config
16
18
  $ csdx COMMAND
17
19
  running command...
18
20
  $ csdx (--version)
19
- @contentstack/cli-config/1.3.1 linux-x64 node-v16.20.0
21
+ @contentstack/cli-config/1.4.0 linux-x64 node-v16.20.0
20
22
  $ csdx --help [COMMAND]
21
23
  USAGE
22
24
  $ csdx COMMAND
23
25
  ...
24
26
  ```
25
27
  <!-- usagestop -->
28
+
26
29
  # Commands
30
+
27
31
  <!-- commands -->
32
+ * [`csdx config:get:base-branch`](#csdx-configgetbase-branch)
28
33
  * [`csdx config:get:region`](#csdx-configgetregion)
34
+ * [`csdx config:remove:base-branch`](#csdx-configremovebase-branch)
35
+ * [`csdx config:set:base-branch`](#csdx-configsetbase-branch)
29
36
  * [`csdx config:set:region [REGION]`](#csdx-configsetregion-region)
30
37
 
38
+ ## `csdx config:get:base-branch`
39
+
40
+ Get current branch set for CLI
41
+
42
+ ```
43
+ USAGE
44
+ $ csdx config:get:base-branch
45
+
46
+ DESCRIPTION
47
+ Get current branch set for CLI
48
+
49
+ EXAMPLES
50
+ $ csdx config:get:base-branch
51
+ ```
52
+
53
+ _See code: [src/commands/config/get/base-branch.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/get/base-branch.ts)_
54
+
31
55
  ## `csdx config:get:region`
32
56
 
33
57
  Get current region set for CLI
@@ -45,6 +69,52 @@ EXAMPLES
45
69
 
46
70
  _See code: [src/commands/config/get/region.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/get/region.ts)_
47
71
 
72
+ ## `csdx config:remove:base-branch`
73
+
74
+ Remove branch config for CLI
75
+
76
+ ```
77
+ USAGE
78
+ $ csdx config:remove:base-branch [-k <value>] [-y]
79
+
80
+ FLAGS
81
+ -k, --stack-api-key=<value> Stack API Key
82
+ -y, --yes Force Remove
83
+
84
+ DESCRIPTION
85
+ Remove branch config for CLI
86
+
87
+ EXAMPLES
88
+ $ csdx config:remove:base-branch
89
+
90
+ $ csdx config:remove:base-branch --stack-api-key <value>
91
+ ```
92
+
93
+ _See code: [src/commands/config/remove/base-branch.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/remove/base-branch.ts)_
94
+
95
+ ## `csdx config:set:base-branch`
96
+
97
+ Set branch for CLI
98
+
99
+ ```
100
+ USAGE
101
+ $ csdx config:set:base-branch [-k <value>] [--base-branch <value>]
102
+
103
+ FLAGS
104
+ -k, --stack-api-key=<value> Stack API Key
105
+ --base-branch=<value> Base Branch
106
+
107
+ DESCRIPTION
108
+ Set branch for CLI
109
+
110
+ EXAMPLES
111
+ $ csdx config:set:base-branch
112
+
113
+ $ csdx config:set:base-branch --stack-api-key <value> --base-branch <value>
114
+ ```
115
+
116
+ _See code: [src/commands/config/set/base-branch.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/set/base-branch.ts)_
117
+
48
118
  ## `csdx config:set:region [REGION]`
49
119
 
50
120
  Set region for CLI
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_command_1 = require("@contentstack/cli-command");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ class BranchGetCommand extends cli_command_1.Command {
6
+ async run() {
7
+ try {
8
+ let config = cli_utilities_1.configHandler.get(`baseBranch`);
9
+ if (config && Object.keys(config).length > 0) {
10
+ let configList = Object.keys(config).map((key) => ({ ['Stack API Key']: key, ['Branch']: config[key] }));
11
+ cli_utilities_1.cliux.table(configList, {
12
+ 'Stack API Key': {
13
+ minWidth: 8,
14
+ },
15
+ Branch: {
16
+ minWidth: 8,
17
+ },
18
+ }, {
19
+ printLine: cli_utilities_1.cliux.print,
20
+ });
21
+ }
22
+ else {
23
+ cli_utilities_1.cliux.print(`error: ${cli_utilities_1.messageHandler.parse('CLI_CONFIG_BRANCH_LIST_NO_BRANCHES')}`, { color: 'red' });
24
+ }
25
+ }
26
+ catch (error) {
27
+ cli_utilities_1.cliux.error('error', error);
28
+ }
29
+ }
30
+ }
31
+ exports.default = BranchGetCommand;
32
+ BranchGetCommand.description = 'Get current branch set for CLI';
33
+ BranchGetCommand.examples = ['$ csdx config:get:base-branch'];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_command_1 = require("@contentstack/cli-command");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const utils_1 = require("../../../utils");
6
+ class RemoveBranchConfigCommand extends cli_command_1.Command {
7
+ async run() {
8
+ try {
9
+ const { flags: configRemoveFlags } = await this.parse(RemoveBranchConfigCommand);
10
+ if (!configRemoveFlags['stack-api-key']) {
11
+ configRemoveFlags['stack-api-key'] = await utils_1.interactive.askStackAPIKey();
12
+ }
13
+ if (cli_utilities_1.configHandler.get(`baseBranch.${configRemoveFlags['stack-api-key']}`) === undefined) {
14
+ cli_utilities_1.cliux.error(`No config set for stack-api-key : ${configRemoveFlags['stack-api-key']}`);
15
+ return;
16
+ }
17
+ else {
18
+ function deleteConfig() {
19
+ cli_utilities_1.configHandler.delete(`baseBranch.${configRemoveFlags['stack-api-key']}`);
20
+ cli_utilities_1.cliux.success(`Base branch configuration for stack-api-key: ${configRemoveFlags['stack-api-key']} removed successfully`);
21
+ }
22
+ cli_utilities_1.cliux.success(`base branch : ${await cli_utilities_1.configHandler.get(`baseBranch.${configRemoveFlags['stack-api-key']}`)}`);
23
+ cli_utilities_1.cliux.success(`stack-api-key: ${configRemoveFlags['stack-api-key']}`);
24
+ if (configRemoveFlags.yes) {
25
+ deleteConfig();
26
+ }
27
+ else {
28
+ const confirmation = await utils_1.interactive.askConfirmation();
29
+ if (!confirmation) {
30
+ return;
31
+ }
32
+ else {
33
+ deleteConfig();
34
+ }
35
+ }
36
+ }
37
+ }
38
+ catch (error) {
39
+ cli_utilities_1.cliux.error('error', error);
40
+ }
41
+ }
42
+ }
43
+ exports.default = RemoveBranchConfigCommand;
44
+ RemoveBranchConfigCommand.description = 'Remove branch config for CLI';
45
+ RemoveBranchConfigCommand.flags = {
46
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
47
+ yes: cli_utilities_1.flags.boolean({ char: 'y', description: 'Force Remove' }),
48
+ };
49
+ RemoveBranchConfigCommand.examples = ['$ csdx config:remove:base-branch', '$ csdx config:remove:base-branch --stack-api-key <value>'];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_command_1 = require("@contentstack/cli-command");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const utils_1 = require("../../../utils");
6
+ class BranchSetCommand extends cli_command_1.Command {
7
+ async run() {
8
+ try {
9
+ const { flags: branchSetFlags } = await this.parse(BranchSetCommand);
10
+ let apiKey = branchSetFlags['stack-api-key'];
11
+ let baseBranch = branchSetFlags['base-branch'];
12
+ if (!apiKey) {
13
+ apiKey = await utils_1.interactive.askStackAPIKey();
14
+ }
15
+ if (!baseBranch) {
16
+ baseBranch = await utils_1.interactive.askBaseBranch();
17
+ }
18
+ cli_utilities_1.configHandler.set(`baseBranch.${apiKey}`, baseBranch);
19
+ cli_utilities_1.cliux.success(`base branch : ${baseBranch}`);
20
+ cli_utilities_1.cliux.success(`stack-api-key: ${apiKey}`);
21
+ cli_utilities_1.cliux.success(`Base branch configuration for stack-api-key: ${apiKey} and branch: ${baseBranch} set successfully`);
22
+ }
23
+ catch (error) {
24
+ cli_utilities_1.cliux.error('error', error);
25
+ }
26
+ }
27
+ }
28
+ exports.default = BranchSetCommand;
29
+ BranchSetCommand.description = 'Set branch for CLI';
30
+ BranchSetCommand.flags = {
31
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
32
+ 'base-branch': cli_utilities_1.flags.string({ description: 'Base Branch' }),
33
+ };
34
+ BranchSetCommand.examples = [
35
+ '$ csdx config:set:base-branch',
36
+ '$ csdx config:set:base-branch --stack-api-key <value> --base-branch <value>',
37
+ ];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.askCustomRegion = exports.askRegions = void 0;
3
+ exports.inquireRequireFieldValidation = exports.askConfirmation = exports.askBaseBranch = exports.askStackAPIKey = exports.askCustomRegion = exports.askRegions = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
6
  const askRegions = async () => {
6
7
  return cli_utilities_1.cliux.inquire({
@@ -41,3 +42,36 @@ const askCustomRegion = async () => {
41
42
  return { name, cma, cda, uiHost };
42
43
  };
43
44
  exports.askCustomRegion = askCustomRegion;
45
+ async function askStackAPIKey() {
46
+ return await cli_utilities_1.cliux.inquire({
47
+ type: 'input',
48
+ message: 'CLI_CONFIG_INQUIRE_API_KEY',
49
+ name: 'stack-api-key',
50
+ validate: inquireRequireFieldValidation,
51
+ });
52
+ }
53
+ exports.askStackAPIKey = askStackAPIKey;
54
+ async function askBaseBranch() {
55
+ return await cli_utilities_1.cliux.inquire({
56
+ type: 'input',
57
+ message: 'CLI_CONFIG_INQUIRE_BASE_BRANCH',
58
+ name: 'base-branch',
59
+ validate: inquireRequireFieldValidation,
60
+ });
61
+ }
62
+ exports.askBaseBranch = askBaseBranch;
63
+ async function askConfirmation() {
64
+ return await cli_utilities_1.cliux.inquire({
65
+ type: 'confirm',
66
+ message: 'Are you sure you want to remove this configuration ?',
67
+ name: 'config_remove_confirmation',
68
+ });
69
+ }
70
+ exports.askConfirmation = askConfirmation;
71
+ function inquireRequireFieldValidation(input) {
72
+ if ((0, lodash_1.isEmpty)(input)) {
73
+ return cli_utilities_1.messageHandler.parse('CLI_BRANCH_REQUIRED_FIELD');
74
+ }
75
+ return true;
76
+ }
77
+ exports.inquireRequireFieldValidation = inquireRequireFieldValidation;
@@ -1,6 +1,20 @@
1
1
  {
2
- "version": "1.3.1",
2
+ "version": "1.4.0",
3
3
  "commands": {
4
+ "config:get:base-branch": {
5
+ "id": "config:get:base-branch",
6
+ "description": "Get current branch set for CLI",
7
+ "strict": true,
8
+ "pluginName": "@contentstack/cli-config",
9
+ "pluginAlias": "@contentstack/cli-config",
10
+ "pluginType": "core",
11
+ "aliases": [],
12
+ "examples": [
13
+ "$ csdx config:get:base-branch"
14
+ ],
15
+ "flags": {},
16
+ "args": {}
17
+ },
4
18
  "config:get:region": {
5
19
  "id": "config:get:region",
6
20
  "description": "Get current region set for CLI",
@@ -15,6 +29,65 @@
15
29
  "flags": {},
16
30
  "args": {}
17
31
  },
32
+ "config:remove:base-branch": {
33
+ "id": "config:remove:base-branch",
34
+ "description": "Remove branch config for CLI",
35
+ "strict": true,
36
+ "pluginName": "@contentstack/cli-config",
37
+ "pluginAlias": "@contentstack/cli-config",
38
+ "pluginType": "core",
39
+ "aliases": [],
40
+ "examples": [
41
+ "$ csdx config:remove:base-branch",
42
+ "$ csdx config:remove:base-branch --stack-api-key <value>"
43
+ ],
44
+ "flags": {
45
+ "stack-api-key": {
46
+ "name": "stack-api-key",
47
+ "type": "option",
48
+ "char": "k",
49
+ "description": "Stack API Key",
50
+ "multiple": false
51
+ },
52
+ "yes": {
53
+ "name": "yes",
54
+ "type": "boolean",
55
+ "char": "y",
56
+ "description": "Force Remove",
57
+ "allowNo": false
58
+ }
59
+ },
60
+ "args": {}
61
+ },
62
+ "config:set:base-branch": {
63
+ "id": "config:set:base-branch",
64
+ "description": "Set branch for CLI",
65
+ "strict": true,
66
+ "pluginName": "@contentstack/cli-config",
67
+ "pluginAlias": "@contentstack/cli-config",
68
+ "pluginType": "core",
69
+ "aliases": [],
70
+ "examples": [
71
+ "$ csdx config:set:base-branch",
72
+ "$ csdx config:set:base-branch --stack-api-key <value> --base-branch <value>"
73
+ ],
74
+ "flags": {
75
+ "stack-api-key": {
76
+ "name": "stack-api-key",
77
+ "type": "option",
78
+ "char": "k",
79
+ "description": "Stack API Key",
80
+ "multiple": false
81
+ },
82
+ "base-branch": {
83
+ "name": "base-branch",
84
+ "type": "option",
85
+ "description": "Base Branch",
86
+ "multiple": false
87
+ }
88
+ },
89
+ "args": {}
90
+ },
18
91
  "config:set:region": {
19
92
  "id": "config:set:region",
20
93
  "description": "Set region for CLI",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-config",
3
3
  "description": "Contentstack CLI plugin for configuration",
4
- "version": "1.3.1",
4
+ "version": "1.4.0",
5
5
  "author": "Contentstack",
6
6
  "scripts": {
7
7
  "build": "npm run clean && npm run compile",
@@ -17,15 +17,17 @@
17
17
  "lint": "eslint src/**/*.ts",
18
18
  "format": "eslint src/**/*.ts --fix",
19
19
  "test:integration": "mocha --forbid-only \"test/run.test.ts\" --integration-test",
20
- "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\" --unit-test"
20
+ "test:unit": "mocha --forbid-only \"test/unit/**/*.test.ts\" --unit-test",
21
+ "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
21
22
  },
22
23
  "dependencies": {
23
- "@contentstack/cli-command": "^1.2.2",
24
- "@contentstack/cli-utilities": "^1.3.1",
24
+ "@contentstack/cli-command": "^1.2.3",
25
+ "@contentstack/cli-utilities": "^1.4.0",
25
26
  "chalk": "^4.0.0",
26
27
  "debug": "^4.1.1",
27
28
  "inquirer": "8.2.4",
28
- "winston": "^3.7.2"
29
+ "winston": "^3.7.2",
30
+ "lodash": "^4.17.20"
29
31
  },
30
32
  "devDependencies": {
31
33
  "@oclif/test": "^2.2.10",
@@ -42,7 +44,7 @@
42
44
  "globby": "^10.0.2",
43
45
  "mocha": "10.1.0",
44
46
  "nyc": "^15.1.0",
45
- "oclif": "^3.1.2",
47
+ "oclif": "^3.8.1",
46
48
  "rimraf": "^2.7.1",
47
49
  "sinon": "^15.0.1",
48
50
  "tmp": "^0.2.1",
@@ -79,4 +81,4 @@
79
81
  }
80
82
  },
81
83
  "repository": "contentstack/cli"
82
- }
84
+ }