@doikayt/typescript-build-config 0.1.20 → 0.1.21
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 +48 -3
- package/package.json +1 -1
- package/src/cli.js +14 -3
- package/src/init.js +1 -5
- package/src/new-package.js +38 -0
- package/src/scope-name.js +6 -0
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Shared build configuration presets for TypeScript-based projects.
|
|
|
13
13
|
- [Console / CLI project](#console--cli-project)
|
|
14
14
|
- [UI / web project (with Playwright e2e)](#ui--web-project-with-playwright-e2e)
|
|
15
15
|
- [Existing project](#existing-project)
|
|
16
|
+
- [Trying it out (demo + scratch repo)](#trying-it-out-demo--scratch-repo)
|
|
16
17
|
- [Dependency Strategy](#dependency-strategy)
|
|
17
18
|
- [Current Contents](#current-contents)
|
|
18
19
|
- [Delivery Model](#delivery-model)
|
|
@@ -23,6 +24,7 @@ Shared build configuration presets for TypeScript-based projects.
|
|
|
23
24
|
- [NX projects](#nx-projects)
|
|
24
25
|
- [The `update-all-format` target](#the-update-all-format-target)
|
|
25
26
|
- [Publishing](#publishing)
|
|
27
|
+
- [Team shell aliases](#team-shell-aliases)
|
|
26
28
|
- [For Maintainers](#for-maintainers)
|
|
27
29
|
- [Clone and install](#clone-and-install)
|
|
28
30
|
- [Run the full CI suite](#run-the-full-ci-suite)
|
|
@@ -136,7 +138,7 @@ publish config accordingly (non-destructively):
|
|
|
136
138
|
### Console / CLI project
|
|
137
139
|
|
|
138
140
|
```bash
|
|
139
|
-
npm init -y
|
|
141
|
+
npx @doikayt/typescript-build-config new # npm init -y + @doikayt scope
|
|
140
142
|
npm install --save-dev @doikayt/typescript-build-config
|
|
141
143
|
npx @doikayt/typescript-build-config init # answer "n" to Playwright; "n" (app) or "y" (library)
|
|
142
144
|
npm install # fetch the declared devDependencies
|
|
@@ -153,7 +155,7 @@ library (see [The canonical script set](#the-canonical-script-set)).
|
|
|
153
155
|
### UI / web project (with Playwright e2e)
|
|
154
156
|
|
|
155
157
|
```bash
|
|
156
|
-
npm init -y
|
|
158
|
+
npx @doikayt/typescript-build-config new # npm init -y + @doikayt scope
|
|
157
159
|
npm install --save-dev @doikayt/typescript-build-config
|
|
158
160
|
npx @doikayt/typescript-build-config init # answer "y" to the Playwright prompt
|
|
159
161
|
npm install
|
|
@@ -173,6 +175,22 @@ required targets (`ci`, `update-all-format`) until you add them — either by
|
|
|
173
175
|
running `init` to adopt the full canonical set, or by defining the two scripts
|
|
174
176
|
by hand (see [Conventions](#conventions-every-project-must-adhere-to)).
|
|
175
177
|
|
|
178
|
+
### Trying it out (demo + scratch repo)
|
|
179
|
+
|
|
180
|
+
Answer **yes** to the demo prompt and `init` seeds a minimal starter — a `src/`
|
|
181
|
+
module, a `README` with doc-generator markers, and a `project.json` — so a
|
|
182
|
+
brand-new project builds, tests, and (for a library) publishes on push.
|
|
183
|
+
|
|
184
|
+
To exercise a scaffold end-to-end without standing up a repo, push it to the
|
|
185
|
+
shared throwaway repo
|
|
186
|
+
**[`doikayt/scratch-pad`](https://github.com/doikayt/scratch-pad)** (force-overwrite
|
|
187
|
+
each run). The full procedure — for both a library and an app, with what to look
|
|
188
|
+
for at each step — is in [docs/verification-runbook.md](docs/verification-runbook.md):
|
|
189
|
+
|
|
190
|
+
- [Pushing to the scratch repo](docs/verification-runbook.md#pushing-to-a-reusable-scratch-repo)
|
|
191
|
+
- [Testing publish without cluttering npm](docs/verification-runbook.md#testing-publish-without-cluttering-npm)
|
|
192
|
+
— dry-run / verdaccio, and deleting a real test publish afterward.
|
|
193
|
+
|
|
176
194
|
## Dependency Strategy
|
|
177
195
|
|
|
178
196
|
`eslint` and `prettier` are listed as `dependencies` and are pulled in
|
|
@@ -185,6 +203,8 @@ versions of these tools may produce peer dependency conflicts.
|
|
|
185
203
|
|
|
186
204
|
## Current Contents
|
|
187
205
|
|
|
206
|
+
- `new` command (`npx @doikayt/typescript-build-config new`) — runs `npm init -y`
|
|
207
|
+
then scopes the package name to `@doikayt` (an existing scope is kept)
|
|
188
208
|
- `init` scaffolder CLI (`npx @doikayt/typescript-build-config init`) — writes
|
|
189
209
|
the canonical npm-script set, declares dev dependencies, and seeds config
|
|
190
210
|
templates (see [Usage](#usage))
|
|
@@ -473,6 +493,31 @@ release job until one is committed.
|
|
|
473
493
|
**Manual publish (emergency):** trigger the workflow manually via
|
|
474
494
|
**GitHub Actions → CI / Release → Run workflow** on the `main` branch.
|
|
475
495
|
|
|
496
|
+
## Team shell aliases
|
|
497
|
+
|
|
498
|
+
This repo doubles as the team's base setup. After cloning it, install the shared
|
|
499
|
+
shell aliases — a **required** onboarding step, so everyone creates and scaffolds
|
|
500
|
+
repos the same way:
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
git clone git@github.com:doikayt/typescript-build-config.git
|
|
504
|
+
cd typescript-build-config
|
|
505
|
+
./shell/install.sh # adds a `source` line to ~/.zshrc / ~/.bashrc (idempotent)
|
|
506
|
+
exec $SHELL # reload — or: source shell/aliases.sh
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
Manual alternative: add `source <clone-path>/shell/aliases.sh` to your shell rc.
|
|
510
|
+
|
|
511
|
+
Aliases provided ([`shell/aliases.sh`](shell/aliases.sh)) — require `gh`
|
|
512
|
+
(authenticated) and `node`/`npm`:
|
|
513
|
+
|
|
514
|
+
| Alias | What it does |
|
|
515
|
+
| --- | --- |
|
|
516
|
+
| `mkrepo <name>` | Create a public repo in the `doikayt` org (guards against duplicates). |
|
|
517
|
+
| `dk-new` | `npm init -y` + `@doikayt` scope. |
|
|
518
|
+
| `dk-init` | Scaffold the build config into the current project. |
|
|
519
|
+
| `dk-scaffold <name> [lib\|app]` | Create the repo, scaffold, and push — one command (defaults to app). |
|
|
520
|
+
|
|
476
521
|
## For Maintainers
|
|
477
522
|
|
|
478
523
|
### Clone and install
|
|
@@ -509,7 +554,7 @@ npm run update-all-format && npm run ci
|
|
|
509
554
|
|
|
510
555
|
To verify end-to-end that `init` scaffolds and ships both a library and an app —
|
|
511
556
|
by hand, with what to look for at each step — follow
|
|
512
|
-
[docs/
|
|
557
|
+
[docs/verification-runbook.md](docs/verification-runbook.md).
|
|
513
558
|
|
|
514
559
|
## License
|
|
515
560
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doikayt/typescript-build-config",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Shared build configuration for TypeScript projects — ESLint, Prettier, tsconfig, and Playwright presets",
|
|
5
5
|
"_comments": {
|
|
6
6
|
"exports": "This block lists the config files that will be extended by files in in src/toplevel - which are copied to consuming project root folder. An example: eslint.config.js imports from '@doikayt/typescript-build-config/eslint'.",
|
package/src/cli.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Main CLI entry for this package, registered as the `typescript-build-config`
|
|
3
3
|
// bin. Invoked as `npx @doikayt/typescript-build-config <subcommand>` — npx
|
|
4
4
|
// resolves the bin whose name matches the package. argv[2] is the subcommand
|
|
5
|
-
// (argv[0]=node, argv[1]=this file).
|
|
6
|
-
//
|
|
5
|
+
// (argv[0]=node, argv[1]=this file). This dispatcher is the seam where future
|
|
6
|
+
// subcommands (e.g. `check-conventions`) plug in.
|
|
7
7
|
import { runInit } from "./init.js";
|
|
8
|
+
import { runNew } from "./new-package.js";
|
|
8
9
|
|
|
9
10
|
const sub = process.argv[2];
|
|
10
11
|
|
|
@@ -18,9 +19,19 @@ if (sub === "init") {
|
|
|
18
19
|
process.exit(1);
|
|
19
20
|
},
|
|
20
21
|
);
|
|
22
|
+
} else if (sub === "new") {
|
|
23
|
+
// `npm init -y` + @doikayt scope. Synchronous (spawnSync).
|
|
24
|
+
try {
|
|
25
|
+
runNew();
|
|
26
|
+
process.exit(0);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(err?.message ?? err);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
21
31
|
} else {
|
|
22
32
|
console.error(
|
|
23
|
-
`Unknown command: ${sub ?? "(none)"}\
|
|
33
|
+
`Unknown command: ${sub ?? "(none)"}\n` +
|
|
34
|
+
`Usage: typescript-build-config <new|init>`,
|
|
24
35
|
);
|
|
25
36
|
process.exit(1);
|
|
26
37
|
}
|
package/src/init.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "./canonical-scripts.js";
|
|
17
17
|
import { applyToPackageJson } from "./package-json.js";
|
|
18
18
|
import { resolveVersions } from "./dep-versions.js";
|
|
19
|
+
import { scopeName } from "./scope-name.js";
|
|
19
20
|
|
|
20
21
|
const templatesDir = fileURLToPath(new URL("templates/", import.meta.url));
|
|
21
22
|
|
|
@@ -76,11 +77,6 @@ function createAskYesNo() {
|
|
|
76
77
|
return ask;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
// Prepend the @doikayt scope unless the name is already scoped.
|
|
80
|
-
function scopeName(name) {
|
|
81
|
-
return name.startsWith("@") ? name : `@doikayt/${name}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
80
|
export async function runInit({
|
|
85
81
|
cwd = process.cwd(),
|
|
86
82
|
prompt,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { spawnSync } from "child_process";
|
|
4
|
+
import { scopeName } from "./scope-name.js";
|
|
5
|
+
|
|
6
|
+
// Default `npm init -y` runner. Injectable so runNew is testable without npm.
|
|
7
|
+
function npmInitY(cwd) {
|
|
8
|
+
const res = spawnSync("npm", ["init", "-y"], { cwd, stdio: "inherit" });
|
|
9
|
+
if (res.error) throw res.error;
|
|
10
|
+
if (res.status !== 0)
|
|
11
|
+
throw new Error(`npm init -y exited with ${res.status}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Run `npm init -y`, then scope the generated package name to @doikayt unless it
|
|
15
|
+
// is already scoped (any @scope/ is left alone). Writes package.json back and
|
|
16
|
+
// returns the final name plus whether it changed.
|
|
17
|
+
export function runNew({
|
|
18
|
+
cwd = process.cwd(),
|
|
19
|
+
npmInit = npmInitY,
|
|
20
|
+
log = console.log,
|
|
21
|
+
} = {}) {
|
|
22
|
+
npmInit(cwd);
|
|
23
|
+
|
|
24
|
+
const pkgPath = resolve(cwd, "package.json");
|
|
25
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
26
|
+
const before = pkg.name || "package";
|
|
27
|
+
const scoped = scopeName(before);
|
|
28
|
+
|
|
29
|
+
if (scoped !== pkg.name) {
|
|
30
|
+
pkg.name = scoped;
|
|
31
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
32
|
+
log(`Scoped package name: ${before} → ${scoped}`);
|
|
33
|
+
} else {
|
|
34
|
+
log(`Package name already scoped: ${scoped}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { name: scoped, changed: scoped !== before };
|
|
38
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Prepend the @doikayt scope unless the name is already scoped — any existing
|
|
2
|
+
// @scope/ is left as-is. Shared by `init` (library name prompt) and the `new`
|
|
3
|
+
// command (scoped `npm init`).
|
|
4
|
+
export function scopeName(name) {
|
|
5
|
+
return name.startsWith("@") ? name : `@doikayt/${name}`;
|
|
6
|
+
}
|