@contentstack/cli-cm-import 2.0.0-beta.14 → 2.0.0-beta.16
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/import.js +2 -2
- package/lib/config/index.js +34 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/import/modules/assets.d.ts +5 -0
- package/lib/import/modules/assets.js +54 -3
- package/lib/import/modules/base-class.js +1 -1
- package/lib/import/modules/content-types.js +2 -2
- package/lib/import/modules/stack.js +8 -0
- package/lib/types/default-config.d.ts +18 -0
- package/lib/types/import-config.d.ts +2 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/backup-handler.js +2 -2
- package/lib/utils/build-import-spaces-options.d.ts +7 -0
- package/lib/utils/build-import-spaces-options.js +41 -0
- package/lib/utils/import-config-handler.js +29 -2
- package/lib/utils/import-path-resolver.d.ts +0 -8
- package/lib/utils/import-path-resolver.js +4 -73
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +3 -2
- package/oclif.manifest.json +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import/2.0.0-beta.
|
|
50
|
+
@contentstack/cli-cm-import/2.0.0-beta.16 linux-x64 node-v22.22.2
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -16,7 +16,7 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
16
16
|
const { flags } = await this.parse(ImportCommand);
|
|
17
17
|
importConfig = await (0, utils_1.setupImportConfig)(flags);
|
|
18
18
|
// Prepare the context object
|
|
19
|
-
(0, cli_utilities_1.createLogContext)(((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'cm:stacks:
|
|
19
|
+
(0, cli_utilities_1.createLogContext)(((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'cm:stacks:import', importConfig.apiKey, importConfig.authenticationMethod);
|
|
20
20
|
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
|
|
21
21
|
importConfig.context = Object.assign({}, context);
|
|
22
22
|
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);
|
|
@@ -37,7 +37,7 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
37
37
|
cli_utilities_1.CLIProgressManager.initializeGlobalSummary(`IMPORT`, flags.branch, 'Importing content...');
|
|
38
38
|
}
|
|
39
39
|
const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
|
|
40
|
-
|
|
40
|
+
await moduleImporter.start();
|
|
41
41
|
backupDir = importConfig.backupDir;
|
|
42
42
|
//Note: Final summary is now handled by summary manager
|
|
43
43
|
cli_utilities_1.CLIProgressManager.printGlobalSummary();
|
package/lib/config/index.js
CHANGED
|
@@ -101,6 +101,40 @@ const config = {
|
|
|
101
101
|
folderValidKeys: ['name', 'parent_uid'],
|
|
102
102
|
validKeys: ['title', 'parent_uid', 'description', 'tags'],
|
|
103
103
|
},
|
|
104
|
+
'asset-management': {
|
|
105
|
+
dirName: 'spaces',
|
|
106
|
+
fieldsDir: 'fields',
|
|
107
|
+
assetTypesDir: 'asset_types',
|
|
108
|
+
fieldsFileName: 'fields.json',
|
|
109
|
+
assetTypesFileName: 'asset-types.json',
|
|
110
|
+
foldersFileName: 'folders.json',
|
|
111
|
+
assetsFileName: 'assets.json',
|
|
112
|
+
fieldsImportInvalidKeys: [
|
|
113
|
+
'created_at',
|
|
114
|
+
'created_by',
|
|
115
|
+
'updated_at',
|
|
116
|
+
'updated_by',
|
|
117
|
+
'is_system',
|
|
118
|
+
'asset_types_count',
|
|
119
|
+
],
|
|
120
|
+
assetTypesImportInvalidKeys: [
|
|
121
|
+
'created_at',
|
|
122
|
+
'created_by',
|
|
123
|
+
'updated_at',
|
|
124
|
+
'updated_by',
|
|
125
|
+
'is_system',
|
|
126
|
+
'category',
|
|
127
|
+
'preview_image_url',
|
|
128
|
+
'category_detail',
|
|
129
|
+
],
|
|
130
|
+
mapperRootDir: 'mapper',
|
|
131
|
+
mapperAssetsModuleDir: 'assets',
|
|
132
|
+
mapperUidFileName: 'uid-mapping.json',
|
|
133
|
+
mapperUrlFileName: 'url-mapping.json',
|
|
134
|
+
mapperSpaceUidFileName: 'space-uid-mapping.json',
|
|
135
|
+
uploadAssetsConcurrency: 2,
|
|
136
|
+
importFoldersConcurrency: 1,
|
|
137
|
+
},
|
|
104
138
|
'assets-old': {
|
|
105
139
|
dirName: 'assets',
|
|
106
140
|
fileName: 'assets.json',
|
package/lib/constants/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare const PATH_CONSTANTS: {
|
|
|
19
19
|
readonly INDEX: "index.json";
|
|
20
20
|
readonly FOLDER_MAPPING: "folder-mapping.json";
|
|
21
21
|
readonly VERSIONED_ASSETS: "versioned-assets.json";
|
|
22
|
+
readonly SPACE_UID_MAPPING: "space-uid-mapping.json";
|
|
22
23
|
};
|
|
23
24
|
/** Module subdirectory names within mapper */
|
|
24
25
|
readonly MAPPER_MODULES: {
|
package/lib/constants/index.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.PATH_CONSTANTS = {
|
|
|
22
22
|
INDEX: 'index.json',
|
|
23
23
|
FOLDER_MAPPING: 'folder-mapping.json',
|
|
24
24
|
VERSIONED_ASSETS: 'versioned-assets.json',
|
|
25
|
+
SPACE_UID_MAPPING: 'space-uid-mapping.json',
|
|
25
26
|
},
|
|
26
27
|
/** Module subdirectory names within mapper */
|
|
27
28
|
MAPPER_MODULES: {
|
|
@@ -32,6 +32,11 @@ export default class ImportAssets extends BaseClass {
|
|
|
32
32
|
* @returns {Promise<void>} Promise<any>
|
|
33
33
|
*/
|
|
34
34
|
start(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Merges imported AM spaces into the target stack branch's `am_v2.linked_workspaces`.
|
|
37
|
+
* Errors are logged and swallowed so a successful import still completes; import failures are handled separately.
|
|
38
|
+
*/
|
|
39
|
+
private linkImportedAmSpacesToBranch;
|
|
35
40
|
/**
|
|
36
41
|
* @method importFolders
|
|
37
42
|
* @returns {Promise<any>} Promise<any>
|
|
@@ -13,6 +13,7 @@ const includes_1 = tslib_1.__importDefault(require("lodash/includes"));
|
|
|
13
13
|
const uuid_1 = require("uuid");
|
|
14
14
|
const node_path_1 = require("node:path");
|
|
15
15
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
16
|
+
const cli_asset_management_1 = require("@contentstack/cli-asset-management");
|
|
16
17
|
const constants_1 = require("../../constants");
|
|
17
18
|
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
18
19
|
const utils_1 = require("../../utils");
|
|
@@ -41,8 +42,31 @@ class ImportAssets extends base_class_1.default {
|
|
|
41
42
|
* @returns {Promise<void>} Promise<any>
|
|
42
43
|
*/
|
|
43
44
|
async start() {
|
|
45
|
+
var _a;
|
|
44
46
|
try {
|
|
45
47
|
cli_utilities_1.log.debug('Starting assets import process...', this.importConfig.context);
|
|
48
|
+
// AM 2.0: assetManagementEnabled is set in the config handler when spaces/ + am_v2 are detected.
|
|
49
|
+
if (this.importConfig.assetManagementEnabled) {
|
|
50
|
+
if (!this.importConfig.assetManagementUrl) {
|
|
51
|
+
cli_utilities_1.log.info('AM 2.0 export detected but assetManagementUrl is not configured in the region settings. Skipping AM 2.0 asset import.', this.importConfig.context);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
55
|
+
let spaceMappings = [];
|
|
56
|
+
try {
|
|
57
|
+
const importer = new cli_asset_management_1.ImportSpaces((0, utils_1.buildImportSpacesOptions)(this.importConfig, this.importConfig.assetManagementUrl));
|
|
58
|
+
importer.setParentProgressManager(progress);
|
|
59
|
+
({ spaceMappings } = await importer.start());
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.completeProgress(false, (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 'AM 2.0 asset import failed');
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
await this.linkImportedAmSpacesToBranch(spaceMappings);
|
|
66
|
+
this.completeProgressWithMessage();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Legacy flow continues below
|
|
46
70
|
// Step 1: Analyze import data
|
|
47
71
|
const [foldersCount, assetsCount, versionedAssetsCount, publishableAssetsCount] = await this.withLoadingSpinner('ASSETS: Analyzing import data...', () => this.analyzeImportData());
|
|
48
72
|
// Step 2: Initialize progress tracking
|
|
@@ -74,6 +98,35 @@ class ImportAssets extends base_class_1.default {
|
|
|
74
98
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
75
99
|
}
|
|
76
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Merges imported AM spaces into the target stack branch's `am_v2.linked_workspaces`.
|
|
103
|
+
* Errors are logged and swallowed so a successful import still completes; import failures are handled separately.
|
|
104
|
+
*/
|
|
105
|
+
async linkImportedAmSpacesToBranch(spaceMappings) {
|
|
106
|
+
var _a, _b, _c, _d;
|
|
107
|
+
if (spaceMappings.length === 0) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const branchUid = (_a = this.importConfig.branchName) !== null && _a !== void 0 ? _a : 'main';
|
|
112
|
+
const branchData = (await this.stack.branch(branchUid).fetch({ include_settings: true }));
|
|
113
|
+
const currentLinked = ((_d = (_c = (_b = branchData === null || branchData === void 0 ? void 0 : branchData.settings) === null || _b === void 0 ? void 0 : _b.am_v2) === null || _c === void 0 ? void 0 : _c.linked_workspaces) !== null && _d !== void 0 ? _d : []);
|
|
114
|
+
const newWorkspaces = spaceMappings.map(({ newSpaceUid, workspaceUid }) => ({
|
|
115
|
+
uid: workspaceUid,
|
|
116
|
+
space_uid: newSpaceUid,
|
|
117
|
+
is_default: false,
|
|
118
|
+
operation: 'LINK',
|
|
119
|
+
}));
|
|
120
|
+
const combinedWorkspaces = [...currentLinked, ...newWorkspaces];
|
|
121
|
+
await this.stack.branch(branchUid).updateSettings({
|
|
122
|
+
branch: { settings: { am_v2: { linked_workspaces: combinedWorkspaces } } },
|
|
123
|
+
});
|
|
124
|
+
cli_utilities_1.log.success(`Linked ${newWorkspaces.length} space(s) to branch "${branchUid}"`, this.importConfig.context);
|
|
125
|
+
}
|
|
126
|
+
catch (linkErr) {
|
|
127
|
+
(0, cli_utilities_1.handleAndLogError)(linkErr, Object.assign(Object.assign({}, this.importConfig.context), { phase: 'AM 2.0 branch linking (linked_workspaces)' }));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
77
130
|
/**
|
|
78
131
|
* @method importFolders
|
|
79
132
|
* @returns {Promise<any>} Promise<any>
|
|
@@ -142,9 +195,7 @@ class ImportAssets extends base_class_1.default {
|
|
|
142
195
|
*/
|
|
143
196
|
async importAssets(isVersion = false) {
|
|
144
197
|
const processName = isVersion ? 'import versioned assets' : 'import assets';
|
|
145
|
-
const indexFileName = isVersion
|
|
146
|
-
? constants_1.PATH_CONSTANTS.FILES.VERSIONED_ASSETS
|
|
147
|
-
: this.assetConfig.fileName;
|
|
198
|
+
const indexFileName = isVersion ? constants_1.PATH_CONSTANTS.FILES.VERSIONED_ASSETS : this.assetConfig.fileName;
|
|
148
199
|
const basePath = isVersion ? (0, node_path_1.join)(this.assetsPath, 'versions') : this.assetsPath;
|
|
149
200
|
const progressProcessName = isVersion ? utils_1.PROCESS_NAMES.ASSET_VERSIONS : utils_1.PROCESS_NAMES.ASSET_UPLOAD;
|
|
150
201
|
cli_utilities_1.log.debug(`Importing ${processName} from ${basePath}`, this.importConfig.context);
|
|
@@ -109,7 +109,7 @@ class BaseClass {
|
|
|
109
109
|
* @returns {Promise} Promise<void>
|
|
110
110
|
*/
|
|
111
111
|
makeConcurrentCall(env, promisifyHandler, logBatchCompletionMsg = true) {
|
|
112
|
-
const { apiParams, apiContent, processName, indexerCount, currentIndexer, concurrencyLimit = this.importConfig.
|
|
112
|
+
const { apiParams, apiContent, processName, indexerCount, currentIndexer, concurrencyLimit = this.importConfig.fetchConcurrency, } = env;
|
|
113
113
|
/* eslint-disable no-async-promise-executor */
|
|
114
114
|
return new Promise(async (resolve) => {
|
|
115
115
|
let batchNo = 0;
|
|
@@ -53,8 +53,8 @@ class ContentTypesImport extends base_class_1.default {
|
|
|
53
53
|
this.createdGFs = [];
|
|
54
54
|
this.pendingGFs = [];
|
|
55
55
|
this.pendingExts = [];
|
|
56
|
-
this.taxonomiesPath = path.join((0, cli_utilities_1.sanitizePath)(importConfig.
|
|
57
|
-
this.extPendingPath = path.join((0, cli_utilities_1.sanitizePath)(importConfig.
|
|
56
|
+
this.taxonomiesPath = path.join((0, cli_utilities_1.sanitizePath)(importConfig.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.TAXONOMIES, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
|
|
57
|
+
this.extPendingPath = path.join((0, cli_utilities_1.sanitizePath)(importConfig.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.EXTENSIONS, constants_1.PATH_CONSTANTS.FILES.PENDING_EXTENSIONS);
|
|
58
58
|
}
|
|
59
59
|
async start() {
|
|
60
60
|
var _a;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
5
6
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
7
|
const constants_1 = require("../../constants");
|
|
7
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
@@ -46,6 +47,13 @@ class ImportStack extends base_class_1.default {
|
|
|
46
47
|
async importStackSettings() {
|
|
47
48
|
var _a, _b, _c;
|
|
48
49
|
cli_utilities_1.log.debug('Processing stack settings for import', this.importConfig.context);
|
|
50
|
+
// Old source-org space UIDs must not be written to the target stack —
|
|
51
|
+
// the asset-management module will apply the correct am_v2.linked_workspaces.
|
|
52
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(this.importConfig.contentDir, 'spaces'))) {
|
|
53
|
+
const _d = this.stackSettings, { am_v2 } = _d, settingsWithoutAm = tslib_1.__rest(_d, ["am_v2"]);
|
|
54
|
+
this.stackSettings = settingsWithoutAm;
|
|
55
|
+
cli_utilities_1.log.debug('Stripped am_v2 from stack settings; asset-management module will apply it after space creation', this.importConfig.context);
|
|
56
|
+
}
|
|
49
57
|
// Update environment UID mapping if live preview is configured
|
|
50
58
|
if (((_a = this.stackSettings) === null || _a === void 0 ? void 0 : _a.live_preview) && ((_b = this.stackSettings) === null || _b === void 0 ? void 0 : _b.live_preview['default-env']) !== undefined) {
|
|
51
59
|
const oldEnvUid = this.stackSettings.live_preview['default-env'];
|
|
@@ -70,6 +70,24 @@ export default interface DefaultConfig {
|
|
|
70
70
|
uploadAssetsConcurrency: number;
|
|
71
71
|
importFoldersConcurrency: number;
|
|
72
72
|
};
|
|
73
|
+
'asset-management': {
|
|
74
|
+
dirName: string;
|
|
75
|
+
fieldsDir: string;
|
|
76
|
+
assetTypesDir: string;
|
|
77
|
+
fieldsFileName: string;
|
|
78
|
+
assetTypesFileName: string;
|
|
79
|
+
foldersFileName: string;
|
|
80
|
+
assetsFileName: string;
|
|
81
|
+
fieldsImportInvalidKeys: string[];
|
|
82
|
+
assetTypesImportInvalidKeys: string[];
|
|
83
|
+
mapperRootDir: string;
|
|
84
|
+
mapperAssetsModuleDir: string;
|
|
85
|
+
mapperUidFileName: string;
|
|
86
|
+
mapperUrlFileName: string;
|
|
87
|
+
mapperSpaceUidFileName: string;
|
|
88
|
+
uploadAssetsConcurrency: number;
|
|
89
|
+
importFoldersConcurrency: number;
|
|
90
|
+
};
|
|
73
91
|
content_types: {
|
|
74
92
|
dirName: string;
|
|
75
93
|
fileName: string;
|
|
@@ -26,7 +26,6 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
|
26
26
|
contentTypes?: string[];
|
|
27
27
|
branches?: branch[];
|
|
28
28
|
branchEnabled?: boolean;
|
|
29
|
-
branchDir?: string;
|
|
30
29
|
branchAlias?: string;
|
|
31
30
|
moduleName?: Modules;
|
|
32
31
|
master_locale: masterLocale;
|
|
@@ -56,6 +55,8 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
|
56
55
|
personalizeProjectName?: string;
|
|
57
56
|
'exclude-global-modules': false;
|
|
58
57
|
context: Context;
|
|
58
|
+
assetManagementUrl?: string;
|
|
59
|
+
assetManagementEnabled?: boolean;
|
|
59
60
|
}
|
|
60
61
|
type branch = {
|
|
61
62
|
uid: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ async function backupHandler(importConfig) {
|
|
|
11
11
|
cli_utilities_1.log.debug(`Using existing backup directory: ${importConfig.useBackedupDir}`);
|
|
12
12
|
return importConfig.useBackedupDir;
|
|
13
13
|
}
|
|
14
|
-
const sourceDir = importConfig.
|
|
15
|
-
cli_utilities_1.log.debug(`Using source directory for backup: ${sourceDir}
|
|
14
|
+
const sourceDir = importConfig.contentDir;
|
|
15
|
+
cli_utilities_1.log.debug(`Using source directory for backup: ${sourceDir}, contentDir: ${importConfig.contentDir})`);
|
|
16
16
|
let backupDirPath;
|
|
17
17
|
const subDir = isSubDirectory(importConfig, sourceDir);
|
|
18
18
|
if (subDir) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ImportSpacesOptions } from '@contentstack/cli-asset-management';
|
|
2
|
+
import type ImportConfig from '../types/import-config';
|
|
3
|
+
/**
|
|
4
|
+
* Maps stack `ImportConfig` and AM base URL into a single `ImportSpacesOptions` for the AM package
|
|
5
|
+
* (variants-style: one flat object; `ImportSpaces` splits API vs context internally).
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildImportSpacesOptions(importConfig: ImportConfig, assetManagementUrl: string): ImportSpacesOptions;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildImportSpacesOptions = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
/**
|
|
6
|
+
* Maps stack `ImportConfig` and AM base URL into a single `ImportSpacesOptions` for the AM package
|
|
7
|
+
* (variants-style: one flat object; `ImportSpaces` splits API vs context internally).
|
|
8
|
+
*/
|
|
9
|
+
function buildImportSpacesOptions(importConfig, assetManagementUrl) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
const am = importConfig.modules['asset-management'];
|
|
12
|
+
const org_uid = (_a = importConfig.org_uid) !== null && _a !== void 0 ? _a : '';
|
|
13
|
+
return {
|
|
14
|
+
contentDir: importConfig.contentDir,
|
|
15
|
+
assetManagementUrl,
|
|
16
|
+
org_uid,
|
|
17
|
+
apiKey: importConfig.apiKey,
|
|
18
|
+
host: (_d = (_c = (_b = importConfig.region) === null || _b === void 0 ? void 0 : _b.cma) !== null && _c !== void 0 ? _c : importConfig.host) !== null && _d !== void 0 ? _d : '',
|
|
19
|
+
sourceApiKey: importConfig.source_stack,
|
|
20
|
+
context: importConfig.context,
|
|
21
|
+
backupDir: importConfig.backupDir,
|
|
22
|
+
apiConcurrency: importConfig.fetchConcurrency,
|
|
23
|
+
uploadAssetsConcurrency: am === null || am === void 0 ? void 0 : am.uploadAssetsConcurrency,
|
|
24
|
+
importFoldersConcurrency: am === null || am === void 0 ? void 0 : am.importFoldersConcurrency,
|
|
25
|
+
spacesDirName: am === null || am === void 0 ? void 0 : am.dirName,
|
|
26
|
+
fieldsDir: am === null || am === void 0 ? void 0 : am.fieldsDir,
|
|
27
|
+
assetTypesDir: am === null || am === void 0 ? void 0 : am.assetTypesDir,
|
|
28
|
+
fieldsFileName: am === null || am === void 0 ? void 0 : am.fieldsFileName,
|
|
29
|
+
assetTypesFileName: am === null || am === void 0 ? void 0 : am.assetTypesFileName,
|
|
30
|
+
foldersFileName: am === null || am === void 0 ? void 0 : am.foldersFileName,
|
|
31
|
+
assetsFileName: am === null || am === void 0 ? void 0 : am.assetsFileName,
|
|
32
|
+
fieldsImportInvalidKeys: am === null || am === void 0 ? void 0 : am.fieldsImportInvalidKeys,
|
|
33
|
+
assetTypesImportInvalidKeys: am === null || am === void 0 ? void 0 : am.assetTypesImportInvalidKeys,
|
|
34
|
+
mapperRootDir: (_e = am === null || am === void 0 ? void 0 : am.mapperRootDir) !== null && _e !== void 0 ? _e : constants_1.PATH_CONSTANTS.MAPPER,
|
|
35
|
+
mapperAssetsModuleDir: (_f = am === null || am === void 0 ? void 0 : am.mapperAssetsModuleDir) !== null && _f !== void 0 ? _f : constants_1.PATH_CONSTANTS.MAPPER_MODULES.ASSETS,
|
|
36
|
+
mapperUidFileName: (_g = am === null || am === void 0 ? void 0 : am.mapperUidFileName) !== null && _g !== void 0 ? _g : constants_1.PATH_CONSTANTS.FILES.UID_MAPPING,
|
|
37
|
+
mapperUrlFileName: (_h = am === null || am === void 0 ? void 0 : am.mapperUrlFileName) !== null && _h !== void 0 ? _h : constants_1.PATH_CONSTANTS.FILES.URL_MAPPING,
|
|
38
|
+
mapperSpaceUidFileName: (_j = am === null || am === void 0 ? void 0 : am.mapperSpaceUidFileName) !== null && _j !== void 0 ? _j : constants_1.PATH_CONSTANTS.FILES.SPACE_UID_MAPPING,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.buildImportSpacesOptions = buildImportSpacesOptions;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const merge_1 = tslib_1.__importDefault(require("merge"));
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
6
7
|
const lodash_1 = require("lodash");
|
|
7
8
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
9
|
const config_1 = tslib_1.__importDefault(require("../config"));
|
|
@@ -10,7 +11,7 @@ const file_helper_1 = require("./file-helper");
|
|
|
10
11
|
const interactive_1 = require("./interactive");
|
|
11
12
|
const login_handler_1 = tslib_1.__importDefault(require("./login-handler"));
|
|
12
13
|
const setupConfig = async (importCmdFlags) => {
|
|
13
|
-
var _a;
|
|
14
|
+
var _a, _b, _c;
|
|
14
15
|
// Set progress supported module FIRST, before any log calls
|
|
15
16
|
// This ensures the logger respects the showConsoleLogs setting correctly
|
|
16
17
|
cli_utilities_1.configHandler.set('log.progressSupportedModule', 'import');
|
|
@@ -88,7 +89,6 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
88
89
|
}
|
|
89
90
|
if (importCmdFlags['branch']) {
|
|
90
91
|
config.branchName = importCmdFlags['branch'];
|
|
91
|
-
config.branchDir = config.contentDir;
|
|
92
92
|
}
|
|
93
93
|
if (importCmdFlags['module']) {
|
|
94
94
|
config.moduleName = importCmdFlags['module'];
|
|
@@ -109,6 +109,33 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
109
109
|
if (importCmdFlags['exclude-global-modules']) {
|
|
110
110
|
config['exclude-global-modules'] = importCmdFlags['exclude-global-modules'];
|
|
111
111
|
}
|
|
112
|
+
const spacesDir = path.join(config.contentDir, 'spaces');
|
|
113
|
+
const stackSettingsPath = path.join(config.contentDir, 'stack', 'settings.json');
|
|
114
|
+
const stackJsonPath = path.join(config.contentDir, 'stack', 'stack.json');
|
|
115
|
+
if ((0, node_fs_1.existsSync)(spacesDir) && (0, node_fs_1.existsSync)(stackSettingsPath)) {
|
|
116
|
+
try {
|
|
117
|
+
const stackSettings = JSON.parse((0, node_fs_1.readFileSync)(stackSettingsPath, 'utf8'));
|
|
118
|
+
if (stackSettings === null || stackSettings === void 0 ? void 0 : stackSettings.am_v2) {
|
|
119
|
+
config.assetManagementEnabled = true;
|
|
120
|
+
config.assetManagementUrl = (_b = cli_utilities_1.configHandler.get('region')) === null || _b === void 0 ? void 0 : _b.assetManagementUrl;
|
|
121
|
+
if ((0, node_fs_1.existsSync)(stackJsonPath)) {
|
|
122
|
+
try {
|
|
123
|
+
const stackData = JSON.parse((0, node_fs_1.readFileSync)(stackJsonPath, 'utf8'));
|
|
124
|
+
const apiKey = (stackData === null || stackData === void 0 ? void 0 : stackData.api_key) || ((_c = stackData === null || stackData === void 0 ? void 0 : stackData.stackHeaders) === null || _c === void 0 ? void 0 : _c.api_key);
|
|
125
|
+
if (apiKey) {
|
|
126
|
+
config.source_stack = apiKey;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (_d) {
|
|
130
|
+
// stack.json unreadable — source stack API key will not be set
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (_e) {
|
|
136
|
+
// stack settings unreadable — not an AM 2.0 export we can process
|
|
137
|
+
}
|
|
138
|
+
}
|
|
112
139
|
// Add authentication details to config for context tracking
|
|
113
140
|
config.authenticationMethod = authenticationMethod;
|
|
114
141
|
cli_utilities_1.log.debug('Import configuration setup completed.', Object.assign({}, config));
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { ImportConfig } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Selects a branch from directory structure when multiple branches are found
|
|
4
|
-
* @param contentDir - The content directory path
|
|
5
|
-
* @returns Promise<{ branchPath: string } | null>
|
|
6
|
-
*/
|
|
7
|
-
export declare const selectBranchFromDirectory: (contentDir: string) => Promise<{
|
|
8
|
-
branchPath: string;
|
|
9
|
-
} | null>;
|
|
10
2
|
/**
|
|
11
3
|
* Resolves the import path based on directory structure and user configuration
|
|
12
4
|
* @param importConfig - The import configuration object
|
|
@@ -1,60 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath =
|
|
3
|
+
exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
5
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
6
6
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
7
|
const config_1 = tslib_1.__importDefault(require("../config"));
|
|
8
|
-
const interactive_1 = require("./interactive");
|
|
9
8
|
const file_helper_1 = require("./file-helper");
|
|
10
|
-
/**
|
|
11
|
-
* Selects a branch from directory structure when multiple branches are found
|
|
12
|
-
* @param contentDir - The content directory path
|
|
13
|
-
* @returns Promise<{ branchPath: string } | null>
|
|
14
|
-
*/
|
|
15
|
-
const selectBranchFromDirectory = async (contentDir) => {
|
|
16
|
-
cli_utilities_1.log.debug('Selecting branch directory from directory structure');
|
|
17
|
-
const branchesJsonPath = path.join(contentDir, 'branches.json');
|
|
18
|
-
if (!(0, file_helper_1.fileExistsSync)(branchesJsonPath)) {
|
|
19
|
-
cli_utilities_1.log.debug('No branches.json found - not a branch-enabled export');
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const branchesData = await (0, file_helper_1.readFile)(branchesJsonPath);
|
|
24
|
-
const branches = branchesData || [];
|
|
25
|
-
if (!branches || !Array.isArray(branches) || branches.length === 0) {
|
|
26
|
-
cli_utilities_1.log.debug('No branches found in branches.json - not a branch-enabled export');
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
if (branches.length === 1) {
|
|
30
|
-
const singleBranch = branches[0];
|
|
31
|
-
const branchPath = path.join(contentDir, singleBranch.uid);
|
|
32
|
-
if (!(0, file_helper_1.fileExistsSync)(branchPath)) {
|
|
33
|
-
cli_utilities_1.log.warn(`Branch path does not exist: ${branchPath}, not a valid branch export`);
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
cli_utilities_1.log.debug(`Single branch detected: ${singleBranch.uid} - auto-resolving to: ${branchPath}`);
|
|
37
|
-
return { branchPath };
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
cli_utilities_1.log.debug(`Multiple branches detected: ${branches.map((b) => b.uid).join(', ')}`);
|
|
41
|
-
const branchNames = branches.map((b) => b.uid);
|
|
42
|
-
const selectedBranch = await (0, interactive_1.askBranchSelection)(branchNames);
|
|
43
|
-
const selectedBranchPath = path.join(contentDir, selectedBranch);
|
|
44
|
-
if (!(0, file_helper_1.fileExistsSync)(selectedBranchPath)) {
|
|
45
|
-
cli_utilities_1.log.warn(`Selected branch path does not exist: ${selectedBranchPath}, not a valid branch export`);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
cli_utilities_1.log.debug(`User selected branch directory: ${selectedBranch} - using path: ${selectedBranchPath}`);
|
|
49
|
-
return { branchPath: selectedBranchPath };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
cli_utilities_1.log.error(`Error selecting branch directory from directory structure: ${error}`);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.selectBranchFromDirectory = selectBranchFromDirectory;
|
|
58
9
|
/**
|
|
59
10
|
* Resolves the import path based on directory structure and user configuration
|
|
60
11
|
* @param importConfig - The import configuration object
|
|
@@ -68,31 +19,12 @@ const resolveImportPath = async (importConfig, stackAPIClient) => {
|
|
|
68
19
|
if (!(0, file_helper_1.fileExistsSync)(contentDir)) {
|
|
69
20
|
throw new Error(`Content directory does not exist: ${contentDir}`);
|
|
70
21
|
}
|
|
71
|
-
if (importConfig.branchName) {
|
|
72
|
-
cli_utilities_1.log.debug(`User specified branch: ${importConfig.branchName}`);
|
|
73
|
-
const currentDirName = path.basename(contentDir);
|
|
74
|
-
if (currentDirName === importConfig.branchName) {
|
|
75
|
-
cli_utilities_1.log.debug(`Already in correct branch directory: ${contentDir}`);
|
|
76
|
-
return contentDir;
|
|
77
|
-
}
|
|
78
|
-
const branchPath = path.join(contentDir, importConfig.branchName);
|
|
79
|
-
if ((0, file_helper_1.fileExistsSync)(branchPath)) {
|
|
80
|
-
cli_utilities_1.log.debug(`Navigating to specified branch directory: ${branchPath}`);
|
|
81
|
-
return branchPath;
|
|
82
|
-
}
|
|
83
|
-
cli_utilities_1.log.debug(`Branch directory not found: ${branchPath}, using contentDir as-is`);
|
|
84
|
-
return contentDir;
|
|
85
|
-
}
|
|
86
22
|
const moduleTypes = config_1.default.modules.types;
|
|
87
23
|
const hasModuleFolders = moduleTypes.some((moduleType) => (0, file_helper_1.fileExistsSync)(path.join(contentDir, moduleType)));
|
|
88
24
|
if (hasModuleFolders) {
|
|
89
|
-
cli_utilities_1.log.debug('Found module folders ');
|
|
25
|
+
cli_utilities_1.log.debug('Found module folders at export root');
|
|
90
26
|
return contentDir;
|
|
91
27
|
}
|
|
92
|
-
const branchSelection = await (0, exports.selectBranchFromDirectory)(contentDir);
|
|
93
|
-
if (branchSelection) {
|
|
94
|
-
return branchSelection.branchPath;
|
|
95
|
-
}
|
|
96
28
|
cli_utilities_1.log.debug('No specific structure detected - using contentDir as-is');
|
|
97
29
|
return contentDir;
|
|
98
30
|
};
|
|
@@ -108,9 +40,8 @@ const updateImportConfigWithResolvedPath = async (importConfig, resolvedPath) =>
|
|
|
108
40
|
cli_utilities_1.log.warn(`Resolved path does not exist: ${resolvedPath}, skipping config update`);
|
|
109
41
|
return;
|
|
110
42
|
}
|
|
111
|
-
importConfig.branchDir = resolvedPath;
|
|
112
43
|
importConfig.contentDir = resolvedPath;
|
|
113
|
-
cli_utilities_1.log.debug(`Import config updated - contentDir: ${importConfig.contentDir}
|
|
44
|
+
cli_utilities_1.log.debug(`Import config updated - contentDir: ${importConfig.contentDir}`);
|
|
114
45
|
};
|
|
115
46
|
exports.updateImportConfigWithResolvedPath = updateImportConfigWithResolvedPath;
|
|
116
47
|
/**
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { setupBranchConfig } from './setup-branch';
|
|
2
|
-
export {
|
|
2
|
+
export { resolveImportPath, updateImportConfigWithResolvedPath, executeImportPathLogic } from './import-path-resolver';
|
|
3
3
|
export * as interactive from './interactive';
|
|
4
4
|
export { default as setupImportConfig } from './import-config-handler';
|
|
5
5
|
export * as fileHelper from './file-helper';
|
|
@@ -14,3 +14,4 @@ export { lookupEntries, removeUidsFromJsonRteFields, removeEntryRefsFromJSONRTE,
|
|
|
14
14
|
export * from './common-helper';
|
|
15
15
|
export { lookUpTaxonomy, lookUpTerms } from './taxonomies-helper';
|
|
16
16
|
export { MODULE_CONTEXTS, MODULE_NAMES, PROCESS_NAMES, PROCESS_STATUS } from './constants';
|
|
17
|
+
export { buildImportSpacesOptions } from './build-import-spaces-options';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PROCESS_STATUS = exports.PROCESS_NAMES = exports.MODULE_NAMES = exports.MODULE_CONTEXTS = exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath = exports.
|
|
3
|
+
exports.buildImportSpacesOptions = exports.PROCESS_STATUS = exports.PROCESS_NAMES = exports.MODULE_NAMES = exports.MODULE_CONTEXTS = exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = exports.executeImportPathLogic = exports.updateImportConfigWithResolvedPath = exports.resolveImportPath = exports.setupBranchConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var setup_branch_1 = require("./setup-branch");
|
|
6
6
|
Object.defineProperty(exports, "setupBranchConfig", { enumerable: true, get: function () { return setup_branch_1.setupBranchConfig; } });
|
|
7
7
|
var import_path_resolver_1 = require("./import-path-resolver");
|
|
8
|
-
Object.defineProperty(exports, "selectBranchFromDirectory", { enumerable: true, get: function () { return import_path_resolver_1.selectBranchFromDirectory; } });
|
|
9
8
|
Object.defineProperty(exports, "resolveImportPath", { enumerable: true, get: function () { return import_path_resolver_1.resolveImportPath; } });
|
|
10
9
|
Object.defineProperty(exports, "updateImportConfigWithResolvedPath", { enumerable: true, get: function () { return import_path_resolver_1.updateImportConfigWithResolvedPath; } });
|
|
11
10
|
Object.defineProperty(exports, "executeImportPathLogic", { enumerable: true, get: function () { return import_path_resolver_1.executeImportPathLogic; } });
|
|
@@ -52,3 +51,5 @@ Object.defineProperty(exports, "MODULE_CONTEXTS", { enumerable: true, get: funct
|
|
|
52
51
|
Object.defineProperty(exports, "MODULE_NAMES", { enumerable: true, get: function () { return constants_1.MODULE_NAMES; } });
|
|
53
52
|
Object.defineProperty(exports, "PROCESS_NAMES", { enumerable: true, get: function () { return constants_1.PROCESS_NAMES; } });
|
|
54
53
|
Object.defineProperty(exports, "PROCESS_STATUS", { enumerable: true, get: function () { return constants_1.PROCESS_STATUS; } });
|
|
54
|
+
var build_import_spaces_options_1 = require("./build-import-spaces-options");
|
|
55
|
+
Object.defineProperty(exports, "buildImportSpacesOptions", { enumerable: true, get: function () { return build_import_spaces_options_1.buildImportSpacesOptions; } });
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.16",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~2.0.0-beta.
|
|
9
|
-
"@contentstack/cli-command": "~2.0.0-beta.
|
|
10
|
-
"@contentstack/cli-utilities": "~2.0.0-beta.
|
|
11
|
-
"@contentstack/cli-variants": "~2.0.0-beta.
|
|
8
|
+
"@contentstack/cli-audit": "~2.0.0-beta.11",
|
|
9
|
+
"@contentstack/cli-command": "~2.0.0-beta.6",
|
|
10
|
+
"@contentstack/cli-utilities": "~2.0.0-beta.7",
|
|
11
|
+
"@contentstack/cli-variants": "~2.0.0-beta.12",
|
|
12
|
+
"@contentstack/cli-asset-management": "~1.0.0-beta.0",
|
|
12
13
|
"@oclif/core": "^4.3.0",
|
|
13
14
|
"big-json": "^3.2.0",
|
|
14
15
|
"bluebird": "^3.7.2",
|
|
15
16
|
"chalk": "^5.6.2",
|
|
16
17
|
"debug": "^4.4.3",
|
|
17
18
|
"fs-extra": "^11.3.3",
|
|
18
|
-
"lodash": "^4.
|
|
19
|
+
"lodash": "^4.18.1",
|
|
19
20
|
"marked": "^4.3.0",
|
|
20
21
|
"merge": "^2.1.1",
|
|
21
22
|
"mkdirp": "^1.0.4",
|
|
22
23
|
"promise-limit": "^2.7.0",
|
|
23
24
|
"uuid": "^9.0.1",
|
|
24
|
-
"winston": "^3.
|
|
25
|
+
"winston": "^3.19.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@oclif/test": "^4.1.
|
|
28
|
+
"@oclif/test": "^4.1.18",
|
|
28
29
|
"@types/big-json": "^3.2.5",
|
|
29
30
|
"@types/bluebird": "^3.5.42",
|
|
30
31
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -90,4 +91,4 @@
|
|
|
90
91
|
}
|
|
91
92
|
},
|
|
92
93
|
"repository": "https://github.com/contentstack/cli"
|
|
93
|
-
}
|
|
94
|
+
}
|