-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add core logic to run generators and also add types
- Loading branch information
Showing
4 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// refactored generator will be written here shortly |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { NodePlopAPI } from "./types"; | ||
import { resolve } from "path"; | ||
/* eslint-disable no-unused-vars */ | ||
|
||
export default function (plop: NodePlopAPI) { | ||
const dependencies = ["webpack", "webpack-cli"]; | ||
// Define a base generator for the project structure | ||
plop.setGenerator("init", { | ||
description: "Create a basic Webpack project", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "projectName", | ||
message: "Enter your project name:", | ||
default: "webpack-project", | ||
validate(input, _) { | ||
if (!input) { | ||
return "Project name cannot be empty"; | ||
} | ||
return true; | ||
}, | ||
}, | ||
{ | ||
type: "input", | ||
name: "configPath", | ||
message: "Enter the project destination:", | ||
default: ".", | ||
filter: (input, answers) => { | ||
return resolve(input, answers.projectName); | ||
}, | ||
}, | ||
{ | ||
type: "list", | ||
name: "langType", | ||
message: "Which of the following JS solutions do you want to use?", | ||
choices: ["none", "ES6", "Typescript"], | ||
default: "none", | ||
filter: (input, _) => { | ||
switch (input) { | ||
case "ES6": | ||
dependencies.push("babel-loader", "@babel/core", "@babel/preset-env"); | ||
break; | ||
case "Typescript": | ||
dependencies.push("typescript", "ts-loader"); | ||
break; | ||
} | ||
return input; | ||
}, | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "devServer", | ||
message: "Would you like to use Webpack Dev server?", | ||
default: true, | ||
filter: (input, _) => { | ||
if (input) { | ||
dependencies.push("webpack-dev-server"); | ||
} | ||
return input; | ||
}, | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "htmlWebpackPlugin", | ||
message: "Do you want to simplify the creation of HTML files for your bundle?", | ||
default: true, | ||
filter: (input, _) => { | ||
if (input) { | ||
dependencies.push("html-webpack-plugin", "html-loader"); | ||
} | ||
return input; | ||
}, | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "workboxWebpackPlugin", | ||
message: "Do you want to add PWA support?", | ||
default: true, | ||
filter: (input, _) => { | ||
if (input) { | ||
dependencies.push("workbox-webpack-plugin"); | ||
} | ||
return input; | ||
}, | ||
}, | ||
{ | ||
type: "list", | ||
name: "cssType", | ||
message: "Which of the following CSS solution do you want to use?", | ||
choices: ["none", "CSS only", "SASS", "LESS", "Stylus"], | ||
default: "Css only", | ||
filter: (input, answers) => { | ||
if (input === "none") { | ||
answers.isCSS = false; | ||
answers.isPostCSS = false; | ||
answers.extractPlugin = "No"; | ||
} else { | ||
dependencies.push("style-loader", "css-loader"); | ||
switch (input) { | ||
case "CSS only": | ||
answers.isCSS = true; | ||
break; | ||
case "SASS": | ||
dependencies.push("sass-loader", "node-sass"); | ||
break; | ||
case "LESS": | ||
dependencies.push("less-loader", "less"); | ||
break; | ||
case "Stylus": | ||
dependencies.push("stylus-loader", "stylus"); | ||
break; | ||
} | ||
} | ||
return input; | ||
}, | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "isCSS", | ||
message: (answers) => | ||
`Will you be using CSS styles along with ${answers.cssType}in your project?`, | ||
when: (answers) => answers.cssType !== "CSS only", | ||
default: true, | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "isPostCSS", | ||
message: "Do you want to use PostCSS in your project?", | ||
when: (answers) => answers.isCSS, | ||
filter: (input, _) => { | ||
if (input) { | ||
dependencies.push("postcss-loader", "autoprefixer"); | ||
} | ||
return input; | ||
}, | ||
default: true, | ||
}, | ||
{ | ||
type: "list", | ||
name: "extractPlugin", | ||
message: "Do you want to extract CSS into separate files?", | ||
choices: ["No", "Only for Production", "Yes"], | ||
when: (answers) => answers.isCSS, | ||
default: "No", | ||
filter: (input, _) => { | ||
if (input !== "No") { | ||
dependencies.push("mini-css-extract-plugin"); | ||
} | ||
return input; | ||
}, | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "addMany", | ||
destination: "{{configPath}}", | ||
base: "../templates/init/default", | ||
templateFiles: "../templates/init/default/**/*", | ||
force: true, | ||
verbose: true, | ||
}, | ||
], | ||
}); | ||
plop.setHelper( | ||
"isEqualToString", | ||
function (this: typeof Function, value: string, comparison: string, options: any) { | ||
return value === comparison ? options.fn(this) : options.inverse(this); | ||
}, | ||
); | ||
} | ||
// module.exports = plop.generator("basicProject").run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type { | ||
ActionConfig, | ||
ActionType, | ||
AddActionConfig, | ||
AddManyActionConfig, | ||
AppendActionConfig, | ||
CustomActionFunction, | ||
ModifyActionConfig, | ||
PlopCfg, | ||
PlopGenerator, | ||
NodePlopAPI, | ||
PlopGeneratorConfig, | ||
Actions, | ||
} from "node-plop"; | ||
|
||
export type InitOptions = { template: string; force?: boolean }; | ||
export type LoaderOptions = { template: string }; | ||
export type PluginOptions = { template: string }; | ||
export type InitGeneratorOptions = { generationPath: string } & InitOptions; | ||
export type LoaderGeneratorOptions = { generationPath: string } & LoaderOptions; | ||
export type PluginGeneratorOptions = { generationPath: string } & PluginOptions; |