@contentstack/cli-cm-export 1.20.1 → 2.0.0-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.
- package/README.md +1 -1
- package/lib/commands/cm/stacks/export.js +15 -6
- package/lib/config/index.js +0 -2
- package/lib/export/module-exporter.js +37 -38
- package/lib/export/modules/assets.js +71 -14
- package/lib/export/modules/base-class.d.ts +17 -0
- package/lib/export/modules/base-class.js +45 -0
- package/lib/export/modules/content-types.js +30 -8
- package/lib/export/modules/custom-roles.js +61 -21
- package/lib/export/modules/entries.d.ts +2 -0
- package/lib/export/modules/entries.js +137 -37
- package/lib/export/modules/environments.js +45 -20
- package/lib/export/modules/extensions.js +42 -17
- package/lib/export/modules/global-fields.d.ts +1 -1
- package/lib/export/modules/global-fields.js +24 -6
- package/lib/export/modules/index.d.ts +1 -0
- package/lib/export/modules/index.js +1 -0
- package/lib/export/modules/labels.js +43 -16
- package/lib/export/modules/locales.js +31 -12
- package/lib/export/modules/marketplace-apps.d.ts +5 -2
- package/lib/export/modules/marketplace-apps.js +95 -25
- package/lib/export/modules/personalize.d.ts +12 -2
- package/lib/export/modules/personalize.js +181 -46
- package/lib/export/modules/stack.js +83 -28
- package/lib/export/modules/taxonomies.d.ts +4 -9
- package/lib/export/modules/taxonomies.js +123 -75
- package/lib/export/modules/webhooks.js +40 -17
- package/lib/export/modules/workflows.js +57 -20
- package/lib/types/default-config.d.ts +0 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/common-helper.d.ts +1 -2
- package/lib/utils/common-helper.js +1 -12
- package/lib/utils/constants.d.ts +147 -0
- package/lib/utils/constants.js +160 -0
- package/lib/utils/export-config-handler.js +2 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/marketplace-app-helper.d.ts +1 -0
- package/lib/utils/marketplace-app-helper.js +21 -12
- package/lib/utils/progress-strategy-registry.d.ts +7 -0
- package/lib/utils/progress-strategy-registry.js +92 -0
- package/messages/index.json +4 -2
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/lib/export/modules-js/assets.d.ts +0 -43
- package/lib/export/modules-js/assets.js +0 -396
- package/lib/export/modules-js/content-types.d.ts +0 -21
- package/lib/export/modules-js/content-types.js +0 -76
- package/lib/export/modules-js/custom-roles.d.ts +0 -21
- package/lib/export/modules-js/custom-roles.js +0 -76
- package/lib/export/modules-js/entries.d.ts +0 -18
- package/lib/export/modules-js/entries.js +0 -143
- package/lib/export/modules-js/environments.d.ts +0 -16
- package/lib/export/modules-js/environments.js +0 -62
- package/lib/export/modules-js/extensions.d.ts +0 -18
- package/lib/export/modules-js/extensions.js +0 -57
- package/lib/export/modules-js/global-fields.d.ts +0 -22
- package/lib/export/modules-js/global-fields.js +0 -108
- package/lib/export/modules-js/index.d.ts +0 -2
- package/lib/export/modules-js/index.js +0 -31
- package/lib/export/modules-js/labels.d.ts +0 -14
- package/lib/export/modules-js/labels.js +0 -56
- package/lib/export/modules-js/locales.d.ts +0 -23
- package/lib/export/modules-js/locales.js +0 -68
- package/lib/export/modules-js/marketplace-apps.d.ts +0 -21
- package/lib/export/modules-js/marketplace-apps.js +0 -132
- package/lib/export/modules-js/stack.d.ts +0 -18
- package/lib/export/modules-js/stack.js +0 -91
- package/lib/export/modules-js/webhooks.d.ts +0 -18
- package/lib/export/modules-js/webhooks.js +0 -60
- package/lib/export/modules-js/workflows.d.ts +0 -16
- package/lib/export/modules-js/workflows.js +0 -89
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export = ExportCustomRoles;
|
|
2
|
-
declare class ExportCustomRoles {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
roles: {};
|
|
5
|
-
customRoles: {};
|
|
6
|
-
EXISTING_ROLES: {
|
|
7
|
-
Admin: number;
|
|
8
|
-
Developer: number;
|
|
9
|
-
'Content Manager': number;
|
|
10
|
-
};
|
|
11
|
-
rolesConfig: {
|
|
12
|
-
dirName: string;
|
|
13
|
-
fileName: string;
|
|
14
|
-
customRolesLocalesFileName: string;
|
|
15
|
-
dependencies?: import("../../types").Modules[];
|
|
16
|
-
};
|
|
17
|
-
config: any;
|
|
18
|
-
stackAPIClient: any;
|
|
19
|
-
start(): Promise<void>;
|
|
20
|
-
getCustomRolesLocales(customRoles: any, customRolesLocalesFilepath: any, stackAPIClient: any, config: any): Promise<void>;
|
|
21
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const mkdirp = require('mkdirp');
|
|
5
|
-
const { merge } = require('lodash');
|
|
6
|
-
const { fileHelper, log, formatError } = require('../../utils');
|
|
7
|
-
const { default: config } = require('../../config');
|
|
8
|
-
module.exports = class ExportCustomRoles {
|
|
9
|
-
constructor(exportConfig, stackAPIClient) {
|
|
10
|
-
this.roles = {};
|
|
11
|
-
this.customRoles = {};
|
|
12
|
-
this.EXISTING_ROLES = {
|
|
13
|
-
Admin: 1,
|
|
14
|
-
Developer: 1,
|
|
15
|
-
'Content Manager': 1,
|
|
16
|
-
};
|
|
17
|
-
this.rolesConfig = config.modules.customRoles;
|
|
18
|
-
this.config = merge(config, exportConfig);
|
|
19
|
-
this.stackAPIClient = stackAPIClient;
|
|
20
|
-
}
|
|
21
|
-
async start() {
|
|
22
|
-
const self = this;
|
|
23
|
-
try {
|
|
24
|
-
log(this.config, 'Starting roles export', 'success');
|
|
25
|
-
const rolesFolderPath = path.resolve(this.config.data, this.config.branchName || '', this.rolesConfig.dirName);
|
|
26
|
-
mkdirp.sync(rolesFolderPath);
|
|
27
|
-
const roles = await self.stackAPIClient.role().fetchAll({ include_rules: true, include_permissions: true });
|
|
28
|
-
const customRoles = roles.items.filter((role) => !self.EXISTING_ROLES[role.name]);
|
|
29
|
-
if (!customRoles.length) {
|
|
30
|
-
log(self.config, 'No custom roles were found in the Stack', 'success');
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
await self.getCustomRolesLocales(customRoles, path.join(rolesFolderPath, self.rolesConfig.customRolesLocalesFileName), self.stackAPIClient, self.config);
|
|
34
|
-
self.customRoles = {};
|
|
35
|
-
customRoles.forEach((role) => {
|
|
36
|
-
log(self.config, `'${role.name}' role was exported successfully`, 'success');
|
|
37
|
-
self.customRoles[role.uid] = role;
|
|
38
|
-
});
|
|
39
|
-
fileHelper.writeFileSync(path.join(rolesFolderPath, self.rolesConfig.fileName), self.customRoles);
|
|
40
|
-
log(self.config, chalk.green('All the custom roles have been exported successfully'), 'success');
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
if (error.statusCode === 401) {
|
|
44
|
-
log(self.config, 'You are not allowed to export roles, Unless you provide email and password in config', 'error');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
log(self.config, `Error occurred in exporting roles. ${formatError(error)}`, 'error');
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async getCustomRolesLocales(customRoles, customRolesLocalesFilepath, stackAPIClient, config) {
|
|
52
|
-
const localesMap = {};
|
|
53
|
-
for (const role of customRoles) {
|
|
54
|
-
const rulesLocales = role.rules.find((rule) => rule.module === 'locale');
|
|
55
|
-
if (rulesLocales.locales && rulesLocales.locales.length) {
|
|
56
|
-
rulesLocales.locales.forEach((locale) => {
|
|
57
|
-
localesMap[locale] = 1;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (Object.keys(localesMap).length) {
|
|
62
|
-
const locales = await stackAPIClient.locale().query({}).find();
|
|
63
|
-
const sourceLocalesMap = {};
|
|
64
|
-
for (const locale of locales.items) {
|
|
65
|
-
sourceLocalesMap[locale.uid] = locale;
|
|
66
|
-
}
|
|
67
|
-
for (const locale in localesMap) {
|
|
68
|
-
if (sourceLocalesMap[locale] !== undefined) {
|
|
69
|
-
delete sourceLocalesMap[locale]['stackHeaders'];
|
|
70
|
-
}
|
|
71
|
-
localesMap[locale] = sourceLocalesMap[locale];
|
|
72
|
-
}
|
|
73
|
-
fileHelper.writeFileSync(customRolesLocalesFilepath, localesMap);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export = EntriesExport;
|
|
2
|
-
declare class EntriesExport {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
stackAPIClient: any;
|
|
5
|
-
exportConfig: any;
|
|
6
|
-
entriesConfig: any;
|
|
7
|
-
entriesRootPath: string;
|
|
8
|
-
localesFilePath: string;
|
|
9
|
-
schemaFilePath: string;
|
|
10
|
-
fetchConcurrency: any;
|
|
11
|
-
writeConcurrency: any;
|
|
12
|
-
start(): Promise<void>;
|
|
13
|
-
getEntries(requestOptions: any, skip?: number, entries?: {}): any;
|
|
14
|
-
getEntryByVersion(requestOptions: any, version: any, entries?: any[]): any;
|
|
15
|
-
getEntriesCount(requestOptions: any): Promise<any>;
|
|
16
|
-
createRequestObjects(locales: any, contentTypes: any): any[];
|
|
17
|
-
sanitizeAttribs(entries: any, entriesList?: {}): {};
|
|
18
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const { values } = require('lodash');
|
|
4
|
-
const { executeTask, formatError, fileHelper, log } = require('../../utils');
|
|
5
|
-
const { sanitizePath } = require('@contentstack/cli-utilities');
|
|
6
|
-
class EntriesExport {
|
|
7
|
-
constructor(exportConfig, stackAPIClient) {
|
|
8
|
-
this.stackAPIClient = stackAPIClient;
|
|
9
|
-
this.exportConfig = exportConfig;
|
|
10
|
-
this.entriesConfig = exportConfig.modules.entries;
|
|
11
|
-
this.entriesRootPath = path.resolve((sanitizePath(exportConfig.data)), sanitizePath(exportConfig.branchName || ''), sanitizePath(this.entriesConfig.dirName));
|
|
12
|
-
this.localesFilePath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), sanitizePath(exportConfig.modules.locales.dirName), sanitizePath(exportConfig.modules.locales.fileName));
|
|
13
|
-
this.schemaFilePath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), sanitizePath(exportConfig.modules.content_types.dirName), 'schema.json');
|
|
14
|
-
this.fetchConcurrency = this.entriesConfig.fetchConcurrency || exportConfig.fetchConcurrency;
|
|
15
|
-
this.writeConcurrency = this.entriesConfig.writeConcurrency || exportConfig.writeConcurrency;
|
|
16
|
-
}
|
|
17
|
-
async start() {
|
|
18
|
-
try {
|
|
19
|
-
log(this.exportConfig, 'Starting entries export', 'info');
|
|
20
|
-
const locales = await fileHelper.readFile(this.localesFilePath);
|
|
21
|
-
const contentTypes = await fileHelper.readFile(this.schemaFilePath);
|
|
22
|
-
if (contentTypes.length === 0) {
|
|
23
|
-
log(this.exportConfig, 'No content types found to export entries', 'info');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const entryRequestOptions = this.createRequestObjects(locales, contentTypes);
|
|
27
|
-
for (let requestOption of entryRequestOptions) {
|
|
28
|
-
log(this.exportConfig, `Starting export of entries of content_type - ${requestOption.content_type} locale - ${requestOption.locale}`, 'info');
|
|
29
|
-
await fileHelper.makeDirectory(path.join(this.entriesRootPath, requestOption.content_type));
|
|
30
|
-
const entries = await this.getEntries(requestOption);
|
|
31
|
-
let entriesFilePath = path.join(this.entriesRootPath, requestOption.content_type, requestOption.locale + '.json');
|
|
32
|
-
await fileHelper.writeLargeFile(entriesFilePath, entries);
|
|
33
|
-
log(this.exportConfig, `Exported entries of type '${requestOption.content_type}' locale '${requestOption.locale}'`, 'success');
|
|
34
|
-
if (this.exportConfig.versioning) {
|
|
35
|
-
log(this.exportConfig, `Started export versioned entries of type '${requestOption.content_type}' locale '${requestOption.locale}'`, 'info');
|
|
36
|
-
for (let entry of values(entries)) {
|
|
37
|
-
const versionedEntries = await this.getEntryByVersion(Object.assign(Object.assign({}, requestOption), { uid: entry.uid }), entry._version);
|
|
38
|
-
let versionedEntryPath = path.join(this.entriesRootPath, requestOption.locale, requestOption.content_type, entry.uid);
|
|
39
|
-
await fileHelper.makeDirectory(versionedEntryPath);
|
|
40
|
-
if (versionedEntries.length > 0) {
|
|
41
|
-
const write = (versionedEntry) => fileHelper.writeFile(path.join(sanitizePath(versionedEntryPath), 'version-' + sanitizePath(versionedEntry._version) + '.json'), versionedEntry);
|
|
42
|
-
await executeTask(versionedEntries, write.bind(this), { concurrency: this.writeConcurrency });
|
|
43
|
-
log(this.exportConfig, `Exported versioned entries of type '${requestOption.content_type}' locale '${requestOption.locale}'`, 'success');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
log(this.exportConfig, chalk.green('Entries exported successfully'), 'success');
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
log(this.exportConfig, `Failed to export entries ${formatError(error)}`, 'error');
|
|
52
|
-
throw new Error('Failed to export entries');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async getEntries(requestOptions, skip = 0, entries = {}) {
|
|
56
|
-
let requestObject = {
|
|
57
|
-
locale: requestOptions.locale,
|
|
58
|
-
skip,
|
|
59
|
-
limit: this.entriesConfig.limit,
|
|
60
|
-
include_count: true,
|
|
61
|
-
include_publish_details: true,
|
|
62
|
-
query: {
|
|
63
|
-
locale: requestOptions.locale,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const entriesSearchResponse = await this.stackAPIClient
|
|
67
|
-
.contentType(requestOptions.content_type)
|
|
68
|
-
.entry()
|
|
69
|
-
.query(requestObject)
|
|
70
|
-
.find();
|
|
71
|
-
if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) {
|
|
72
|
-
// clean up attribs and add to parent entry list
|
|
73
|
-
this.sanitizeAttribs(entriesSearchResponse.items, entries);
|
|
74
|
-
skip += this.entriesConfig.limit || 100;
|
|
75
|
-
if (skip > entriesSearchResponse.count) {
|
|
76
|
-
return entries;
|
|
77
|
-
}
|
|
78
|
-
return await this.getEntries(requestOptions, skip, entries);
|
|
79
|
-
}
|
|
80
|
-
return entries;
|
|
81
|
-
}
|
|
82
|
-
async getEntryByVersion(requestOptions, version, entries = []) {
|
|
83
|
-
const queryRequestObject = {
|
|
84
|
-
locale: requestOptions.locale,
|
|
85
|
-
except: {
|
|
86
|
-
BASE: this.entriesConfig.invalidKeys,
|
|
87
|
-
},
|
|
88
|
-
version,
|
|
89
|
-
};
|
|
90
|
-
const entryResponse = await this.stackAPIClient
|
|
91
|
-
.contentType(requestOptions.content_type)
|
|
92
|
-
.entry(requestOptions.uid)
|
|
93
|
-
.fetch(queryRequestObject);
|
|
94
|
-
entries.push(entryResponse);
|
|
95
|
-
if (--version > 0) {
|
|
96
|
-
return await this.getEntryByVersion(requestOptions, version, entries);
|
|
97
|
-
}
|
|
98
|
-
return entries;
|
|
99
|
-
}
|
|
100
|
-
async getEntriesCount(requestOptions) {
|
|
101
|
-
let requestObject = {
|
|
102
|
-
locale: requestOptions.locale,
|
|
103
|
-
limit: 1,
|
|
104
|
-
include_count: true,
|
|
105
|
-
include_publish_details: true,
|
|
106
|
-
query: {
|
|
107
|
-
locale: requestOptions.locale,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
const entriesSearchResponse = await this.stackAPIClient
|
|
111
|
-
.contentType(requestOptions.content_type)
|
|
112
|
-
.entry()
|
|
113
|
-
.query(requestObject)
|
|
114
|
-
.find();
|
|
115
|
-
return entriesSearchResponse.count;
|
|
116
|
-
}
|
|
117
|
-
createRequestObjects(locales, contentTypes) {
|
|
118
|
-
let requestObjects = [];
|
|
119
|
-
contentTypes.forEach((contentType) => {
|
|
120
|
-
if (Object.keys(locales).length !== 0) {
|
|
121
|
-
for (let locale in locales) {
|
|
122
|
-
requestObjects.push({
|
|
123
|
-
content_type: contentType.uid,
|
|
124
|
-
locale: locales[locale].code,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
requestObjects.push({
|
|
129
|
-
content_type: contentType.uid,
|
|
130
|
-
locale: this.exportConfig.master_locale.code,
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
return requestObjects;
|
|
134
|
-
}
|
|
135
|
-
sanitizeAttribs(entries, entriesList = {}) {
|
|
136
|
-
entries.forEach((entry) => {
|
|
137
|
-
this.entriesConfig.invalidKeys.forEach((key) => delete entry[key]);
|
|
138
|
-
entriesList[entry.uid] = entry;
|
|
139
|
-
});
|
|
140
|
-
return entriesList;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
module.exports = EntriesExport;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export = ExportEnvironments;
|
|
2
|
-
declare class ExportEnvironments {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
config: {};
|
|
5
|
-
master: {};
|
|
6
|
-
environments: {};
|
|
7
|
-
requestOptions: {
|
|
8
|
-
json: boolean;
|
|
9
|
-
qs: {
|
|
10
|
-
asc: string;
|
|
11
|
-
include_count: boolean;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
stackAPIClient: any;
|
|
15
|
-
start(): Promise<any>;
|
|
16
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
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 { merge } = require('lodash');
|
|
10
|
-
const { fileHelper, log, formatError } = require('../../utils');
|
|
11
|
-
module.exports = class ExportEnvironments {
|
|
12
|
-
constructor(exportConfig, stackAPIClient) {
|
|
13
|
-
this.config = {};
|
|
14
|
-
this.master = {};
|
|
15
|
-
this.environments = {};
|
|
16
|
-
this.requestOptions = {
|
|
17
|
-
json: true,
|
|
18
|
-
qs: {
|
|
19
|
-
asc: 'updated_at',
|
|
20
|
-
include_count: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
this.config = merge(this.config, exportConfig);
|
|
24
|
-
this.stackAPIClient = stackAPIClient;
|
|
25
|
-
}
|
|
26
|
-
start() {
|
|
27
|
-
const self = this;
|
|
28
|
-
const environmentConfig = self.config.modules.environments;
|
|
29
|
-
const environmentsFolderPath = path.resolve(self.config.data, self.config.branchName || '', environmentConfig.dirName);
|
|
30
|
-
// Create folder for environments
|
|
31
|
-
fileHelper.makeDirectory(environmentsFolderPath);
|
|
32
|
-
log(this.config, 'Starting environment export', 'success');
|
|
33
|
-
return new Promise(function (resolve, reject) {
|
|
34
|
-
self.stackAPIClient
|
|
35
|
-
.environment()
|
|
36
|
-
.query(self.requestOptions.qs)
|
|
37
|
-
.find()
|
|
38
|
-
.then((environmentResponse) => {
|
|
39
|
-
if (environmentResponse.items.length !== 0) {
|
|
40
|
-
for (let i = 0, total = environmentResponse.count; i < total; i++) {
|
|
41
|
-
const envUid = environmentResponse.items[i].uid;
|
|
42
|
-
self.master[envUid] = '';
|
|
43
|
-
self.environments[envUid] = environmentResponse.items[i];
|
|
44
|
-
delete self.environments[envUid].uid;
|
|
45
|
-
delete self.environments[envUid]['ACL'];
|
|
46
|
-
}
|
|
47
|
-
fileHelper.writeFileSync(path.join(environmentsFolderPath, environmentConfig.fileName), self.environments);
|
|
48
|
-
log(self.config, chalk.green('All the environments have been exported successfully'), 'success');
|
|
49
|
-
return resolve();
|
|
50
|
-
}
|
|
51
|
-
if (environmentResponse.items.length === 0) {
|
|
52
|
-
log(self.config, 'No environments found', 'success');
|
|
53
|
-
resolve();
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
.catch((error) => {
|
|
57
|
-
log(self.config, `Environments export failed. ${formatError(error)}`, 'error');
|
|
58
|
-
reject(error);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export = ExportExtensions;
|
|
2
|
-
declare class ExportExtensions {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
master: {};
|
|
5
|
-
extensions: {};
|
|
6
|
-
extensionConfig: {
|
|
7
|
-
dirName: string;
|
|
8
|
-
fileName: string;
|
|
9
|
-
dependencies?: import("../../types").Modules[];
|
|
10
|
-
};
|
|
11
|
-
queryRequestOptions: {
|
|
12
|
-
asc: string;
|
|
13
|
-
include_count: boolean;
|
|
14
|
-
};
|
|
15
|
-
config: any;
|
|
16
|
-
stackAPIClient: any;
|
|
17
|
-
start(): Promise<any>;
|
|
18
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const mkdirp = require('mkdirp');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const { merge } = require('lodash');
|
|
10
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
11
|
-
const { default: config } = require('../../config');
|
|
12
|
-
module.exports = class ExportExtensions {
|
|
13
|
-
constructor(exportConfig, stackAPIClient) {
|
|
14
|
-
this.master = {};
|
|
15
|
-
this.extensions = {};
|
|
16
|
-
this.extensionConfig = config.modules.extensions;
|
|
17
|
-
this.queryRequestOptions = {
|
|
18
|
-
asc: 'updated_at',
|
|
19
|
-
include_count: true,
|
|
20
|
-
};
|
|
21
|
-
this.config = merge(config, exportConfig);
|
|
22
|
-
this.stackAPIClient = stackAPIClient;
|
|
23
|
-
}
|
|
24
|
-
start() {
|
|
25
|
-
log(this.config, 'Starting extension export', 'success');
|
|
26
|
-
const self = this;
|
|
27
|
-
const extensionsFolderPath = path.resolve(this.config.data, this.config.branchName || '', this.extensionConfig.dirName);
|
|
28
|
-
// Create folder for extensions
|
|
29
|
-
mkdirp.sync(extensionsFolderPath);
|
|
30
|
-
return new Promise(function (resolve, reject) {
|
|
31
|
-
self.stackAPIClient
|
|
32
|
-
.extension()
|
|
33
|
-
.query(self.queryRequestOptions)
|
|
34
|
-
.find()
|
|
35
|
-
.then((extension) => {
|
|
36
|
-
if (extension.items.length !== 0) {
|
|
37
|
-
for (let i = 0, total = extension.count; i < total; i++) {
|
|
38
|
-
const extUid = extension.items[i].uid;
|
|
39
|
-
self.master[extUid] = '';
|
|
40
|
-
self.extensions[extUid] = extension.items[i];
|
|
41
|
-
delete self.extensions[extUid].uid;
|
|
42
|
-
delete self.extensions[extUid].SYS_ACL;
|
|
43
|
-
}
|
|
44
|
-
fileHelper.writeFileSync(path.join(extensionsFolderPath, self.extensionConfig.fileName), self.extensions);
|
|
45
|
-
log(self.config, chalk.green('All the extensions have been exported successfully'), 'success');
|
|
46
|
-
return resolve();
|
|
47
|
-
}
|
|
48
|
-
log(self.config, 'No extensions found', 'success');
|
|
49
|
-
resolve();
|
|
50
|
-
})
|
|
51
|
-
.catch((error) => {
|
|
52
|
-
log(self.config, `Failed to export extensions. ${formatError(error)}`, 'error');
|
|
53
|
-
reject();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export = ExportGlobalFields;
|
|
2
|
-
declare class ExportGlobalFields {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
limit: number;
|
|
5
|
-
config: {};
|
|
6
|
-
global_fields: any[];
|
|
7
|
-
master: {};
|
|
8
|
-
globalfields: {};
|
|
9
|
-
requestOptions: {};
|
|
10
|
-
globalfieldsFolderPath: string;
|
|
11
|
-
globalfieldsConfig: {
|
|
12
|
-
dirName: string;
|
|
13
|
-
fileName: string;
|
|
14
|
-
validKeys: string[];
|
|
15
|
-
dependencies?: import("../../types").Modules[];
|
|
16
|
-
};
|
|
17
|
-
validKeys: string[];
|
|
18
|
-
stackAPIClient: any;
|
|
19
|
-
start(): Promise<any>;
|
|
20
|
-
getGlobalFields(skip: any, globalFieldConfig: any): Promise<any>;
|
|
21
|
-
writeGlobalFields(): Promise<any>;
|
|
22
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
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 { merge } = require('lodash');
|
|
10
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
11
|
-
const { default: config } = require('../../config');
|
|
12
|
-
const { sanitizePath } = require('@contentstack/cli-utilities');
|
|
13
|
-
module.exports = class ExportGlobalFields {
|
|
14
|
-
constructor(exportConfig, stackAPIClient) {
|
|
15
|
-
this.limit = 100;
|
|
16
|
-
this.config = {};
|
|
17
|
-
this.global_fields = [];
|
|
18
|
-
this.master = {};
|
|
19
|
-
this.globalfields = {};
|
|
20
|
-
this.requestOptions = {};
|
|
21
|
-
this.globalfieldsConfig = config.modules.globalfields;
|
|
22
|
-
this.validKeys = config.modules.globalfields.validKeys;
|
|
23
|
-
this.requestOptions = {
|
|
24
|
-
qs: {
|
|
25
|
-
skip: 0,
|
|
26
|
-
limit: this.limit,
|
|
27
|
-
asc: 'updated_at',
|
|
28
|
-
include_count: true,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
this.config = merge(config, exportConfig);
|
|
32
|
-
this.stackAPIClient = stackAPIClient;
|
|
33
|
-
this.globalfieldsFolderPath = path.resolve(sanitizePath(this.config.data), sanitizePath(this.config.branchName || ''), sanitizePath(this.globalfieldsConfig.dirName));
|
|
34
|
-
}
|
|
35
|
-
start() {
|
|
36
|
-
const self = this;
|
|
37
|
-
// Create folder for Global Fields
|
|
38
|
-
mkdirp.sync(self.globalfieldsFolderPath);
|
|
39
|
-
log(self.config, 'Starting Global Fields export', 'success');
|
|
40
|
-
return new Promise(function (resolve, reject) {
|
|
41
|
-
try {
|
|
42
|
-
return self
|
|
43
|
-
.getGlobalFields(0, self.config)
|
|
44
|
-
.then(function (result) {
|
|
45
|
-
if (!result) {
|
|
46
|
-
return self.writeGlobalFields().then(resolve).catch(reject);
|
|
47
|
-
}
|
|
48
|
-
return resolve();
|
|
49
|
-
})
|
|
50
|
-
.catch(reject);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
log(self.config, error, 'error');
|
|
54
|
-
return reject(error);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
getGlobalFields(skip, globalFieldConfig) {
|
|
59
|
-
const self = this;
|
|
60
|
-
self.requestOptions.qs.skip = skip;
|
|
61
|
-
return new Promise(function (resolve, reject) {
|
|
62
|
-
self.stackAPIClient
|
|
63
|
-
.globalField()
|
|
64
|
-
.query(self.requestOptions.qs)
|
|
65
|
-
.find()
|
|
66
|
-
.then((globalFieldResponse) => {
|
|
67
|
-
try {
|
|
68
|
-
if (globalFieldResponse.items.length === 0) {
|
|
69
|
-
log(globalFieldConfig, 'No global fields found', 'success');
|
|
70
|
-
return resolve('No Global Fields');
|
|
71
|
-
}
|
|
72
|
-
globalFieldResponse.items.forEach(function (globalField) {
|
|
73
|
-
for (const key in globalField) {
|
|
74
|
-
if (self.validKeys.indexOf(key) === -1) {
|
|
75
|
-
delete globalField[key];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
self.global_fields.push(globalField);
|
|
79
|
-
});
|
|
80
|
-
skip += self.limit;
|
|
81
|
-
if (skip >= globalFieldResponse.count) {
|
|
82
|
-
return resolve();
|
|
83
|
-
}
|
|
84
|
-
return self.getGlobalFields(skip, globalFieldConfig).then(resolve).catch(reject);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
log(globalFieldConfig, `Failed to export global-fields. ${formatError(error)}`, 'error');
|
|
88
|
-
reject(error);
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
.catch(reject);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
writeGlobalFields() {
|
|
95
|
-
const self = this;
|
|
96
|
-
return new Promise(function (resolve, reject) {
|
|
97
|
-
try {
|
|
98
|
-
fileHelper.writeFileSync(path.join(self.globalfieldsFolderPath, self.globalfieldsConfig.fileName), self.global_fields);
|
|
99
|
-
log(self.config, chalk.green('Global Fields export completed successfully'), 'success');
|
|
100
|
-
resolve();
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
log(self.config, error, 'error');
|
|
104
|
-
reject(error);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
-
if (k2 === undefined) k2 = k;
|
|
3
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
-
}
|
|
7
|
-
Object.defineProperty(o, k2, desc);
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
-
if (mod && mod.__esModule) return mod;
|
|
19
|
-
var result = {};
|
|
20
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
-
__setModuleDefault(result, mod);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
async function startModuleExport(modulePayload) {
|
|
25
|
-
var _a;
|
|
26
|
-
const { moduleName, exportConfig, stackAPIClient } = modulePayload;
|
|
27
|
-
const { default: ModuleRunner } = await (_a = `./${moduleName}.js`, Promise.resolve().then(() => __importStar(require(_a))));
|
|
28
|
-
const moduleRunner = new ModuleRunner(exportConfig, stackAPIClient);
|
|
29
|
-
return moduleRunner.start();
|
|
30
|
-
}
|
|
31
|
-
module.exports = startModuleExport;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export = ExportLabels;
|
|
2
|
-
declare class ExportLabels {
|
|
3
|
-
constructor(exportConfig: any, stackAPIClient: any);
|
|
4
|
-
labels: {};
|
|
5
|
-
labelConfig: {
|
|
6
|
-
dirName: string;
|
|
7
|
-
fileName: string;
|
|
8
|
-
invalidKeys: string[];
|
|
9
|
-
dependencies?: import("../../types").Modules[];
|
|
10
|
-
};
|
|
11
|
-
config: any;
|
|
12
|
-
stackAPIClient: any;
|
|
13
|
-
start(): Promise<any>;
|
|
14
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
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 { merge } = require('lodash');
|
|
10
|
-
const { formatError, log, fileHelper } = require('../../utils');
|
|
11
|
-
const { default: config } = require('../../config');
|
|
12
|
-
module.exports = class ExportLabels {
|
|
13
|
-
constructor(exportConfig, stackAPIClient) {
|
|
14
|
-
this.labels = {};
|
|
15
|
-
this.labelConfig = config.modules.labels;
|
|
16
|
-
this.config = merge(config, exportConfig);
|
|
17
|
-
this.stackAPIClient = stackAPIClient;
|
|
18
|
-
}
|
|
19
|
-
start() {
|
|
20
|
-
log(this.config, 'Starting labels export', 'success');
|
|
21
|
-
const self = this;
|
|
22
|
-
const labelsFolderPath = path.resolve(config.data, this.config.branchName || '', self.labelConfig.dirName);
|
|
23
|
-
// Create locale folder
|
|
24
|
-
mkdirp.sync(labelsFolderPath);
|
|
25
|
-
return new Promise(function (resolve, reject) {
|
|
26
|
-
return self.stackAPIClient
|
|
27
|
-
.label()
|
|
28
|
-
.query()
|
|
29
|
-
.find()
|
|
30
|
-
.then((response) => {
|
|
31
|
-
if (response.items.length !== 0) {
|
|
32
|
-
response.items.forEach(function (label) {
|
|
33
|
-
log(self.config, `'${label.name}' label was exported successfully`, 'success');
|
|
34
|
-
self.labels[label.uid] = label;
|
|
35
|
-
const deleteItems = self.config.modules.labels.invalidKeys;
|
|
36
|
-
deleteItems.forEach((e) => delete label[e]);
|
|
37
|
-
});
|
|
38
|
-
log(self.config, chalk.green('All the labels have been exported successfully'), 'success');
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
log(self.config, 'No labels found', 'success');
|
|
42
|
-
}
|
|
43
|
-
fileHelper.writeFileSync(path.join(labelsFolderPath, self.labelConfig.fileName), self.labels);
|
|
44
|
-
resolve();
|
|
45
|
-
})
|
|
46
|
-
.catch(function (error) {
|
|
47
|
-
if (error.statusCode === 401) {
|
|
48
|
-
log(self.config, 'You are not allowed to export label, Unless you provide email and password in config', 'error');
|
|
49
|
-
return resolve();
|
|
50
|
-
}
|
|
51
|
-
log(self.config, `Failed to export labels. ${formatError(error)}`, 'error');
|
|
52
|
-
reject();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|