@contentstack/cli-config 1.4.11 → 1.4.12

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
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
18
18
  $ csdx COMMAND
19
19
  running command...
20
20
  $ csdx (--version)
21
- @contentstack/cli-config/1.4.11 linux-x64 node-v18.17.1
21
+ @contentstack/cli-config/1.4.12 linux-x64 node-v18.18.0
22
22
  $ csdx --help [COMMAND]
23
23
  USAGE
24
24
  $ csdx COMMAND
@@ -0,0 +1,37 @@
1
+ import { Command } from '@contentstack/cli-command';
2
+ import { ArgInput, FlagInput, Interfaces, LoggerService } from '@contentstack/cli-utilities';
3
+ export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
4
+ export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
5
+ export declare abstract class BaseCommand<T extends typeof Command> extends Command {
6
+ logger: LoggerService;
7
+ protected args: Args<T>;
8
+ protected flags: Flags<T>;
9
+ static baseFlags: FlagInput;
10
+ static args: ArgInput<{
11
+ [arg: string]: any;
12
+ }>;
13
+ /**
14
+ * The `init` function initializes the command by parsing arguments and flags, registering search
15
+ * plugins, registering the configuration, and initializing the logger.
16
+ */
17
+ init(): Promise<void>;
18
+ /**
19
+ * The catch function is used to handle errors from a command, either by adding custom logic or
20
+ * returning the parent class error handling.
21
+ * @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
22
+ * an object that extends the `Error` class and may also have an optional property `exitCode` of type
23
+ * `number`.
24
+ * @returns The parent class error handling is being returned.
25
+ */
26
+ protected catch(err: Error & {
27
+ exitCode?: number;
28
+ }): Promise<any>;
29
+ /**
30
+ * The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
31
+ * an error occurred.
32
+ * @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
33
+ * @returns The `finally` method is returning the result of calling the `finally` method of the
34
+ * superclass, which is a promise.
35
+ */
36
+ protected finally(_: Error | undefined): Promise<any>;
37
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseCommand = void 0;
4
+ const cli_command_1 = require("@contentstack/cli-command");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ class BaseCommand extends cli_command_1.Command {
7
+ /**
8
+ * The `init` function initializes the command by parsing arguments and flags, registering search
9
+ * plugins, registering the configuration, and initializing the logger.
10
+ */
11
+ async init() {
12
+ await super.init();
13
+ const { args, flags } = await this.parse({
14
+ flags: this.ctor.flags,
15
+ baseFlags: super.ctor.baseFlags,
16
+ args: this.ctor.args,
17
+ strict: this.ctor.strict,
18
+ });
19
+ this.flags = flags;
20
+ this.args = args;
21
+ // Init logger
22
+ this.logger = new cli_utilities_1.LoggerService(process.cwd(), 'cli-log');
23
+ }
24
+ /**
25
+ * The catch function is used to handle errors from a command, either by adding custom logic or
26
+ * returning the parent class error handling.
27
+ * @param err - The `err` parameter is of type `Error & { exitCode?: number }`. This means that it is
28
+ * an object that extends the `Error` class and may also have an optional property `exitCode` of type
29
+ * `number`.
30
+ * @returns The parent class error handling is being returned.
31
+ */
32
+ async catch(err) {
33
+ // add any custom logic to handle errors from the command
34
+ // or simply return the parent class error handling
35
+ return super.catch(err);
36
+ }
37
+ /**
38
+ * The `finally` function is called after the `run` and `catch` functions, regardless of whether or not
39
+ * an error occurred.
40
+ * @param {Error | undefined} _ - The parameter "_" represents an error object or undefined.
41
+ * @returns The `finally` method is returning the result of calling the `finally` method of the
42
+ * superclass, which is a promise.
43
+ */
44
+ async finally(_) {
45
+ // called after run and catch regardless of whether or not the command errored
46
+ return super.finally(_);
47
+ }
48
+ }
49
+ exports.BaseCommand = BaseCommand;
50
+ // NOTE define flags that canin be inherited by any command that extends BaseCommand
51
+ BaseCommand.baseFlags = {};
@@ -1,5 +1,5 @@
1
- import { Command } from '@contentstack/cli-command';
2
- export default class RegionGetCommand extends Command {
1
+ import { BaseCommand } from '../../../base-command';
2
+ export default class RegionGetCommand extends BaseCommand<typeof RegionGetCommand> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  config: any;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const cli_command_1 = require("@contentstack/cli-command");
4
3
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
- class RegionGetCommand extends cli_command_1.Command {
4
+ const base_command_1 = require("../../../base-command");
5
+ class RegionGetCommand extends base_command_1.BaseCommand {
6
6
  async run() {
7
7
  let currentRegion = this.region;
8
8
  if (!currentRegion) {
9
- cli_utilities_1.logger.error('No region set');
9
+ this.logger.error('No region set');
10
10
  cli_utilities_1.cliux.error('CLI_CONFIG_GET_REGION_NOT_FOUND');
11
11
  this.exit();
12
12
  }
@@ -14,6 +14,7 @@ class RegionGetCommand extends cli_command_1.Command {
14
14
  cli_utilities_1.cliux.print(`CDA HOST: ${currentRegion.cda}`);
15
15
  cli_utilities_1.cliux.print(`CMA HOST: ${currentRegion.cma}`);
16
16
  cli_utilities_1.cliux.print(`UI HOST: ${currentRegion.uiHost}`);
17
+ this.logger.error(`Currently using ${currentRegion.name} region`);
17
18
  }
18
19
  }
19
20
  exports.default = RegionGetCommand;
@@ -1,6 +1,6 @@
1
- import { Command } from '@contentstack/cli-command';
2
1
  import { FlagInput, ArgInput } from '@contentstack/cli-utilities';
3
- export default class RegionSetCommand extends Command {
2
+ import { BaseCommand } from '../../../base-command';
3
+ export default class RegionSetCommand extends BaseCommand<typeof RegionSetCommand> {
4
4
  config: any;
5
5
  static description: string;
6
6
  static flags: FlagInput;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const cli_command_1 = require("@contentstack/cli-command");
4
3
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
4
  const utils_1 = require("../../../utils");
6
- class RegionSetCommand extends cli_command_1.Command {
5
+ const base_command_1 = require("../../../base-command");
6
+ class RegionSetCommand extends base_command_1.BaseCommand {
7
7
  async run() {
8
8
  const { args, flags: regionSetFlags } = await this.parse(RegionSetCommand);
9
9
  let cda = regionSetFlags.cda;
@@ -36,7 +36,7 @@ class RegionSetCommand extends cli_command_1.Command {
36
36
  cli_utilities_1.cliux.success(`UI HOST: ${customRegion.uiHost}`);
37
37
  }
38
38
  catch (error) {
39
- cli_utilities_1.logger.error('failed to set the region', error);
39
+ this.logger.error('failed to set the region', error);
40
40
  cli_utilities_1.cliux.error(`Failed to set region due to: ${error.message}`);
41
41
  }
42
42
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.11",
2
+ "version": "1.4.12",
3
3
  "commands": {
4
4
  "config:get:base-branch": {
5
5
  "id": "config:get:base-branch",
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.4.11",
4
+ "version": "1.4.12",
5
5
  "author": "Contentstack",
6
6
  "scripts": {
7
7
  "build": "npm run clean && npm run compile",
@@ -21,8 +21,8 @@
21
21
  "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
22
22
  },
23
23
  "dependencies": {
24
- "@contentstack/cli-command": "~1.2.12",
25
- "@contentstack/cli-utilities": "~1.5.2",
24
+ "@contentstack/cli-command": "~1.2.13",
25
+ "@contentstack/cli-utilities": "~1.5.3",
26
26
  "chalk": "^4.0.0",
27
27
  "debug": "^4.1.1",
28
28
  "mkdirp": "^1.0.4",