@contentstack/cli-cm-import 0.1.1-beta.1 → 0.1.1-beta.12
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 +13 -9
- package/oclif.manifest.json +1 -1
- package/package.json +13 -10
- package/src/app.js +106 -76
- package/src/commands/cm/import.js +106 -49
- package/src/config/default.js +238 -211
- package/src/lib/import/assets.js +44 -40
- package/src/lib/import/content-types.js +90 -97
- package/src/lib/import/entries.js +423 -406
- package/src/lib/import/environments.js +1 -1
- package/src/lib/import/global-fields.js +4 -0
- package/src/lib/import/labels.js +43 -37
- package/src/lib/import/locales.js +32 -21
- package/src/lib/import/workflows.js +118 -0
- package/src/lib/util/contentstack-management-sdk.js +22 -5
- package/src/lib/util/extensionsUidReplace.js +27 -29
- package/src/lib/util/import-flags.js +135 -75
- package/src/lib/util/index.js +100 -28
- package/src/lib/util/log.js +4 -2
- package/src/lib/util/login.js +4 -4
- package/src/lib/util/lookupReplaceEntries.js +92 -94
- package/src/lib/util/removeReferenceFields.js +3 -5
- package/src/lib/util/supress-mandatory-fields.js +1 -1
|
@@ -4,170 +4,168 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
var
|
|
7
|
+
// eslint-disable-next-line unicorn/filename-case
|
|
8
|
+
var path = require('path')
|
|
9
|
+
var _ = require('lodash')
|
|
9
10
|
|
|
10
|
-
var util = require('
|
|
11
|
-
var helper = require('./fs')
|
|
12
|
-
var config = util.getConfig()
|
|
11
|
+
var util = require('.')
|
|
12
|
+
var helper = require('./fs')
|
|
13
|
+
var config = util.getConfig()
|
|
13
14
|
// update references in entry object
|
|
14
15
|
module.exports = function (data, mappedUids, uidMapperPath) {
|
|
15
|
-
var parent = []
|
|
16
|
-
var uids = []
|
|
17
|
-
var unmapped = []
|
|
18
|
-
var mapped = []
|
|
16
|
+
var parent = []
|
|
17
|
+
var uids = []
|
|
18
|
+
var unmapped = []
|
|
19
|
+
var mapped = []
|
|
19
20
|
|
|
20
|
-
var isNewRefFields = false
|
|
21
|
-
var preserveStackVersion = config.preserveStackVersion
|
|
21
|
+
var isNewRefFields = false
|
|
22
|
+
var preserveStackVersion = config.preserveStackVersion
|
|
22
23
|
|
|
23
24
|
var update = function (parent, form_id, entry) {
|
|
24
|
-
var _entry = entry
|
|
25
|
-
|
|
25
|
+
var _entry = entry
|
|
26
|
+
var len = parent.length
|
|
26
27
|
for (var j = 0; j < len; j++) {
|
|
27
28
|
if (_entry && parent[j]) {
|
|
28
|
-
if (j
|
|
29
|
+
if (j === (len - 1) && _entry[parent[j]]) {
|
|
29
30
|
if (form_id !== '_assets') {
|
|
30
31
|
if (_entry[parent[j]].length) {
|
|
31
32
|
_entry[parent[j]].forEach((item, idx) => {
|
|
32
33
|
if (typeof item.uid === 'string' && item._content_type_uid) {
|
|
33
|
-
uids.push(item.uid)
|
|
34
|
+
uids.push(item.uid)
|
|
34
35
|
} else if (typeof item === 'string' && (preserveStackVersion === true)) {
|
|
35
|
-
uids.push(item)
|
|
36
|
+
uids.push(item)
|
|
36
37
|
} else {
|
|
37
|
-
uids.push(item)
|
|
38
|
+
uids.push(item)
|
|
38
39
|
_entry[parent[j]][idx] = {
|
|
39
40
|
uid: item,
|
|
40
|
-
_content_type_uid: form_id
|
|
41
|
-
}
|
|
41
|
+
_content_type_uid: form_id,
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
|
-
})
|
|
44
|
+
})
|
|
44
45
|
}
|
|
45
|
-
} else {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
uids.push(_entry[parent[j]][k]['uid']);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
if (_entry[parent[j]]['uid'].length) {
|
|
54
|
-
uids.push(_entry[parent[j]]['uid']);
|
|
46
|
+
} else if (Array.isArray(_entry[parent[j]])) {
|
|
47
|
+
for (var k = 0; k < _entry[parent[j]].length; k++) {
|
|
48
|
+
if (_entry[parent[j]][k].uid.length) {
|
|
49
|
+
uids.push(_entry[parent[j]][k].uid)
|
|
55
50
|
}
|
|
56
51
|
}
|
|
52
|
+
} else if (_entry[parent[j]].uid.length) {
|
|
53
|
+
uids.push(_entry[parent[j]].uid)
|
|
57
54
|
}
|
|
58
55
|
} else {
|
|
59
|
-
_entry = _entry[parent[j]]
|
|
60
|
-
var _keys = _.clone(parent).splice(eval(j + 1), len)
|
|
61
|
-
if (_entry
|
|
56
|
+
_entry = _entry[parent[j]]
|
|
57
|
+
var _keys = _.clone(parent).splice(eval(j + 1), len)
|
|
58
|
+
if (Array.isArray(_entry)) {
|
|
62
59
|
for (var i = 0, _i = _entry.length; i < _i; i++) {
|
|
63
|
-
update(_keys, form_id, _entry[i])
|
|
60
|
+
update(_keys, form_id, _entry[i])
|
|
64
61
|
}
|
|
65
62
|
} else if (!(_entry instanceof Object)) {
|
|
66
|
-
break
|
|
63
|
+
break
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
}
|
|
68
|
+
}
|
|
72
69
|
var find = function (schema, entry) {
|
|
73
70
|
for (var i = 0, _i = schema.length; i < _i; i++) {
|
|
74
71
|
switch (schema[i].data_type) {
|
|
75
72
|
case 'reference':
|
|
76
|
-
if (schema[i].reference_to
|
|
77
|
-
isNewRefFields = true
|
|
78
|
-
schema[i].reference_to.forEach(
|
|
79
|
-
parent.push(schema[i].uid)
|
|
80
|
-
update(parent, reference, entry)
|
|
81
|
-
parent.pop()
|
|
82
|
-
})
|
|
73
|
+
if (Array.isArray(schema[i].reference_to)) {
|
|
74
|
+
isNewRefFields = true
|
|
75
|
+
schema[i].reference_to.forEach(reference => {
|
|
76
|
+
parent.push(schema[i].uid)
|
|
77
|
+
update(parent, reference, entry)
|
|
78
|
+
parent.pop()
|
|
79
|
+
})
|
|
83
80
|
} else {
|
|
84
|
-
parent.push(schema[i].uid)
|
|
85
|
-
update(parent, schema[i].reference_to, entry)
|
|
86
|
-
parent.pop()
|
|
81
|
+
parent.push(schema[i].uid)
|
|
82
|
+
update(parent, schema[i].reference_to, entry)
|
|
83
|
+
parent.pop()
|
|
87
84
|
}
|
|
88
|
-
break
|
|
85
|
+
break
|
|
89
86
|
case 'group':
|
|
90
|
-
parent.push(schema[i].uid)
|
|
91
|
-
find(schema[i].schema, entry)
|
|
92
|
-
parent.pop()
|
|
93
|
-
break
|
|
87
|
+
parent.push(schema[i].uid)
|
|
88
|
+
find(schema[i].schema, entry)
|
|
89
|
+
parent.pop()
|
|
90
|
+
break
|
|
94
91
|
case 'blocks':
|
|
95
92
|
for (var j = 0, _j = schema[i].blocks.length; j < _j; j++) {
|
|
96
|
-
parent.push(schema[i].uid)
|
|
97
|
-
parent.push(schema[i].blocks[j].uid)
|
|
98
|
-
find(schema[i].blocks[j].schema, entry)
|
|
99
|
-
parent.pop()
|
|
100
|
-
parent.pop()
|
|
93
|
+
parent.push(schema[i].uid)
|
|
94
|
+
parent.push(schema[i].blocks[j].uid)
|
|
95
|
+
find(schema[i].blocks[j].schema, entry)
|
|
96
|
+
parent.pop()
|
|
97
|
+
parent.pop()
|
|
101
98
|
}
|
|
102
|
-
break
|
|
99
|
+
break
|
|
103
100
|
}
|
|
104
101
|
}
|
|
105
|
-
}
|
|
106
|
-
find(data.content_type.schema, data.entry)
|
|
102
|
+
}
|
|
103
|
+
find(data.content_type.schema, data.entry)
|
|
107
104
|
if (isNewRefFields) {
|
|
108
|
-
findUidsInNewRefFields(data.entry, uids)
|
|
105
|
+
findUidsInNewRefFields(data.entry, uids)
|
|
109
106
|
}
|
|
110
|
-
uids = _.flattenDeep(uids)
|
|
111
|
-
// if no references are found, return
|
|
107
|
+
uids = _.flattenDeep(uids)
|
|
108
|
+
// if no references are found, return
|
|
112
109
|
if (uids.length === 0) {
|
|
113
|
-
return data.entry
|
|
110
|
+
return data.entry
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
uids = _.uniq(uids)
|
|
117
|
-
var entry = JSON.stringify(data.entry)
|
|
118
|
-
uids.forEach(function (uid) {
|
|
113
|
+
uids = _.uniq(uids)
|
|
114
|
+
var entry = JSON.stringify(data.entry)
|
|
115
|
+
uids.forEach(function (uid) {
|
|
119
116
|
if (mappedUids.hasOwnProperty(uid)) {
|
|
120
|
-
entry = entry.replace(new RegExp(uid, 'img'), mappedUids[uid])
|
|
121
|
-
mapped.push(uid)
|
|
117
|
+
entry = entry.replace(new RegExp(uid, 'img'), mappedUids[uid])
|
|
118
|
+
mapped.push(uid)
|
|
122
119
|
} else {
|
|
123
|
-
unmapped.push(uid)
|
|
120
|
+
unmapped.push(uid)
|
|
124
121
|
}
|
|
125
|
-
})
|
|
122
|
+
})
|
|
126
123
|
|
|
127
|
-
if (unmapped.length) {
|
|
128
|
-
var unmappedUids = helper.readFile(path.join(uidMapperPath, 'unmapped-uids.json'))
|
|
129
|
-
unmappedUids = unmappedUids || {}
|
|
124
|
+
if (unmapped.length > 0) {
|
|
125
|
+
var unmappedUids = helper.readFile(path.join(uidMapperPath, 'unmapped-uids.json'))
|
|
126
|
+
unmappedUids = unmappedUids || {}
|
|
130
127
|
if (unmappedUids.hasOwnProperty(data.content_type.uid)) {
|
|
131
|
-
unmappedUids[data.content_type.uid][data.entry.uid] = unmapped
|
|
128
|
+
unmappedUids[data.content_type.uid][data.entry.uid] = unmapped
|
|
132
129
|
} else {
|
|
133
130
|
unmappedUids[data.content_type.uid] = {
|
|
134
|
-
[data.entry.uid]: unmapped
|
|
135
|
-
}
|
|
131
|
+
[data.entry.uid]: unmapped,
|
|
132
|
+
}
|
|
136
133
|
}
|
|
137
134
|
// write the unmapped contents to ./mapper/language/unmapped-uids.json
|
|
138
|
-
helper.writeFile(path.join(uidMapperPath, 'unmapped-uids.json'), unmappedUids)
|
|
135
|
+
helper.writeFile(path.join(uidMapperPath, 'unmapped-uids.json'), unmappedUids)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
if (mapped.length) {
|
|
142
|
-
var _mappedUids = helper.readFile(path.join(uidMapperPath, 'mapped-uids.json'))
|
|
143
|
-
_mappedUids = _mappedUids || {}
|
|
138
|
+
if (mapped.length > 0) {
|
|
139
|
+
var _mappedUids = helper.readFile(path.join(uidMapperPath, 'mapped-uids.json'))
|
|
140
|
+
_mappedUids = _mappedUids || {}
|
|
144
141
|
if (_mappedUids.hasOwnProperty(data.content_type.uid)) {
|
|
145
|
-
_mappedUids[data.content_type.uid][data.entry.uid] = mapped
|
|
142
|
+
_mappedUids[data.content_type.uid][data.entry.uid] = mapped
|
|
146
143
|
} else {
|
|
147
144
|
_mappedUids[data.content_type.uid] = {
|
|
148
|
-
[data.entry.uid]: mapped
|
|
149
|
-
}
|
|
145
|
+
[data.entry.uid]: mapped,
|
|
146
|
+
}
|
|
150
147
|
}
|
|
151
148
|
// write the mapped contents to ./mapper/language/mapped-uids.json
|
|
152
|
-
helper.writeFile(path.join(uidMapperPath, 'mapped-uids.json'), _mappedUids)
|
|
149
|
+
helper.writeFile(path.join(uidMapperPath, 'mapped-uids.json'), _mappedUids)
|
|
153
150
|
}
|
|
154
151
|
|
|
155
|
-
return JSON.parse(entry)
|
|
156
|
-
}
|
|
152
|
+
return JSON.parse(entry)
|
|
153
|
+
}
|
|
157
154
|
|
|
158
155
|
function findUidsInNewRefFields(entry, uids) {
|
|
159
156
|
if (entry && typeof entry === 'object') {
|
|
160
157
|
if (entry.uid && entry._content_type_uid) {
|
|
161
|
-
uids.push(entry.uid)
|
|
162
|
-
} else if (entry
|
|
163
|
-
entry.forEach(function(elem) {
|
|
164
|
-
findUidsInNewRefFields(elem, uids)
|
|
165
|
-
})
|
|
158
|
+
uids.push(entry.uid)
|
|
159
|
+
} else if (Array.isArray(entry) && entry.length) {
|
|
160
|
+
entry.forEach(function (elem) {
|
|
161
|
+
findUidsInNewRefFields(elem, uids)
|
|
162
|
+
})
|
|
166
163
|
} else if (Object.keys(entry).length) {
|
|
167
164
|
for (var key in entry) {
|
|
168
|
-
|
|
165
|
+
if (key) {
|
|
166
|
+
findUidsInNewRefFields(entry[key], uids)
|
|
167
|
+
}
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
|
-
|
|
173
|
-
}
|
|
171
|
+
}
|
|
@@ -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',
|