Skip to content

Commit 89b82a3

Browse files
committed
fix: stack clone & seed issue
1 parent 9d1fc18 commit 89b82a3

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

packages/contentstack-auth/src/base-command.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Command } from '@contentstack/cli-command';
2-
import { configHandler, Flags, Interfaces, LoggerService, log } from '@contentstack/cli-utilities';
2+
import { configHandler, Flags, Interfaces, log } from '@contentstack/cli-utilities';
33
import { Context } from './interfaces';
44

55
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
66
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
77

88
export abstract class BaseCommand<T extends typeof Command> extends Command {
9-
public logger!: LoggerService;
109
protected args!: Args<T>;
1110
protected flags!: Flags<T>;
1211
public contextDetails!: Context;
@@ -17,8 +16,6 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
1716
*/
1817
public async init(): Promise<void> {
1918
await super.init();
20-
// Init logger
21-
this.logger = new LoggerService(process.cwd(), 'cli-log');
2219
this.contextDetails = { ...this.createExportContext() };
2320
}
2421

@@ -51,11 +48,11 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
5148
// Create export context object
5249
protected createExportContext(apiKey?: string): Context {
5350
return {
54-
command: this.context.info.command,
51+
command: this.context?.info?.command || 'auth',
5552
module: '',
56-
userId: configHandler.get('userUid'),
57-
email: configHandler.get('email'),
58-
sessionId: this.context.sessionId,
53+
userId: configHandler.get('userUid') || '',
54+
email: configHandler.get('email') || '',
55+
sessionId: this.context?.sessionId,
5956
apiKey: apiKey || '',
6057
orgId: configHandler.get('oauthOrgUid') || '',
6158
};

packages/contentstack-export/src/commands/cm/stacks/export.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class ExportCommand extends Command {
118118
// Prepare the context object
119119
const context = this.createExportContext(exportConfig.apiKey, exportConfig.authenticationMethod);
120120
exportConfig.context = { ...context };
121-
log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);
121+
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);
122122

123123
// Assign exportConfig variables
124124
this.assignExportConfig(exportConfig);
@@ -145,11 +145,11 @@ export default class ExportCommand extends Command {
145145
// Create export context object
146146
private createExportContext(apiKey: string, authenticationMethod?: string): Context {
147147
return {
148-
command: this.context.info.command,
148+
command: this.context?.info?.command || 'cm:stacks:export',
149149
module: '',
150-
userId: configHandler.get('userUid'),
151-
email: configHandler.get('email'),
152-
sessionId: this.context.sessionId,
150+
userId: configHandler.get('userUid') || '',
151+
email: configHandler.get('email') || '',
152+
sessionId: this.context?.sessionId || '',
153153
apiKey: apiKey || '',
154154
orgId: configHandler.get('oauthOrgUid') || '',
155155
authenticationMethod: authenticationMethod || 'Basic Auth',

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,24 @@ export default class ImportCommand extends Command {
150150
// Prepare the context object
151151
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
152152
importConfig.context = {...context};
153-
log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);
153+
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);
154154

155155
// Note setting host to create cma client
156156
importConfig.host = this.cmaHost;
157157
importConfig.region = this.region;
158158
if (this.developerHubUrl) importConfig.developerHubBaseUrl = this.developerHubUrl;
159159
if (this.personalizeUrl) importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl;
160-
backupDir = importConfig.cliLogsPath || importConfig.backupDir;
161-
160+
162161
const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig);
163-
162+
164163
if (!flags.branch) {
165164
try {
166165
const branches = await managementAPIClient
167-
.stack({ api_key: importConfig.apiKey })
168-
.branch()
169-
.query()
170-
.find()
171-
.then(({ items }: any) => items);
166+
.stack({ api_key: importConfig.apiKey })
167+
.branch()
168+
.query()
169+
.find()
170+
.then(({ items }: any) => items);
172171
if (branches.length) {
173172
flags.branch = 'main';
174173
}
@@ -178,6 +177,7 @@ export default class ImportCommand extends Command {
178177
}
179178
const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
180179
const result = await moduleImporter.start();
180+
backupDir = importConfig.backupDir;
181181

182182
if (!result?.noSuccessMsg) {
183183
const successMessage = importConfig.stackName
@@ -187,20 +187,22 @@ export default class ImportCommand extends Command {
187187
}
188188

189189
log.success(`The log has been stored at '${getLogPath()}'`, importConfig.context)
190+
log.info(`The backup content has been stored at '${backupDir}'`, importConfig.context);
190191
} catch (error) {
191192
handleAndLogError(error);
192193
log.info(`The log has been stored at '${getLogPath()}'`)
194+
log.info(`The backup content has been stored at '${backupDir}'`);
193195
}
194196
}
195197

196198
// Create export context object
197199
private createImportContext(apiKey: string, authenticationMethod?: string): Context {
198200
return {
199-
command: this.context.info.command,
201+
command: this.context?.info?.command || 'cm:stacks:import',
200202
module: '',
201-
userId: configHandler.get('userUid'),
202-
email: configHandler.get('email'),
203-
sessionId: this.context.sessionId,
203+
userId: configHandler.get('userUid') || '',
204+
email: configHandler.get('email') || '',
205+
sessionId: this.context?.sessionId,
204206
apiKey: apiKey || '',
205207
orgId: configHandler.get('oauthOrgUid') || '',
206208
authenticationMethod: authenticationMethod || 'Basic Auth',

packages/contentstack-utilities/src/logger/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function handleAndLogError(error: unknown, context?: ErrorContext, errorMessage?
6161
}
6262

6363
function getLogPath(): string {
64-
return process.env.CS_CLI_LOG_PATH || configHandler.get('log.path') || path.join(process.cwd(), 'logs');
64+
return process.env.CS_CLI_LOG_PATH || configHandler.get('log.path') || path.join(__dirname, 'logs');
6565
}
6666

6767
export { v2Logger, cliErrorHandler, handleAndLogError, getLogPath };

0 commit comments

Comments
 (0)