@contentstack/cli-cm-import 0.1.1-beta.7 → 1.0.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.
@@ -4,102 +4,117 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- const mkdirp = require('mkdirp')
8
- const fs = require('fs')
9
- const path = require('path')
10
- const Promise = require('bluebird')
7
+ const mkdirp = require('mkdirp');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const Promise = require('bluebird');
11
+ const { isEmpty } = require('lodash');
11
12
 
12
- const request = require('../util/request')
13
- const helper = require('../util/fs')
14
- let {addlogs} = require('../util/log')
15
- let util = require('../util/')
16
- const chalk = require('chalk')
17
- let stack = require('../util/contentstack-management-sdk')
13
+ const helper = require('../util/fs');
14
+ let { addlogs } = require('../util/log');
15
+ const chalk = require('chalk');
16
+ let stack = require('../util/contentstack-management-sdk');
18
17
 
19
- let config = require('../../config/default')
20
- let environmentConfig = config.modules.environments
21
- let environmentsFolderPath
22
- let envMapperPath
23
- let envUidMapperPath
24
- let envSuccessPath
25
- let envFailsPath
26
- let client
18
+ let config = require('../../config/default');
19
+ let environmentConfig = config.modules.environments;
20
+ let environmentsFolderPath;
21
+ let envMapperPath;
22
+ let envUidMapperPath;
23
+ let envSuccessPath;
24
+ let envFailsPath;
25
+ let client;
27
26
 
28
- function importEnvironments () {
29
- this.fails = []
30
- this.success = []
31
- this.envUidMapper = {}
27
+ function importEnvironments() {
28
+ this.fails = [];
29
+ this.success = [];
30
+ this.envUidMapper = {};
32
31
  }
33
32
 
34
33
  importEnvironments.prototype = {
35
34
  start: function (credentialConfig) {
36
- let self = this
37
- config = credentialConfig
38
- addlogs(config, 'Migrating environment', 'success')
39
- environmentsFolderPath = path.resolve(config.data, environmentConfig.dirName)
40
- envMapperPath = path.resolve(config.data, 'mapper', 'environments')
41
- envUidMapperPath = path.resolve(config.data, 'mapper', 'environments', 'uid-mapping.json')
42
- envSuccessPath = path.resolve(config.data, 'environments', 'success.json')
43
- envFailsPath = path.resolve(config.data, 'environments', 'fails.json')
44
- self.environments = helper.readFile(path.resolve(environmentsFolderPath, environmentConfig.fileName))
45
- client = stack.Client(config)
35
+ let self = this;
36
+ config = credentialConfig;
37
+ addlogs(config, 'Migrating environment', 'success');
38
+ environmentsFolderPath = path.resolve(config.data, environmentConfig.dirName);
39
+ envMapperPath = path.resolve(config.data, 'mapper', 'environments');
40
+ envUidMapperPath = path.resolve(config.data, 'mapper', 'environments', 'uid-mapping.json');
41
+ envSuccessPath = path.resolve(config.data, 'environments', 'success.json');
42
+ envFailsPath = path.resolve(config.data, 'environments', 'fails.json');
43
+ self.environments = helper.readFile(path.resolve(environmentsFolderPath, environmentConfig.fileName));
44
+ client = stack.Client(config);
46
45
  if (fs.existsSync(envUidMapperPath)) {
47
- self.envUidMapper = helper.readFile(envUidMapperPath)
48
- self.envUidMapper = self.envUidMapper || {}
46
+ self.envUidMapper = helper.readFile(envUidMapperPath);
47
+ self.envUidMapper = self.envUidMapper || {};
49
48
  }
50
49
 
51
- mkdirp.sync(envMapperPath)
50
+ mkdirp.sync(envMapperPath);
52
51
  return new Promise(function (resolve, reject) {
53
- if (self.environments === undefined) {
54
- addlogs(config, chalk.yellow('No Environment Found'), 'success')
55
- return resolve()
52
+ if (self.environments === undefined || isEmpty(self.environments)) {
53
+ addlogs(config, chalk.yellow('No Environment Found'), 'success');
54
+ return resolve({ empty: true });
56
55
  }
57
56
 
58
- let envUids = Object.keys(self.environments)
59
- return Promise.map(envUids, function (envUid) {
60
- let env = self.environments[envUid]
61
- if (!self.envUidMapper.hasOwnProperty(envUid)) {
62
- let requestOption = {
57
+ let envUids = Object.keys(self.environments);
58
+ return Promise.map(
59
+ envUids,
60
+ function (envUid) {
61
+ let env = self.environments[envUid];
62
+ if (!self.envUidMapper.hasOwnProperty(envUid)) {
63
+ let requestOption = {
63
64
  environment: env,
64
- }
65
+ };
65
66
 
66
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).environment().create(requestOption)
67
- .then(environment => {
68
- self.success.push(environment.items)
69
- self.envUidMapper[envUid] = environment.uid
70
- helper.writeFile(envUidMapperPath, self.envUidMapper)
71
- return
72
- }).catch(function (err) {
73
- let error = JSON.parse(err.message)
74
- if (error.errors.name) {
75
- addlogs(config, chalk.white('Environment: \'' + env.name + '\' already exists'), 'error')
76
- } else {
77
- addlogs(config, chalk.white('Environment: \'' + env.name + '\' failed to be import\n ' + JSON.stringify(error.errors)), 'error')
78
- }
79
- return
80
- })
81
- } else {
82
- // the environment has already been created
83
- addlogs(config, chalk.white('The environment: \'' + env.name +
84
- '\' already exists. Skipping it to avoid duplicates!'), 'success')
85
- return
86
- }
87
- // import 2 environments at a time
88
- }, {
89
- concurrency: 2,
90
- }).then(function () {
91
- // environments have imported successfully
92
- helper.writeFile(envSuccessPath, self.success)
93
- addlogs(config, chalk.green('Environments have been imported successfully!'), 'success')
94
- return resolve()
95
- }).catch(function (error) {
96
- // error while importing environments
97
- helper.writeFile(envFailsPath, self.fails)
98
- addlogs(config, chalk.red('Environment import failed'), 'error')
99
- return reject(error)
100
- })
101
- })
67
+ return client
68
+ .stack({ api_key: config.target_stack, management_token: config.management_token })
69
+ .environment()
70
+ .create(requestOption)
71
+ .then((environment) => {
72
+ self.success.push(environment.items);
73
+ self.envUidMapper[envUid] = environment.uid;
74
+ helper.writeFile(envUidMapperPath, self.envUidMapper);
75
+ })
76
+ .catch(function (err) {
77
+ let error = JSON.parse(err.message);
78
+ if (error.errors.name) {
79
+ addlogs(config, chalk.white("Environment: '" + env.name + "' already exists"), 'error');
80
+ } else {
81
+ addlogs(
82
+ config,
83
+ chalk.white(
84
+ "Environment: '" + env.name + "' failed to be import\n " + JSON.stringify(error.errors),
85
+ ),
86
+ 'error',
87
+ );
88
+ }
89
+ });
90
+ } else {
91
+ // the environment has already been created
92
+ addlogs(
93
+ config,
94
+ chalk.white("The environment: '" + env.name + "' already exists. Skipping it to avoid duplicates!"),
95
+ 'success',
96
+ );
97
+ }
98
+ // import 2 environments at a time
99
+ },
100
+ {
101
+ concurrency: 2,
102
+ },
103
+ )
104
+ .then(function () {
105
+ // environments have imported successfully
106
+ helper.writeFile(envSuccessPath, self.success);
107
+ addlogs(config, chalk.green('Environments have been imported successfully!'), 'success');
108
+ return resolve();
109
+ })
110
+ .catch(function (error) {
111
+ // error while importing environments
112
+ helper.writeFile(envFailsPath, self.fails);
113
+ addlogs(config, chalk.red('Environment import failed'), 'error');
114
+ return reject(error);
115
+ });
116
+ });
102
117
  },
103
- }
118
+ };
104
119
 
105
- module.exports = new importEnvironments()
120
+ module.exports = new importEnvironments();
@@ -4,96 +4,114 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- const mkdirp = require('mkdirp')
8
- const fs = require('fs')
9
- const path = require('path')
10
- const Promise = require('bluebird')
11
- const chalk = require('chalk')
7
+ const mkdirp = require('mkdirp');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const Promise = require('bluebird');
11
+ const chalk = require('chalk');
12
+ const {isEmpty} = require('lodash');
12
13
 
13
- const helper = require('../util/fs')
14
- const {addlogs} = require('../util/log')
15
- const util = require('../util')
14
+ const helper = require('../util/fs');
15
+ const { addlogs } = require('../util/log');
16
+ const util = require('../util');
16
17
 
17
- let config = util.getConfig()
18
- const reqConcurrency = config.concurrency
19
- const extensionsConfig = config.modules.extensions
20
- const stack = require('../util/contentstack-management-sdk')
21
- let extensionsFolderPath
22
- let extMapperPath
23
- let extUidMapperPath
24
- let extSuccessPath
25
- let extFailsPath
26
- let client
18
+ let config = util.getConfig();
19
+ const reqConcurrency = config.concurrency;
20
+ const extensionsConfig = config.modules.extensions;
21
+ const stack = require('../util/contentstack-management-sdk');
22
+ let extensionsFolderPath;
23
+ let extMapperPath;
24
+ let extUidMapperPath;
25
+ let extSuccessPath;
26
+ let extFailsPath;
27
+ let client;
27
28
 
28
- function importExtensions () {
29
- this.fails = []
30
- this.success = []
31
- this.extUidMapper = {}
29
+ function importExtensions() {
30
+ this.fails = [];
31
+ this.success = [];
32
+ this.extUidMapper = {};
32
33
  }
33
34
 
34
35
  importExtensions.prototype = {
35
36
  start: function (credential) {
36
- addlogs(config, chalk.white('Migrating extensions'), 'success')
37
- let self = this
38
- config = credential
39
- client = stack.Client(config)
37
+ addlogs(config, chalk.white('Migrating extensions'), 'success');
38
+ let self = this;
39
+ config = credential;
40
+ client = stack.Client(config);
40
41
 
41
- extensionsFolderPath = path.resolve(config.data, extensionsConfig.dirName)
42
- extMapperPath = path.resolve(config.data, 'mapper', 'extensions')
43
- extUidMapperPath = path.resolve(config.data, 'mapper/extensions', 'uid-mapping.json')
44
- extSuccessPath = path.resolve(config.data, 'extensions', 'success.json')
45
- extFailsPath = path.resolve(config.data, 'extensions', 'fails.json')
46
- self.extensions = helper.readFile(path.resolve(extensionsFolderPath, extensionsConfig.fileName))
42
+ extensionsFolderPath = path.resolve(config.data, extensionsConfig.dirName);
43
+ extMapperPath = path.resolve(config.data, 'mapper', 'extensions');
44
+ extUidMapperPath = path.resolve(config.data, 'mapper/extensions', 'uid-mapping.json');
45
+ extSuccessPath = path.resolve(config.data, 'extensions', 'success.json');
46
+ extFailsPath = path.resolve(config.data, 'extensions', 'fails.json');
47
+ self.extensions = helper.readFile(path.resolve(extensionsFolderPath, extensionsConfig.fileName));
47
48
  if (fs.existsSync(extUidMapperPath)) {
48
- self.extUidMapper = helper.readFile(extUidMapperPath)
49
- self.extUidMapper = self.extUidMapper || {}
49
+ self.extUidMapper = helper.readFile(extUidMapperPath);
50
+ self.extUidMapper = self.extUidMapper || {};
50
51
  }
51
52
 
52
- mkdirp.sync(extMapperPath)
53
+ mkdirp.sync(extMapperPath);
53
54
 
54
55
  return new Promise(function (resolve, reject) {
55
- if (self.extensions === undefined) {
56
- addlogs(config, chalk.white('No Extensions Found'), 'success')
57
- return resolve()
56
+ if (self.extensions === undefined || isEmpty(self.extensions)) {
57
+ addlogs(config, chalk.white('No Extensions Found'), 'success');
58
+ return resolve({ empty: true });
58
59
  }
59
- let extUids = Object.keys(self.extensions)
60
- return Promise.map(extUids, function (extUid) {
61
- let ext = self.extensions[extUid]
62
- if (!self.extUidMapper.hasOwnProperty(extUid)) {
63
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).extension().create({extension: ext})
64
- .then(response => {
65
- self.success.push(response)
66
- self.extUidMapper[extUid] = response.uid
67
- helper.writeFile(extUidMapperPath, self.extUidMapper)
68
- }).catch(function (err) {
69
- let error = JSON.parse(err.message)
70
- self.fails.push(ext)
71
- if (error.errors.title) {
72
- addlogs(config, chalk.white('Extension: \'' + ext.title + '\' already exists'), 'success')
73
- } else {
74
- addlogs(config, chalk.white('Extension: \'' + ext.title + '\' failed to be import\n ' + JSON.stringify(error.errors)), 'error')
75
- }
76
- })
77
- }
78
- // the extensions has already been created
79
- addlogs(config, chalk.white('The extension: \'' + ext.name +
80
- '\' already exists. Skipping it to avoid duplicates!'), 'success')
81
- // import 2 extensions at a time
82
- }, {
83
- concurrency: reqConcurrency,
84
- }).then(function () {
85
- // extensions have imported successfully
86
- helper.writeFile(extSuccessPath, self.success)
87
- addlogs(config, chalk.green('Extensions have been imported successfully!'), 'success')
88
- return resolve()
89
- }).catch(function (error) {
90
- // error while importing extensions
91
- helper.writeFile(extFailsPath, self.fails)
92
- addlogs(config, chalk.red('Extension import failed'), 'error')
93
- return reject(error)
94
- })
95
- })
60
+ let extUids = Object.keys(self.extensions);
61
+ return Promise.map(
62
+ extUids,
63
+ function (extUid) {
64
+ let ext = self.extensions[extUid];
65
+ if (!self.extUidMapper.hasOwnProperty(extUid)) {
66
+ return client
67
+ .stack({ api_key: config.target_stack, management_token: config.management_token })
68
+ .extension()
69
+ .create({ extension: ext })
70
+ .then((response) => {
71
+ self.success.push(response);
72
+ self.extUidMapper[extUid] = response.uid;
73
+ helper.writeFile(extUidMapperPath, self.extUidMapper);
74
+ })
75
+ .catch(function (err) {
76
+ let error = JSON.parse(err.message);
77
+ self.fails.push(ext);
78
+ if (error.errors.title) {
79
+ addlogs(config, chalk.white("Extension: '" + ext.title + "' already exists"), 'success');
80
+ } else {
81
+ addlogs(
82
+ config,
83
+ chalk.white("Extension: '" + ext.title + "' failed to be import\n " + JSON.stringify(error.errors)),
84
+ 'error',
85
+ );
86
+ }
87
+ });
88
+ }
89
+ // the extensions has already been created
90
+ addlogs(
91
+ config,
92
+ chalk.white("The extension: '" + ext.title + "' already exists. Skipping it to avoid duplicates!"),
93
+ 'success',
94
+ );
95
+ // import 2 extensions at a time
96
+ },
97
+ {
98
+ concurrency: reqConcurrency,
99
+ },
100
+ )
101
+ .then(function () {
102
+ // extensions have imported successfully
103
+ helper.writeFile(extSuccessPath, self.success);
104
+ addlogs(config, chalk.green('Extensions have been imported successfully!'), 'success');
105
+ return resolve();
106
+ })
107
+ .catch(function (error) {
108
+ // error while importing extensions
109
+ helper.writeFile(extFailsPath, self.fails);
110
+ addlogs(config, chalk.red('Extension import failed'), 'error');
111
+ return reject(error);
112
+ });
113
+ });
96
114
  },
97
- }
115
+ };
98
116
 
99
- module.exports = new importExtensions()
117
+ module.exports = new importExtensions();
@@ -4,130 +4,141 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- let mkdirp = require('mkdirp')
8
- let fs = require('fs')
9
- let path = require('path')
10
- let Promise = require('bluebird')
11
- let chalk = require('chalk')
7
+ let mkdirp = require('mkdirp');
8
+ let fs = require('fs');
9
+ let path = require('path');
10
+ let Promise = require('bluebird');
11
+ let chalk = require('chalk');
12
+ const {isEmpty} = require('lodash');
12
13
 
13
- let helper = require('../util/fs')
14
- let {addlogs} = require('../util/log')
15
- let util = require('../util')
16
- let extension_supress = require('../util/extensionsUidReplace')
17
- let removeReferenceFields = require('../util/removeReferenceFields')
18
- const stack = require('../util/contentstack-management-sdk')
14
+ let helper = require('../util/fs');
15
+ let { addlogs } = require('../util/log');
16
+ let extension_supress = require('../util/extensionsUidReplace');
17
+ let removeReferenceFields = require('../util/removeReferenceFields');
18
+ const stack = require('../util/contentstack-management-sdk');
19
19
 
20
- let config = require('../../config/default')
21
- let reqConcurrency = config.concurrency
22
- let globalfieldsConfig = config.modules.globalfields
23
- let globalfieldsFolderPath
24
- let globalfieldsMapperPath
25
- let globalfieldsUidMapperPath
26
- let globalfieldsSuccessPath
27
- let globalfieldsFailsPath
28
- let client
20
+ let config = require('../../config/default');
21
+ let reqConcurrency = config.concurrency;
22
+ let globalfieldsConfig = config.modules.globalfields;
23
+ let globalfieldsFolderPath;
24
+ let globalfieldsMapperPath;
25
+ let globalfieldsUidMapperPath;
26
+ let globalfieldsSuccessPath;
27
+ let globalfieldsFailsPath;
28
+ let client;
29
+ let globalFieldsPending;
29
30
 
31
+ global._globalField_pending = [];
30
32
 
31
- global._globalField_pending = []
32
-
33
- function importGlobalFields () {
34
- this.fails = []
35
- this.success = []
36
- this.snipUidMapper = {}
33
+ function importGlobalFields() {
34
+ this.fails = [];
35
+ this.success = [];
36
+ this.snipUidMapper = {};
37
37
  this.requestOptions = {
38
38
  uri: config.host + config.apis.globalfields,
39
39
  headers: config.headers,
40
40
  method: 'POST',
41
- }
41
+ };
42
42
  }
43
43
 
44
44
  importGlobalFields.prototype = {
45
45
  start: function (credential) {
46
- addlogs(config, chalk.white('Migrating global-fields'), 'success')
47
- let self = this
48
- config = credential
49
- globalfieldsFolderPath = path.resolve(config.data, globalfieldsConfig.dirName)
50
- globalfieldsMapperPath = path.resolve(config.data, 'mapper', 'global_fields')
51
- globalfieldsUidMapperPath = path.resolve(config.data, 'mapper', 'global_fields', 'uid-mapping.json')
52
- globalfieldsSuccessPath = path.resolve(config.data, 'mapper', 'global_fields', 'success.json')
53
- globalFieldsPending = path.resolve(config.data, 'mapper', 'global_fields', 'pending_global_fields.js')
54
- globalfieldsFailsPath = path.resolve(config.data, 'mapper', 'global_fields', 'fails.json')
55
- self.globalfields = helper.readFile(path.resolve(globalfieldsFolderPath, globalfieldsConfig.fileName))
46
+ addlogs(config, chalk.white('Migrating global-fields'), 'success');
47
+ let self = this;
48
+ config = credential;
49
+ globalfieldsFolderPath = path.resolve(config.data, globalfieldsConfig.dirName);
50
+ globalfieldsMapperPath = path.resolve(config.data, 'mapper', 'global_fields');
51
+ globalfieldsUidMapperPath = path.resolve(config.data, 'mapper', 'global_fields', 'uid-mapping.json');
52
+ globalfieldsSuccessPath = path.resolve(config.data, 'mapper', 'global_fields', 'success.json');
53
+ globalFieldsPending = path.resolve(config.data, 'mapper', 'global_fields', 'pending_global_fields.js');
54
+ globalfieldsFailsPath = path.resolve(config.data, 'mapper', 'global_fields', 'fails.json');
55
+ self.globalfields = helper.readFile(path.resolve(globalfieldsFolderPath, globalfieldsConfig.fileName));
56
56
  if (fs.existsSync(globalfieldsUidMapperPath)) {
57
- self.snipUidMapper = helper.readFile(globalfieldsUidMapperPath)
58
- self.snipUidMapper = this.snipUidMapper || {}
57
+ self.snipUidMapper = helper.readFile(globalfieldsUidMapperPath);
58
+ self.snipUidMapper = this.snipUidMapper || {};
59
59
  }
60
60
 
61
61
  if (!fs.existsSync(globalfieldsMapperPath)) {
62
- mkdirp.sync(globalfieldsMapperPath)
62
+ mkdirp.sync(globalfieldsMapperPath);
63
63
  }
64
- client = stack.Client(config)
64
+ client = stack.Client(config);
65
65
  return new Promise(function (resolve, reject) {
66
- if (self.globalfields === undefined) {
67
- addlogs(config, chalk.white('No globalfields Found'), 'success')
68
- helper.writeFile(globalFieldsPending, _globalField_pending)
69
- return resolve()
66
+ if (self.globalfields === undefined || isEmpty(self.globalfields)) {
67
+ addlogs(config, chalk.white('No globalfields Found'), 'success');
68
+ helper.writeFile(globalFieldsPending, _globalField_pending);
69
+ return resolve({ empty: true });
70
70
  }
71
- let snipUids = Object.keys(self.globalfields)
72
- return Promise.map(snipUids, function (snipUid) {
73
- let flag = {
74
- supressed: false,
75
- }
76
- let snip = self.globalfields[snipUid]
77
- extension_supress(snip.schema)
78
- removeReferenceFields(snip.schema, flag)
71
+ let snipUids = Object.keys(self.globalfields);
72
+ return Promise.map(
73
+ snipUids,
74
+ function (snipUid) {
75
+ let flag = {
76
+ supressed: false,
77
+ };
78
+ let snip = self.globalfields[snipUid];
79
+ extension_supress(snip.schema);
80
+ removeReferenceFields(snip.schema, flag);
79
81
 
80
- if (flag.supressed) {
81
- // eslint-disable-next-line no-undef
82
- _globalField_pending.push(snip.uid)
83
- }
82
+ if (flag.supressed) {
83
+ // eslint-disable-next-line no-undef
84
+ _globalField_pending.push(snip.uid);
85
+ }
84
86
 
85
- if (!self.snipUidMapper.hasOwnProperty(snipUid)) {
86
- let requestOption = {
87
- global_field: snip,
87
+ if (!self.snipUidMapper.hasOwnProperty(snipUid)) {
88
+ let requestOption = {
89
+ global_field: snip,
90
+ };
91
+ return client
92
+ .stack({ api_key: config.target_stack, management_token: config.management_token })
93
+ .globalField()
94
+ .create(requestOption)
95
+ .then((globalField) => {
96
+ self.success.push(globalField.items);
97
+ let global_field_uid = globalField.uid;
98
+ self.snipUidMapper[snipUid] = globalField.items;
99
+ helper.writeFile(globalfieldsUidMapperPath, self.snipUidMapper);
100
+ addlogs(config, chalk.green('Global field ' + global_field_uid + ' created successfully'), 'success');
101
+ })
102
+ .catch(function (err) {
103
+ let error = JSON.parse(err.message);
104
+ if (error.errors.title) {
105
+ // eslint-disable-next-line no-undef
106
+ addlogs(config, chalk.white(snip.uid + ' globalfield already exists'), 'error');
107
+ } else {
108
+ addlogs(config, chalk.red('Globalfield failed to import ' + JSON.stringify(error.errors)), 'error');
109
+ }
110
+ self.fails.push(snip);
111
+ });
112
+ } else {
113
+ // globalfields has already been created
114
+ addlogs(
115
+ config,
116
+ chalk.white('The globalfields already exists. Skipping it to avoid duplicates!'),
117
+ 'success',
118
+ );
88
119
  }
89
- return client.stack({api_key: config.target_stack, management_token: config.management_token}).globalField().create(requestOption)
90
- .then(globalField => {
91
- self.success.push(globalField.items)
92
- let global_field_uid = globalField.uid
93
- self.snipUidMapper[snipUid] = globalField.items
94
- helper.writeFile(globalfieldsUidMapperPath, self.snipUidMapper)
95
- addlogs(config, chalk.green('Global field ' + global_field_uid + ' created successfully'), 'success')
96
- return
97
- }).catch(function (err) {
98
- let error = JSON.parse(err.message)
99
- if (error.errors.title) {
100
- // eslint-disable-next-line no-undef
101
- addlogs(config, chalk.white(snip.uid + ' globalfield already exists'), 'error')
102
- } else {
103
- addlogs(config, chalk.red('Globalfield failed to import ' + JSON.stringify(error.errors)), 'error')
104
- }
105
- self.fails.push(snip)
106
- return
107
- })
108
- } else {
109
- // globalfields has already been created
110
- addlogs(config, chalk.white('The globalfields already exists. Skipping it to avoid duplicates!'), 'success')
111
- return
112
- }
113
- // import 2 globalfields at a time
114
- }, {
115
- concurrency: reqConcurrency,
116
- }).then(function () {
117
- // globalfields have imported successfully
118
- helper.writeFile(globalfieldsSuccessPath, self.success)
119
- helper.writeFile(globalFieldsPending, _globalField_pending)
120
- addlogs(config, chalk.green('globalfields have been imported successfully!'), 'success')
121
- return resolve()
122
- }).catch(function (err) {
123
- let error = JSON.parse(err)
124
- // error while importing globalfields
125
- helper.writeFile(globalfieldsFailsPath, self.fails)
126
- addlogs(config, chalk.red('globalfields import failed'), 'error')
127
- return reject(error)
128
- })
129
- })
120
+ // import 2 globalfields at a time
121
+ },
122
+ {
123
+ concurrency: reqConcurrency,
124
+ },
125
+ )
126
+ .then(function () {
127
+ // globalfields have imported successfully
128
+ helper.writeFile(globalfieldsSuccessPath, self.success);
129
+ helper.writeFile(globalFieldsPending, _globalField_pending);
130
+ addlogs(config, chalk.green('globalfields have been imported successfully!'), 'success');
131
+ return resolve();
132
+ })
133
+ .catch(function (err) {
134
+ let error = JSON.parse(err);
135
+ // error while importing globalfields
136
+ helper.writeFile(globalfieldsFailsPath, self.fails);
137
+ addlogs(config, chalk.red('globalfields import failed'), 'error');
138
+ return reject(error);
139
+ });
140
+ });
130
141
  },
131
- }
142
+ };
132
143
 
133
- module.exports = new importGlobalFields()
144
+ module.exports = new importGlobalFields();