Skip to content

Commit 75d0bda

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 3e183fd commit 75d0bda

File tree

24 files changed

+369
-634
lines changed

24 files changed

+369
-634
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
@@ -19,7 +19,7 @@ jobs:
1919
timeout-minutes: 10
2020
strategy:
2121
matrix:
22-
node-version: [12.x, 14.x]
22+
node-version: [14.x, 16.x]
2323
steps:
2424
- uses: actions/checkout@v2
2525
with:

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@
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
Example:
5759

5860
```sh
59-
$ npx preact-cli create default my-project
61+
$ npm init preact-cli default my-project
6062
```
6163

6264
The above command pulls the template from [preactjs-templates/default], prompts for some information, and generates the project at `./my-project/`.
@@ -65,7 +67,7 @@ The above command pulls the template from [preactjs-templates/default], prompts
6567

6668
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.
6769

68-
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.
70+
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.
6971

7072
Current available templates include:
7173

@@ -81,35 +83,40 @@ Current available templates include:
8183

8284
- [widget-typescript] - Widget template implemented in TypeScript
8385

84-
> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template: <br /> `npx preact-cli create <username>/<repository> <project-name>`
86+
> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template: <br /> `npm init preact-cli <username>/<repository> <project-name>`
8587
8688
### CLI Options
8789

90+
#### preact list
91+
92+
Lists all the official preactjs-cli repositories
93+
94+
```sh
95+
$ [npm init / yarn create] preact-cli list
96+
```
97+
8898
#### preact create
8999

90100
Create a project to quick start development.
91101

92102
```
93-
$ npx preact-cli create <template-name> <project-name>
103+
$ [npm init / yarn create] preact-cli <template-name> <project-name>
94104
95105
--name The application name.
96106
--cwd A directory to use instead of $PWD.
97107
--force Force option to create the directory for the new app [boolean] [default: false]
98-
--yarn Installs dependencies with yarn. [boolean] [default: false]
99108
--git Initialize version control using git. [boolean] [default: false]
100109
--install Installs dependencies. [boolean] [default: true]
101110
```
102111

103-
Note: If you don't specify enough data to the `npx preact-cli create` command, it will prompt the required questions.
104-
105112
#### preact build
106113

107114
Create a production build
108115

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

111118
```
112-
$ preact build
119+
$ [npm run / yarn] preact build
113120
114121
--src Specify source directory (default src)
115122
--dest Specify output directory (default build)
@@ -134,7 +141,7 @@ $ preact build
134141
Spin up a development server with multiple features like `hot-module-replacement`, `module-watcher`
135142

136143
```
137-
$ preact watch
144+
$ [npm run / yarn] preact watch
138145
139146
--src Specify source directory (default src)
140147
--cwd A directory to use instead of $PWD (default .)
@@ -161,18 +168,14 @@ Note:
161168
1. You can run dev server using `HTTPS` then you can use the following `HTTPS=true preact watch`
162169
2. You can run the dev server on a different port using `PORT=8091 preact watch`
163170

164-
#### preact list
171+
#### preact info
165172

166-
Lists all the official preactjs-cli repositories
173+
Prints debugging information concerning the local environment.
167174

168175
```sh
169-
$ preact list
176+
$ [npm run / yarn] preact info
170177
```
171178

172-
#### preact info
173-
174-
Prints debugging information concerning the local environment.
175-
176179
### Pre-rendering
177180

178181
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",
@@ -90,15 +83,13 @@
9083
"terser-webpack-plugin": "^5.3.0",
9184
"typescript": "^4.6.4",
9285
"update-notifier": "^5.1.0",
93-
"validate-npm-package-name": "^4.0.0",
9486
"webpack": "^5.67.0",
9587
"webpack-bundle-analyzer": "^4.5.0",
9688
"webpack-dev-server": "^4.9.0",
9789
"webpack-manifest-plugin": "^5.0.0",
9890
"webpack-merge": "^5.8.0",
9991
"webpack-plugin-replace": "^1.2.0",
10092
"webpack-remove-empty-scripts": "^0.7.2",
101-
"which": "^2.0.2",
10293
"workbox-cacheable-response": "^6.5.3",
10394
"workbox-core": "^6.5.3",
10495
"workbox-precaching": "^6.5.3",
@@ -108,9 +99,8 @@
10899
},
109100
"devDependencies": {
110101
"@types/express": "^4.17.13",
111-
"@types/jest": "^24.9.1",
102+
"glob": "^8.0.3",
112103
"html-looks-like": "^1.0.2",
113-
"jest": "^24.9.0",
114104
"less": "^4.1.3",
115105
"less-loader": "^10.2.0",
116106
"ncp": "^2.0.0",

0 commit comments

Comments
 (0)