@contentstack/cli-cm-export 1.5.8 → 1.6.1
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 +2 -2
- package/lib/commands/cm/stacks/export.d.ts +10 -0
- package/lib/commands/cm/stacks/export.js +108 -0
- package/lib/config/index.d.ts +3 -0
- package/lib/config/index.js +393 -0
- package/lib/export/index.d.ts +1 -0
- package/lib/export/index.js +8 -0
- package/lib/export/module-exporter.d.ts +15 -0
- package/lib/export/module-exporter.js +93 -0
- package/lib/export/modules/assets.d.ts +54 -0
- package/lib/export/modules/assets.js +303 -0
- package/lib/export/modules/base-class.d.ts +48 -0
- package/lib/export/modules/base-class.js +117 -0
- package/lib/export/modules/index.d.ts +3 -0
- package/lib/export/modules/index.js +38 -0
- package/lib/export/modules/locales.d.ts +16 -0
- package/lib/export/modules/locales.js +68 -0
- package/lib/export/modules-js/assets.d.ts +43 -0
- package/lib/export/modules-js/assets.js +391 -0
- package/lib/export/modules-js/content-types.d.ts +21 -0
- package/lib/export/modules-js/content-types.js +75 -0
- package/lib/export/modules-js/custom-roles.d.ts +21 -0
- package/lib/export/modules-js/custom-roles.js +76 -0
- package/lib/export/modules-js/entries.d.ts +18 -0
- package/lib/export/modules-js/entries.js +141 -0
- package/lib/export/modules-js/environments.d.ts +16 -0
- package/lib/export/modules-js/environments.js +62 -0
- package/lib/export/modules-js/extensions.d.ts +18 -0
- package/lib/export/modules-js/extensions.js +57 -0
- package/lib/export/modules-js/global-fields.d.ts +22 -0
- package/lib/export/modules-js/global-fields.js +107 -0
- package/lib/export/modules-js/index.d.ts +1 -0
- package/lib/export/modules-js/index.js +33 -0
- package/lib/export/modules-js/labels.d.ts +14 -0
- package/lib/export/modules-js/labels.js +56 -0
- package/lib/export/modules-js/locales.d.ts +23 -0
- package/lib/export/modules-js/locales.js +67 -0
- package/lib/export/modules-js/marketplace-apps.d.ts +21 -0
- package/lib/export/modules-js/marketplace-apps.js +144 -0
- package/lib/export/modules-js/stack.d.ts +18 -0
- package/lib/export/modules-js/stack.js +91 -0
- package/lib/export/modules-js/webhooks.d.ts +18 -0
- package/lib/export/modules-js/webhooks.js +60 -0
- package/lib/export/modules-js/workflows.d.ts +16 -0
- package/lib/export/modules-js/workflows.js +89 -0
- package/lib/types/default-config.d.ts +158 -0
- package/lib/types/default-config.js +2 -0
- package/lib/types/export-config.d.ts +34 -0
- package/lib/types/export-config.js +2 -0
- package/lib/types/index.d.ts +45 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/basic-login.d.ts +8 -0
- package/lib/utils/basic-login.js +45 -0
- package/lib/utils/common-helper.d.ts +11 -0
- package/lib/utils/common-helper.js +78 -0
- package/lib/utils/export-config-handler.d.ts +3 -0
- package/lib/utils/export-config-handler.js +72 -0
- package/lib/utils/file-helper.d.ts +14 -0
- package/lib/utils/file-helper.js +120 -0
- package/lib/utils/index.d.ts +10 -0
- package/lib/utils/index.js +21 -0
- package/lib/utils/interactive.d.ts +6 -0
- package/lib/utils/interactive.js +71 -0
- package/lib/utils/logger.d.ts +8 -0
- package/lib/utils/logger.js +154 -0
- package/lib/utils/marketplace-app-helper.d.ts +1 -0
- package/lib/utils/marketplace-app-helper.js +23 -0
- package/lib/utils/setup-branches.d.ts +3 -0
- package/lib/utils/setup-branches.js +49 -0
- package/lib/utils/setup-export-dir.d.ts +2 -0
- package/lib/utils/setup-export-dir.js +12 -0
- package/messages/index.json +1 -7
- package/oclif.manifest.json +1 -1
- package/package.json +37 -23
- package/src/app.js +0 -161
- package/src/commands/cm/stacks/export.js +0 -202
- package/src/config/default.js +0 -360
- package/src/lib/export/assets.js +0 -451
- package/src/lib/export/content-types.js +0 -90
- package/src/lib/export/custom-roles.js +0 -93
- package/src/lib/export/entries.js +0 -200
- package/src/lib/export/environments.js +0 -74
- package/src/lib/export/extensions.js +0 -69
- package/src/lib/export/global-fields.js +0 -122
- package/src/lib/export/labels.js +0 -69
- package/src/lib/export/locales.js +0 -72
- package/src/lib/export/marketplace-apps.js +0 -184
- package/src/lib/export/stack.js +0 -99
- package/src/lib/export/webhooks.js +0 -76
- package/src/lib/export/workflows.js +0 -110
- package/src/lib/util/export-flags.js +0 -193
- package/src/lib/util/helper.js +0 -113
- package/src/lib/util/index.js +0 -80
- package/src/lib/util/log.js +0 -158
- package/src/lib/util/login.js +0 -79
- package/src/lib/util/marketplace-app-helper.js +0 -24
- package/src/lib/util/setup-branches.js +0 -56
package/src/lib/util/helper.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const mkdirp = require('mkdirp');
|
|
10
|
-
const bigJSON = require('big-json');
|
|
11
|
-
|
|
12
|
-
exports.readFileSync = (filePath, parse) => {
|
|
13
|
-
let data;
|
|
14
|
-
parse = typeof parse === 'undefined' ? true : parse;
|
|
15
|
-
filePath = path.resolve(filePath);
|
|
16
|
-
if (fs.existsSync(filePath)) {
|
|
17
|
-
data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : data;
|
|
18
|
-
}
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// by default file type is json
|
|
23
|
-
exports.readFile = async (filePath, options = { type: 'json' }) => {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
filePath = path.resolve(filePath);
|
|
26
|
-
fs.readFile(filePath, 'utf-8', (error, data) => {
|
|
27
|
-
if (error) {
|
|
28
|
-
reject(error);
|
|
29
|
-
} else {
|
|
30
|
-
if (options.type !== 'json') {
|
|
31
|
-
return resolve(data);
|
|
32
|
-
}
|
|
33
|
-
resolve(JSON.parse(data));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
exports.makeDirectory = async (path) => {
|
|
40
|
-
if (!path) {
|
|
41
|
-
throw new Error('Invalid path to create directory');
|
|
42
|
-
}
|
|
43
|
-
return mkdirp(path);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.readLargeFile = (filePath, opts = {}) => {
|
|
47
|
-
if (typeof filePath !== 'string') {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
filePath = path.resolve(filePath);
|
|
51
|
-
if (fs.existsSync(filePath)) {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
|
|
54
|
-
const parseStream = bigJSON.createParseStream();
|
|
55
|
-
parseStream.on('data', (data) => {
|
|
56
|
-
if (opts.type === 'array') {
|
|
57
|
-
return resolve(Object.values(data));
|
|
58
|
-
}
|
|
59
|
-
resolve(data);
|
|
60
|
-
});
|
|
61
|
-
parseStream.on('error', (error) => {
|
|
62
|
-
console.log('error', error);
|
|
63
|
-
reject(error);
|
|
64
|
-
});
|
|
65
|
-
readStream.pipe(parseStream);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
exports.writeLargeFile = (filePath, data) => {
|
|
71
|
-
if (typeof filePath !== 'string' || typeof data !== 'object') {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
filePath = path.resolve(filePath);
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
const stringifyStream = bigJSON.createStringifyStream({
|
|
77
|
-
body: data,
|
|
78
|
-
});
|
|
79
|
-
const writeStream = fs.createWriteStream(filePath, 'utf-8');
|
|
80
|
-
stringifyStream.pipe(writeStream);
|
|
81
|
-
writeStream.on('finish', () => {
|
|
82
|
-
resolve();
|
|
83
|
-
});
|
|
84
|
-
writeStream.on('error', (error) => {
|
|
85
|
-
reject(error);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
exports.writeFileSync = (filePath, data) => {
|
|
91
|
-
data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
|
|
92
|
-
fs.writeFileSync(filePath, data);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
exports.writeFile = (filePath, data) => {
|
|
96
|
-
return new Promise((resolve, reject) => {
|
|
97
|
-
data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
|
|
98
|
-
fs.writeFile(filePath, data, (error) => {
|
|
99
|
-
if (error) {
|
|
100
|
-
return reject(error);
|
|
101
|
-
}
|
|
102
|
-
resolve('done');
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
exports.readdir = (dirPath) => {
|
|
108
|
-
if (fs.existsSync(path)) {
|
|
109
|
-
return fs.readdirSync(dirPath);
|
|
110
|
-
} else {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
};
|
package/src/lib/util/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const _ = require('lodash');
|
|
8
|
-
const defaultConfig = require('../../config/default');
|
|
9
|
-
const promiseLimit = require('promise-limit');
|
|
10
|
-
const { isAuthenticated } = require('@contentstack/cli-utilities');
|
|
11
|
-
|
|
12
|
-
exports.validateConfig = (config) => {
|
|
13
|
-
if (!config.host || !config.cdn) {
|
|
14
|
-
throw new Error('Host/CDN end point is missing from config');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (config.email && config.password && !config.access_token && !config.source_stack) {
|
|
18
|
-
throw new Error('Kindly provide access_token or api_token');
|
|
19
|
-
} else if (
|
|
20
|
-
!config.email &&
|
|
21
|
-
!config.password &&
|
|
22
|
-
!config.management_token &&
|
|
23
|
-
config.source_stack &&
|
|
24
|
-
!config.access_token &&
|
|
25
|
-
!isAuthenticated()
|
|
26
|
-
) {
|
|
27
|
-
throw new Error('Kindly provide management_token or email and password');
|
|
28
|
-
} else if (
|
|
29
|
-
config.email &&
|
|
30
|
-
config.password &&
|
|
31
|
-
!config.access_token &&
|
|
32
|
-
config.source_stack &&
|
|
33
|
-
!config.management_token &&
|
|
34
|
-
!isAuthenticated()
|
|
35
|
-
) {
|
|
36
|
-
throw new Error('Kindly provide access_token or management_token');
|
|
37
|
-
} else if (!config.email && !config.password && config.preserveStackVersion) {
|
|
38
|
-
throw new Error('Kindly provide Email and password for stack details');
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
exports.buildAppConfig = function (config) {
|
|
43
|
-
config = _.merge(defaultConfig, config);
|
|
44
|
-
return config;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
exports.formatError = function (error) {
|
|
48
|
-
try {
|
|
49
|
-
if (typeof error === 'string') {
|
|
50
|
-
error = JSON.parse(error);
|
|
51
|
-
} else {
|
|
52
|
-
error = JSON.parse(error.message);
|
|
53
|
-
}
|
|
54
|
-
} catch (e) {}
|
|
55
|
-
let message = error.errorMessage || error.error_message || error.message || error;
|
|
56
|
-
if (error.errors && Object.keys(error.errors).length > 0) {
|
|
57
|
-
Object.keys(error.errors).forEach((e) => {
|
|
58
|
-
let entity = e;
|
|
59
|
-
if (e === 'authorization') entity = 'Management Token';
|
|
60
|
-
if (e === 'api_key') entity = 'Stack API key';
|
|
61
|
-
if (e === 'uid') entity = 'Content Type';
|
|
62
|
-
if (e === 'access_token') entity = 'Delivery Token';
|
|
63
|
-
message += ' ' + [entity, error.errors[e]].join(' ');
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return message;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
exports.executeTask = function (tasks = [], handler, options) {
|
|
70
|
-
if (typeof handler !== 'function') {
|
|
71
|
-
throw new Error('Invalid handler');
|
|
72
|
-
}
|
|
73
|
-
const { concurrency = 1 } = options;
|
|
74
|
-
const limit = promiseLimit(concurrency);
|
|
75
|
-
return Promise.all(
|
|
76
|
-
tasks.map((task) => {
|
|
77
|
-
return limit(() => handler(task));
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
};
|
package/src/lib/util/log.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var winston = require('winston');
|
|
8
|
-
var path = require('path');
|
|
9
|
-
var mkdirp = require('mkdirp');
|
|
10
|
-
var slice = Array.prototype.slice;
|
|
11
|
-
|
|
12
|
-
const ansiRegexPattern = [
|
|
13
|
-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
14
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
|
|
15
|
-
].join('|');
|
|
16
|
-
|
|
17
|
-
function returnString(args) {
|
|
18
|
-
var returnStr = '';
|
|
19
|
-
if (args && args.length) {
|
|
20
|
-
returnStr = args
|
|
21
|
-
.map(function (item) {
|
|
22
|
-
if (item && typeof item === 'object') {
|
|
23
|
-
try {
|
|
24
|
-
return JSON.stringify(item).replace(/authtoken\":\"blt................/g, 'authtoken":"blt....');
|
|
25
|
-
} catch (error) {}
|
|
26
|
-
return item;
|
|
27
|
-
}
|
|
28
|
-
return item;
|
|
29
|
-
})
|
|
30
|
-
.join(' ')
|
|
31
|
-
.trim();
|
|
32
|
-
}
|
|
33
|
-
returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), '').trim();
|
|
34
|
-
return returnStr;
|
|
35
|
-
}
|
|
36
|
-
var myCustomLevels = {
|
|
37
|
-
levels: {
|
|
38
|
-
warn: 1,
|
|
39
|
-
info: 2,
|
|
40
|
-
debug: 3,
|
|
41
|
-
},
|
|
42
|
-
colors: {
|
|
43
|
-
//colors aren't being used anywhere as of now, we're using chalk to add colors while logging
|
|
44
|
-
info: 'blue',
|
|
45
|
-
debug: 'green',
|
|
46
|
-
warn: 'yellow',
|
|
47
|
-
error: 'red',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
let logger;
|
|
52
|
-
let errorLogger;
|
|
53
|
-
|
|
54
|
-
let successTransport;
|
|
55
|
-
let errorTransport;
|
|
56
|
-
|
|
57
|
-
function init(_logPath) {
|
|
58
|
-
if (!logger || !errorLogger) {
|
|
59
|
-
var logsDir = path.resolve(_logPath, 'logs', 'export');
|
|
60
|
-
// Create dir if doesn't already exist
|
|
61
|
-
mkdirp.sync(logsDir);
|
|
62
|
-
|
|
63
|
-
successTransport = {
|
|
64
|
-
filename: path.join(logsDir, 'success.log'),
|
|
65
|
-
maxFiles: 20,
|
|
66
|
-
maxsize: 1000000,
|
|
67
|
-
tailable: true,
|
|
68
|
-
json: true,
|
|
69
|
-
level: 'info',
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
errorTransport = {
|
|
73
|
-
filename: path.join(logsDir, 'error.log'),
|
|
74
|
-
maxFiles: 20,
|
|
75
|
-
maxsize: 1000000,
|
|
76
|
-
tailable: true,
|
|
77
|
-
json: true,
|
|
78
|
-
level: 'error',
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
logger = winston.createLogger({
|
|
82
|
-
transports: [
|
|
83
|
-
new winston.transports.File(successTransport),
|
|
84
|
-
new winston.transports.Console({ format: winston.format.simple() }),
|
|
85
|
-
],
|
|
86
|
-
levels: myCustomLevels.levels,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
errorLogger = winston.createLogger({
|
|
90
|
-
transports: [
|
|
91
|
-
new winston.transports.File(errorTransport),
|
|
92
|
-
new winston.transports.Console({ level: 'error', format: winston.format.simple() }),
|
|
93
|
-
],
|
|
94
|
-
levels: { error: 0 },
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
log: function () {
|
|
100
|
-
let args = slice.call(arguments);
|
|
101
|
-
let logString = returnString(args);
|
|
102
|
-
if (logString) {
|
|
103
|
-
logger.log('info', logString);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
warn: function () {
|
|
107
|
-
let args = slice.call(arguments);
|
|
108
|
-
let logString = returnString(args);
|
|
109
|
-
if (logString) {
|
|
110
|
-
logger.log('warn', logString);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
error: function () {
|
|
114
|
-
let args = slice.call(arguments);
|
|
115
|
-
let logString = returnString(args);
|
|
116
|
-
if (logString) {
|
|
117
|
-
errorLogger.log('error', logString);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
debug: function () {
|
|
121
|
-
let args = slice.call(arguments);
|
|
122
|
-
let logString = returnString(args);
|
|
123
|
-
if (logString) {
|
|
124
|
-
logger.log('debug', logString);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
exports.addlogs = async (config, message, type) => {
|
|
131
|
-
// ignoring the type argument, as we are not using it to create a logfile anymore
|
|
132
|
-
if (type !== 'error') {
|
|
133
|
-
// removed type argument from init method
|
|
134
|
-
init(config.data).log(message);
|
|
135
|
-
} else {
|
|
136
|
-
init(config.data).error(message);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
exports.unlinkFileLogger = () => {
|
|
141
|
-
if (logger) {
|
|
142
|
-
const transports = logger.transports;
|
|
143
|
-
transports.forEach((transport) => {
|
|
144
|
-
if (transport.name === 'file') {
|
|
145
|
-
logger.remove(transport);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (errorLogger) {
|
|
151
|
-
const transports = errorLogger.transports;
|
|
152
|
-
transports.forEach((transport) => {
|
|
153
|
-
if (transport.name === 'file') {
|
|
154
|
-
errorLogger.remove(transport);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
};
|
package/src/lib/util/login.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements-per-line */
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
/* eslint-disable no-empty */
|
|
4
|
-
/*!
|
|
5
|
-
* Contentstack Import
|
|
6
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const chalk = require('chalk');
|
|
11
|
-
const { addlogs } = require('../util/log');
|
|
12
|
-
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
13
|
-
|
|
14
|
-
module.exports.login = (config) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
managementSDKClient(config)
|
|
17
|
-
.then((APIClient) => {
|
|
18
|
-
if (config.email && config.password) {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.log('Logging into Contentstack');
|
|
21
|
-
APIClient.login({ email: config.email, password: config.password })
|
|
22
|
-
.then((response) => {
|
|
23
|
-
// eslint-disable-next-line no-console
|
|
24
|
-
console.log(chalk.green('Contentstack account authenticated successfully!'));
|
|
25
|
-
config.headers = {
|
|
26
|
-
api_key: config.source_stack,
|
|
27
|
-
access_token: config.access_token,
|
|
28
|
-
authtoken: response.user.authtoken,
|
|
29
|
-
'X-User-Agent': 'contentstack-export/v',
|
|
30
|
-
};
|
|
31
|
-
resolve(config);
|
|
32
|
-
})
|
|
33
|
-
.catch((error) => {
|
|
34
|
-
reject(error);
|
|
35
|
-
});
|
|
36
|
-
} else if (isAuthenticated() && !config.management_token) {
|
|
37
|
-
const stackAPIClient = APIClient.stack({
|
|
38
|
-
api_key: config.source_stack,
|
|
39
|
-
management_token: config.management_token,
|
|
40
|
-
});
|
|
41
|
-
stackAPIClient
|
|
42
|
-
.users()
|
|
43
|
-
.then(() => {
|
|
44
|
-
resolve();
|
|
45
|
-
})
|
|
46
|
-
.catch((error) => {
|
|
47
|
-
if (error.errors.api_key) {
|
|
48
|
-
return reject(error);
|
|
49
|
-
}
|
|
50
|
-
addlogs(config, error.errorMessage, 'error');
|
|
51
|
-
reject(error);
|
|
52
|
-
});
|
|
53
|
-
} else if (!config.email && !config.password && config.source_stack && config.access_token) {
|
|
54
|
-
addlogs(
|
|
55
|
-
config,
|
|
56
|
-
chalk.yellow('Content types, entries, assets, labels, global fields, extensions modules will be exported'),
|
|
57
|
-
'success',
|
|
58
|
-
);
|
|
59
|
-
addlogs(
|
|
60
|
-
config,
|
|
61
|
-
chalk.yellow(
|
|
62
|
-
'Email, password, or management token is not set in the config, cannot export Webhook and label modules',
|
|
63
|
-
),
|
|
64
|
-
'success',
|
|
65
|
-
);
|
|
66
|
-
config.headers = {
|
|
67
|
-
api_key: config.source_stack,
|
|
68
|
-
access_token: config.access_token,
|
|
69
|
-
'X-User-Agent': 'contentstack-export/v',
|
|
70
|
-
};
|
|
71
|
-
resolve(config);
|
|
72
|
-
// eslint-disable-next-line no-else-return
|
|
73
|
-
} else if (config.management_token) {
|
|
74
|
-
resolve();
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
.catch((error) => reject(error));
|
|
78
|
-
});
|
|
79
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
let config = require('../../config/default');
|
|
2
|
-
const { cliux, configHandler } = require('@contentstack/cli-utilities');
|
|
3
|
-
|
|
4
|
-
const getDeveloperHubUrl = async () => {
|
|
5
|
-
const { cma, name } = configHandler.get('region') || {};
|
|
6
|
-
let developerHubBaseUrl = config.developerHubUrls[cma];
|
|
7
|
-
|
|
8
|
-
if (!developerHubBaseUrl) {
|
|
9
|
-
developerHubBaseUrl = await cliux.inquire({
|
|
10
|
-
type: 'input',
|
|
11
|
-
name: 'name',
|
|
12
|
-
validate: (url) => {
|
|
13
|
-
if (!url) return "Developer-hub URL can't be empty.";
|
|
14
|
-
|
|
15
|
-
return true;
|
|
16
|
-
},
|
|
17
|
-
message: `Enter the developer-hub base URL for the ${name} region - `,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
module.exports = { getDeveloperHubUrl };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const mkdirp = require('mkdirp');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const helper = require('./helper');
|
|
4
|
-
const {isAuthenticated, configHandler} = require('@contentstack/cli-utilities')
|
|
5
|
-
|
|
6
|
-
const setupBranches = async (config, branch, stackAPIClient) => {
|
|
7
|
-
if (typeof config !== 'object') {
|
|
8
|
-
throw new Error('Invalid config to setup the branch');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let branches = [];
|
|
12
|
-
|
|
13
|
-
const headers = { api_key: config.source_stack };
|
|
14
|
-
|
|
15
|
-
if (isAuthenticated()) {
|
|
16
|
-
headers['authtoken'] = configHandler.get('authtoken');
|
|
17
|
-
} else if (config.management_token) {
|
|
18
|
-
headers['authorization'] = config.management_token;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof branch === 'string') {
|
|
22
|
-
// check branch exists
|
|
23
|
-
const result = await stackAPIClient
|
|
24
|
-
.branch(branch)
|
|
25
|
-
.fetch()
|
|
26
|
-
.catch((_err) => {});
|
|
27
|
-
if (result && typeof result === 'object') {
|
|
28
|
-
branches.push(result);
|
|
29
|
-
} else {
|
|
30
|
-
throw new Error('No branch found with the name ' + branch);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
try {
|
|
34
|
-
const result = await stackAPIClient
|
|
35
|
-
.branch()
|
|
36
|
-
.query()
|
|
37
|
-
.find()
|
|
38
|
-
.catch((_err) => {});
|
|
39
|
-
if (result && result.items && Array.isArray(result.items) && result.items.length > 0) {
|
|
40
|
-
branches = result.items;
|
|
41
|
-
} else {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
mkdirp.sync(config.data);
|
|
50
|
-
// create branch info file
|
|
51
|
-
helper.writeFile(path.join(config.data, 'branches.json'), branches);
|
|
52
|
-
// add branches list in the
|
|
53
|
-
config.branches = branches;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
module.exports = setupBranches;
|