Skip to content

Commit cd8a937

Browse files
committed
fix(core-template): fix bug related to missing variables in template generator
1 parent c1be880 commit cd8a937

8 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/bin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
import 'source-map-support/register';
4+
35
import yargs from 'yargs';
46
import { Logger } from './core/Logger';
57
import { IArgs, runGenerator } from './index';
@@ -29,6 +31,7 @@ yargs
2931
runGenerator({ directory, wrap })
3032
.then(() => process.exit(0))
3133
.catch(err => {
34+
console.log(err);
3235
Logger.error(err);
3336
process.exit(1);
3437
});

src/core/TemplateBase.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as c from './temlpates/shared';
44

55
/* istanbul ignore next */
66
export class TemplateBase {
7-
constructor(protected vars: Variables) {}
7+
protected vars: Variables;
8+
9+
constructor(vars: Variables) {
10+
this.vars = vars;
11+
}
812

913
protected getReactImportSpecifier(): t.ImportSpecifier[] {
1014
return this.vars.hooks.map(hook => c.importSpec(hook));

src/core/temlpates/ComponentTemplateBase.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { IComponentVariables } from '@/types';
21
import { TemplateBase } from '@/core/TemplateBase';
2+
import { IComponentVariables } from '@/types';
33

44
/* istanbul ignore next */
55
export class ComponentTemplateBase extends TemplateBase {
6-
protected vars: IComponentVariables;
6+
constructor(protected vars: IComponentVariables) {
7+
super(vars);
8+
}
79

810
protected hasMod(mod: string) {
911
return this.vars.mods?.includes(mod);

src/core/temlpates/components/ComponentTemplate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import * as c from '../shared';
88
export class ComponentTemplate
99
extends ComponentTemplateBase
1010
implements Template {
11-
protected vars: IComponentVariables;
11+
constructor(protected vars: IComponentVariables) {
12+
super(vars);
13+
}
1214

1315
private getStyleImport() {
1416
const specifiers = [];

src/core/temlpates/components/ComponentTestTemplate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import * as c from '../shared';
88
export class ComponentTestTemplate
99
extends ComponentTemplateBase
1010
implements Template {
11-
protected vars: IComponentVariables;
11+
constructor(protected vars: IComponentVariables) {
12+
super(vars);
13+
}
1214

1315
generateAST(): t.File {
1416
const componentPath = `./${this.vars.componentName}`;

src/core/temlpates/components/HOCTemplate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { IHOCVariables } from '@/types';
66
import * as c from '../shared';
77

88
export class HOCTemplate extends TemplateBase implements Template {
9-
protected vars: IHOCVariables;
9+
constructor(protected vars: IHOCVariables) {
10+
super(vars);
11+
}
1012

1113
generateAST(): t.File {
1214
const body: t.Statement[] = [];

src/core/temlpates/components/HookTemplate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { IHookVariables } from '@/types';
66
import * as c from '../shared';
77

88
export class HookTemplate extends TemplateBase implements Template {
9-
protected vars: IHookVariables;
9+
constructor(protected vars: IHookVariables) {
10+
super(vars);
11+
}
1012

1113
generateAST(): t.File {
1214
const body: t.Statement[] = [];

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export interface IArgs {
1111
directory?: string;
1212
}
1313

14-
export async function runGenerator(args: IArgs, data?: any) {
14+
type Data = {
15+
type?: string;
16+
answers?: object;
17+
};
18+
19+
export async function runGenerator(args: IArgs, data: Data = {}) {
1520
const { directory, wrap } = args;
1621

1722
let { type } = data;

0 commit comments

Comments
 (0)