@contentstack/cli-cm-export-query 1.0.0-beta.3 → 1.0.0-beta.5
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/lib/commands/cm/stacks/export-query.js +5 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/branch-helper.js +7 -2
- package/lib/utils/config-handler.js +6 -3
- package/lib/utils/dependency-resolver.js +2 -2
- package/lib/utils/query-parser.js +4 -4
- package/lib/utils/referenced-asset-handler.js +3 -3
- package/oclif.manifest.json +14 -1
- package/package.json +10 -10
|
@@ -65,6 +65,11 @@ ExportQueryCommand.flags = {
|
|
|
65
65
|
}),
|
|
66
66
|
branch: cli_utilities_1.flags.string({
|
|
67
67
|
description: 'Branch name to export from',
|
|
68
|
+
exclusive: ['branch-alias'],
|
|
69
|
+
}),
|
|
70
|
+
'branch-alias': cli_utilities_1.flags.string({
|
|
71
|
+
description: 'Alias of Branch to export from',
|
|
72
|
+
exclusive: ['branch'],
|
|
68
73
|
}),
|
|
69
74
|
query: cli_utilities_1.flags.string({
|
|
70
75
|
required: true,
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupBranches = void 0;
|
|
4
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
4
5
|
const logger_1 = require("./logger");
|
|
5
6
|
/**
|
|
6
7
|
* Validates and sets up branch configuration for the stack
|
|
@@ -11,9 +12,13 @@ const logger_1 = require("./logger");
|
|
|
11
12
|
*/
|
|
12
13
|
const setupBranches = async (config, stackAPIClient) => {
|
|
13
14
|
if (typeof config !== 'object') {
|
|
14
|
-
throw new Error('
|
|
15
|
+
throw new Error('The branch configuration is invalid.');
|
|
15
16
|
}
|
|
16
17
|
try {
|
|
18
|
+
if (config.branchAlias) {
|
|
19
|
+
config.branchName = await (0, cli_utilities_1.getBranchFromAlias)(stackAPIClient, config.branchAlias);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
17
22
|
if (config.branchName) {
|
|
18
23
|
// Check if the specified branch exists
|
|
19
24
|
(0, logger_1.log)(config, `Validating branch: ${config.branchName}`, 'info');
|
|
@@ -28,7 +33,7 @@ const setupBranches = async (config, stackAPIClient) => {
|
|
|
28
33
|
(0, logger_1.log)(config, `Branch '${config.branchName}' found`, 'success');
|
|
29
34
|
}
|
|
30
35
|
else {
|
|
31
|
-
throw new Error(`No branch found
|
|
36
|
+
throw new Error(`No branch found named ${config.branchName}.`);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
@@ -12,6 +12,9 @@ async function setupQueryExportConfig(flags) {
|
|
|
12
12
|
const exportQueryConfig = Object.assign(Object.assign({}, config_1.default), { exportDir, stackApiKey: flags['stack-api-key'] || '', managementToken: flags.alias ? (_a = cli_utilities_1.configHandler.get(`tokens.${flags.alias}`)) === null || _a === void 0 ? void 0 : _a.token : undefined, query: flags.query, skipReferences: flags['skip-references'] || false, skipDependencies: flags['skip-dependencies'] || false, branchName: flags.branch, securedAssets: flags['secured-assets'] || false, isQueryBasedExport: true, logsPath: exportDir, dataPath: exportDir,
|
|
13
13
|
// Todo: accept the path of the config file from the user
|
|
14
14
|
externalConfigPath: path.join(__dirname, '../config/export-config.json') });
|
|
15
|
+
if (flags['branch-alias']) {
|
|
16
|
+
exportQueryConfig.branchAlias = flags['branch-alias'];
|
|
17
|
+
}
|
|
15
18
|
// override the external config path if the user provides a config file
|
|
16
19
|
if (flags.config) {
|
|
17
20
|
exportQueryConfig.externalConfigPath = (0, cli_utilities_1.sanitizePath)(flags['config']);
|
|
@@ -22,17 +25,17 @@ async function setupQueryExportConfig(flags) {
|
|
|
22
25
|
exportQueryConfig.managementToken = token;
|
|
23
26
|
exportQueryConfig.stackApiKey = apiKey;
|
|
24
27
|
if (!exportQueryConfig.managementToken) {
|
|
25
|
-
throw new Error(`No management token found
|
|
28
|
+
throw new Error(`No management token found for alias ${flags.alias}.`);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
if (!exportQueryConfig.managementToken) {
|
|
29
32
|
if (!(0, cli_utilities_1.isAuthenticated)()) {
|
|
30
|
-
throw new Error('
|
|
33
|
+
throw new Error('Log in or provide an alias for the management token.');
|
|
31
34
|
}
|
|
32
35
|
else {
|
|
33
36
|
exportQueryConfig.stackApiKey = flags['stack-api-key'] || (await (0, common_helper_1.askAPIKey)());
|
|
34
37
|
if (typeof exportQueryConfig.stackApiKey !== 'string') {
|
|
35
|
-
throw new Error('
|
|
38
|
+
throw new Error('The API key is invalid.');
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -46,7 +46,7 @@ class ContentTypeDependenciesHandler {
|
|
|
46
46
|
(0, logger_1.log)(this.exportQueryConfig, `Dependencies separated - Global Fields: ${dependencies.globalFields.size}, Extensions: ${dependencies.extensions.size}, Taxonomies: ${dependencies.taxonomies.size}, Marketplace Apps: ${dependencies.marketplaceApps.size}`, 'info');
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
|
-
(0, logger_1.log)(this.exportQueryConfig, `
|
|
49
|
+
(0, logger_1.log)(this.exportQueryConfig, `Failed to separate extensions and Marketplace apps: ${error.message}`, 'error');
|
|
50
50
|
// Keep original extensions if separation fails
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -87,7 +87,7 @@ class ContentTypeDependenciesHandler {
|
|
|
87
87
|
return { extensions: regularExtensions, marketplaceApps };
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
|
-
(0, logger_1.log)(this.exportQueryConfig, `
|
|
90
|
+
(0, logger_1.log)(this.exportQueryConfig, `Failed to fetch extensions and Marketplace apps: ${error.message}`, 'error');
|
|
91
91
|
return { extensions: extensionUIDs, marketplaceApps: [] };
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -26,7 +26,7 @@ class QueryParser {
|
|
|
26
26
|
return JSON.parse(content);
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
throw new cli_utilities_1.CLIError(`Failed to parse query file: ${error.message}`);
|
|
29
|
+
throw new cli_utilities_1.CLIError(`Failed to parse the query file: ${error.message}`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
parseFromString(queryString) {
|
|
@@ -39,14 +39,14 @@ class QueryParser {
|
|
|
39
39
|
}
|
|
40
40
|
validate(query) {
|
|
41
41
|
if (!query || typeof query !== 'object') {
|
|
42
|
-
throw new cli_utilities_1.CLIError('
|
|
42
|
+
throw new cli_utilities_1.CLIError('The query must be a valid JSON object.');
|
|
43
43
|
}
|
|
44
44
|
if (!query.modules || typeof query.modules !== 'object') {
|
|
45
|
-
throw new cli_utilities_1.CLIError('
|
|
45
|
+
throw new cli_utilities_1.CLIError('The query must contain a "modules" object.');
|
|
46
46
|
}
|
|
47
47
|
const modules = Object.keys(query.modules);
|
|
48
48
|
if (modules.length === 0) {
|
|
49
|
-
throw new cli_utilities_1.CLIError('
|
|
49
|
+
throw new cli_utilities_1.CLIError('The query must contain at least one module.');
|
|
50
50
|
}
|
|
51
51
|
// Validate supported modules
|
|
52
52
|
const queryableModules = this.config.modules.queryable;
|
|
@@ -37,7 +37,7 @@ class AssetReferenceHandler {
|
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
(0, logger_1.log)(this.exportQueryConfig, `
|
|
40
|
+
(0, logger_1.log)(this.exportQueryConfig, `Failed to extract assets: ${error.message}`, 'error');
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -66,7 +66,7 @@ class AssetReferenceHandler {
|
|
|
66
66
|
return entriesCount;
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
69
|
-
(0, logger_1.log)(this.exportQueryConfig, `
|
|
69
|
+
(0, logger_1.log)(this.exportQueryConfig, `Failed to process file ${filePath}: ${error.message}`, 'warn');
|
|
70
70
|
return 0;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -123,7 +123,7 @@ class AssetReferenceHandler {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
catch (error) {
|
|
126
|
-
(0, logger_1.log)(this.exportQueryConfig, `
|
|
126
|
+
(0, logger_1.log)(this.exportQueryConfig, `Failed to read directory ${dir}: ${error.message}`, 'warn');
|
|
127
127
|
}
|
|
128
128
|
return jsonFiles;
|
|
129
129
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -45,11 +45,24 @@
|
|
|
45
45
|
},
|
|
46
46
|
"branch": {
|
|
47
47
|
"description": "Branch name to export from",
|
|
48
|
+
"exclusive": [
|
|
49
|
+
"branch-alias"
|
|
50
|
+
],
|
|
48
51
|
"name": "branch",
|
|
49
52
|
"hasDynamicHelp": false,
|
|
50
53
|
"multiple": false,
|
|
51
54
|
"type": "option"
|
|
52
55
|
},
|
|
56
|
+
"branch-alias": {
|
|
57
|
+
"description": "Alias of Branch to export from",
|
|
58
|
+
"exclusive": [
|
|
59
|
+
"branch"
|
|
60
|
+
],
|
|
61
|
+
"name": "branch-alias",
|
|
62
|
+
"hasDynamicHelp": false,
|
|
63
|
+
"multiple": false,
|
|
64
|
+
"type": "option"
|
|
65
|
+
},
|
|
53
66
|
"query": {
|
|
54
67
|
"description": "Query as JSON string or file path",
|
|
55
68
|
"name": "query",
|
|
@@ -102,5 +115,5 @@
|
|
|
102
115
|
]
|
|
103
116
|
}
|
|
104
117
|
},
|
|
105
|
-
"version": "1.0.0-beta.
|
|
118
|
+
"version": "1.0.0-beta.5"
|
|
106
119
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export-query",
|
|
3
3
|
"description": "Contentstack CLI plugin to export content from stack",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.5",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-export": "~1.
|
|
9
|
-
"@contentstack/cli-command": "~1.6.
|
|
10
|
-
"@contentstack/cli-utilities": "~1.
|
|
8
|
+
"@contentstack/cli-cm-export": "~1.20.2",
|
|
9
|
+
"@contentstack/cli-command": "~1.6.1",
|
|
10
|
+
"@contentstack/cli-utilities": "~1.14.1",
|
|
11
11
|
"@oclif/core": "^4.3.0",
|
|
12
12
|
"async": "^3.2.6",
|
|
13
13
|
"big-json": "^3.2.0",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"winston": "^3.17.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@contentstack/cli-dev-dependencies": "~1.3.
|
|
25
|
-
"@oclif/plugin-help": "^6.2.
|
|
26
|
-
"@oclif/test": "^4.1.
|
|
24
|
+
"@contentstack/cli-dev-dependencies": "~1.3.1",
|
|
25
|
+
"@oclif/plugin-help": "^6.2.33",
|
|
26
|
+
"@oclif/test": "^4.1.14",
|
|
27
27
|
"@types/big-json": "^3.2.5",
|
|
28
28
|
"@types/chai": "^4.3.20",
|
|
29
29
|
"@types/mkdirp": "^1.0.2",
|
|
30
30
|
"@types/mocha": "^10.0.10",
|
|
31
|
-
"@types/node": "^20.19.
|
|
31
|
+
"@types/node": "^20.19.17",
|
|
32
32
|
"@types/progress-stream": "^2.0.5",
|
|
33
33
|
"@types/sinon": "^17.0.4",
|
|
34
34
|
"chai": "^4.5.0",
|
|
35
|
-
"dotenv": "^16.
|
|
35
|
+
"dotenv": "^16.6.1",
|
|
36
36
|
"dotenv-expand": "^9.0.0",
|
|
37
37
|
"eslint": "^8.57.1",
|
|
38
|
-
"eslint-config-oclif": "^6.0.
|
|
38
|
+
"eslint-config-oclif": "^6.0.104",
|
|
39
39
|
"husky": "^9.1.7",
|
|
40
40
|
"mocha": "10.8.2",
|
|
41
41
|
"nyc": "^15.1.0",
|