@contentstack/cli-cm-export 1.4.0 → 1.5.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 +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +9 -5
- package/src/app.js +2 -2
- package/src/commands/cm/stacks/export.js +4 -8
- package/src/lib/export/assets.js +2 -2
- package/src/lib/export/marketplace-apps.js +11 -4
- package/src/lib/export/stack.js +2 -2
- package/src/lib/util/export-flags.js +1 -10
- package/src/lib/util/index.js +3 -2
- package/src/lib/util/login.js +3 -4
- package/src/lib/util/setup-branches.js +3 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ $ npm install -g @contentstack/cli-cm-export
|
|
|
38
38
|
$ csdx COMMAND
|
|
39
39
|
running command...
|
|
40
40
|
$ csdx (--version)
|
|
41
|
-
@contentstack/cli-cm-export/1.
|
|
41
|
+
@contentstack/cli-cm-export/1.5.0 linux-x64 node-v16.20.0
|
|
42
42
|
$ csdx --help [COMMAND]
|
|
43
43
|
USAGE
|
|
44
44
|
$ csdx COMMAND
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export",
|
|
3
3
|
"description": "Contentstack CLI plugin to export content from stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "^1.2.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.2.
|
|
8
|
+
"@contentstack/cli-command": "^1.2.1",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.2.1",
|
|
10
10
|
"@oclif/command": "^1.8.16",
|
|
11
11
|
"@oclif/config": "^1.18.3",
|
|
12
12
|
"async": "^3.2.4",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"winston": "^3.7.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@contentstack/cli-auth": "^1.2.
|
|
27
|
-
"@contentstack/cli-config": "^1.2.
|
|
26
|
+
"@contentstack/cli-auth": "^1.2.1",
|
|
27
|
+
"@contentstack/cli-config": "^1.2.1",
|
|
28
28
|
"@contentstack/cli-dev-dependencies": "^1.2.0",
|
|
29
29
|
"@oclif/plugin-help": "^5.1.19",
|
|
30
30
|
"@oclif/test": "^1.2.6",
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
"csdxConfig": {
|
|
74
74
|
"expiredCommands": {
|
|
75
75
|
"cm:export": "csdx cm:stacks:export"
|
|
76
|
+
},
|
|
77
|
+
"shortCommandName": {
|
|
78
|
+
"cm:stacks:export": "EXPRT",
|
|
79
|
+
"cm:export": "O-EXPRT"
|
|
76
80
|
}
|
|
77
81
|
},
|
|
78
82
|
"main": "./src/commands/cm/stacks/export.js",
|
package/src/app.js
CHANGED
|
@@ -6,7 +6,7 @@ const util = require('./lib/util');
|
|
|
6
6
|
const login = require('./lib/util/login');
|
|
7
7
|
const setupBranches = require('./lib/util/setup-branches');
|
|
8
8
|
const { addlogs, unlinkFileLogger } = require('./lib/util/log');
|
|
9
|
-
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
9
|
+
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
10
10
|
|
|
11
11
|
exports.initial = async (config) => {
|
|
12
12
|
return new Promise(async (resolve, reject) => {
|
|
@@ -56,7 +56,7 @@ exports.initial = async (config) => {
|
|
|
56
56
|
if (
|
|
57
57
|
(config.email && config.password) ||
|
|
58
58
|
(!config.email && !config.password && config.source_stack && config.access_token) ||
|
|
59
|
-
(
|
|
59
|
+
(isAuthenticated() && !config.management_token)
|
|
60
60
|
) {
|
|
61
61
|
login
|
|
62
62
|
.login(config)
|
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
withoutParametersWithAuthToken,
|
|
10
10
|
} = require('../../../lib/util/export-flags');
|
|
11
11
|
const config = require('../../../config/default');
|
|
12
|
-
const { configHandler, printFlagDeprecation, flags } = require('@contentstack/cli-utilities');
|
|
12
|
+
const { configHandler, printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
13
13
|
|
|
14
14
|
class ExportCommand extends Command {
|
|
15
15
|
async run() {
|
|
@@ -22,7 +22,6 @@ class ExportCommand extends Command {
|
|
|
22
22
|
const moduleName = exportCommandFlags.module;
|
|
23
23
|
const contentTypes = exportCommandFlags['content-types'];
|
|
24
24
|
const branchName = exportCommandFlags.branch;
|
|
25
|
-
let _authToken = configHandler.get('authtoken');
|
|
26
25
|
let host = this.region;
|
|
27
26
|
let cmaHost = host.cma.split('//');
|
|
28
27
|
let cdaHost = host.cda.split('//');
|
|
@@ -56,7 +55,6 @@ class ExportCommand extends Command {
|
|
|
56
55
|
data,
|
|
57
56
|
moduleName,
|
|
58
57
|
host,
|
|
59
|
-
_authToken,
|
|
60
58
|
contentTypes,
|
|
61
59
|
branchName,
|
|
62
60
|
securedAssets,
|
|
@@ -66,7 +64,6 @@ class ExportCommand extends Command {
|
|
|
66
64
|
managementTokens,
|
|
67
65
|
moduleName,
|
|
68
66
|
host,
|
|
69
|
-
_authToken,
|
|
70
67
|
contentTypes,
|
|
71
68
|
branchName,
|
|
72
69
|
securedAssets,
|
|
@@ -77,12 +74,11 @@ class ExportCommand extends Command {
|
|
|
77
74
|
} else {
|
|
78
75
|
this.log(alias + ' management token is not present, please add managment token first');
|
|
79
76
|
}
|
|
80
|
-
} else if (
|
|
77
|
+
} else if (isAuthenticated()) {
|
|
81
78
|
if (extConfig) {
|
|
82
|
-
await configWithAuthToken(extConfig,
|
|
79
|
+
await configWithAuthToken(extConfig, moduleName, host, contentTypes, branchName, securedAssets);
|
|
83
80
|
} else if (sourceStack && data) {
|
|
84
81
|
return await parametersWithAuthToken(
|
|
85
|
-
_authToken,
|
|
86
82
|
sourceStack,
|
|
87
83
|
data,
|
|
88
84
|
moduleName,
|
|
@@ -92,7 +88,7 @@ class ExportCommand extends Command {
|
|
|
92
88
|
securedAssets,
|
|
93
89
|
);
|
|
94
90
|
} else if (data === undefined && sourceStack === undefined) {
|
|
95
|
-
await withoutParametersWithAuthToken(
|
|
91
|
+
await withoutParametersWithAuthToken(moduleName, host, contentTypes, branchName, securedAssets);
|
|
96
92
|
} else {
|
|
97
93
|
this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
|
|
98
94
|
}
|
package/src/lib/export/assets.js
CHANGED
|
@@ -11,7 +11,7 @@ const Promise = require('bluebird');
|
|
|
11
11
|
const _ = require('lodash');
|
|
12
12
|
const chalk = require('chalk');
|
|
13
13
|
const progress = require('progress-stream');
|
|
14
|
-
const { HttpClient } = require('@contentstack/cli-utilities');
|
|
14
|
+
const { HttpClient, configHandler } = require('@contentstack/cli-utilities');
|
|
15
15
|
|
|
16
16
|
const helper = require('../util/helper');
|
|
17
17
|
const { addlogs } = require('../util/log');
|
|
@@ -350,7 +350,7 @@ module.exports = class ExportAssets {
|
|
|
350
350
|
}
|
|
351
351
|
self.assetStream = {
|
|
352
352
|
url: self.config.securedAssets
|
|
353
|
-
? `${asset.url}?authtoken=${
|
|
353
|
+
? `${asset.url}?authtoken=${configHandler.get('authtoken')}`
|
|
354
354
|
: asset.url,
|
|
355
355
|
};
|
|
356
356
|
|
|
@@ -7,7 +7,14 @@ const _ = require('lodash');
|
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const chalk = require('chalk');
|
|
9
9
|
const mkdirp = require('mkdirp');
|
|
10
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
cliux,
|
|
12
|
+
HttpClient,
|
|
13
|
+
NodeCrypto,
|
|
14
|
+
managementSDKClient,
|
|
15
|
+
isAuthenticated,
|
|
16
|
+
configHandler
|
|
17
|
+
} = require('@contentstack/cli-utilities');
|
|
11
18
|
|
|
12
19
|
const { formatError } = require('../util');
|
|
13
20
|
const config = require('../../config/default');
|
|
@@ -29,7 +36,7 @@ module.exports = class ExportMarketplaceApps {
|
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
async start() {
|
|
32
|
-
if (!
|
|
39
|
+
if (!isAuthenticated()) {
|
|
33
40
|
cliux.print(
|
|
34
41
|
'WARNING!!! To export Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in',
|
|
35
42
|
{ color: 'yellow' },
|
|
@@ -42,7 +49,7 @@ module.exports = class ExportMarketplaceApps {
|
|
|
42
49
|
await this.getOrgUid();
|
|
43
50
|
|
|
44
51
|
this.httpClient = new HttpClient().headers({
|
|
45
|
-
authtoken:
|
|
52
|
+
authtoken: configHandler.get('authtoken'),
|
|
46
53
|
organization_uid: this.config.org_uid,
|
|
47
54
|
});
|
|
48
55
|
|
|
@@ -58,7 +65,7 @@ module.exports = class ExportMarketplaceApps {
|
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
async getOrgUid() {
|
|
61
|
-
if (
|
|
68
|
+
if (isAuthenticated()) {
|
|
62
69
|
const tempAPIClient = await managementSDKClient({ host: this.config.host });
|
|
63
70
|
const tempStackData = await tempAPIClient
|
|
64
71
|
.stack({ api_key: this.config.source_stack })
|
package/src/lib/export/stack.js
CHANGED
|
@@ -10,7 +10,7 @@ const { merge } = require('lodash');
|
|
|
10
10
|
const helper = require('../util/helper');
|
|
11
11
|
const { addlogs } = require('../util/log');
|
|
12
12
|
const config = require('../../config/default');
|
|
13
|
-
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
13
|
+
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
14
14
|
module.exports = class ExportStack {
|
|
15
15
|
stackConfig = config.modules.stack;
|
|
16
16
|
|
|
@@ -27,7 +27,7 @@ module.exports = class ExportStack {
|
|
|
27
27
|
|
|
28
28
|
async start() {
|
|
29
29
|
const self = this;
|
|
30
|
-
if (
|
|
30
|
+
if (isAuthenticated()) {
|
|
31
31
|
const tempAPIClient = await managementSDKClient({ host: config.host });
|
|
32
32
|
const tempStackData = await tempAPIClient
|
|
33
33
|
.stack({ api_key: self.config.source_stack })
|
|
@@ -35,13 +35,11 @@ exports.parameterWithMToken = async function (
|
|
|
35
35
|
data,
|
|
36
36
|
moduleName,
|
|
37
37
|
host,
|
|
38
|
-
_authToken,
|
|
39
38
|
contentTypes,
|
|
40
39
|
branchName,
|
|
41
40
|
securedAssets,
|
|
42
41
|
) {
|
|
43
42
|
defaultConfig.management_token = managementTokens.token;
|
|
44
|
-
defaultConfig.auth_token = _authToken;
|
|
45
43
|
defaultConfig.host = host.cma;
|
|
46
44
|
defaultConfig.cdn = host.cda;
|
|
47
45
|
defaultConfig.branchName = branchName;
|
|
@@ -65,7 +63,6 @@ exports.withoutParameterMToken = async (
|
|
|
65
63
|
managementTokens,
|
|
66
64
|
moduleName,
|
|
67
65
|
host,
|
|
68
|
-
_authToken,
|
|
69
66
|
contentTypes,
|
|
70
67
|
branchName,
|
|
71
68
|
securedAssets,
|
|
@@ -76,7 +73,6 @@ exports.withoutParameterMToken = async (
|
|
|
76
73
|
defaultConfig.host = host.cma;
|
|
77
74
|
defaultConfig.cdn = host.cda;
|
|
78
75
|
defaultConfig.branchName = branchName;
|
|
79
|
-
defaultConfig.auth_token = _authToken;
|
|
80
76
|
defaultConfig.securedAssets = securedAssets;
|
|
81
77
|
if (moduleName) {
|
|
82
78
|
defaultConfig.moduleName = moduleName;
|
|
@@ -90,9 +86,8 @@ exports.withoutParameterMToken = async (
|
|
|
90
86
|
await initial(defaultConfig);
|
|
91
87
|
};
|
|
92
88
|
|
|
93
|
-
exports.configWithAuthToken = async function (config,
|
|
89
|
+
exports.configWithAuthToken = async function (config, moduleName, host, contentTypes, branchName, securedAssets) {
|
|
94
90
|
let externalConfig = helper.readFile(path.resolve(config));
|
|
95
|
-
defaultConfig.auth_token = _authToken;
|
|
96
91
|
defaultConfig.host = host.cma;
|
|
97
92
|
defaultConfig.cdn = host.cda;
|
|
98
93
|
defaultConfig.branchName = branchName;
|
|
@@ -109,7 +104,6 @@ exports.configWithAuthToken = async function (config, _authToken, moduleName, ho
|
|
|
109
104
|
};
|
|
110
105
|
|
|
111
106
|
exports.parametersWithAuthToken = function (
|
|
112
|
-
_authToken,
|
|
113
107
|
sourceStack,
|
|
114
108
|
data,
|
|
115
109
|
moduleName,
|
|
@@ -119,7 +113,6 @@ exports.parametersWithAuthToken = function (
|
|
|
119
113
|
securedAssets,
|
|
120
114
|
) {
|
|
121
115
|
return new Promise(async (resolve, reject) => {
|
|
122
|
-
defaultConfig.auth_token = _authToken;
|
|
123
116
|
defaultConfig.source_stack = sourceStack;
|
|
124
117
|
if (moduleName) {
|
|
125
118
|
defaultConfig.moduleName = moduleName;
|
|
@@ -144,7 +137,6 @@ exports.parametersWithAuthToken = function (
|
|
|
144
137
|
};
|
|
145
138
|
|
|
146
139
|
exports.withoutParametersWithAuthToken = async (
|
|
147
|
-
_authToken,
|
|
148
140
|
moduleName,
|
|
149
141
|
host,
|
|
150
142
|
contentTypes,
|
|
@@ -153,7 +145,6 @@ exports.withoutParametersWithAuthToken = async (
|
|
|
153
145
|
) => {
|
|
154
146
|
const stackUid = await cliux.prompt(message.promptMessageList.promptSourceStack);
|
|
155
147
|
const pathOfExport = await cliux.prompt(message.promptMessageList.promptPathStoredData);
|
|
156
|
-
defaultConfig.auth_token = _authToken;
|
|
157
148
|
defaultConfig.source_stack = stackUid;
|
|
158
149
|
defaultConfig.securedAssets = securedAssets;
|
|
159
150
|
if (moduleName) {
|
package/src/lib/util/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var _ = require('lodash');
|
|
|
8
8
|
var defaultConfig = require('../../config/default');
|
|
9
9
|
const chalk = require('chalk');
|
|
10
10
|
const promiseLimit = require('promise-limit');
|
|
11
|
+
const { isAuthenticated } = require('@contentstack/cli-utilities')
|
|
11
12
|
|
|
12
13
|
exports.validateConfig = function (config) {
|
|
13
14
|
if (!config.host || !config.cdn) {
|
|
@@ -22,7 +23,7 @@ exports.validateConfig = function (config) {
|
|
|
22
23
|
!config.management_token &&
|
|
23
24
|
config.source_stack &&
|
|
24
25
|
!config.access_token &&
|
|
25
|
-
!
|
|
26
|
+
!isAuthenticated()
|
|
26
27
|
) {
|
|
27
28
|
throw new Error('Kindly provide management_token or email and password');
|
|
28
29
|
} else if (
|
|
@@ -31,7 +32,7 @@ exports.validateConfig = function (config) {
|
|
|
31
32
|
!config.access_token &&
|
|
32
33
|
config.source_stack &&
|
|
33
34
|
!config.management_token &&
|
|
34
|
-
!
|
|
35
|
+
!isAuthenticated()
|
|
35
36
|
) {
|
|
36
37
|
throw new Error('Kindly provide access_token or management_token');
|
|
37
38
|
} else if (!config.email && !config.password && config.preserveStackVersion) {
|
package/src/lib/util/login.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const chalk = require('chalk');
|
|
11
11
|
const { addlogs } = require('../util/log');
|
|
12
|
-
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
12
|
+
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
13
13
|
|
|
14
14
|
module.exports.login = (config) => {
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
@@ -22,11 +22,10 @@ module.exports.login = (config) => {
|
|
|
22
22
|
.then((response) => {
|
|
23
23
|
// eslint-disable-next-line no-console
|
|
24
24
|
console.log(chalk.green('Contentstack account authenticated successfully!'));
|
|
25
|
-
config.authtoken = response.user.authtoken;
|
|
26
25
|
config.headers = {
|
|
27
26
|
api_key: config.source_stack,
|
|
28
27
|
access_token: config.access_token,
|
|
29
|
-
authtoken:
|
|
28
|
+
authtoken: response.user.authtoken,
|
|
30
29
|
'X-User-Agent': 'contentstack-export/v',
|
|
31
30
|
};
|
|
32
31
|
resolve(config);
|
|
@@ -34,7 +33,7 @@ module.exports.login = (config) => {
|
|
|
34
33
|
.catch((error) => {
|
|
35
34
|
reject(error);
|
|
36
35
|
});
|
|
37
|
-
} else if (
|
|
36
|
+
} else if (isAuthenticated() && !config.management_token) {
|
|
38
37
|
const stackAPIClient = APIClient.stack({
|
|
39
38
|
api_key: config.source_stack,
|
|
40
39
|
management_token: config.management_token,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const mkdirp = require('mkdirp');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const helper = require('./helper');
|
|
4
|
+
const {isAuthenticated, configHandler} = require('@contentstack/cli-utilities')
|
|
4
5
|
|
|
5
6
|
const setupBranches = async (config, branch, stackAPIClient) => {
|
|
6
7
|
if (typeof config !== 'object') {
|
|
@@ -9,8 +10,8 @@ const setupBranches = async (config, branch, stackAPIClient) => {
|
|
|
9
10
|
let branches = [];
|
|
10
11
|
const headers = { api_key: config.source_stack };
|
|
11
12
|
|
|
12
|
-
if (
|
|
13
|
-
headers['authtoken'] =
|
|
13
|
+
if (isAuthenticated()) {
|
|
14
|
+
headers['authtoken'] = configHandler.get('authtoken');
|
|
14
15
|
} else if (config.management_token) {
|
|
15
16
|
headers['authorization'] = config.management_token;
|
|
16
17
|
}
|