Skip to content

Commit e8e505b

Browse files
test: migrate tests to .mts, add branch coverage cases, adjust coverage script
1 parent 1633789 commit e8e505b

21 files changed

Lines changed: 1475 additions & 1018 deletions

File tree

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,45 @@ jobs:
5050
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
5151
name: Pull Request Validation
5252
uses: ./.github/workflows/pr-review.yml
53+
54+
tests:
55+
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
56+
name: Unit Tests
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
- name: Setup Node 22
61+
uses: actions/setup-node@v4
62+
with:
63+
node-version: 22
64+
cache: npm
65+
- name: Install
66+
run: npm ci
67+
- name: Build
68+
run: npm run build --if-present
69+
- name: Run tests
70+
run: npm test
71+
72+
coverage:
73+
needs: tests
74+
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
75+
name: Coverage
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v4
79+
- name: Setup Node 22
80+
uses: actions/setup-node@v4
81+
with:
82+
node-version: 22
83+
cache: npm
84+
- name: Install
85+
run: npm ci
86+
- name: Run coverage
87+
run: CNA_SKIP_GIT=1 npm run test:coverage
88+
- name: Upload coverage artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: coverage-lcov
92+
path: |
93+
coverage
94+
lcov.info

.github/workflows/test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
unit-tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node 22
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
cache: "npm"
22+
23+
- name: Install
24+
run: npm ci
25+
26+
- name: Build
27+
run: npm run build --if-present
28+
29+
- name: Run tests
30+
run: npm test
31+
32+
coverage:
33+
needs: unit-tests
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
- name: Setup Node 22
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
cache: npm
43+
- name: Install
44+
run: npm ci
45+
- name: Run coverage
46+
run: CNA_SKIP_GIT=1 npm run test:coverage
47+
- name: Upload coverage artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: coverage-lcov
51+
path: |
52+
coverage
53+
lcov.info

README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,155 @@ npm run build -- --filter create-awesome-node-app
5555
./packages/create-awesome-node-app/index.js my-app
5656
```
5757

58+
### More Usage Examples
59+
60+
Below are additional real-world examples leveraging the public templates catalog and local `file://` paths.
61+
62+
#### 1. Use a catalog template by slug (non-interactive)
63+
64+
Create a React + Vite project (slug: `react-vite-boilerplate`):
65+
66+
```sh
67+
npx create-awesome-node-app my-react-app -t react-vite-boilerplate
68+
```
69+
70+
Create a NestJS API (slug: `nestjs-boilerplate`):
71+
72+
```sh
73+
npx create-awesome-node-app my-nest-api -t nestjs-boilerplate
74+
```
75+
76+
Create a Next.js full‑stack app (slug: `nextjs-starter`) with a custom `srcDir` override:
77+
78+
```sh
79+
npx create-awesome-node-app my-next --template nextjs-starter --srcDir app
80+
```
81+
82+
#### 2. Add extensions (addons) by slug
83+
84+
React project with Tailwind CSS + Zustand state management (extensions `tailwind-css` and `zustand`):
85+
86+
```sh
87+
npx create-awesome-node-app my-react-app -t react-vite-boilerplate --addons tailwind-css zustand
88+
```
89+
90+
NestJS project with Drizzle (PostgreSQL) + OpenAPI docs:
91+
92+
```sh
93+
npx create-awesome-node-app my-nest-api -t nestjs-boilerplate --addons drizzle-orm-postgresql openapi
94+
```
95+
96+
#### 3. Mix template + explicit extension URLs
97+
98+
You can always pass full GitHub URLs (they can include `/tree/<branch>/<subdir>`):
99+
100+
```sh
101+
npx create-awesome-node-app my-app \
102+
-t https://github.com/Create-Node-App/cna-templates/tree/main/templates/react-vite-starter \
103+
--addons https://github.com/Create-Node-App/cna-templates/tree/main/extensions/react-query
104+
```
105+
106+
#### 4. Local development with `file://` URLs (templates & extensions)
107+
108+
When iterating on your own template or extension locally, point the CLI to a folder on disk. This is useful while building new starters before publishing.
109+
110+
Supported forms:
111+
112+
```sh
113+
# Basic local template (directory contains a template/ or direct files)
114+
npx create-awesome-node-app local-app \
115+
-t file:///absolute/path/to/my-template
116+
117+
# Local template selecting a subdirectory (instead of putting /tree/<branch>/<subdir>)
118+
npx create-awesome-node-app local-app \
119+
-t "file:///absolute/path/to/monorepo?subdir=templates/react-vite-starter"
120+
121+
# Combine a local template with a local extension
122+
npx create-awesome-node-app local-app \
123+
-t file:///absolute/path/to/my-template \
124+
--addons file:///absolute/path/to/my-extension
125+
```
126+
127+
Notes for local usage:
128+
129+
- `file://` templates do not perform any git clone; files are read directly from disk.
130+
- Optional query `?subdir=relative/path` lets you target a nested directory inside a local repo.
131+
- You can add `?ignorePackage=true` to ignore a template's `package.json` (useful when only copying files).
132+
133+
#### 5. Append additional extensions with `--extend`
134+
135+
`--extend` appends more raw URLs or slugs after initial template + addons resolution (handy for layering):
136+
137+
```sh
138+
npx create-awesome-node-app layered-app \
139+
-t react-vite-boilerplate \
140+
--addons tailwind-css \
141+
--extend https://github.com/Create-Node-App/cna-templates/tree/main/extensions/react-hook-form
142+
```
143+
144+
#### 6. Verbose mode for debugging
145+
146+
Add `--verbose` to see template resolution, first discovered file, prepared operations count, and copy/append actions:
147+
148+
```sh
149+
npx create-awesome-node-app debug-app -t react-vite-boilerplate --verbose
150+
```
151+
152+
### Template Catalog Reference (Excerpt)
153+
154+
Some popular template slugs available right now:
155+
156+
| Slug | Description |
157+
| --------------------------------- | ------------------------------------ |
158+
| `react-vite-boilerplate` | React + Vite + TypeScript + Router |
159+
| `nextjs-starter` | Production-ready Next.js starter |
160+
| `nestjs-boilerplate` | Scalable NestJS backend |
161+
| `turborepo-boilerplate` | Monorepo with Turborepo + Changesets |
162+
| `web-extension-react-boilerplate` | React WebExtension with Vite |
163+
| `webdriverio-boilerplate` | WebdriverIO testing setup |
164+
165+
(Full catalog fetched from: `https://raw.githubusercontent.com/Create-Node-App/cna-templates/main/templates.json`.)
166+
167+
### Extension Slug Examples (React)
168+
169+
| Slug | Purpose |
170+
| ------------------------------------ | ------------------------------------- |
171+
| `tailwind-css` | Tailwind CSS utility-first styling |
172+
| `zustand` | Lightweight state management |
173+
| `react-query` (tanstack-react-query) | Async server state management |
174+
| `react-i18n` | Internationalization setup |
175+
| `shadcn-ui` | Radix + Tailwind component primitives |
176+
| `material-ui` | MUI component library |
177+
178+
You can combine multiple in one command via `--addons`.
179+
180+
### Ignoring `package.json` from a template
181+
182+
If you only want the file structure (not the template's `package.json`), append `?ignorePackage=true`:
183+
184+
```sh
185+
npx create-awesome-node-app structure-only \
186+
-t "https://github.com/Create-Node-App/cna-templates/tree/main/templates/react-vite-starter?ignorePackage=true"
187+
```
188+
189+
### Using a Different Source Directory
190+
191+
Most templates expose a `srcDir` custom option. Override it like this:
192+
193+
```sh
194+
npx create-awesome-node-app custom-src -t react-vite-boilerplate --srcDir app
195+
```
196+
197+
### Import Path Alias
198+
199+
Likewise override the import alias (defaults often `@/`):
200+
201+
```sh
202+
npx create-awesome-node-app custom-alias -t react-vite-boilerplate --projectImportPath "~/"
203+
```
204+
205+
---
206+
58207
## 🤝 Contributing
59208

60209
- Contributions make the open source community such an amazing place to learn, inspire, and create.

0 commit comments

Comments
 (0)