From d3e759558d2c33525a29e14daaa9f5b0c742faea Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Sun, 24 Jul 2022 23:05:48 -0500 Subject: [PATCH] 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 --- .changeset/tiny-garlics-argue.md | 14 + .github/workflows/ci.yml | 2 +- README.md | 37 +- package.json | 4 + packages/cli/global.d.ts | 9 + packages/cli/lib/commands/create.js | 440 ------------------ packages/cli/lib/commands/index.js | 5 - packages/cli/lib/constants.js | 44 -- packages/cli/lib/index.js | 10 - packages/cli/lib/lib/setup.js | 65 --- packages/cli/lib/util.js | 25 - packages/cli/package.json | 10 +- packages/cli/tests/create.test.js | 43 -- packages/cli/tests/images/build.js | 24 +- packages/cli/tests/lib/cli.js | 11 +- packages/cli/tests/service-worker.test.js | 1 + packages/create-cli/package.json | 36 ++ packages/create-cli/src/commands/create.js | 145 ++++++ .../lib => create-cli/src}/commands/list.js | 0 packages/create-cli/src/index.js | 31 ++ packages/create-cli/src/resources/sw.js | 4 + .../create-cli/src/resources/template.html | 15 + packages/create-cli/src/util.js | 50 ++ packages/create-cli/tests/.eslintrc | 9 + packages/create-cli/tests/create.test.js | 26 ++ .../tests/images/create.js | 0 yarn.lock | 23 +- 27 files changed, 386 insertions(+), 697 deletions(-) create mode 100644 .changeset/tiny-garlics-argue.md delete mode 100644 packages/cli/lib/commands/create.js delete mode 100644 packages/cli/lib/constants.js delete mode 100644 packages/cli/lib/lib/setup.js delete mode 100644 packages/cli/tests/create.test.js create mode 100644 packages/create-cli/package.json create mode 100644 packages/create-cli/src/commands/create.js rename packages/{cli/lib => create-cli/src}/commands/list.js (100%) create mode 100755 packages/create-cli/src/index.js create mode 100644 packages/create-cli/src/resources/sw.js create mode 100644 packages/create-cli/src/resources/template.html create mode 100644 packages/create-cli/src/util.js create mode 100644 packages/create-cli/tests/.eslintrc create mode 100644 packages/create-cli/tests/create.test.js rename packages/{cli => create-cli}/tests/images/create.js (100%) diff --git a/.changeset/tiny-garlics-argue.md b/.changeset/tiny-garlics-argue.md new file mode 100644 index 000000000..4a11690db --- /dev/null +++ b/.changeset/tiny-garlics-argue.md @@ -0,0 +1,14 @@ +--- +'preact-cli': major +'create-preact-cli': major +--- + +Extracts project creation functionality from `preact-cli` into `create-preact-cli` + +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. + +By extracting project initialization into its own package, we can provide much, much faster project setup times. + +To setup a new project, users will use `npm init preact-cli ...` or `yarn create preact-cli ...`. + +Additionally, the `--yarn` flag has been removed in favour of using the yarn initializer (`yarn create`). diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 147ad9650..3b6c79ebc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x, 14.x] + node-version: [14.x, 16.x] steps: - uses: actions/checkout@v2 with: diff --git a/README.md b/README.md index 084651231..13ea794e8 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,15 @@ ### Usage ```sh -$ npx preact-cli create +$ npm init preact-cli + +$ yarn create preact-cli ``` Example: ```sh -$ npx preact-cli create default my-project +$ npm init preact-cli default my-project ``` 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 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. -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 ` to use that template. +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 ` to use that template. Current available templates include: @@ -81,27 +83,32 @@ Current available templates include: - [widget-typescript] - Widget template implemented in TypeScript -> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template:
`npx preact-cli create / ` +> 💁 Tip: Any Github repo with a `'template'` folder can be used as a custom template:
`npm init preact-cli / ` ### CLI Options +#### preact list + +Lists all the official preactjs-cli repositories + +```sh +$ [npm init / yarn create] preact-cli list +``` + #### preact create Create a project to quick start development. ``` -$ npx preact-cli create +$ [npm init / yarn create] preact-cli --name The application name. --cwd A directory to use instead of $PWD. --force Force option to create the directory for the new app [boolean] [default: false] - --yarn Installs dependencies with yarn. [boolean] [default: false] --git Initialize version control using git. [boolean] [default: false] --install Installs dependencies. [boolean] [default: true] ``` -Note: If you don't specify enough data to the `npx preact-cli create` command, it will prompt the required questions. - #### preact build Create a production build @@ -109,7 +116,7 @@ Create a production build You can disable `default: true` flags by prefixing them with `--no-