@mono-labs/cli 0.0.205 → 0.0.207

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/dist/cdk/index.js CHANGED
@@ -1,4 +1,8 @@
1
- export function replaceTokens(str, env) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceTokens = replaceTokens;
4
+ exports.setUpConfig = setUpConfig;
5
+ function replaceTokens(str, env) {
2
6
  if (typeof str !== 'string')
3
7
  return str;
4
8
  return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
@@ -26,7 +30,7 @@ function filterEnvByPrefix(env, prefix) {
26
30
  }
27
31
  return filtered;
28
32
  }
29
- export function setUpConfig(config) {
33
+ function setUpConfig(config) {
30
34
  const { extra = {}, ...other } = config.expo || {};
31
35
  const router = extra['router'] ?
32
36
  { origin: false, ...extra['router'] }
package/dist/expo.js CHANGED
@@ -1,4 +1,8 @@
1
- export function replaceTokens(str, env) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceTokens = replaceTokens;
4
+ exports.setUpConfig = setUpConfig;
5
+ function replaceTokens(str, env) {
2
6
  if (typeof str !== 'string')
3
7
  return str;
4
8
  return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
@@ -26,7 +30,7 @@ function filterEnvByPrefix(env, prefix) {
26
30
  }
27
31
  return filtered;
28
32
  }
29
- export function setUpConfig(config) {
33
+ function setUpConfig(config) {
30
34
  const { extra = {}, ...other } = config.expo || {};
31
35
  const router = extra['router'] ?
32
36
  { origin: false, ...extra['router'] }
package/dist/merge-env.js CHANGED
@@ -1,14 +1,20 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import dotenv from 'dotenv';
4
- export function loadMergedEnv() {
5
- const ENV_PATH = path.resolve(process.cwd(), '.env');
6
- const ENV_LOCAL_PATH = path.resolve(process.cwd(), '.env.local');
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.loadMergedEnv = loadMergedEnv;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const dotenv_1 = __importDefault(require("dotenv"));
10
+ function loadMergedEnv() {
11
+ const ENV_PATH = path_1.default.resolve(process.cwd(), '.env');
12
+ const ENV_LOCAL_PATH = path_1.default.resolve(process.cwd(), '.env.local');
7
13
  // Load base .env
8
- const base = fs.existsSync(ENV_PATH) ? dotenv.parse(fs.readFileSync(ENV_PATH)) : {};
14
+ const base = fs_1.default.existsSync(ENV_PATH) ? dotenv_1.default.parse(fs_1.default.readFileSync(ENV_PATH)) : {};
9
15
  // Load overrides .env.local
10
- const local = fs.existsSync(ENV_LOCAL_PATH) ?
11
- dotenv.parse(fs.readFileSync(ENV_LOCAL_PATH))
16
+ const local = fs_1.default.existsSync(ENV_LOCAL_PATH) ?
17
+ dotenv_1.default.parse(fs_1.default.readFileSync(ENV_LOCAL_PATH))
12
18
  : {};
13
19
  // Merge: local overrides base
14
20
  const merged = {
@@ -1,28 +1,30 @@
1
- // scripts/generate-readme.ts
1
+ "use strict";
2
+ // scripts/generate-readme.mjs
2
3
  // Node >= 18 recommended
3
- import { promises as fs } from 'node:fs';
4
- import path from 'node:path';
5
- import { generateDocsIndex } from './generate-docs.js';
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const generate_docs_js_1 = require("./generate-docs.js");
6
11
  /* -------------------------------------------------------------------------- */
7
- /* Path helpers */
12
+ /* Constants */
8
13
  /* -------------------------------------------------------------------------- */
9
- // Always use the working directory as the root for all file actions
10
- const REPO_ROOT = path.resolve(process.cwd());
11
- const MONO_DIR = path.join(REPO_ROOT, '.mono');
12
- const ROOT_PKG_JSON = path.join(REPO_ROOT, 'package.json');
13
- const OUTPUT_PATH = path.join(REPO_ROOT, 'docs');
14
- const OUTPUT_README = path.join(OUTPUT_PATH, 'command-line.md');
14
+ const REPO_ROOT = node_path_1.default.resolve(process.cwd());
15
+ const MONO_DIR = node_path_1.default.join(REPO_ROOT, '.mono');
16
+ const ROOT_PKG_JSON = node_path_1.default.join(REPO_ROOT, 'package.json');
17
+ const OUTPUT_PATH = node_path_1.default.join(REPO_ROOT, 'docs');
18
+ const OUTPUT_README = node_path_1.default.join(OUTPUT_PATH, 'command-line.md');
15
19
  /* -------------------------------------------------------------------------- */
16
- /* Utils */
20
+ /* Utils */
17
21
  /* -------------------------------------------------------------------------- */
18
22
  async function ensureParentDir(filePath) {
19
- // Always resolve parent dir relative to working directory
20
- const dir = path.resolve(process.cwd(), path.dirname(filePath));
21
- await fs.mkdir(dir, { recursive: true });
23
+ await node_fs_1.promises.mkdir(node_path_1.default.dirname(filePath), { recursive: true });
22
24
  }
23
25
  async function exists(p) {
24
26
  try {
25
- await fs.access(p);
27
+ await node_fs_1.promises.access(p);
26
28
  return true;
27
29
  }
28
30
  catch {
@@ -30,21 +32,16 @@ async function exists(p) {
30
32
  }
31
33
  }
32
34
  function isObject(v) {
33
- return v !== null && typeof v === 'object' && !Array.isArray(v);
35
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
34
36
  }
35
37
  function toPosix(p) {
36
- return p.split(path.sep).join('/');
38
+ return p.split(node_path_1.default.sep).join('/');
37
39
  }
38
40
  async function readJson(filePath) {
39
- // Always resolve filePath relative to working directory
40
- const absPath = path.resolve(process.cwd(), filePath);
41
- const raw = await fs.readFile(absPath, 'utf8');
42
- return JSON.parse(raw);
41
+ return JSON.parse(await node_fs_1.promises.readFile(filePath, 'utf8'));
43
42
  }
44
43
  async function listDir(dir) {
45
- // Always resolve dir relative to working directory
46
- const absDir = path.resolve(process.cwd(), dir);
47
- return fs.readdir(absDir, { withFileTypes: true });
44
+ return node_fs_1.promises.readdir(dir, { withFileTypes: true });
48
45
  }
49
46
  function normalizeWorkspacePatterns(workspacesField) {
50
47
  if (Array.isArray(workspacesField))
@@ -55,18 +52,18 @@ function normalizeWorkspacePatterns(workspacesField) {
55
52
  }
56
53
  return [];
57
54
  }
58
- function mdEscapeInline(value) {
59
- return String(value ?? '').replaceAll('`', '\\`');
55
+ function mdEscapeInline(s) {
56
+ return s.replaceAll('`', '\\`');
60
57
  }
61
58
  function indentLines(s, spaces = 2) {
62
59
  const pad = ' '.repeat(spaces);
63
60
  return s
64
61
  .split('\n')
65
- .map((line) => pad + line)
62
+ .map((l) => pad + l)
66
63
  .join('\n');
67
64
  }
68
65
  /* -------------------------------------------------------------------------- */
69
- /* Workspace glob pattern expansion */
66
+ /* Workspace globbing */
70
67
  /* -------------------------------------------------------------------------- */
71
68
  function matchSegment(patternSeg, name) {
72
69
  if (patternSeg === '*')
@@ -74,113 +71,78 @@ function matchSegment(patternSeg, name) {
74
71
  if (!patternSeg.includes('*'))
75
72
  return patternSeg === name;
76
73
  const escaped = patternSeg.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
77
- const regex = new RegExp(`^${escaped.replaceAll('*', '.*')}$`);
78
- return regex.test(name);
74
+ return new RegExp(`^${escaped.replaceAll('*', '.*')}$`).test(name);
79
75
  }
80
76
  async function expandWorkspacePattern(root, pattern) {
81
- const segments = toPosix(pattern).split('/').filter(Boolean);
82
- async function expandFrom(dir, index) {
83
- // Always resolve dir relative to working directory
84
- const absDir = path.resolve(process.cwd(), dir);
85
- if (index >= segments.length)
86
- return [absDir];
87
- const seg = segments[index];
88
- if (seg === '**') {
89
- const results = [];
90
- results.push(...(await expandFrom(absDir, index + 1)));
91
- const entries = await fs
92
- .readdir(absDir, { withFileTypes: true })
93
- .catch(() => []);
94
- for (const entry of entries) {
95
- if (!entry.isDirectory())
96
- continue;
97
- results.push(...(await expandFrom(path.join(absDir, entry.name), index)));
98
- }
99
- return results;
100
- }
101
- const entries = await fs
102
- .readdir(absDir, { withFileTypes: true })
77
+ const segs = toPosix(pattern).split('/').filter(Boolean);
78
+ async function expandFrom(dir, idx) {
79
+ if (idx >= segs.length)
80
+ return [dir];
81
+ const entries = await node_fs_1.promises
82
+ .readdir(dir, { withFileTypes: true })
103
83
  .catch(() => []);
104
- const results = [];
105
- for (const entry of entries) {
106
- if (!entry.isDirectory())
107
- continue;
108
- if (!matchSegment(seg, entry.name))
109
- continue;
110
- results.push(...(await expandFrom(path.join(absDir, entry.name), index + 1)));
84
+ const seg = segs[idx];
85
+ if (seg === '**') {
86
+ const nested = await Promise.all(entries
87
+ .filter((e) => e.isDirectory())
88
+ .map((e) => expandFrom(node_path_1.default.join(dir, e.name), idx)));
89
+ return [...(await expandFrom(dir, idx + 1)), ...nested.flat()];
111
90
  }
112
- return results;
91
+ const nested = await Promise.all(entries
92
+ .filter((e) => e.isDirectory() && matchSegment(seg, e.name))
93
+ .map((e) => expandFrom(node_path_1.default.join(dir, e.name), idx + 1)));
94
+ return nested.flat();
113
95
  }
114
96
  const dirs = await expandFrom(root, 0);
115
- const pkgDirs = [];
116
- for (const d of dirs) {
117
- if (await exists(path.join(d, 'package.json'))) {
118
- pkgDirs.push(d);
119
- }
120
- }
121
- return Array.from(new Set(pkgDirs));
97
+ const pkgDirs = (await Promise.all(dirs.map(async (d) => (await exists(node_path_1.default.join(d, 'package.json'))) ? d : null))).filter(Boolean);
98
+ return [...new Set(pkgDirs)];
122
99
  }
123
- async function findWorkspacePackageDirs(repoRoot, patterns) {
124
- const dirs = [];
125
- for (const pat of patterns) {
126
- dirs.push(...(await expandWorkspacePattern(repoRoot, pat)));
127
- }
128
- return Array.from(new Set(dirs));
100
+ async function findWorkspacePackageDirs(repoRoot, workspacePatterns) {
101
+ const resolved = await Promise.all(workspacePatterns.map((p) => expandWorkspacePattern(repoRoot, p)));
102
+ return [...new Set(resolved.flat())];
129
103
  }
130
104
  /* -------------------------------------------------------------------------- */
131
- /* .mono configuration */
105
+ /* Mono config + commands */
132
106
  /* -------------------------------------------------------------------------- */
133
107
  async function readMonoConfig() {
134
- // Always resolve configPath relative to working directory
135
- const configPath = path.resolve(process.cwd(), path.join(MONO_DIR, 'config.json'));
108
+ const configPath = node_path_1.default.join(MONO_DIR, 'config.json');
136
109
  if (!(await exists(configPath)))
137
110
  return null;
138
- try {
139
- const config = await readJson(configPath);
140
- return { path: configPath, config };
141
- }
142
- catch {
143
- return null;
144
- }
111
+ return {
112
+ path: configPath,
113
+ config: await readJson(configPath),
114
+ };
145
115
  }
146
116
  function commandNameFromFile(filePath) {
147
- return path.basename(filePath).replace(/\.json$/i, '');
117
+ return node_path_1.default.basename(filePath).replace(/\.json$/i, '');
148
118
  }
149
119
  async function readMonoCommands() {
150
- // Always resolve MONO_DIR relative to working directory
151
- const monoDirAbs = path.resolve(process.cwd(), MONO_DIR);
152
- if (!(await exists(monoDirAbs)))
120
+ if (!(await exists(MONO_DIR)))
153
121
  return [];
154
- const entries = await listDir(monoDirAbs);
155
- const jsonFiles = entries
156
- .filter((e) => e.isFile() && e.name.endsWith('.json'))
157
- .map((e) => path.join(monoDirAbs, e.name))
158
- .filter((p) => path.basename(p) !== 'config.json');
159
- const commands = [];
160
- for (const file of jsonFiles) {
161
- try {
162
- const json = await readJson(file);
163
- commands.push({
164
- name: commandNameFromFile(file),
165
- file,
166
- json,
167
- });
168
- }
169
- catch {
170
- /* ignore invalid JSON */
171
- }
172
- }
122
+ const entries = await listDir(MONO_DIR);
123
+ const commands = await Promise.all(entries
124
+ .filter((e) => e.isFile() && e.name.endsWith('.json') && e.name !== 'config.json')
125
+ .map(async (e) => {
126
+ const file = node_path_1.default.join(MONO_DIR, e.name);
127
+ const json = await readJson(file);
128
+ return {
129
+ name: commandNameFromFile(file),
130
+ file,
131
+ json,
132
+ };
133
+ }));
173
134
  return commands.sort((a, b) => a.name.localeCompare(b.name));
174
135
  }
175
136
  /* -------------------------------------------------------------------------- */
176
- /* Options schema parsing */
137
+ /* Options parsing */
177
138
  /* -------------------------------------------------------------------------- */
178
139
  function parseOptionsSchema(optionsObj) {
179
140
  if (!isObject(optionsObj))
180
141
  return [];
181
- const entries = Object.entries(optionsObj).map(([key, raw]) => {
142
+ return Object.entries(optionsObj)
143
+ .map(([key, raw]) => {
182
144
  const o = isObject(raw) ? raw : {};
183
- const hasType = typeof o.type === 'string' && o.type.length > 0;
145
+ const hasType = typeof o.type === 'string';
184
146
  return {
185
147
  key,
186
148
  kind: hasType ? 'value' : 'boolean',
@@ -188,41 +150,20 @@ function parseOptionsSchema(optionsObj) {
188
150
  description: typeof o.description === 'string' ? o.description : '',
189
151
  shortcut: typeof o.shortcut === 'string' ? o.shortcut : '',
190
152
  default: o.default,
191
- allowed: Array.isArray(o.options) ? o.options : null,
153
+ allowed: Array.isArray(o.options) ?
154
+ o.options.filter((x) => typeof x === 'string')
155
+ : null,
192
156
  allowAll: o.allowAll === true,
193
157
  };
194
- });
195
- return entries.sort((a, b) => a.key.localeCompare(b.key));
158
+ })
159
+ .sort((a, b) => a.key.localeCompare(b.key));
196
160
  }
197
161
  /* -------------------------------------------------------------------------- */
198
- /* Formatting */
199
- /* -------------------------------------------------------------------------- */
200
- function buildUsageExample(commandName, cmdJson, options) {
201
- const arg = cmdJson.argument;
202
- const hasArg = isObject(arg);
203
- const parts = [`yarn mono ${commandName}`];
204
- if (hasArg)
205
- parts.push(`<${commandName}-arg>`);
206
- const valueOpts = options.filter((o) => o.kind === 'value');
207
- const boolOpts = options.filter((o) => o.kind === 'boolean');
208
- for (const o of valueOpts.slice(0, 2)) {
209
- const value = o.default !== undefined ?
210
- String(o.default)
211
- : (o.allowed?.[0] ?? '<value>');
212
- parts.push(`--${o.key} ${value}`);
213
- }
214
- if (boolOpts[0]) {
215
- parts.push(`--${boolOpts[0].key}`);
216
- }
217
- return parts.join(' ');
218
- }
219
- /* -------------------------------------------------------------------------- */
220
- /* Main */
162
+ /* Main */
221
163
  /* -------------------------------------------------------------------------- */
222
164
  async function main() {
223
- // Always resolve all paths relative to working directory
224
165
  if (!(await exists(ROOT_PKG_JSON))) {
225
- throw new Error(`Missing ${ROOT_PKG_JSON}`);
166
+ throw new Error(`Missing: ${ROOT_PKG_JSON}`);
226
167
  }
227
168
  await ensureParentDir(OUTPUT_PATH);
228
169
  const rootPkg = await readJson(ROOT_PKG_JSON);
@@ -230,43 +171,35 @@ async function main() {
230
171
  const monoConfig = await readMonoConfig();
231
172
  const monoCommands = await readMonoCommands();
232
173
  const pkgDirs = await findWorkspacePackageDirs(REPO_ROOT, workspacePatterns);
233
- const packages = [];
234
- for (const dir of pkgDirs) {
235
- try {
236
- const pkg = await readJson(path.join(dir, 'package.json'));
237
- packages.push({
238
- name: pkg.name ??
239
- toPosix(path.relative(REPO_ROOT, dir)) ??
240
- path.basename(dir),
241
- dir,
242
- scripts: pkg.scripts ?? {},
243
- });
244
- }
245
- catch {
246
- /* ignore */
247
- }
248
- }
174
+ const packages = await Promise.all(pkgDirs.map(async (dir) => {
175
+ const pj = await readJson(node_path_1.default.join(dir, 'package.json'));
176
+ return {
177
+ name: pj.name ||
178
+ toPosix(node_path_1.default.relative(REPO_ROOT, dir)) ||
179
+ node_path_1.default.basename(dir),
180
+ dir,
181
+ scripts: pj.scripts ?? {},
182
+ };
183
+ }));
249
184
  const parts = [];
250
185
  parts.push(`# Mono Command-Line Reference
251
186
 
252
- > Generated by \`scripts/generate-readme.ts\`.
187
+ > Generated by \`scripts/generate-readme.mjs\`.
188
+ > Update \`.mono/config.json\`, \`.mono/*.json\`, and workspace package scripts to change this output.
253
189
 
254
190
  `);
255
- // Reuse your existing formatters here
256
- // (unchanged logic, now fully typed)
257
- const docsIndex = await generateDocsIndex({
258
- docsDir: path.join(REPO_ROOT, 'docs'),
191
+ const docsIndex = await (0, generate_docs_js_1.generateDocsIndex)({
192
+ docsDir: node_path_1.default.join(REPO_ROOT, 'docs'),
259
193
  excludeFile: 'command-line.md',
260
194
  });
261
195
  parts.push(docsIndex);
262
- await ensureParentDir(OUTPUT_README);
263
- await fs.writeFile(OUTPUT_README, parts.join('\n'), 'utf8');
196
+ await node_fs_1.promises.writeFile(OUTPUT_README, parts.join('\n'), 'utf8');
264
197
  console.log(`Generated: ${OUTPUT_README}`);
265
198
  console.log(`- mono config: ${monoConfig ? 'yes' : 'no'}`);
266
199
  console.log(`- mono commands: ${monoCommands.length}`);
267
200
  console.log(`- workspace packages: ${packages.length}`);
268
201
  }
269
202
  main().catch((err) => {
270
- console.error(err instanceof Error ? err.stack : err);
271
- process.exit(1);
203
+ console.error(err);
204
+ process.exitCode = 1;
272
205
  });
@@ -1,2 +1,4 @@
1
- import './build-mono-readme';
2
- import './generate-readme';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./build-mono-readme");
4
+ require("./generate-readme");
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  // scripts/generate-repo-help.mjs
2
3
  // Generates a developer-friendly workspace command reference.
3
4
  //
@@ -10,18 +11,23 @@
10
11
  // - Optimize for onboarding and day-to-day use
11
12
  // - Keep raw yarn workspace commands for reference
12
13
  // - Emphasize `yarn mono` as the primary interface
13
- import { promises as fs } from 'node:fs';
14
- import path from 'node:path';
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.generateDocsIndex = generateDocsIndex;
19
+ const node_fs_1 = require("node:fs");
20
+ const node_path_1 = __importDefault(require("node:path"));
15
21
  /**
16
22
  * Generate a docs index from markdown files.
17
23
  *
18
24
  * @param options - Options for docs index generation
19
25
  * @returns Markdown-formatted index
20
26
  */
21
- export async function generateDocsIndex({ docsDir, excludeFile, }) {
27
+ async function generateDocsIndex({ docsDir, excludeFile, }) {
22
28
  // Always resolve docsDir relative to the working directory
23
- const dirPath = path.resolve(process.cwd(), docsDir);
24
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
29
+ const dirPath = node_path_1.default.resolve(process.cwd(), docsDir);
30
+ const entries = await node_fs_1.promises.readdir(dirPath, { withFileTypes: true });
25
31
  const links = [];
26
32
  for (const entry of entries) {
27
33
  if (!entry.isFile())
@@ -34,8 +40,8 @@ export async function generateDocsIndex({ docsDir, excludeFile, }) {
34
40
  // Optionally ignore a caller-specified file
35
41
  if (excludeFile && entry.name === excludeFile)
36
42
  continue;
37
- const filePath = path.join(dirPath, entry.name);
38
- const contents = await fs.readFile(filePath, 'utf8');
43
+ const filePath = node_path_1.default.join(dirPath, entry.name);
44
+ const contents = await node_fs_1.promises.readFile(filePath, 'utf8');
39
45
  // Find first markdown H1
40
46
  const match = contents.match(/^#\s+(.+)$/m);
41
47
  if (!match)