Skip to content

Commit d51aecd

Browse files
committed
fix: Fix issue on init command
1 parent 6e8e341 commit d51aecd

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

packages/cli-core/src/services/CliService.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class CliService {
7575
}
7676
];
7777

78-
return createTasksRunner(tasks, ctx);
78+
return createTasksRunner(tasks, this.mapContext(cmdName, ctx));
7979
}
8080

8181
/**
@@ -113,15 +113,16 @@ export class CliService {
113113
const provider = this.commands.get(cmdName);
114114
const instance = this.injector.get<ICommand>(provider.useClass)!;
115115

116-
if (instance.$mapContext) {
117-
ctx = instance.$mapContext(ctx);
118-
}
116+
ctx = this.mapContext(cmdName, ctx);
119117

120118
if (instance.$beforeExec) {
121119
await instance.$beforeExec(ctx);
122120
}
123121

124-
return [...(await instance.$exec(ctx)), ...(await this.hooks.emit(CommandStoreKeys.EXEC_HOOKS, cmdName, ctx))];
122+
return [
123+
...(await instance.$exec(ctx)),
124+
...(await this.hooks.emit(CommandStoreKeys.EXEC_HOOKS, cmdName, ctx))
125+
];
125126
}
126127

127128
/**
@@ -171,6 +172,17 @@ export class CliService {
171172
});
172173
}
173174

175+
private mapContext(cmdName: string, ctx: any) {
176+
const provider = this.commands.get(cmdName);
177+
const instance = this.injector.get<ICommand>(provider.useClass)!;
178+
179+
if (instance.$mapContext) {
180+
ctx = instance.$mapContext(JSON.parse(JSON.stringify(ctx)));
181+
}
182+
183+
return ctx;
184+
}
185+
174186
/**
175187
* Build command and sub-commands
176188
* @param provider

packages/cli-core/src/services/Renderer.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ export class RootRendererService extends Renderer {
7171
return this.configuration.templateDir;
7272
}
7373

74-
set templateDir(path: string) {}
74+
set templateDir(path: string) {
75+
}
7576

7677
get rootDir() {
7778
return this.configuration.project?.rootDir;
7879
}
7980

80-
set rootDir(path: string) {}
81+
set rootDir(path: string) {
82+
}
8183
}
8284

8385
@Injectable()
@@ -89,13 +91,15 @@ export class SrcRendererService extends Renderer {
8991
return this.configuration.templateDir;
9092
}
9193

92-
set templateDir(path: string) {}
94+
set templateDir(path: string) {
95+
}
9396

9497
get rootDir() {
9598
return join(...[this.configuration.project?.rootDir, this.configuration.project?.srcDir].filter(Boolean));
9699
}
97100

98-
set rootDir(path: string) {}
101+
set rootDir(path: string) {
102+
}
99103
}
100104

101105
@Injectable()
@@ -107,11 +111,13 @@ export class ScriptsRendererService extends Renderer {
107111
return this.configuration.templateDir;
108112
}
109113

110-
set templateDir(template: string) {}
114+
set templateDir(template: string) {
115+
}
111116

112117
get rootDir() {
113118
return join(...[this.configuration.project?.rootDir, this.configuration.project?.scriptsDir].filter(Boolean));
114119
}
115120

116-
set rootDir(template: string) {}
121+
set rootDir(template: string) {
122+
}
117123
}

0 commit comments

Comments
 (0)