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 #4167

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

maverox
Copy link
Collaborator

@maverox maverox commented May 16, 2024

What kind of change does this PR introduce?

  • inits the create-webpack-app

Did you add tests for your changes?
yes
If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Other information

@maverox maverox requested a review from a team as a code owner May 16, 2024 15:45
Copy link

linux-foundation-easycla bot commented May 16, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

} from "node-plop";

export type InitOptions = { template: string; force?: boolean };
export type LoaderOptions = { template: string };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: slack conv, you should make this generic. You see the pattern

Copy link
Collaborator Author

@maverox maverox May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will work on this soon,
I will definitely use the already established types and interfaces in @generators package as inspiration and tweak them.

This project has been created using **webpack-cli**, you can now run

```bash
npm run build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what I am supposed to do here I would love if you can be a bit more specific,
all I can infer is you want me to change the run -> --run

Suggested change
npm run build
npm --run build

like this?
also I have read the section in the link provided

add ejs for rendering logic using ejs templates in future
for compatibility with plopfile, as it throws error if it's a commonjs
file
- change templates to ejs templates
- implement ejs rendering logic in plopfile.ts
- remove helper function
- remove unnecessary comment
@maverox
Copy link
Collaborator Author

maverox commented May 18, 2024

@evenstensberg @snitin315 ,
I have resolved the problem with rendering
pushed the changes in the latest commits please have a look.

```js
const createWebpackApp = require("create-webpack-app");

// TODO: DEMONSTRATE API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to promote the API usage? IMO, CWA interaction should be limited to CLI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same thing, will surely work on a better readme.

import { fileURLToPath } from "node:url";
import minimist from "minimist";
import { Plop, run } from "plop";
/* cSpell:disable */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this disable cspell for the whole file or just the next line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

section of code but I have found a better alternative

Suggested change
/* cSpell:disable */
/* cSpell:words plopfile */

"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack/create-webpack-app.git"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is under the webpacki-cli repo

"watch": "tsc --watch"
},
"engines": {
"node": ">=14.15.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's support the minimum version as v18, we also have plans to drop support for v14 in other packages too.

Suggested change
"node": ">=14.15.0"
"node": ">=18.12.0"

Comment on lines 51 to 52
"peerDependencies": {},
"peerDependenciesMeta": {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"peerDependencies": {},
"peerDependenciesMeta": {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this in latest commit

import { NodePlopAPI } from "./types";
import { resolve } from "path";
import ejs from "ejs";
/* eslint-disable no-unused-vars */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not disable the rule for the whole file, prefer to use //eslint-disable-next-line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this in latest commits

message: "Enter your project name:",
default: "webpack-project",
validate(input, _) {
if (!input) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more strict check, in case the user just passes space.

Suggested change
if (!input) {
if (!input.trim()) {

},
{
type: "input",
name: "configPath",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "configPath",
name: "projectPath",

Comment on lines 34 to 43
type: "input",
name: "entryPoint",
message: "Enter the entry point of your application:",
default: "src/index.js",
validate(input, _) {
if (!input) {
return "Entry point cannot be empty";
}
return true;
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are the ones generating templates we should have control over the entry point. We should not ask this question for scaffolding, users can refactor templates if they wish to post scaffolding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

- better input validation
- remove entrypoint prompt
- fix path issues
- add both index.js and index.ts
- fix bud in package.json template file
- fix the url
- bumped the required node from 14 -> 18
- removed empty peerDeps and peerMetaDeps fields
- fix cli entry point typo
@maverox
Copy link
Collaborator Author

maverox commented May 19, 2024

@snitin315 I have made all the changes you asked!
PTAL

Copy link

codecov bot commented May 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.19%. Comparing base (31f634a) to head (769e095).
Report is 52 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4167      +/-   ##
==========================================
+ Coverage   90.18%   90.19%   +0.01%     
==========================================
  Files          22       22              
  Lines        1702     1714      +12     
  Branches      491      493       +2     
==========================================
+ Hits         1535     1546      +11     
- Misses        167      168       +1     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd1099a...769e095. Read the comment docs.

maverox added 12 commits June 1, 2024 19:39
- installs all the packages from deps array to the project directory
- single prompt to ask whether to skip
- if yes then returns default answers object
- if no then returns the interactive prompts interface
created commander cli
implement init command with
-s -f flags to
skip and -f to override
- create test cases for all the functionalities
- Default project
- Project with a specified generation path
- TypeScript project
- ES6 project
- Project with Sass
- Project with Sass and PostCSS
- Project with Mini-CSS-Extract-Plugin
- Project with Sass, CSS, and PostCSSProject with Less
- Project with Stylus
- Project with Webpack Dev Server (WDS)
- Project with HtmlWebpackPluginProject with WorkboxWebpackPlugin
- Project with a writable current path
- Project with Yarn package manager
@maverox maverox requested a review from snitin315 June 10, 2024 21:26
@snitin315 snitin315 self-assigned this Jun 15, 2024
@@ -11,3 +11,6 @@ test/build/config/error-commonjs/syntax-error.js
test/build/config/error-mjs/syntax-error.mjs
test/build/config/error-array/webpack.config.js
test/configtest/with-config-path/syntax-error.config.js

packages/create-webpack-app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should run ESlint on all packages.

packages/create-webpack-app/README.md Outdated Show resolved Hide resolved
packages/create-webpack-app/README.md Outdated Show resolved Hide resolved
## How to install

```bash
npm install --save-dev @webpack-cli/create-webpack-app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing it locally should not be required, npx create-react-app my-app should work directly.

@@ -0,0 +1,55 @@
import { Command } from "commander";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the webpack-cli package? It also offers utilities like logger. Checkout the CLI tests for more info.

if (answers.isPostCSS) {
dependencies.push("postcss-loader", "autoprefixer");
}
console.log(`Installing packages: ${dependencies.join("\n")}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use logger utility from webpack-cli

@snitin315
Copy link
Member

@maverox I scaffolded the project with the following answers, but when I started the project there were some errors.

? Enter the project destination: /Users/nitin.kumar/Projects/open-source/webpack-cli/packages/create-webpack-app/test-project
? Enter your project name: test
? Which of the following JS solutions do you want to use? none
? Would you like to use Webpack Dev server? Yes
? Do you want to simplify the creation of HTML files for your bundle? Yes
? Do you want to add PWA support? No
? Which of the following CSS solution do you want to use? CSS only
? Do you want to use PostCSS in your project? Yes
? Do you want to extract CSS into separate files? Only for Production
? Which package manager do you want to use? yarn
Screenshot 2024-06-15 at 8 13 14 AM

<% } %>

const config = {
entry: '<%= entryPoint %>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should resolve to src/index.js in case of #4167 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on this

@@ -0,0 +1,2 @@
// delete this file if Language is Javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle this ourselves. If the language is not javascript, it shouldn't be scaffolded at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on this currently, after looking at the tests I have realised the default files and will try to add all other files conditionally.
So in a local change where I have implemented this conditional entry point generation, and soon add others like this.

const plop = await nodePlop("./lib/plopfile.js");
const defaultValues = {
init: {
projectPath: resolve(join(process.cwd(), ".")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing this could be cumbersome, how about default to scaffold in the current dir? I think it's a standard to scaffold in the current dir.

Thoughts? @snitin315 @evenstensberg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't have to ask the project path we can just scaffold files in cwd/project-name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a recent local commit I have changed the default projectPath to process.cwd() so the generator defaults to
cwd/project-name,
but do you want me to remove the prompt where it asks generation path?(because that is important for bypassing with argument for genPath)

maverox and others added 2 commits June 15, 2024 18:02
fix grammar

Co-authored-by: Nitin Kumar <snitin315@gmail.com>
Co-authored-by: Nitin Kumar <snitin315@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants