@contentstack/cli-cm-import 1.5.11 → 1.7.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.
Files changed (126) hide show
  1. package/README.md +6 -14
  2. package/bin/dev +17 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/run +6 -0
  5. package/bin/run.cmd +3 -0
  6. package/lib/commands/cm/stacks/import.d.ts +10 -0
  7. package/lib/commands/cm/stacks/import.js +111 -0
  8. package/lib/config/index.d.ts +3 -0
  9. package/lib/config/index.js +395 -0
  10. package/lib/import/index.d.ts +1 -0
  11. package/lib/import/index.js +8 -0
  12. package/lib/import/module-importer.d.ts +13 -0
  13. package/lib/import/module-importer.js +70 -0
  14. package/lib/import/modules/assets.d.ts +63 -0
  15. package/lib/import/modules/assets.js +265 -0
  16. package/lib/import/modules/base-class.d.ts +70 -0
  17. package/lib/import/modules/base-class.js +218 -0
  18. package/lib/import/modules/content-types.d.ts +56 -0
  19. package/lib/import/modules/content-types.js +186 -0
  20. package/lib/import/modules/custom-roles.d.ts +37 -0
  21. package/lib/import/modules/custom-roles.js +171 -0
  22. package/lib/import/modules/environments.d.ts +27 -0
  23. package/lib/import/modules/environments.js +106 -0
  24. package/lib/import/modules/extensions.d.ts +27 -0
  25. package/lib/import/modules/extensions.js +106 -0
  26. package/lib/import/modules/global-fields.d.ts +34 -0
  27. package/lib/import/modules/global-fields.js +99 -0
  28. package/lib/import/modules/index.d.ts +2 -0
  29. package/lib/import/modules/index.js +19 -0
  30. package/lib/import/modules/labels.d.ts +34 -0
  31. package/lib/import/modules/labels.js +171 -0
  32. package/lib/import/modules/locales.d.ts +31 -0
  33. package/lib/import/modules/locales.js +144 -0
  34. package/lib/import/modules/marketplace-apps.d.ts +51 -0
  35. package/lib/import/modules/marketplace-apps.js +297 -0
  36. package/lib/import/modules/webhooks.d.ts +27 -0
  37. package/lib/import/modules/webhooks.js +110 -0
  38. package/lib/import/modules-js/assets.d.ts +33 -0
  39. package/lib/import/modules-js/assets.js +415 -0
  40. package/lib/import/modules-js/content-types.d.ts +33 -0
  41. package/lib/import/modules-js/content-types.js +176 -0
  42. package/lib/import/modules-js/custom-roles.d.ts +15 -0
  43. package/lib/import/modules-js/custom-roles.js +143 -0
  44. package/lib/import/modules-js/entries.d.ts +54 -0
  45. package/lib/import/modules-js/entries.js +1260 -0
  46. package/lib/import/modules-js/environments.d.ts +13 -0
  47. package/lib/import/modules-js/environments.js +85 -0
  48. package/lib/import/modules-js/extensions.d.ts +18 -0
  49. package/lib/import/modules-js/extensions.js +86 -0
  50. package/lib/import/modules-js/global-fields.d.ts +13 -0
  51. package/lib/import/modules-js/global-fields.js +109 -0
  52. package/lib/import/modules-js/index.d.ts +1 -0
  53. package/lib/import/modules-js/index.js +33 -0
  54. package/lib/import/modules-js/labels.d.ts +20 -0
  55. package/lib/import/modules-js/labels.js +148 -0
  56. package/lib/import/modules-js/locales.d.ts +24 -0
  57. package/lib/import/modules-js/locales.js +196 -0
  58. package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
  59. package/lib/import/modules-js/marketplace-apps.js +409 -0
  60. package/lib/import/modules-js/webhooks.d.ts +17 -0
  61. package/lib/import/modules-js/webhooks.js +85 -0
  62. package/lib/import/modules-js/workflows.d.ts +18 -0
  63. package/lib/import/modules-js/workflows.js +132 -0
  64. package/lib/types/default-config.d.ts +143 -0
  65. package/lib/types/default-config.js +2 -0
  66. package/lib/types/import-config.d.ts +52 -0
  67. package/lib/types/import-config.js +2 -0
  68. package/lib/types/index.d.ts +63 -0
  69. package/lib/types/index.js +4 -0
  70. package/lib/utils/asset-helper.d.ts +4 -0
  71. package/lib/utils/asset-helper.js +387 -0
  72. package/lib/utils/backup-handler.d.ts +2 -0
  73. package/lib/utils/backup-handler.js +31 -0
  74. package/lib/utils/common-helper.d.ts +20 -0
  75. package/lib/utils/common-helper.js +244 -0
  76. package/lib/utils/content-type-helper.d.ts +51 -0
  77. package/lib/utils/content-type-helper.js +145 -0
  78. package/lib/utils/entries-helper.d.ts +4 -0
  79. package/lib/utils/entries-helper.js +252 -0
  80. package/lib/utils/extension-helper.d.ts +5 -0
  81. package/lib/utils/extension-helper.js +84 -0
  82. package/lib/utils/file-helper.d.ts +14 -0
  83. package/lib/utils/file-helper.js +140 -0
  84. package/lib/utils/import-config-handler.d.ts +3 -0
  85. package/lib/utils/import-config-handler.js +73 -0
  86. package/lib/utils/index.d.ts +12 -0
  87. package/lib/utils/index.js +39 -0
  88. package/lib/utils/interactive.d.ts +7 -0
  89. package/lib/utils/interactive.js +88 -0
  90. package/lib/utils/logger.d.ts +8 -0
  91. package/lib/utils/logger.js +154 -0
  92. package/lib/utils/login-handler.d.ts +8 -0
  93. package/lib/utils/login-handler.js +53 -0
  94. package/lib/utils/marketplace-app-helper.d.ts +16 -0
  95. package/lib/utils/marketplace-app-helper.js +143 -0
  96. package/messages/index.json +1 -7
  97. package/oclif.manifest.json +2 -2
  98. package/package.json +46 -20
  99. package/src/app.js +0 -217
  100. package/src/commands/cm/stacks/import.js +0 -161
  101. package/src/config/default.js +0 -352
  102. package/src/lib/import/assets.js +0 -495
  103. package/src/lib/import/content-types.js +0 -201
  104. package/src/lib/import/custom-roles.js +0 -169
  105. package/src/lib/import/entries.js +0 -1495
  106. package/src/lib/import/environments.js +0 -106
  107. package/src/lib/import/extensions.js +0 -108
  108. package/src/lib/import/global-fields.js +0 -135
  109. package/src/lib/import/labels.js +0 -175
  110. package/src/lib/import/locales.js +0 -216
  111. package/src/lib/import/marketplace-apps.js +0 -542
  112. package/src/lib/import/webhooks.js +0 -113
  113. package/src/lib/import/workflows.js +0 -166
  114. package/src/lib/util/extensionsUidReplace.js +0 -67
  115. package/src/lib/util/fs.js +0 -124
  116. package/src/lib/util/import-flags.js +0 -187
  117. package/src/lib/util/index.js +0 -222
  118. package/src/lib/util/log.js +0 -144
  119. package/src/lib/util/login.js +0 -58
  120. package/src/lib/util/lookupReplaceAssets.js +0 -366
  121. package/src/lib/util/lookupReplaceEntries.js +0 -250
  122. package/src/lib/util/marketplace-app-helper.js +0 -31
  123. package/src/lib/util/removeReferenceFields.js +0 -59
  124. package/src/lib/util/schemaTemplate.js +0 -38
  125. package/src/lib/util/supress-mandatory-fields.js +0 -34
  126. package/src/lib/util/upload.js +0 -56
@@ -1,216 +0,0 @@
1
- /* eslint-disable no-prototype-builtins */
2
- /*!
3
- * Contentstack Import
4
- * Copyright (c) 2019 Contentstack LLC
5
- * MIT Licensed
6
- */
7
-
8
- let fs = require('fs');
9
- let path = require('path');
10
- let chalk = require('chalk');
11
- let mkdirp = require('mkdirp');
12
- let Promise = require('bluebird');
13
- let { isEmpty, merge, cloneDeep } = require('lodash');
14
- const { cliux } = require('@contentstack/cli-utilities');
15
-
16
- let helper = require('../util/fs');
17
- let { addlogs } = require('../util/log');
18
- const { formatError } = require('../util');
19
- let config = require('../../config/default');
20
-
21
- module.exports = class ImportLanguages {
22
- fails = [];
23
- success = [];
24
- langUidMapper = {};
25
- masterLanguage = config.master_locale;
26
- langConfig = config.modules.locales;
27
- sourceMasterLangConfig = config.modules.masterLocale;
28
- reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
29
-
30
- constructor(importConfig, stackAPIClient) {
31
- this.config = merge(config, importConfig);
32
- this.stackAPIClient = stackAPIClient;
33
- }
34
-
35
- start() {
36
- addlogs(this.config, 'Migrating languages', 'success');
37
-
38
- const self = this;
39
- let langMapperPath = path.resolve(this.config.data, 'mapper', 'languages');
40
- let langFolderPath = path.resolve(this.config.data, this.langConfig.dirName);
41
- let langFailsPath = path.resolve(this.config.data, 'mapper', 'languages', 'fails.json');
42
- let langUidMapperPath = path.resolve(this.config.data, 'mapper', 'languages', 'uid-mapper.json');
43
- self.langSuccessPath = path.resolve(this.config.data, 'mapper', 'languages', 'success.json');
44
- self.languages = helper.readFileSync(path.resolve(langFolderPath, this.langConfig.fileName));
45
- self.sourceMasterLanguages = helper.readFileSync(path.resolve(langFolderPath, this.sourceMasterLangConfig.fileName));
46
-
47
- mkdirp.sync(langMapperPath);
48
-
49
- if (fs.existsSync(langUidMapperPath)) {
50
- self.langUidMapper = helper.readFileSync(langUidMapperPath);
51
- self.langUidMapper = self.langUidMapper || {};
52
- }
53
-
54
- return new Promise(async function (resolve, reject) {
55
- if (self.languages === undefined || isEmpty(self.languages)) {
56
- addlogs(self.config, chalk.white('No Languages Found'), 'success');
57
- return resolve({ empty: true });
58
- }
59
-
60
- let sourceMasterLangDetails = self.sourceMasterLanguages && Object.values(self.sourceMasterLanguages);
61
- if (sourceMasterLangDetails &&
62
- sourceMasterLangDetails[0] &&
63
- sourceMasterLangDetails[0]["code"] &&
64
- self.masterLanguage["code"] === sourceMasterLangDetails[0]["code"]) {
65
- await self.checkAndUpdateMasterLocaleName(sourceMasterLangDetails).catch((error) => {
66
- addlogs(self.config, formatError(error), 'warn');
67
- })
68
- }
69
-
70
- let langUids = Object.keys(self.languages);
71
- return Promise.map(
72
- langUids,
73
- (langUid) => {
74
- let lang = self.languages[langUid];
75
- if (!self.langUidMapper.hasOwnProperty(langUid) && lang.code !== self.masterLanguage) {
76
- let requestOption = {
77
- locale: {
78
- code: lang.code,
79
- name: lang.name,
80
- },
81
- };
82
-
83
- return self.stackAPIClient
84
- .locale()
85
- .create(requestOption)
86
- .then((locale) => {
87
- self.success.push(locale.items);
88
- self.langUidMapper[langUid] = locale.uid;
89
- helper.writeFileSync(langUidMapperPath, self.langUidMapper);
90
- })
91
- .catch(function (err) {
92
- let error = JSON.parse(err.message);
93
- if (error.hasOwnProperty('errorCode') && error.errorCode === 247) {
94
- if(error.errors.code){
95
- addlogs(self.config, error.errors.code[0], 'error');
96
- }else{
97
- addlogs(self.config, err, 'error');
98
- }
99
- return err;
100
- }
101
- self.fails.push(lang);
102
- addlogs(self.config, `Language '${lang.code}' failed to import\n`, 'error');
103
- addlogs(self.config, formatError(err), 'error');
104
- });
105
- } else {
106
- // the language has already been created
107
- addlogs(self.config, `The language '${lang.code}' already exists.`, 'error');
108
- }
109
-
110
- // import 2 languages at a time
111
- },
112
- { concurrency: self.reqConcurrency },
113
- )
114
- .then(function () {
115
- // languages have imported successfully
116
- self
117
- .updateLocales(langUids)
118
- .then(() => {
119
- helper.writeFileSync(self.langSuccessPath, self.success);
120
- addlogs(self.config, chalk.green('Languages have been imported successfully!'), 'success');
121
- resolve();
122
- })
123
- .catch(function (error) {
124
- addlogs(self.config, formatError(error), 'error');
125
- reject(error);
126
- });
127
- })
128
- .catch(function (error) {
129
- // error while importing languages
130
- helper.writeFileSync(langFailsPath, self.fails);
131
- addlogs(self.config, `Language import failed. ${formatError(error)}`, 'error');
132
- reject('failed to import Languages');
133
- });
134
- });
135
- }
136
-
137
- updateLocales(langUids) {
138
- let self = this;
139
- return new Promise(function (resolve, reject) {
140
- Promise.all(
141
- langUids.map(async (langUid) => {
142
- let lang = {};
143
- let requireKeys = self.config.modules.locales.requiredKeys;
144
- let _lang = self.languages[langUid];
145
- requireKeys.forEach((e) => {
146
- lang[e] = _lang[e];
147
- });
148
- let langobj = self.stackAPIClient.locale(lang.code);
149
- Object.assign(langobj, cloneDeep(lang));
150
- langobj.update().then(() => {
151
- // empty function
152
- });
153
- }),
154
- )
155
- .then(resolve)
156
- .catch((error) => {
157
- addlogs(self.config, formatError(error), 'error');
158
- reject(error);
159
- });
160
- });
161
- }
162
-
163
- checkAndUpdateMasterLocaleName(sourceMasterLangDetails) {
164
- let self = this;
165
- return new Promise(async function (resolve, reject) {
166
- let masterLangDetails = await self.stackAPIClient.locale(self.masterLanguage["code"]).fetch()
167
- .catch((error) => {
168
- addlogs(self.config, formatError(error), 'warn');
169
- })
170
- if (masterLangDetails &&
171
- masterLangDetails["name"] &&
172
- sourceMasterLangDetails[0]["name"] &&
173
- masterLangDetails["name"].toString().toUpperCase() !== sourceMasterLangDetails[0]["name"].toString().toUpperCase()
174
- ) {
175
- cliux.print(
176
- 'WARNING!!! The master language name for the source and destination is different.',
177
- { color: 'yellow' },
178
- );
179
- cliux.print(
180
- `Old Master language name: ${masterLangDetails["name"]}`,
181
- { color: 'red' },
182
- );
183
- cliux.print(
184
- `New Master language name: ${sourceMasterLangDetails[0]["name"]}`,
185
- { color: 'green' },
186
- );
187
- let confirm = await cliux.inquire({
188
- type: 'confirm',
189
- message: 'Are you sure you want to update name of master language?',
190
- name: 'confirmation',
191
- })
192
-
193
- if (confirm) {
194
- let languid = sourceMasterLangDetails[0] && sourceMasterLangDetails[0]["uid"];
195
- let lang = self.sourceMasterLanguages[languid];
196
- if (!lang) return reject('Locale not found.!');
197
- const langObj = self.stackAPIClient.locale(lang.code);
198
- Object.assign(langObj, { name: lang.name });
199
- langObj.update()
200
- .then(() => {
201
- helper.writeFileSync(self.langSuccessPath, self.success);
202
- addlogs(self.config, chalk.green('Master Languages name have been updated successfully!'), 'success');
203
- resolve();
204
- })
205
- .catch(function (error) {
206
- reject(error);
207
- });
208
- } else {
209
- resolve();
210
- }
211
- } else {
212
- resolve();
213
- }
214
- });
215
- }
216
- };