presetter 7.2.0 → 8.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/README.md +396 -87
- package/lib/context.d.ts +14 -0
- package/lib/context.d.ts.map +1 -0
- package/lib/context.js +53 -0
- package/lib/debugger.d.ts.map +1 -1
- package/lib/debugger.js +1 -1
- package/lib/executable/entry.d.ts.map +1 -1
- package/lib/executable/entry.js +3 -3
- package/lib/executable/error.d.ts.map +1 -1
- package/lib/executable/error.js +1 -1
- package/lib/executable/index.d.ts.map +1 -1
- package/lib/executable/index.js +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/io.d.ts.map +1 -1
- package/lib/io.js +1 -1
- package/lib/preset/bootstrap.d.ts.map +1 -1
- package/lib/preset/bootstrap.js +5 -10
- package/lib/preset/config/index.d.ts.map +1 -1
- package/lib/preset/config/index.js +1 -1
- package/lib/preset/config/resolve.d.ts.map +1 -1
- package/lib/preset/config/resolve.js +1 -1
- package/lib/preset/config/search.d.ts.map +1 -1
- package/lib/preset/config/search.js +4 -4
- package/lib/preset/index.d.ts +0 -1
- package/lib/preset/index.d.ts.map +1 -1
- package/lib/preset/index.js +1 -2
- package/lib/preset/project.d.ts +2 -2
- package/lib/preset/project.d.ts.map +1 -1
- package/lib/preset/project.js +6 -7
- package/lib/preset/resolution/asset.d.ts +3 -3
- package/lib/preset/resolution/asset.d.ts.map +1 -1
- package/lib/preset/resolution/asset.js +1 -1
- package/lib/preset/resolution/content.d.ts +3 -3
- package/lib/preset/resolution/content.d.ts.map +1 -1
- package/lib/preset/resolution/content.js +1 -1
- package/lib/preset/resolution/debugger.d.ts.map +1 -1
- package/lib/preset/resolution/debugger.js +1 -1
- package/lib/preset/resolution/index.d.ts.map +1 -1
- package/lib/preset/resolution/index.js +1 -1
- package/lib/preset/resolution/object.d.ts.map +1 -1
- package/lib/preset/resolution/object.js +1 -1
- package/lib/preset/resolution/preset.d.ts +2 -2
- package/lib/preset/resolution/preset.d.ts.map +1 -1
- package/lib/preset/resolution/preset.js +1 -1
- package/lib/preset/resolution/script.d.ts +2 -2
- package/lib/preset/resolution/script.d.ts.map +1 -1
- package/lib/preset/resolution/script.js +1 -1
- package/lib/preset/resolution/variable.d.ts +2 -2
- package/lib/preset/resolution/variable.d.ts.map +1 -1
- package/lib/preset/resolution/variable.js +1 -1
- package/lib/preset/scripts.d.ts.map +1 -1
- package/lib/preset/scripts.js +3 -3
- package/lib/resolve.d.ts.map +1 -1
- package/lib/resolve.js +6 -5
- package/lib/run.d.ts.map +1 -1
- package/lib/run.js +29 -23
- package/lib/scripts.d.ts.map +1 -1
- package/lib/scripts.js +1 -1
- package/lib/serialization.d.ts.map +1 -1
- package/lib/serialization.js +3 -3
- package/lib/task.d.ts.map +1 -1
- package/lib/task.js +1 -1
- package/lib/template/index.d.ts.map +1 -1
- package/lib/template/index.js +1 -1
- package/lib/template/merge.d.ts.map +1 -1
- package/lib/template/merge.js +1 -1
- package/lib/template/substitute.d.ts.map +1 -1
- package/lib/template/substitute.js +1 -1
- package/lib/utilities/display.d.ts.map +1 -1
- package/lib/utilities/display.js +1 -1
- package/lib/utilities/index.d.ts.map +1 -1
- package/lib/utilities/index.js +1 -1
- package/lib/utilities/mapping.d.ts.map +1 -1
- package/lib/utilities/mapping.js +1 -1
- package/lib/utilities/object.d.ts.map +1 -1
- package/lib/utilities/object.js +1 -1
- package/package.json +56 -36
- package/types/mvdan-sh/index.d.ts +44 -0
- package/types/npmcli__run-script/index.d.ts +27 -0
- package/lib/package.d.ts +0 -40
- package/lib/package.d.ts.map +0 -1
- package/lib/package.js +0 -93
- package/lib/preset/context.d.ts +0 -8
- package/lib/preset/context.d.ts.map +0 -1
- package/lib/preset/context.js +0 -13
package/README.md
CHANGED
@@ -1,152 +1,461 @@
|
|
1
|
-
|
1
|
+
# 🚀 Presetter
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
• [Quick Start](#quick-start) • [Usage](#usage) • [Customization](#customization) •
|
5
|
+
<div align="center">
|
8
6
|
|
9
7
|
[](https://github.com/alvis/presetter/releases)
|
10
8
|
[](https://github.com/alvis/presetter/actions)
|
11
9
|
[](https://codeclimate.com/github/alvis/presetter/maintainability)
|
12
10
|
[](https://codeclimate.com/github/alvis/presetter/test_coverage)
|
13
|
-
[](https://sonarcloud.io/summary/new_code?id=presetter)
|
12
|
+
[](https://libraries.io/npm/presetter)
|
13
|
+
|
14
|
+
Template-driven configuration management — transform 40+ dev dependencies into 2 packages ⚡
|
15
|
+
|
16
|
+
• [Quick Start](#-quick-start) • [CLI Reference](#-cli-reference) • [Presets](#-official-presets) • [Architecture](#-how-it-works) •
|
16
17
|
|
17
18
|
</div>
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
---
|
21
|
+
|
22
|
+
**Presetter is the configuration management tool that processes presets to generate perfect development environments with zero manual setup.**
|
21
23
|
|
22
|
-
|
24
|
+
## ⚡ The Development Setup Revolution
|
23
25
|
|
24
|
-
|
26
|
+
### Still copying configs between projects? 😤
|
25
27
|
|
26
|
-
|
28
|
+
How many times have you copied configuration files for `babel`, `eslint`, `vitest`, `typescript`, or life cycle scripts across projects? How many dev dependencies do you install before you can even start coding?
|
27
29
|
|
28
|
-
|
30
|
+
**What if setup took one command and two packages?**
|
29
31
|
|
30
|
-
|
32
|
+
### The manual setup nightmare vs. Presetter magic ✨
|
31
33
|
|
32
|
-
|
34
|
+
```diff
|
35
|
+
# Before: Manual development setup (40+ packages, 20+ config files)
|
36
|
+
my-project/
|
37
|
+
├── package.json ← 47 devDependencies to manage
|
38
|
+
├── .babelrc.json ← Manual Babel configuration
|
39
|
+
├── .eslintrc.json ← Custom ESLint rules and plugins
|
40
|
+
├── .prettierrc.json ← Prettier formatting rules
|
41
|
+
├── vitest.config.ts ← Test configuration
|
42
|
+
├── tsconfig.json ← TypeScript compiler options
|
43
|
+
├── tsconfig.build.json ← Build-specific TS config
|
44
|
+
├── .lintstagedrc.json ← Pre-commit hook configuration
|
45
|
+
├── .husky/ ← Git hooks setup
|
46
|
+
├── rollup.config.js ← Bundle configuration
|
47
|
+
├── tailwind.config.js ← CSS framework config
|
48
|
+
└── ... (dozen more config files) ← Endless configuration maintenance
|
33
49
|
|
34
|
-
|
35
|
-
|
50
|
+
# After: Presetter setup (2 packages, 1 command)
|
51
|
+
my-project/
|
52
|
+
+├── presetter.config.ts ← Single preset reference
|
53
|
+
├── package.json ← 2 devDependencies total!
|
54
|
+
└── Perfect configs generated automatically from templates 🎯
|
36
55
|
```
|
37
56
|
|
38
|
-
|
57
|
+
---
|
58
|
+
|
59
|
+
## 🎯 One Command. Perfect Setup. Every Time
|
60
|
+
|
61
|
+
```bash
|
62
|
+
# Choose your development style and get everything instantly:
|
63
|
+
|
64
|
+
# 🟢 Modern ESM development
|
65
|
+
npx presetter use presetter-preset-esm
|
39
66
|
|
40
|
-
|
67
|
+
# 🔗 Legacy CommonJS compatibility
|
68
|
+
npx presetter use presetter-preset-cjs
|
41
69
|
|
42
|
-
|
43
|
-
|
70
|
+
# 🌐 Dual-module library publishing
|
71
|
+
npx presetter use presetter-preset-hybrid
|
72
|
+
|
73
|
+
# 🎨 Modern web development with TailwindCSS + Storybook
|
74
|
+
npx presetter use presetter-preset-esm presetter-preset-web
|
75
|
+
|
76
|
+
# ⚛️ React application with optimized toolchain
|
77
|
+
npx presetter use presetter-preset-esm presetter-preset-react
|
78
|
+
|
79
|
+
# 🏢 Production-grade with security hardening + 100% coverage
|
80
|
+
npx presetter use presetter-preset-esm presetter-preset-strict
|
81
|
+
```
|
82
|
+
|
83
|
+
**That's it.** TypeScript, ESLint, Vitest, build scripts, git hooks, formatter, linter, bundler — everything configured perfectly and working together.
|
44
84
|
|
45
85
|

|
46
86
|
|
47
87
|
---
|
48
88
|
|
49
|
-
##
|
89
|
+
## ✨ What Makes Presetter Revolutionary
|
90
|
+
|
91
|
+
### 🧠 Intelligent Configuration Generation
|
92
|
+
|
93
|
+
Presetter doesn't copy static files. It **generates** configurations using sophisticated templates that adapt to your project:
|
94
|
+
|
95
|
+
- **Context-aware**: Presets know about your project structure, dependencies, and requirements
|
96
|
+
- **Variable substitution**: Templates use dynamic values (`{source}`, `{target}`, `{output}`)
|
97
|
+
- **Smart merging**: Deep merge algorithms handle complex configuration inheritance
|
98
|
+
- **Two-pass resolution**: Initial setup + override pass for perfect customization
|
99
|
+
|
100
|
+
### 🏗️ Composable Preset Architecture
|
101
|
+
|
102
|
+
Mix and match presets like building blocks:
|
50
103
|
|
51
|
-
|
104
|
+
```typescript
|
105
|
+
// presetter.config.ts - Build your perfect development environment
|
106
|
+
import { preset } from 'presetter';
|
107
|
+
import essentials from 'presetter-preset-essentials';
|
108
|
+
import web from 'presetter-preset-web';
|
109
|
+
import react from 'presetter-preset-react';
|
110
|
+
import strict from 'presetter-preset-strict';
|
52
111
|
|
112
|
+
export default preset('my-perfect-app', {
|
113
|
+
extends: [essentials, web, react, strict], // 🚀 Ultimate React stack
|
114
|
+
override: {
|
115
|
+
variables: {
|
116
|
+
target: 'ES2023', // 🎯 Cutting-edge compilation target
|
117
|
+
},
|
118
|
+
},
|
119
|
+
});
|
53
120
|
```
|
54
|
-
|
121
|
+
|
122
|
+
### ⚡ Real Developer Productivity
|
123
|
+
|
124
|
+
| Manual Setup Time | With Presetter | Productivity Gain |
|
125
|
+
| ------------------------------------- | -------------------------------- | ---------------------------- |
|
126
|
+
| **2-4 hours** initial setup | **30 seconds** | **24x faster** ⚡ |
|
127
|
+
| **30 minutes** per config update | **Automatic** via preset updates | **∞ maintenance time saved** |
|
128
|
+
| **Copy-paste errors** across projects | **Zero config drift** | **100% consistency** |
|
129
|
+
|
130
|
+
---
|
131
|
+
|
132
|
+
## 🔍 Understanding Presetter vs Presets
|
133
|
+
|
134
|
+
**Critical distinction:**
|
135
|
+
|
136
|
+
| Component | Role | What it does |
|
137
|
+
| ------------------------------- | ---------------------------------- | ------------------------------------------------------------------------ |
|
138
|
+
| **Presetter** (this package) | 🎛️ Configuration management engine | CLI tool that processes presets, generates configs, manages dependencies |
|
139
|
+
| **Presets** (template packages) | 📋 Configuration templates | Define what configs to generate, how tools should be configured |
|
140
|
+
|
141
|
+
**Think of it like:**
|
142
|
+
|
143
|
+
- **Presetter** = The powerful engine that builds development environments
|
144
|
+
- **Presets** = The blueprints that define what to build
|
145
|
+
|
146
|
+
---
|
147
|
+
|
148
|
+
## 🚀 Quick Start
|
149
|
+
|
150
|
+
### 🎬 Instant Project Setup
|
151
|
+
|
152
|
+
```bash
|
153
|
+
# 1. Choose and adopt a preset (creates presetter.config.ts automatically)
|
154
|
+
npx presetter use presetter-preset-esm
|
155
|
+
|
156
|
+
# 2. Install dependencies (presetter bootstrap runs automatically)
|
157
|
+
npm install
|
158
|
+
|
159
|
+
# 3. Start developing immediately!
|
160
|
+
npm run build # ✅ TypeScript compilation
|
161
|
+
npm run test # ✅ Vitest testing
|
162
|
+
npm run lint # ✅ ESLint checking
|
163
|
+
npm run watch # ✅ Development mode
|
164
|
+
```
|
165
|
+
|
166
|
+
### 🔧 Converting Existing Projects
|
167
|
+
|
168
|
+
```bash
|
169
|
+
# 1. Review current setup (decide what to keep/replace)
|
170
|
+
ls -la *.config.* .*rc.* tsconfig*.json
|
171
|
+
|
172
|
+
# 2. Remove unnecessary configs and dev dependencies
|
173
|
+
npm uninstall babel eslint prettier typescript vitest # ...and 30+ more
|
174
|
+
|
175
|
+
# 3. Adopt presetter
|
176
|
+
npx presetter use presetter-preset-esm
|
177
|
+
|
178
|
+
# 4. Cleanup and enjoy zero-config development
|
179
|
+
```
|
180
|
+
|
181
|
+
---
|
182
|
+
|
183
|
+
## 🛠️ CLI Reference
|
184
|
+
|
185
|
+
Presetter provides powerful CLI commands for managing your development environment:
|
186
|
+
|
187
|
+
```bash
|
188
|
+
⚙️ presetter: your preset configurator
|
55
189
|
|
56
190
|
Commands:
|
57
|
-
presetter use <preset>
|
58
|
-
presetter bootstrap
|
59
|
-
presetter run
|
60
|
-
presetter unset
|
191
|
+
presetter use <preset> Adopt specified preset(s) to the project
|
192
|
+
presetter bootstrap Apply preset configurations to the project
|
193
|
+
presetter run <task> Run a task with preset + local script merging
|
194
|
+
presetter unset Remove all artifacts created by presets
|
195
|
+
|
196
|
+
Shortcuts:
|
197
|
+
run <task> Shortcut for 'presetter run <task>'
|
198
|
+
run-s <tasks...> Run tasks sequentially
|
199
|
+
run-p <tasks...> Run tasks in parallel
|
61
200
|
|
62
201
|
Options:
|
63
|
-
--help
|
64
|
-
--version
|
202
|
+
--help Show help
|
203
|
+
--version Show version number
|
65
204
|
```
|
66
205
|
|
67
|
-
###
|
206
|
+
### 🎯 Common Commands
|
68
207
|
|
69
|
-
|
70
|
-
|
208
|
+
```bash
|
209
|
+
# Adopt presets (automatically bootstraps)
|
210
|
+
presetter use presetter-preset-esm presetter-preset-strict
|
71
211
|
|
72
|
-
|
212
|
+
# Manually bootstrap (if needed)
|
213
|
+
presetter bootstrap
|
73
214
|
|
74
|
-
|
75
|
-
|
215
|
+
# Run development tasks
|
216
|
+
run build # Build your project
|
217
|
+
run test # Run tests
|
218
|
+
run lint # Lint your code
|
219
|
+
run watch # Development mode with hot reload
|
76
220
|
|
77
|
-
|
78
|
-
-
|
79
|
-
-
|
221
|
+
# Run multiple tasks
|
222
|
+
run-s clean build test # Sequential execution
|
223
|
+
run-p lint test # Parallel execution
|
80
224
|
|
81
|
-
|
225
|
+
# Remove all preset configurations
|
226
|
+
presetter unset
|
227
|
+
```
|
82
228
|
|
83
|
-
|
84
|
-
follow the steps below:
|
229
|
+
---
|
85
230
|
|
86
|
-
|
87
|
-
2. Remove any unnecessary dev dependencies, .config files or life cycle scripts
|
88
|
-
3. Make sure `presetter bootstrap` will be executed in the post installation life cycle.
|
89
|
-
4. Add your preset via `presetter use <preset package name>`
|
231
|
+
## 📦 Official Presets
|
90
232
|
|
91
|
-
|
233
|
+
Presetter comes with a comprehensive ecosystem of official presets:
|
92
234
|
|
93
|
-
|
94
|
-
they have to be installed to the adopting project and it's what `presetter bootstrap` for.
|
235
|
+
### Core Development Presets
|
95
236
|
|
96
|
-
|
237
|
+
| Preset | Purpose | Best For |
|
238
|
+
| ------------------------------------------------------------------------------------------------------------ | ------------------------------ | ----------------------------------------- |
|
239
|
+
| **[presetter-preset-essentials](https://github.com/alvis/presetter/blob/master/packages/preset-essentials)** | 🏗️ Complete TypeScript toolkit | Foundation for all TypeScript projects |
|
240
|
+
| **[presetter-preset-esm](https://github.com/alvis/presetter/blob/master/packages/preset-esm)** | 🚀 ESM-first development | Modern Node.js projects, libraries |
|
241
|
+
| **[presetter-preset-cjs](https://github.com/alvis/presetter/blob/master/packages/preset-cjs)** | 🔗 CommonJS compatibility | Legacy environments, enterprise |
|
242
|
+
| **[presetter-preset-hybrid](https://github.com/alvis/presetter/blob/master/packages/preset-hybrid)** | 🌐 Dual-module packages | npm libraries needing broad compatibility |
|
97
243
|
|
98
|
-
|
99
|
-
- [you installed a new packages via npm](https://github.com/alvis/presetter/blob/master/README.md#missing-dependent-development-packages-after-npm-install-package).
|
244
|
+
### Specialized Extension Presets
|
100
245
|
|
101
|
-
|
246
|
+
| Preset | Purpose | Extends |
|
247
|
+
| ---------------------------------------------------------------------------------------------------- | --------------------------- | --------------- |
|
248
|
+
| **[presetter-preset-strict](https://github.com/alvis/presetter/blob/master/packages/preset-strict)** | 🏢 Production-grade quality | Any base preset |
|
249
|
+
| **[presetter-preset-web](https://github.com/alvis/presetter/blob/master/packages/preset-web)** | 🎨 Modern web development | Any base preset |
|
250
|
+
| **[presetter-preset-react](https://github.com/alvis/presetter/blob/master/packages/preset-react)** | ⚛️ React development | Any base preset |
|
251
|
+
| **[presetter-preset-rollup](https://github.com/alvis/presetter/blob/master/packages/preset-rollup)** | 📦 Library bundling | Any base preset |
|
102
252
|
|
103
|
-
|
253
|
+
### 🎯 Preset Combination Examples
|
104
254
|
|
105
|
-
|
106
|
-
|
107
|
-
|
255
|
+
```typescript
|
256
|
+
// Modern web application
|
257
|
+
extends: [essentials, esm, web, strict]
|
108
258
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
"release": "run release --",
|
118
|
-
"test": "run test --",
|
119
|
-
"watch": "run watch"
|
120
|
-
}
|
121
|
-
}
|
259
|
+
// React component library
|
260
|
+
extends: [essentials, hybrid, react, rollup]
|
261
|
+
|
262
|
+
// Enterprise Node.js service
|
263
|
+
extends: [essentials, cjs, strict]
|
264
|
+
|
265
|
+
// Full-stack TypeScript monorepo
|
266
|
+
extends: [monorepo, essentials, web, react]
|
122
267
|
```
|
123
268
|
|
124
|
-
|
125
|
-
place them into a temporary `package.json` and run the task via `npm run <task>` as usual.
|
269
|
+
---
|
126
270
|
|
127
|
-
|
271
|
+
## 🏗️ How It Works
|
272
|
+
|
273
|
+
Presetter uses a sophisticated **two-pass resolution system** that makes configuration management both powerful and flexible:
|
274
|
+
|
275
|
+
### Phase 1: Dependency Resolution 🔍
|
276
|
+
|
277
|
+
```
|
278
|
+
📋 Preset Chain: [base] → [extensions] → [customizations]
|
279
|
+
↓
|
280
|
+
🧩 Build dependency tree and merge configurations
|
281
|
+
↓
|
282
|
+
🔄 Resolve variables with substitution support
|
283
|
+
```
|
284
|
+
|
285
|
+
### Phase 2: Asset Generation 🏭
|
286
|
+
|
287
|
+
```
|
288
|
+
📝 Template Processing: YAML/JSON/TS → Generated Configs
|
289
|
+
↓
|
290
|
+
🎯 Context-aware generation (project structure, dependencies)
|
291
|
+
↓
|
292
|
+
✨ Smart merging with existing configurations
|
293
|
+
```
|
294
|
+
|
295
|
+
### 🧠 Intelligent Features
|
296
|
+
|
297
|
+
- **Variable System**: Templates use `{source}`, `{output}`, `{target}` for dynamic configuration
|
298
|
+
- **Context Awareness**: Presets adapt based on project structure and location
|
299
|
+
- **Deep Merging**: Sophisticated algorithms handle complex inheritance
|
300
|
+
- **Script Composition**: Local scripts merge with preset scripts intelligently
|
128
301
|
|
129
302
|
---
|
130
303
|
|
131
|
-
##
|
304
|
+
## 🛠️ Advanced Usage
|
305
|
+
|
306
|
+
### 🎨 Custom Preset Configuration
|
307
|
+
|
308
|
+
```typescript
|
309
|
+
// presetter.config.ts
|
310
|
+
import { preset } from 'presetter';
|
311
|
+
import esm from 'presetter-preset-esm';
|
312
|
+
|
313
|
+
export default preset('my-project', {
|
314
|
+
extends: [esm],
|
315
|
+
override: {
|
316
|
+
variables: {
|
317
|
+
target: 'ES2023', // Modern compilation target
|
318
|
+
source: 'source', // Custom source directory
|
319
|
+
output: 'dist', // Custom output directory
|
320
|
+
},
|
321
|
+
assets: {
|
322
|
+
'tsconfig.json': {
|
323
|
+
compilerOptions: {
|
324
|
+
allowImportingTsExtensions: true, // Enable experimental features
|
325
|
+
},
|
326
|
+
},
|
327
|
+
'package.json': {
|
328
|
+
scripts: {
|
329
|
+
'custom:task': 'echo "My custom script"',
|
330
|
+
},
|
331
|
+
},
|
332
|
+
},
|
333
|
+
},
|
334
|
+
});
|
335
|
+
```
|
336
|
+
|
337
|
+
### 🔧 Local Configuration Override
|
338
|
+
|
339
|
+
Presetter respects local configurations - simply create your own file:
|
132
340
|
|
133
|
-
|
341
|
+
```bash
|
342
|
+
# Presetter will use your local version instead of generating from template
|
343
|
+
touch .eslintrc.json # Use your custom ESLint config
|
344
|
+
touch vitest.config.ts # Use your custom Vitest config
|
345
|
+
```
|
134
346
|
|
135
|
-
|
347
|
+
### 🏗️ Script Composition
|
136
348
|
|
137
|
-
|
138
|
-
e.g. For [presetter-preset-esm](https://github.com/alvis/presetter/tree/master/packages/preset-esm), you can adding an expression to `.gitignore` with the following in `.presetterrc`:
|
349
|
+
Combine preset scripts with your local scripts:
|
139
350
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
351
|
+
````json5
|
352
|
+
```jsonc
|
353
|
+
scripts: {
|
354
|
+
'build': 'run build', // Use preset's build script
|
355
|
+
'build:custom': 'run build && echo done', // Extend preset's build
|
356
|
+
'test': 'run test --', // Preset test + pass arguments
|
357
|
+
'custom': "echo 'My script'", // Pure local script
|
358
|
+
},
|
146
359
|
}
|
360
|
+
````
|
361
|
+
|
362
|
+
---
|
363
|
+
|
364
|
+
## 🌟 Benefits & Features
|
365
|
+
|
366
|
+
### ✅ Developer Experience
|
367
|
+
|
368
|
+
- **⚡ Zero-config setup**: One command gets you productive immediately
|
369
|
+
- **🔄 Consistent updates**: Update all projects by updating preset versions
|
370
|
+
- **🎯 Best practices**: Configurations follow industry standards and expert recommendations
|
371
|
+
- **🚀 Composable architecture**: Mix and match presets to build perfect environments
|
372
|
+
|
373
|
+
### ✅ Project Management
|
374
|
+
|
375
|
+
- **📦 Dependency reduction**: 40+ packages → 2 packages
|
376
|
+
- **🔧 Maintenance simplification**: Single source of truth for configurations
|
377
|
+
- **🌐 Team consistency**: Same setup across all team members and projects
|
378
|
+
- **📈 Scalability**: Manage configurations across dozens of projects effortlessly
|
379
|
+
|
380
|
+
### ✅ Technical Excellence
|
381
|
+
|
382
|
+
- **🧠 Intelligent merging**: Sophisticated algorithms handle complex configurations
|
383
|
+
- **🔄 Two-pass resolution**: Initial setup + override for perfect customization
|
384
|
+
- **📝 Template system**: Dynamic, context-aware configuration generation
|
385
|
+
- **🎛️ Fine-grained control**: Override anything while maintaining preset benefits
|
386
|
+
|
387
|
+
---
|
388
|
+
|
389
|
+
## 🆚 Alternatives Comparison
|
390
|
+
|
391
|
+
| Solution | Setup Time | Maintenance | Consistency | Flexibility | Learning Curve |
|
392
|
+
| ------------------- | -------------- | ----------- | ----------- | ----------- | -------------- |
|
393
|
+
| **Manual Setup** | 2-4 hours | High | Poor | Full | High |
|
394
|
+
| **Boilerplate/CRA** | 5 minutes | Medium | Medium | Limited | Medium |
|
395
|
+
| **Presetter** | **30 seconds** | **Zero** | **Perfect** | **Full** | **Low** |
|
396
|
+
|
397
|
+
---
|
398
|
+
|
399
|
+
## 🛠️ Troubleshooting
|
400
|
+
|
401
|
+
### Common Issues
|
402
|
+
|
403
|
+
| Issue | Symptoms | Solution |
|
404
|
+
| ------------------------ | ------------------------ | ----------------------------------------------- |
|
405
|
+
| **Missing dependencies** | Package import errors | Run `presetter bootstrap` |
|
406
|
+
| **Config conflicts** | Unexpected tool behavior | Check for local config files overriding presets |
|
407
|
+
| **Script not found** | `run` command fails | Ensure script exists in preset or package.json |
|
408
|
+
| **Preset not found** | Bootstrap fails | Check preset package name and installation |
|
409
|
+
|
410
|
+
### Debug Mode
|
411
|
+
|
412
|
+
```bash
|
413
|
+
# Enable detailed logging for troubleshooting
|
414
|
+
DEBUG=presetter* presetter bootstrap
|
415
|
+
DEBUG=presetter* run build
|
147
416
|
```
|
148
417
|
|
149
|
-
|
418
|
+
---
|
419
|
+
|
420
|
+
## ❓ FAQ
|
421
|
+
|
422
|
+
### How is this different from boilerplates?
|
423
|
+
|
424
|
+
Boilerplates copy static files once. Presetter **generates** configurations dynamically and **maintains** them through preset updates. When you update a preset, all projects using it get the improvements automatically.
|
425
|
+
|
426
|
+
### Can I customize generated configurations?
|
427
|
+
|
428
|
+
Yes! Presetter offers multiple customization levels:
|
429
|
+
|
430
|
+
- **Variable overrides**: Change compilation targets, directories, etc.
|
431
|
+
- **Asset overrides**: Modify specific configuration properties
|
432
|
+
- **Local files**: Replace preset configs entirely with your own files
|
433
|
+
|
434
|
+
### How do I update configurations across projects?
|
435
|
+
|
436
|
+
Simply update the preset package version in your projects. Presetter will regenerate configurations with the latest improvements when you run `bootstrap`.
|
437
|
+
|
438
|
+
### Can I create my own presets?
|
439
|
+
|
440
|
+
Absolutely! Presets are just npm packages that export configuration templates. See [presetter-types](https://github.com/alvis/presetter/blob/master/packages/types) for TypeScript definitions.
|
441
|
+
|
442
|
+
### Does this work with monorepos?
|
443
|
+
|
444
|
+
Yes! Presetter supports monorepo setups and can bootstrap multiple projects with glob patterns. Use [presetter-preset-monorepo](https://github.com/alvis/presetter/blob/master/packages/preset-monorepo) for monorepo-specific configurations.
|
445
|
+
|
446
|
+
---
|
447
|
+
|
448
|
+
## 🤝 Contributing
|
449
|
+
|
450
|
+
We'd love your ideas and contributions!
|
451
|
+
Submit issues or suggestions via [GitHub Issues](https://github.com/alvis/presetter/issues).
|
452
|
+
See the [Contribution Guide](https://github.com/alvis/presetter/blob/master/CONTRIBUTING.md) for more details.
|
453
|
+
|
454
|
+
---
|
455
|
+
|
456
|
+
## 📄 License
|
457
|
+
|
458
|
+
Released under the [MIT License](https://github.com/alvis/presetter/blob/master/LICENSE).
|
459
|
+
© 2020, [Alvis Tang](https://github.com/alvis).
|
150
460
|
|
151
|
-
|
152
|
-
Presetter always respects any local version which is not symlinked to the preset.
|
461
|
+
[](https://github.com/alvis/presetter/blob/master/LICENSE)
|
package/lib/context.d.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { ProjectContext } from 'presetter-types';
|
2
|
+
/**
|
3
|
+
* get scripts from the targeted project's package.json
|
4
|
+
* @param cwd path to the project's root folder
|
5
|
+
* @returns package detail
|
6
|
+
*/
|
7
|
+
export declare function resolveProjectContext(cwd?: string): Promise<ProjectContext>;
|
8
|
+
/**
|
9
|
+
* resolve the root of the repository holding the project based on the presence of .git .hg etc meta directories or a parent package.json
|
10
|
+
* @param cwd currnet working directory
|
11
|
+
* @returns path to the repository root, if found
|
12
|
+
*/
|
13
|
+
export declare function resolveRepoRoot(cwd?: string): Promise<string | undefined>;
|
14
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,CAAC,CAgCzB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAc7B"}
|
package/lib/context.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
2
|
+
import { dirname, relative } from 'node:path';
|
3
|
+
import { findUp } from 'find-up-simple';
|
4
|
+
/**
|
5
|
+
* get scripts from the targeted project's package.json
|
6
|
+
* @param cwd path to the project's root folder
|
7
|
+
* @returns package detail
|
8
|
+
*/
|
9
|
+
export async function resolveProjectContext(cwd) {
|
10
|
+
// try to find the target project's package.json
|
11
|
+
const packageJsonPath = await findUp('package.json', {
|
12
|
+
cwd,
|
13
|
+
type: 'file',
|
14
|
+
});
|
15
|
+
// throw an error if there's no package.json found
|
16
|
+
if (!packageJsonPath) {
|
17
|
+
throw new Error("failed to find target's package.json");
|
18
|
+
}
|
19
|
+
// read the content of the project's package.json
|
20
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
|
21
|
+
// compute the rest of metadata
|
22
|
+
const projectRoot = dirname(packageJsonPath);
|
23
|
+
const repoRoot = (await resolveRepoRoot(cwd)) ?? projectRoot;
|
24
|
+
const relativeProjectRoot = relative(repoRoot, projectRoot) || '.';
|
25
|
+
const relativeRepoRoot = relative(projectRoot, repoRoot) || '.';
|
26
|
+
const isRepoRoot = repoRoot === projectRoot;
|
27
|
+
return {
|
28
|
+
isRepoRoot,
|
29
|
+
relativeProjectRoot,
|
30
|
+
relativeRepoRoot,
|
31
|
+
repoRoot,
|
32
|
+
projectRoot,
|
33
|
+
packageJson,
|
34
|
+
};
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* resolve the root of the repository holding the project based on the presence of .git .hg etc meta directories or a parent package.json
|
38
|
+
* @param cwd currnet working directory
|
39
|
+
* @returns path to the repository root, if found
|
40
|
+
*/
|
41
|
+
export async function resolveRepoRoot(cwd) {
|
42
|
+
for (const name of ['.git', '.hg', '.svn']) {
|
43
|
+
const metaPath = await findUp(name, { cwd });
|
44
|
+
if (metaPath) {
|
45
|
+
return dirname(metaPath);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
const parentPackagePath = await findUp('package.json', {
|
49
|
+
cwd: dirname(cwd ?? process.cwd()),
|
50
|
+
});
|
51
|
+
return parentPackagePath ? dirname(parentPackagePath) : undefined;
|
52
|
+
}
|
53
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM1QyxPQUFPLEVBQUUsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUU5QyxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFLeEM7Ozs7R0FJRztBQUNILE1BQU0sQ0FBQyxLQUFLLFVBQVUscUJBQXFCLENBQ3pDLEdBQVk7SUFFWixnREFBZ0Q7SUFDaEQsTUFBTSxlQUFlLEdBQUcsTUFBTSxNQUFNLENBQUMsY0FBYyxFQUFFO1FBQ25ELEdBQUc7UUFDSCxJQUFJLEVBQUUsTUFBTTtLQUNiLENBQUMsQ0FBQztJQUVILGtEQUFrRDtJQUNsRCxJQUFJLENBQUMsZUFBZSxFQUFFLENBQUM7UUFDckIsTUFBTSxJQUFJLEtBQUssQ0FBQyxzQ0FBc0MsQ0FBQyxDQUFDO0lBQzFELENBQUM7SUFFRCxpREFBaUQ7SUFDakQsTUFBTSxXQUFXLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FDNUIsTUFBTSxRQUFRLENBQUMsZUFBZSxFQUFFLEVBQUUsUUFBUSxFQUFFLE1BQU0sRUFBRSxDQUFDLENBQ3ZDLENBQUM7SUFFakIsK0JBQStCO0lBQy9CLE1BQU0sV0FBVyxHQUFHLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FBQztJQUM3QyxNQUFNLFFBQVEsR0FBRyxDQUFDLE1BQU0sZUFBZSxDQUFDLEdBQUcsQ0FBQyxDQUFDLElBQUksV0FBVyxDQUFDO0lBQzdELE1BQU0sbUJBQW1CLEdBQUcsUUFBUSxDQUFDLFFBQVEsRUFBRSxXQUFXLENBQUMsSUFBSSxHQUFHLENBQUM7SUFDbkUsTUFBTSxnQkFBZ0IsR0FBRyxRQUFRLENBQUMsV0FBVyxFQUFFLFFBQVEsQ0FBQyxJQUFJLEdBQUcsQ0FBQztJQUNoRSxNQUFNLFVBQVUsR0FBRyxRQUFRLEtBQUssV0FBVyxDQUFDO0lBRTVDLE9BQU87UUFDTCxVQUFVO1FBQ1YsbUJBQW1CO1FBQ25CLGdCQUFnQjtRQUNoQixRQUFRO1FBQ1IsV0FBVztRQUNYLFdBQVc7S0FDWixDQUFDO0FBQ0osQ0FBQztBQUVEOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLGVBQWUsQ0FDbkMsR0FBWTtJQUVaLEtBQUssTUFBTSxJQUFJLElBQUksQ0FBQyxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sQ0FBQyxFQUFFLENBQUM7UUFDM0MsTUFBTSxRQUFRLEdBQUcsTUFBTSxNQUFNLENBQUMsSUFBSSxFQUFFLEVBQUUsR0FBRyxFQUFFLENBQUMsQ0FBQztRQUU3QyxJQUFJLFFBQVEsRUFBRSxDQUFDO1lBQ2IsT0FBTyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDM0IsQ0FBQztJQUNILENBQUM7SUFFRCxNQUFNLGlCQUFpQixHQUFHLE1BQU0sTUFBTSxDQUFDLGNBQWMsRUFBRTtRQUNyRCxHQUFHLEVBQUUsT0FBTyxDQUFDLEdBQUcsSUFBSSxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUM7S0FDbkMsQ0FBQyxDQUFDO0lBRUgsT0FBTyxpQkFBaUIsQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLGlCQUFpQixDQUFDLENBQUMsQ0FBQyxDQUFDLFNBQVMsQ0FBQztBQUNwRSxDQUFDIn0=
|
package/lib/debugger.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"debugger.d.ts","sourceRoot":"","sources":["../
|
1
|
+
{"version":3,"file":"debugger.d.ts","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;;AAE1B,wBAAkC"}
|
package/lib/debugger.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/* v8 ignore start */
|
2
2
|
import Debug from 'debug';
|
3
3
|
export default Debug('presetter');
|
4
|
-
//# sourceMappingURL=data:application/json;base64,
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVidWdnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVidWdnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEscUJBQXFCO0FBRXJCLE9BQU8sS0FBSyxNQUFNLE9BQU8sQ0FBQztBQUUxQixlQUFlLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQyJ9
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/executable/entry.ts"],"names":[],"mappings":"AA+GA;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAezD"}
|