Skip to content

Commit

Permalink
chore(types): move to @types/yeoman-generator (#869)
Browse files Browse the repository at this point in the history
* misc(types): update webpack-scaffold to yeoman-generator

* misc(types): updates utils/entry.ts to yeoman-generator

* misc(types): update generators to yeoman-generator

* misc(types): remove unused yeoman types

* chore(types): updated TODOs

* chore(@types): update yeoman-generator to 3.1.2

* misc(packages): refactor yeoman-generator imports

* misc(generators): remove comments
  • Loading branch information
misterdev authored and ematipico committed May 3, 2019
1 parent 68b674b commit c910463
Show file tree
Hide file tree
Showing 19 changed files with 6,454 additions and 2,299 deletions.
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 {
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

0 comments on commit c910463

Please sign in to comment.