ts-builds 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +2 -0
- package/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/cli.js +168 -0
- package/dist/tsdown.config.base.js +15 -0
- package/dist/vitest.config.base.js +26 -0
- package/eslint.config.base.mjs +76 -0
- package/package-scripts.json +96 -0
- package/package.json +90 -0
- package/prettier-config.js +12 -0
- package/templates/npmrc +7 -0
- package/tsconfig.base.json +18 -0
package/.prettierignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jordan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# ts-builds
|
|
2
|
+
|
|
3
|
+
[](https://github.com/jordanburke/ts-builds/actions/workflows/node.js.yml)
|
|
4
|
+
|
|
5
|
+
Shared TypeScript configuration files for library templates. Provides standardized ESLint, Prettier, Vitest, TypeScript, and build configs.
|
|
6
|
+
|
|
7
|
+
## 📦 What's Included
|
|
8
|
+
|
|
9
|
+
This package provides base configuration files for TypeScript library templates:
|
|
10
|
+
|
|
11
|
+
### Locked Configs (Use As-Is)
|
|
12
|
+
|
|
13
|
+
- **`.prettierrc`** - Code formatting rules
|
|
14
|
+
- **`.prettierignore`** - Files to ignore from formatting
|
|
15
|
+
|
|
16
|
+
### Extendable Configs (Can Be Customized)
|
|
17
|
+
|
|
18
|
+
- **`eslint.config.base.mjs`** - Base ESLint rules + TypeScript support
|
|
19
|
+
- **`vitest.config.base.ts`** - Vitest test framework configuration
|
|
20
|
+
- **`tsconfig.base.json`** - TypeScript compiler base settings
|
|
21
|
+
- **`tsdown.config.base.ts`** - Build configuration for tsdown
|
|
22
|
+
- **`package-scripts.json`** - Standardized npm scripts reference
|
|
23
|
+
|
|
24
|
+
## 🚀 Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add -D ts-builds
|
|
28
|
+
|
|
29
|
+
# Also install peer dependency:
|
|
30
|
+
pnpm add -D tsdown
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🛠️ CLI Commands
|
|
34
|
+
|
|
35
|
+
### Initialize Project
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx ts-builds
|
|
39
|
+
# or
|
|
40
|
+
npx ts-builds init
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Creates `.npmrc` to configure pnpm to hoist CLI binaries from peer dependencies.
|
|
44
|
+
|
|
45
|
+
### Show Help
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx ts-builds help
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### List Bundled Packages
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx ts-builds info
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Shows all 19 packages bundled with this config (eslint, prettier, typescript, vitest, etc.) that you **don't need to install separately**.
|
|
58
|
+
|
|
59
|
+
### Remove Redundant Dependencies
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx ts-builds cleanup
|
|
63
|
+
# or auto-confirm with
|
|
64
|
+
npx ts-builds cleanup --yes
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Scans your `package.json` and removes any devDependencies that are already bundled with `ts-builds`.
|
|
68
|
+
|
|
69
|
+
### Minimal Installation
|
|
70
|
+
|
|
71
|
+
Since this package bundles all tooling, you only need:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"ts-builds": "^1.0.0",
|
|
77
|
+
"tsdown": "^0.12.0"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**For local development** (testing before publishing):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Build first, then test
|
|
86
|
+
pnpm build
|
|
87
|
+
node dist/cli.js help
|
|
88
|
+
|
|
89
|
+
# Or link globally
|
|
90
|
+
pnpm link --global
|
|
91
|
+
ts-builds help
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 📖 Usage
|
|
95
|
+
|
|
96
|
+
### Prettier (Locked - Use Exact Copy)
|
|
97
|
+
|
|
98
|
+
Copy the Prettier config to your project root:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
cp node_modules/ts-builds/.prettierrc .
|
|
102
|
+
cp node_modules/ts-builds/.prettierignore .
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or reference it in your `package.json`:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"prettier": "ts-builds/prettier"
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### ESLint (Extendable)
|
|
114
|
+
|
|
115
|
+
**Basic usage (inherit all base rules):**
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
// eslint.config.mjs
|
|
119
|
+
import baseConfig from "ts-builds/eslint"
|
|
120
|
+
|
|
121
|
+
export default [...baseConfig]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Extended usage (add variant-specific rules):**
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
// eslint.config.mjs
|
|
128
|
+
import baseConfig from "ts-builds/eslint"
|
|
129
|
+
|
|
130
|
+
export default [
|
|
131
|
+
...baseConfig,
|
|
132
|
+
{
|
|
133
|
+
// React-specific rules
|
|
134
|
+
files: ["**/*.tsx"],
|
|
135
|
+
rules: {
|
|
136
|
+
"react/jsx-uses-react": "error",
|
|
137
|
+
"react-hooks/rules-of-hooks": "error",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Vitest (Extendable)
|
|
144
|
+
|
|
145
|
+
**Basic usage:**
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
// vitest.config.ts
|
|
149
|
+
import { defineConfig } from "vitest/config"
|
|
150
|
+
import baseConfig from "ts-builds/vitest"
|
|
151
|
+
|
|
152
|
+
export default defineConfig(baseConfig)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Extended usage:**
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// vitest.config.ts
|
|
159
|
+
import { defineConfig } from "vitest/config"
|
|
160
|
+
import baseConfig from "ts-builds/vitest"
|
|
161
|
+
|
|
162
|
+
export default defineConfig({
|
|
163
|
+
...baseConfig,
|
|
164
|
+
test: {
|
|
165
|
+
...baseConfig.test,
|
|
166
|
+
setupFiles: ["./test/setup.ts"], // Add custom setup
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### TypeScript (Extendable)
|
|
172
|
+
|
|
173
|
+
**Basic usage:**
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"extends": "ts-builds/tsconfig",
|
|
178
|
+
"compilerOptions": {
|
|
179
|
+
"outDir": "./dist"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Extended usage:**
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"extends": "ts-builds/tsconfig",
|
|
189
|
+
"compilerOptions": {
|
|
190
|
+
"outDir": "./dist",
|
|
191
|
+
"jsx": "react-jsx",
|
|
192
|
+
"lib": ["ES2020", "DOM"]
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Tsdown (Extendable)
|
|
198
|
+
|
|
199
|
+
**Basic usage:**
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// tsdown.config.ts
|
|
203
|
+
import baseConfig from "ts-builds/tsdown"
|
|
204
|
+
|
|
205
|
+
export default baseConfig
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Extended usage (customize entry points):**
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// tsdown.config.ts
|
|
212
|
+
import baseConfig from "ts-builds/tsdown"
|
|
213
|
+
import type { UserConfig } from "tsdown"
|
|
214
|
+
|
|
215
|
+
export default {
|
|
216
|
+
...baseConfig,
|
|
217
|
+
entry: ["src/index.ts", "src/cli.ts"], // Multiple entry points
|
|
218
|
+
} satisfies UserConfig
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Package Scripts (Reference Only)
|
|
222
|
+
|
|
223
|
+
The `package-scripts.json` file contains standardized npm scripts. Copy the relevant scripts to your `package.json`:
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"scripts": {
|
|
228
|
+
"validate": "pnpm format && pnpm lint && pnpm test && pnpm build",
|
|
229
|
+
"format": "prettier --write .",
|
|
230
|
+
"format:check": "prettier --check .",
|
|
231
|
+
"lint": "eslint ./src --fix",
|
|
232
|
+
"lint:check": "eslint ./src",
|
|
233
|
+
"test": "vitest run",
|
|
234
|
+
"test:watch": "vitest",
|
|
235
|
+
"test:coverage": "vitest run --coverage",
|
|
236
|
+
"test:ui": "vitest --ui",
|
|
237
|
+
"build": "rimraf dist && cross-env NODE_ENV=production tsdown",
|
|
238
|
+
"build:watch": "tsdown --watch",
|
|
239
|
+
"dev": "tsdown --watch",
|
|
240
|
+
"prepublishOnly": "pnpm validate",
|
|
241
|
+
"ts-types": "tsc"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 🔄 Update Workflow
|
|
247
|
+
|
|
248
|
+
When configs are updated in this package, update your template:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Update to latest version
|
|
252
|
+
pnpm update ts-builds
|
|
253
|
+
|
|
254
|
+
# Re-copy locked files (Prettier)
|
|
255
|
+
cp node_modules/ts-builds/.prettierrc .
|
|
256
|
+
cp node_modules/ts-builds/.prettierignore .
|
|
257
|
+
|
|
258
|
+
# Test that everything still works
|
|
259
|
+
pnpm validate
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## 🎯 Design Philosophy
|
|
263
|
+
|
|
264
|
+
### Locked vs Extendable
|
|
265
|
+
|
|
266
|
+
**Locked files** ensure consistency across all templates:
|
|
267
|
+
|
|
268
|
+
- **Prettier** - Code formatting should be identical everywhere
|
|
269
|
+
- Prevents formatting debates and merge conflicts
|
|
270
|
+
|
|
271
|
+
**Extendable files** allow variant-specific customization:
|
|
272
|
+
|
|
273
|
+
- **ESLint** - Different variants need different rules (React, Node.js, etc.)
|
|
274
|
+
- **Vitest** - Some variants need custom test setup
|
|
275
|
+
- **TypeScript** - Browser vs Node targets, JSX support, etc.
|
|
276
|
+
- **Build configs** - Different entry points, output formats
|
|
277
|
+
|
|
278
|
+
### Semantic Versioning
|
|
279
|
+
|
|
280
|
+
This package follows semver:
|
|
281
|
+
|
|
282
|
+
- **Patch** (1.0.x) - Bug fixes in configs
|
|
283
|
+
- **Minor** (1.x.0) - New configs added, backward compatible
|
|
284
|
+
- **Major** (x.0.0) - Breaking changes to existing configs
|
|
285
|
+
|
|
286
|
+
## 📚 Available Template Variants
|
|
287
|
+
|
|
288
|
+
Templates using these configs:
|
|
289
|
+
|
|
290
|
+
- **[typescript-library-template](https://github.com/jordanburke/typescript-library-template)** - Base template (tsdown)
|
|
291
|
+
- **typescript-library-template-vite** - Vite-based variant (coming soon)
|
|
292
|
+
- **typescript-library-template-react** - React library variant (coming soon)
|
|
293
|
+
|
|
294
|
+
## 🤝 Contributing
|
|
295
|
+
|
|
296
|
+
Found a bug or want to improve the configs?
|
|
297
|
+
|
|
298
|
+
1. Fork this repository
|
|
299
|
+
2. Make your changes
|
|
300
|
+
3. Test in a template project
|
|
301
|
+
4. Submit a PR with explanation
|
|
302
|
+
|
|
303
|
+
## 📄 License
|
|
304
|
+
|
|
305
|
+
MIT © Jordan Burke
|
|
306
|
+
|
|
307
|
+
## 🔗 Related
|
|
308
|
+
|
|
309
|
+
- [STANDARDIZATION_GUIDE.md](./STANDARDIZATION_GUIDE.md) - How to apply this pattern
|
|
310
|
+
- [package-scripts.json](./package-scripts.json) - Script reference documentation
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
const templateDir = join(dirname(fileURLToPath(import.meta.url)), "..", "templates");
|
|
9
|
+
const targetDir = process.cwd();
|
|
10
|
+
const bundledPackages = [
|
|
11
|
+
"@eslint/eslintrc",
|
|
12
|
+
"@eslint/js",
|
|
13
|
+
"@typescript-eslint/eslint-plugin",
|
|
14
|
+
"@typescript-eslint/parser",
|
|
15
|
+
"@vitest/coverage-v8",
|
|
16
|
+
"@vitest/ui",
|
|
17
|
+
"cross-env",
|
|
18
|
+
"eslint",
|
|
19
|
+
"eslint-config-prettier",
|
|
20
|
+
"eslint-plugin-import",
|
|
21
|
+
"eslint-plugin-prettier",
|
|
22
|
+
"eslint-plugin-simple-import-sort",
|
|
23
|
+
"prettier",
|
|
24
|
+
"rimraf",
|
|
25
|
+
"ts-node",
|
|
26
|
+
"typescript",
|
|
27
|
+
"vitest"
|
|
28
|
+
];
|
|
29
|
+
const files = [{
|
|
30
|
+
src: "npmrc",
|
|
31
|
+
dest: ".npmrc"
|
|
32
|
+
}];
|
|
33
|
+
function showHelp() {
|
|
34
|
+
console.log(`
|
|
35
|
+
ts-builds - Shared TypeScript configuration files
|
|
36
|
+
|
|
37
|
+
USAGE:
|
|
38
|
+
npx ts-builds [command]
|
|
39
|
+
|
|
40
|
+
COMMANDS:
|
|
41
|
+
init Initialize project with config files (default)
|
|
42
|
+
info Show bundled packages you don't need to install
|
|
43
|
+
cleanup Remove redundant dependencies from package.json
|
|
44
|
+
help Show this help message
|
|
45
|
+
|
|
46
|
+
EXAMPLES:
|
|
47
|
+
npx ts-builds # Initialize project
|
|
48
|
+
npx ts-builds info # List bundled packages
|
|
49
|
+
npx ts-builds cleanup # Remove redundant deps
|
|
50
|
+
|
|
51
|
+
DESCRIPTION:
|
|
52
|
+
This package bundles all ESLint, Prettier, Vitest, and TypeScript
|
|
53
|
+
tooling as dependencies. You only need to install:
|
|
54
|
+
|
|
55
|
+
- ts-builds (this package)
|
|
56
|
+
- tsdown (peer dependency for building)
|
|
57
|
+
|
|
58
|
+
Run 'npx ts-builds info' to see the full list
|
|
59
|
+
of bundled packages.
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
function showInfo() {
|
|
63
|
+
console.log(`
|
|
64
|
+
ts-builds bundles these packages:
|
|
65
|
+
|
|
66
|
+
You DON'T need to install:
|
|
67
|
+
${bundledPackages.map((pkg) => ` - ${pkg}`).join("\n")}
|
|
68
|
+
|
|
69
|
+
You ONLY need to install:
|
|
70
|
+
- ts-builds (this package)
|
|
71
|
+
- tsdown (peer dependency, optional)
|
|
72
|
+
|
|
73
|
+
Example minimal package.json devDependencies:
|
|
74
|
+
{
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"ts-builds": "^3.0.0",
|
|
77
|
+
"tsdown": "^0.12.0"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
82
|
+
async function cleanup() {
|
|
83
|
+
const packageJsonPath = join(targetDir, "package.json");
|
|
84
|
+
if (!existsSync(packageJsonPath)) {
|
|
85
|
+
console.error("Error: No package.json found in current directory");
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
89
|
+
const devDeps = packageJson.devDependencies || {};
|
|
90
|
+
const deps = packageJson.dependencies || {};
|
|
91
|
+
const redundantDev = bundledPackages.filter((pkg) => pkg in devDeps);
|
|
92
|
+
const redundantDeps = bundledPackages.filter((pkg) => pkg in deps);
|
|
93
|
+
if (redundantDev.length === 0 && redundantDeps.length === 0) {
|
|
94
|
+
console.log("✓ No redundant packages found. Your package.json is clean!");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
console.log("\nFound redundant packages that are bundled with ts-builds:\n");
|
|
98
|
+
if (redundantDev.length > 0) {
|
|
99
|
+
console.log("devDependencies to remove:");
|
|
100
|
+
redundantDev.forEach((pkg) => console.log(` - ${pkg}`));
|
|
101
|
+
}
|
|
102
|
+
if (redundantDeps.length > 0) {
|
|
103
|
+
console.log("\ndependencies to remove:");
|
|
104
|
+
redundantDeps.forEach((pkg) => console.log(` - ${pkg}`));
|
|
105
|
+
}
|
|
106
|
+
if (!(process.argv.includes("--yes") || process.argv.includes("-y"))) {
|
|
107
|
+
const rl = createInterface({
|
|
108
|
+
input: process.stdin,
|
|
109
|
+
output: process.stdout
|
|
110
|
+
});
|
|
111
|
+
const answer = await new Promise((resolve) => {
|
|
112
|
+
rl.question("\nRemove these packages? (y/N) ", resolve);
|
|
113
|
+
});
|
|
114
|
+
rl.close();
|
|
115
|
+
if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
|
|
116
|
+
console.log("Cancelled.");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
redundantDev.forEach((pkg) => delete devDeps[pkg]);
|
|
121
|
+
redundantDeps.forEach((pkg) => delete deps[pkg]);
|
|
122
|
+
if (Object.keys(devDeps).length > 0) packageJson.devDependencies = devDeps;
|
|
123
|
+
else delete packageJson.devDependencies;
|
|
124
|
+
if (Object.keys(deps).length > 0) packageJson.dependencies = deps;
|
|
125
|
+
else delete packageJson.dependencies;
|
|
126
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
127
|
+
const totalRemoved = redundantDev.length + redundantDeps.length;
|
|
128
|
+
console.log(`\n✓ Removed ${totalRemoved} redundant package(s) from package.json`);
|
|
129
|
+
console.log("\nRun 'pnpm install' to update your lockfile.");
|
|
130
|
+
}
|
|
131
|
+
function init() {
|
|
132
|
+
console.log("Initializing ts-builds...");
|
|
133
|
+
for (const { src: srcFile, dest: destFile } of files) {
|
|
134
|
+
const src = join(templateDir, srcFile);
|
|
135
|
+
const dest = join(targetDir, destFile);
|
|
136
|
+
if (existsSync(dest)) console.log(` ⚠ ${destFile} already exists, skipping`);
|
|
137
|
+
else {
|
|
138
|
+
copyFileSync(src, dest);
|
|
139
|
+
console.log(` ✓ Created ${destFile}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
console.log("\nDone! Your project is configured to hoist CLI binaries from peer dependencies.");
|
|
143
|
+
console.log("\nNext steps:");
|
|
144
|
+
console.log(" - Run 'npx ts-builds info' to see bundled packages");
|
|
145
|
+
console.log(" - Run 'npx ts-builds cleanup' to remove redundant deps");
|
|
146
|
+
}
|
|
147
|
+
switch (process.argv[2] || "init") {
|
|
148
|
+
case "help":
|
|
149
|
+
case "--help":
|
|
150
|
+
case "-h":
|
|
151
|
+
showHelp();
|
|
152
|
+
break;
|
|
153
|
+
case "info":
|
|
154
|
+
case "--info":
|
|
155
|
+
showInfo();
|
|
156
|
+
break;
|
|
157
|
+
case "cleanup":
|
|
158
|
+
case "--cleanup":
|
|
159
|
+
await cleanup();
|
|
160
|
+
break;
|
|
161
|
+
case "init":
|
|
162
|
+
default:
|
|
163
|
+
init();
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
export { };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/tsdown.config.base.ts
|
|
2
|
+
const env = process.env.NODE_ENV;
|
|
3
|
+
const tsdown = {
|
|
4
|
+
sourcemap: true,
|
|
5
|
+
clean: true,
|
|
6
|
+
dts: true,
|
|
7
|
+
format: ["cjs", "esm"],
|
|
8
|
+
minify: env === "production",
|
|
9
|
+
target: "es2020",
|
|
10
|
+
outDir: env === "production" ? "dist" : "lib",
|
|
11
|
+
entry: ["src/index.ts", "src/**/*.ts"]
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { tsdown };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
//#region src/vitest.config.base.ts
|
|
4
|
+
var vitest_config_base_default = defineConfig({ test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
environment: "node",
|
|
7
|
+
include: ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: "v8",
|
|
10
|
+
reporter: [
|
|
11
|
+
"text",
|
|
12
|
+
"json",
|
|
13
|
+
"html"
|
|
14
|
+
],
|
|
15
|
+
exclude: [
|
|
16
|
+
"node_modules/",
|
|
17
|
+
"dist/",
|
|
18
|
+
"**/*.d.ts",
|
|
19
|
+
"**/*.test.{js,ts}",
|
|
20
|
+
"**/*.config.{js,ts}"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
} });
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { vitest_config_base_default as default };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
|
|
4
|
+
import { FlatCompat } from "@eslint/eslintrc"
|
|
5
|
+
import js from "@eslint/js"
|
|
6
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin"
|
|
7
|
+
import tsParser from "@typescript-eslint/parser"
|
|
8
|
+
import prettier from "eslint-plugin-prettier"
|
|
9
|
+
import simpleImportSort from "eslint-plugin-simple-import-sort"
|
|
10
|
+
import globals from "globals"
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
13
|
+
const __dirname = path.dirname(__filename)
|
|
14
|
+
const compat = new FlatCompat({
|
|
15
|
+
baseDirectory: __dirname,
|
|
16
|
+
recommendedConfig: js.configs.recommended,
|
|
17
|
+
allConfig: js.configs.all,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export default [
|
|
21
|
+
{
|
|
22
|
+
ignores: [
|
|
23
|
+
"**/.gitignore",
|
|
24
|
+
"**/.eslintignore",
|
|
25
|
+
"**/node_modules",
|
|
26
|
+
"**/.DS_Store",
|
|
27
|
+
"**/dist-ssr",
|
|
28
|
+
"**/*.local",
|
|
29
|
+
"**/tsconfig.json",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"),
|
|
33
|
+
{
|
|
34
|
+
plugins: {
|
|
35
|
+
"@typescript-eslint": typescriptEslint,
|
|
36
|
+
"simple-import-sort": simpleImportSort,
|
|
37
|
+
prettier,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
languageOptions: {
|
|
41
|
+
globals: {
|
|
42
|
+
...globals.browser,
|
|
43
|
+
...globals.amd,
|
|
44
|
+
...globals.node,
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
parser: tsParser,
|
|
48
|
+
ecmaVersion: 2020,
|
|
49
|
+
sourceType: "module",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
settings: {
|
|
53
|
+
"import/resolver": {
|
|
54
|
+
node: {
|
|
55
|
+
paths: ["'src'"],
|
|
56
|
+
extensions: [".js", ".ts"],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
rules: {
|
|
62
|
+
"prettier/prettier": [
|
|
63
|
+
"error",
|
|
64
|
+
{},
|
|
65
|
+
{
|
|
66
|
+
usePrettierrc: true,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
|
|
70
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
71
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
72
|
+
"simple-import-sort/imports": "error",
|
|
73
|
+
"simple-import-sort/exports": "error",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Standardized npm scripts for TypeScript library templates. Copy these to your package.json scripts section.",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"validate": {
|
|
5
|
+
"command": "pnpm format && pnpm lint && pnpm test && pnpm build",
|
|
6
|
+
"description": "Run all checks before committing (format, lint, test, build)",
|
|
7
|
+
"required": true
|
|
8
|
+
},
|
|
9
|
+
"format": {
|
|
10
|
+
"command": "prettier --write .",
|
|
11
|
+
"description": "Format all code with Prettier",
|
|
12
|
+
"required": true
|
|
13
|
+
},
|
|
14
|
+
"format:check": {
|
|
15
|
+
"command": "prettier --check .",
|
|
16
|
+
"description": "Check Prettier formatting without writing",
|
|
17
|
+
"required": true
|
|
18
|
+
},
|
|
19
|
+
"lint": {
|
|
20
|
+
"command": "eslint ./src --fix",
|
|
21
|
+
"description": "Lint and auto-fix with ESLint",
|
|
22
|
+
"required": true
|
|
23
|
+
},
|
|
24
|
+
"lint:check": {
|
|
25
|
+
"command": "eslint ./src",
|
|
26
|
+
"description": "Check ESLint without fixing",
|
|
27
|
+
"required": true
|
|
28
|
+
},
|
|
29
|
+
"test": {
|
|
30
|
+
"command": "vitest run",
|
|
31
|
+
"description": "Run tests once",
|
|
32
|
+
"required": true
|
|
33
|
+
},
|
|
34
|
+
"test:watch": {
|
|
35
|
+
"command": "vitest",
|
|
36
|
+
"description": "Run tests in watch mode",
|
|
37
|
+
"required": false
|
|
38
|
+
},
|
|
39
|
+
"test:coverage": {
|
|
40
|
+
"command": "vitest run --coverage",
|
|
41
|
+
"description": "Run tests with coverage report",
|
|
42
|
+
"required": false
|
|
43
|
+
},
|
|
44
|
+
"test:ui": {
|
|
45
|
+
"command": "vitest --ui",
|
|
46
|
+
"description": "Launch Vitest UI",
|
|
47
|
+
"required": false
|
|
48
|
+
},
|
|
49
|
+
"build": {
|
|
50
|
+
"command": "rimraf dist && cross-env NODE_ENV=production tsdown",
|
|
51
|
+
"description": "Production build (tsdown variant)",
|
|
52
|
+
"required": true,
|
|
53
|
+
"variants": {
|
|
54
|
+
"vite": "rimraf dist && vite build"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"build:watch": {
|
|
58
|
+
"command": "tsdown --watch",
|
|
59
|
+
"description": "Watch mode build (tsdown variant)",
|
|
60
|
+
"required": false,
|
|
61
|
+
"variants": {
|
|
62
|
+
"vite": "vite build --watch"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"dev": {
|
|
66
|
+
"command": "tsdown --watch",
|
|
67
|
+
"description": "Development mode (alias for build:watch)",
|
|
68
|
+
"required": false,
|
|
69
|
+
"variants": {
|
|
70
|
+
"vite": "vite build --watch"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"prepublishOnly": {
|
|
74
|
+
"command": "pnpm validate",
|
|
75
|
+
"description": "Auto-run validation before npm publish",
|
|
76
|
+
"required": true
|
|
77
|
+
},
|
|
78
|
+
"ts-types": {
|
|
79
|
+
"command": "tsc",
|
|
80
|
+
"description": "Type-check with TypeScript compiler",
|
|
81
|
+
"required": false
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"usage": {
|
|
85
|
+
"instructions": "Copy the scripts from the 'scripts' object above to your package.json. Adjust build commands based on your build tool (tsdown, vite, etc.). Scripts marked 'required: true' should be included in all templates.",
|
|
86
|
+
"example": {
|
|
87
|
+
"scripts": {
|
|
88
|
+
"validate": "pnpm format && pnpm lint && pnpm test && pnpm build",
|
|
89
|
+
"format": "prettier --write .",
|
|
90
|
+
"lint": "eslint ./src --fix",
|
|
91
|
+
"test": "vitest run",
|
|
92
|
+
"build": "rimraf dist && cross-env NODE_ENV=production tsdown"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-builds",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared TypeScript configuration files for library templates. Provides standardized ESLint, Prettier, Vitest, TypeScript, and build configs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"template",
|
|
8
|
+
"config",
|
|
9
|
+
"eslint",
|
|
10
|
+
"prettier",
|
|
11
|
+
"vitest",
|
|
12
|
+
"tsdown",
|
|
13
|
+
"shared-config"
|
|
14
|
+
],
|
|
15
|
+
"author": "jordan.burke@gmail.com",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"homepage": "https://github.com/jordanburke/ts-builds",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/jordanburke/ts-builds"
|
|
22
|
+
},
|
|
23
|
+
"main": "./prettier-config.js",
|
|
24
|
+
"bin": {
|
|
25
|
+
"ts-builds": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./prettier-config.js",
|
|
29
|
+
"./prettier": "./prettier-config.js",
|
|
30
|
+
"./prettier-ignore": "./.prettierignore",
|
|
31
|
+
"./eslint": "./eslint.config.base.mjs",
|
|
32
|
+
"./vitest": "./dist/vitest.config.base.js",
|
|
33
|
+
"./tsconfig": "./tsconfig.base.json",
|
|
34
|
+
"./tsdown": "./dist/tsdown.config.base.js",
|
|
35
|
+
"./scripts": "./package-scripts.json",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"templates",
|
|
40
|
+
"prettier-config.js",
|
|
41
|
+
".prettierignore",
|
|
42
|
+
"eslint.config.base.mjs",
|
|
43
|
+
"dist",
|
|
44
|
+
"tsconfig.base.json",
|
|
45
|
+
"package-scripts.json",
|
|
46
|
+
"scripts",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
52
|
+
"@eslint/js": "^9.39.1",
|
|
53
|
+
"@types/node": "^22.19.1",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
56
|
+
"@vitest/coverage-v8": "^4.0.14",
|
|
57
|
+
"@vitest/ui": "^4.0.14",
|
|
58
|
+
"cross-env": "^10.1.0",
|
|
59
|
+
"eslint": "^9.39.1",
|
|
60
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
|
+
"eslint-plugin-import": "^2.32.0",
|
|
62
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
63
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
64
|
+
"globals": "^16.5.0",
|
|
65
|
+
"prettier": "^3.7.3",
|
|
66
|
+
"rimraf": "^6.1.2",
|
|
67
|
+
"ts-node": "^10.9.2",
|
|
68
|
+
"typescript": "^5.9.3",
|
|
69
|
+
"vitest": "^4.0.14"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"tsdown": "^0.16.8"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"tsdown": "^0.x"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"tsdown": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"format": "prettier --write .",
|
|
84
|
+
"format:check": "prettier --check .",
|
|
85
|
+
"build": "rimraf dist && tsdown",
|
|
86
|
+
"test": "vitest run",
|
|
87
|
+
"test:watch": "vitest",
|
|
88
|
+
"validate": "pnpm format && pnpm build && pnpm test"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shareable Prettier configuration for TypeScript library templates
|
|
3
|
+
* @see https://prettier.io/docs/sharing-configurations
|
|
4
|
+
*/
|
|
5
|
+
export default {
|
|
6
|
+
semi: false,
|
|
7
|
+
trailingComma: "all",
|
|
8
|
+
singleQuote: false,
|
|
9
|
+
printWidth: 120,
|
|
10
|
+
tabWidth: 2,
|
|
11
|
+
endOfLine: "auto",
|
|
12
|
+
}
|
package/templates/npmrc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["esnext", "dom"],
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noImplicitAny": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"outDir": "lib",
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"rootDir": "src",
|
|
14
|
+
"emitDeclarationOnly": true,
|
|
15
|
+
"strictPropertyInitialization": false
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"]
|
|
18
|
+
}
|