Skip to content

Commit

Permalink
feat(init): wip typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
misterdev committed May 28, 2019
1 parent f46f4e5 commit 093a36d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
23 changes: 9 additions & 14 deletions packages/generators/init-generator.ts
Expand Up @@ -10,7 +10,7 @@ import { Confirm, Input, List } from "@webpack-cli/webpack-scaffold";

import { WebpackOptions } from "./types";
import entryQuestions from "./utils/entry";
import getBabelPlugin from "./utils/module";
import langQuestionHandler from "./utils/language";
import styleQuestionHandler, { ILoader, StylingType } from "./utils/style";
import tooltip from "./utils/tooltip";

Expand Down Expand Up @@ -194,22 +194,17 @@ export default class InitGenerator extends Generator {
})
.then(() =>
this.prompt([
Confirm("useBabel", "Will you be using ES2015?"),
List("langType", "Will you use one of the below JS solutions?", [
"ES6",
"Typescript",
"No",
]),
]),
)
.then((useBabelAnswer: {
useBabel: boolean;
.then((langTypeAnswer: {
langType: boolean;
}) => {
if (useBabelAnswer.useBabel) {
this.configuration.config.webpackOptions.module.rules.push(
getBabelPlugin(),
);
this.dependencies.push(
"babel-loader",
"@babel/core",
"@babel/preset-env",
);
}
langQuestionHandler(this, langTypeAnswer.langType);
})
.then(() =>
this.prompt([
Expand Down
@@ -1,4 +1,9 @@
interface Module extends Object {
export enum LangType {
ES6 = "ES6",
Typescript = "Typescript",
}

interface ModuleRule extends Object {
include: string[];
loader: string;
options: {
Expand All @@ -16,7 +21,7 @@ type Preset = string | object;
*
* @returns {Function} A callable function that adds the babel-loader with env preset
*/
export default function(): Module {
export function getBabelPlugin(): ModuleRule {
return {
include: ["path.resolve(__dirname, 'src')"],
loader: "'babel-loader'",
Expand All @@ -34,3 +39,20 @@ export default function(): Module {
test: `${new RegExp(/\.js$/)}`
};
}

export default function language(self, langType) {
switch (langType) {
case LangType.ES6:
self.configuration.config.webpackOptions.module.rules.push(
getBabelPlugin(),
);
self.dependencies.push(
"babel-loader",
"@babel/core",
"@babel/preset-env",
);
break;
case LangType.Typescript:
break;
}
}

0 comments on commit 093a36d

Please sign in to comment.