@contentstack/cli-cm-import 1.2.1 → 1.2.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/README.md
CHANGED
|
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
37
37
|
$ csdx COMMAND
|
|
38
38
|
running command...
|
|
39
39
|
$ csdx (-v|--version|version)
|
|
40
|
-
@contentstack/cli-cm-import/1.2.
|
|
40
|
+
@contentstack/cli-cm-import/1.2.2 darwin-x64 node-v18.12.1
|
|
41
41
|
$ csdx --help [COMMAND]
|
|
42
42
|
USAGE
|
|
43
43
|
$ csdx COMMAND
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.2.
|
|
1
|
+
{"version":"1.2.2","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name> --yes"],"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","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"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"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"},"yes":{"name":"yes","type":"boolean","char":"y","description":"[optional] Override marketplace prompts","required":false,"allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"eslint-config-oclif": "^3.1.0",
|
|
30
30
|
"globby": "^10.0.2",
|
|
31
31
|
"mocha": "^10.0.0",
|
|
32
|
-
"nyc": "^
|
|
32
|
+
"nyc": "^15.1.0"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=8.0.0"
|
|
@@ -154,11 +154,11 @@ class ContentTypesImport {
|
|
|
154
154
|
addlogs(this.importConfig, contentType.uid + ' updated with references', 'success');
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
async updateGlobalFields(
|
|
157
|
+
async updateGlobalFields(uid) {
|
|
158
158
|
const globalField = find(this.globalFields, { uid });
|
|
159
159
|
if (globalField) {
|
|
160
160
|
supress(globalField.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
|
|
161
|
-
let globalFieldObj = this.stackAPIClient.globalField(globalField);
|
|
161
|
+
let globalFieldObj = this.stackAPIClient.globalField(globalField.uid);
|
|
162
162
|
Object.assign(globalFieldObj, cloneDeep(globalField));
|
|
163
163
|
try {
|
|
164
164
|
const globalFieldResponse = await globalFieldObj.update();
|
|
@@ -166,7 +166,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
166
166
|
);
|
|
167
167
|
|
|
168
168
|
if (continueProcess) {
|
|
169
|
-
return resolve();
|
|
169
|
+
return Promise.resolve();
|
|
170
170
|
} else {
|
|
171
171
|
process.exit();
|
|
172
172
|
}
|
|
@@ -197,18 +197,55 @@ module.exports = class ImportMarketplaceApps {
|
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
* @method updateNameInManifestUILocations
|
|
202
|
+
* @param {Array<Object>} locations
|
|
203
|
+
* @returns {Array<Object>}
|
|
204
|
+
*/
|
|
205
|
+
updateNameInManifestUILocations = (locations, appSuffix = 1) => {
|
|
206
|
+
return _.map(locations, (location) => {
|
|
207
|
+
if (location.meta) {
|
|
208
|
+
location.meta = _.map(location.meta, (meta) => {
|
|
209
|
+
meta.name = `${_.first(_.split(meta.name, '◈'))}◈${appSuffix}`;
|
|
210
|
+
|
|
211
|
+
return meta;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return location;
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
getAppName = (name, appSuffix = 1) => {
|
|
220
|
+
if (name.length >= 19) name = name.slice(0, 18);
|
|
221
|
+
|
|
222
|
+
name = `${_.first(_.split(name, '◈'))}◈${appSuffix}`;
|
|
223
|
+
|
|
224
|
+
return name;
|
|
225
|
+
};
|
|
226
|
+
|
|
200
227
|
/**
|
|
201
228
|
* @method createAllPrivateAppsInDeveloperHub
|
|
202
229
|
* @param {Object} options
|
|
203
230
|
* @returns {Promise<void>}
|
|
204
231
|
*/
|
|
205
|
-
createAllPrivateAppsInDeveloperHub = async (options, uidCleaned = false) => {
|
|
232
|
+
createAllPrivateAppsInDeveloperHub = async (options, uidCleaned = false, appSuffix = 1, isRecursive = false) => {
|
|
206
233
|
const self = this;
|
|
207
234
|
const { app, httpClient } = options;
|
|
208
235
|
|
|
209
236
|
return new Promise((resolve) => {
|
|
210
237
|
if (!uidCleaned && app.manifest.ui_location && !_.isEmpty(app.manifest.ui_location.locations)) {
|
|
211
238
|
app.manifest.ui_location.locations = this.removeUidFromManifestUILocations(app.manifest.ui_location.locations);
|
|
239
|
+
} else if (isRecursive && app.manifest.ui_location && !_.isEmpty(app.manifest.ui_location.locations)) {
|
|
240
|
+
app.manifest.ui_location.locations = this.updateNameInManifestUILocations(
|
|
241
|
+
app.manifest.ui_location.locations,
|
|
242
|
+
appSuffix - 1 || 1,
|
|
243
|
+
isRecursive,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (app.manifest.name > 20) {
|
|
248
|
+
app.manifest.name = app.manifest.name.slice(0, 20);
|
|
212
249
|
}
|
|
213
250
|
|
|
214
251
|
httpClient
|
|
@@ -222,7 +259,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
222
259
|
|
|
223
260
|
if (_.toLower(error) === 'conflict') {
|
|
224
261
|
const appName = self.config.forceMarketplaceAppsImport
|
|
225
|
-
? self.getAppName(app.manifest.name)
|
|
262
|
+
? self.getAppName(app.manifest.name, appSuffix)
|
|
226
263
|
: await cliux.inquire({
|
|
227
264
|
type: 'input',
|
|
228
265
|
name: 'name',
|
|
@@ -232,7 +269,10 @@ module.exports = class ImportMarketplaceApps {
|
|
|
232
269
|
});
|
|
233
270
|
app.manifest.name = appName;
|
|
234
271
|
|
|
235
|
-
await self
|
|
272
|
+
await self
|
|
273
|
+
.createAllPrivateAppsInDeveloperHub({ app, httpClient }, true, appSuffix + 1, true)
|
|
274
|
+
.then(resolve)
|
|
275
|
+
.catch(resolve);
|
|
236
276
|
} else {
|
|
237
277
|
if (self.config.forceMarketplaceAppsImport) return resolve();
|
|
238
278
|
|
|
@@ -251,7 +291,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
251
291
|
} else if (data) {
|
|
252
292
|
// NOTE new app installation
|
|
253
293
|
log(self.config, `${name} app created successfully.!`, 'success');
|
|
254
|
-
this.updatePrivateAppUid(app, data, app.manifest
|
|
294
|
+
this.updatePrivateAppUid(app, data, app.manifest);
|
|
255
295
|
}
|
|
256
296
|
|
|
257
297
|
resolve();
|
|
@@ -273,7 +313,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
273
313
|
* @param {Object} app
|
|
274
314
|
* @param {Object} data
|
|
275
315
|
*/
|
|
276
|
-
updatePrivateAppUid = (app, data,
|
|
316
|
+
updatePrivateAppUid = (app, data, manifest) => {
|
|
277
317
|
const self = this;
|
|
278
318
|
const allMarketplaceApps = readFileSync(
|
|
279
319
|
path.resolve(self.marketplaceAppFolderPath, self.marketplaceAppConfig.fileName),
|
|
@@ -283,6 +323,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
283
323
|
if (index > -1) {
|
|
284
324
|
allMarketplaceApps[index] = {
|
|
285
325
|
...allMarketplaceApps[index],
|
|
326
|
+
manifest,
|
|
286
327
|
title: data.name,
|
|
287
328
|
app_uid: data.uid,
|
|
288
329
|
old_title: allMarketplaceApps[index].title,
|
|
@@ -292,9 +333,6 @@ module.exports = class ImportMarketplaceApps {
|
|
|
292
333
|
],
|
|
293
334
|
};
|
|
294
335
|
|
|
295
|
-
// NOTE Update app name
|
|
296
|
-
allMarketplaceApps[index].manifest.name = appName;
|
|
297
|
-
|
|
298
336
|
writeFile(path.join(self.marketplaceAppFolderPath, self.marketplaceAppConfig.fileName), allMarketplaceApps);
|
|
299
337
|
}
|
|
300
338
|
};
|
|
@@ -55,7 +55,28 @@ let extension_uid_Replace = (module.exports = function (schema, preserveStackVer
|
|
|
55
55
|
const oldExt = _.find(marketplaceApps, { uid: schema[i].extension_uid });
|
|
56
56
|
|
|
57
57
|
if (oldExt) {
|
|
58
|
-
|
|
58
|
+
let ext = _.find(installedExtensions, (ext) => {
|
|
59
|
+
const { type, title, app_uid } = ext;
|
|
60
|
+
|
|
61
|
+
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
62
|
+
const titles = [
|
|
63
|
+
...(oldExt.manifest
|
|
64
|
+
? _.map(
|
|
65
|
+
_.map(
|
|
66
|
+
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
67
|
+
'meta',
|
|
68
|
+
).flat(),
|
|
69
|
+
'name',
|
|
70
|
+
)
|
|
71
|
+
: []),
|
|
72
|
+
oldExt.title,
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
return _.includes(titles, title);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
59
80
|
|
|
60
81
|
if (ext) {
|
|
61
82
|
schema[i].extension_uid = ext.uid;
|
|
@@ -80,10 +80,27 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
80
80
|
const oldExt = _.find(marketplaceApps, { uid: schema[i].extension_uid });
|
|
81
81
|
|
|
82
82
|
if (oldExt) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
app_uid
|
|
83
|
+
let ext = _.find(installedExtensions, (ext) => {
|
|
84
|
+
const { type, title, app_uid } = ext;
|
|
85
|
+
|
|
86
|
+
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
87
|
+
const titles = [
|
|
88
|
+
...(oldExt.manifest
|
|
89
|
+
? _.map(
|
|
90
|
+
_.map(
|
|
91
|
+
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
92
|
+
'meta',
|
|
93
|
+
).flat(),
|
|
94
|
+
'name',
|
|
95
|
+
)
|
|
96
|
+
: []),
|
|
97
|
+
oldExt.title,
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
return _.includes(titles, title);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false;
|
|
87
104
|
});
|
|
88
105
|
|
|
89
106
|
if (ext) {
|
|
@@ -104,10 +121,27 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
104
121
|
const oldExt = _.find(marketplaceApps, { uid: row.extension_uid });
|
|
105
122
|
|
|
106
123
|
if (oldExt) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
app_uid
|
|
124
|
+
let ext = _.find(installedExtensions, (ext) => {
|
|
125
|
+
const { type, title, app_uid } = ext;
|
|
126
|
+
|
|
127
|
+
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
128
|
+
const titles = [
|
|
129
|
+
...(oldExt.manifest
|
|
130
|
+
? _.map(
|
|
131
|
+
_.map(
|
|
132
|
+
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
133
|
+
'meta',
|
|
134
|
+
).flat(),
|
|
135
|
+
'name',
|
|
136
|
+
)
|
|
137
|
+
: []),
|
|
138
|
+
oldExt.title,
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
return _.includes(titles, title);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return false;
|
|
111
145
|
});
|
|
112
146
|
|
|
113
147
|
if (ext) {
|
|
@@ -121,10 +155,27 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
121
155
|
const oldExt = _.find(marketplaceApps, { uid: entryObj[row.uid].metadata.extension_uid });
|
|
122
156
|
|
|
123
157
|
if (oldExt) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
app_uid
|
|
158
|
+
let ext = _.find(installedExtensions, (ext) => {
|
|
159
|
+
const { type, title, app_uid } = ext;
|
|
160
|
+
|
|
161
|
+
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
162
|
+
const titles = [
|
|
163
|
+
...(oldExt.manifest
|
|
164
|
+
? _.map(
|
|
165
|
+
_.map(
|
|
166
|
+
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
167
|
+
'meta',
|
|
168
|
+
).flat(),
|
|
169
|
+
'name',
|
|
170
|
+
)
|
|
171
|
+
: []),
|
|
172
|
+
oldExt.title,
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
return _.includes(titles, title);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return false;
|
|
128
179
|
});
|
|
129
180
|
|
|
130
181
|
if (ext) {
|