@contentstack/cli-cm-import 1.28.1 → 2.0.1-beta

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 (85) hide show
  1. package/README.md +5 -7
  2. package/lib/commands/cm/stacks/import.d.ts +2 -0
  3. package/lib/commands/cm/stacks/import.js +46 -11
  4. package/lib/config/index.js +0 -1
  5. package/lib/import/module-importer.js +6 -20
  6. package/lib/import/modules/assets.d.ts +6 -0
  7. package/lib/import/modules/assets.js +102 -25
  8. package/lib/import/modules/base-class.d.ts +17 -0
  9. package/lib/import/modules/base-class.js +45 -0
  10. package/lib/import/modules/content-types.d.ts +7 -10
  11. package/lib/import/modules/content-types.js +132 -68
  12. package/lib/import/modules/custom-roles.d.ts +6 -2
  13. package/lib/import/modules/custom-roles.js +80 -69
  14. package/lib/import/modules/entries.d.ts +7 -0
  15. package/lib/import/modules/entries.js +278 -163
  16. package/lib/import/modules/environments.d.ts +3 -0
  17. package/lib/import/modules/environments.js +69 -38
  18. package/lib/import/modules/extensions.d.ts +3 -0
  19. package/lib/import/modules/extensions.js +99 -64
  20. package/lib/import/modules/global-fields.d.ts +8 -1
  21. package/lib/import/modules/global-fields.js +123 -63
  22. package/lib/import/modules/index.d.ts +1 -0
  23. package/lib/import/modules/index.js +1 -0
  24. package/lib/import/modules/labels.d.ts +3 -0
  25. package/lib/import/modules/labels.js +104 -54
  26. package/lib/import/modules/locales.d.ts +15 -4
  27. package/lib/import/modules/locales.js +194 -94
  28. package/lib/import/modules/marketplace-apps.d.ts +6 -3
  29. package/lib/import/modules/marketplace-apps.js +177 -102
  30. package/lib/import/modules/personalize.d.ts +11 -4
  31. package/lib/import/modules/personalize.js +138 -47
  32. package/lib/import/modules/stack.d.ts +6 -0
  33. package/lib/import/modules/stack.js +71 -27
  34. package/lib/import/modules/taxonomies.d.ts +4 -2
  35. package/lib/import/modules/taxonomies.js +60 -46
  36. package/lib/import/modules/variant-entries.d.ts +7 -4
  37. package/lib/import/modules/variant-entries.js +76 -35
  38. package/lib/import/modules/webhooks.d.ts +3 -0
  39. package/lib/import/modules/webhooks.js +71 -40
  40. package/lib/import/modules/workflows.d.ts +3 -0
  41. package/lib/import/modules/workflows.js +98 -48
  42. package/lib/types/default-config.d.ts +0 -1
  43. package/lib/types/import-config.d.ts +0 -1
  44. package/lib/types/index.d.ts +1 -12
  45. package/lib/utils/backup-handler.js +0 -1
  46. package/lib/utils/constants.d.ts +243 -0
  47. package/lib/utils/constants.js +264 -0
  48. package/lib/utils/import-config-handler.js +2 -0
  49. package/lib/utils/import-path-resolver.js +3 -13
  50. package/lib/utils/index.d.ts +1 -1
  51. package/lib/utils/index.js +6 -2
  52. package/lib/utils/marketplace-app-helper.js +3 -8
  53. package/lib/utils/progress-strategy-registry.d.ts +7 -0
  54. package/lib/utils/progress-strategy-registry.js +78 -0
  55. package/lib/utils/setup-branch.js +1 -1
  56. package/oclif.manifest.json +2 -2
  57. package/package.json +3 -3
  58. package/lib/import/modules-js/assets.d.ts +0 -33
  59. package/lib/import/modules-js/assets.js +0 -428
  60. package/lib/import/modules-js/content-types.d.ts +0 -34
  61. package/lib/import/modules-js/content-types.js +0 -204
  62. package/lib/import/modules-js/custom-roles.d.ts +0 -15
  63. package/lib/import/modules-js/custom-roles.js +0 -143
  64. package/lib/import/modules-js/entries.d.ts +0 -54
  65. package/lib/import/modules-js/entries.js +0 -1280
  66. package/lib/import/modules-js/environments.d.ts +0 -13
  67. package/lib/import/modules-js/environments.js +0 -85
  68. package/lib/import/modules-js/extensions.d.ts +0 -18
  69. package/lib/import/modules-js/extensions.js +0 -86
  70. package/lib/import/modules-js/global-fields.d.ts +0 -13
  71. package/lib/import/modules-js/global-fields.js +0 -106
  72. package/lib/import/modules-js/index.d.ts +0 -1
  73. package/lib/import/modules-js/index.js +0 -33
  74. package/lib/import/modules-js/labels.d.ts +0 -20
  75. package/lib/import/modules-js/labels.js +0 -148
  76. package/lib/import/modules-js/locales.d.ts +0 -24
  77. package/lib/import/modules-js/locales.js +0 -196
  78. package/lib/import/modules-js/marketplace-apps.d.ts +0 -63
  79. package/lib/import/modules-js/marketplace-apps.js +0 -429
  80. package/lib/import/modules-js/webhooks.d.ts +0 -17
  81. package/lib/import/modules-js/webhooks.js +0 -85
  82. package/lib/import/modules-js/workflows.d.ts +0 -19
  83. package/lib/import/modules-js/workflows.js +0 -170
  84. package/lib/utils/log.d.ts +0 -12
  85. package/lib/utils/log.js +0 -31
@@ -1,13 +0,0 @@
1
- export = ImportEnvironments;
2
- declare class ImportEnvironments {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- fails: any[];
5
- success: any[];
6
- envUidMapper: {};
7
- fetchConcurrency: any;
8
- config: any;
9
- stackAPIClient: any;
10
- start(): Promise<any>;
11
- environments: any;
12
- }
13
- import Promise = require("bluebird");
@@ -1,85 +0,0 @@
1
- /*!
2
- * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- const fs = require('fs');
7
- const path = require('path');
8
- const chalk = require('chalk');
9
- const mkdirp = require('mkdirp');
10
- const Promise = require('bluebird');
11
- const { isEmpty, merge } = require('lodash');
12
- const { readFileSync, writeFileSync } = require('../../utils/file-helper');
13
- const { log } = require('../../utils/logger');
14
- const { formatError } = require('../../utils');
15
- const config = require('../../config').default;
16
- module.exports = class ImportEnvironments {
17
- constructor(importConfig, stackAPIClient) {
18
- this.fails = [];
19
- this.success = [];
20
- this.envUidMapper = {};
21
- this.fetchConcurrency = config.modules.environments.concurrency || config.fetchConcurrency || 2;
22
- this.config = importConfig;
23
- this.stackAPIClient = stackAPIClient;
24
- }
25
- start() {
26
- log(this.config, 'Migrating environment', 'success');
27
- const self = this;
28
- let environmentConfig = config.modules.environments;
29
- let environmentsFolderPath = path.resolve(this.config.data, environmentConfig.dirName);
30
- let envMapperPath = path.resolve(this.config.data, 'mapper', 'environments');
31
- let envUidMapperPath = path.resolve(this.config.data, 'mapper', 'environments', 'uid-mapping.json');
32
- let envSuccessPath = path.resolve(this.config.data, 'environments', 'success.json');
33
- let envFailsPath = path.resolve(this.config.data, 'environments', 'fails.json');
34
- self.environments = readFileSync(path.resolve(environmentsFolderPath, environmentConfig.fileName));
35
- if (fs.existsSync(envUidMapperPath)) {
36
- self.envUidMapper = readFileSync(envUidMapperPath);
37
- self.envUidMapper = self.envUidMapper || {};
38
- }
39
- mkdirp.sync(envMapperPath);
40
- return new Promise(function (resolve, reject) {
41
- if (self.environments === undefined || isEmpty(self.environments)) {
42
- log(self.config, chalk.yellow('No Environment Found'), 'success');
43
- return resolve({ empty: true });
44
- }
45
- let envUids = Object.keys(self.environments);
46
- return Promise.map(envUids, function (envUid) {
47
- let env = self.environments[envUid];
48
- if (!self.envUidMapper.hasOwnProperty(envUid)) {
49
- let requestOption = { environment: env };
50
- return self.stackAPIClient
51
- .environment()
52
- .create(requestOption)
53
- .then((environment) => {
54
- self.success.push(environment.items);
55
- self.envUidMapper[envUid] = environment.uid;
56
- writeFileSync(envUidMapperPath, self.envUidMapper);
57
- })
58
- .catch(function (err) {
59
- let error = JSON.parse(err.message);
60
- if (error.errors.name) {
61
- log(self.config, `Environment '${env.name}' already exists`, 'error');
62
- }
63
- else {
64
- log(config, `Environment '${env.name}' failed to be import\n ${JSON.stringify(error.errors)}`, 'error');
65
- }
66
- });
67
- }
68
- else {
69
- // the environment has already been created
70
- log(config, `The environment '${env.name}' already exists. Skipping it to avoid duplicates!`, 'success');
71
- }
72
- }, { concurrency: self.fetchConcurrency })
73
- .then(function () {
74
- writeFileSync(envSuccessPath, self.success);
75
- log(self.config, chalk.green('Environments have been imported successfully!'), 'success');
76
- resolve('');
77
- })
78
- .catch(function (error) {
79
- writeFileSync(envFailsPath, self.fails);
80
- log(self.config, `Failed to import environment ${formatError(error)}`, 'error');
81
- reject(error);
82
- });
83
- });
84
- }
85
- };
@@ -1,18 +0,0 @@
1
- export = ImportExtensions;
2
- declare class ImportExtensions {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- fails: any[];
5
- success: any[];
6
- extUidMapper: {};
7
- extensionsConfig: {
8
- dirName: string;
9
- fileName: string;
10
- validKeys: string[];
11
- };
12
- reqConcurrency: number;
13
- config: any;
14
- stackAPIClient: any;
15
- start(): Promise<any>;
16
- extensions: any;
17
- }
18
- import Promise = require("bluebird");
@@ -1,86 +0,0 @@
1
- /*!
2
- * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- const mkdirp = require('mkdirp');
7
- const fs = require('fs');
8
- const path = require('path');
9
- const Promise = require('bluebird');
10
- const chalk = require('chalk');
11
- const { isEmpty, merge } = require('lodash');
12
- const { default: config } = require('../../config');
13
- const { fileHelper, log, formatError } = require('../../utils');
14
- module.exports = class ImportExtensions {
15
- constructor(importConfig, stackAPIClient) {
16
- this.fails = [];
17
- this.success = [];
18
- this.extUidMapper = {};
19
- this.extensionsConfig = config.modules.extensions;
20
- this.reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
21
- this.config = merge(config, importConfig);
22
- this.stackAPIClient = stackAPIClient;
23
- }
24
- start() {
25
- log(this.config, chalk.white('Migrating extensions'), 'success');
26
- const self = this;
27
- let extensionsFolderPath = path.resolve(this.config.data, this.extensionsConfig.dirName);
28
- let extMapperPath = path.resolve(this.config.data, 'mapper', 'extensions');
29
- let extUidMapperPath = path.resolve(this.config.data, 'mapper/extensions', 'uid-mapping.json');
30
- let extSuccessPath = path.resolve(this.config.data, 'extensions', 'success.json');
31
- let extFailsPath = path.resolve(this.config.data, 'extensions', 'fails.json');
32
- this.extensions = fileHelper.readFileSync(path.resolve(extensionsFolderPath, this.extensionsConfig.fileName));
33
- if (fs.existsSync(extUidMapperPath)) {
34
- self.extUidMapper = fileHelper.readFileSync(extUidMapperPath);
35
- self.extUidMapper = self.extUidMapper || {};
36
- }
37
- mkdirp.sync(extMapperPath);
38
- return new Promise(function (resolve, reject) {
39
- if (self.extensions === undefined || isEmpty(self.extensions)) {
40
- log(self.config, chalk.white('No Extensions Found'), 'success');
41
- return resolve({ empty: true });
42
- }
43
- let extUids = Object.keys(self.extensions);
44
- return Promise.map(extUids, function (extUid) {
45
- let ext = self.extensions[extUid];
46
- if (!self.extUidMapper.hasOwnProperty(extUid)) {
47
- return self.stackAPIClient
48
- .extension()
49
- .create({ extension: ext })
50
- .then((response) => {
51
- self.success.push(response);
52
- self.extUidMapper[extUid] = response.uid;
53
- fileHelper.writeFileSync(extUidMapperPath, self.extUidMapper);
54
- })
55
- .catch(function (err) {
56
- let error = JSON.parse(err.message);
57
- self.fails.push(ext);
58
- if (error.errors.title) {
59
- log(self.config, `Extension '${ext.title}' already exists`, 'error');
60
- }
61
- else {
62
- log(self.config, "Extension: '" + ext.title + "' failed to import" + formatError(error), 'error');
63
- }
64
- });
65
- }
66
- // the extensions has already been created
67
- log(config, chalk.white("The extension: '" + ext.title + "' already exists. Skipping it to avoid duplicates!"), 'success');
68
- // import 2 extensions at a time
69
- }, {
70
- concurrency: self.reqConcurrency,
71
- })
72
- .then(function () {
73
- // extensions have imported successfully
74
- fileHelper.writeFileSync(extSuccessPath, self.success);
75
- log(self.config, chalk.green('Extensions have been imported successfully!'), 'success');
76
- resolve();
77
- })
78
- .catch(function (error) {
79
- // error while importing extensions
80
- fileHelper.writeFileSync(extFailsPath, self.fails);
81
- log(self.config, `Extension import failed ${formatError(error)}`, 'error');
82
- reject(error);
83
- });
84
- });
85
- }
86
- };
@@ -1,13 +0,0 @@
1
- export = ImportGlobalFields;
2
- declare class ImportGlobalFields {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- fails: any[];
5
- success: any[];
6
- snipUidMapper: {};
7
- installedExtensions: any[];
8
- reqConcurrency: number;
9
- config: any;
10
- stackAPIClient: any;
11
- start(): globalThis.Promise<any>;
12
- globalfields: any;
13
- }
@@ -1,106 +0,0 @@
1
- /*!
2
- * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- let fs = require('fs');
7
- let path = require('path');
8
- let chalk = require('chalk');
9
- let mkdirp = require('mkdirp');
10
- let Promise = require('bluebird');
11
- const { isEmpty, merge } = require('lodash');
12
- let { default: config } = require('../../config');
13
- const { fileHelper, log, formatError, lookupExtension, removeReferenceFields } = require('../../utils');
14
- global._globalField_pending = [];
15
- module.exports = class ImportGlobalFields {
16
- constructor(importConfig, stackAPIClient) {
17
- this.fails = [];
18
- this.success = [];
19
- this.snipUidMapper = {};
20
- this.installedExtensions = [];
21
- this.reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
22
- this.config = merge(config, importConfig);
23
- this.stackAPIClient = stackAPIClient;
24
- }
25
- async start() {
26
- log(this.config, chalk.white('Migrating global-fields'), 'success');
27
- let self = this;
28
- let globalfieldsConfig = config.modules.globalfields;
29
- let globalfieldsFolderPath = path.resolve(this.config.data, globalfieldsConfig.dirName);
30
- let globalfieldsMapperPath = path.resolve(this.config.data, 'mapper', 'global_fields');
31
- let globalfieldsUidMapperPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'uid-mapping.json');
32
- let globalfieldsSuccessPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'success.json');
33
- let globalFieldsPending = path.resolve(this.config.data, 'mapper', 'global_fields', 'pending_global_fields.js');
34
- let globalfieldsFailsPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'fails.json');
35
- self.globalfields = fileHelper.readFileSync(path.resolve(globalfieldsFolderPath, globalfieldsConfig.fileName));
36
- const appMapperPath = path.join(this.config.data, 'mapper', 'marketplace_apps', 'uid-mapping.json');
37
- this.installedExtensions = ((await fileHelper.readFileSync(appMapperPath)) || { extension_uid: {} }).extension_uid;
38
- if (fs.existsSync(globalfieldsUidMapperPath)) {
39
- self.snipUidMapper = fileHelper.readFileSync(globalfieldsUidMapperPath);
40
- self.snipUidMapper = self.snipUidMapper || {};
41
- }
42
- if (!fs.existsSync(globalfieldsMapperPath)) {
43
- mkdirp.sync(globalfieldsMapperPath);
44
- }
45
- return new Promise(function (resolve, reject) {
46
- if (self.globalfields === undefined || isEmpty(self.globalfields)) {
47
- log(self.config, chalk.white('No globalfields Found'), 'success');
48
- fileHelper.writeFileSync(globalFieldsPending, _globalField_pending);
49
- return resolve({ empty: true });
50
- }
51
- let snipUids = Object.keys(self.globalfields);
52
- return Promise.map(snipUids, async function (snipUid) {
53
- let flag = { supressed: false };
54
- let snip = self.globalfields[snipUid];
55
- lookupExtension(self.config, snip.schema, self.config.preserveStackVersion, self.installedExtensions);
56
- await removeReferenceFields(snip.schema, flag, self.stackAPIClient);
57
- if (flag.supressed) {
58
- // eslint-disable-next-line no-undef
59
- _globalField_pending.push(snip.uid);
60
- }
61
- if (!self.snipUidMapper.hasOwnProperty(snipUid)) {
62
- let requestOption = { global_field: snip };
63
- return self.stackAPIClient
64
- .globalField()
65
- .create(requestOption)
66
- .then((globalField) => {
67
- self.success.push(globalField.items);
68
- let global_field_uid = globalField.uid;
69
- self.snipUidMapper[snipUid] = globalField.items;
70
- fileHelper.writeFileSync(globalfieldsUidMapperPath, self.snipUidMapper);
71
- log(self.config, chalk.green('Global field ' + global_field_uid + ' created successfully'), 'success');
72
- })
73
- .catch(function (err) {
74
- let error = JSON.parse(err.message);
75
- if (error.errors.title) {
76
- // eslint-disable-next-line no-undef
77
- log(self.config, `Globalfield '${snip.uid} already exists'`, 'error');
78
- }
79
- else {
80
- log(self.config, chalk.red(`Globalfield '${snip.title}' failed to import. ${formatError(error)}`), 'error');
81
- }
82
- self.fails.push(snip);
83
- });
84
- }
85
- else {
86
- // globalfields has already been created
87
- log(self.config, chalk.white('The globalfields already exists. Skipping it to avoid duplicates!'), 'success');
88
- }
89
- // import 2 globalfields at a time
90
- }, { concurrency: self.reqConcurrency })
91
- .then(function () {
92
- // globalfields have imported successfully
93
- fileHelper.writeFileSync(globalfieldsSuccessPath, self.success);
94
- fileHelper.writeFileSync(globalFieldsPending, _globalField_pending);
95
- log(self.config, chalk.green('globalfields have been imported successfully!'), 'success');
96
- return resolve();
97
- })
98
- .catch(function (err) {
99
- let error = JSON.parse(err);
100
- fileHelper.writeFileSync(globalfieldsFailsPath, self.fails);
101
- log(self.config, `Globalfields import failed. ${formatError(err)}`, 'error');
102
- return reject(error);
103
- });
104
- });
105
- }
106
- };
@@ -1 +0,0 @@
1
- export default function startModuleImport(modulePayload: any): Promise<any>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var _a;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- async function startModuleImport(modulePayload) {
28
- const { moduleName, importConfig, stackAPIClient } = modulePayload;
29
- const { default: ModuleRunner } = await (_a = `./${moduleName}`, Promise.resolve().then(() => __importStar(require(_a))));
30
- const moduleRunner = new ModuleRunner(importConfig, stackAPIClient);
31
- return moduleRunner.start();
32
- }
33
- exports.default = startModuleImport;
@@ -1,20 +0,0 @@
1
- export = ImportLabels;
2
- declare class ImportLabels {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- config: any;
5
- fails: any[];
6
- success: any[];
7
- labelUids: any[];
8
- labelsFolderPath: any;
9
- labelUidMapper: {};
10
- labelConfig: {
11
- dirName: string;
12
- fileName: string;
13
- };
14
- reqConcurrency: number;
15
- stackAPIClient: any;
16
- start(): Promise<any>;
17
- labels: any;
18
- updateLabels(): Promise<any>;
19
- }
20
- import Promise = require("bluebird");
@@ -1,148 +0,0 @@
1
- /*!
2
- * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- const path = require('path');
7
- const chalk = require('chalk');
8
- const mkdirp = require('mkdirp');
9
- const Promise = require('bluebird');
10
- const { existsSync } = require('fs');
11
- const { isEmpty, merge } = require('lodash');
12
- let { default: config } = require('../../config');
13
- const { fileHelper, log, formatError } = require('../../utils');
14
- module.exports = class ImportLabels {
15
- constructor(importConfig, stackAPIClient) {
16
- this.fails = [];
17
- this.success = [];
18
- this.labelUids = [];
19
- this.labelUidMapper = {};
20
- this.labelConfig = config.modules.labels;
21
- this.reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
22
- this.config = merge(config, importConfig);
23
- this.stackAPIClient = stackAPIClient;
24
- }
25
- start() {
26
- const self = this;
27
- log(this.config, chalk.white('Migrating labels'), 'success');
28
- let labelMapperPath = path.resolve(this.config.data, 'mapper', 'labels');
29
- let labelFailsPath = path.resolve(this.config.data, 'labels', 'fails.json');
30
- let labelSuccessPath = path.resolve(this.config.data, 'labels', 'success.json');
31
- this.labelsFolderPath = path.resolve(this.config.data, this.labelConfig.dirName);
32
- let labelUidMapperPath = path.resolve(this.config.data, 'mapper', 'labels', 'uid-mapping.json');
33
- if (existsSync(labelUidMapperPath)) {
34
- this.labelUidMapper = fileHelper.readFileSync(labelUidMapperPath);
35
- this.labelUidMapper = this.labelUidMapper || {};
36
- }
37
- self.labels = fileHelper.readFileSync(path.resolve(this.labelsFolderPath, this.labelConfig.fileName));
38
- mkdirp.sync(labelMapperPath);
39
- return new Promise(function (resolve, reject) {
40
- if (self.labels == undefined || isEmpty(self.labels)) {
41
- log(self.config, chalk.white('No Label Found'), 'success');
42
- return resolve({ empty: true });
43
- }
44
- self.labelUids = Object.keys(self.labels);
45
- return Promise.map(self.labelUids, function (labelUid) {
46
- let label = self.labels[labelUid];
47
- if (label.parent.length != 0) {
48
- delete label['parent'];
49
- }
50
- if (!self.labelUidMapper.hasOwnProperty(labelUid)) {
51
- let requestOption = { label: label };
52
- return self.stackAPIClient
53
- .label()
54
- .create(requestOption)
55
- .then(function (response) {
56
- self.labelUidMapper[labelUid] = response;
57
- })
58
- .catch(function (error) {
59
- self.fails.push(label);
60
- if (error.errors.name) {
61
- log(self.config, `Label '${label.name}' already exist`, 'error');
62
- }
63
- else {
64
- log(self.config, `Label '${label.name}' failed to be imported\n`, 'error');
65
- }
66
- });
67
- }
68
- else {
69
- // the label has already been created
70
- log(self.config, chalk.white(`The label '${label.name}' already exists. Skipping it to avoid duplicates!'`), 'success');
71
- }
72
- // import 1 labels at a time
73
- }, { concurrency: self.reqConcurrency })
74
- .then(function () {
75
- fileHelper.writeFileSync(labelUidMapperPath, self.labelUidMapper);
76
- // eslint-disable-next-line no-undef
77
- return self
78
- .updateLabels()
79
- .then(function () {
80
- fileHelper.writeFileSync(labelSuccessPath, self.success);
81
- log(self.config, chalk.green('Labels have been imported successfully!'), 'success');
82
- return resolve();
83
- })
84
- .catch(function (error) {
85
- log(self.config, self.config, `Failed to import label, ${formatError(error)}`, 'error');
86
- // eslint-disable-next-line no-console
87
- return reject(error);
88
- });
89
- })
90
- .catch(function (error) {
91
- // error while importing labels
92
- fileHelper.writeFileSync(labelUidMapperPath, self.labelUidMapper);
93
- fileHelper.writeFileSync(labelFailsPath, self.fails);
94
- log(self.config, `Failed to import label, ${formatError(error)}`, 'error');
95
- return reject(error);
96
- });
97
- });
98
- }
99
- updateLabels() {
100
- const self = this;
101
- return new Promise(function (resolve, reject) {
102
- let labelsObj = fileHelper.readFileSync(path.resolve(self.labelsFolderPath, self.labelConfig.fileName));
103
- return Promise.map(self.labelUids, function (labelUid) {
104
- let label = labelsObj[labelUid];
105
- if (self.labelUidMapper.hasOwnProperty(labelUid)) {
106
- let newLabelUid = self.labelUidMapper[labelUid];
107
- if (label.parent.length > 0) {
108
- let parentUids = label.parent;
109
- for (let i = 0; i < parentUids.length; i++) {
110
- if (self.labelUidMapper.hasOwnProperty(parentUids[i])) {
111
- label.parent[i] = self.labelUidMapper[parentUids[i]].uid;
112
- }
113
- }
114
- return self.stackAPIClient
115
- .label(newLabelUid.uid)
116
- .fetch()
117
- .then(function (response) {
118
- //Object.assign(response, _.cloneDeep(label))
119
- response.parent = label.parent;
120
- response
121
- .update()
122
- .then((result) => {
123
- self.success.push(result);
124
- })
125
- .catch((error) => {
126
- log(self.config, formatError(error), 'error');
127
- return reject(error);
128
- });
129
- })
130
- .catch(function (error) {
131
- log(self.config, formatError(error), 'error');
132
- return reject(error);
133
- });
134
- }
135
- }
136
- }, {
137
- concurrency: self.reqConcurrency,
138
- })
139
- .then(function () {
140
- return resolve();
141
- })
142
- .catch(function (error) {
143
- // eslint-disable-next-line no-console
144
- return reject(error);
145
- });
146
- });
147
- }
148
- };
@@ -1,24 +0,0 @@
1
- export = ImportLanguages;
2
- declare class ImportLanguages {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- config: any;
5
- stackAPIClient: any;
6
- fails: any[];
7
- success: any[];
8
- langUidMapper: {};
9
- masterLanguage: any;
10
- langConfig: any;
11
- sourceMasterLangConfig: {
12
- dirName: string;
13
- fileName: string;
14
- requiredKeys: string[];
15
- };
16
- reqConcurrency: any;
17
- start(): Promise<any>;
18
- langSuccessPath: string;
19
- languages: any;
20
- sourceMasterLanguages: any;
21
- updateLocales(langUids: any): Promise<any>;
22
- checkAndUpdateMasterLocaleName(sourceMasterLangDetails: any): Promise<any>;
23
- }
24
- import Promise = require("bluebird");