Skip to content

Commit

Permalink
chore(generate-loader,plugin): add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Jul 14, 2018
1 parent 47702cb commit 184fe2f
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 52 deletions.
1 change: 1 addition & 0 deletions packages/generate-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
3 changes: 3 additions & 0 deletions packages/generate-loader/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
examples
test
types
templates/test
*.ts
tsconfig.json
18 changes: 0 additions & 18 deletions packages/generate-loader/index.js

This file was deleted.

18 changes: 18 additions & 0 deletions packages/generate-loader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import LoaderGenerator from "@webpack-cli/generators/loader-generator";
import * as yeoman from "yeoman-environment";

import { IYeoman } from "./types/Yeoman";

/**
* Runs a yeoman generator to create a new webpack loader project
* @returns {void}
*/

export default function loaderCreator(): void {
const env = yeoman.createEnv();
const generatorName: string = "webpack-loader-generator";

env.registerStub(LoaderGenerator, generatorName);

env.run(generatorName);
}
10 changes: 10 additions & 0 deletions packages/generate-loader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/generate-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"dependencies": {
"@webpack-cli/generators": "^0.0.8",
"yeoman-environment": "^2.1.1"
},
"devDependencies": {
"@types/node": "^10.3.6",
"typescript": "^2.9.2"
},
"scripts": {
"build": "tsc"
}
}
3 changes: 3 additions & 0 deletions packages/generate-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}
12 changes: 12 additions & 0 deletions packages/generate-loader/types/Yeoman.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface IRunEnv extends Object {
on?: (event: string, callbackFn: Function) => void;
}

export interface IYeoman extends Object {
registerStub?(generator: IGenerator, namespace: string): void;
run?(target: string, options?: object, done?: Function): IRunEnv;
}

export interface IGenerator extends Object {
composeWith?: (path: string) => void;
}
1 change: 1 addition & 0 deletions packages/generate-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
3 changes: 3 additions & 0 deletions packages/generate-plugin/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
examples
test
types
templates/test
*.ts
tsconfig.json
18 changes: 0 additions & 18 deletions packages/generate-plugin/index.js

This file was deleted.

18 changes: 18 additions & 0 deletions packages/generate-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import PluginGenerator from "@webpack-cli/generators/plugin-generator";
import * as yeoman from "yeoman-environment";

import { IYeoman } from "./types/Yeoman";

/**
* Runs a yeoman generator to create a new webpack plugin project
* @returns {void}
*/

export default function pluginCreator(): void {
const env = yeoman.createEnv();
const generatorName: string = "webpack-plugin-generator";

env.registerStub(PluginGenerator, generatorName);

env.run(generatorName);
}
10 changes: 10 additions & 0 deletions packages/generate-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/generate-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"dependencies": {
"@webpack-cli/generators": "^0.0.8",
"yeoman-environment": "^2.1.1"
},
"devDependencies": {
"@types/node": "^10.3.6",
"typescript": "^2.9.2"
},
"scripts": {
"build": "tsc"
}
}
3 changes: 3 additions & 0 deletions packages/generate-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}
12 changes: 12 additions & 0 deletions packages/generate-plugin/types/Yeoman.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface IRunEnv extends Object {
on?: (event: string, callbackFn: Function) => void;
}

export interface IYeoman extends Object {
registerStub?(generator: IGenerator, namespace: string): void;
run?(target: string, options?: object, done?: Function): IRunEnv;
}

export interface IGenerator extends Object {
composeWith?: (path: string) => void;
}
8 changes: 4 additions & 4 deletions packages/generators/addon-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
import Generator = require("yeoman-generator");

import * as copyUtils from "@webpack-cli/utils/copy-utils";
import { IScaffoldBaseObject } from "@webpack-cli/webpack-scaffold";
import { IInquirerScaffoldObject } from "@webpack-cli/webpack-scaffold";

/**
* Creates a Yeoman Generator that generates a project conforming
Expand All @@ -27,19 +27,19 @@ import { IScaffoldBaseObject } from "@webpack-cli/webpack-scaffold";
* @returns {Generator} A class extending Generator
*/
export default function addonGenerator(
prompts: IScaffoldBaseObject[],
prompts: IInquirerScaffoldObject[],
templateDir: string,
copyFiles: string[],
copyTemplateFiles: string[],
templateFn: Function,
) {
return class AddOnGenerator extends Generator {
public props: IScaffoldBaseObject;
public props: IInquirerScaffoldObject;
private copy: (value: string, index: number, array: string[]) => void;
private copyTpl: (value: string, index: number, array: string[]) => void;

public prompting() {
return this.prompt(prompts).then((props: IScaffoldBaseObject) => {
return this.prompt(prompts).then((props: IInquirerScaffoldObject) => {
this.props = props;
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/generators/loader-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import addonGenerator from "./addon-generator";
* @param {string} name A loader name to be formatted
* @returns {string} The formatted string
*/
export function makeLoaderName(name: string): string {
function makeLoaderName(name: string): string {
name = _.kebabCase(name);
if (!/loader$/.test(name)) {
name += "-loader";
Expand Down Expand Up @@ -51,7 +51,7 @@ const LoaderGenerator = addonGenerator(
"examples/simple/src/static-esm-module.js.tpl",
],
["src/_index.js.tpl"],
(gen: IYeoman): object => ({ name: gen.props.name }),
(gen): object => ({ name: gen.props.name }),
);

export default LoaderGenerator;
2 changes: 1 addition & 1 deletion packages/generators/plugin-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const PluginGenerator = addonGenerator(
"examples/simple/src/static-esm-module.js.tpl",
],
["src/_index.js.tpl", "examples/simple/_webpack.config.js.tpl"],
(gen: IYeoman): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }),
(gen): object => ({ name: _.upperFirst(_.camelCase(gen.props.name)) }),
);

export default PluginGenerator;
2 changes: 1 addition & 1 deletion packages/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function runTransform(webpackProperties: IWebpackProperties, acti
return pEachSeries(transformations, (f: string): boolean | INode => {
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
})
.then((_?: any) => {
.then((value: string[]): void | PromiseLike <void> => {
let configurationName: string = "webpack.config.js";
if (config.configName) {
configurationName = "webpack." + config.configName + ".js";
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/copy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IGenerator {
* @returns {Function} A curried function that takes a file path and copies it
*/
export const generatorCopy = (
generator: any,
generator,
templateDir: string,
): (filePath: string) => void => (filePath: string): void => {
const sourceParts: string[] = templateDir.split(path.delimiter);
Expand All @@ -43,7 +43,7 @@ export const generatorCopy = (
* @returns {Function} A curried function that takes a file path and copies it
*/
export const generatorCopyTpl = (
generator: any,
generator,
templateDir: string,
templateData: object,
): (filePath: string) => void => (filePath: string): void => {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/modify-config-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function modifyHelperUtil(
}
}

const env: IYeoman = yeoman.createEnv("webpack", null);
const env = yeoman.createEnv("webpack", null);
const generatorName: string = `webpack-${action}-generator`;

if (!generator) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function runTransform(transformConfig: ITransformConfig, action:
}
return astTransform(j, ast, f, config.webpackOptions[f], transformAction);
})
.then((_: any) => {
.then((value: string[]): void | PromiseLike <void> => {
let configurationName: string;
if (!config.configName) {
configurationName = "webpack.config.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/webpack-scaffold/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as jscodeshift from "jscodeshift";

export interface IScaffoldBaseObject {
export interface IInquirerScaffoldObject {
type?: string;
name: string;
message: string;
Expand All @@ -12,11 +12,11 @@ export interface IScaffoldBaseObject {
filter?: (name: string) => string;
}

export interface IInquirerList extends IScaffoldBaseObject {
export interface IInquirerList extends IInquirerScaffoldObject {
choices?: string[];
}

export interface IInquirerInput extends IScaffoldBaseObject {
export interface IInquirerInput extends IInquirerScaffoldObject {
validate?: (input: string) => string | boolean;
}

Expand Down Expand Up @@ -110,7 +110,7 @@ export function InputValidate(name: string, message: string, cb?: (input: string
};
}

export function Confirm(name: string, message: string): IScaffoldBaseObject {
export function Confirm(name: string, message: string): IInquirerScaffoldObject {
return {
message,
name,
Expand Down

0 comments on commit 184fe2f

Please sign in to comment.