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