Skip to content

Commit 2431d9b

Browse files
committed
refactor: Extracting project creation out to own package (#1708)
* refactor: Extracting out project creation to own package * docs: Adding changeset * refactor: Misc edits to common deps & workspace helper scripts * test: Fixing 'create' test suite * ci: Increase minimum Node version * chore: Fix typos * docs: Update ReadMe instructions * chore: Better (and untaken) package name * docs: Update changeset * test: Update 'create' test suite & build output hashes * docs: Expounding upon changeset
1 parent e7e10a3 commit 2431d9b

File tree

24 files changed

+1582
-2263
lines changed

24 files changed

+1582
-2263
lines changed

.changeset/tiny-garlics-argue.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'preact-cli': major
3+
'create-preact-cli': major
4+
---
5+
6+
Extracts project creation functionality from `preact-cli` into `create-preact-cli`
7+
8+
Setting up new `preact-cli` projects with `npx` is slow, as all dependencies of `preact-cli` would need to be installed, even though only a handful are used for project initialization. On the other hand, suggesting global installs is less than attractive due to NPM's poor default install location (requires `sudo`) and this can get out of sync over time.
9+
10+
By extracting project initialization into its own package, we can provide much, much faster project setup times.
11+
12+
To setup a new project, users will use `npm init preact-cli ...` or `yarn create preact-cli ...`.
13+
14+
Additionally, the `--yarn` flag has been removed in favour of using the yarn initializer (`yarn create`).

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
timeout-minutes: 10
1818
strategy:
1919
matrix:
20-
node-version: [12.x, 14.x]
20+
node-version: [14.x, 16.x]
2121

2222
steps:
2323
- uses: actions/checkout@v2

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
### Usage
5151

5252
```sh
53-
$ npx preact-cli create <template-name> <project-name>
53+
$ npm init preact-cli <template-name> <project-name>
54+
55+
$ yarn create preact-cli <template-name> <project-name>
5456
```
5557

5658
> **Note**
@@ -64,7 +66,7 @@ $ npx preact-cli create <template-name> <project-name>
6466
Example:
6567
6668
```sh
67-
$ npx preact-cli create default my-project
69+
$ npm init preact-cli default my-project
6870
```
6971
7072
The above command pulls the template from [preactjs-templates/default], prompts for some information, and generates the project at `./my-project/`.
@@ -73,7 +75,7 @@ The above command pulls the template from [preactjs-templates/default], prompts
7375

7476
The purpose of official preact project templates are to provide opinionated development tooling setups so that users can get started with actual app code as fast as possible. However, these templates are un-opinionated in terms of how you structure your app code and what libraries you use in addition to preact.js.
7577

76-
All official project templates are repos in the [preactjs-templates organization]. When a new template is added to the organization, you will be able to run `npx preact-cli create <template-name> <project-name>` to use that template.
78+
All official project templates are repos in the [preactjs-templates organization]. When a new template is added to the organization, you will be able to run `npm init preact-cli <template-name> <project-name>` to use that template.
7779

7880
Current available templates include:
7981

@@ -89,35 +91,40 @@ Current available templates include:
8991

9092
- [widget-typescript] - Widget template implemented in TypeScript
9193

92-
> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template: <br /> `npx preact-cli create <username>/<repository> <project-name>`
94+
> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template: <br /> `npm init preact-cli <username>/<repository> <project-name>`
9395
9496
### CLI Options
9597

98+
#### preact list
99+
100+
Lists all the official preactjs-cli repositories
101+
102+
```sh
103+
$ [npm init / yarn create] preact-cli list
104+
```
105+
96106
#### preact create
97107

98108
Create a project to quick start development.
99109

100110
```
101-
$ npx preact-cli create <template-name> <project-name>
111+
$ [npm init / yarn create] preact-cli <template-name> <project-name>
102112
103113
--name The application name.
104114
--cwd A directory to use instead of $PWD.
105115
--force Force option to create the directory for the new app [boolean] [default: false]
106-
--yarn Installs dependencies with yarn. [boolean] [default: false]
107116
--git Initialize version control using git. [boolean] [default: false]
108117
--install Installs dependencies. [boolean] [default: true]
109118
```
110119

111-
Note: If you don't specify enough data to the `npx preact-cli create` command, it will prompt the required questions.
112-
113120
#### preact build
114121

115122
Create a production build
116123

117124
You can disable `default: true` flags by prefixing them with `--no-<option>`; for example, `--no-sw`, `--no-prerender`, and `--no-inline-css`.
118125

119126
```
120-
$ preact build
127+
$ [npm run / yarn] preact build
121128
122129
--src Specify source directory (default src)
123130
--dest Specify output directory (default build)
@@ -142,7 +149,7 @@ $ preact build
142149
Spin up a development server with multiple features like `hot-module-replacement`, `module-watcher`
143150

144151
```
145-
$ preact watch
152+
$ [npm run / yarn] preact watch
146153
147154
--src Specify source directory (default src)
148155
--cwd A directory to use instead of $PWD (default .)
@@ -169,18 +176,14 @@ Note:
169176
1. You can run dev server using `HTTPS` then you can use the following `HTTPS=true preact watch`
170177
2. You can run the dev server on a different port using `PORT=8091 preact watch`
171178

172-
#### preact list
179+
#### preact info
173180

174-
Lists all the official preactjs-cli repositories
181+
Prints debugging information concerning the local environment.
175182

176183
```sh
177-
$ preact list
184+
$ [npm run / yarn] preact info
178185
```
179186

180-
#### preact info
181-
182-
Prints debugging information concerning the local environment.
183-
184187
### Pre-rendering
185188

186189
Preact CLI in order to follow [PRPL] pattern renders initial route (`/`) into generated static `index.html` - this ensures that users get to see your page before any JavaScript is run, and thus providing users with slow devices or poor connection your website's content much faster.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"packages/*"
55
],
66
"scripts": {
7+
"cli": "yarn workspace preact-cli",
8+
"create-cli": "yarn workspace create-preact-cli",
79
"pretest": "yarn lint",
810
"test": "run-p test:*",
9-
"test:cli": "yarn workspace preact-cli test",
11+
"test:cli": "yarn cli test",
12+
"test:create-cli": "yarn create-cli test",
1013
"prettier": "prettier --write **/*.{js,ts,tsx,json,css,scss,md,yml}",
1114
"lint": "eslint .",
1215
"changeset": "changeset",
@@ -25,13 +28,15 @@
2528
"devDependencies": {
2629
"@changesets/changelog-github": "^0.4.0",
2730
"@changesets/cli": "^2.16.0",
31+
"@types/jest": "^24.9.1",
2832
"babel-eslint": "^10.0.1",
2933
"eslint": "^7.24.0",
3034
"eslint-config-prettier": "^8.2.0",
3135
"eslint-plugin-babel": "^5.3.0",
3236
"eslint-plugin-prettier": "^3.4.0",
3337
"eslint-plugin-react": "^7.23.2",
3438
"husky": "^6.0.0",
39+
"jest": "^24.9.0",
3540
"lint-staged": "^11.0.0",
3641
"ncp": "^2.0.0",
3742
"npm-run-all": "^4.1.5",

packages/cli/package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"keywords": [
66
"preact",
77
"cli",
8-
"pwa",
9-
"project",
10-
"generator"
8+
"pwa"
119
],
1210
"homepage": "https://github.com/preactjs/preact-cli",
1311
"bugs": "https://github.com/preactjs/preact-cli/issues",
@@ -52,7 +50,6 @@
5250
"console-clear": "^1.0.0",
5351
"copy-webpack-plugin": "^9.1.0",
5452
"critters-webpack-plugin": "^3.0.2",
55-
"cross-spawn-promise": "^0.10.1",
5653
"css-loader": "^6.6.0",
5754
"css-minimizer-webpack-plugin": "3.4.1",
5855
"dotenv": "^16.0.0",
@@ -61,8 +58,6 @@
6158
"esm": "^3.2.25",
6259
"fork-ts-checker-webpack-plugin": "^7.1.1",
6360
"get-port": "^5.0.0",
64-
"gittar": "^0.1.0",
65-
"glob": "^8.0.3",
6661
"html-webpack-plugin": "^5.5.0",
6762
"html-webpack-skip-assets-plugin": "1.0.3",
6863
"ip": "^1.1.8",
@@ -72,13 +67,11 @@
7267
"minimatch": "^3.0.3",
7368
"native-url": "0.3.4",
7469
"optimize-plugin": "^1.3.1",
75-
"ora": "^5.4.1",
7670
"postcss": "^8.4.13",
7771
"postcss-load-config": "^3.1.4",
7872
"postcss-loader": "^6.2.1",
7973
"progress-bar-webpack-plugin": "^2.1.0",
8074
"promise-polyfill": "^8.2.3",
81-
"prompts": "^2.4.2",
8275
"react-refresh": "0.11.0",
8376
"rimraf": "^3.0.2",
8477
"sade": "^1.8.1",
@@ -89,14 +82,12 @@
8982
"style-loader": "^3.3.1",
9083
"terser-webpack-plugin": "^5.3.0",
9184
"update-notifier": "^5.1.0",
92-
"validate-npm-package-name": "^4.0.0",
9385
"webpack": "^5.67.0",
9486
"webpack-bundle-analyzer": "^4.5.0",
9587
"webpack-dev-server": "^4.9.0",
9688
"webpack-manifest-plugin": "^5.0.0",
9789
"webpack-merge": "^5.8.0",
9890
"webpack-remove-empty-scripts": "^0.7.2",
99-
"which": "^2.0.2",
10091
"workbox-cacheable-response": "^6.5.3",
10192
"workbox-core": "^6.5.3",
10293
"workbox-precaching": "^6.5.3",
@@ -106,9 +97,8 @@
10697
},
10798
"devDependencies": {
10899
"@types/express": "^4.17.13",
109-
"@types/jest": "^24.9.1",
100+
"glob": "^8.0.3",
110101
"html-looks-like": "^1.0.2",
111-
"jest": "^24.9.0",
112102
"less": "^4.1.3",
113103
"less-loader": "^10.2.0",
114104
"ncp": "^2.0.0",

0 commit comments

Comments
 (0)