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

feat: init create-webpack-app package [1] #4214

Merged
merged 84 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
f910fe3
feat: init new package and installed deps
maverox May 13, 2024
c175c9d
feat: add template directory from prototype
maverox May 13, 2024
12fbc20
build: typescript init
maverox May 15, 2024
92c2f19
build: set type: module in package.json
maverox May 15, 2024
488f3df
feat: change template to align more with generators package
maverox May 16, 2024
a17fa63
feat: add core logic to run generators and also add types
maverox May 16, 2024
bb6ca9f
chore: add scripts in package.json
maverox May 16, 2024
d5e9fc3
build: change module type to esm in package.json
maverox May 16, 2024
667d50d
feat: add entrypoint executable which wraps the generator cli
maverox May 16, 2024
8f89b98
chore: add ejs and @types/ejs as dependencies
maverox May 18, 2024
d2ca7f6
build: change emit module of tsc to esnext
maverox May 18, 2024
acf5fa5
feat: add ejs template rendering support
maverox May 18, 2024
df39698
feat: add entryPoint prompt
maverox May 18, 2024
93c2142
chore: remove unused code
maverox May 18, 2024
85b06bc
chore: change eslint and cspell silencer
maverox May 19, 2024
88acfd2
build: change plopfile.ts on reviews
maverox May 19, 2024
55e13ec
feat: change the templates
maverox May 19, 2024
897e00b
fix: fix missing comma in tsconfig
maverox May 19, 2024
f9cb74a
chore: change package.json on reviews
maverox May 19, 2024
b6baa6a
docs: change readme based on review
maverox May 19, 2024
d9a0856
fix: customACtionConfig support in plopfile.ts setGenerator config pr…
maverox May 27, 2024
d8ec7e1
feat: add npmInstall custom package
maverox Jun 1, 2024
4c59396
chore: remove redundant code
maverox Jun 1, 2024
04b5f90
fix: typo in prompt
maverox Jun 1, 2024
1bdf924
feat: add skip prompt functionality
maverox Jun 5, 2024
5e6a70b
chore: install commander and remove obsolete deps
maverox Jun 7, 2024
bb5e201
refactor: remove dynamic prompt and revert to previous state
maverox Jun 7, 2024
9bf21bf
feat: create commander cli and implement skip feat
maverox Jun 7, 2024
a295914
refactor: change prompt order to have genPath as first
maverox Jun 8, 2024
e6add83
refactor: change console output format for deps installation
maverox Jun 8, 2024
4ac8bf0
feat: change -s flag to -f|--force and make it default
maverox Jun 8, 2024
d1fb3e7
chore: add 'uzair' as a word for cspell
maverox Jun 8, 2024
2928772
test: create test suite for create-webpack-app package
maverox Jun 8, 2024
3f66230
Update packages/create-webpack-app/README.md
maverox Jun 15, 2024
769e095
Update packages/create-webpack-app/README.md
maverox Jun 15, 2024
cb309df
refactor: migrate cli logic to ts from js
maverox Jun 25, 2024
860e5c2
feat: add conditional file generation based on dynamic action function
maverox Jun 25, 2024
de92604
docs: change doc to align with its features
maverox Jun 25, 2024
b150fa8
feat: change dependency installation to be cross-compatible
maverox Jun 25, 2024
f3315f4
refactor: remove unused var
maverox Jun 25, 2024
19f59ea
feat: add types
maverox Jun 25, 2024
02f04cb
chore: enable eslint for package/create-webpack-app
maverox Jun 25, 2024
284ab14
chore: change module type and fix control flow for errors
maverox Jun 25, 2024
b80f340
feat: add logger utility module
maverox Jul 1, 2024
944bb33
refactor: refactor and implement logger
maverox Jul 1, 2024
b82f4be
feat: change stdio settings for pkgInstall action
maverox Jul 1, 2024
b4cca8f
fix: change conditional prompt to align with original logic
maverox Jul 1, 2024
e3ef415
test: implement test according to package
maverox Jul 1, 2024
0a42c64
fix: changed template package.json to improve compatibility with syntax
maverox Jul 1, 2024
f0196bd
chore: add peerDep webpack-cli and dep colorette
maverox Jul 1, 2024
8e9dfb6
feat: remove projectName and use path only
maverox Jul 4, 2024
ff53355
chore: remove "uzair" as word from cspell.json
maverox Jul 4, 2024
22873e8
chore: remove test/create-webpack-app from .eslintignore
maverox Jul 7, 2024
fdd61df
perf: change generator conditional flows and dependencies attached
maverox Jul 7, 2024
ea92e56
refactor: remove redundant code from test.utils and extend from utils…
maverox Jul 7, 2024
3fb7b98
test: update snapshots and test according to previous two commits
maverox Jul 7, 2024
2c5bfb3
feat: loader and plugin commands, more templates (#4225)
maverox Aug 25, 2024
a6e4b61
feat: modular and scalable refactor, --template flag and react templa…
maverox Aug 25, 2024
06fe8cf
fix: remove obsolete files after merge
maverox Aug 25, 2024
add60da
test: change vue tests according to change in default value of "cssType"
maverox Aug 25, 2024
e1664ff
fix: use more compatible splice than toSpliced method
maverox Aug 25, 2024
72c6efd
test: skip all but first test for loader suite
maverox Aug 26, 2024
dd7dff1
test: skip all tests for loader suite (modify previous commit)
maverox Aug 26, 2024
804638c
feat: improve react generator and template
maverox Sep 1, 2024
830239f
feat: improve vue generator and templates
maverox Sep 1, 2024
f6fffa8
feat: make cssType as CSS only instead of none for svelte and remove …
maverox Sep 1, 2024
572f42a
feat: remove redundant build:prod command from template package.json
maverox Sep 1, 2024
67682a1
test: modify test according to changes in previous commit and also re…
maverox Sep 1, 2024
403d12e
Feat: File generation and collision handler [6] (#4249)
maverox Sep 11, 2024
20073b9
fix: remove inconsistencies after merge
maverox Sep 13, 2024
390325e
feat: add fileGenerator improved version with better conflict resolution
maverox Sep 13, 2024
acd575a
fix: test discrepancy after merge
maverox Sep 17, 2024
838a6fa
fix: fix issue with plop.js prompt failure due to inquirer update
maverox Sep 17, 2024
5ba3f4f
Revert "fix: fix issue with plop.js prompt failure due to inquirer up…
maverox Sep 20, 2024
6697fa0
fix: failing prompts after update to inquirer v9.3.6
maverox Sep 20, 2024
b79e528
chore: remove obsolete comments
maverox Sep 20, 2024
e33e4cb
test: skip `create-webpack-app` suites for node ver. lower than 18
maverox Sep 21, 2024
1cfccdd
ci: fix failing CI on windows due to unnormalized paths in logs
maverox Sep 21, 2024
28c6a83
chore: fix lint
snitin315 Oct 2, 2024
6092fb1
Merge remote-tracking branch 'origin/master' into gsoc/create-webpack…
snitin315 Oct 2, 2024
e714995
chore: refactor nodeVersion util
snitin315 Oct 2, 2024
cd8ab15
chore: fix tests
snitin315 Oct 2, 2024
01cb7a4
Merge remote-tracking branch 'origin/master' into gsoc/create-webpack…
snitin315 Oct 3, 2024
cc36af2
Merge remote-tracking branch 'origin/master' into gsoc/create-webpack…
snitin315 Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"nwjs",
"Oikawa",
"pathinfo",
"plopfile",
"pnpm",
"postcss",
"prebuild",
Expand Down Expand Up @@ -101,7 +102,8 @@
"Yuuji",
"Zangetsu",
"Zenitsu",
"quickstart"
"quickstart",
"pinia"
],
"dictionaries": ["npm", "software-terms"],
"ignorePaths": [
Expand Down
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ module.exports = {
"node/no-unsupported-features/es-syntax": "off",
},
},
{
files: ["**/packages/create-webpack-app/**/*.js"],
parserOptions: {
sourceType: "module",
},
},
],
};
48 changes: 48 additions & 0 deletions packages/create-webpack-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div>
<a href="https://github.com/webpack/webpack-cli">
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
</div>

# create-webpack-app CLI

## About

- `create-webpack-app` is a cli tool that enables developers to scaffold a new webpack project quickly. It provides developers with a flexible set of commands to increase speed when setting up a custom webpack project. webpack CLI addresses these needs by providing tools to improve the setup of custom webpack configuration.
- It also supports several front-end frameworks and libraries like React, Angular, Vue, Svelte, etc.
- Webpack Loader and Plugin scaffolding is also supported.

## Supported arguments and commands

### Usage

```bash
npx create-webpack-app [command] [options]
```

### CLI options

**To generate default template**

```bash
npx create-webpack-app
```

**To generate with default answers**

```bash
npx create-webpack-app -f, --force
```

**To generate in a specified path**

```bash
npx create-webpack-app [generation-path]
```

**To generate a project according to a template**

```bash
npx create-webpack-app --template <template-name>

```
4 changes: 4 additions & 0 deletions packages/create-webpack-app/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

//eslint-disable-next-line
import * as cli from "../lib/index.js";
57 changes: 57 additions & 0 deletions packages/create-webpack-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "create-webpack-app",
"version": "1.0.0",
"description": "CLI for scaffolding webpack projects using default config, framework templates, loader or plugins templates",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack-cli/create-webpack-app.git"
},
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/create-webpack-app",
"bugs": "https://github.com/webpack/webpack-cli/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"bin": {
"create-webpack-app": "./bin/cli.js"
},
"type": "module",
"main": "./lib/index.js",
"scripts": {
"build": "tsc --build",
"watch": "tsc --watch"
},
"engines": {
"node": ">=18.12.0"
},
"keywords": [
"webpack",
"cli",
"scaffolding",
"module",
"bundler",
"web",
"frameworks"
],
"files": [
"bin",
"lib",
"!**/*__tests__"
],
"peerDependencies": {
"webpack-cli": "^5.x.x"
},
"dependencies": {
"@inquirer/prompts": "^5.1.2",
"colorette": "^2.0.20",
"commander": "^12.1.0",
"cross-spawn": "^7.0.3",
"ejs": "^3.1.10",
"node-plop": "^0.32.0"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/ejs": "^3.1.5"
}
}
198 changes: 198 additions & 0 deletions packages/create-webpack-app/src/generators/init/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import { Answers, ActionType } from "../../types";
import { dirname, join, resolve } from "path";
import { NodePlopAPI, DynamicActionsFunction } from "node-plop";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));

export default async function (plop: NodePlopAPI) {
// dependencies to be installed
const devDependencies: Array<string> = ["webpack", "webpack-cli"];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileActions.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
// Define a custom action for installing packages

// Define a base generator for the project structure
plop.setGenerator("init-default", {
description: "Create a basic webpack project",
prompts: [
{
type: "input",
name: "projectPath",
message: "Enter the project destination:",
default: ".",
filter: (input) => {
return resolve(process.cwd(), input);
},
},
{
type: "list",
name: "langType",
message: "Which of the following JS solutions do you want to use?",
choices: ["none", "ES6", "Typescript"],
default: "none",
},
{
type: "confirm",
name: "devServer",
message: "Would you like to use Webpack Dev server?",
default: true,
},
{
type: "confirm",
name: "htmlWebpackPlugin",
message: "Do you want to simplify the creation of HTML files for your bundle?",
default: true,
},
{
type: "confirm",
name: "workboxWebpackPlugin",
message: "Do you want to add PWA support?",
default: true,
},
{
type: "list",
name: "cssType",
message: "Which of the following CSS solution do you want to use?",
choices: ["none", "CSS only", "SASS", "LESS", "Stylus"],
default: "none",
filter: (input, answers) => {
if (input === "none") {
answers.isCSS = false;
answers.isPostCSS = false;
answers.extractPlugin = "No";
} else if (input === "CSS only") {
answers.isCSS = true;
}
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?",
default: (answers: Answers) => answers.cssType == "CSS only",
},
{
type: "list",
name: "extractPlugin",
message: "Do you want to extract CSS into separate files?",
choices: ["No", "Only for Production", "Yes"],
default: "No",
},
{
type: "list",
name: "packageManager",
message: "Which package manager do you want to use?",
choices: ["npm", "yarn", "pnpm"],
default: "npm",
validate(input) {
if (!input.trim()) {
return "Package manager cannot be empty";
}
return true;
},
},
],
actions: function (answers: Answers) {
const actions: ActionType[] = [];

switch (answers.langType) {
case "ES6":
devDependencies.push("babel-loader", "@babel/core", "@babel/preset-env");
break;
case "Typescript":
devDependencies.push("typescript", "ts-loader");
break;
}

if (answers.devServer) {
devDependencies.push("webpack-dev-server");
}

if (answers.htmlWebpackPlugin) {
devDependencies.push("html-webpack-plugin", "html-loader");
}

if (answers.workboxWebpackPlugin) {
devDependencies.push("workbox-webpack-plugin");
}

if (answers.isPostCSS) {
devDependencies.push("postcss-loader", "postcss", "autoprefixer");
}

if (answers.extractPlugin !== "No") {
devDependencies.push("mini-css-extract-plugin");
}

if (answers.cssType !== "none") {
devDependencies.push("style-loader", "css-loader");
switch (answers.cssType) {
case "SASS":
devDependencies.push("sass-loader", "sass");
break;
case "LESS":
devDependencies.push("less-loader", "less");
break;
case "Stylus":
devDependencies.push("stylus-loader", "stylus");
break;
}
}
if (answers.extractPlugin !== "No") {
devDependencies.push("mini-css-extract-plugin");
}

const files = ["./index.html", "webpack.config.js", "package.json", "README.md"];

switch (answers.langType) {
case "Typescript":
answers.entryPoint = "./src/index.ts";
files.push("tsconfig.json", answers.entryPoint as string);
break;
case "ES6":
answers.entryPoint = "./src/index.js";
files.push("babel.config.json", answers.entryPoint as string);
break;
default:
answers.entryPoint = "./src/index.js";
files.push(answers.entryPoint as string);
break;
}
if (answers.isPostCSS) {
files.push("postcss.config.js");
}

for (const file of files) {
const initialConfig: ActionType = {
type: "fileActions",
path: join(answers.projectPath, file),
templateFile: join(plop.getPlopfilePath(), "../templates/init/default", `${file}.tpl`),
data: answers,
};
actions.push(initialConfig);
}

actions.push({
type: "pkgInstall",
path: plop.renderString("{{projectPath}}/", answers),
// Custom function don't automatically render hbs template as path hence manual rendering
packages: devDependencies,
});
return actions;
} as DynamicActionsFunction,
});
}
Loading
Loading