@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,4 @@
1
+ export { findProjectRoot, getRootDirectory, getRootJson, resolveMonoDirectory, getMonoFiles, getMonoConfig, } from './loadFromRoot';
2
+ export type { MonoWorkspaceConfig, MonoProjectConfig, MonoFiles, MonoConfig, } from './loadFromRoot';
3
+ export { loadAppConfig, loadProjectConfig, loadMergedEnv } from './project/index';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // @mono-labs/project barrel export
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.loadMergedEnv = exports.loadProjectConfig = exports.loadAppConfig = exports.getMonoConfig = exports.getMonoFiles = exports.resolveMonoDirectory = exports.getRootJson = exports.getRootDirectory = exports.findProjectRoot = void 0;
5
+ var loadFromRoot_1 = require("./loadFromRoot");
6
+ Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return loadFromRoot_1.findProjectRoot; } });
7
+ Object.defineProperty(exports, "getRootDirectory", { enumerable: true, get: function () { return loadFromRoot_1.getRootDirectory; } });
8
+ Object.defineProperty(exports, "getRootJson", { enumerable: true, get: function () { return loadFromRoot_1.getRootJson; } });
9
+ Object.defineProperty(exports, "resolveMonoDirectory", { enumerable: true, get: function () { return loadFromRoot_1.resolveMonoDirectory; } });
10
+ Object.defineProperty(exports, "getMonoFiles", { enumerable: true, get: function () { return loadFromRoot_1.getMonoFiles; } });
11
+ Object.defineProperty(exports, "getMonoConfig", { enumerable: true, get: function () { return loadFromRoot_1.getMonoConfig; } });
12
+ var index_1 = require("./project/index");
13
+ Object.defineProperty(exports, "loadAppConfig", { enumerable: true, get: function () { return index_1.loadAppConfig; } });
14
+ Object.defineProperty(exports, "loadProjectConfig", { enumerable: true, get: function () { return index_1.loadProjectConfig; } });
15
+ Object.defineProperty(exports, "loadMergedEnv", { enumerable: true, get: function () { return index_1.loadMergedEnv; } });
@@ -0,0 +1,33 @@
1
+ export interface MonoWorkspaceConfig {
2
+ packageMaps: Record<string, string>;
3
+ }
4
+ export interface MonoProjectConfig {
5
+ envMap: string[];
6
+ workspace: MonoWorkspaceConfig;
7
+ prodFlag: string;
8
+ }
9
+ export type MonoFiles = Record<string, unknown>;
10
+ export interface MonoConfig {
11
+ config: MonoProjectConfig;
12
+ files: MonoFiles;
13
+ }
14
+ /**
15
+ * Walk up from cwd until we find a directory containing package.json.
16
+ * This is treated as the project root.
17
+ */
18
+ export declare function findProjectRoot(startDir?: string): string;
19
+ export declare function getRootDirectory(): string;
20
+ export declare function getRootJson(): Record<string, unknown>;
21
+ /**
22
+ * Resolve the .mono directory.
23
+ * Priority:
24
+ * 1. project root/.mono
25
+ * 2. cwd/.mono
26
+ */
27
+ export declare function resolveMonoDirectory(): string | null;
28
+ export declare function getMonoFiles(): string[];
29
+ /**
30
+ * Load and validate mono configuration.
31
+ */
32
+ export declare function getMonoConfig(): MonoConfig;
33
+ //# sourceMappingURL=loadFromRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadFromRoot.d.ts","sourceRoot":"","sources":["../src/loadFromRoot.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,SAAS,CAAC;CACjB;AAMD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,GAAE,MAAsB,GAAG,MAAM,CAexE;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASrD;AAYD;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,IAAI,CASpD;AAED,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAQvC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAwC1C"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findProjectRoot = findProjectRoot;
7
+ exports.getRootDirectory = getRootDirectory;
8
+ exports.getRootJson = getRootJson;
9
+ exports.resolveMonoDirectory = resolveMonoDirectory;
10
+ exports.getMonoFiles = getMonoFiles;
11
+ exports.getMonoConfig = getMonoConfig;
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ /* ------------------------------------------------------------------
15
+ * Helpers
16
+ * ------------------------------------------------------------------ */
17
+ /**
18
+ * Walk up from cwd until we find a directory containing package.json.
19
+ * This is treated as the project root.
20
+ */
21
+ function findProjectRoot(startDir = process.cwd()) {
22
+ let current = startDir;
23
+ while (true) {
24
+ const pkg = path_1.default.join(current, 'package.json');
25
+ if (fs_1.default.existsSync(pkg))
26
+ return current;
27
+ const parent = path_1.default.dirname(current);
28
+ if (parent === current)
29
+ break;
30
+ current = parent;
31
+ }
32
+ // Fallback: use cwd
33
+ return startDir;
34
+ }
35
+ function getRootDirectory() {
36
+ return findProjectRoot();
37
+ }
38
+ function getRootJson() {
39
+ const root = getRootDirectory();
40
+ const jsonPath = path_1.default.join(root, 'package.json');
41
+ if (!fs_1.default.existsSync(jsonPath)) {
42
+ throw new Error(`package.json not found in ${root}`);
43
+ }
44
+ return JSON.parse(fs_1.default.readFileSync(jsonPath, 'utf-8'));
45
+ }
46
+ /* ------------------------------------------------------------------
47
+ * Mono (.mono) handling
48
+ * ------------------------------------------------------------------ */
49
+ const DISALLOWED_FILES = new Set(['tools']);
50
+ function readJsonFile(filePath) {
51
+ return JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
52
+ }
53
+ /**
54
+ * Resolve the .mono directory.
55
+ * Priority:
56
+ * 1. project root/.mono
57
+ * 2. cwd/.mono
58
+ */
59
+ function resolveMonoDirectory() {
60
+ const root = getRootDirectory();
61
+ const rootMono = path_1.default.join(root, '.mono');
62
+ if (fs_1.default.existsSync(rootMono))
63
+ return rootMono;
64
+ const cwdMono = path_1.default.join(process.cwd(), '.mono');
65
+ if (fs_1.default.existsSync(cwdMono))
66
+ return cwdMono;
67
+ return null;
68
+ }
69
+ function getMonoFiles() {
70
+ const dir = resolveMonoDirectory();
71
+ if (!dir)
72
+ return [];
73
+ return fs_1.default
74
+ .readdirSync(dir)
75
+ .filter((f) => f.endsWith('.json'))
76
+ .map((f) => path_1.default.join(dir, f));
77
+ }
78
+ /**
79
+ * Load and validate mono configuration.
80
+ */
81
+ function getMonoConfig() {
82
+ const monoDir = resolveMonoDirectory();
83
+ if (!monoDir) {
84
+ return {
85
+ files: {},
86
+ config: {
87
+ envMap: [],
88
+ workspace: { packageMaps: {} },
89
+ prodFlag: 'live',
90
+ },
91
+ };
92
+ }
93
+ const files = {};
94
+ let config = {
95
+ envMap: [],
96
+ workspace: { packageMaps: {} },
97
+ prodFlag: 'live',
98
+ };
99
+ for (const filePath of getMonoFiles()) {
100
+ const fileName = path_1.default.basename(filePath, '.json');
101
+ if (DISALLOWED_FILES.has(fileName)) {
102
+ throw new Error(`Disallowed file name in .mono directory: ${fileName}`);
103
+ }
104
+ const data = readJsonFile(filePath);
105
+ if (fileName === 'config') {
106
+ if (typeof data === 'object' && data !== null) {
107
+ config = data;
108
+ }
109
+ }
110
+ else {
111
+ files[fileName] = data;
112
+ }
113
+ }
114
+ return { files, config };
115
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=build-mono-readme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-mono-readme.d.ts","sourceRoot":"","sources":["../../src/project/build-mono-readme.ts"],"names":[],"mappings":""}
@@ -0,0 +1,451 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // scripts/generate-readme.mjs
7
+ // Node >= 18 recommended
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const generate_docs_1 = require("./generate-docs");
11
+ const REPO_ROOT = node_path_1.default.resolve(process.cwd());
12
+ const MONO_DIR = node_path_1.default.join(REPO_ROOT, '.mono');
13
+ const ROOT_PKG_JSON = node_path_1.default.join(REPO_ROOT, 'package.json');
14
+ const OUTPUT_PATH = node_path_1.default.join(REPO_ROOT, 'docs');
15
+ const OUTPUT_README = node_path_1.default.join(OUTPUT_PATH, 'command-line.md');
16
+ async function ensureParentDir(filePath) {
17
+ const dir = node_path_1.default.dirname(filePath);
18
+ await node_fs_1.promises.mkdir(dir, { recursive: true });
19
+ }
20
+ // ---------- utils ----------
21
+ async function exists(p) {
22
+ try {
23
+ await node_fs_1.promises.access(p);
24
+ // Log existence check
25
+ return true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ function isObject(v) {
32
+ return v !== null && typeof v === 'object' && !Array.isArray(v);
33
+ }
34
+ function toPosix(p) {
35
+ return p.split(node_path_1.default.sep).join('/');
36
+ }
37
+ async function readJson(filePath) {
38
+ const raw = await node_fs_1.promises.readFile(filePath, 'utf8');
39
+ try {
40
+ const parsed = JSON.parse(raw);
41
+ return parsed;
42
+ }
43
+ catch (err) {
44
+ throw err;
45
+ }
46
+ }
47
+ async function listDir(dir) {
48
+ const entries = await node_fs_1.promises.readdir(dir, { withFileTypes: true });
49
+ return entries;
50
+ }
51
+ function normalizeWorkspacePatterns(workspacesField) {
52
+ if (Array.isArray(workspacesField))
53
+ return workspacesField;
54
+ if (isObject(workspacesField) && Array.isArray(workspacesField.packages))
55
+ return workspacesField.packages;
56
+ return [];
57
+ }
58
+ function mdEscapeInline(s) {
59
+ return String(s ?? '').replaceAll('`', '\`');
60
+ }
61
+ function indentLines(s, spaces = 2) {
62
+ const pad = ' '.repeat(spaces);
63
+ return String(s ?? '')
64
+ .split('\n')
65
+ .map((l) => pad + l)
66
+ .join('\n');
67
+ }
68
+ // ---------- workspace glob matching (supports *, **, and plain segments) ----------
69
+ function matchSegment(patternSeg, name) {
70
+ if (patternSeg === '*')
71
+ return true;
72
+ if (!patternSeg.includes('*'))
73
+ return patternSeg === name;
74
+ const escaped = patternSeg.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
75
+ const regex = new RegExp('^' + escaped.replaceAll('*', '.*') + '$');
76
+ return regex.test(name);
77
+ }
78
+ async function expandWorkspacePattern(root, pattern) {
79
+ const segs = toPosix(pattern).split('/').filter(Boolean);
80
+ async function expandFrom(dir, segIndex) {
81
+ if (segIndex >= segs.length)
82
+ return [dir];
83
+ const seg = segs[segIndex];
84
+ if (seg === '**') {
85
+ const results = [];
86
+ results.push(...(await expandFrom(dir, segIndex + 1)));
87
+ const entries = await node_fs_1.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
88
+ for (const e of entries) {
89
+ if (!e.isDirectory())
90
+ continue;
91
+ results.push(...(await expandFrom(node_path_1.default.join(dir, e.name), segIndex)));
92
+ }
93
+ return results;
94
+ }
95
+ const entries = await node_fs_1.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
96
+ const results = [];
97
+ for (const e of entries) {
98
+ if (!e.isDirectory())
99
+ continue;
100
+ if (!matchSegment(seg, e.name))
101
+ continue;
102
+ results.push(...(await expandFrom(node_path_1.default.join(dir, e.name), segIndex + 1)));
103
+ }
104
+ return results;
105
+ }
106
+ const dirs = await expandFrom(root, 0);
107
+ const pkgDirs = [];
108
+ for (const d of dirs) {
109
+ const pkgPath = node_path_1.default.join(d, 'package.json');
110
+ if (await exists(pkgPath)) {
111
+ pkgDirs.push(d);
112
+ }
113
+ }
114
+ return [...new Set(pkgDirs)];
115
+ }
116
+ async function findWorkspacePackageDirs(repoRoot, workspacePatterns) {
117
+ const dirs = [];
118
+ for (const pat of workspacePatterns) {
119
+ const expanded = await expandWorkspacePattern(repoRoot, pat);
120
+ dirs.push(...expanded);
121
+ dirs.push(...expanded);
122
+ }
123
+ const uniqueDirs = [...new Set(dirs)];
124
+ return uniqueDirs;
125
+ }
126
+ // ---------- .mono parsing ----------
127
+ async function readMonoConfig() {
128
+ const configPath = node_path_1.default.join(MONO_DIR, 'config.json');
129
+ console.log(`[readMonoConfig] Looking for mono config at:`, configPath);
130
+ if (!(await exists(configPath))) {
131
+ console.log(`[readMonoConfig] No mono config found.`);
132
+ return null;
133
+ }
134
+ try {
135
+ const config = await readJson(configPath);
136
+ return { path: configPath, config };
137
+ }
138
+ catch (err) {
139
+ return null;
140
+ }
141
+ }
142
+ function commandNameFromFile(filePath) {
143
+ return node_path_1.default.basename(filePath).replace(/\.json$/i, '');
144
+ }
145
+ async function readMonoCommands() {
146
+ if (!(await exists(MONO_DIR))) {
147
+ return [];
148
+ }
149
+ const entries = await listDir(MONO_DIR);
150
+ const jsonFiles = entries
151
+ .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.json'))
152
+ .map((e) => node_path_1.default.join(MONO_DIR, e.name))
153
+ .filter((p) => node_path_1.default.basename(p).toLowerCase() !== 'config.json');
154
+ const commands = [];
155
+ for (const file of jsonFiles) {
156
+ try {
157
+ const j = await readJson(file);
158
+ commands.push({
159
+ name: commandNameFromFile(file),
160
+ file,
161
+ json: j,
162
+ });
163
+ }
164
+ catch (err) {
165
+ console.error(`[readMonoCommands] Failed to load command file:`, file, err);
166
+ // skip invalid json
167
+ }
168
+ }
169
+ commands.sort((a, b) => a.name.localeCompare(b.name));
170
+ return commands;
171
+ }
172
+ function parseOptionsSchema(optionsObj) {
173
+ if (!isObject(optionsObj))
174
+ return [];
175
+ const entries = Object.entries(optionsObj).map(([key, raw]) => {
176
+ const o = isObject(raw) ? raw : {};
177
+ const hasType = typeof o.type === 'string' && o.type.trim().length > 0;
178
+ const isBoolToggle = !hasType;
179
+ return {
180
+ key,
181
+ kind: isBoolToggle ? 'boolean' : 'value',
182
+ type: hasType ? String(o.type) : 'boolean',
183
+ description: typeof o.description === 'string' ? o.description : '',
184
+ shortcut: typeof o.shortcut === 'string' ? o.shortcut : '',
185
+ default: o.default,
186
+ allowed: Array.isArray(o.options) ? o.options : null,
187
+ allowAll: o.allowAll === true,
188
+ };
189
+ });
190
+ entries.sort((a, b) => a.key.localeCompare(b.key));
191
+ return entries;
192
+ }
193
+ function buildUsageExample(commandName, cmdJson, options) {
194
+ const arg = cmdJson?.argument;
195
+ const hasArg = isObject(arg);
196
+ const argToken = hasArg ? `<${commandName}-arg>` : '';
197
+ const valueOpts = options.filter((o) => o.kind === 'value');
198
+ const boolOpts = options.filter((o) => o.kind === 'boolean');
199
+ const exampleParts = [`yarn mono ${commandName}`];
200
+ if (argToken)
201
+ exampleParts.push(argToken);
202
+ for (const o of valueOpts.slice(0, 2)) {
203
+ const flag = `--${o.key}`;
204
+ const val = o.default !== undefined ? o.default : (o.allowed?.[0] ?? '<value>');
205
+ exampleParts.push(`${flag} ${val}`);
206
+ }
207
+ if (boolOpts.length) {
208
+ exampleParts.push(`--${boolOpts[0].key}`);
209
+ }
210
+ return exampleParts.join(' ');
211
+ }
212
+ function formatMonoConfigSection(monoConfig) {
213
+ const lines = [];
214
+ lines.push('## Mono configuration');
215
+ lines.push('');
216
+ if (!monoConfig) {
217
+ lines.push('_No `.mono/config.json` found._');
218
+ return lines.join('\n');
219
+ }
220
+ const c = monoConfig.config;
221
+ lines.push(`Source: \`${toPosix(node_path_1.default.relative(REPO_ROOT, monoConfig.path))}\``);
222
+ lines.push('');
223
+ if (Array.isArray(c.envMap) && c.envMap.length) {
224
+ lines.push('### envMap');
225
+ lines.push('');
226
+ lines.push('- ' + c.envMap.map((x) => `\`${mdEscapeInline(x)}\``).join(', '));
227
+ lines.push('');
228
+ }
229
+ const pkgMaps = c?.workspace?.packageMaps;
230
+ if (pkgMaps && isObject(pkgMaps) && Object.keys(pkgMaps).length) {
231
+ lines.push('### Workspace aliases (packageMaps)');
232
+ lines.push('');
233
+ const entries = Object.entries(pkgMaps).sort(([a], [b]) => a.localeCompare(b));
234
+ for (const [alias, target] of entries) {
235
+ lines.push(`- \`${mdEscapeInline(alias)}\` → \`${mdEscapeInline(String(target))}\``);
236
+ }
237
+ lines.push('');
238
+ }
239
+ const pre = c?.workspace?.preactions;
240
+ if (Array.isArray(pre) && pre.length) {
241
+ lines.push('### Global preactions');
242
+ lines.push('');
243
+ lines.push('```bash');
244
+ for (const p of pre)
245
+ lines.push(String(p));
246
+ lines.push('```');
247
+ lines.push('');
248
+ }
249
+ if (typeof c.prodFlag === 'string' && c.prodFlag.trim()) {
250
+ lines.push('### prodFlag');
251
+ lines.push('');
252
+ lines.push(`Production flag keyword: \`${mdEscapeInline(c.prodFlag.trim())}\``);
253
+ lines.push('');
254
+ }
255
+ return lines.join('\n');
256
+ }
257
+ function formatMonoCommandsSection(commands) {
258
+ const lines = [];
259
+ lines.push('## Mono commands');
260
+ lines.push('');
261
+ lines.push('Generated from `.mono/*.json` (excluding `config.json`). Each filename becomes a command:');
262
+ lines.push('');
263
+ lines.push('```bash');
264
+ lines.push('yarn mono <command> [argument] [--options]');
265
+ lines.push('```');
266
+ lines.push('');
267
+ if (!commands.length) {
268
+ lines.push('_No mono command JSON files found._');
269
+ return lines.join('\n');
270
+ }
271
+ // Index
272
+ lines.push('### Command index');
273
+ lines.push('');
274
+ for (const c of commands) {
275
+ const desc = typeof c.json?.description === 'string' ? c.json.description.trim() : '';
276
+ const suffix = desc ? ` — ${desc}` : '';
277
+ lines.push(`- [\`${mdEscapeInline(c.name)}\`](#mono-command-${mdEscapeInline(c.name).toLowerCase()})${suffix}`);
278
+ }
279
+ lines.push('');
280
+ for (const c of commands) {
281
+ const j = c.json || {};
282
+ const rel = toPosix(node_path_1.default.relative(REPO_ROOT, c.file));
283
+ const anchor = `mono-command-${c.name.toLowerCase()}`;
284
+ const desc = typeof j.description === 'string' ? j.description.trim() : '';
285
+ const arg = j.argument;
286
+ const options = parseOptionsSchema(j.options);
287
+ lines.push('---');
288
+ lines.push(`### Mono command: ${c.name}`);
289
+ lines.push(`<a id="${anchor}"></a>`);
290
+ lines.push('');
291
+ lines.push(`Source: \`${rel}\``);
292
+ lines.push('');
293
+ if (desc) {
294
+ lines.push(`**Description:** ${mdEscapeInline(desc)}`);
295
+ lines.push('');
296
+ }
297
+ // Usage
298
+ lines.push('**Usage**');
299
+ lines.push('');
300
+ lines.push('```bash');
301
+ lines.push(`yarn mono ${c.name}${isObject(arg) ? ` <${c.name}-arg>` : ''} [--options]`);
302
+ lines.push('```');
303
+ lines.push('');
304
+ lines.push('Example:');
305
+ lines.push('');
306
+ lines.push('```bash');
307
+ lines.push(buildUsageExample(c.name, j, options));
308
+ lines.push('```');
309
+ lines.push('');
310
+ // Argument
311
+ if (isObject(arg)) {
312
+ lines.push('**Argument**');
313
+ lines.push('');
314
+ const bits = [];
315
+ if (typeof arg.type === 'string')
316
+ bits.push(`type: \`${mdEscapeInline(arg.type)}\``);
317
+ if (arg.default !== undefined)
318
+ bits.push(`default: \`${mdEscapeInline(String(arg.default))}\``);
319
+ if (typeof arg.description === 'string')
320
+ bits.push(mdEscapeInline(arg.description));
321
+ lines.push(`- ${bits.join(' • ') || '_(no details)_'} `);
322
+ lines.push('');
323
+ }
324
+ // Options
325
+ if (options.length) {
326
+ lines.push('**Options**');
327
+ lines.push('');
328
+ lines.push('| Option | Type | Shortcut | Default | Allowed | Notes |');
329
+ lines.push('|---|---:|:---:|---:|---|---|');
330
+ for (const o of options) {
331
+ const optCol = o.kind === 'boolean'
332
+ ? `\`--${mdEscapeInline(o.key)}\``
333
+ : `\`--${mdEscapeInline(o.key)} <${mdEscapeInline(o.key)}>\``;
334
+ const typeCol = `\`${mdEscapeInline(o.type)}\``;
335
+ const shortCol = o.shortcut ? `\`-${mdEscapeInline(o.shortcut)}\`` : '';
336
+ const defCol = o.default !== undefined ? `\`${mdEscapeInline(o.default)}\`` : '';
337
+ const allowedCol = o.allowed
338
+ ? o.allowed.map((x) => `\`${mdEscapeInline(x)}\``).join(', ')
339
+ : '';
340
+ const notes = [
341
+ o.allowAll ? 'allowAll' : '',
342
+ o.description ? mdEscapeInline(o.description) : '',
343
+ ]
344
+ .filter(Boolean)
345
+ .join(' • ');
346
+ lines.push(`| ${optCol} | ${typeCol} | ${shortCol} | ${defCol} | ${allowedCol} | ${notes} |`);
347
+ }
348
+ lines.push('');
349
+ }
350
+ // Environments
351
+ if (j.environments && isObject(j.environments) && Object.keys(j.environments).length) {
352
+ lines.push('**Environment Variables**');
353
+ lines.push('');
354
+ const envs = Object.entries(j.environments).sort(([a], [b]) => a.localeCompare(b));
355
+ for (const [envName, envObj] of envs) {
356
+ lines.push(`- \`${mdEscapeInline(envName)}\``);
357
+ if (isObject(envObj) && Object.keys(envObj).length) {
358
+ const kv = Object.entries(envObj).sort(([a], [b]) => a.localeCompare(b));
359
+ lines.push(indentLines(kv
360
+ .map(([k, v]) => `- \`${mdEscapeInline(k)}\` = \`${mdEscapeInline(String(v))}\``)
361
+ .join('\n'), 2));
362
+ }
363
+ }
364
+ lines.push('');
365
+ }
366
+ // preactions/actions
367
+ if (Array.isArray(j.preactions) && j.preactions.length) {
368
+ lines.push('**Preactions**');
369
+ lines.push('');
370
+ lines.push('```bash');
371
+ for (const p of j.preactions)
372
+ lines.push(String(p));
373
+ lines.push('```');
374
+ lines.push('');
375
+ }
376
+ if (Array.isArray(j.actions) && j.actions.length) {
377
+ lines.push('**Actions**');
378
+ lines.push('');
379
+ lines.push('```bash');
380
+ for (const a of j.actions)
381
+ lines.push(String(a));
382
+ lines.push('```');
383
+ lines.push('');
384
+ }
385
+ }
386
+ return lines.join('\n');
387
+ }
388
+ function collectScripts(packages) {
389
+ const scriptToPackages = new Map();
390
+ for (const p of packages) {
391
+ for (const scriptName of Object.keys(p.scripts || {})) {
392
+ if (!scriptToPackages.has(scriptName))
393
+ scriptToPackages.set(scriptName, []);
394
+ scriptToPackages.get(scriptName).push(p.name);
395
+ }
396
+ }
397
+ return scriptToPackages;
398
+ }
399
+ // ---------- main ----------
400
+ async function main() {
401
+ if (!(await exists(ROOT_PKG_JSON)))
402
+ throw new Error(`Missing: ${ROOT_PKG_JSON}`);
403
+ await ensureParentDir(OUTPUT_PATH);
404
+ const rootPkg = await readJson(ROOT_PKG_JSON);
405
+ const workspacePatterns = normalizeWorkspacePatterns(rootPkg.workspaces);
406
+ const monoConfig = await readMonoConfig();
407
+ const monoCommands = await readMonoCommands();
408
+ const pkgDirs = await findWorkspacePackageDirs(REPO_ROOT, workspacePatterns);
409
+ const packages = [];
410
+ for (const dir of pkgDirs) {
411
+ try {
412
+ const pkgPath = node_path_1.default.join(dir, 'package.json');
413
+ const pj = await readJson(pkgPath);
414
+ packages.push({
415
+ name: pj.name || toPosix(node_path_1.default.relative(REPO_ROOT, dir)) || node_path_1.default.basename(dir),
416
+ dir,
417
+ scripts: pj.scripts || {},
418
+ });
419
+ }
420
+ catch (err) {
421
+ console.error(`[main] Failed to load package.json for:`, dir, err);
422
+ // skip
423
+ }
424
+ }
425
+ const parts = [];
426
+ parts.push(`# ⚙️ Command Line Reference
427
+
428
+ > Generated by \`scripts/generate-readme.mjs\`.
429
+ > Update \`.mono/config.json\`, \`.mono/*.json\`, and workspace package scripts to change this output.
430
+
431
+ `);
432
+ parts.push(formatMonoConfigSection(monoConfig));
433
+ parts.push('');
434
+ parts.push(formatMonoCommandsSection(monoCommands));
435
+ parts.push('');
436
+ const val = await (0, generate_docs_1.generateDocsIndex)({
437
+ docsDir: node_path_1.default.join(REPO_ROOT, 'docs'),
438
+ excludeFile: 'command-line.md',
439
+ });
440
+ val.split('\n').forEach((line) => parts.push(line));
441
+ await ensureParentDir(OUTPUT_README);
442
+ await node_fs_1.promises.writeFile(OUTPUT_README, parts.join('\n'), 'utf8');
443
+ console.log(`[main] Generated: ${OUTPUT_README}`);
444
+ console.log(`[main] mono config: ${monoConfig ? 'yes' : 'no'}`);
445
+ console.log(`[main] mono commands: ${monoCommands.length}`);
446
+ console.log(`[main] workspace packages: ${packages.length}`);
447
+ }
448
+ main().catch((err) => {
449
+ console.error(err?.stack || String(err));
450
+ process.exitCode = 1;
451
+ });
@@ -0,0 +1,3 @@
1
+ import './build-mono-readme';
2
+ import './generate-readme';
3
+ //# sourceMappingURL=build-readme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-readme.d.ts","sourceRoot":"","sources":["../../src/project/build-readme.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./build-mono-readme");
4
+ require("./generate-readme");
@@ -0,0 +1,12 @@
1
+ export interface GenerateDocsIndexOptions {
2
+ docsDir: string;
3
+ excludeFile?: string;
4
+ }
5
+ /**
6
+ * Generate a docs index from markdown files.
7
+ *
8
+ * @param options - Options for docs index generation
9
+ * @returns Markdown-formatted index
10
+ */
11
+ export declare function generateDocsIndex({ docsDir, excludeFile, }: GenerateDocsIndexOptions): Promise<string>;
12
+ //# sourceMappingURL=generate-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-docs.d.ts","sourceRoot":"","sources":["../../src/project/generate-docs.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,wBAAwB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,EACvC,OAAO,EACP,WAAW,GACX,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgD5C"}