Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(types): move to @types/yeoman-generator #869

Merged
merged 8 commits into from May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions packages/generate-loader/types/Yeoman.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/generate-plugin/types/Yeoman.ts

This file was deleted.

20 changes: 10 additions & 10 deletions packages/generators/add-generator.ts
@@ -1,4 +1,4 @@
import Generator = require("yeoman-generator");
import * as Generator from "yeoman-generator";

import * as glob from "glob-all";
import * as autoComplete from "inquirer-autocomplete-prompt";
Expand All @@ -7,7 +7,7 @@ import * as path from "path";
import npmExists from "@webpack-cli/utils/npm-exists";
import { getPackageManager } from "@webpack-cli/utils/package-manager";
import PROP_TYPES from "@webpack-cli/utils/prop-types";
import { AutoComplete, Confirm, InquirerInput, Input, List } from "@webpack-cli/webpack-scaffold";
import { AutoComplete, Confirm, Input, List } from "@webpack-cli/webpack-scaffold";

import { SchemaProperties, WebpackOptions } from "./types";
import entryQuestions from "./utils/entry";
Expand Down Expand Up @@ -102,13 +102,13 @@ export default class AddGenerator extends Generator {
registerPrompt("autocomplete", autoComplete);
}

public prompting(): void {
const done: () => void | boolean = this.async();
public prompting(): Promise<void | {}> {
const done: () => {} = this.async();
let action: string;
const self: this = this;
const manualOrListInput: (promptAction: string) => InquirerInput = (promptAction: string): InquirerInput =>
const manualOrListInput: (promptAction: string) => Generator.Question = (promptAction: string): Generator.Question =>
Input("actionAnswer", `What do you want to add to ${promptAction}?`);
let inputPrompt: InquirerInput;
let inputPrompt: Generator.Question;

// first index indicates if it has a deep prop, 2nd indicates what kind of
// TODO: this must be reviewed. It starts as an array of booleans but after that it get overridden
Expand All @@ -132,13 +132,13 @@ export default class AddGenerator extends Generator {
}
)
.then(
(): void => {
(): Promise<void | {}> => {
if (action === "entry") {
return this.prompt([
Confirm("entryType", "Will your application have multiple bundles?", false)
])
.then(
(entryTypeAnswer: { entryType: boolean }): Promise<{}> => {
(entryTypeAnswer: { entryType: boolean }): Promise<void | {}> => {
// Ask different questions for entry points
return entryQuestions(self, entryTypeAnswer);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ export default class AddGenerator extends Generator {
}
)
.then(
(answerToAction: { actionAnswer: string }): void => {
(answerToAction: { actionAnswer: string }): Promise<void | {}> => {
if (!answerToAction) {
done();
return;
Expand Down Expand Up @@ -364,7 +364,7 @@ export default class AddGenerator extends Generator {
pluginsSchemaProps
)
]).then(
(pluginsPropAnswer: { pluginsPropType: string }): Promise<{}> => {
(pluginsPropAnswer: { pluginsPropType: string }): Promise<void | {}> => {
return this.prompt([
Input(
"pluginsPropTypeVal",
Expand Down
27 changes: 14 additions & 13 deletions packages/generators/addon-generator.ts
@@ -1,16 +1,14 @@
import * as mkdirp from "mkdirp";
import * as path from "path";
import Generator = require("yeoman-generator");
import * as Generator from "yeoman-generator";

import * as copyUtils from "@webpack-cli/utils/copy-utils";
import { InquirerScaffoldObject } from "@webpack-cli/webpack-scaffold";
import { YeoGenerator } from "../generate-loader/types/Yeoman";

/**
* Creates a Yeoman Generator that generates a project conforming
* to webpack-defaults.
*
* @param {any[]} prompts An array of Yeoman prompt objects
* @param {Generator.Questions} prompts An array of Yeoman prompt objects
*
* @param {string} templateDir Absolute path to template directory
*
Expand All @@ -27,21 +25,23 @@ import { YeoGenerator } from "../generate-loader/types/Yeoman";
*
* @returns {Generator} A class extending Generator
*/
export default function addonGenerator(
prompts: InquirerScaffoldObject[],
const addonGenerator = (
prompts: Generator.Questions,
templateDir: string,
copyFiles: string[],
copyTemplateFiles: string[],
templateFn: Function
): YeoGenerator {
return class AddOnGenerator extends Generator {
public props: InquirerScaffoldObject;
): typeof Generator => class AddonGenerator extends Generator {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about typeof Generator, just Generator doesn't work

public props: Generator.Question;
public copy: (value: string, index: number, array: string[]) => void;
public copyTpl: (value: string, index: number, array: string[]) => void;

public async prompting(): Promise<void> {
const scaffoldObject: InquirerScaffoldObject = await this.prompt(prompts);
this.props = scaffoldObject;
public prompting(): Promise<void | {}> {
return this.prompt(prompts).then(
(props: Generator.Question): void => {
this.props = props;
}
);
}

public default(): void {
Expand Down Expand Up @@ -80,4 +80,5 @@ export default function addonGenerator(
this.spawnCommand("npm", ["run", "defaults"]);
}
};
}

export default addonGenerator;
13 changes: 7 additions & 6 deletions packages/generators/init-generator.ts
@@ -1,6 +1,7 @@
import chalk from "chalk";
import * as logSymbols from "log-symbols";
import Generator = require("yeoman-generator");
import * as Generator from "yeoman-generator";
import * as Inquirer from "inquirer";

import { getPackageManager } from "@webpack-cli/utils/package-manager";
import { Confirm, Input, List } from "@webpack-cli/webpack-scaffold";
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class InitGenerator extends Generator {

// eslint-disable-next-line
public prompting(): any {
const done: () => void | boolean = this.async();
const done: () => {} = this.async();
const self: this = this;
let regExpForStyles: string;
let ExtractUseProps: object[];
Expand Down Expand Up @@ -83,7 +84,7 @@ export default class InitGenerator extends Generator {

return this.prompt([Confirm("entryType", "Will your application have multiple bundles?", false)])
.then(
(entryTypeAnswer: { entryType: boolean }): Promise<{}> => {
(entryTypeAnswer: { entryType: boolean }): Promise<void | {}> => {
// Ask different questions for entry points
return entryQuestions(self, entryTypeAnswer);
}
Expand Down Expand Up @@ -125,7 +126,7 @@ export default class InitGenerator extends Generator {
}
)
.then(
(): void => {
(): Promise<Inquirer.Answers> => {
this.isProd = this.usingDefaults ? true : false;
this.configuration.config.configName = this.isProd ? "prod" : "config";
if (!this.isProd) {
Expand All @@ -144,7 +145,7 @@ export default class InitGenerator extends Generator {
}
)
.then(
(): void => {
(): Promise<Inquirer.Answers> => {
return this.prompt([
List("stylingType", "Will you use one of the below CSS solutions?", [
"No",
Expand Down Expand Up @@ -319,7 +320,7 @@ export default class InitGenerator extends Generator {
}
)
.then(
(): void => {
(): Promise<Inquirer.Answers> => {
if (this.isProd) {
// Ask if the user wants to use extractPlugin
return this.prompt([
Expand Down