@ontrails/trails 1.0.0-beta.14 → 1.0.0-beta.15
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/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +13 -0
- package/__tests__/examples.test.ts +29 -4
- package/dist/src/app.js +2 -2
- package/dist/src/app.js.map +1 -1
- package/dist/src/clack.d.ts +1 -1
- package/dist/src/clack.js +1 -1
- package/dist/src/cli.js +4 -3
- package/dist/src/cli.js.map +1 -1
- package/dist/src/trails/add-surface.d.ts +3 -3
- package/dist/src/trails/add-surface.d.ts.map +1 -1
- package/dist/src/trails/add-surface.js +46 -24
- package/dist/src/trails/add-surface.js.map +1 -1
- package/dist/src/trails/add-trail.d.ts +3 -1
- package/dist/src/trails/add-trail.d.ts.map +1 -1
- package/dist/src/trails/add-trail.js +38 -11
- package/dist/src/trails/add-trail.js.map +1 -1
- package/dist/src/trails/add-trailhead.d.ts +1 -1
- package/dist/src/trails/add-trailhead.d.ts.map +1 -1
- package/dist/src/trails/add-trailhead.js +4 -4
- package/dist/src/trails/add-verify.d.ts +1 -1
- package/dist/src/trails/add-verify.d.ts.map +1 -1
- package/dist/src/trails/add-verify.js +7 -6
- package/dist/src/trails/add-verify.js.map +1 -1
- package/dist/src/trails/create-scaffold.d.ts +1 -1
- package/dist/src/trails/create-scaffold.d.ts.map +1 -1
- package/dist/src/trails/create-scaffold.js +10 -3
- package/dist/src/trails/create-scaffold.js.map +1 -1
- package/dist/src/trails/create.d.ts +10 -14
- package/dist/src/trails/create.d.ts.map +1 -1
- package/dist/src/trails/create.js +42 -37
- package/dist/src/trails/create.js.map +1 -1
- package/dist/src/trails/dev-clean.d.ts +4 -4
- package/dist/src/trails/dev-clean.d.ts.map +1 -1
- package/dist/src/trails/dev-clean.js +22 -21
- package/dist/src/trails/dev-clean.js.map +1 -1
- package/dist/src/trails/dev-reset.d.ts +1 -1
- package/dist/src/trails/dev-reset.d.ts.map +1 -1
- package/dist/src/trails/dev-reset.js +3 -2
- package/dist/src/trails/dev-reset.js.map +1 -1
- package/dist/src/trails/dev-stats.d.ts +4 -4
- package/dist/src/trails/dev-stats.d.ts.map +1 -1
- package/dist/src/trails/dev-stats.js +19 -19
- package/dist/src/trails/dev-stats.js.map +1 -1
- package/dist/src/trails/dev-support.d.ts +17 -17
- package/dist/src/trails/dev-support.d.ts.map +1 -1
- package/dist/src/trails/dev-support.js +60 -57
- package/dist/src/trails/dev-support.js.map +1 -1
- package/dist/src/trails/draft-promote.d.ts +1 -1
- package/dist/src/trails/draft-promote.d.ts.map +1 -1
- package/dist/src/trails/draft-promote.js +30 -16
- package/dist/src/trails/draft-promote.js.map +1 -1
- package/dist/src/trails/guide.d.ts +2 -2
- package/dist/src/trails/guide.d.ts.map +1 -1
- package/dist/src/trails/guide.js +1 -4
- package/dist/src/trails/guide.js.map +1 -1
- package/dist/src/trails/load-app.d.ts +7 -1
- package/dist/src/trails/load-app.d.ts.map +1 -1
- package/dist/src/trails/load-app.js +374 -26
- package/dist/src/trails/load-app.js.map +1 -1
- package/dist/src/trails/survey.d.ts +5 -5
- package/dist/src/trails/survey.d.ts.map +1 -1
- package/dist/src/trails/survey.js +51 -29
- package/dist/src/trails/survey.js.map +1 -1
- package/dist/src/trails/topo-export.d.ts +5 -4
- package/dist/src/trails/topo-export.d.ts.map +1 -1
- package/dist/src/trails/topo-export.js +4 -7
- package/dist/src/trails/topo-export.js.map +1 -1
- package/dist/src/trails/topo-history.d.ts +6 -10
- package/dist/src/trails/topo-history.d.ts.map +1 -1
- package/dist/src/trails/topo-history.js +7 -8
- package/dist/src/trails/topo-history.js.map +1 -1
- package/dist/src/trails/topo-pin.d.ts +5 -9
- package/dist/src/trails/topo-pin.d.ts.map +1 -1
- package/dist/src/trails/topo-pin.js +5 -9
- package/dist/src/trails/topo-pin.js.map +1 -1
- package/dist/src/trails/topo-read-support.d.ts +12 -8
- package/dist/src/trails/topo-read-support.d.ts.map +1 -1
- package/dist/src/trails/topo-read-support.js +71 -82
- package/dist/src/trails/topo-read-support.js.map +1 -1
- package/dist/src/trails/topo-reports.d.ts +15 -11
- package/dist/src/trails/topo-reports.d.ts.map +1 -1
- package/dist/src/trails/topo-reports.js +40 -34
- package/dist/src/trails/topo-reports.js.map +1 -1
- package/dist/src/trails/topo-show.d.ts +4 -4
- package/dist/src/trails/topo-show.d.ts.map +1 -1
- package/dist/src/trails/topo-show.js +8 -12
- package/dist/src/trails/topo-show.js.map +1 -1
- package/dist/src/trails/topo-store-support.d.ts +2 -2
- package/dist/src/trails/topo-store-support.d.ts.map +1 -1
- package/dist/src/trails/topo-store-support.js +22 -22
- package/dist/src/trails/topo-store-support.js.map +1 -1
- package/dist/src/trails/topo-support.d.ts +19 -30
- package/dist/src/trails/topo-support.d.ts.map +1 -1
- package/dist/src/trails/topo-support.js +63 -96
- package/dist/src/trails/topo-support.js.map +1 -1
- package/dist/src/trails/topo-unpin.d.ts +9 -4
- package/dist/src/trails/topo-unpin.d.ts.map +1 -1
- package/dist/src/trails/topo-unpin.js +9 -4
- package/dist/src/trails/topo-unpin.js.map +1 -1
- package/dist/src/trails/topo-verify.d.ts +2 -2
- package/dist/src/trails/topo-verify.d.ts.map +1 -1
- package/dist/src/trails/topo-verify.js +1 -5
- package/dist/src/trails/topo-verify.js.map +1 -1
- package/dist/src/trails/topo.d.ts +2 -2
- package/dist/src/trails/topo.d.ts.map +1 -1
- package/dist/src/trails/topo.js +6 -10
- package/dist/src/trails/topo.js.map +1 -1
- package/dist/src/trails/warden.d.ts +3 -2
- package/dist/src/trails/warden.d.ts.map +1 -1
- package/dist/src/trails/warden.js +11 -2
- package/dist/src/trails/warden.js.map +1 -1
- package/dist/src/versions.d.ts +12 -0
- package/dist/src/versions.d.ts.map +1 -0
- package/dist/src/versions.js +23 -0
- package/dist/src/versions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/__tests__/add-trail.test.ts +97 -0
- package/src/__tests__/create.test.ts +91 -27
- package/src/__tests__/guide.test.ts +10 -5
- package/src/__tests__/load-app.test.ts +365 -4
- package/src/__tests__/survey.test.ts +143 -67
- package/src/__tests__/topo-dev.test.ts +48 -46
- package/src/app.ts +2 -2
- package/src/clack.ts +1 -1
- package/src/cli.ts +4 -3
- package/src/trails/add-surface.ts +150 -0
- package/src/trails/add-trail.ts +46 -10
- package/src/trails/add-verify.ts +11 -6
- package/src/trails/create-scaffold.ts +16 -3
- package/src/trails/create.ts +76 -71
- package/src/trails/dev-clean.ts +25 -21
- package/src/trails/dev-reset.ts +3 -2
- package/src/trails/dev-stats.ts +22 -19
- package/src/trails/dev-support.ts +88 -86
- package/src/trails/draft-promote.ts +70 -35
- package/src/trails/guide.ts +1 -4
- package/src/trails/load-app.ts +511 -32
- package/src/trails/survey.ts +60 -35
- package/src/trails/topo-export.ts +5 -9
- package/src/trails/topo-history.ts +8 -10
- package/src/trails/topo-pin.ts +9 -13
- package/src/trails/topo-read-support.ts +103 -106
- package/src/trails/topo-reports.ts +54 -47
- package/src/trails/topo-show.ts +8 -12
- package/src/trails/topo-store-support.ts +36 -28
- package/src/trails/topo-support.ts +90 -134
- package/src/trails/topo-unpin.ts +11 -6
- package/src/trails/topo-verify.ts +1 -5
- package/src/trails/topo.ts +6 -10
- package/src/trails/warden.ts +12 -3
- package/src/versions.ts +43 -0
- package/tsconfig.tests.json +10 -0
- package/src/trails/add-trailhead.ts +0 -121
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `add.trailhead` trail -- Add a trailhead to an existing project.
|
|
3
|
-
*
|
|
4
|
-
* Generates the CLI or MCP entry point and updates package.json dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { existsSync, mkdirSync } from 'node:fs';
|
|
8
|
-
import { basename, dirname, join, resolve } from 'node:path';
|
|
9
|
-
|
|
10
|
-
import { Result, trail } from '@ontrails/core';
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
|
|
13
|
-
import { findTopoPath } from './project.js';
|
|
14
|
-
|
|
15
|
-
const generateCliEntry = (appImportPath: string): string =>
|
|
16
|
-
`import { trailhead } from '@ontrails/cli/commander';
|
|
17
|
-
|
|
18
|
-
import { app } from '${appImportPath}';
|
|
19
|
-
|
|
20
|
-
trailhead(app);
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
const generateMcpEntry = (appImportPath: string): string =>
|
|
24
|
-
`import { trailhead } from '@ontrails/mcp';
|
|
25
|
-
|
|
26
|
-
import { app } from '${appImportPath}';
|
|
27
|
-
|
|
28
|
-
await trailhead(app);
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
/** Resolve the entry file for a trailhead. */
|
|
32
|
-
const getEntryFile = (trailhead: 'cli' | 'mcp'): string =>
|
|
33
|
-
trailhead === 'cli' ? 'src/cli.ts' : 'src/mcp.ts';
|
|
34
|
-
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Trail definition
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
/** Patch deps and optionally bin in a parsed package.json. */
|
|
40
|
-
const patchPkgDeps = (
|
|
41
|
-
pkg: Record<string, unknown>,
|
|
42
|
-
trailhead: 'cli' | 'mcp',
|
|
43
|
-
cwd: string
|
|
44
|
-
): string => {
|
|
45
|
-
const depName = trailhead === 'cli' ? '@ontrails/cli' : '@ontrails/mcp';
|
|
46
|
-
const deps = (pkg['dependencies'] ?? {}) as Record<string, string>;
|
|
47
|
-
deps[depName] = 'workspace:*';
|
|
48
|
-
if (trailhead === 'cli') {
|
|
49
|
-
deps['commander'] = '^14.0.0';
|
|
50
|
-
pkg['bin'] = {
|
|
51
|
-
[(pkg['name'] as string | undefined) ?? basename(cwd)]: './src/cli.ts',
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
pkg['dependencies'] = Object.fromEntries(
|
|
55
|
-
Object.entries(deps).toSorted(([a], [b]) => a.localeCompare(b))
|
|
56
|
-
);
|
|
57
|
-
return depName;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/** Update package.json with trailhead dependency and CLI bin if needed. */
|
|
61
|
-
const updatePkgJsonForTrailhead = async (
|
|
62
|
-
cwd: string,
|
|
63
|
-
trailhead: 'cli' | 'mcp'
|
|
64
|
-
): Promise<string> => {
|
|
65
|
-
const pkgPath = join(cwd, 'package.json');
|
|
66
|
-
if (!existsSync(pkgPath)) {
|
|
67
|
-
return trailhead === 'cli' ? '@ontrails/cli' : '@ontrails/mcp';
|
|
68
|
-
}
|
|
69
|
-
const pkg = (await Bun.file(pkgPath).json()) as Record<string, unknown>;
|
|
70
|
-
const depName = patchPkgDeps(pkg, trailhead, cwd);
|
|
71
|
-
await Bun.write(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
72
|
-
return depName;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/** Create the entry file for a trailhead and return the relative path. */
|
|
76
|
-
const writeTrailheadEntry = async (
|
|
77
|
-
cwd: string,
|
|
78
|
-
trailhead: 'cli' | 'mcp'
|
|
79
|
-
): Promise<string> => {
|
|
80
|
-
const entryFile = getEntryFile(trailhead);
|
|
81
|
-
const fullEntryPath = join(cwd, entryFile);
|
|
82
|
-
const appImport = (await findTopoPath(cwd)) ?? './app.js';
|
|
83
|
-
const content =
|
|
84
|
-
trailhead === 'cli'
|
|
85
|
-
? generateCliEntry(appImport)
|
|
86
|
-
: generateMcpEntry(appImport);
|
|
87
|
-
|
|
88
|
-
mkdirSync(dirname(fullEntryPath), { recursive: true });
|
|
89
|
-
await Bun.write(fullEntryPath, content);
|
|
90
|
-
return entryFile;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const addTrailhead = trail('add.trailhead', {
|
|
94
|
-
blaze: async (input) => {
|
|
95
|
-
const cwd = resolve(input.dir ?? '.');
|
|
96
|
-
const { trailhead } = input;
|
|
97
|
-
const entryFile = getEntryFile(trailhead);
|
|
98
|
-
|
|
99
|
-
if (existsSync(join(cwd, entryFile))) {
|
|
100
|
-
return Result.err(
|
|
101
|
-
new Error(
|
|
102
|
-
`${trailhead.toUpperCase()} trailhead already exists. Nothing to do.`
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return Result.ok({
|
|
108
|
-
created: await writeTrailheadEntry(cwd, trailhead),
|
|
109
|
-
dependency: await updatePkgJsonForTrailhead(cwd, trailhead),
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
description: 'Add a trailhead to an existing project',
|
|
113
|
-
input: z.object({
|
|
114
|
-
dir: z.string().optional().describe('Project directory'),
|
|
115
|
-
trailhead: z.enum(['cli', 'mcp']).describe('Trailhead to add'),
|
|
116
|
-
}),
|
|
117
|
-
output: z.object({
|
|
118
|
-
created: z.string(),
|
|
119
|
-
dependency: z.string(),
|
|
120
|
-
}),
|
|
121
|
-
});
|