Skip to content

Commit

Permalink
chore: update yeoman-generator to v5 (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 26, 2022
1 parent f304ab2 commit 820db8f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1,258 deletions.
2 changes: 1 addition & 1 deletion packages/generators/package.json
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"webpack-cli": "^4.10.0",
"yeoman-environment": "^3.9.1",
"yeoman-generator": "^4.12.0"
"yeoman-generator": "^5.7.0"
},
"peerDependencies": {
"webpack": "5.x.x",
Expand Down
3 changes: 3 additions & 0 deletions packages/generators/src/addon-generator.ts
Expand Up @@ -6,6 +6,9 @@ import { CustomGenerator } from "./types";
import type { CustomGeneratorOptions, BaseCustomGeneratorOptions } from "./types";
import { getInstaller, getTemplate } from "./utils/helpers";

// eslint-disable-next-line @typescript-eslint/no-var-requires
Object.assign(Generator.prototype, require("yeoman-generator/lib/actions/install"));

// Helper to get the template-directory content
const getFiles = (dir: string): string[] => {
return fs.readdirSync(dir).reduce((list, file) => {
Expand Down
16 changes: 1 addition & 15 deletions packages/generators/src/init-generator.ts
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { readFileSync, writeFileSync } from "fs";

import { CustomGenerator, InitGeneratorOptions, CustomGeneratorOptions } from "./types";
import { getInstaller, getTemplate } from "./utils/helpers";
Expand All @@ -19,20 +19,6 @@ export default class InitGenerator<
}

public async prompting(): Promise<void> {
if (!existsSync(this.generationPath)) {
this.cli.logger.log(
`${this.cli.colors.blue(
"ℹ INFO ",
)} supplied generation path doesn't exist, required folders will be created.`,
);
try {
mkdirSync(this.generationPath, { recursive: true });
} catch (error) {
this.cli.logger.error(`Failed to create directory.\n ${error}`);
process.exit(2);
}
}

this.template = await getTemplate.call(this);

await handlers[this.template as keyof typeof handlers].questions(this, Question);
Expand Down
6 changes: 3 additions & 3 deletions test/init/init.test.js
Expand Up @@ -81,8 +81,8 @@ describe("init command", () => {
const assetsPath = path.resolve(os.tmpdir(), Date.now().toString());
const { stdout, stderr } = await run(__dirname, ["init", assetsPath, "--force"]);

expect(stdout).toContain("generation path doesn't exist, required folders will be created.");
expect(stdout).toContain("Project has been initialised with webpack!");
expect(stderr).toContain(`create ${path.relative(__dirname, assetsPath)}`);
expect(stderr).toContain("webpack.config.js");

// Test files
Expand All @@ -98,8 +98,8 @@ describe("init command", () => {
const assetsPath = path.resolve(os.tmpdir(), Date.now().toString());
const { stdout, stderr } = await run(__dirname, ["init", assetsPath, "--force"]);

expect(stdout).toContain("generation path doesn't exist, required folders will be created.");
expect(stdout).toContain("Project has been initialised with webpack!");
expect(stderr).toContain(`create ${path.relative(__dirname, assetsPath)}`);
expect(stderr).toContain("webpack.config.js");

// Test files
Expand Down Expand Up @@ -512,7 +512,7 @@ describe("init command", () => {
const { exitCode, stderr } = await run(projectPath, ["init", "my-app"], { reject: false });

expect(exitCode).toBe(2);
expect(stderr).toContain("Failed to create directory");
expect(stderr).toContain("Failed to initialize the project.");
});

it("should work with 'new' alias", async () => {
Expand Down

0 comments on commit 820db8f

Please sign in to comment.