@contentstack/cli 0.1.1-beta.9 → 1.0.2
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/LICENSE +21 -0
- package/README.md +1137 -665
- package/bin/run +1 -4
- package/lib/config/index.js +9 -0
- package/lib/help.js +38 -0
- package/lib/hooks/init/context-init.js +10 -0
- package/lib/hooks/init/utils-init.js +12 -0
- package/lib/hooks/prerun/auth-guard.js +40 -0
- package/lib/hooks/prerun/command-deprecation-check.js +10 -0
- package/lib/index.js +3 -0
- package/lib/interfaces/index.js +2 -0
- package/lib/utils/context-handler.js +39 -0
- package/lib/utils/index.js +5 -0
- package/oclif.manifest.json +1 -1
- package/package.json +98 -66
- package/src/commands/config/get/region.js +0 -17
- package/src/commands/config/set/region.js +0 -70
- package/src/help.js +0 -20
- package/src/hooks/init.js +0 -21
- package/src/hooks/prerun/analytics.js +0 -40
- package/src/hooks/prerun/print-region.js +0 -11
- package/src/hooks/validate-auth-token.js +0 -7
- package/src/hooks/validate-management-token.js +0 -19
- package/src/index.js +0 -1
- package/src/util/analytics.js +0 -61
- package/src/util/contentstack-client.js +0 -17
- package/src/util/custom-errors.js +0 -7
- package/src/util/request.js +0 -71
- package/src/util/user-config.js +0 -128
package/bin/run
CHANGED
package/lib/help.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const figlet = require("figlet");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
class MyHelpClass extends core_1.Help {
|
|
7
|
+
constructor(config, opts) {
|
|
8
|
+
super(config, opts);
|
|
9
|
+
}
|
|
10
|
+
showRootHelp() {
|
|
11
|
+
// Shows Contentstack graphics
|
|
12
|
+
cli_utilities_1.cliux.print(figlet.textSync('Contentstack', {
|
|
13
|
+
horizontalLayout: 'default',
|
|
14
|
+
verticalLayout: 'default',
|
|
15
|
+
}));
|
|
16
|
+
super.showRootHelp();
|
|
17
|
+
}
|
|
18
|
+
showCommandHelp(command) {
|
|
19
|
+
if (command.id === 'cm:bulk-publish') {
|
|
20
|
+
let { context: { plugin: { commands = [] } = {} } = {} } = this.config;
|
|
21
|
+
commands = commands.map((c) => {
|
|
22
|
+
return Object.assign(Object.assign({}, c), { name: c.id });
|
|
23
|
+
});
|
|
24
|
+
const title = command.description && this.render(command.description).split('\n')[0];
|
|
25
|
+
if (title)
|
|
26
|
+
console.log(title + '\n');
|
|
27
|
+
console.log(this.formatCommand(command));
|
|
28
|
+
console.log('');
|
|
29
|
+
if (commands.length > 0) {
|
|
30
|
+
console.log(this.formatCommands(commands));
|
|
31
|
+
console.log('');
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
super.showCommandHelp(command);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = MyHelpClass;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../../utils");
|
|
4
|
+
/**
|
|
5
|
+
* Set the cli context
|
|
6
|
+
*/
|
|
7
|
+
function default_1(opts) {
|
|
8
|
+
this.config.context = new utils_1.CsdxContext(opts, this.config);
|
|
9
|
+
}
|
|
10
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
|
+
/**
|
|
5
|
+
* Initialize the utilities
|
|
6
|
+
*/
|
|
7
|
+
function default_1(_opts) {
|
|
8
|
+
cli_utilities_1.logger.init(this.config.context);
|
|
9
|
+
cli_utilities_1.messageHandler.init(this.config.context);
|
|
10
|
+
cli_utilities_1.cliux.init(this.config.context);
|
|
11
|
+
}
|
|
12
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
|
+
// TBD: run region command if region is not there
|
|
5
|
+
async function default_1(opts) {
|
|
6
|
+
const { context: { plugin: { config: { protectedCommands = {} } = {} } = {}, region = null } = {} } = this.config;
|
|
7
|
+
if (opts.Command.id !== 'config:set:region') {
|
|
8
|
+
if (!region) {
|
|
9
|
+
cli_utilities_1.cliux.error('No region found, please set a region $config:set:region');
|
|
10
|
+
this.exit();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
cli_utilities_1.cliux.print(`\n Currently using ${region.name} region \n`, { color: 'grey' });
|
|
14
|
+
}
|
|
15
|
+
// Auth guard
|
|
16
|
+
if (protectedCommands[opts.Command.id]) {
|
|
17
|
+
const authToken = cli_utilities_1.configHandler.get('authtoken');
|
|
18
|
+
if (!authToken) {
|
|
19
|
+
cli_utilities_1.logger.error('No auth token found for command', opts.Command.id);
|
|
20
|
+
cli_utilities_1.cliux.error('Please login to execute the command');
|
|
21
|
+
this.exit();
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const result = await cli_utilities_1.HttpClient.create().headers({ authtoken: authToken }).get(`${region.cma}/v3/user`);
|
|
25
|
+
if (result.status !== 200) {
|
|
26
|
+
cli_utilities_1.logger.error('error in auth validation');
|
|
27
|
+
cli_utilities_1.cliux.error('Please login to execute the command');
|
|
28
|
+
this.exit();
|
|
29
|
+
}
|
|
30
|
+
cli_utilities_1.logger.debug('logged in user', result.data);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
cli_utilities_1.logger.error('error in auth validation', error);
|
|
34
|
+
cli_utilities_1.cliux.error('Please login to execute the command');
|
|
35
|
+
this.exit();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uuid_1 = require("uuid");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
class CsdxContext {
|
|
7
|
+
constructor(cliOpts, cliConfig) {
|
|
8
|
+
const command = cliConfig.findCommand(cliOpts.id) || {};
|
|
9
|
+
const config = cli_utilities_1.configHandler;
|
|
10
|
+
let sessionId = cli_utilities_1.configHandler.get('sessionId');
|
|
11
|
+
if (!sessionId) {
|
|
12
|
+
sessionId = (0, uuid_1.v4)();
|
|
13
|
+
cli_utilities_1.configHandler.set('sessionId', sessionId);
|
|
14
|
+
}
|
|
15
|
+
this.id = sessionId;
|
|
16
|
+
this.user = {
|
|
17
|
+
authtoken: cli_utilities_1.configHandler.get('authtoken'),
|
|
18
|
+
email: cli_utilities_1.configHandler.get('email'),
|
|
19
|
+
};
|
|
20
|
+
this.config = Object.assign({}, config);
|
|
21
|
+
this.region = cli_utilities_1.configHandler.get('region');
|
|
22
|
+
this.info = { command: cliOpts.id };
|
|
23
|
+
if (command.pluginName) {
|
|
24
|
+
this.plugin = (cliConfig.plugins || []).find((p) => p.name === command.pluginName) || {};
|
|
25
|
+
this.plugin.name = command.pluginName;
|
|
26
|
+
this.plugin.config = Object.assign({}, ((this.plugin.pjson && this.plugin.pjson.csdxConfig) || {}));
|
|
27
|
+
this.messageFilePath = path.resolve(this.plugin.root, this.plugin.config.messageFilePath || './messages/index.json');
|
|
28
|
+
}
|
|
29
|
+
this.flagWarningPrintState = {};
|
|
30
|
+
}
|
|
31
|
+
getToken(alias) {
|
|
32
|
+
if (alias) {
|
|
33
|
+
const token = cli_utilities_1.configHandler.get(`tokens.${alias}`);
|
|
34
|
+
if (token)
|
|
35
|
+
return token;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = CsdxContext;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsdxContext = void 0;
|
|
4
|
+
var context_handler_1 = require("./context-handler");
|
|
5
|
+
Object.defineProperty(exports, "CsdxContext", { enumerable: true, get: function () { return context_handler_1.default; } });
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"
|
|
1
|
+
{"version":"1.0.2","commands":{}}
|
package/package.json
CHANGED
|
@@ -1,122 +1,154 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli",
|
|
3
3
|
"description": "Command-line tool (CLI) to interact with Contentstack",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bin": {
|
|
7
7
|
"csdx": "./bin/run"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm run clean && npm run compile",
|
|
12
|
+
"clean": "rm -rf ./lib && rm -rf tsconfig.build.tsbuildinfo",
|
|
13
|
+
"compile": "tsc -b tsconfig.json",
|
|
14
|
+
"postpack": "rm -f oclif.manifest.json",
|
|
15
|
+
"prepack": "npm run build && oclif-dev manifest && oclif-dev readme",
|
|
16
|
+
"version": "oclif-dev readme",
|
|
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",
|
|
21
|
+
"lint": "eslint src/**/*.ts"
|
|
22
|
+
},
|
|
10
23
|
"dependencies": {
|
|
11
|
-
"@contentstack/cli-auth": "
|
|
12
|
-
"@contentstack/cli-cm-
|
|
13
|
-
"@contentstack/cli-cm-
|
|
14
|
-
"@contentstack/cli-cm-
|
|
15
|
-
"@contentstack/cli-cm-export
|
|
16
|
-
"@contentstack/cli-cm-
|
|
17
|
-
"@contentstack/cli-cm-
|
|
18
|
-
"@contentstack/cli-cm-
|
|
19
|
-
"@contentstack/cli-
|
|
20
|
-
"@contentstack/cli-
|
|
21
|
-
"@contentstack/
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
+
"@contentstack/cli-auth": "^1.0.0",
|
|
25
|
+
"@contentstack/cli-cm-bootstrap": "^1.1.0",
|
|
26
|
+
"@contentstack/cli-cm-bulk-publish": "^1.0.0",
|
|
27
|
+
"@contentstack/cli-cm-clone": "^1.0.0",
|
|
28
|
+
"@contentstack/cli-cm-export": "^1.0.0",
|
|
29
|
+
"@contentstack/cli-cm-export-to-csv": "^1.0.0",
|
|
30
|
+
"@contentstack/cli-cm-import": "^1.0.0",
|
|
31
|
+
"@contentstack/cli-cm-migrate-rte": "^1.1.0",
|
|
32
|
+
"@contentstack/cli-cm-seed": "^1.1.0",
|
|
33
|
+
"@contentstack/cli-command": "^1.0.0",
|
|
34
|
+
"@contentstack/cli-config": "^1.0.0",
|
|
35
|
+
"@contentstack/cli-migration": "^1.0.0",
|
|
36
|
+
"@contentstack/cli-utilities": "^1.0.0",
|
|
37
|
+
"@contentstack/management": "^1.3.0",
|
|
38
|
+
"@oclif/command": "^1.8.16",
|
|
39
|
+
"@oclif/config": "^1.18.3",
|
|
40
|
+
"@oclif/core": "^1.9.5",
|
|
24
41
|
"@oclif/errors": "^1.3.3",
|
|
25
|
-
"@oclif/plugin-
|
|
26
|
-
"@oclif/plugin-
|
|
27
|
-
"
|
|
28
|
-
"axios": "^0.19.2",
|
|
29
|
-
"bluebird": "^3.7.2",
|
|
30
|
-
"chalk": "^4.1.0",
|
|
31
|
-
"cli-ux": "^5.5.0",
|
|
32
|
-
"configstore": "^5.0.1",
|
|
42
|
+
"@oclif/plugin-not-found": "^2.3.1",
|
|
43
|
+
"@oclif/plugin-plugins": "^2.1.0",
|
|
44
|
+
"chalk": "^4.0.0",
|
|
33
45
|
"debug": "^4.1.1",
|
|
34
|
-
"figlet": "^1.
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"uuid": "^8.2.0"
|
|
46
|
+
"figlet": "^1.5.2",
|
|
47
|
+
"inquirer": "^7.1.0",
|
|
48
|
+
"uuid": "^8.3.2",
|
|
49
|
+
"winston": "^3.7.2"
|
|
39
50
|
},
|
|
40
51
|
"devDependencies": {
|
|
41
|
-
"shelljs": "^0.8.4",
|
|
42
52
|
"@oclif/dev-cli": "^1.22.2",
|
|
43
|
-
"@oclif/
|
|
44
|
-
"
|
|
45
|
-
"
|
|
53
|
+
"@oclif/plugin-help": "^5.1.12",
|
|
54
|
+
"@oclif/test": "^1.2.8",
|
|
55
|
+
"@types/chai": "^4.2.18",
|
|
56
|
+
"@types/inquirer": "^7.3.1",
|
|
57
|
+
"@types/mkdirp": "^1.0.1",
|
|
58
|
+
"@types/mocha": "^8.2.2",
|
|
59
|
+
"@types/nock": "^11.1.0",
|
|
60
|
+
"@types/node": "^14.14.32",
|
|
61
|
+
"@types/sinon": "^10.0.2",
|
|
62
|
+
"@types/tar": "^4.0.3",
|
|
63
|
+
"@types/winston": "^2.4.4",
|
|
64
|
+
"chai": "^4.3.4",
|
|
65
|
+
"eslint": "^8.18.0",
|
|
46
66
|
"eslint-config-oclif": "^3.1.0",
|
|
67
|
+
"eslint-config-oclif-typescript": "^0.1.0",
|
|
47
68
|
"globby": "^10.0.2",
|
|
48
|
-
"mocha": "^
|
|
49
|
-
"
|
|
69
|
+
"mocha": "^10.0.0",
|
|
70
|
+
"nock": "^13.1.0",
|
|
71
|
+
"nyc": "^15.1.0",
|
|
72
|
+
"rimraf": "^2.7.1",
|
|
73
|
+
"sinon": "^11.1.1",
|
|
74
|
+
"tmp": "^0.2.1",
|
|
75
|
+
"ts-node": "^8.10.2",
|
|
76
|
+
"typescript": "^4.7.4",
|
|
77
|
+
"shelljs": "^0.8.4"
|
|
50
78
|
},
|
|
51
79
|
"engines": {
|
|
52
80
|
"node": ">=8.0.0"
|
|
53
81
|
},
|
|
54
82
|
"files": [
|
|
55
83
|
"/bin",
|
|
84
|
+
"/lib",
|
|
56
85
|
"/npm-shrinkwrap.json",
|
|
57
|
-
"/oclif.manifest.json"
|
|
58
|
-
"/src"
|
|
86
|
+
"/oclif.manifest.json"
|
|
59
87
|
],
|
|
60
88
|
"homepage": "https://github.com/contentstack/cli",
|
|
61
89
|
"keywords": [
|
|
62
90
|
"contentstack",
|
|
63
91
|
"cli",
|
|
64
|
-
"plugin"
|
|
65
|
-
"contentstack-cli-core"
|
|
92
|
+
"plugin"
|
|
66
93
|
],
|
|
67
94
|
"license": "MIT",
|
|
68
|
-
"main": "src/index.js",
|
|
69
95
|
"oclif": {
|
|
70
96
|
"topics": {
|
|
71
97
|
"auth": {
|
|
72
|
-
"description": "
|
|
98
|
+
"description": "Perform authentication-related activities"
|
|
73
99
|
},
|
|
74
100
|
"cm": {
|
|
75
|
-
"description": "
|
|
101
|
+
"description": "Perform content management activities"
|
|
76
102
|
},
|
|
77
103
|
"config": {
|
|
78
|
-
"description": "
|
|
104
|
+
"description": "Perform configuration related activities"
|
|
105
|
+
},
|
|
106
|
+
"cm:assets": {
|
|
107
|
+
"description": "Assets related operations"
|
|
108
|
+
},
|
|
109
|
+
"cm:entries": {
|
|
110
|
+
"description": "Entries related operations"
|
|
111
|
+
},
|
|
112
|
+
"cm:stacks": {
|
|
113
|
+
"description": "Stacks related operations"
|
|
79
114
|
},
|
|
80
115
|
"plugins": {
|
|
81
|
-
"description": "
|
|
116
|
+
"description": "List installed plugins"
|
|
82
117
|
}
|
|
83
118
|
},
|
|
84
|
-
"helpClass": "./
|
|
85
|
-
"commands": "./
|
|
119
|
+
"helpClass": "./lib/help.js",
|
|
120
|
+
"commands": "./lib/commands",
|
|
86
121
|
"bin": "csdx",
|
|
87
122
|
"plugins": [
|
|
88
|
-
"@oclif/plugin-help",
|
|
89
123
|
"@oclif/plugin-not-found",
|
|
90
124
|
"@oclif/plugin-plugins",
|
|
125
|
+
"@contentstack/cli-config",
|
|
91
126
|
"@contentstack/cli-auth",
|
|
92
|
-
"@contentstack/cli-cm-export",
|
|
93
127
|
"@contentstack/cli-cm-import",
|
|
94
|
-
"@contentstack/cli-cm-
|
|
95
|
-
"@contentstack/cli-plugins-plugin",
|
|
96
|
-
"@contentstack/cli-cm-clone",
|
|
97
|
-
"@contentstack/cli-cm-export-to-csv",
|
|
128
|
+
"@contentstack/cli-cm-export",
|
|
98
129
|
"@contentstack/cli-cm-seed",
|
|
99
|
-
"@contentstack/cli-cm-
|
|
130
|
+
"@contentstack/cli-cm-bootstrap",
|
|
131
|
+
"@contentstack/cli-cm-export-to-csv",
|
|
132
|
+
"@contentstack/cli-cm-clone",
|
|
133
|
+
"@contentstack/cli-cm-migrate-rte",
|
|
134
|
+
"@contentstack/cli-migration",
|
|
135
|
+
"@contentstack/cli-cm-bulk-publish"
|
|
100
136
|
],
|
|
101
137
|
"hooks": {
|
|
102
138
|
"prerun": [
|
|
103
|
-
"./
|
|
104
|
-
"./
|
|
139
|
+
"./lib/hooks/prerun/auth-guard",
|
|
140
|
+
"./lib/hooks/prerun/command-deprecation-check"
|
|
105
141
|
],
|
|
106
142
|
"init": [
|
|
107
|
-
"./
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
"validateAuthToken": "./src/hooks/validate-auth-token.js"
|
|
143
|
+
"./lib/hooks/init/context-init",
|
|
144
|
+
"./lib/hooks/init/utils-init"
|
|
145
|
+
]
|
|
111
146
|
}
|
|
112
147
|
},
|
|
113
148
|
"repository": "https://github.com/contentstack/cli",
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"test": "nyc mocha \"test/**/*.test.js\" ",
|
|
119
|
-
"test-report": "nyc --reporter=html mocha \"test/**/*.test.js\"",
|
|
120
|
-
"version": "oclif-dev readme --multi && git add README.md"
|
|
149
|
+
"husky": {
|
|
150
|
+
"hooks": {
|
|
151
|
+
"pre-commit": "npm run lint"
|
|
152
|
+
}
|
|
121
153
|
}
|
|
122
|
-
}
|
|
154
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const {Command} = require('@contentstack/cli-command')
|
|
2
|
-
const {cli} = require('cli-ux')
|
|
3
|
-
const chalk = require('chalk')
|
|
4
|
-
|
|
5
|
-
class RegionCommand extends Command {
|
|
6
|
-
async run() {
|
|
7
|
-
let currentRegion = this.region
|
|
8
|
-
cli.log(chalk.green(`Currently using ${currentRegion.name} region`))
|
|
9
|
-
cli.log(chalk.green(`CDA HOST: ${currentRegion.cda}`))
|
|
10
|
-
cli.log(chalk.green(`CMA HOST: ${currentRegion.cma}`))
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
RegionCommand.description = `Get current region set for CLI
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
module.exports = RegionCommand
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const {Command, flags} = require('@oclif/command')
|
|
2
|
-
const {cli} = require('cli-ux')
|
|
3
|
-
const chalk = require('chalk')
|
|
4
|
-
|
|
5
|
-
class RegionCommand extends Command {
|
|
6
|
-
async run() {
|
|
7
|
-
const {args, flags} = this.parse(RegionCommand)
|
|
8
|
-
const {cda, cma, name} = flags
|
|
9
|
-
// Custom flag will get first priority over region argument
|
|
10
|
-
if (cda && cma && name) {
|
|
11
|
-
try {
|
|
12
|
-
let customRegion = {cda, cma, name}
|
|
13
|
-
customRegion = this.config.userConfig.setCustomRegion(customRegion)
|
|
14
|
-
cli.log(chalk.green(`Custom region has been set to ${customRegion.name}`))
|
|
15
|
-
cli.log(chalk.green(`CDA HOST: ${customRegion.cda}`))
|
|
16
|
-
cli.log(chalk.green(`CMA HOST: ${customRegion.cma}`))
|
|
17
|
-
} catch (error) {
|
|
18
|
-
if (error.name && error.name === 'TypeError') {
|
|
19
|
-
cli.log(chalk.red(error.message))
|
|
20
|
-
} else {
|
|
21
|
-
cli.log(chalk.red(`Failed to set region due to: ${error.message}`))
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} else if (args.region) {
|
|
25
|
-
const selectedRegion = args.region
|
|
26
|
-
let regionDetails = this.config.userConfig.setRegion(selectedRegion)
|
|
27
|
-
cli.log(chalk.green(`Region has been set to ${selectedRegion}`))
|
|
28
|
-
cli.log(chalk.green(`CDA HOST: ${regionDetails.cda}`))
|
|
29
|
-
cli.log(chalk.green(`CMA HOST: ${regionDetails.cma}`))
|
|
30
|
-
} else {
|
|
31
|
-
this.config.userConfig.setRegion('NA')
|
|
32
|
-
cli.log('No argument or custom flag provided. Setting region to default NA')
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
RegionCommand.description = `Set region for CLI
|
|
38
|
-
`
|
|
39
|
-
|
|
40
|
-
RegionCommand.args = [{
|
|
41
|
-
name: 'region',
|
|
42
|
-
description: 'North America(NA), Europe (EU)',
|
|
43
|
-
options: ['EU', 'NA'],
|
|
44
|
-
}]
|
|
45
|
-
|
|
46
|
-
RegionCommand.examples = [
|
|
47
|
-
'$ csdx config:set:region EU',
|
|
48
|
-
'$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --name "India"',
|
|
49
|
-
'$ csdx config:set:region --cma="https://in-api.contentstack.com" --cda="https://in-cda.contentstack.com" --name="India"',
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
RegionCommand.flags = {
|
|
53
|
-
cda: flags.string({
|
|
54
|
-
char: 'd',
|
|
55
|
-
description: 'Custom host to set for content delivery API, if this flag is added then cma and name flags are required',
|
|
56
|
-
dependsOn: ['cma', 'name'],
|
|
57
|
-
}),
|
|
58
|
-
cma: flags.string({
|
|
59
|
-
char: 'm',
|
|
60
|
-
description: 'Custom host to set for content management API, , if this flag is added then cda and name flags are required',
|
|
61
|
-
dependsOn: ['cda', 'name'],
|
|
62
|
-
}),
|
|
63
|
-
name: flags.string({
|
|
64
|
-
char: 'n',
|
|
65
|
-
description: 'Name for the region, if this flag is added then cda and cma flags are required',
|
|
66
|
-
dependsOn: ['cda', 'cma'],
|
|
67
|
-
}),
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = RegionCommand
|
package/src/help.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const Help = require('@oclif/plugin-help').default
|
|
2
|
-
const figlet = require('figlet')
|
|
3
|
-
const {cli} = require('cli-ux')
|
|
4
|
-
|
|
5
|
-
class MyHelpClass extends Help {
|
|
6
|
-
constructor(config, opts) {
|
|
7
|
-
super(config, opts)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
showRootHelp() {
|
|
11
|
-
// Shows Contentstack graphics
|
|
12
|
-
cli.log(figlet.textSync('Contentstack', {
|
|
13
|
-
horizontalLayout: 'default',
|
|
14
|
-
verticalLayout: 'default',
|
|
15
|
-
}))
|
|
16
|
-
super.showRootHelp()
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = MyHelpClass
|
package/src/hooks/init.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const {UserConfig} = require('../util/user-config')
|
|
3
|
-
const ContentstackClient = require('../util/contentstack-client')
|
|
4
|
-
const debug = require('debug')('hooks:init')
|
|
5
|
-
|
|
6
|
-
module.exports = async function () {
|
|
7
|
-
debug('Showing Contentstack ASCII art')
|
|
8
|
-
// Shows Contentstack graphics
|
|
9
|
-
// cli.log(figlet.textSync('Contentstack', {
|
|
10
|
-
// horizontalLayout: 'default',
|
|
11
|
-
// verticalLayout: 'default',
|
|
12
|
-
// }))
|
|
13
|
-
debug('Rendered loading ASCII art')
|
|
14
|
-
// eslint-disable-next-line no-warning-comments
|
|
15
|
-
// TODO: Add this into 'command' class in future when command class is implemented
|
|
16
|
-
// attach user config object which will allow other plugins to access some config methods
|
|
17
|
-
this.config.userConfig = new UserConfig()
|
|
18
|
-
const region = this.config.userConfig.getRegion()
|
|
19
|
-
this.config.contentstackClient = new ContentstackClient(region.cma).instance
|
|
20
|
-
debug('Done loading init hook')
|
|
21
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const Analytics = require('../../util/analytics')
|
|
2
|
-
const {getUUID} = require('../../util/user-config')
|
|
3
|
-
const debug = require('debug')('hooks:analytics')
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line no-warning-comments
|
|
6
|
-
// TODO: Add dimensions customDimensions: {
|
|
7
|
-
// os: 'dimension1',
|
|
8
|
-
// 'cli-version': 'dimension2',
|
|
9
|
-
// },
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This hook gets UUID for Analytics to maintain uniqueness of user and run before every command gets executed.
|
|
13
|
-
*/
|
|
14
|
-
let uuid = getUUID()
|
|
15
|
-
const googleAnalyticsConf = {
|
|
16
|
-
trackingID: 'UA-169821045-2',
|
|
17
|
-
cid: uuid,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const analytics = new Analytics({
|
|
21
|
-
trackingID: googleAnalyticsConf.trackingID,
|
|
22
|
-
cid: googleAnalyticsConf.cid,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param {Object} opts Options provided to hooks via Oclif framework.
|
|
28
|
-
*/
|
|
29
|
-
module.exports = async function (opts) {
|
|
30
|
-
const plugin = opts.Command.plugin
|
|
31
|
-
let result = await analytics.track(opts.Command.id, {
|
|
32
|
-
category: `${plugin.name}`,
|
|
33
|
-
label: `${this.config.version}`,
|
|
34
|
-
os: `${this.config.userAgent}`,
|
|
35
|
-
})
|
|
36
|
-
debug('Analytics captured', result.status)
|
|
37
|
-
if (typeof result === Error) {
|
|
38
|
-
debug('Failed to send analytics.', result)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const {cli} = require('cli-ux')
|
|
2
|
-
const chalk = require('chalk')
|
|
3
|
-
const {Command} = require('@contentstack/cli-command')
|
|
4
|
-
const command = new Command()
|
|
5
|
-
|
|
6
|
-
module.exports = async function (opts) {
|
|
7
|
-
if (opts.Command.id !== 'config:get:region') {
|
|
8
|
-
const region = command.region
|
|
9
|
-
cli.log(chalk.grey(`Currently using ${region.name} region`))
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const Configstore = require('configstore')
|
|
2
|
-
const config = new Configstore('contentstack_cli')
|
|
3
|
-
|
|
4
|
-
module.exports = async function () {
|
|
5
|
-
if (!config.has('authtoken'))
|
|
6
|
-
this.error('Authtoken is not configured. Please configure the authtoken using \'csdx auth:login\'', {exit: 2})
|
|
7
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const Configstore = require('configstore')
|
|
2
|
-
const config = new Configstore('contentstack_cli')
|
|
3
|
-
|
|
4
|
-
const {Command} = require('@contentstack/cli-command')
|
|
5
|
-
const command = new Command()
|
|
6
|
-
|
|
7
|
-
module.exports = async function (data) {
|
|
8
|
-
try {
|
|
9
|
-
if (!config.has('tokens'))
|
|
10
|
-
this.error('No tokens have been added. Please add a token using csdx auth:tokens:add -a [ALIAS]', {exit: 2})
|
|
11
|
-
let tokens = config.get('tokens')
|
|
12
|
-
if (!command.getToken(data.alias))
|
|
13
|
-
this.error(`The configured management token alias ${data.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${data.alias}'`, {exit: 2})
|
|
14
|
-
} catch (error) {
|
|
15
|
-
let message = error.message.split(' ')
|
|
16
|
-
message.unshift(error.value)
|
|
17
|
-
this.error(message.join(' '))
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@oclif/command')
|