Skip to content

Commit beea1d1

Browse files
refactor: use type for types (#3832)
1 parent 0931ab6 commit beea1d1

File tree

20 files changed

+73
-66
lines changed

20 files changed

+73
-66
lines changed

packages/configtest/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IWebpackCLI } from "webpack-cli";
1+
import { type IWebpackCLI } from "webpack-cli";
22

33
const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
44

packages/generators/src/addon-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import Generator from "yeoman-generator";
44

5-
import { CustomGenerator } from "./types";
5+
import { CustomGenerator } from "./custom-generator";
66
import type { CustomGeneratorOptions, BaseCustomGeneratorOptions } from "./types";
77
import { getInstaller, getTemplate } from "./utils/helpers";
88

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Generator from "yeoman-generator";
2+
import { type IWebpackCLI } from "webpack-cli";
3+
import path from "path";
4+
import { BaseCustomGeneratorOptions, CustomGeneratorOptions } from "./types";
5+
6+
export class CustomGenerator<
7+
T extends BaseCustomGeneratorOptions = BaseCustomGeneratorOptions,
8+
Z extends CustomGeneratorOptions<T> = CustomGeneratorOptions<T>,
9+
> extends Generator<Z> {
10+
public cli: IWebpackCLI;
11+
public template: string;
12+
public dependencies: string[];
13+
public force: boolean;
14+
public answers: Record<string, unknown>;
15+
public generationPath: string;
16+
public supportedTemplates: string[];
17+
public packageManager: string | undefined;
18+
19+
public constructor(args: string | string[], opts: Z) {
20+
super(args, opts);
21+
22+
this.cli = opts.cli;
23+
this.dependencies = [];
24+
this.answers = {};
25+
this.supportedTemplates = [];
26+
27+
const { options } = opts;
28+
29+
this.template = options.template;
30+
this.force = typeof options.force !== "undefined" ? options.force : false;
31+
this.generationPath = path.resolve(process.cwd(), options.generationPath);
32+
}
33+
}

packages/generators/src/handlers/default.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "path";
2-
import { CustomGenerator } from "../types";
3-
import * as QuestionAPI from "../utils/scaffold-utils";
2+
import type { CustomGenerator } from "../custom-generator";
3+
import type * as QuestionAPI from "../utils/scaffold-utils";
44

55
const templatePath = path.resolve(__dirname, "../../init-template/default");
66
const resolveFile = (file: string): string => {

packages/generators/src/handlers/react.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path";
2-
import { CustomGenerator } from "../types";
32
import { questions as defaultQuestions } from "./default";
4-
import * as QuestionAPI from "../utils/scaffold-utils";
3+
import type { CustomGenerator } from "../custom-generator";
4+
import type * as QuestionAPI from "../utils/scaffold-utils";
55

66
const templatePath = path.resolve(__dirname, "../../init-template/react");
77
const resolveFile = (file: string): string => {

packages/generators/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import pluginGenerator from "./plugin-generator";
44
import addonGenerator from "./addon-generator";
55
import initGenerator from "./init-generator";
66
import type { InitOptions, LoaderOptions, PluginOptions } from "./types";
7-
import { IWebpackCLI } from "webpack-cli";
7+
import type { IWebpackCLI } from "webpack-cli";
88

99
class GeneratorsCommand {
1010
async apply(cli: IWebpackCLI): Promise<void> {

packages/generators/src/init-generator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { readFileSync, writeFileSync } from "fs";
22

3-
import { CustomGenerator, InitGeneratorOptions, CustomGeneratorOptions } from "./types";
3+
import { CustomGenerator } from "./custom-generator";
44
import { getInstaller, getTemplate } from "./utils/helpers";
55
import * as Question from "./utils/scaffold-utils";
66
import handlers from "./handlers";
77

8+
import { type InitGeneratorOptions, type CustomGeneratorOptions } from "./types";
9+
810
export default class InitGenerator<
911
T extends InitGeneratorOptions = InitGeneratorOptions,
1012
Z extends CustomGeneratorOptions<T> = CustomGeneratorOptions<T>,

packages/generators/src/loader-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path from "path";
22
import addonGenerator from "./addon-generator";
33
import { toKebabCase } from "./utils/helpers";
4+
45
import type { LoaderGeneratorOptions } from "./types";
5-
import Generator from "yeoman-generator";
6+
import type Generator from "yeoman-generator";
67

78
/**
89
* Formats a string into webpack loader format

packages/generators/src/plugin-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "path";
22
import addonGenerator from "./addon-generator";
33
import { toKebabCase, toUpperCamelCase } from "./utils/helpers";
44
import type { PluginGeneratorOptions } from "./types";
5-
import Generator from "yeoman-generator";
5+
import type Generator from "yeoman-generator";
66

77
export const PluginGenerator = addonGenerator<PluginGeneratorOptions>(
88
[
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import Generator from "yeoman-generator";
2-
import path from "path";
3-
import { IWebpackCLI } from "webpack-cli";
1+
import type Generator from "yeoman-generator";
2+
import { type IWebpackCLI } from "webpack-cli";
43

54
export type InitOptions = { template: string; force?: boolean };
65
export type LoaderOptions = { template: string };
@@ -20,32 +19,3 @@ export type CustomGeneratorOptions<T extends BaseCustomGeneratorOptions> =
2019
cli: IWebpackCLI;
2120
options: T;
2221
};
23-
24-
export class CustomGenerator<
25-
T extends BaseCustomGeneratorOptions = BaseCustomGeneratorOptions,
26-
Z extends CustomGeneratorOptions<T> = CustomGeneratorOptions<T>,
27-
> extends Generator<Z> {
28-
public cli: IWebpackCLI;
29-
public template: string;
30-
public dependencies: string[];
31-
public force: boolean;
32-
public answers: Record<string, unknown>;
33-
public generationPath: string;
34-
public supportedTemplates: string[];
35-
public packageManager: string | undefined;
36-
37-
public constructor(args: string | string[], opts: Z) {
38-
super(args, opts);
39-
40-
this.cli = opts.cli;
41-
this.dependencies = [];
42-
this.answers = {};
43-
this.supportedTemplates = [];
44-
45-
const { options } = opts;
46-
47-
this.template = options.template;
48-
this.force = typeof options.force !== "undefined" ? options.force : false;
49-
this.generationPath = path.resolve(process.cwd(), options.generationPath);
50-
}
51-
}

0 commit comments

Comments
 (0)