Skip to content

Commit

Permalink
@contentstack/management dependency updated, code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyagustine committed Jun 5, 2023
1 parent 5bbe4b8 commit d03833c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,66 @@ Validate Fields with Regex Property of Content Type and Global Field in a Stack
[![License](https://img.shields.io/npm/l/cli-cm-regex-validate.svg)](https://github.com/contentstack/cli-cm-regex-validate/blob/master/package.json)

<!-- toc -->

- [Usage](#usage)
- [Commands](#commands)
* [cli-cm-regex-validate](#cli-cm-regex-validate)
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g @contentstack/cli
$ csdx plugins:install @contentstack/cli-cm-regex-validate
$ npm install -g @contentstack/cli-cm-regex-validate
$ csdx COMMAND
running command...
$ csdx (-v|--version|version)
@contentstack/cli-cm-regex-validate/1.0.2 darwin-x64 node-v16.17.0
$ csdx (--version)
@contentstack/cli-cm-regex-validate/1.1.4 darwin-arm64 node-v16.19.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->

- [`csdx cm:stacks:validate-regex`](#csdx-cmstacksvalidate-regex)
* [`csdx cm:stacks:validate-regex`](#csdx-cmstacksvalidate-regex)

## `csdx cm:stacks:validate-regex`

This command is used to find all the invalid regexes present in the content types and global fields of your stack.

```
USAGE
$ csdx cm:stacks:validate-regex
OPTIONS
-a, --alias=alias Alias (name) assigned to the management token
-c, --contentType To find invalid regexes within the content types
-f, --filePath=filePath [optional] The path or the location in your file system where the CSV output file should be
stored.
$ csdx cm:stacks:validate-regex [-h] [-a <value>] [-c] [-g] [-f <value>]
-g, --globalField To find invalid regexes within the global fields
FLAGS
-a, --alias=<value> Alias (name) assigned to the management token
-c, --contentType To find invalid regexes within the content types
-f, --filePath=<value> [optional] The path or the location in your file system where the CSV output file should be
stored.
-g, --globalField To find invalid regexes within the global fields
-h, --help To show the flags that can be used with this CLI command
-h, --help To show the flags that can be used with this CLI command
DESCRIPTION
This command is used to find all the invalid regexes present in the content types and global fields of your stack.
EXAMPLES
$ csdx cm:stacks:validate-regex
$ csdx cm:stacks:validate-regex -a <management_token_alias>
$ csdx cm:stacks:validate-regex -c
$ csdx cm:stacks:validate-regex -g
$ csdx cm:stacks:validate-regex -f <path/to/the/directory>
$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g
$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g -f <path/to/the/directory>
```

_See code: [src/commands/cm/stacks/validate-regex.ts](https://github.com/contentstack/cli-cm-regex-validate/blob/v1.0.2/src/commands/cm/stacks/validate-regex.ts)_

_See code: [src/commands/cm/stacks/validate-regex.ts](https://github.com/contentstack/cli-cm-regex-validate/blob/v1.1.4/src/commands/cm/stacks/validate-regex.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@contentstack/cli-command": "^1.2.7",
"@contentstack/cli-utilities": "^1.4.3",
"@contentstack/management": "^1.2.4",
"@contentstack/management": "^1.8.0",
"cli-table3": "^0.6.0",
"cli-ux": "^6.0.9",
"inquirer": "^8.2.4",
Expand Down
32 changes: 21 additions & 11 deletions src/utils/connect-stack.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import * as contentstackSdk from '@contentstack/management'
import {cli} from 'cli-ux'
import processStack from './process-stack'
const regexMessages = require('../../messages/index.json').validateRegex
import { cli } from "cli-ux";
import * as contentstackSdk from "@contentstack/management";

export default async function connectStack(flags: any, host: string, tokenDetails: any) {
import processStack from "./process-stack";
const regexMessages = require("../../messages/index.json").validateRegex;

export default async function connectStack(
flags: any,
host: string,
tokenDetails: any
) {
try {
const startTime = Date.now()
cli.action.start(regexMessages.cliAction.connectStackStart, '', {stdout: true})
const startTime = Date.now();
cli.action.start(regexMessages.cliAction.connectStackStart, "", {
stdout: true,
});
const client = contentstackSdk.client({
host: host,
})
const stackInstance = await client.stack({api_key: tokenDetails.apiKey, management_token: tokenDetails.token})
await processStack(flags, stackInstance, startTime)
});
const stackInstance = client.stack({
api_key: tokenDetails.apiKey,
management_token: tokenDetails.token,
});
await processStack(flags, stackInstance, startTime);
} catch (error) {
throw new Error(regexMessages.errors.stack.apiKey)
throw new Error(regexMessages.errors.stack.apiKey);
}
}

0 comments on commit d03833c

Please sign in to comment.