@mrpelz/boilerplate-common 13.0.0 → 13.0.2

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 CHANGED
@@ -1,10 +1,11 @@
1
- # boilerplate-common
1
+ # `@mrpelz/boilerplate-common`
2
2
 
3
- Easily start new TypeScript-based projects using a modular and extensible toolset. It tries to handle common pitfalls for edge-cases while providing opinionated defaults for everyday-use.
3
+ Easily start new TypeScript-based projects using a modular and extensible toolset.
4
+ This boilerplate tries to provide opinionated defaults for everyday-use while handling common pitfalls for edge-cases. If your edge-case is too special, it won’t prescribe a fixed configuration, always allowing a route to customization without all-or-nothing breakout.
4
5
 
5
6
  ## Philosophy
6
7
 
7
- ### Providing sane defaults without weird configuration templates
8
+ ### Updatability vs. Customization
8
9
 
9
10
  Boilerplates that want to offer developers a good experience in the long-term have to balance two interests: Updatability and customization.
10
11
 
@@ -12,30 +13,74 @@ Customization is necessary so that the boilerplate can cover as little edge case
12
13
 
13
14
  Updatability ensures that the boilerplate can reflect changing best practices over time, even after the initial installation.
14
15
 
16
+ ### The Problem with Configuration Templates
17
+
15
18
  Boilerplates that define configuration files via a template system can offer a streamlined initial installation thanks to the standardized production of all project files.
16
- However, if a developer modifies one of the produced files after the installation (e.g. to handle a very special project setup), the boilerplate’s next update will either overwrite this modification or not update the affected file at all.
19
+ However, if a developer modifies one of the produced files after the installation (e.g. to handle a very special project setup), the boilerplate’s next update will either overwrite this per-project customization or not update the affected file at all, possibly creating breaking changes in conjunction with other updated configuration files.
20
+
21
+ ### How to Facilitate Customization/Abandoning Updates After Initial Install
22
+
23
+ Keeping production of configuration files confined to a template system, this “customization and update problem” can only be solved by either abstracting the tooling to such an extent that customizations also need to happen within the abstraction (thus creating user lock-in and mental overhead translating and maintaining the customizations), or at the other extreme, by only setting up a new project environment at the time of initial install, leaving developers to their own devices for subsequent updates and requiring them to replicate changes to the boilerplate on their own.
17
24
 
18
- If you stick with the production of configuration files via a template system, this “customization and update problem” can only be solved by either abstracting the tooling to such an extent that customizations also need to happen within the abstraction (thus creating user lock-in), or at the other extreme, by only setting up a new project environment at the time of initial install, leaving developers to their own devices for subsequent updates and requiring them to replicate changes to the boilerplate on their own.
25
+ ### No Configuration Templates
19
26
 
20
- Instead of using a template system for all config files, this boilerplate uses the extension mechanism provided by the given tool, provides its default configurations as artifacts within the NPM package and generates skeleton configs importing (or otherwise referencing) these artifacts. For non-extensible files it creates symlinks with proper path-handling.
27
+ Instead of using a template system for all config files, this boilerplate uses the extension mechanism provided by the given tool, provides its default configurations as artifacts within the NPM package and generates skeleton configs importing (or otherwise referencing) these artifacts. For non-extensible files it creates symlinks with proper relative path-handling.
21
28
 
22
29
  For configurations handled through skeleton files, customization is easily done by recomposing configuration options with the always updated defaults referenced from the package.
23
30
 
24
- For the very few symlinked configs, the user can choose to stick with the updated default or move to a fully-custom file maintained at the project’s discretion.
31
+ For the very few symlinked configs, the user can choose to stick with the updated default or move to a fully-custom file maintained at the project’s discretion. (Re)running a bootstrap script allows for easy restore of previously customized files, if a project withes to return to a tool’s provided default config.
32
+
33
+ ## NPM-Package
34
+
35
+ Provides the configuration basis for the other boilerplate packages. Use it for projects that produce library code not strictly meant to run browser- or server-side.
36
+
37
+ ### Features
38
+
39
+ * TypeScript-config to output native ESM-modules
40
+ * produce sourcemaps
41
+ * lint and typecheck sourcecode with amendable defaults using ESLint
42
+ * lint and typecheck configurations defined as code (e.g. `eslint.config.js`)
43
+ * run unit tests using a TypeScript- and ESM-compatible basic Jest setup
44
+ * enforce commit message formatting using Commitlint
45
+ * enforce package.json matching repository attributes, e.g. name, version, repository fields, key sorting
46
+ * .editorconfig to match other tools’ settings
47
+ * VSCode project-settings and -extension suggestions to match tooling
48
+ * lint Bash-scripts using Shellcheck
49
+ * derive package versions from git tags and automatically handle prerelease-versioning in a feature-branch workflow
50
+ * Tmux niceties to help keep watch on all lint/check tasks during development
51
+ * GitLab-CI pipelines
52
+ * to run relevant checks on every change pushed to a merge request
53
+ * manually trigger (pre-)release tagging after checks complete
54
+ (no guessing breaking-changes from commit messages, press the appropriate play-button for pre-, patch-, minor- or major-release tagging after check-pipeline completes)
55
+ * produce NPM-packages on release and publish to GitLab package-registry
56
+ * comment prerelease-info to merge requests
25
57
 
26
58
  ## Usage
27
59
 
28
60
  > **ℹ️ Opinion**
29
- >This Readme will only provide examples for `npm`.
61
+ > This Readme provides examples for `npm`.
30
62
  >
31
63
  > The supporting scripts all use `npm` internally.
32
- Feel free to change them in your project to use `yarn` or something else, but as long as you want to use this boilerplate as-is, stick to `npm`. 🙂
64
+ Feel free to change them in your project to use `yarn`, `pnpm` or something else, but as long as you want to use this boilerplate as-is, stick to `npm`.
33
65
 
34
66
  ### Prerequisites
35
67
 
36
68
  * `node` and `npm` installed
37
69
  * (optionally) `git` installed and set up
38
- * (GNU) `make`, `sed`, `tmux` and `xargs` installed
70
+ * (GNU!) `make`, `sed`, `tmux` and `xargs` installed
71
+ > This boilerplate uses `make` for task orchestration. In order to compose Makefiles from NPM-dependency artifacts, **GNU**-Make is a strict necessity.
72
+ >
73
+ > In order to compose Makefiles from NPM-dependency artifacts, *GNU*-Make is a strict necessity. If you’re using macOS, install using `brew install make` and amend your `$PATH` to use GNU-Make by default (e.g. by putting
74
+ > ```bash
75
+ > PATH="$HOMEBREW_PREFIX/opt/make/libexec/gnubin:$PATH"
76
+ > ```
77
+ > to your `.zshrc`).
78
+ * (GNU!) `ln` installed
79
+ > Some config files cannot be natively extended and need to be symlinked to the boilerplate’s default. This ensures new defaults apply when the boilerplate is updated. In order to keep the project root portable across different developers’ environments, symlinks need to use relative paths, which unfortunately is only a feature in the `ln` utility from GNU-Coreutils. If you’re using macOS, install using `brew install coreutils` and amend your `$PATH` to use GNU-Coreutils by default (e.g. by putting
80
+ > ```bash
81
+ > PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
82
+ > ```
83
+ > to your `.zshrc`).
39
84
 
40
85
  ### 1. Optionally Create Environment First
41
86
 
@@ -81,22 +126,18 @@ Whenever you are prompted, you can just hit enter to select the capitalized defa
81
126
  Prompts for creating a symlink look like this:
82
127
 
83
128
  ```bash
84
- [SYMBOLIC LINK] ".editorconfig"
85
- ❓ 🔗 add symbolic link ".editorconfig" (pointing to target "node_modules/@mrpelz/boilerplate-common/.editorconfig") to "." in "/home/mrpelz/work/misc/new-project"?
129
+ [SYMBOLIC LINK] "<file name>"
130
+ ❓ 🔗 add symbolic link "<file name>" (pointing to target "<target>") to "<directory>" in "<project root>"?
86
131
  ❔ [Y/n]
87
132
  ```
88
133
 
89
134
  Prompts for creating config files look like this:
90
135
 
91
136
  ```bash
92
- [CONFIG FILE] "eslint.config.js"
137
+ [CONFIG FILE] "<file name>"
93
138
  🆕 new file contents:
94
- // @ts-ignore
95
- import config from '@mrpelz/boilerplate-common/eslint.config.js';
96
-
97
- /** @type {import('eslint').Linter.Config[]} */
98
- export default config;
99
- ❓ 📄 add config file "eslint.config.js" to "." in "/home/mrpelz/work/misc/new-project"?
139
+ <file contents>
140
+ ❓ 📄 add config file "<file name>" to "<directory>" in "<project root>"?
100
141
  ❔ [Y/n]
101
142
  ```
102
143
 
@@ -107,24 +148,22 @@ export default config;
107
148
  ```bash
108
149
  npm exec boilerplate-bootstrap y
109
150
  ```
110
- ### 4. Create Entry-Point Source File
111
-
112
- ```bash
113
- touch src/main.ts
114
- ```
115
151
 
116
152
  ## Scripts
117
153
 
118
- > **ℹ️ Opinion**
119
- > This boilerplate uses `make` to orchestrate tooling instead of stringing together multiple NPM scripts.
120
- > Make is exactly designed for this purpose while NPM scripts are hard to compose, reuse and are just a byproduct of custom module-lifecycle hook scripts.
154
+ > **ℹ️ Opinion**
155
+ >
156
+ > This boilerplate uses `make` for task orchestration instead of stringing together multiple NPM scripts.
157
+ > Make is exactly designed for this purpose while NPM scripts are hard to compose, reuse and are just a byproduct of custom package-lifecycle hook scripts.
158
+
159
+ ### Calling a make target:
121
160
 
122
- Calling a make target:
123
161
  ```bash
124
162
  make <target>
125
163
  ```
126
164
 
127
- > **ℹ️ Good to know**
165
+ > **ℹ️ Good to know**
166
+ >
128
167
  > In order to get autocompletion working in ZSH, add
129
168
  > ```bash
130
169
  > zstyle ':completion:*:make:*:targets' call-command true
@@ -132,12 +171,10 @@ make <target>
132
171
  > ```
133
172
  > to your `.zshrc`.
134
173
 
135
- > **ℹ️ Good to know II**
136
- > For the purpose of this ReadMe, “meta file” means a file that is related to the tooling itself (e.g. configuring `eslint`) and is not part of the application’s source code.
137
-
138
- > **ℹ️ Good to know III**
174
+ > **ℹ️ Good to know**
175
+ >
139
176
  > The boilerplate tries to handle “monorepos”.
140
- > For the purpose of this ReadMe, “root package” is the package that contains NPM workspaces and the packages within those workspaces are called “sub packages”.
177
+ > For the purpose of this ReadMe, “root package” is the package that contains NPM workspace definitions and the packages within those workspaces are called “sub packages”.
141
178
  >
142
179
  > When running a target from the root package, the target automatically runs for all sub packages/workspaces (`packages`) if that makes sense for the given target.
143
180
  > You can change the sub package location by overwriting `SUB_PACKAGE_DIR` in your skeleton Makefile.
@@ -147,37 +184,184 @@ make <target>
147
184
  > make check_lint include_sub_packages=false
148
185
  > ```
149
186
 
150
- target | util | description
151
- ---|---|---
152
- check || run `check_commit`, `check_package_json`, `check_lint`, `check_config`, `check_typescript` and `check_test`
153
- check_commit | `commitlint` | check validity of latest git commit message
154
- check_config | `tsc` | type-check meta files
155
- check_lint | `eslint` | lint-check both src files and meta files
156
- check_package_json || run `util_get_package_json`, `check_package_json_sort`, `check_package_json_repository`, `check_package_json_name` and `check_package_json_version`
157
- check_package_json_name | `git`, `npm` | when using git and not running in a sub package, verify that `package.json` name matches repository name, disable this behavior by overwriting target with `exit 0` in skeleton Makefile
158
- check_package_json_repository | `git`, `npm` | when using git, verify that `package.json` repository fields are set up properly (`name` === `"git"`, `url` corresponds to git repository), when running in a sub package, also verify that `directory` points to the workspace directory
159
- check_package_json_sort | `sort-package-json` | verify correct field order in `package.json`
160
- check_package_json_version | `git`, `npm` | verify that `package.json` version matches git tags
161
- check_test | `jest` | run unit tests
162
- check_typescript | `tsc` | type-check src files
163
- transform || run `transform_package_json`, `transform_lint` and `transform_typescript`
164
- transform_clear || run `util_clear` and `transform`
165
- transform_lint | `eslint` | lint-fix both src files and meta files
166
- transform_package_json || run `transform_package_json_sort`, `transform_package_json_name`, `transform_package_json_version` and `transform_package_json_fix`
167
- transform_package_json_fix | `npm` | apply NPM’s [package fixes](https://docs.npmjs.com/cli/v10/commands/npm-pkg) which are otherwise applied right before publishing to npmjs.com
168
- transform_package_json_name | `git`, `npm` | apply git repository name as `package.json` name
169
- transform_package_json_sort | `sort-package-json` | fix field order in `package.json`
170
- transform_package_json_version | `git`, `npm` | apply git tag version as `package.json` version
171
- transform_prod || run `util_clear` and `transform_typescript`
172
- transform_typescript | `tsc` | run build
173
- util_clear | `rm` | clear `dist` directory
174
- util_edit | `code` | open VSCode in project directory (opens separate window for each sub package when working in a monorepo so that tooling integrations can use sub package specific settings)
175
- util_get_package_json | `npm`, (optional) `highlight` | display `package.json`
176
- util_get_version | return `package.json` version
177
- util_install_git_hooks | `husky` | (re)setup git hooks
178
- watch | `tmux` | show multi-panel dashboard running watchers for linting, unit testing, config type-checking and src building (read more below)
179
- watch_config | `tsc` | continuously type-check meta files
180
- watch_dev | `tmux` | show multi-panel dashboard running watchers for linting, unit testing, config type-checking, src building and a terminal panel for additional tasks (read more below)
181
- watch_lint | `nodemon`, `eslint` | continuously lint-check both src files and meta files
182
- watch_test | `jest` | continuously run unit tests
183
- watch_typescript | `tsc` | continuously run build
187
+ ## Check
188
+
189
+ ### `make check`
190
+
191
+ Run all of:
192
+
193
+ * `check_commit`
194
+ * `check_package_json`
195
+ * `check_lint`
196
+ * `check_config`
197
+ * `check_typescript`
198
+ * `check_test`
199
+
200
+ ### `make check_commit`
201
+
202
+ Run `commitlint` for the latest commit.
203
+
204
+ ### `make check_config`
205
+
206
+ Run `tsc` to typecheck meta-files.
207
+
208
+ > **ℹ️ Good to know**
209
+ >
210
+ > For the purpose of this ReadMe, “meta-file” means a file that is related to the tooling itself (e.g. configuring ESLint) and is not part of the application’s source code.
211
+
212
+ ### `make check_lint`
213
+
214
+ Run `eslint` to lint both sourcecode and meta-files.
215
+
216
+ ### `make check_package_json`
217
+
218
+ Run all of:
219
+
220
+ * `util_get_package_json`
221
+ * `check_package_json_sort`
222
+ * `check_package_json_repository`
223
+ * `check_package_json_name`
224
+ * `check_package_json_version`
225
+
226
+ ### `make check_package_json_name`
227
+
228
+ If package is linked to a Git repository and isn’t a sub-package, check if the `package.json` name matches the repository name.
229
+
230
+ ### `make check_package_json_repository`
231
+
232
+ If package is linked to a Git repository, check if the `package.json` repository fields contain the correct type, point to the correct repository and, if the package is a sub-package, point towards the correct sub-directory within the repository.
233
+
234
+ ### `make check_package_json_sort`
235
+
236
+ Run `sort-package-json` to check for proper key sorting in `package.json`.
237
+
238
+ ### `make check_package_json_version`
239
+
240
+ If package is linked to a Git repository, check if the `package.json` version matches the latest release version derived from Git tags.
241
+
242
+ ### `make check_test`
243
+
244
+ Run unit-tests using `jest`.
245
+
246
+ ### `make check_typescript`
247
+
248
+ Run `tsc` to typecheck sourcecode.
249
+
250
+ ## Transform
251
+
252
+ ### `make transform`
253
+
254
+ Run all of:
255
+
256
+ * `transform_package_json`
257
+ * `transform_lint`
258
+ * `transform_build`
259
+
260
+ ### `make transform_build`
261
+
262
+ Run `tsc` to build sourcecode (excluding test-files).
263
+
264
+ ### `make transform_lint`
265
+
266
+ Run `eslint` to fix lint-errors in both sourcecode and meta-files.
267
+
268
+ ### `make transform_package_json`
269
+
270
+ Run all of:
271
+
272
+ * `transform_package_json_sort`
273
+ * `transform_package_json_name`
274
+ * `transform_package_json_version`
275
+ * `transform_package_json_fix`
276
+
277
+ ### `make transform_package_json_fix`
278
+
279
+ Run `npm pkg fix` to fix common misconfigurations in `package.json`.
280
+
281
+ ### `make transform_package_json_name`
282
+
283
+ If not a sub-package, set Git repository name as `package.json` name.
284
+
285
+ ### `make transform_package_json_sort`
286
+
287
+ Run `sort-package-json` to apply proper key sorting in `package.json`.
288
+
289
+ ### `make transform_package_json_version`
290
+
291
+ Set Git repository version (from tags) as `package.json` version.
292
+
293
+ ### `make transform_prod`
294
+
295
+ Run `util_clear` and `transform_build`.
296
+
297
+ ## Util
298
+
299
+ ### `make util_clear`
300
+
301
+ Clear out `dist` directory.
302
+
303
+ ### `make util_edit`
304
+
305
+ Open VSCode for root- and sub-packages.
306
+
307
+ ### `make util_get_package_json`
308
+
309
+ Output `package.json` to stdout.
310
+
311
+ ### `make util_get_package_spec`
312
+
313
+ Output root- or sub-package spec (i.e. namespace + package name + version) to stdout.
314
+
315
+ ### `make util_get_package_spec_inner`
316
+
317
+ Output package spec (i.e. namespace + package name + version) to stdout.
318
+
319
+ ### `make util_get_next_prerelease_version <prerelease-tag>`
320
+
321
+ Check Git tags for `<prerelease-tag>` and output appropriate sequential semver-prerelease version to stdout.
322
+
323
+ ### `make util_get_version`
324
+
325
+ Output `package.json` version to stdout.
326
+
327
+ ### `make util_install_git_hooks`
328
+
329
+ Run `husky` to (re)install Git-hooks.
330
+
331
+ ## Watch
332
+
333
+ ### `make watch`
334
+
335
+ Use Tmux to show multi-panel view for:
336
+
337
+ * `watch_lint`
338
+ * `watch_test`
339
+ * `watch_build`
340
+ * `watch_config`
341
+
342
+ ### `make watch_build`
343
+
344
+ Run `tsc` to build sourcecode (excluding test-files) with `--watch`-option.
345
+
346
+ ### `make watch_config`
347
+
348
+ Run `tsc` to typecheck meta-files with `--watch`-option.
349
+
350
+ ### `make watch_dev`
351
+
352
+ Use Tmux to show multi-panel view for:
353
+
354
+ * `watch_lint`
355
+ * `watch_test`
356
+ * `watch_build`
357
+ * `watch_config`
358
+
359
+ …and provide “work-area” shell at the bottom.
360
+
361
+ ### `make watch_lint`
362
+
363
+ Run `eslint` with `nodemon` to (re)lint both sourcecode and meta-files on file change.
364
+
365
+ ### `make watch_test`
366
+
367
+ Run unit-tests using `jest` with `--watch`-option.
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const sum: (a: number, b: number) => number;
2
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAAe,CAAC"}
package/dist/main.js ADDED
@@ -0,0 +1,3 @@
1
+ // noop
2
+ export const sum = (a, b) => a + b;
3
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO;AAEP,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrpelz/boilerplate-common",
3
- "version": "13.0.0",
3
+ "version": "13.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mrpelz/boilerplate.git",
@@ -24,8 +24,9 @@ if check_response "🕳 run npm install?" y; then
24
24
  npm install
25
25
  fi
26
26
 
27
- if check_response "📂 create \"src\" directory (this will *not* overwrite/empty out existing directories)?" y; then
27
+ if check_response "📂 create \"src\" directory and main entry-file (this will *not* overwrite/empty out existing directories/files)?" y; then
28
28
  mkdir -p src
29
+ touch "src/main.ts"
29
30
  fi
30
31
 
31
32
  if check_response "📂 create \"dist\" directory (this will *not* overwrite/empty out existing directories)?" y; then