@contentstack/cli-cm-import 0.1.1-beta.9 → 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.
- package/LICENSE +21 -0
- package/README.md +54 -23
- package/oclif.manifest.json +1 -1
- package/package.json +69 -65
- package/src/app.js +170 -103
- package/src/commands/cm/stacks/import.js +186 -0
- package/src/config/default.js +17 -57
- package/src/lib/import/assets.js +346 -281
- package/src/lib/import/content-types.js +198 -178
- package/src/lib/import/entries.js +1274 -684
- package/src/lib/import/environments.js +97 -82
- package/src/lib/import/extensions.js +95 -77
- package/src/lib/import/global-fields.js +114 -103
- package/src/lib/import/labels.js +118 -98
- package/src/lib/import/locales.js +124 -111
- package/src/lib/import/webhooks.js +76 -59
- package/src/lib/import/workflows.js +88 -68
- package/src/lib/util/contentstack-management-sdk.js +21 -8
- package/src/lib/util/extensionsUidReplace.js +34 -22
- package/src/lib/util/fs.js +3 -4
- package/src/lib/util/import-flags.js +150 -111
- package/src/lib/util/index.js +134 -130
- package/src/lib/util/log.js +73 -35
- package/src/lib/util/login.js +37 -36
- package/src/lib/util/lookupReplaceAssets.js +167 -61
- package/src/lib/util/lookupReplaceEntries.js +144 -66
- package/src/lib/util/removeReferenceFields.js +29 -26
- package/src/lib/util/schemaTemplate.js +31 -33
- package/src/lib/util/supress-mandatory-fields.js +14 -8
- package/src/lib/util/upload.js +29 -28
- package/src/commands/cm/import.js +0 -159
- package/src/lib/util/request.js +0 -82
|
@@ -9,22 +9,23 @@ const fs = require('fs');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const Promise = require('bluebird');
|
|
11
11
|
const chalk = require('chalk');
|
|
12
|
+
const {isEmpty} = require('lodash');
|
|
12
13
|
|
|
13
14
|
const helper = require('../util/fs');
|
|
14
|
-
const {addlogs} = require('../util/log');
|
|
15
|
-
let config = require('../../config/default')
|
|
16
|
-
let stack = require('../util/contentstack-management-sdk')
|
|
15
|
+
const { addlogs } = require('../util/log');
|
|
16
|
+
let config = require('../../config/default');
|
|
17
|
+
let stack = require('../util/contentstack-management-sdk');
|
|
17
18
|
let reqConcurrency = config.concurrency;
|
|
18
19
|
let webhooksConfig = config.modules.webhooks;
|
|
19
20
|
|
|
20
|
-
let webhooksFolderPath
|
|
21
|
-
let webMapperPath
|
|
22
|
-
let webUidMapperPath
|
|
23
|
-
let webSuccessPath
|
|
24
|
-
let webFailsPath
|
|
25
|
-
let client
|
|
21
|
+
let webhooksFolderPath;
|
|
22
|
+
let webMapperPath;
|
|
23
|
+
let webUidMapperPath;
|
|
24
|
+
let webSuccessPath;
|
|
25
|
+
let webFailsPath;
|
|
26
|
+
let client;
|
|
26
27
|
|
|
27
|
-
function importWebhooks
|
|
28
|
+
function importWebhooks() {
|
|
28
29
|
this.fails = [];
|
|
29
30
|
this.success = [];
|
|
30
31
|
this.webUidMapper = {};
|
|
@@ -33,9 +34,9 @@ function importWebhooks () {
|
|
|
33
34
|
importWebhooks.prototype = {
|
|
34
35
|
start: function (credentialConfig) {
|
|
35
36
|
let self = this;
|
|
36
|
-
config = credentialConfig
|
|
37
|
-
addlogs(config, chalk.white('Migrating webhooks'), 'success')
|
|
38
|
-
client = stack.Client(config)
|
|
37
|
+
config = credentialConfig;
|
|
38
|
+
addlogs(config, chalk.white('Migrating webhooks'), 'success');
|
|
39
|
+
client = stack.Client(config);
|
|
39
40
|
webhooksFolderPath = path.resolve(config.data, webhooksConfig.dirName);
|
|
40
41
|
webMapperPath = path.resolve(config.data, 'mapper', 'webhooks');
|
|
41
42
|
webUidMapperPath = path.resolve(config.data, 'mapper', 'webhooks', 'uid-mapping.json');
|
|
@@ -49,56 +50,72 @@ importWebhooks.prototype = {
|
|
|
49
50
|
mkdirp.sync(webMapperPath);
|
|
50
51
|
|
|
51
52
|
return new Promise(function (resolve, reject) {
|
|
52
|
-
if(self.webhooks == undefined) {
|
|
53
|
+
if (self.webhooks == undefined || isEmpty(self.webhooks)) {
|
|
53
54
|
addlogs(config, chalk.white('No Webhooks Found'), 'success');
|
|
54
|
-
return resolve();
|
|
55
|
+
return resolve({ empty: true });
|
|
55
56
|
}
|
|
56
57
|
let webUids = Object.keys(self.webhooks);
|
|
57
|
-
return Promise.map(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
58
|
+
return Promise.map(
|
|
59
|
+
webUids,
|
|
60
|
+
function (webUid) {
|
|
61
|
+
let web = self.webhooks[webUid];
|
|
62
|
+
if (config.importWebhookStatus !== 'current' || config.importWebhookStatus === 'disable') {
|
|
63
|
+
web.disabled = true;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
65
|
+
|
|
66
|
+
if (!self.webUidMapper.hasOwnProperty(webUid)) {
|
|
67
|
+
let requestOption = {
|
|
68
|
+
json: {
|
|
69
|
+
webhook: web,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return client
|
|
74
|
+
.stack({ api_key: config.target_stack, management_token: config.management_token })
|
|
75
|
+
.webhook()
|
|
76
|
+
.create(requestOption.json)
|
|
77
|
+
.then(function (response) {
|
|
78
|
+
self.success.push(response);
|
|
79
|
+
self.webUidMapper[webUid] = response.uid;
|
|
80
|
+
helper.writeFile(webUidMapperPath, self.webUidMapper);
|
|
81
|
+
})
|
|
82
|
+
.catch(function (err) {
|
|
83
|
+
let error = JSON.parse(err.message);
|
|
84
|
+
self.fails.push(web);
|
|
85
|
+
addlogs(
|
|
86
|
+
config,
|
|
87
|
+
chalk.red("Webhooks: '" + web.name + "' failed to be import\n" + JSON.stringify(error)),
|
|
88
|
+
'error',
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
// the webhooks has already been created
|
|
93
|
+
addlogs(
|
|
94
|
+
config,
|
|
95
|
+
chalk.white("The Webhooks: '" + web.name + "' already exists. Skipping it to avoid duplicates!"),
|
|
96
|
+
'success',
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
// import 2 webhooks at a time
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
concurrency: reqConcurrency,
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
.then(function () {
|
|
106
|
+
// webhooks have imported successfully
|
|
107
|
+
helper.writeFile(webSuccessPath, self.success);
|
|
108
|
+
addlogs(config, chalk.green('Webhooks have been imported successfully!'), 'success');
|
|
109
|
+
return resolve();
|
|
110
|
+
})
|
|
111
|
+
.catch(function (error) {
|
|
112
|
+
// error while importing environments
|
|
113
|
+
helper.writeFile(webFailsPath, self.fails);
|
|
114
|
+
addlogs(config, chalk.red('Webhooks import failed'), 'error');
|
|
115
|
+
return reject(error);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
},
|
|
102
119
|
};
|
|
103
120
|
|
|
104
121
|
module.exports = new importWebhooks();
|
|
@@ -9,22 +9,21 @@ const fs = require('fs');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const Promise = require('bluebird');
|
|
11
11
|
const chalk = require('chalk');
|
|
12
|
-
const
|
|
12
|
+
const {isEmpty} = require('lodash');
|
|
13
13
|
|
|
14
14
|
const helper = require('../util/fs');
|
|
15
15
|
const { addlogs } = require('../util/log');
|
|
16
|
-
let config = require('../../config/default')
|
|
16
|
+
let config = require('../../config/default');
|
|
17
17
|
let stack = require('../util/contentstack-management-sdk');
|
|
18
18
|
|
|
19
19
|
let reqConcurrency = config.concurrency;
|
|
20
20
|
let workflowConfig = config.modules.workflows;
|
|
21
|
-
let workflowFolderPath
|
|
22
|
-
let workflowMapperPath
|
|
23
|
-
let workflowUidMapperPath
|
|
24
|
-
let workflowSuccessPath
|
|
25
|
-
let workflowFailsPath
|
|
26
|
-
let client
|
|
27
|
-
|
|
21
|
+
let workflowFolderPath;
|
|
22
|
+
let workflowMapperPath;
|
|
23
|
+
let workflowUidMapperPath;
|
|
24
|
+
let workflowSuccessPath;
|
|
25
|
+
let workflowFailsPath;
|
|
26
|
+
let client;
|
|
28
27
|
|
|
29
28
|
function importWorkflows() {
|
|
30
29
|
this.fails = [];
|
|
@@ -40,10 +39,10 @@ function importWorkflows() {
|
|
|
40
39
|
importWorkflows.prototype = {
|
|
41
40
|
start: function (credentialConfig) {
|
|
42
41
|
let self = this;
|
|
43
|
-
config = credentialConfig
|
|
44
|
-
client = stack.Client(config)
|
|
45
|
-
addlogs(config, chalk.white('Migrating workflows'), 'success')
|
|
46
|
-
workflowFolderPath = path.resolve(config.data, workflowConfig.dirName)
|
|
42
|
+
config = credentialConfig;
|
|
43
|
+
client = stack.Client(config);
|
|
44
|
+
addlogs(config, chalk.white('Migrating workflows'), 'success');
|
|
45
|
+
workflowFolderPath = path.resolve(config.data, workflowConfig.dirName);
|
|
47
46
|
self.workflows = helper.readFile(path.resolve(workflowFolderPath, workflowConfig.fileName));
|
|
48
47
|
workflowMapperPath = path.resolve(config.data, 'mapper', 'workflows');
|
|
49
48
|
workflowUidMapperPath = path.resolve(config.data, 'mapper', 'workflows', 'uid-mapping.json');
|
|
@@ -51,68 +50,89 @@ importWorkflows.prototype = {
|
|
|
51
50
|
workflowFailsPath = path.resolve(config.data, 'workflows', 'fails.json');
|
|
52
51
|
mkdirp.sync(workflowMapperPath);
|
|
53
52
|
return new Promise(function (resolve, reject) {
|
|
54
|
-
if (self.workflows == undefined) {
|
|
55
|
-
addlogs(config, chalk.white('No workflow Found'), '
|
|
56
|
-
return resolve();
|
|
53
|
+
if (self.workflows == undefined || isEmpty(self.workflows)) {
|
|
54
|
+
addlogs(config, chalk.white('No workflow Found'), 'success');
|
|
55
|
+
return resolve({ empty: true });
|
|
57
56
|
}
|
|
58
57
|
self.workflowsUids = Object.keys(self.workflows);
|
|
59
|
-
return Promise.map(
|
|
60
|
-
|
|
58
|
+
return Promise.map(
|
|
59
|
+
self.workflowsUids,
|
|
60
|
+
function (workflowUid) {
|
|
61
|
+
let workflow = self.workflows[workflowUid];
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) {
|
|
64
|
+
const workflowStages = workflow.workflow_stages
|
|
65
|
+
for (const stage of workflowStages) {
|
|
66
|
+
if (
|
|
67
|
+
stage.SYS_ACL.users.uids.length > 0 &&
|
|
68
|
+
stage.SYS_ACL.users.uids[0] !== '$all'
|
|
69
|
+
) {
|
|
70
|
+
stage.SYS_ACL.users.uids = ['$all'];
|
|
71
|
+
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
if (stage.SYS_ACL.roles.uids.length > 0) {
|
|
74
|
+
stage.SYS_ACL.roles.uids = [];
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
if (workflow.
|
|
73
|
-
|
|
78
|
+
if (workflow.admin_users !== undefined) {
|
|
79
|
+
addlogs(config, chalk.yellow('We are skipping import of `Workflow superuser(s)` from workflow'), 'info');
|
|
80
|
+
delete workflow.admin_users;
|
|
74
81
|
}
|
|
75
|
-
}
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
let requestOption = {
|
|
84
|
+
workflow,
|
|
85
|
+
};
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
87
|
+
return client
|
|
88
|
+
.stack({ api_key: config.target_stack, management_token: config.management_token })
|
|
89
|
+
.workflow()
|
|
90
|
+
.create(requestOption)
|
|
91
|
+
.then(function (response) {
|
|
92
|
+
self.workflowUidMapper[workflowUid] = response;
|
|
93
|
+
helper.writeFile(workflowUidMapperPath, self.workflowUidMapper);
|
|
94
|
+
})
|
|
95
|
+
.catch(function (error) {
|
|
96
|
+
self.fails.push(workflow);
|
|
97
|
+
if (error.errors.name) {
|
|
98
|
+
addlogs(config, chalk.red("workflow: '" + workflow.name + "' already exist"), 'error');
|
|
99
|
+
} else if (error.errors['workflow_stages.0.users']) {
|
|
100
|
+
addlogs(
|
|
101
|
+
config,
|
|
102
|
+
chalk.red(
|
|
103
|
+
"Failed to import Workflows as you've specified certain roles in the Stage transition and access rules section. We currently don't import roles to the stack.",
|
|
104
|
+
),
|
|
105
|
+
'error',
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
addlogs(config, chalk.red("workflow: '" + workflow.name + "' failed"), 'error');
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
// the workflow has already been created
|
|
113
|
+
addlogs(
|
|
114
|
+
config,
|
|
115
|
+
chalk.white("The Workflows: '" + workflow.name + "' already exists. Skipping it to avoid duplicates!"),
|
|
116
|
+
'success',
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
// import 1 workflows at a time
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
concurrency: reqConcurrency,
|
|
123
|
+
},
|
|
124
|
+
)
|
|
125
|
+
.then(function () {
|
|
126
|
+
helper.writeFile(workflowSuccessPath, self.success);
|
|
127
|
+
addlogs(config, chalk.green('Workflows have been imported successfully!'), 'success');
|
|
128
|
+
return resolve();
|
|
129
|
+
})
|
|
130
|
+
.catch(function (error) {
|
|
131
|
+
helper.writeFile(workflowFailsPath, self.fails);
|
|
132
|
+
addlogs(config, chalk.red('Workflows import failed'), 'error');
|
|
133
|
+
return reject(error);
|
|
134
|
+
});
|
|
115
135
|
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
module.exports = new importWorkflows();
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
module.exports = new importWorkflows();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const contentstacksdk = require(
|
|
1
|
+
const contentstacksdk = require('@contentstack/management');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
const { addlogs } = require('./log');
|
|
2
5
|
|
|
3
6
|
exports.Client = function (config) {
|
|
4
7
|
const option = {
|
|
@@ -8,21 +11,31 @@ exports.Client = function (config) {
|
|
|
8
11
|
api_key: config.target_stack,
|
|
9
12
|
maxContentLength: 100000000,
|
|
10
13
|
maxBodyLength: 1000000000,
|
|
14
|
+
maxRequests: 10,
|
|
15
|
+
retryLimit: 5,
|
|
16
|
+
timeout: 60000,
|
|
17
|
+
httpsAgent: new https.Agent({
|
|
18
|
+
maxSockets: 100,
|
|
19
|
+
maxFreeSockets: 10,
|
|
20
|
+
keepAlive: true,
|
|
21
|
+
timeout: 60000, // active socket keepalive for 60 seconds
|
|
22
|
+
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
23
|
+
}),
|
|
24
|
+
retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
|
|
11
25
|
logHandler: (level, data) => {},
|
|
12
26
|
retryCondition: (error) => {
|
|
13
27
|
// no async function should be used here
|
|
14
|
-
|
|
15
|
-
error.response &&
|
|
16
|
-
(error.response.status === 429 || error.response.status === 408)
|
|
17
|
-
) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
28
|
+
return error.response && (error.response.status === 429 || error.response.status === 408);
|
|
21
29
|
},
|
|
22
30
|
retryDelayOptions: {
|
|
23
31
|
base: 1000,
|
|
24
32
|
},
|
|
25
33
|
};
|
|
34
|
+
if (typeof config.branchName === 'string') {
|
|
35
|
+
option.headers = {
|
|
36
|
+
branch: config.branchName,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
26
39
|
const client = contentstacksdk.client(option);
|
|
27
40
|
return client;
|
|
28
41
|
};
|
|
@@ -5,46 +5,58 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line unicorn/filename-case
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
let path = require('path');
|
|
9
|
+
let helper = require('./fs');
|
|
10
|
+
let util = require('../util');
|
|
11
|
+
let config = util.getConfig();
|
|
12
|
+
let extensionPath = path.resolve(config.data, 'mapper/extensions', 'uid-mapping.json');
|
|
13
|
+
let globalfieldsPath = path.resolve(config.data, 'mapper/globalfields', 'uid-mapping.json');
|
|
14
14
|
|
|
15
15
|
// eslint-disable-next-line camelcase
|
|
16
|
-
|
|
17
|
-
for (
|
|
16
|
+
let extension_uid_Replace = (module.exports = function (schema, preserveStackVersion) {
|
|
17
|
+
for (let i in schema) {
|
|
18
18
|
if (schema[i].data_type === 'group') {
|
|
19
|
-
extension_uid_Replace(schema[i].schema, preserveStackVersion)
|
|
19
|
+
extension_uid_Replace(schema[i].schema, preserveStackVersion);
|
|
20
20
|
} else if (schema[i].data_type === 'blocks') {
|
|
21
|
-
for (
|
|
21
|
+
for (let block in schema[i].blocks) {
|
|
22
22
|
if (schema[i].blocks[block].hasOwnProperty('reference_to')) {
|
|
23
|
-
delete schema[i].blocks[block].schema
|
|
23
|
+
delete schema[i].blocks[block].schema;
|
|
24
24
|
} else {
|
|
25
|
-
extension_uid_Replace(schema[i].blocks[block].schema, preserveStackVersion)
|
|
25
|
+
extension_uid_Replace(schema[i].blocks[block].schema, preserveStackVersion);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
} else if (
|
|
28
|
+
} else if (
|
|
29
|
+
schema[i].data_type === 'reference' &&
|
|
30
|
+
!schema[i].field_metadata.hasOwnProperty('ref_multiple_content_types')
|
|
31
|
+
) {
|
|
29
32
|
if (preserveStackVersion) {
|
|
30
33
|
// do nothing
|
|
31
34
|
} else {
|
|
32
|
-
schema[i].reference_to = [schema[i].reference_to]
|
|
33
|
-
schema[i].field_metadata.ref_multiple_content_types = true
|
|
35
|
+
schema[i].reference_to = [schema[i].reference_to];
|
|
36
|
+
schema[i].field_metadata.ref_multiple_content_types = true;
|
|
34
37
|
}
|
|
35
38
|
} else if (schema[i].data_type === 'global_field') {
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
let global_fields_key_value = schema[i].reference_to;
|
|
40
|
+
let global_fields_data = helper.readFile(path.join(globalfieldsPath));
|
|
38
41
|
if (global_fields_data && global_fields_data.hasOwnProperty(global_fields_key_value)) {
|
|
39
|
-
schema[i].reference_to = global_fields_data[global_fields_key_value]
|
|
42
|
+
schema[i].reference_to = global_fields_data[global_fields_key_value];
|
|
40
43
|
}
|
|
41
44
|
} else if (schema[i].hasOwnProperty('extension_uid')) {
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const extension_key_value = schema[i].extension_uid;
|
|
46
|
+
const data = helper.readFile(path.join(extensionPath));
|
|
44
47
|
if (data && data.hasOwnProperty(extension_key_value)) {
|
|
45
48
|
// eslint-disable-next-line camelcase
|
|
46
|
-
schema[i].extension_uid = data[extension_key_value]
|
|
49
|
+
schema[i].extension_uid = data[extension_key_value];
|
|
47
50
|
}
|
|
51
|
+
} else if (schema[i].data_type === 'json' && schema[i].hasOwnProperty('plugins') && schema[i].plugins.length > 0) {
|
|
52
|
+
const newPluginUidsArray = [];
|
|
53
|
+
const data = helper.readFile(path.join(extensionPath));
|
|
54
|
+
schema[i].plugins.forEach((extension_key_value) => {
|
|
55
|
+
if (data && data.hasOwnProperty(extension_key_value)) {
|
|
56
|
+
newPluginUidsArray.push(data[extension_key_value]);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
schema[i].plugins = newPluginUidsArray;
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
|
-
}
|
|
62
|
+
})
|
package/src/lib/util/fs.js
CHANGED
|
@@ -10,16 +10,16 @@ var mkdirp = require('mkdirp');
|
|
|
10
10
|
|
|
11
11
|
exports.readFile = function (filePath, parse) {
|
|
12
12
|
var data;
|
|
13
|
-
parse =
|
|
13
|
+
parse = typeof parse === 'undefined' ? true : parse;
|
|
14
14
|
filePath = path.resolve(filePath);
|
|
15
15
|
if (fs.existsSync(filePath)) {
|
|
16
|
-
data =
|
|
16
|
+
data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : data;
|
|
17
17
|
}
|
|
18
18
|
return data;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
exports.writeFile = function (filePath, data) {
|
|
22
|
-
data =
|
|
22
|
+
data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
|
|
23
23
|
fs.writeFileSync(filePath, data);
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -39,4 +39,3 @@ exports.readdir = function (dirPath) {
|
|
|
39
39
|
return [];
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
|