@divithselvam/jokebook 0.0.0-stage → 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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +186 -2
- package/bin/run.js +24 -0
- package/dist/commands/add.d.ts +25 -0
- package/dist/commands/add.js +144 -0
- package/dist/commands/init.d.ts +18 -0
- package/dist/commands/init.js +218 -0
- package/dist/commands/stack/list.d.ts +40 -0
- package/dist/commands/stack/list.js +83 -0
- package/dist/commands/stack/show.d.ts +11 -0
- package/dist/commands/stack/show.js +35 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +203 -0
- package/dist/starter-1.0.0-desktop.tgz +0 -0
- package/dist/starter-1.0.0-mobile.tgz +0 -0
- package/dist/starter-1.0.0-web.tgz +0 -0
- package/docs/STACK.md +565 -0
- package/package.json +85 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Jokebook are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-11-30
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Versioned starter 1.0.0 with `web`, `desktop`, `mobile` and `full` presets.
|
|
10
|
+
- SvelteKit and Vite+ web foundation, Rust/Axum API, Cargo workspace, PostgreSQL Compose configuration and one root pnpm lockfile.
|
|
11
|
+
- Optional Tauri desktop client generated from the official Tauri template.
|
|
12
|
+
- Optional shared Swift 6.4.3 core with a SwiftUI iOS app and a Jetpack Compose Android app, linked through swift-java 0.7.0 JNI bindings and the Swift SDK for Android.
|
|
13
|
+
- `jokebook init` with interactive and unattended modes, dry runs, JSON output, exact destination handling, staging and cancellation.
|
|
14
|
+
- `jokebook stack list` and `jokebook stack show` with catalog hash verification and full capability lookup.
|
|
15
|
+
- `jokebook add runtime-validation` (alias `valibot`) with exact pinning, idempotency, verification and rollback.
|
|
16
|
+
- Project-local installation of `blame-the-intern` and `modern-web-guidance` through the pinned Skills CLI 1.9.1.
|
|
17
|
+
- Provenance checks for both skills and the exact two-line generated `AGENTS.md`.
|
|
18
|
+
- Byte-for-byte `STACK.md` copies whose SHA-256 is recorded in each product.
|
|
19
|
+
- Local release verification with ESLint, tests, a packed-package smoke test and `prepublishOnly`.
|
|
20
|
+
- Node 26.13.1, npm 11.20.0 and pnpm 12.25.1 pins.
|
|
21
|
+
|
|
22
|
+
### Security
|
|
23
|
+
|
|
24
|
+
- Child processes run with closed stdin, a non-interactive environment and a cancellation signal.
|
|
25
|
+
- Error output redacts likely tokens, credentials and authorization headers.
|
|
26
|
+
- Existing non-empty destinations are refused.
|
|
27
|
+
- A staged product is moved into place only after dependency installation, recipe checks and both skill verifications succeed.
|
|
28
|
+
|
|
29
|
+
[1.0.0]: https://github.com/Divith123/jokebook/releases/tag/v1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License Copyright (c) 2026 Divithselvam
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free
|
|
4
|
+
of charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,187 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Jokebook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@divithselvam/jokebook)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Jokebook is a versioned project generator for production-minded web products. One command creates a pnpm workspace with a SvelteKit web app, a Rust/Axum API, PostgreSQL development configuration, and optional Tauri desktop and shared-Swift native mobile clients.
|
|
7
|
+
|
|
8
|
+
Every generated product carries a byte-for-byte copy of the architecture and package catalog it was built from, plus two project-local agent skills whose source commits are recorded in `skills-lock.json`. Generation is staged, checked, and moved into place only after dependency installation and skill verification succeed.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- **Node.js 26.13.1** with its **npm 11.20.0** and `npx`.
|
|
13
|
+
- **pnpm 12.25.1** on `PATH`.
|
|
14
|
+
- **Git**.
|
|
15
|
+
- For native targets: Rust 1.100.1, Docker, Xcode 27.2, Swift 6.4.3, the Swift SDK for Android, Android NDK r30 and a JDK as described in the generated mobile `README.md`.
|
|
16
|
+
|
|
17
|
+
Jokebook rejects a different Node or pnpm release before writing a product. The CLI itself is published for Node 26.13.1.
|
|
18
|
+
|
|
19
|
+
## Install and run
|
|
20
|
+
|
|
21
|
+
Without a global install:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm exec --yes --package=@divithselvam/jokebook -- jokebook init
|
|
25
|
+
npm exec --yes --package=@divithselvam/jokebook -- jokebook init my-product --preset web --no-interactive --json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install the executable globally:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install --global @divithselvam/jokebook
|
|
32
|
+
jokebook init
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Presets
|
|
36
|
+
|
|
37
|
+
| Preset | Surfaces |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `web` (default) | SvelteKit, Vite+, Rust/Axum API and PostgreSQL development configuration |
|
|
40
|
+
| `desktop` | Web foundation plus a Tauri desktop client |
|
|
41
|
+
| `mobile` | Web foundation plus a shared Swift core, a SwiftUI iOS app and a Jetpack Compose Android app |
|
|
42
|
+
| `full` | Web foundation, Tauri desktop client, SwiftUI iOS app and Jetpack Compose Android app |
|
|
43
|
+
|
|
44
|
+
No GPUI preset is shipped. The catalog documents GPUI for products that need a native Rust renderer, but Jokebook has no verified upstream generation route for it.
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
jokebook init [product] [--preset web|desktop|mobile|full] [--dir <path>] [--with <recipe>]...
|
|
50
|
+
[--interactive | --no-interactive] [--json] [--dry-run]
|
|
51
|
+
jokebook stack list [--json]
|
|
52
|
+
jokebook stack show <capability> [--json]
|
|
53
|
+
jokebook add <recipe> [--no-interactive] [--json] [--dry-run]
|
|
54
|
+
jokebook --help
|
|
55
|
+
jokebook --version
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### `init`
|
|
59
|
+
|
|
60
|
+
Flags take precedence. In an interactive terminal, Jokebook prompts only for missing values: product name, destination, preset and optional recipes. It shows the resolved plan before writing.
|
|
61
|
+
|
|
62
|
+
`--no-interactive`, `--json`, CI, a missing TTY or `TERM=dumb` select unattended mode. Unattended mode requires a product name and never reads stdin. Defaults are the `web` preset, no recipes and `./<product>`.
|
|
63
|
+
|
|
64
|
+
`--dir` sets the exact destination. Its parent must already exist; the destination itself must be absent or an empty real directory. `--dry-run` validates and prints the resolved plan without writing a project, changing manifests or installing skills.
|
|
65
|
+
|
|
66
|
+
The command exits `0` on success, `1` on failure and `130` on cancellation. `--json` prints exactly one parseable object to stdout in both cases, with the operation, stage, destination, starter revision, resolved settings, installed skills, actionable error details and a corrected usage line when relevant.
|
|
67
|
+
|
|
68
|
+
### `stack`
|
|
69
|
+
|
|
70
|
+
`stack list` and `stack show` are read-only. Inside a generated product they read that product's pinned `STACK.md` and verify its SHA-256. Elsewhere they read the catalog bundled with the CLI.
|
|
71
|
+
|
|
72
|
+
`stack show` accepts a capability slug from `stack list` or a unique backticked package name. It reports the recommendation, version evidence, owning workspace, source rows and links, supported setup notes and verification status.
|
|
73
|
+
|
|
74
|
+
### `add`
|
|
75
|
+
|
|
76
|
+
`add runtime-validation` (alias `valibot`) resolves the catalog's exact Valibot 1.5.0 pin in `apps/web`, installs it with the product's pnpm workspace, and verifies a real import. It can also be selected with `init --with runtime-validation`. Repeating the recipe verifies the existing installation and makes no change.
|
|
77
|
+
|
|
78
|
+
Catalog capabilities without an automated recipe return their documented setup guidance and leave the product untouched. Run `add` from the product directory or any of its subdirectories.
|
|
79
|
+
|
|
80
|
+
## What a product contains
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
my-product/
|
|
84
|
+
apps/web/ SvelteKit web application
|
|
85
|
+
apps/desktop/ Tauri desktop client (desktop and full)
|
|
86
|
+
apps/mobile/ Shared Swift core, SwiftUI iOS app and Jetpack Compose Android app
|
|
87
|
+
(mobile and full; see apps/mobile/README.md)
|
|
88
|
+
services/api/ Rust/Axum HTTP API
|
|
89
|
+
packages/ Shared workspace packages
|
|
90
|
+
STACK.md Pinned architecture and package catalog
|
|
91
|
+
AGENTS.md Two-line project instruction for coding agents
|
|
92
|
+
skills-lock.json Skills CLI provenance for both project skills
|
|
93
|
+
pnpm-workspace.yaml One pnpm workspace and root lockfile
|
|
94
|
+
Cargo.toml Rust workspace
|
|
95
|
+
package.json Product marker, preset and catalog hash
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The generated `README.md` covers development commands, the API and readiness endpoints, production static hosting, native prerequisites and catalog lookup commands.
|
|
99
|
+
|
|
100
|
+
## How generation works
|
|
101
|
+
|
|
102
|
+
1. Resolve flags and prompts into one validated configuration.
|
|
103
|
+
2. Reject a non-empty destination before touching the filesystem.
|
|
104
|
+
3. Extract the versioned starter into a staging directory alongside the destination.
|
|
105
|
+
4. Write the product marker, copy the pinned catalog and configure desktop identifiers when needed.
|
|
106
|
+
5. Run `pnpm install --frozen-lockfile` in the staged workspace.
|
|
107
|
+
6. Apply selected recipes and install both project-local agent skills.
|
|
108
|
+
7. Re-check the destination and rename the completed staging directory into place.
|
|
109
|
+
|
|
110
|
+
If any step fails, the staging directory is removed and an existing empty destination is left untouched. Child processes receive closed stdin, a non-interactive environment and a cancellation signal.
|
|
111
|
+
|
|
112
|
+
## Catalog and recipes
|
|
113
|
+
|
|
114
|
+
`docs/STACK.md` is the canonical package and platform decision record. Starter 1.0.0 preserves the 30 November 2026 catalog at SHA-256 `850953320cc8e9093b9c3286e4279596dbdd274319e2b60ab648977ae4e90307`.
|
|
115
|
+
|
|
116
|
+
Every generated product gets a byte-for-byte copy of that revision. The CLI refuses to continue if a product's `STACK.md` no longer matches the hash recorded in its `package.json`. Catalog rows are parsed into capability slugs, versions, workspace ownership, setup notes and source links by `jokebook stack list` and `jokebook stack show`.
|
|
117
|
+
|
|
118
|
+
`runtime-validation` is the only automated recipe in 1.0.0 because it has a real, repeatable integration test. Other capabilities remain documented recommendations; they are not installed blindly.
|
|
119
|
+
|
|
120
|
+
## Agent skills
|
|
121
|
+
|
|
122
|
+
Every real `init` installs these two skills with the pinned Skills CLI 1.9.1, from the staged product root:
|
|
123
|
+
|
|
124
|
+
- `Divith123/skills` → `blame-the-intern`
|
|
125
|
+
- `googlechrome/modern-web-guidance` → `modern-web-guidance`
|
|
126
|
+
|
|
127
|
+
Both use the project-local `universal` target and copy mode. Jokebook verifies each `SKILL.md` identity and the source repository and commit recorded by the Skills CLI. It then writes the starter's exact two-line `AGENTS.md`:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
Use `blame-the-intern` from `.agents/skills/blame-the-intern/SKILL.md` and read `STACK.md` before scaffolding or changing dependencies.
|
|
131
|
+
Use `modern-web-guidance` from `.agents/skills/modern-web-guidance/SKILL.md` for browser UI, accessibility, and web performance.
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
No agent command or global skill installation is required after generation.
|
|
135
|
+
|
|
136
|
+
## Runtime decisions
|
|
137
|
+
|
|
138
|
+
The default and only qualified runtime path is Node 26.13.1 with pnpm 12.25.1. Vite+'s environment management selects Node and supports a pinned pnpm version; the starter uses one root pnpm workspace and lockfile.
|
|
139
|
+
|
|
140
|
+
Deno is not a supported product profile. It has npm compatibility and its own dependency management, but Jokebook has no verified Deno starter that passes official scaffolding, workspace resolution, Vite+ builds, both Skills CLI installs, Tauri tooling and packed-CLI checks. Shipping a Deno label without those checks would be misleading.
|
|
141
|
+
|
|
142
|
+
## Local verification
|
|
143
|
+
|
|
144
|
+
This repository intentionally does not depend on GitHub Actions. The release gate runs locally with the pinned toolchain:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
npm ci
|
|
148
|
+
npm run verify
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`npm run verify` runs ESLint, the test suite and a packed-package smoke test. The smoke test builds the tarball, installs it into a clean temporary directory, runs `jokebook --version`, reads the full catalog and resolves a dry-run plan. `npm run verify:package` runs only that package check.
|
|
152
|
+
|
|
153
|
+
Before a release, inspect the package and run a publish dry run:
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
npm pack
|
|
157
|
+
npm publish --access public --dry-run
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`prepublishOnly` runs `npm run verify`, so a publish cannot bypass the local gate. `npm run build` produces the compiled CLI and the three starter archives in `dist/`.
|
|
161
|
+
|
|
162
|
+
## Starter provenance
|
|
163
|
+
|
|
164
|
+
Starter **1.0.0** preserves the 30 November 2026 catalog at SHA-256 `850953320cc8e9093b9c3286e4279596dbdd274319e2b60ab648977ae4e90307`.
|
|
165
|
+
|
|
166
|
+
| Source | Generation |
|
|
167
|
+
| --- | --- |
|
|
168
|
+
| CLI | oclif 6.0.15 `generate` and `generate command` |
|
|
169
|
+
| Workspace and `AGENTS.md` | Vite+ 1.8.0 `vp create vite:monorepo --agent codex --package-manager pnpm --no-interactive` |
|
|
170
|
+
| Web | `sv@1.7.1 create`, minimal and demo templates with the static adapter. The demo supplies the generated route-options file. |
|
|
171
|
+
| PostgreSQL compose | Svelte CLI 1.7.1 official Drizzle add-on with PostgreSQL and Docker. The Compose service was integrated with SQLx. |
|
|
172
|
+
| Rust | Cargo 1.100.1 `init --lib`, `new --bin`, `add` and `generate-lockfile` |
|
|
173
|
+
| Desktop | `create-tauri-app@4.7.5` Svelte TypeScript template, built by Tauri CLI 2.13.0 |
|
|
174
|
+
| Mobile | Hand-written SwiftPM `MobileCore` and `MobileCoreAndroid` targets, SwiftUI app, Jetpack Compose app, swift-java 0.7.0 JNI bindings, Swift 6.4.3, Kotlin 2.4.21, Compose BOM 2026.09.00, Gradle 9.5.0 and NDK r30 |
|
|
175
|
+
| Skills | Vercel Skills CLI 1.9.1, run locally with `--agent universal --copy --yes` |
|
|
176
|
+
|
|
177
|
+
Refresh starter sources with the upstream generators, verify the resulting workspace locks and target builds, then update the starter revision and catalog digest before packing. The Jokebook source repository uses npm to build and distribute the CLI; each generated product uses pnpm.
|
|
178
|
+
|
|
179
|
+
Release verification for 1.0.0 runs on macOS on Apple silicon. The CLI and starter use cross-platform Node APIs, but Linux and Windows native builds are not part of the 1.0.0 verification matrix. The generated README lists the host-specific prerequisites.
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request. Security reports belong in [SECURITY.md](SECURITY.md). Participation is covered by the [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See [LICENSE](LICENSE).
|
package/bin/run.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
if (Object.hasOwn(process.env, 'NO_COLOR')) delete process.env.FORCE_COLOR
|
|
4
|
+
const {run, flush, Errors} = await import('@oclif/core')
|
|
5
|
+
try {
|
|
6
|
+
await run(process.argv.slice(2), import.meta.url)
|
|
7
|
+
await flush()
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (!process.argv.includes('--json')) {
|
|
10
|
+
await Errors.handle(error)
|
|
11
|
+
} else {
|
|
12
|
+
console.log(JSON.stringify({
|
|
13
|
+
ok: false,
|
|
14
|
+
stage: 'arguments',
|
|
15
|
+
settings: null,
|
|
16
|
+
destination: null,
|
|
17
|
+
starterRevision: '1.0.0',
|
|
18
|
+
installedSkills: [],
|
|
19
|
+
error: {message: error.message},
|
|
20
|
+
usage: 'Try: jokebook --help',
|
|
21
|
+
}))
|
|
22
|
+
process.exitCode = 1
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import { findProduct, Workflow } from '../index.js';
|
|
3
|
+
export declare const recipeName = "runtime-validation";
|
|
4
|
+
export declare const recipePackage = "valibot";
|
|
5
|
+
export declare function resolveRecipe(name: string, product?: Awaited<ReturnType<typeof findProduct>>): Promise<string>;
|
|
6
|
+
export declare function applyRecipe(workflow: Workflow, cwd: string, recipe: string, isDryRun: boolean): Promise<{
|
|
7
|
+
alreadyApplied: boolean;
|
|
8
|
+
changed: boolean;
|
|
9
|
+
dryRun: boolean;
|
|
10
|
+
package: string;
|
|
11
|
+
recipe: string;
|
|
12
|
+
workspace: string;
|
|
13
|
+
}>;
|
|
14
|
+
export default class Add extends Command {
|
|
15
|
+
static args: {
|
|
16
|
+
recipe: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
17
|
+
};
|
|
18
|
+
static description: string;
|
|
19
|
+
static flags: {
|
|
20
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
'no-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
};
|
|
24
|
+
run(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import { lstat, mkdir, readFile, rmdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { catalogDocument, findProduct, Issue, readJson, release, slug, Workflow } from '../index.js';
|
|
5
|
+
import { entries, lookup } from './stack/list.js';
|
|
6
|
+
export const recipeName = 'runtime-validation';
|
|
7
|
+
export const recipePackage = 'valibot';
|
|
8
|
+
const recipeVersion = '1.5.0';
|
|
9
|
+
const usage = 'Try: jokebook add runtime-validation --no-interactive (from a Jokebook product)';
|
|
10
|
+
export async function resolveRecipe(name, product) {
|
|
11
|
+
if ([recipeName, recipePackage].includes(slug(name)))
|
|
12
|
+
return recipeName;
|
|
13
|
+
const { text } = await catalogDocument(product);
|
|
14
|
+
const capability = lookup(entries(text), name);
|
|
15
|
+
if (capability) {
|
|
16
|
+
throw new Issue('This capability requires manual integration. Follow the catalog setup instructions.', { capability });
|
|
17
|
+
}
|
|
18
|
+
throw new Issue(`Unknown recipe "${name}". Run jokebook stack list to find a capability.`);
|
|
19
|
+
}
|
|
20
|
+
async function inspect(cwd) {
|
|
21
|
+
const workspace = path.join(cwd, 'apps/web');
|
|
22
|
+
const manifest = path.join(workspace, 'package.json');
|
|
23
|
+
const lockfile = path.join(cwd, 'pnpm-lock.yaml');
|
|
24
|
+
const root = path.join(cwd, 'package.json');
|
|
25
|
+
const expected = [root, manifest, lockfile, path.join(cwd, 'pnpm-workspace.yaml')];
|
|
26
|
+
await Promise.all(expected.map(async (file) => {
|
|
27
|
+
if (!(await lstat(file)).isFile())
|
|
28
|
+
throw new Issue(`Expected a regular project file at ${file}.`);
|
|
29
|
+
}));
|
|
30
|
+
const { packageManager } = await readJson(root);
|
|
31
|
+
if (packageManager !== `pnpm@${release.pnpm}`)
|
|
32
|
+
throw new Issue('Restore the starter pnpm pin before applying recipes.');
|
|
33
|
+
const contents = await readFile(manifest, 'utf8');
|
|
34
|
+
const data = JSON.parse(contents);
|
|
35
|
+
const declarations = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
|
|
36
|
+
.filter((group) => data[group]?.[recipePackage] !== undefined);
|
|
37
|
+
const isApplied = declarations.length === 1 && declarations[0] === 'dependencies' &&
|
|
38
|
+
data.dependencies?.[recipePackage] === recipeVersion;
|
|
39
|
+
if (!isApplied && declarations.length > 0) {
|
|
40
|
+
throw new Issue(`apps/web already declares ${recipePackage} in a conflicting form. Review that declaration before applying this recipe.`);
|
|
41
|
+
}
|
|
42
|
+
return { contents, isApplied, lockfile, manifest };
|
|
43
|
+
}
|
|
44
|
+
export async function applyRecipe(workflow, cwd, recipe, isDryRun) {
|
|
45
|
+
workflow.stage = 'recipe-inspection';
|
|
46
|
+
if (recipe !== recipeName)
|
|
47
|
+
throw new Issue(`Unknown verified recipe "${recipe}".`);
|
|
48
|
+
const current = await inspect(cwd);
|
|
49
|
+
const spec = `${recipePackage}@${recipeVersion}`;
|
|
50
|
+
const result = {
|
|
51
|
+
alreadyApplied: current.isApplied,
|
|
52
|
+
changed: !current.isApplied && !isDryRun,
|
|
53
|
+
dryRun: isDryRun,
|
|
54
|
+
package: spec,
|
|
55
|
+
recipe,
|
|
56
|
+
workspace: 'apps/web',
|
|
57
|
+
};
|
|
58
|
+
if (isDryRun)
|
|
59
|
+
return result;
|
|
60
|
+
const lock = path.join(cwd, '.jokebook-recipe-lock');
|
|
61
|
+
try {
|
|
62
|
+
await mkdir(lock);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error.code === 'EEXIST') {
|
|
66
|
+
throw new Issue('Another Jokebook recipe is running. If it exited unexpectedly, remove the empty .jokebook-recipe-lock directory and retry.');
|
|
67
|
+
}
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const { contents, isApplied, lockfile, manifest } = await inspect(cwd);
|
|
72
|
+
const previousLock = await readFile(lockfile);
|
|
73
|
+
workflow.stage = 'recipe-installation';
|
|
74
|
+
try {
|
|
75
|
+
if (!isApplied) {
|
|
76
|
+
await workflow.command('pnpm', ['--filter', './apps/web', 'add', '--save-exact', '--lockfile-only', spec], {
|
|
77
|
+
cwd,
|
|
78
|
+
deliverable: `resolve ${spec} for apps/web`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
await workflow.command('pnpm', ['install', '--frozen-lockfile'], { cwd, deliverable: 'install recipe dependencies' });
|
|
82
|
+
workflow.stage = 'recipe-verification';
|
|
83
|
+
await workflow.command('pnpm', ['--filter', './apps/web', 'exec', 'node', '--input-type=module',
|
|
84
|
+
'-e', "import {parse, string} from 'valibot'; if (parse(string(), 'ready') !== 'ready') process.exit(1)"], {
|
|
85
|
+
cwd,
|
|
86
|
+
deliverable: `verify ${spec} from apps/web`,
|
|
87
|
+
});
|
|
88
|
+
return { ...result, alreadyApplied: isApplied, changed: !isApplied };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!isApplied) {
|
|
92
|
+
await writeFile(manifest, contents);
|
|
93
|
+
await writeFile(lockfile, previousLock);
|
|
94
|
+
try {
|
|
95
|
+
await workflow.command('pnpm', ['install', '--frozen-lockfile'], {
|
|
96
|
+
cwd,
|
|
97
|
+
deliverable: 'restore original dependency installation',
|
|
98
|
+
signal: new AbortController().signal,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error_) {
|
|
102
|
+
throw new Issue('Recipe failed and dependency recovery also failed. The pre-recipe manifest and lockfile were restored.', { original: error instanceof Issue ? { message: error.message, ...error.details } : String(error),
|
|
103
|
+
recovery: error_ instanceof Issue ? { message: error_.message, ...error_.details } : String(error_) });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
await rmdir(lock);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export default class Add extends Command {
|
|
114
|
+
static args = { recipe: Args.string({ description: 'Recipe or catalog capability slug', required: true }) };
|
|
115
|
+
static description = 'Apply a verified recipe to an existing product';
|
|
116
|
+
static flags = {
|
|
117
|
+
'dry-run': Flags.boolean({ description: 'Inspect and show planned changes' }),
|
|
118
|
+
json: Flags.boolean({ description: 'Emit a single JSON result' }),
|
|
119
|
+
'no-interactive': Flags.boolean({ description: 'Use unattended mode (the default)' }),
|
|
120
|
+
};
|
|
121
|
+
async run() {
|
|
122
|
+
const workflow = new Workflow('add');
|
|
123
|
+
await workflow.report(this.argv.includes('--json'), usage, async () => {
|
|
124
|
+
const { args, flags } = await this.parse(Add);
|
|
125
|
+
workflow.stage = 'recipe-inspection';
|
|
126
|
+
const product = await findProduct();
|
|
127
|
+
if (product) {
|
|
128
|
+
workflow.destination = product.cwd;
|
|
129
|
+
workflow.starterRevision = product.marker.starter;
|
|
130
|
+
await catalogDocument(product);
|
|
131
|
+
}
|
|
132
|
+
const recipe = await resolveRecipe(args.recipe, product);
|
|
133
|
+
if (!product)
|
|
134
|
+
throw new Issue('Run this command inside a product created by Jokebook.');
|
|
135
|
+
if (product.marker.starter !== release.revision)
|
|
136
|
+
throw new Issue('Use the Jokebook version that created this starter.');
|
|
137
|
+
if (!flags['dry-run'])
|
|
138
|
+
await workflow.prerequisites(product.cwd);
|
|
139
|
+
const result = await applyRecipe(workflow, product.cwd, recipe, flags['dry-run']);
|
|
140
|
+
workflow.stage = flags['dry-run'] ? 'plan' : 'complete';
|
|
141
|
+
return result;
|
|
142
|
+
}, (result) => `${result.dryRun ? 'Plan:' : 'Verified'} ${result.package} in ${result.workspace}${result.alreadyApplied ? ' (already applied)' : ''}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Init extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
product: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
dir: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
'no-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
preset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
with: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<void>;
|
|
18
|
+
}
|