|
1 | | -# template-ts [](https://github.com/nice-winter/template-ts/actions/workflows/ci.yml) |
| 1 | +# @pkgtools/init [](https://github.com/pkgtoolsjs/init/actions/workflows/ci.yml) |
2 | 2 |
|
3 | | -A Node.js template with TypeScript and ES Module support. It is designed for quickly initializing an empty TypeScript project, with pre-configured support for [oxlint](https://oxc.rs/docs/guide/usage/linter.html) for code linting, [tsdown](https://tsdown.dev/) for JavaScript bundling, and VSCode debugging. |
4 | | - |
5 | | -It also comes with pre-configured CI/CD workflows based on GitHub Actions, making it suitable for rapid library development or quick prototyping, without the need to set everything up from scratch. |
6 | | - |
7 | | -Projects initialized with this template are recommended to be developed in [VS Code](https://code.visualstudio.com). |
8 | | - |
9 | | -## Features |
10 | | - |
11 | | -- ✅ ES Module support. |
12 | | -- 🩹 Linting and formatting with Git hooks. |
13 | | -- 📝 Automatically watches for file changes and restarts. |
14 | | -- 🐞 VS Code debugging support. |
15 | | -- 📦 Bundles JavaScript using [tsdown](https://tsdown.dev/). |
16 | | -- 🚀 CI/CD integration. |
17 | | - |
18 | | -## Environment Requirements |
19 | | - |
20 | | -- **Node.js**: Requires >= **22.0.0**. |
21 | | - |
22 | | -## Usage |
23 | | - |
24 | | -### Initialization |
25 | | - |
26 | | -Click the `Use this template` button at the top-right and set a name for the new repository, |
27 | | - |
28 | | -or directly clone this repository to your local machine: |
29 | | - |
30 | | -```bash |
31 | | -# Use the `degit` command to clone the template repository to your local machine. |
32 | | -npx degit nice-winter/template-ts my-project |
33 | | - |
34 | | -# Enter the project directory and install dependencies. |
35 | | -cd my-project |
36 | | -npm i |
37 | | - |
38 | | -# Start and watch for file changes. |
39 | | -npm run dev |
40 | | -``` |
41 | | - |
42 | | -### Develop and build |
43 | | - |
44 | | -Start and watch for file changes: |
45 | | - |
46 | | -```bash |
47 | | -npm run dev |
48 | | -``` |
49 | | - |
50 | | -Linting & Formatting: |
51 | | - |
52 | | -```bash |
53 | | -# lint |
54 | | -npm run lint |
55 | | - |
56 | | -# format |
57 | | -npm run format |
58 | | -``` |
59 | | - |
60 | | -Bundling to JavaScript: |
61 | | - |
62 | | -```bash |
63 | | -# build for production |
64 | | -npm run build |
65 | | -``` |
66 | | - |
67 | | -The JavaScript files will output to `dist` . |
68 | | - |
69 | | -### CI/CD |
70 | | - |
71 | | -This template comes with the following pre-configured workflows: |
72 | | - |
73 | | -- **ci**: Triggered on any push or when a PR is opened to the `main` branch. |
74 | | - It runs a series of unit tests and builds the project. |
75 | | - |
76 | | -- **release**: Triggered when a tag is pushed with the format `v*`. |
77 | | - It automatically creates a release in the repository and applies the corresponding tag. |
78 | | - |
79 | | -- **publish**: Triggered when a tag is pushed with the format `v*`. |
80 | | - It runs unit tests and builds the project before publishing it to NPM. |
81 | | - |
82 | | -**However, you need to adjust the following configurations for publish to work properly.** |
83 | | - |
84 | | -1.You need to add your `NPM_TOKEN` to the secrets in the repository settings. |
85 | | - |
86 | | -2.To prevent accidental publishing, the template project's package.json has private set to true by default. To publish your package, you must change `private` from true to `false` in package.json: |
87 | | - |
88 | | -```diff |
89 | | -{ |
90 | | - "name": "@nice-winter/template-ts", |
91 | | - "description": "...", |
92 | | - "version": "1.0.0", |
93 | | -- "private": true, |
94 | | -+ "private": false, |
95 | | - // ...Other keys... |
96 | | -} |
97 | | -``` |
98 | | - |
99 | | -3.Update the `repository.url` field in package.json to **your repository URL**: |
100 | | - |
101 | | -⚠️ **Note:** The publish workflow enables [Generating provenance statements](https://docs.npmjs.com/generating-provenance-statements) by default when publishing to NPM. You need to update the `repository.url` field in package.json to your own repository URL, otherwise, it will cause an error. |
102 | | - |
103 | | -```diff |
104 | | -{ |
105 | | - "author": "...", |
106 | | - "repository": { |
107 | | -- "url": "git+https://github.com/nice-winter/template-ts.git" |
108 | | -+ "url": "git+https://github.com/yourname/your-repository.git" |
109 | | - }, |
110 | | - "license": "MIT", |
111 | | - "dependencies": {}, |
112 | | - // ...Other keys... |
113 | | -} |
114 | | -``` |
115 | | - |
116 | | -Only then will the "Publish package" workflow be triggered. Otherwise, it will not be published to NPM. |
| 3 | +Initialize a Node.js project. |
117 | 4 |
|
118 | 5 | ## License |
119 | 6 |
|
|
0 commit comments