@contentstack/cli-cm-import 0.1.1-beta.10 → 0.1.1-beta.13
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 +7 -2
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
- package/src/app.js +4 -7
- package/src/commands/cm/import.js +29 -16
- package/src/lib/import/assets.js +3 -3
- package/src/lib/import/content-types.js +1 -3
- package/src/lib/import/entries.js +1 -11
- package/src/lib/import/global-fields.js +1 -0
- package/src/lib/import/workflows.js +6 -1
- package/src/lib/util/contentstack-management-sdk.js +9 -4
- package/src/lib/util/import-flags.js +18 -12
- package/src/lib/util/index.js +29 -29
- package/src/lib/util/login.js +2 -2
- package/src/lib/util/removeReferenceFields.js +3 -5
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
16
16
|
$ csdx COMMAND
|
|
17
17
|
running command...
|
|
18
18
|
$ csdx (-v|--version|version)
|
|
19
|
-
@contentstack/cli-cm-import/0.1.1-beta.
|
|
19
|
+
@contentstack/cli-cm-import/0.1.1-beta.13 linux-x64 node-v12.22.7
|
|
20
20
|
$ csdx --help [COMMAND]
|
|
21
21
|
USAGE
|
|
22
22
|
$ csdx COMMAND
|
|
@@ -29,12 +29,15 @@ USAGE
|
|
|
29
29
|
|
|
30
30
|
## `csdx cm:import`
|
|
31
31
|
|
|
32
|
+
Import script for importing the content into new stack
|
|
33
|
+
|
|
32
34
|
```
|
|
33
35
|
USAGE
|
|
34
36
|
$ csdx cm:import
|
|
35
37
|
|
|
36
38
|
OPTIONS
|
|
37
39
|
-A, --auth-token to use auth token
|
|
40
|
+
-B, --branch=branch [optional] branch name
|
|
38
41
|
-a, --management-token-alias=management-token-alias alias of the management token
|
|
39
42
|
-b, --backup-dir=backup-dir [optional] backup directory name when using specific module
|
|
40
43
|
-c, --config=config [optional] path of config file
|
|
@@ -55,7 +58,9 @@ EXAMPLES
|
|
|
55
58
|
csdx cm:import -a <management_token_alias>
|
|
56
59
|
csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>
|
|
57
60
|
csdx cm:import -a <management_token_alias> -c <path/of/config/file>
|
|
61
|
+
csdx cm:import -A -m <single module name>
|
|
62
|
+
csdx cm:import -A -B <branch name>
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
_See code: [src/commands/cm/import.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.
|
|
65
|
+
_See code: [src/commands/cm/import.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.13/packages/contentstack-import/src/commands/cm/import.js)_
|
|
61
66
|
<!-- commandsstop -->
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.1.1-beta.
|
|
1
|
+
{"version":"0.1.1-beta.13","commands":{"cm:import":{"id":"cm:import","description":"Import script for importing the content into new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:import command.\n","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":[],"examples":["csdx cm:import -A","csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>","csdx cm:import -A -c <path/of/config/dir>","csdx cm:import -A -m <single module name>","csdx cm:import -A -m <single module name> -b <backup dir>","csdx cm:import -a <management_token_alias>","csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>","csdx cm:import -a <management_token_alias> -c <path/of/config/file>","csdx cm:import -A -m <single module name>","csdx cm:import -A -B <branch name>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack"},"data":{"name":"data","type":"option","char":"d","description":"path and location where data is stored"},"management-token-alias":{"name":"management-token-alias","type":"option","char":"a","description":"alias of the management token"},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "0.1.1-beta.
|
|
4
|
+
"version": "0.1.1-beta.13",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "0.1.
|
|
9
|
-
"@contentstack/management": "^1.
|
|
8
|
+
"@contentstack/cli-command": "0.1.1-beta.6",
|
|
9
|
+
"@contentstack/management": "^1.3.0",
|
|
10
10
|
"@oclif/command": "^1.6.1",
|
|
11
11
|
"@oclif/config": "^1.15.1",
|
|
12
12
|
"axios": "^0.21.1",
|
|
13
13
|
"bluebird": "3.5.1",
|
|
14
14
|
"configstore": "^5.0.1",
|
|
15
|
-
"debug": "4.1.0",
|
|
15
|
+
"debug": "^4.1.0",
|
|
16
16
|
"lodash": "^4.17.20",
|
|
17
17
|
"marked": "0.7.0",
|
|
18
18
|
"mkdirp": "^1.0.4",
|
package/src/app.js
CHANGED
|
@@ -11,18 +11,15 @@ let path = require('path')
|
|
|
11
11
|
const chalk = require('chalk')
|
|
12
12
|
const helper = require('./lib/util/fs')
|
|
13
13
|
let _ = require('lodash')
|
|
14
|
-
|
|
15
14
|
let login = require('./lib/util/login')
|
|
16
15
|
let util = require('./lib/util/index')
|
|
17
|
-
|
|
18
|
-
|
|
19
16
|
let { addlogs } = require('./lib/util/log')
|
|
20
17
|
|
|
21
18
|
exports.initial = function (configData) {
|
|
22
19
|
return new Promise(function (resolve, reject) {
|
|
23
20
|
let config = util.initialization(configData)
|
|
24
21
|
config.oldPath = config.data
|
|
25
|
-
if (config
|
|
22
|
+
if (config) {
|
|
26
23
|
login(config)
|
|
27
24
|
.then(function () {
|
|
28
25
|
if (fs.existsSync(config.data)) {
|
|
@@ -36,7 +33,7 @@ exports.initial = function (configData) {
|
|
|
36
33
|
})
|
|
37
34
|
.then(() => {
|
|
38
35
|
let types = config.modules.types
|
|
39
|
-
if (config.moduleName
|
|
36
|
+
if (config.moduleName) {
|
|
40
37
|
singleImport(config.moduleName, types, config).then(() => {
|
|
41
38
|
return resolve()
|
|
42
39
|
})
|
|
@@ -89,7 +86,7 @@ let singleImport = async (moduleName, types, config) => {
|
|
|
89
86
|
addlogs(config, 'Failed to migrate ' + moduleName, 'error')
|
|
90
87
|
addlogs(config, error, 'error')
|
|
91
88
|
addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error')
|
|
92
|
-
return reject()
|
|
89
|
+
return reject(error)
|
|
93
90
|
})
|
|
94
91
|
} else {
|
|
95
92
|
addlogs(config, 'Please provide valid module name.', 'error')
|
|
@@ -125,7 +122,7 @@ let allImport = async (config, types) => {
|
|
|
125
122
|
addlogs(config, chalk.red('Failed to migrate stack: ' + config.target_stack + '. Please check error logs for more info'), 'error')
|
|
126
123
|
addlogs(config, error, 'error')
|
|
127
124
|
addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error')
|
|
128
|
-
return reject()
|
|
125
|
+
return reject(error)
|
|
129
126
|
}
|
|
130
127
|
})
|
|
131
128
|
}
|
|
@@ -14,29 +14,31 @@ const {configWithMToken,
|
|
|
14
14
|
class ImportCommand extends Command {
|
|
15
15
|
async run() {
|
|
16
16
|
let self = this
|
|
17
|
-
const
|
|
18
|
-
const extConfig =
|
|
19
|
-
let targetStack =
|
|
20
|
-
const data =
|
|
21
|
-
const moduleName =
|
|
22
|
-
const backupdir =
|
|
23
|
-
const alias =
|
|
24
|
-
const authToken =
|
|
17
|
+
const importCommandFlags = self.parse(ImportCommand).flags
|
|
18
|
+
const extConfig = importCommandFlags.config
|
|
19
|
+
let targetStack = importCommandFlags['stack-uid']
|
|
20
|
+
const data = importCommandFlags.data
|
|
21
|
+
const moduleName = importCommandFlags.module
|
|
22
|
+
const backupdir = importCommandFlags["backup-dir"]
|
|
23
|
+
const alias = importCommandFlags['management-token-alias']
|
|
24
|
+
const authToken = importCommandFlags['auth-token']
|
|
25
25
|
let _authToken = credStore.get('authtoken')
|
|
26
|
+
let branchName = importCommandFlags.branch
|
|
26
27
|
let host = self.cmaHost
|
|
27
28
|
|
|
28
29
|
return new Promise(function (resolve, reject) {
|
|
29
|
-
if (alias
|
|
30
|
+
if (alias) {
|
|
30
31
|
let managementTokens = self.getToken(alias)
|
|
31
32
|
|
|
32
|
-
if (managementTokens
|
|
33
|
-
if (extConfig &&
|
|
33
|
+
if (managementTokens) {
|
|
34
|
+
if (extConfig && _authToken) {
|
|
34
35
|
configWithMToken(
|
|
35
36
|
extConfig,
|
|
36
37
|
managementTokens,
|
|
37
38
|
moduleName,
|
|
38
39
|
host,
|
|
39
40
|
_authToken,
|
|
41
|
+
branchName,
|
|
40
42
|
backupdir
|
|
41
43
|
)
|
|
42
44
|
.then(() => {
|
|
@@ -49,6 +51,7 @@ class ImportCommand extends Command {
|
|
|
49
51
|
moduleName,
|
|
50
52
|
host,
|
|
51
53
|
_authToken,
|
|
54
|
+
branchName,
|
|
52
55
|
backupdir
|
|
53
56
|
)
|
|
54
57
|
.then(() => {
|
|
@@ -60,6 +63,7 @@ class ImportCommand extends Command {
|
|
|
60
63
|
moduleName,
|
|
61
64
|
host,
|
|
62
65
|
_authToken,
|
|
66
|
+
branchName,
|
|
63
67
|
backupdir
|
|
64
68
|
)
|
|
65
69
|
.then(() => {
|
|
@@ -69,13 +73,14 @@ class ImportCommand extends Command {
|
|
|
69
73
|
} else {
|
|
70
74
|
console.log('management Token is not present please add managment token first')
|
|
71
75
|
}
|
|
72
|
-
} else if (authToken &&
|
|
73
|
-
if (extConfig
|
|
76
|
+
} else if (authToken && _authToken) {
|
|
77
|
+
if (extConfig) {
|
|
74
78
|
configWithAuthToken(
|
|
75
79
|
extConfig,
|
|
76
80
|
_authToken,
|
|
77
81
|
moduleName,
|
|
78
82
|
host,
|
|
83
|
+
branchName,
|
|
79
84
|
backupdir
|
|
80
85
|
)
|
|
81
86
|
.then(() => {
|
|
@@ -88,7 +93,8 @@ class ImportCommand extends Command {
|
|
|
88
93
|
data,
|
|
89
94
|
moduleName,
|
|
90
95
|
host,
|
|
91
|
-
backupdir
|
|
96
|
+
backupdir,
|
|
97
|
+
branchName
|
|
92
98
|
)
|
|
93
99
|
.then(() => {
|
|
94
100
|
return resolve()
|
|
@@ -98,7 +104,8 @@ class ImportCommand extends Command {
|
|
|
98
104
|
_authToken,
|
|
99
105
|
moduleName,
|
|
100
106
|
host,
|
|
101
|
-
backupdir
|
|
107
|
+
backupdir,
|
|
108
|
+
branchName
|
|
102
109
|
)
|
|
103
110
|
.then(() => {
|
|
104
111
|
return resolve()
|
|
@@ -124,6 +131,8 @@ ImportCommand.examples = [
|
|
|
124
131
|
`csdx cm:import -a <management_token_alias>`,
|
|
125
132
|
`csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>`,
|
|
126
133
|
`csdx cm:import -a <management_token_alias> -c <path/of/config/file>`,
|
|
134
|
+
`csdx cm:import -A -m <single module name>`,
|
|
135
|
+
`csdx cm:import -A -B <branch name>`,
|
|
127
136
|
]
|
|
128
137
|
ImportCommand.flags = {
|
|
129
138
|
config: flags.string({
|
|
@@ -153,7 +162,11 @@ ImportCommand.flags = {
|
|
|
153
162
|
"backup-dir": flags.string({
|
|
154
163
|
char: 'b',
|
|
155
164
|
description: '[optional] backup directory name when using specific module'
|
|
165
|
+
}),
|
|
166
|
+
'branch': flags.string({
|
|
167
|
+
char: 'B',
|
|
168
|
+
description: '[optional] branch name'
|
|
156
169
|
})
|
|
157
170
|
}
|
|
158
171
|
|
|
159
|
-
module.exports = ImportCommand
|
|
172
|
+
module.exports = ImportCommand
|
package/src/lib/import/assets.js
CHANGED
|
@@ -142,11 +142,11 @@ importAssets.prototype = {
|
|
|
142
142
|
}
|
|
143
143
|
// TODO: if there are failures, retry
|
|
144
144
|
return resolve()
|
|
145
|
-
}).catch(function () {
|
|
146
|
-
return reject()
|
|
145
|
+
}).catch(function (error) {
|
|
146
|
+
return reject(error)
|
|
147
147
|
})
|
|
148
148
|
}).catch(function (error) {
|
|
149
|
-
return reject()
|
|
149
|
+
return reject(error)
|
|
150
150
|
})
|
|
151
151
|
})
|
|
152
152
|
},
|
|
@@ -36,7 +36,6 @@ let client
|
|
|
36
36
|
let stack = {}
|
|
37
37
|
|
|
38
38
|
function importContentTypes() {
|
|
39
|
-
let self = this
|
|
40
39
|
this.contentTypes = []
|
|
41
40
|
this.schemaTemplate = require('../util/schemaTemplate')
|
|
42
41
|
this.requestOptions = {
|
|
@@ -180,7 +179,7 @@ importContentTypes.prototype = {
|
|
|
180
179
|
return resolve()
|
|
181
180
|
}).catch(err => {
|
|
182
181
|
addlogs(config, err, 'error')
|
|
183
|
-
return reject()
|
|
182
|
+
return reject(err)
|
|
184
183
|
})
|
|
185
184
|
}, 1000)
|
|
186
185
|
})
|
|
@@ -191,7 +190,6 @@ importContentTypes.prototype = {
|
|
|
191
190
|
return new Promise(function (resolve, reject) {
|
|
192
191
|
// eslint-disable-next-line no-undef
|
|
193
192
|
return Promise.map(globalFieldPendingPath, function (globalfield) {
|
|
194
|
-
let lenGlobalField = (self.globalfields).length
|
|
195
193
|
let Obj = _.find(self.globalfields, {uid: globalfield})
|
|
196
194
|
let globalFieldObj = stack.globalField(globalfield)
|
|
197
195
|
Object.assign(globalFieldObj, _.cloneDeep(Obj))
|
|
@@ -448,14 +448,6 @@ importEntries.prototype = {
|
|
|
448
448
|
return
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
-
let requestObject = {
|
|
452
|
-
qs: {
|
|
453
|
-
locale: lang,
|
|
454
|
-
},
|
|
455
|
-
json: {
|
|
456
|
-
entry: entry,
|
|
457
|
-
},
|
|
458
|
-
}
|
|
459
451
|
let promiseResult = new Promise((resolve, reject) => {
|
|
460
452
|
let entryResponse = client.stack({api_key: config.target_stack, management_token: config.management_token}).contentType(ctUid).entry(entry.uid)
|
|
461
453
|
Object.assign(entryResponse, entry)
|
|
@@ -482,7 +474,7 @@ importEntries.prototype = {
|
|
|
482
474
|
locale: lang,
|
|
483
475
|
error: error,
|
|
484
476
|
})
|
|
485
|
-
return reject()
|
|
477
|
+
return reject(error)
|
|
486
478
|
})
|
|
487
479
|
})
|
|
488
480
|
await promiseResult
|
|
@@ -615,7 +607,6 @@ importEntries.prototype = {
|
|
|
615
607
|
})
|
|
616
608
|
},
|
|
617
609
|
unSuppressFields: function () {
|
|
618
|
-
let self = this
|
|
619
610
|
return new Promise(function (resolve, reject) {
|
|
620
611
|
let modifiedSchemas = helper.readFile(modifiedSchemaPath)
|
|
621
612
|
let modifiedSchemasUids = []
|
|
@@ -719,7 +710,6 @@ importEntries.prototype = {
|
|
|
719
710
|
})
|
|
720
711
|
},
|
|
721
712
|
field_rules_update: function (schema) {
|
|
722
|
-
let self = this
|
|
723
713
|
return new Promise(function (resolve, reject) {
|
|
724
714
|
if (schema.field_rules) {
|
|
725
715
|
let fieldRuleLength = schema.field_rules.length
|
|
@@ -74,8 +74,13 @@ importWorkflows.prototype = {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
if(workflow.admin_users !== undefined) {
|
|
78
|
+
addlogs(config, chalk.yellow('We are skipping import of `Workflow superuser(s)` from workflow'), 'info');
|
|
79
|
+
delete workflow.admin_users;
|
|
80
|
+
}
|
|
81
|
+
|
|
77
82
|
let requestOption = {
|
|
78
|
-
workflow
|
|
83
|
+
workflow
|
|
79
84
|
};
|
|
80
85
|
|
|
81
86
|
return client.stack({ api_key: config.target_stack, management_token: config.management_token }).workflow().create(requestOption)
|
|
@@ -22,7 +22,12 @@ exports.Client = function (config) {
|
|
|
22
22
|
retryDelayOptions: {
|
|
23
23
|
base: 1000,
|
|
24
24
|
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
}
|
|
26
|
+
if (typeof config.branchName === 'string') {
|
|
27
|
+
option.headers = {
|
|
28
|
+
branch: config.branchName,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const client = contentstacksdk.client(option)
|
|
32
|
+
return client
|
|
33
|
+
}
|
|
@@ -9,10 +9,11 @@ let _ = require('lodash')
|
|
|
9
9
|
const { cli } = require('cli-ux')
|
|
10
10
|
let message = require('../../../messages/index.json')
|
|
11
11
|
|
|
12
|
-
exports.configWithMToken = function (config, managementTokens, moduleName, host, _authToken, backupdir) {
|
|
12
|
+
exports.configWithMToken = function (config, managementTokens, moduleName, host, _authToken, backupdir, branchName) {
|
|
13
13
|
return new Promise(async function (resolve, reject) {
|
|
14
14
|
let externalConfig = require(config)
|
|
15
15
|
defaultConfig.management_token = managementTokens.token
|
|
16
|
+
defaultConfig.branchName = branchName
|
|
16
17
|
if (moduleName && moduleName !== undefined) {
|
|
17
18
|
defaultConfig.moduleName = moduleName
|
|
18
19
|
}
|
|
@@ -26,16 +27,17 @@ exports.configWithMToken = function (config, managementTokens, moduleName, host,
|
|
|
26
27
|
.then(() => {
|
|
27
28
|
return resolve()
|
|
28
29
|
}).catch((error) => {
|
|
29
|
-
return reject()
|
|
30
|
+
return reject(error)
|
|
30
31
|
})
|
|
31
32
|
})
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
exports.parameterWithMToken = function (managementTokens, data, moduleName, host, _authToken, backupdir) {
|
|
35
|
+
exports.parameterWithMToken = function (managementTokens, data, moduleName, host, _authToken, backupdir, branchName) {
|
|
35
36
|
return new Promise(async function (resolve, reject) {
|
|
36
37
|
defaultConfig.management_token = managementTokens.token
|
|
37
38
|
defaultConfig.target_stack = managementTokens.apiKey
|
|
38
39
|
defaultConfig.auth_token = _authToken
|
|
40
|
+
defaultConfig.branchName = branchName
|
|
39
41
|
if (moduleName && moduleName !== undefined) {
|
|
40
42
|
defaultConfig.moduleName = moduleName
|
|
41
43
|
}
|
|
@@ -48,18 +50,19 @@ exports.parameterWithMToken = function (managementTokens, data, moduleName, host
|
|
|
48
50
|
.then(() => {
|
|
49
51
|
return resolve()
|
|
50
52
|
}).catch((error) => {
|
|
51
|
-
return reject()
|
|
53
|
+
return reject(error)
|
|
52
54
|
})
|
|
53
55
|
})
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
// using ManagemetToken
|
|
57
|
-
exports.withoutParameterMToken = async (managementTokens, moduleName, host, _authToken, backupdir) => {
|
|
59
|
+
exports.withoutParameterMToken = async (managementTokens, moduleName, host, _authToken, backupdir, branchName) => {
|
|
58
60
|
return new Promise(async function (resolve, reject) {
|
|
59
61
|
const exporteddata = await cli.prompt(message.promptMessageList.promptPathStoredData)
|
|
60
62
|
defaultConfig.management_token = managementTokens.token
|
|
61
63
|
defaultConfig.target_stack = managementTokens.apiKey
|
|
62
64
|
defaultConfig.auth_token = _authToken
|
|
65
|
+
defaultConfig.branchName = branchName
|
|
63
66
|
if (moduleName && moduleName !== undefined) {
|
|
64
67
|
defaultConfig.moduleName = moduleName
|
|
65
68
|
}
|
|
@@ -72,15 +75,16 @@ exports.withoutParameterMToken = async (managementTokens, moduleName, host, _aut
|
|
|
72
75
|
.then(() => {
|
|
73
76
|
return resolve()
|
|
74
77
|
}).catch((error) => {
|
|
75
|
-
return reject()
|
|
78
|
+
return reject(error)
|
|
76
79
|
})
|
|
77
80
|
})
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
exports.configWithAuthToken = function (config, _authToken, moduleName, host, backupdir) {
|
|
83
|
+
exports.configWithAuthToken = function (config, _authToken, moduleName, host, backupdir, branchName) {
|
|
81
84
|
return new Promise(async function (resolve, reject) {
|
|
82
85
|
let externalConfig = require(config)
|
|
83
86
|
defaultConfig.auth_token = _authToken
|
|
87
|
+
defaultConfig.branchName = branchName
|
|
84
88
|
if (moduleName && moduleName !== undefined) {
|
|
85
89
|
defaultConfig.moduleName = moduleName
|
|
86
90
|
}
|
|
@@ -99,15 +103,16 @@ exports.configWithAuthToken = function (config, _authToken, moduleName, host, ba
|
|
|
99
103
|
.then(() => {
|
|
100
104
|
return resolve()
|
|
101
105
|
}).catch((error) => {
|
|
102
|
-
return reject()
|
|
106
|
+
return reject(error)
|
|
103
107
|
})
|
|
104
108
|
})
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
exports.parametersWithAuthToken = function (_authToken, targetStack, data, moduleName, host, backupdir) {
|
|
111
|
+
exports.parametersWithAuthToken = function (_authToken, targetStack, data, moduleName, host, backupdir, branchName) {
|
|
108
112
|
return new Promise(async function (resolve, reject) {
|
|
109
113
|
defaultConfig.auth_token = _authToken
|
|
110
114
|
defaultConfig.target_stack = targetStack
|
|
115
|
+
defaultConfig.branchName = branchName
|
|
111
116
|
if (moduleName && moduleName !== undefined && backupdir === undefined) {
|
|
112
117
|
defaultConfig.moduleName = moduleName
|
|
113
118
|
} else if (moduleName && moduleName !== undefined && backupdir !== undefined) {
|
|
@@ -121,18 +126,19 @@ exports.parametersWithAuthToken = function (_authToken, targetStack, data, modul
|
|
|
121
126
|
.then(() => {
|
|
122
127
|
return resolve()
|
|
123
128
|
}).catch((error) => {
|
|
124
|
-
return reject()
|
|
129
|
+
return reject(error)
|
|
125
130
|
})
|
|
126
131
|
})
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
exports.withoutParametersWithAuthToken = async (_authToken, moduleName, host, backupdir) => {
|
|
134
|
+
exports.withoutParametersWithAuthToken = async (_authToken, moduleName, host, backupdir, branchName) => {
|
|
130
135
|
return new Promise(async function (resolve, reject) {
|
|
131
136
|
const stackUid = await cli.prompt(message.promptMessageList.promptTargetStack)
|
|
132
137
|
const exporteddata = await cli.prompt(message.promptMessageList.promptPathStoredData)
|
|
133
138
|
defaultConfig.auth_token = _authToken
|
|
134
139
|
defaultConfig.target_stack = stackUid
|
|
135
140
|
defaultConfig.data = exporteddata
|
|
141
|
+
defaultConfig.branchName = branchName
|
|
136
142
|
if (moduleName && moduleName !== undefined && backupdir === undefined) {
|
|
137
143
|
defaultConfig.moduleName = moduleName
|
|
138
144
|
} else if (moduleName && moduleName !== undefined && backupdir !== undefined) {
|
|
@@ -146,7 +152,7 @@ exports.withoutParametersWithAuthToken = async (_authToken, moduleName, host, ba
|
|
|
146
152
|
.then(() => {
|
|
147
153
|
return resolve()
|
|
148
154
|
}).catch((error) => {
|
|
149
|
-
return reject()
|
|
155
|
+
return reject(error)
|
|
150
156
|
})
|
|
151
157
|
})
|
|
152
158
|
}
|
package/src/lib/util/index.js
CHANGED
|
@@ -24,40 +24,40 @@ exports.initialization = function(configData) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
exports.validateConfig = function (
|
|
28
|
-
if (
|
|
29
|
-
addlogs(
|
|
27
|
+
exports.validateConfig = function (importConfig) {
|
|
28
|
+
if (importConfig.email && importConfig.password && !importConfig.target_stack) {
|
|
29
|
+
addlogs(importConfig, chalk.red('Kindly provide api_token'), 'error')
|
|
30
30
|
return 'error'
|
|
31
|
-
} if(!
|
|
32
|
-
addlogs(
|
|
31
|
+
} else if(!importConfig.email && !importConfig.password && !importConfig.management_token && importConfig.target_stack && !importConfig.auth_token) {
|
|
32
|
+
addlogs(importConfig, chalk.red('Kindly provide management_token or email and password'), 'error')
|
|
33
33
|
return 'error'
|
|
34
|
-
} else if(!
|
|
35
|
-
addlogs(
|
|
34
|
+
} else if(!importConfig.email && !importConfig.password && importConfig.preserveStackVersion) {
|
|
35
|
+
addlogs(importConfig, chalk.red('Kindly provide Email and password for old version stack'), 'error')
|
|
36
36
|
return 'error'
|
|
37
|
-
} else if(
|
|
38
|
-
addlogs(
|
|
37
|
+
} else if(importConfig.email && !importConfig.password || !importConfig.email && importConfig.password) {
|
|
38
|
+
addlogs(importConfig, chalk.red('Kindly provide Email and password'), 'error')
|
|
39
39
|
return 'error'
|
|
40
40
|
}
|
|
41
|
-
// if(!
|
|
42
|
-
// addlogs(
|
|
41
|
+
// if(!importConfig.languagesCode.includes(importConfig.master_locale.code)) {
|
|
42
|
+
// addlogs(importConfig, chalk.red('Kindly provide valid master_locale code'), 'error')
|
|
43
43
|
// return 'error'
|
|
44
44
|
// }
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
exports.buildAppConfig = function (
|
|
48
|
-
|
|
49
|
-
return
|
|
47
|
+
exports.buildAppConfig = function (importConfig) {
|
|
48
|
+
importConfig = _.merge(defaultConfig, importConfig)
|
|
49
|
+
return importConfig
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
exports.sanitizeStack = function (
|
|
53
|
-
if (typeof
|
|
52
|
+
exports.sanitizeStack = function (importConfig) {
|
|
53
|
+
if (typeof importConfig.preserveStackVersion !== 'boolean' || !importConfig.preserveStackVersion) {
|
|
54
54
|
return Promise.resolve()
|
|
55
55
|
}
|
|
56
|
-
addlogs(
|
|
56
|
+
addlogs(importConfig, 'Running script to maintain stack version.', 'success')
|
|
57
57
|
var getStackOptions = {
|
|
58
|
-
url:
|
|
58
|
+
url: importConfig.host + importConfig.apis.stacks,
|
|
59
59
|
method: 'GET',
|
|
60
|
-
headers:
|
|
60
|
+
headers: importConfig.headers,
|
|
61
61
|
json: true
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -67,7 +67,7 @@ exports.sanitizeStack = function (config) {
|
|
|
67
67
|
if (stackDetails.body && stackDetails.body.stack && stackDetails.body.stack.settings) {
|
|
68
68
|
const newStackVersion = stackDetails.body.stack.settings.version
|
|
69
69
|
const newStackDate = new Date(newStackVersion).toString()
|
|
70
|
-
const stackFilePath = path.join(
|
|
70
|
+
const stackFilePath = path.join(importConfig.data, importConfig.modules.stack.dirName, importConfig.modules.stack.fileName)
|
|
71
71
|
|
|
72
72
|
const oldStackDetails = fs.readFile(stackFilePath)
|
|
73
73
|
if (!oldStackDetails || !oldStackDetails.settings || !oldStackDetails.settings.hasOwnProperty('version')) {
|
|
@@ -78,15 +78,15 @@ exports.sanitizeStack = function (config) {
|
|
|
78
78
|
if (oldStackDate > newStackDate) {
|
|
79
79
|
throw new Error('Migration Error. You cannot migrate data from new stack onto old. Kindly contact support@contentstack.com for more details.')
|
|
80
80
|
} else if (oldStackDate === newStackDate) {
|
|
81
|
-
addlogs(
|
|
81
|
+
addlogs(importConfig, 'The version of both the stacks are same.', 'success')
|
|
82
82
|
return Promise.resolve()
|
|
83
83
|
}
|
|
84
|
-
addlogs(
|
|
84
|
+
addlogs(importConfig, 'Updating stack version.', 'success')
|
|
85
85
|
// Update the new stack
|
|
86
86
|
var updateStackOptions = {
|
|
87
|
-
url:
|
|
87
|
+
url: importConfig.host + importConfig.apis.stacks + 'settings/set-version',
|
|
88
88
|
method: 'PUT',
|
|
89
|
-
headers:
|
|
89
|
+
headers: importConfig.headers,
|
|
90
90
|
body: {
|
|
91
91
|
stack_settings: {
|
|
92
92
|
version: '2017-10-14' // This can be used as a variable
|
|
@@ -96,7 +96,7 @@ exports.sanitizeStack = function (config) {
|
|
|
96
96
|
|
|
97
97
|
return request(updateStackOptions)
|
|
98
98
|
.then((response) => {
|
|
99
|
-
addlogs(
|
|
99
|
+
addlogs(importConfig, `Stack version preserved successfully!\n${JSON.stringify(response.body)}`, 'success')
|
|
100
100
|
return;
|
|
101
101
|
})
|
|
102
102
|
}
|
|
@@ -125,9 +125,9 @@ exports.masterLocalDetails = function(credentialConfig) {
|
|
|
125
125
|
})
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
exports.field_rules_update = function(
|
|
128
|
+
exports.field_rules_update = function(importConfig, ctPath) {
|
|
129
129
|
return new Promise(function (resolve, reject) {
|
|
130
|
-
let client = stack.Client(
|
|
130
|
+
let client = stack.Client(importConfig)
|
|
131
131
|
|
|
132
132
|
fs.readFile(path.join(ctPath + '/field_rules_uid.json'), async (err, data) => {
|
|
133
133
|
if (err) {
|
|
@@ -145,7 +145,7 @@ exports.field_rules_update = function(config, ctPath) {
|
|
|
145
145
|
let fieldRuleConditionLength = schema.field_rules[k].conditions.length
|
|
146
146
|
for (let i = 0; i < fieldRuleConditionLength; i++) {
|
|
147
147
|
if (schema.field_rules[k].conditions[i].operand_field === 'reference') {
|
|
148
|
-
let entryMapperPath = path.resolve(
|
|
148
|
+
let entryMapperPath = path.resolve(importConfig.data, 'mapper', 'entries')
|
|
149
149
|
let entryUidMapperPath = path.join(entryMapperPath, 'uid-mapping.json')
|
|
150
150
|
let fieldRulesValue = schema.field_rules[k].conditions[i].value
|
|
151
151
|
let fieldRulesArray = fieldRulesValue.split('.')
|
|
@@ -163,7 +163,7 @@ exports.field_rules_update = function(config, ctPath) {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
let ctObj = client.stack({ api_key:
|
|
166
|
+
let ctObj = client.stack({ api_key: importConfig.target_stack, management_token: importConfig.management_token }).contentType(schema.uid)
|
|
167
167
|
Object.assign(ctObj, _.cloneDeep(schema))
|
|
168
168
|
ctObj.update()
|
|
169
169
|
.then(() => {
|
package/src/lib/util/login.js
CHANGED
|
@@ -44,10 +44,10 @@ module.exports = function (config) {
|
|
|
44
44
|
let errorstack_key = error.errors.api_key
|
|
45
45
|
if(error.errors.api_key) {
|
|
46
46
|
addlogs(config, chalk.red("Stack Api key " + errorstack_key[0], "Please enter valid Key"), 'error')
|
|
47
|
-
return reject()
|
|
47
|
+
return reject(error)
|
|
48
48
|
}
|
|
49
49
|
addlogs(config, error.errorMessage, 'error')
|
|
50
|
-
return reject()
|
|
50
|
+
return reject(error)
|
|
51
51
|
})
|
|
52
52
|
}
|
|
53
53
|
});
|
|
@@ -4,7 +4,7 @@ var _ = require('lodash');
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable no-empty */
|
|
6
6
|
var removeReferenceFields = module.exports = function (schema, flag) {
|
|
7
|
-
for (
|
|
7
|
+
for (let i = 0; i < schema.length; i++) {
|
|
8
8
|
if (schema[i].data_type === 'group') {
|
|
9
9
|
removeReferenceFields(schema[i].schema, flag);
|
|
10
10
|
} else if (schema[i].data_type === 'blocks') {
|
|
@@ -13,10 +13,8 @@ var removeReferenceFields = module.exports = function (schema, flag) {
|
|
|
13
13
|
}
|
|
14
14
|
} else if(schema[i].data_type === 'reference') {
|
|
15
15
|
flag.supressed = true;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
|
|
16
|
+
schema.splice(i, 1);
|
|
17
|
+
--i;
|
|
20
18
|
if(schema.length < 1) {
|
|
21
19
|
schema.push({
|
|
22
20
|
'data_type': 'text',
|