@contentstack/cli 2.0.0-beta.2 → 2.0.0-beta.21

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.
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("../../utils");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
5
  /**
5
6
  * Set the cli context
6
7
  */
7
8
  function default_1(opts) {
9
+ // Store command ID for session-based log organization
10
+ if (opts.id) {
11
+ cli_utilities_1.configHandler.set('currentCommandId', opts.id);
12
+ }
8
13
  this.config.context = new utils_1.CsdxContext(opts, this.config);
9
14
  }
10
15
  exports.default = default_1;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Initialize the utilities
3
3
  */
4
- export default function (_opts: any): void;
4
+ export default function (_opts: any): Promise<void>;
@@ -4,7 +4,8 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
4
  /**
5
5
  * Initialize the utilities
6
6
  */
7
- function default_1(_opts) {
7
+ async function default_1(_opts) {
8
+ await (0, cli_utilities_1.loadChalk)();
8
9
  const { context } = this.config;
9
10
  cli_utilities_1.messageHandler.init(context);
10
11
  cli_utilities_1.cliux.init(context);
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cli_utilities_1 = require("@contentstack/cli-utilities");
4
- const cli_utilities_2 = require("@contentstack/cli-utilities");
5
4
  // TBD: run region command if region is not there
6
5
  async function default_1(opts) {
7
- const newLogger = new cli_utilities_2.LoggerService(process.cwd(), 'cli-log');
8
6
  const { context: { plugin: { config: { protectedCommands = {} } = {} } = {}, region = null } = {} } = this.config;
9
7
  if (opts.Command.id !== 'config:set:region') {
10
8
  if (!region) {
@@ -12,28 +10,28 @@ async function default_1(opts) {
12
10
  this.exit();
13
11
  return;
14
12
  }
15
- cli_utilities_1.cliux.print(`\n Currently using ${region.name} region \n`, { color: 'grey' });
13
+ cli_utilities_1.cliux.print(`Currently using region: ${region.name}`, { color: 'grey' });
16
14
  }
17
15
  // Auth guard
18
16
  if (protectedCommands[opts.Command.id]) {
19
17
  if (!(0, cli_utilities_1.isAuthenticated)()) {
20
- newLogger.error('No auth token found for command', opts.Command.id);
21
- cli_utilities_1.cliux.error('Please login to execute the command');
18
+ (0, cli_utilities_1.handleAndLogError)(new Error('Authentication required for this command'), { module: 'auth-guard', commandId: opts.Command.id });
19
+ cli_utilities_1.cliux.error('Please log in to execute the command');
22
20
  this.exit();
23
21
  }
24
22
  const client = await (0, cli_utilities_1.managementSDKClient)({ host: region.cma });
25
23
  try {
26
24
  const result = await client.getUser();
27
25
  if (!result) {
28
- newLogger.error('error in auth validation');
29
- cli_utilities_1.cliux.error('Please login to execute the command');
26
+ (0, cli_utilities_1.handleAndLogError)(new Error('Error in auth validation'), { module: 'auth-guard' });
27
+ cli_utilities_1.cliux.error('Please log in to execute the command');
30
28
  this.exit();
31
29
  }
32
- newLogger.debug('logged in user', result.data);
30
+ cli_utilities_1.log.debug('Logged-in user', { module: 'auth-guard', userData: result.data });
33
31
  }
34
32
  catch (error) {
35
- newLogger.error('error in auth validation', error);
36
- cli_utilities_1.cliux.error('Please login to execute the command');
33
+ (0, cli_utilities_1.handleAndLogError)(error, { module: 'auth-guard' }, 'Error in auth validation');
34
+ cli_utilities_1.cliux.error('Please log in to execute the command');
37
35
  process.exit();
38
36
  }
39
37
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * When an invalid command is corrected (e.g. loginasda → login), init ran with the invalid
3
+ * command so context.messageFilePath was never set. Re-build context and re-init utilities
4
+ * for the actual command so i18n prompts show human-readable text.
5
+ */
6
+ export default function (opts: {
7
+ Command?: {
8
+ id?: string;
9
+ };
10
+ config?: any;
11
+ }): Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
+ const utils_1 = require("../../utils");
5
+ /**
6
+ * When an invalid command is corrected (e.g. loginasda → login), init ran with the invalid
7
+ * command so context.messageFilePath was never set. Re-build context and re-init utilities
8
+ * for the actual command so i18n prompts show human-readable text.
9
+ */
10
+ async function default_1(opts) {
11
+ var _a, _b, _c;
12
+ const config = (_a = opts === null || opts === void 0 ? void 0 : opts.config) !== null && _a !== void 0 ? _a : this.config;
13
+ const commandId = (_b = opts === null || opts === void 0 ? void 0 : opts.Command) === null || _b === void 0 ? void 0 : _b.id;
14
+ if (!((_c = config === null || config === void 0 ? void 0 : config.context) === null || _c === void 0 ? void 0 : _c.messageFilePath) && commandId) {
15
+ config.context = new utils_1.CsdxContext({ id: commandId }, config);
16
+ cli_utilities_1.messageHandler.init(config.context);
17
+ cli_utilities_1.cliux.init(config.context);
18
+ cli_utilities_1.managementSDKInitiator.init(config.context);
19
+ cli_utilities_1.marketplaceSDKInitiator.init(config.context);
20
+ }
21
+ }
22
+ exports.default = default_1;
@@ -4,14 +4,17 @@ const tslib_1 = require("tslib");
4
4
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
5
  const semver = tslib_1.__importStar(require("semver"));
6
6
  const versionUpgradeWarningFrequency = {
7
- versionSyncDuration: 3 * 24 * 60 * 60 * 1000,
7
+ versionSyncDuration: 3 * 24 * 60 * 60 * 1000, // 3 days
8
8
  };
9
9
  async function default_1(_opts) {
10
10
  var _a, _b;
11
11
  const now = Date.now();
12
12
  const today = new Date().toISOString().split('T')[0];
13
- const logger = new cli_utilities_1.LoggerService(process.env.CS_CLI_LOG_PATH || process.cwd(), 'cli-log');
14
13
  let cache = { lastChecked: 0, lastWarnedDate: '', latestVersion: '' };
14
+ // if CLI_VERSION is not set or is not the same as the current version, set it
15
+ if (!cli_utilities_1.configHandler.get('CLI_VERSION') || cli_utilities_1.configHandler.get('CLI_VERSION') !== this.config.version) {
16
+ cli_utilities_1.configHandler.set('CLI_VERSION', this.config.version); // set current version in configHandler
17
+ }
15
18
  if (!cli_utilities_1.configHandler.get('versionUpgradeWarningFrequency')) {
16
19
  cli_utilities_1.configHandler.set('versionUpgradeWarningFrequency', versionUpgradeWarningFrequency);
17
20
  }
@@ -26,7 +29,7 @@ async function default_1(_opts) {
26
29
  try {
27
30
  const latestVersion = (_b = (_a = (await httpClient.get(`https://registry.npmjs.org/@contentstack/cli/latest`))) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.version;
28
31
  if (!latestVersion) {
29
- logger.error('Failed to retrieve the latest version from the registry.');
32
+ (0, cli_utilities_1.handleAndLogError)(new Error('Failed to retrieve the latest version from the registry.'), { module: 'latest-version-warning' });
30
33
  return;
31
34
  }
32
35
  cache.latestVersion = latestVersion;
@@ -35,7 +38,7 @@ async function default_1(_opts) {
35
38
  cli_utilities_1.configHandler.set('versionUpgradeWarningCache', cache);
36
39
  }
37
40
  catch (error) {
38
- logger.error('Failed to check the latest version', error);
41
+ (0, cli_utilities_1.handleAndLogError)(error, { module: 'latest-version-warning' }, 'Failed to check the latest version');
39
42
  return;
40
43
  }
41
44
  }
@@ -7,7 +7,7 @@ export interface InquirePayload {
7
7
  name: string;
8
8
  message: string;
9
9
  choices?: Array<any>;
10
- transformer?: Function;
10
+ transformer?: (value: any) => any;
11
11
  }
12
12
  export interface Region {
13
13
  name: string;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "commands": {},
3
- "version": "2.0.0-beta.2"
3
+ "version": "2.0.0-beta.21"
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli",
3
3
  "description": "Command-line tool (CLI) to interact with Contentstack",
4
- "version": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.21",
5
5
  "author": "Contentstack",
6
6
  "bin": {
7
7
  "csdx": "./bin/run.js"
@@ -9,77 +9,79 @@
9
9
  "main": "lib/index.js",
10
10
  "types": "lib/index.d.ts",
11
11
  "scripts": {
12
- "build": "npm run clean && npm run compile",
13
- "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
12
+ "build": "pnpm compile && oclif manifest && oclif readme",
13
+ "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo",
14
14
  "compile": "tsc -b tsconfig.json",
15
15
  "postpack": "rm -f oclif.manifest.json",
16
16
  "version": "oclif readme && git add README.md",
17
- "test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
18
- "pretest": "tsc -p test",
19
- "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
20
- "posttest": "npm run lint",
17
+ "test": "mocha \"test/unit/**/*.test.ts\"",
21
18
  "lint": "eslint src/**/*.ts",
22
19
  "prepack": "pnpm compile && oclif manifest && oclif readme"
23
20
  },
24
21
  "dependencies": {
25
- "@contentstack/cli-audit": "~1.16.0",
26
- "@contentstack/cli-auth": "~1.6.2",
27
- "@contentstack/cli-cm-bootstrap": "~2.0.0-beta.2",
28
- "@contentstack/cli-cm-branches": "~1.6.1",
29
- "@contentstack/cli-cm-bulk-publish": "~1.10.1",
30
- "@contentstack/cli-cm-clone": "~2.0.0-beta.2",
31
- "@contentstack/cli-cm-export": "~2.0.0-beta.2",
32
- "@contentstack/cli-cm-export-to-csv": "~1.10.0",
33
- "@contentstack/cli-cm-import": "~2.0.0-beta.2",
34
- "@contentstack/cli-cm-import-setup": "1.7.0",
35
- "@contentstack/cli-cm-migrate-rte": "~1.6.2",
36
- "@contentstack/cli-cm-seed": "~2.0.0-beta.2",
37
- "@contentstack/cli-command": "~1.6.2",
38
- "@contentstack/cli-config": "~1.15.3",
39
- "@contentstack/cli-launch": "^1.9.2",
40
- "@contentstack/cli-migration": "~1.8.2",
41
- "@contentstack/cli-utilities": "~1.15.0",
42
- "@contentstack/cli-variants": "~2.0.0-beta.2",
43
- "@contentstack/management": "~1.22.0",
44
- "@oclif/core": "^4.3.0",
45
- "@oclif/plugin-help": "^6.2.28",
46
- "@oclif/plugin-not-found": "^3.2.53",
47
- "@oclif/plugin-plugins": "^5.4.38",
48
- "chalk": "^4.1.2",
22
+ "@contentstack/cli-audit": "~2.0.0-beta.11",
23
+ "@contentstack/cli-cm-export": "~2.0.0-beta.16",
24
+ "@contentstack/cli-cm-import": "~2.0.0-beta.16",
25
+ "@contentstack/cli-auth": "~2.0.0-beta.11",
26
+ "@contentstack/cli-bulk-operations": "^1.0.1",
27
+ "@contentstack/cli-cm-bootstrap": "~2.0.0-beta.16",
28
+ "@contentstack/cli-cm-branches": "~2.0.0-beta.6",
29
+ "@contentstack/cli-cm-clone": "~2.0.0-beta.17",
30
+ "@contentstack/cli-cm-export-to-csv": "~2.0.0-beta.6",
31
+ "@contentstack/cli-cm-import-setup": "~2.0.0-beta.10",
32
+ "@contentstack/cli-cm-seed": "~2.0.0-beta.16",
33
+ "@contentstack/cli-command": "~2.0.0-beta.6",
34
+ "@contentstack/cli-config": "~2.0.0-beta.8",
35
+ "@contentstack/cli-launch": "^1.9.7",
36
+ "@contentstack/cli-migration": "~2.0.0-beta.11",
37
+ "@contentstack/cli-utilities": "~2.0.0-beta.7",
38
+ "@contentstack/cli-variants": "~2.0.0-beta.12",
39
+ "@contentstack/management": "~1.30.1",
40
+ "@contentstack/utils": "~1.9.1",
41
+ "@oclif/core": "^4.10.5",
42
+ "@oclif/plugin-help": "^6.2.44",
43
+ "@oclif/plugin-not-found": "^3.2.80",
44
+ "@oclif/plugin-plugins": "^5.4.61",
45
+ "chalk": "^5.6.2",
49
46
  "cli-progress": "^3.12.0",
50
- "debug": "^4.4.1",
51
- "figlet": "1.8.1",
52
- "inquirer": "8.2.7",
47
+ "debug": "^4.4.3",
48
+ "figlet": "1.11.0",
49
+ "inquirer": "^12.11.1",
53
50
  "node-machine-id": "^1.1.12",
54
51
  "open": "^8.4.2",
55
52
  "ora": "^8.2.0",
56
- "semver": "^7.7.2",
53
+ "semver": "^7.7.4",
57
54
  "short-uuid": "^4.2.2",
58
55
  "uuid": "^9.0.1",
59
- "winston": "^3.17.0"
56
+ "winston": "^3.19.0"
57
+ },
58
+ "overrides": {
59
+ "@oclif/core": {
60
+ "picomatch": "^4.0.4"
61
+ }
60
62
  },
61
63
  "devDependencies": {
62
- "@oclif/test": "^4.1.13",
64
+ "@oclif/test": "^4.1.18",
63
65
  "@types/chai": "^4.3.20",
64
- "@types/inquirer": "^9.0.8",
66
+ "@types/inquirer": "^9.0.9",
65
67
  "@types/mkdirp": "^1.0.2",
66
68
  "@types/mocha": "^8.2.3",
67
- "@types/node": "^14.18.63",
68
- "@types/semver": "^7.7.0",
69
+ "@types/node": "^18.19.130",
70
+ "@types/semver": "^7.7.1",
69
71
  "@types/sinon": "^10.0.20",
70
72
  "chai": "^4.5.0",
71
73
  "eslint": "^8.57.1",
72
- "eslint-config-oclif": "^6.0.62",
74
+ "eslint-config-oclif": "^6.0.157",
73
75
  "eslint-config-oclif-typescript": "^3.1.14",
74
76
  "globby": "^10.0.2",
75
77
  "mocha": "10.8.2",
76
78
  "nock": "^13.5.6",
77
79
  "nyc": "^15.1.0",
78
- "oclif": "^4.17.46",
80
+ "oclif": "^4.23.0",
79
81
  "rimraf": "^5.0.10",
80
82
  "shelljs": "^0.10.0",
81
- "sinon": "^19.0.5",
82
- "tmp": "^0.2.3",
83
+ "sinon": "^21.1.2",
84
+ "tmp": "^0.2.5",
83
85
  "ts-node": "^10.9.2",
84
86
  "tslib": "^2.8.1",
85
87
  "typescript": "^4.9.5"
@@ -148,17 +150,16 @@
148
150
  "@contentstack/cli-cm-bootstrap",
149
151
  "@contentstack/cli-cm-export-to-csv",
150
152
  "@contentstack/cli-cm-clone",
151
- "@contentstack/cli-cm-migrate-rte",
152
153
  "@contentstack/cli-migration",
153
- "@contentstack/cli-cm-bulk-publish",
154
154
  "@contentstack/cli-cm-branches",
155
155
  "@contentstack/cli-audit",
156
156
  "@contentstack/cli-cm-import-setup",
157
- "@contentstack/cli-launch"
157
+ "@contentstack/cli-launch",
158
+ "@contentstack/cli-bulk-operations"
158
159
  ],
159
160
  "hooks": {
160
161
  "prerun": [
161
- "./lib/hooks/prerun/command-deprecation-check",
162
+ "./lib/hooks/prerun/init-context-for-command",
162
163
  "./lib/hooks/prerun/default-rate-limit-check",
163
164
  "./lib/hooks/prerun/latest-version-warning"
164
165
  ],
@@ -1 +0,0 @@
1
- export default function (_opts: any): Promise<void>;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cli_utilities_1 = require("@contentstack/cli-utilities");
4
- async function default_1(_opts) {
5
- const { context: { plugin: { config: { expiredCommands = {} } = {} } = {}, info: { command = null } = {} } = {} } = this.config;
6
- if (expiredCommands.hasOwnProperty(command)) {
7
- cli_utilities_1.cliux.print(`WARNING!!! You're using the old (soon to be deprecated) Contentstack CLI command. We recommend you to use the latest ${expiredCommands[command]} command.`, { color: 'yellow' });
8
- }
9
- }
10
- exports.default = default_1;