@mono-labs/project 0.0.248

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.
@@ -0,0 +1,145 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ /* ------------------------------------------------------------------
5
+ * Types
6
+ * ------------------------------------------------------------------ */
7
+
8
+ export interface MonoWorkspaceConfig {
9
+ packageMaps: Record<string, string>;
10
+ }
11
+
12
+ export interface MonoProjectConfig {
13
+ envMap: string[];
14
+ workspace: MonoWorkspaceConfig;
15
+ prodFlag: string;
16
+ }
17
+
18
+ export type MonoFiles = Record<string, unknown>;
19
+
20
+ export interface MonoConfig {
21
+ config: MonoProjectConfig;
22
+ files: MonoFiles;
23
+ }
24
+
25
+ /* ------------------------------------------------------------------
26
+ * Helpers
27
+ * ------------------------------------------------------------------ */
28
+
29
+ /**
30
+ * Walk up from cwd until we find a directory containing package.json.
31
+ * This is treated as the project root.
32
+ */
33
+ export function findProjectRoot(startDir: string = process.cwd()): string {
34
+ let current = startDir;
35
+
36
+ while (true) {
37
+ const pkg = path.join(current, 'package.json');
38
+ if (fs.existsSync(pkg)) return current;
39
+
40
+ const parent = path.dirname(current);
41
+ if (parent === current) break;
42
+
43
+ current = parent;
44
+ }
45
+
46
+ // Fallback: use cwd
47
+ return startDir;
48
+ }
49
+
50
+ export function getRootDirectory(): string {
51
+ return findProjectRoot();
52
+ }
53
+
54
+ export function getRootJson(): Record<string, unknown> {
55
+ const root = getRootDirectory();
56
+ const jsonPath = path.join(root, 'package.json');
57
+
58
+ if (!fs.existsSync(jsonPath)) {
59
+ throw new Error(`package.json not found in ${root}`);
60
+ }
61
+
62
+ return JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
63
+ }
64
+
65
+ /* ------------------------------------------------------------------
66
+ * Mono (.mono) handling
67
+ * ------------------------------------------------------------------ */
68
+
69
+ const DISALLOWED_FILES = new Set(['tools']);
70
+
71
+ function readJsonFile(filePath: string): unknown {
72
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
73
+ }
74
+
75
+ /**
76
+ * Resolve the .mono directory.
77
+ * Priority:
78
+ * 1. project root/.mono
79
+ * 2. cwd/.mono
80
+ */
81
+ export function resolveMonoDirectory(): string | null {
82
+ const root = getRootDirectory();
83
+ const rootMono = path.join(root, '.mono');
84
+ if (fs.existsSync(rootMono)) return rootMono;
85
+
86
+ const cwdMono = path.join(process.cwd(), '.mono');
87
+ if (fs.existsSync(cwdMono)) return cwdMono;
88
+
89
+ return null;
90
+ }
91
+
92
+ export function getMonoFiles(): string[] {
93
+ const dir = resolveMonoDirectory();
94
+ if (!dir) return [];
95
+
96
+ return fs
97
+ .readdirSync(dir)
98
+ .filter((f) => f.endsWith('.json'))
99
+ .map((f) => path.join(dir, f));
100
+ }
101
+
102
+ /**
103
+ * Load and validate mono configuration.
104
+ */
105
+ export function getMonoConfig(): MonoConfig {
106
+ const monoDir = resolveMonoDirectory();
107
+
108
+ if (!monoDir) {
109
+ return {
110
+ files: {},
111
+ config: {
112
+ envMap: [],
113
+ workspace: { packageMaps: {} },
114
+ prodFlag: 'live',
115
+ },
116
+ };
117
+ }
118
+
119
+ const files: MonoFiles = {};
120
+ let config: MonoProjectConfig = {
121
+ envMap: [],
122
+ workspace: { packageMaps: {} },
123
+ prodFlag: 'live',
124
+ };
125
+
126
+ for (const filePath of getMonoFiles()) {
127
+ const fileName = path.basename(filePath, '.json');
128
+
129
+ if (DISALLOWED_FILES.has(fileName)) {
130
+ throw new Error(`Disallowed file name in .mono directory: ${fileName}`);
131
+ }
132
+
133
+ const data = readJsonFile(filePath);
134
+
135
+ if (fileName === 'config') {
136
+ if (typeof data === 'object' && data !== null) {
137
+ config = data as MonoProjectConfig;
138
+ }
139
+ } else {
140
+ files[fileName] = data;
141
+ }
142
+ }
143
+
144
+ return { files, config };
145
+ }
@@ -0,0 +1,540 @@
1
+ // scripts/generate-readme.mjs
2
+ // Node >= 18 recommended
3
+ import { promises as fs } from 'node:fs'
4
+ import { Dirent } from 'node:fs'
5
+ import path from 'node:path'
6
+ import { generateDocsIndex } from './generate-docs'
7
+
8
+ const REPO_ROOT = path.resolve(process.cwd())
9
+ const MONO_DIR = path.join(REPO_ROOT, '.mono')
10
+ const ROOT_PKG_JSON = path.join(REPO_ROOT, 'package.json')
11
+ const OUTPUT_PATH = path.join(REPO_ROOT, 'docs')
12
+ const OUTPUT_README = path.join(OUTPUT_PATH, 'command-line.md')
13
+
14
+ async function ensureParentDir(filePath: string): Promise<void> {
15
+ const dir = path.dirname(filePath)
16
+ await fs.mkdir(dir, { recursive: true })
17
+ }
18
+
19
+ // ---------- utils ----------
20
+ async function exists(p: string): Promise<boolean> {
21
+ try {
22
+ await fs.access(p)
23
+ // Log existence check
24
+
25
+ return true
26
+ } catch {
27
+ return false
28
+ }
29
+ }
30
+ function isObject(v: unknown): v is Record<string, unknown> {
31
+ return v !== null && typeof v === 'object' && !Array.isArray(v)
32
+ }
33
+ function toPosix(p: string): string {
34
+ return p.split(path.sep).join('/')
35
+ }
36
+ async function readJson<T = any>(filePath: string): Promise<T> {
37
+ const raw = await fs.readFile(filePath, 'utf8')
38
+ try {
39
+ const parsed = JSON.parse(raw)
40
+
41
+ return parsed
42
+ } catch (err) {
43
+ throw err
44
+ }
45
+ }
46
+ async function listDir(dir: string): Promise<Dirent[]> {
47
+ const entries = await fs.readdir(dir, { withFileTypes: true })
48
+
49
+ return entries
50
+ }
51
+ function normalizeWorkspacePatterns(workspacesField: unknown): string[] {
52
+ if (Array.isArray(workspacesField)) return workspacesField as string[]
53
+ if (isObject(workspacesField) && Array.isArray((workspacesField as any).packages))
54
+ return (workspacesField as any).packages
55
+ return []
56
+ }
57
+ function mdEscapeInline(s: string): string {
58
+ return String(s ?? '').replaceAll('`', '\`')
59
+ }
60
+ function indentLines(s: string, spaces = 2): string {
61
+ const pad = ' '.repeat(spaces)
62
+ return String(s ?? '')
63
+ .split('\n')
64
+ .map((l) => pad + l)
65
+ .join('\n')
66
+ }
67
+
68
+ // ---------- workspace glob matching (supports *, **, and plain segments) ----------
69
+ function matchSegment(patternSeg: string, name: string): boolean {
70
+ if (patternSeg === '*') return true
71
+ if (!patternSeg.includes('*')) return patternSeg === name
72
+ const escaped = patternSeg.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
73
+ const regex = new RegExp('^' + escaped.replaceAll('*', '.*') + '$')
74
+ return regex.test(name)
75
+ }
76
+
77
+ async function expandWorkspacePattern(root: string, pattern: string): Promise<string[]> {
78
+ const segs = toPosix(pattern).split('/').filter(Boolean)
79
+
80
+ async function expandFrom(dir: string, segIndex: number): Promise<string[]> {
81
+ if (segIndex >= segs.length) return [dir]
82
+ const seg = segs[segIndex]
83
+
84
+ if (seg === '**') {
85
+ const results: string[] = []
86
+ results.push(...(await expandFrom(dir, segIndex + 1)))
87
+ const entries = await fs.readdir(dir, { withFileTypes: true }).catch(() => [])
88
+
89
+ for (const e of entries) {
90
+ if (!e.isDirectory()) continue
91
+
92
+ results.push(...(await expandFrom(path.join(dir, e.name), segIndex)))
93
+ }
94
+ return results
95
+ }
96
+
97
+ const entries = await fs.readdir(dir, { withFileTypes: true }).catch(() => [])
98
+
99
+ const results: string[] = []
100
+ for (const e of entries) {
101
+ if (!e.isDirectory()) continue
102
+ if (!matchSegment(seg, e.name)) continue
103
+
104
+ results.push(...(await expandFrom(path.join(dir, e.name), segIndex + 1)))
105
+ }
106
+ return results
107
+ }
108
+
109
+ const dirs = await expandFrom(root, 0)
110
+
111
+ const pkgDirs: string[] = []
112
+ for (const d of dirs) {
113
+ const pkgPath = path.join(d, 'package.json')
114
+ if (await exists(pkgPath)) {
115
+ pkgDirs.push(d)
116
+ }
117
+ }
118
+
119
+ return [...new Set(pkgDirs)]
120
+ }
121
+
122
+ async function findWorkspacePackageDirs(
123
+ repoRoot: string,
124
+ workspacePatterns: string[]
125
+ ): Promise<string[]> {
126
+ const dirs: string[] = []
127
+ for (const pat of workspacePatterns) {
128
+ const expanded = await expandWorkspacePattern(repoRoot, pat)
129
+ dirs.push(...expanded)
130
+ dirs.push(...expanded)
131
+ }
132
+ const uniqueDirs = [...new Set(dirs)]
133
+ return uniqueDirs
134
+ }
135
+
136
+ // ---------- .mono parsing ----------
137
+ async function readMonoConfig(): Promise<MonoConfig | null> {
138
+ const configPath = path.join(MONO_DIR, 'config.json')
139
+ console.log(`[readMonoConfig] Looking for mono config at:`, configPath)
140
+ if (!(await exists(configPath))) {
141
+ console.log(`[readMonoConfig] No mono config found.`)
142
+ return null
143
+ }
144
+ try {
145
+ const config = await readJson<any>(configPath)
146
+ return { path: configPath, config }
147
+ } catch (err) {
148
+ return null
149
+ }
150
+ }
151
+
152
+ function commandNameFromFile(filePath: string): string {
153
+ return path.basename(filePath).replace(/\.json$/i, '')
154
+ }
155
+
156
+ async function readMonoCommands(): Promise<MonoCommand[]> {
157
+ if (!(await exists(MONO_DIR))) {
158
+ return []
159
+ }
160
+ const entries = await listDir(MONO_DIR)
161
+
162
+ const jsonFiles = entries
163
+ .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.json'))
164
+ .map((e) => path.join(MONO_DIR, e.name))
165
+ .filter((p) => path.basename(p).toLowerCase() !== 'config.json')
166
+
167
+ const commands: MonoCommand[] = []
168
+ for (const file of jsonFiles) {
169
+ try {
170
+ const j = await readJson<any>(file)
171
+ commands.push({
172
+ name: commandNameFromFile(file),
173
+ file,
174
+ json: j,
175
+ })
176
+ } catch (err) {
177
+ console.error(`[readMonoCommands] Failed to load command file:`, file, err)
178
+ // skip invalid json
179
+ }
180
+ }
181
+
182
+ commands.sort((a, b) => a.name.localeCompare(b.name))
183
+
184
+ return commands
185
+ }
186
+
187
+ // ---------- mono docs formatting ----------
188
+ type OptionSchema = {
189
+ key: string
190
+ kind: 'boolean' | 'value'
191
+ type: string
192
+ description: string
193
+ shortcut: string
194
+ default: any
195
+ allowed: string[] | null
196
+ allowAll: boolean
197
+ }
198
+
199
+ type MonoConfig = {
200
+ path: string
201
+ config: any
202
+ }
203
+
204
+ function parseOptionsSchema(optionsObj: unknown): OptionSchema[] {
205
+ if (!isObject(optionsObj)) return []
206
+
207
+ const entries: OptionSchema[] = Object.entries(optionsObj).map(([key, raw]) => {
208
+ const o = isObject(raw) ? raw : {}
209
+ const hasType = typeof o.type === 'string' && o.type.trim().length > 0
210
+ const isBoolToggle = !hasType
211
+ return {
212
+ key,
213
+ kind: isBoolToggle ? 'boolean' : 'value',
214
+ type: hasType ? String(o.type) : 'boolean',
215
+ description: typeof o.description === 'string' ? o.description : '',
216
+ shortcut: typeof o.shortcut === 'string' ? o.shortcut : '',
217
+ default: o.default,
218
+ allowed: Array.isArray(o.options) ? o.options : null,
219
+ allowAll: o.allowAll === true,
220
+ }
221
+ })
222
+
223
+ entries.sort((a, b) => a.key.localeCompare(b.key))
224
+ return entries
225
+ }
226
+
227
+ function buildUsageExample(commandName: string, cmdJson: any, options: OptionSchema[]): string {
228
+ const arg = cmdJson?.argument
229
+ const hasArg = isObject(arg)
230
+ const argToken = hasArg ? `<${commandName}-arg>` : ''
231
+
232
+ const valueOpts = options.filter((o) => o.kind === 'value')
233
+ const boolOpts = options.filter((o) => o.kind === 'boolean')
234
+
235
+ const exampleParts = [`yarn mono ${commandName}`]
236
+ if (argToken) exampleParts.push(argToken)
237
+
238
+ for (const o of valueOpts.slice(0, 2)) {
239
+ const flag = `--${o.key}`
240
+ const val = o.default !== undefined ? o.default : (o.allowed?.[0] ?? '<value>')
241
+ exampleParts.push(`${flag} ${val}`)
242
+ }
243
+ if (boolOpts.length) {
244
+ exampleParts.push(`--${boolOpts[0].key}`)
245
+ }
246
+
247
+ return exampleParts.join(' ')
248
+ }
249
+
250
+ function formatMonoConfigSection(monoConfig: MonoConfig | null): string {
251
+ const lines: string[] = []
252
+ lines.push('## Mono configuration')
253
+ lines.push('')
254
+
255
+ if (!monoConfig) {
256
+ lines.push('_No `.mono/config.json` found._')
257
+ return lines.join('\n')
258
+ }
259
+
260
+ const c = monoConfig.config
261
+ lines.push(`Source: \`${toPosix(path.relative(REPO_ROOT, monoConfig.path))}\``)
262
+ lines.push('')
263
+
264
+ if (Array.isArray(c.envMap) && c.envMap.length) {
265
+ lines.push('### envMap')
266
+ lines.push('')
267
+ lines.push('- ' + c.envMap.map((x: string) => `\`${mdEscapeInline(x)}\``).join(', '))
268
+ lines.push('')
269
+ }
270
+
271
+ const pkgMaps = c?.workspace?.packageMaps
272
+ if (pkgMaps && isObject(pkgMaps) && Object.keys(pkgMaps).length) {
273
+ lines.push('### Workspace aliases (packageMaps)')
274
+ lines.push('')
275
+ const entries = Object.entries(pkgMaps).sort(([a], [b]) => a.localeCompare(b))
276
+ for (const [alias, target] of entries) {
277
+ lines.push(`- \`${mdEscapeInline(alias)}\` → \`${mdEscapeInline(String(target))}\``)
278
+ }
279
+ lines.push('')
280
+ }
281
+
282
+ const pre = c?.workspace?.preactions
283
+ if (Array.isArray(pre) && pre.length) {
284
+ lines.push('### Global preactions')
285
+ lines.push('')
286
+ lines.push('```bash')
287
+ for (const p of pre) lines.push(String(p))
288
+ lines.push('```')
289
+ lines.push('')
290
+ }
291
+
292
+ if (typeof c.prodFlag === 'string' && c.prodFlag.trim()) {
293
+ lines.push('### prodFlag')
294
+ lines.push('')
295
+ lines.push(`Production flag keyword: \`${mdEscapeInline(c.prodFlag.trim())}\``)
296
+ lines.push('')
297
+ }
298
+
299
+ return lines.join('\n')
300
+ }
301
+
302
+ type MonoCommand = {
303
+ name: string
304
+ file: string
305
+ json: any
306
+ }
307
+
308
+ function formatMonoCommandsSection(commands: MonoCommand[]): string {
309
+ const lines: string[] = []
310
+ lines.push('## Mono commands')
311
+ lines.push('')
312
+ lines.push(
313
+ 'Generated from `.mono/*.json` (excluding `config.json`). Each filename becomes a command:'
314
+ )
315
+ lines.push('')
316
+ lines.push('```bash')
317
+ lines.push('yarn mono <command> [argument] [--options]')
318
+ lines.push('```')
319
+ lines.push('')
320
+
321
+ if (!commands.length) {
322
+ lines.push('_No mono command JSON files found._')
323
+ return lines.join('\n')
324
+ }
325
+
326
+ // Index
327
+ lines.push('### Command index')
328
+ lines.push('')
329
+ for (const c of commands) {
330
+ const desc = typeof c.json?.description === 'string' ? c.json.description.trim() : ''
331
+ const suffix = desc ? ` — ${desc}` : ''
332
+ lines.push(
333
+ `- [\`${mdEscapeInline(c.name)}\`](#mono-command-${mdEscapeInline(c.name).toLowerCase()})${suffix}`
334
+ )
335
+ }
336
+ lines.push('')
337
+
338
+ for (const c of commands) {
339
+ const j = c.json || {}
340
+ const rel = toPosix(path.relative(REPO_ROOT, c.file))
341
+ const anchor = `mono-command-${c.name.toLowerCase()}`
342
+
343
+ const desc = typeof j.description === 'string' ? j.description.trim() : ''
344
+ const arg = j.argument
345
+ const options = parseOptionsSchema(j.options)
346
+
347
+ lines.push('---')
348
+ lines.push(`### Mono command: ${c.name}`)
349
+ lines.push(`<a id="${anchor}"></a>`)
350
+ lines.push('')
351
+ lines.push(`Source: \`${rel}\``)
352
+ lines.push('')
353
+
354
+ if (desc) {
355
+ lines.push(`**Description:** ${mdEscapeInline(desc)}`)
356
+ lines.push('')
357
+ }
358
+
359
+ // Usage
360
+ lines.push('**Usage**')
361
+ lines.push('')
362
+ lines.push('```bash')
363
+ lines.push(`yarn mono ${c.name}${isObject(arg) ? ` <${c.name}-arg>` : ''} [--options]`)
364
+ lines.push('```')
365
+ lines.push('')
366
+ lines.push('Example:')
367
+ lines.push('')
368
+ lines.push('```bash')
369
+ lines.push(buildUsageExample(c.name, j, options))
370
+ lines.push('```')
371
+ lines.push('')
372
+
373
+ // Argument
374
+ if (isObject(arg)) {
375
+ lines.push('**Argument**')
376
+ lines.push('')
377
+ const bits: string[] = []
378
+ if (typeof arg.type === 'string') bits.push(`type: \`${mdEscapeInline(arg.type)}\``)
379
+ if (arg.default !== undefined)
380
+ bits.push(`default: \`${mdEscapeInline(String(arg.default))}\``)
381
+ if (typeof arg.description === 'string') bits.push(mdEscapeInline(arg.description))
382
+ lines.push(`- ${bits.join(' • ') || '_(no details)_'} `)
383
+ lines.push('')
384
+ }
385
+
386
+ // Options
387
+ if (options.length) {
388
+ lines.push('**Options**')
389
+ lines.push('')
390
+ lines.push('| Option | Type | Shortcut | Default | Allowed | Notes |')
391
+ lines.push('|---|---:|:---:|---:|---|---|')
392
+ for (const o of options) {
393
+ const optCol =
394
+ o.kind === 'boolean'
395
+ ? `\`--${mdEscapeInline(o.key)}\``
396
+ : `\`--${mdEscapeInline(o.key)} <${mdEscapeInline(o.key)}>\``
397
+ const typeCol = `\`${mdEscapeInline(o.type)}\``
398
+ const shortCol = o.shortcut ? `\`-${mdEscapeInline(o.shortcut)}\`` : ''
399
+ const defCol = o.default !== undefined ? `\`${mdEscapeInline(o.default)}\`` : ''
400
+ const allowedCol = o.allowed
401
+ ? o.allowed.map((x) => `\`${mdEscapeInline(x)}\``).join(', ')
402
+ : ''
403
+ const notes = [
404
+ o.allowAll ? 'allowAll' : '',
405
+ o.description ? mdEscapeInline(o.description) : '',
406
+ ]
407
+ .filter(Boolean)
408
+ .join(' • ')
409
+ lines.push(
410
+ `| ${optCol} | ${typeCol} | ${shortCol} | ${defCol} | ${allowedCol} | ${notes} |`
411
+ )
412
+ }
413
+ lines.push('')
414
+ }
415
+
416
+ // Environments
417
+ if (j.environments && isObject(j.environments) && Object.keys(j.environments).length) {
418
+ lines.push('**Environment Variables**')
419
+ lines.push('')
420
+ const envs = Object.entries(j.environments).sort(([a], [b]) => a.localeCompare(b))
421
+ for (const [envName, envObj] of envs) {
422
+ lines.push(`- \`${mdEscapeInline(envName)}\``)
423
+ if (isObject(envObj) && Object.keys(envObj).length) {
424
+ const kv = Object.entries(envObj).sort(([a], [b]) => a.localeCompare(b))
425
+ lines.push(
426
+ indentLines(
427
+ kv
428
+ .map(([k, v]) => `- \`${mdEscapeInline(k)}\` = \`${mdEscapeInline(String(v))}\``)
429
+ .join('\n'),
430
+ 2
431
+ )
432
+ )
433
+ }
434
+ }
435
+ lines.push('')
436
+ }
437
+
438
+ // preactions/actions
439
+ if (Array.isArray(j.preactions) && j.preactions.length) {
440
+ lines.push('**Preactions**')
441
+ lines.push('')
442
+ lines.push('```bash')
443
+ for (const p of j.preactions) lines.push(String(p))
444
+ lines.push('```')
445
+ lines.push('')
446
+ }
447
+
448
+ if (Array.isArray(j.actions) && j.actions.length) {
449
+ lines.push('**Actions**')
450
+ lines.push('')
451
+ lines.push('```bash')
452
+ for (const a of j.actions) lines.push(String(a))
453
+ lines.push('```')
454
+ lines.push('')
455
+ }
456
+ }
457
+
458
+ return lines.join('\n')
459
+ }
460
+
461
+ // ---------- workspace scripts summary ----------
462
+
463
+ // Define PackageInfo type
464
+ type PackageInfo = {
465
+ name: string
466
+ dir: string
467
+ scripts: Record<string, string>
468
+ }
469
+
470
+ function collectScripts(packages: PackageInfo[]): Map<string, string[]> {
471
+ const scriptToPackages = new Map<string, string[]>()
472
+ for (const p of packages) {
473
+ for (const scriptName of Object.keys(p.scripts || {})) {
474
+ if (!scriptToPackages.has(scriptName)) scriptToPackages.set(scriptName, [])
475
+ scriptToPackages.get(scriptName)!.push(p.name)
476
+ }
477
+ }
478
+ return scriptToPackages
479
+ }
480
+
481
+ // ---------- main ----------
482
+ async function main(): Promise<void> {
483
+ if (!(await exists(ROOT_PKG_JSON))) throw new Error(`Missing: ${ROOT_PKG_JSON}`)
484
+ await ensureParentDir(OUTPUT_PATH)
485
+
486
+ const rootPkg = await readJson<any>(ROOT_PKG_JSON)
487
+ const workspacePatterns = normalizeWorkspacePatterns(rootPkg.workspaces)
488
+
489
+ const monoConfig = await readMonoConfig()
490
+ const monoCommands = await readMonoCommands()
491
+
492
+ const pkgDirs = await findWorkspacePackageDirs(REPO_ROOT, workspacePatterns)
493
+ const packages: PackageInfo[] = []
494
+ for (const dir of pkgDirs) {
495
+ try {
496
+ const pkgPath = path.join(dir, 'package.json')
497
+ const pj = await readJson<any>(pkgPath)
498
+ packages.push({
499
+ name: pj.name || toPosix(path.relative(REPO_ROOT, dir)) || path.basename(dir),
500
+ dir,
501
+ scripts: pj.scripts || {},
502
+ })
503
+ } catch (err) {
504
+ console.error(`[main] Failed to load package.json for:`, dir, err)
505
+ // skip
506
+ }
507
+ }
508
+
509
+ const parts: string[] = []
510
+ parts.push(`# ⚙️ Command Line Reference
511
+
512
+ > Generated by \`scripts/generate-readme.mjs\`.
513
+ > Update \`.mono/config.json\`, \`.mono/*.json\`, and workspace package scripts to change this output.
514
+
515
+ `)
516
+ parts.push(formatMonoConfigSection(monoConfig))
517
+ parts.push('')
518
+ parts.push(formatMonoCommandsSection(monoCommands))
519
+ parts.push('')
520
+
521
+ const val = await generateDocsIndex({
522
+ docsDir: path.join(REPO_ROOT, 'docs'),
523
+ excludeFile: 'command-line.md',
524
+ })
525
+
526
+ val.split('\n').forEach((line) => parts.push(line))
527
+
528
+ await ensureParentDir(OUTPUT_README)
529
+ await fs.writeFile(OUTPUT_README, parts.join('\n'), 'utf8')
530
+
531
+ console.log(`[main] Generated: ${OUTPUT_README}`)
532
+ console.log(`[main] mono config: ${monoConfig ? 'yes' : 'no'}`)
533
+ console.log(`[main] mono commands: ${monoCommands.length}`)
534
+ console.log(`[main] workspace packages: ${packages.length}`)
535
+ }
536
+
537
+ main().catch((err) => {
538
+ console.error(err?.stack || String(err))
539
+ process.exitCode = 1
540
+ })
@@ -0,0 +1,2 @@
1
+ import './build-mono-readme';
2
+ import './generate-readme';