@frigear-nu/cli 0.2.4 → 0.2.6

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,15 @@
1
+ import { defineCommand } from 'citty';
2
+
3
+ const index = defineCommand({
4
+ meta: {
5
+ name: "platform",
6
+ description: "Add apps of a platform to the workspace and set up their native targets"
7
+ },
8
+ subCommands: {
9
+ add: () => import('./add.mjs').then((module) => module.default),
10
+ init: () => import('./init2.mjs').then((module) => module.default),
11
+ list: () => import('./list.mjs').then((module) => module.default)
12
+ }
13
+ });
14
+
15
+ export { index as default };
@@ -0,0 +1,13 @@
1
+ import { defineCommand } from 'citty';
2
+
3
+ const index = defineCommand({
4
+ meta: {
5
+ name: "prepare",
6
+ description: "Prepare a workspace for its first run"
7
+ },
8
+ subCommands: {
9
+ env: () => import('./env.mjs').then((module) => module.default)
10
+ }
11
+ });
12
+
13
+ export { index as default };
@@ -5,9 +5,8 @@ import { readFile, writeFile, readdir, stat, mkdir, rename } from 'node:fs/promi
5
5
  import { join, basename, relative, dirname, resolve } from 'node:path';
6
6
  import { parseModule } from 'magicast';
7
7
  import { getDefaultExportOptions } from 'magicast/helpers';
8
- import { i as isBetween, d as duplicateVersions, s as sharedDuplicates, m as manifestFiles, f as findPins, c as currentVersions, b as compareVersions, r as rewritePins, e as movePatchedDependencies } from '../shared/cli.DUmSgMcB.mjs';
9
- import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.Cfkcp0w9.mjs';
10
- import { i as installDeps } from '../shared/cli.CkMCvUCp.mjs';
8
+ import { j as isBetween, k as duplicateVersions, s as sharedDuplicates, d as defineCommandArgs, f as findWorkspaceRoot, m as manifestFiles, n as findPins, o as currentVersions, q as compareVersions, u as rewritePins, v as movePatchedDependencies } from '../shared/cli.B7bXD3w0.mjs';
9
+ import { i as installDeps } from '../shared/cli.C-q4Gf2K.mjs';
11
10
 
12
11
  const DOCS = "https://docs.frigear.dev";
13
12
  const SOURCE = /\.(?:[cm]?[jt]s|tsx|jsx|vue)$/;
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { m as main } from './shared/cli.B_BErT55.mjs';
2
+ import { m as main } from './shared/cli.CIFLvzV1.mjs';
3
3
  import 'citty';
4
4
 
5
5
  await main();
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as citty from 'citty';
2
+ import { ConsolaInstance } from 'consola';
3
+ import { PackageJson } from 'pkg-types';
2
4
 
3
5
  declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
4
6
  declare function main(): Promise<void>;
@@ -186,5 +188,280 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
186
188
  */
187
189
  declare const migrations: Migration[];
188
190
 
189
- export { PLATFORMS, STARTERS, main as default, _default as initCmd, mainCmd, migrations, resolveStarter, upgradeWorkspace };
190
- export type { Migration, Platform, Rule, Starter, UpgradeOptions };
191
+ /** What `platform init <target>` runs in an app: the app's own `script` when it has it, else the `bin` command. */
192
+ interface PlatformTarget {
193
+ description?: string;
194
+ /** Other names for the target, e.g. `watchos` for `apple-watch`. */
195
+ aliases?: string[];
196
+ /** A script of the app's package.json, run with the workspace's package manager. */
197
+ script?: string;
198
+ /** A binary of the app's dependencies and its leading arguments, e.g. `['frigear-mobile', 'native']`. */
199
+ bin?: string[];
200
+ /** Arguments appended to the script or the binary. */
201
+ args?: string[];
202
+ }
203
+ interface NextStepsContext {
204
+ /** The app's folder name, e.g. `mobile`. */
205
+ appName: string;
206
+ /** The app's path relative to the workspace root, e.g. `apps/mobile`. */
207
+ appDir: string;
208
+ /** The app's package name, e.g. `@workspace/mobile`. */
209
+ packageName: string;
210
+ root: string;
211
+ /** Whether an app of the workspace runs `@frigear-nu/oauth-server`, so the new app can sign in there. */
212
+ hasOAuthServer: boolean;
213
+ }
214
+ interface PlatformDefinition {
215
+ /** `mobile`, `display`, ... */
216
+ name: string;
217
+ description?: string;
218
+ /** A template name (`web`, `mobile`, ... or a project's own) or a giget source. */
219
+ template?: string;
220
+ /** Folder name of the app when none is given; defaults to `name`. */
221
+ defaultAppName?: string;
222
+ /**
223
+ * Root package.json scripts added for each app of the platform. In keys and values `<name>` is the app's folder name
224
+ * and `<dir>` its path from the root (`./apps/mobile`). Existing scripts are never overwritten.
225
+ */
226
+ scripts?: Record<string, string>;
227
+ /** Printed after the app was added; `<name>`, `<dir>` and `<package>` are replaced in string steps. */
228
+ nextSteps?: string[] | ((context: NextStepsContext) => string[]);
229
+ /** What `platform init <target>` can do for apps of this platform. */
230
+ targets?: Record<string, PlatformTarget>;
231
+ /** Recognises an app of this platform that has no `frigear.platform` field in its package.json. */
232
+ detect?: (pkg: PackageJson) => boolean;
233
+ }
234
+ declare const definePlatform: (definition: PlatformDefinition) => PlatformDefinition;
235
+ /** App templates, as paths in the frigear-nu repository. */
236
+ declare const APP_TEMPLATES: {
237
+ readonly web: ".starters/workspace/apps/web";
238
+ readonly 'web-standalone': ".starters/mobile-standalone/apps/web";
239
+ readonly mobile: ".starters/mobile/apps/mobile";
240
+ readonly desktop: ".starters/desktop/apps/desktop";
241
+ };
242
+ type AppTemplate = keyof typeof APP_TEMPLATES;
243
+ /** The built-in platforms. A project adds its own, or overrides these, under `frigear.platforms` in the root package.json. */
244
+ declare const BUILTIN_PLATFORMS: Record<string, PlatformDefinition>;
245
+ interface PlatformRegistry {
246
+ platforms: Record<string, PlatformDefinition>;
247
+ /** Template names and their giget sources. */
248
+ templates: Record<string, string>;
249
+ }
250
+ /** The built-ins plus a project's own platforms and templates from `frigear` in its root package.json. */
251
+ declare const platformRegistry: (rootPkg?: PackageJson, ref?: string) => PlatformRegistry;
252
+ /** Whether a `--template` value is a giget source rather than a template name. */
253
+ declare const isTemplateSource: (value: string) => boolean;
254
+ /** The target of a platform by name or alias. */
255
+ declare const findTarget: (platform: PlatformDefinition, name: string) => {
256
+ id: string;
257
+ target: PlatformTarget;
258
+ } | undefined;
259
+
260
+ interface AddPlatformOptions {
261
+ /** Any folder of the workspace: the root, the apps folder, an app. */
262
+ cwd: string;
263
+ /** A platform name (`web`, `mobile`, `desktop`, a project's own, or any name with `template`), or a definition. */
264
+ platform: string | PlatformDefinition;
265
+ /** The app's folder name; defaults to the platform's `defaultAppName` or name. */
266
+ name?: string;
267
+ /** A template name or giget source, instead of the platform's own template. */
268
+ template?: string;
269
+ /** The folder apps go into: `auto` (default) or a path relative to `cwd`. */
270
+ appsDir?: string;
271
+ /** Branch or tag of the frigear-nu repository for the built-in templates. */
272
+ ref?: string;
273
+ /** Add the platform's scripts to the root package.json (default true). */
274
+ scripts?: boolean;
275
+ /** Install the workspace's dependencies afterwards (default true). */
276
+ install?: boolean;
277
+ /** Run the root `prepare:env` script afterwards, when there is one (default: same as `install`). */
278
+ prepareEnv?: boolean;
279
+ logger?: ConsolaInstance;
280
+ }
281
+ interface AddPlatformResult {
282
+ root: string;
283
+ /** The platform the app was added as. */
284
+ platform: string;
285
+ /** The template source the app was copied from. */
286
+ source: string;
287
+ appName: string;
288
+ /** Absolute path of the new app. */
289
+ appDir: string;
290
+ packageName: string;
291
+ appsDir: {
292
+ dir: string;
293
+ covered: boolean;
294
+ };
295
+ scripts: {
296
+ added: string[];
297
+ skipped: string[];
298
+ };
299
+ nextSteps: string[];
300
+ }
301
+ /** The scope the apps in `appsDir` use (`@workspace` in the starters), else the root package's scope. */
302
+ declare const resolveAppScope: (root: string, appsDir?: string) => Promise<string | undefined>;
303
+ /** The platform definition for a name or definition; an unknown name is an ad hoc platform when a template is given. */
304
+ declare const resolvePlatform: (registry: PlatformRegistry, platform: string | PlatformDefinition, template?: string) => PlatformDefinition;
305
+ /** The giget source for a template name or source. */
306
+ declare const resolveTemplateSource: (registry: PlatformRegistry, template: string) => string;
307
+ /** Replaces `<name>`, `<dir>` and `<package>` in a script name, command or step. */
308
+ declare const fillPlaceholders: (text: string, values: {
309
+ name: string;
310
+ dir: string;
311
+ package?: string;
312
+ }) => string;
313
+ /** The root scripts of a platform for one app, keyed by app name. */
314
+ declare const platformScripts: (platform: PlatformDefinition, appName: string, appDir: string) => {
315
+ [k: string]: string;
316
+ };
317
+ /** Adds scripts to the root package.json, keeping every script that is already there. */
318
+ declare const mergeRootScripts: (root: string, scripts: Record<string, string>) => Promise<{
319
+ added: string[];
320
+ skipped: string[];
321
+ }>;
322
+ /**
323
+ * Adds an app of a platform to the workspace: copies the template into `<appsDir>/<name>`, names the package in the
324
+ * workspace's scope, records the platform in its package.json (`frigear.platform`), adds the platform's root scripts
325
+ * and installs. Works from any folder of the workspace.
326
+ */
327
+ declare const addPlatform: (options: AddPlatformOptions) => Promise<AddPlatformResult>;
328
+
329
+ type PlatformErrorCode = 'NO_WORKSPACE' | 'OUTSIDE_ROOT' | 'APP_EXISTS' | 'UNKNOWN_PLATFORM' | 'UNKNOWN_TEMPLATE' | 'UNKNOWN_TARGET' | 'APP_NOT_FOUND' | 'APP_AMBIGUOUS' | 'DOWNLOAD_FAILED';
330
+ /** An error of `addPlatform` / `initPlatform`; `candidates` lists the choices when one has to be picked. */
331
+ declare class PlatformError extends Error {
332
+ readonly code: PlatformErrorCode;
333
+ readonly candidates?: string[];
334
+ constructor(code: PlatformErrorCode, message: string, options?: {
335
+ candidates?: string[];
336
+ cause?: unknown;
337
+ });
338
+ }
339
+
340
+ interface WorkspaceApp {
341
+ /** Folder name, e.g. `mobile`. */
342
+ name: string;
343
+ /** Absolute path. */
344
+ dir: string;
345
+ pkg: PackageJson;
346
+ /** The platform from `frigear.platform`, else detected from its dependencies. */
347
+ platform?: PlatformDefinition;
348
+ }
349
+ /** The platform of an app: its `frigear.platform` field, else the first platform whose `detect` matches (`web` last). */
350
+ declare const detectAppPlatform: (registry: PlatformRegistry, pkg: PackageJson) => PlatformDefinition | undefined;
351
+ /** The apps of the workspace (folders with a package.json in the apps folder) and their platforms. */
352
+ declare const listWorkspaceApps: (appsDir: string, registry: PlatformRegistry) => Promise<WorkspaceApp[]>;
353
+ interface ResolvePlatformAppOptions {
354
+ cwd: string;
355
+ root: string;
356
+ appsDir: string;
357
+ registry: PlatformRegistry;
358
+ target: string;
359
+ /** A folder name under the apps folder, or a path relative to `cwd`. */
360
+ app?: string;
361
+ }
362
+ /** The app to set a target up in: `app`, else the app `cwd` is in, else the only app whose platform has the target. */
363
+ declare const resolvePlatformApp: (options: ResolvePlatformAppOptions) => Promise<WorkspaceApp>;
364
+ interface InitPlatformOptions {
365
+ /** Any folder of the workspace. */
366
+ cwd: string;
367
+ /** `ios`, `android`, `apple-watch`, `tauri`, or a target of a project's own platform. */
368
+ target: string;
369
+ /** The app: a folder name under the apps folder, or a path. */
370
+ app?: string;
371
+ /** The folder apps live in: `auto` (default) or a path relative to `cwd`. */
372
+ appsDir?: string;
373
+ /** Extra arguments for the script or binary. */
374
+ args?: string[];
375
+ /** Only work out what would run. */
376
+ dryRun?: boolean;
377
+ logger?: ConsolaInstance;
378
+ }
379
+ interface InitPlatformResult {
380
+ root: string;
381
+ app: WorkspaceApp;
382
+ platform: string;
383
+ target: string;
384
+ /** What runs (or would run): `script <name> ...` or `exec <bin> ...`. */
385
+ command: {
386
+ kind: 'script' | 'exec';
387
+ name: string;
388
+ args: string[];
389
+ };
390
+ }
391
+ /** How a target runs in an app: its script when the app has it, else the binary. */
392
+ declare const targetCommand: (target: PlatformTarget, pkg: PackageJson, extra?: string[]) => InitPlatformResult["command"] | undefined;
393
+ /** Sets up a target (`ios`, `apple-watch`, `tauri`, ...) in an app of the workspace, through the app's own tooling. */
394
+ declare const initPlatform: (options: InitPlatformOptions) => Promise<InitPlatformResult>;
395
+
396
+ interface AppsDir {
397
+ /** Absolute path of the folder new apps go into. */
398
+ dir: string;
399
+ /** Whether a `pnpm-workspace.yaml` glob covers its subfolders; if not, pnpm will not install an app put there. */
400
+ covered: boolean;
401
+ }
402
+ /**
403
+ * The folder apps live in. `appsDir` (resolved against `cwd`) when given and not `auto`; else the apps folder `cwd` is
404
+ * in (so the command works from the root and from inside `apps/`); else `apps`, or the first other folder of a
405
+ * one-level `pnpm-workspace.yaml` glob that is not `packages`.
406
+ */
407
+ declare const resolveAppsDir: ({ cwd, root, appsDir }: {
408
+ cwd: string;
409
+ root: string;
410
+ appsDir?: string;
411
+ }) => Promise<AppsDir>;
412
+
413
+ /**
414
+ * How a secret is generated: a spec string or a function.
415
+ *
416
+ * - `random:<bytes>`: random bytes, base64 (`random:32` gives 44 characters)
417
+ * - `hex:<bytes>`: random bytes, hex
418
+ * - `uuid`: a random UUID
419
+ * - `rsa`: a 2048-bit PKCS#8 RSA private key on one line with `\n` escapes, in double quotes
420
+ */
421
+ type SecretGenerator = string | (() => string);
422
+ /** The secrets filled in when their line is empty, unless a project turns them off. */
423
+ declare const BUILTIN_SECRETS: Record<string, SecretGenerator>;
424
+ /** The folders whose direct subfolders are searched for `.env.example`. */
425
+ declare const DEFAULT_ENV_DIRS: string[];
426
+ /** A new value for `key` from its generator. Throws for an unknown spec. */
427
+ declare const generateSecret: (key: string, generator: SecretGenerator) => string;
428
+ interface EnvConfig {
429
+ /** The secrets to fill in, built-ins included; a project's `false` has removed a built-in. */
430
+ secrets: Record<string, SecretGenerator>;
431
+ dirs: string[];
432
+ }
433
+ /**
434
+ * The secrets and folders of a workspace: the built-ins, then `frigear.env` of its root package.json
435
+ * (`secrets`: key → spec, or `false` to drop a built-in; `dirs`: the folders to search).
436
+ */
437
+ declare const resolveEnvConfig: (rootPkg?: PackageJson) => EnvConfig;
438
+ interface PrepareEnvOptions {
439
+ /** The workspace root. */
440
+ root: string;
441
+ /** Its root package.json; read from `root` when left out. Its `frigear.env` is applied before `secrets`. */
442
+ rootPkg?: PackageJson;
443
+ /** More secrets, or other generators for existing ones (functions allowed), applied last. */
444
+ secrets?: Record<string, SecretGenerator | false>;
445
+ /** The folders whose direct subfolders are searched; default `frigear.env.dirs`, else `apps` and `packages`. */
446
+ dirs?: string[];
447
+ /** Report what would change without writing anything. */
448
+ dryRun?: boolean;
449
+ }
450
+ interface PrepareEnvResult {
451
+ /** The `.env` file, relative to the root. */
452
+ file: string;
453
+ /** Whether it was (or would be) created from `.env.example`. */
454
+ created: boolean;
455
+ /** The keys that got a generated value. */
456
+ generated: string[];
457
+ }
458
+ /**
459
+ * Creates each app's and package's `.env` from its `.env.example` (when it has none) and fills in empty secrets, in new
460
+ * and existing files. A value that is set is never changed, so running it again is safe.
461
+ */
462
+ declare const prepareEnv: (options: PrepareEnvOptions) => Promise<PrepareEnvResult[]>;
463
+ /** One line per file, as the command prints it. */
464
+ declare const describeEnvResult: (result: PrepareEnvResult) => string;
465
+
466
+ export { APP_TEMPLATES, BUILTIN_PLATFORMS, BUILTIN_SECRETS, DEFAULT_ENV_DIRS, PLATFORMS, PlatformError, STARTERS, addPlatform, main as default, definePlatform, describeEnvResult, detectAppPlatform, fillPlaceholders, findTarget, generateSecret, _default as initCmd, initPlatform, isTemplateSource, listWorkspaceApps, mainCmd, mergeRootScripts, migrations, platformRegistry, platformScripts, prepareEnv, resolveAppScope, resolveAppsDir, resolveEnvConfig, resolvePlatform, resolvePlatformApp, resolveStarter, resolveTemplateSource, targetCommand, upgradeWorkspace };
467
+ export type { AddPlatformOptions, AddPlatformResult, AppTemplate, AppsDir, EnvConfig, InitPlatformOptions, InitPlatformResult, Migration, NextStepsContext, Platform, PlatformDefinition, PlatformErrorCode, PlatformRegistry, PlatformTarget, PrepareEnvOptions, PrepareEnvResult, ResolvePlatformAppOptions, Rule, SecretGenerator, Starter, UpgradeOptions, WorkspaceApp };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as citty from 'citty';
2
+ import { ConsolaInstance } from 'consola';
3
+ import { PackageJson } from 'pkg-types';
2
4
 
3
5
  declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
4
6
  declare function main(): Promise<void>;
@@ -186,5 +188,280 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
186
188
  */
187
189
  declare const migrations: Migration[];
188
190
 
189
- export { PLATFORMS, STARTERS, main as default, _default as initCmd, mainCmd, migrations, resolveStarter, upgradeWorkspace };
190
- export type { Migration, Platform, Rule, Starter, UpgradeOptions };
191
+ /** What `platform init <target>` runs in an app: the app's own `script` when it has it, else the `bin` command. */
192
+ interface PlatformTarget {
193
+ description?: string;
194
+ /** Other names for the target, e.g. `watchos` for `apple-watch`. */
195
+ aliases?: string[];
196
+ /** A script of the app's package.json, run with the workspace's package manager. */
197
+ script?: string;
198
+ /** A binary of the app's dependencies and its leading arguments, e.g. `['frigear-mobile', 'native']`. */
199
+ bin?: string[];
200
+ /** Arguments appended to the script or the binary. */
201
+ args?: string[];
202
+ }
203
+ interface NextStepsContext {
204
+ /** The app's folder name, e.g. `mobile`. */
205
+ appName: string;
206
+ /** The app's path relative to the workspace root, e.g. `apps/mobile`. */
207
+ appDir: string;
208
+ /** The app's package name, e.g. `@workspace/mobile`. */
209
+ packageName: string;
210
+ root: string;
211
+ /** Whether an app of the workspace runs `@frigear-nu/oauth-server`, so the new app can sign in there. */
212
+ hasOAuthServer: boolean;
213
+ }
214
+ interface PlatformDefinition {
215
+ /** `mobile`, `display`, ... */
216
+ name: string;
217
+ description?: string;
218
+ /** A template name (`web`, `mobile`, ... or a project's own) or a giget source. */
219
+ template?: string;
220
+ /** Folder name of the app when none is given; defaults to `name`. */
221
+ defaultAppName?: string;
222
+ /**
223
+ * Root package.json scripts added for each app of the platform. In keys and values `<name>` is the app's folder name
224
+ * and `<dir>` its path from the root (`./apps/mobile`). Existing scripts are never overwritten.
225
+ */
226
+ scripts?: Record<string, string>;
227
+ /** Printed after the app was added; `<name>`, `<dir>` and `<package>` are replaced in string steps. */
228
+ nextSteps?: string[] | ((context: NextStepsContext) => string[]);
229
+ /** What `platform init <target>` can do for apps of this platform. */
230
+ targets?: Record<string, PlatformTarget>;
231
+ /** Recognises an app of this platform that has no `frigear.platform` field in its package.json. */
232
+ detect?: (pkg: PackageJson) => boolean;
233
+ }
234
+ declare const definePlatform: (definition: PlatformDefinition) => PlatformDefinition;
235
+ /** App templates, as paths in the frigear-nu repository. */
236
+ declare const APP_TEMPLATES: {
237
+ readonly web: ".starters/workspace/apps/web";
238
+ readonly 'web-standalone': ".starters/mobile-standalone/apps/web";
239
+ readonly mobile: ".starters/mobile/apps/mobile";
240
+ readonly desktop: ".starters/desktop/apps/desktop";
241
+ };
242
+ type AppTemplate = keyof typeof APP_TEMPLATES;
243
+ /** The built-in platforms. A project adds its own, or overrides these, under `frigear.platforms` in the root package.json. */
244
+ declare const BUILTIN_PLATFORMS: Record<string, PlatformDefinition>;
245
+ interface PlatformRegistry {
246
+ platforms: Record<string, PlatformDefinition>;
247
+ /** Template names and their giget sources. */
248
+ templates: Record<string, string>;
249
+ }
250
+ /** The built-ins plus a project's own platforms and templates from `frigear` in its root package.json. */
251
+ declare const platformRegistry: (rootPkg?: PackageJson, ref?: string) => PlatformRegistry;
252
+ /** Whether a `--template` value is a giget source rather than a template name. */
253
+ declare const isTemplateSource: (value: string) => boolean;
254
+ /** The target of a platform by name or alias. */
255
+ declare const findTarget: (platform: PlatformDefinition, name: string) => {
256
+ id: string;
257
+ target: PlatformTarget;
258
+ } | undefined;
259
+
260
+ interface AddPlatformOptions {
261
+ /** Any folder of the workspace: the root, the apps folder, an app. */
262
+ cwd: string;
263
+ /** A platform name (`web`, `mobile`, `desktop`, a project's own, or any name with `template`), or a definition. */
264
+ platform: string | PlatformDefinition;
265
+ /** The app's folder name; defaults to the platform's `defaultAppName` or name. */
266
+ name?: string;
267
+ /** A template name or giget source, instead of the platform's own template. */
268
+ template?: string;
269
+ /** The folder apps go into: `auto` (default) or a path relative to `cwd`. */
270
+ appsDir?: string;
271
+ /** Branch or tag of the frigear-nu repository for the built-in templates. */
272
+ ref?: string;
273
+ /** Add the platform's scripts to the root package.json (default true). */
274
+ scripts?: boolean;
275
+ /** Install the workspace's dependencies afterwards (default true). */
276
+ install?: boolean;
277
+ /** Run the root `prepare:env` script afterwards, when there is one (default: same as `install`). */
278
+ prepareEnv?: boolean;
279
+ logger?: ConsolaInstance;
280
+ }
281
+ interface AddPlatformResult {
282
+ root: string;
283
+ /** The platform the app was added as. */
284
+ platform: string;
285
+ /** The template source the app was copied from. */
286
+ source: string;
287
+ appName: string;
288
+ /** Absolute path of the new app. */
289
+ appDir: string;
290
+ packageName: string;
291
+ appsDir: {
292
+ dir: string;
293
+ covered: boolean;
294
+ };
295
+ scripts: {
296
+ added: string[];
297
+ skipped: string[];
298
+ };
299
+ nextSteps: string[];
300
+ }
301
+ /** The scope the apps in `appsDir` use (`@workspace` in the starters), else the root package's scope. */
302
+ declare const resolveAppScope: (root: string, appsDir?: string) => Promise<string | undefined>;
303
+ /** The platform definition for a name or definition; an unknown name is an ad hoc platform when a template is given. */
304
+ declare const resolvePlatform: (registry: PlatformRegistry, platform: string | PlatformDefinition, template?: string) => PlatformDefinition;
305
+ /** The giget source for a template name or source. */
306
+ declare const resolveTemplateSource: (registry: PlatformRegistry, template: string) => string;
307
+ /** Replaces `<name>`, `<dir>` and `<package>` in a script name, command or step. */
308
+ declare const fillPlaceholders: (text: string, values: {
309
+ name: string;
310
+ dir: string;
311
+ package?: string;
312
+ }) => string;
313
+ /** The root scripts of a platform for one app, keyed by app name. */
314
+ declare const platformScripts: (platform: PlatformDefinition, appName: string, appDir: string) => {
315
+ [k: string]: string;
316
+ };
317
+ /** Adds scripts to the root package.json, keeping every script that is already there. */
318
+ declare const mergeRootScripts: (root: string, scripts: Record<string, string>) => Promise<{
319
+ added: string[];
320
+ skipped: string[];
321
+ }>;
322
+ /**
323
+ * Adds an app of a platform to the workspace: copies the template into `<appsDir>/<name>`, names the package in the
324
+ * workspace's scope, records the platform in its package.json (`frigear.platform`), adds the platform's root scripts
325
+ * and installs. Works from any folder of the workspace.
326
+ */
327
+ declare const addPlatform: (options: AddPlatformOptions) => Promise<AddPlatformResult>;
328
+
329
+ type PlatformErrorCode = 'NO_WORKSPACE' | 'OUTSIDE_ROOT' | 'APP_EXISTS' | 'UNKNOWN_PLATFORM' | 'UNKNOWN_TEMPLATE' | 'UNKNOWN_TARGET' | 'APP_NOT_FOUND' | 'APP_AMBIGUOUS' | 'DOWNLOAD_FAILED';
330
+ /** An error of `addPlatform` / `initPlatform`; `candidates` lists the choices when one has to be picked. */
331
+ declare class PlatformError extends Error {
332
+ readonly code: PlatformErrorCode;
333
+ readonly candidates?: string[];
334
+ constructor(code: PlatformErrorCode, message: string, options?: {
335
+ candidates?: string[];
336
+ cause?: unknown;
337
+ });
338
+ }
339
+
340
+ interface WorkspaceApp {
341
+ /** Folder name, e.g. `mobile`. */
342
+ name: string;
343
+ /** Absolute path. */
344
+ dir: string;
345
+ pkg: PackageJson;
346
+ /** The platform from `frigear.platform`, else detected from its dependencies. */
347
+ platform?: PlatformDefinition;
348
+ }
349
+ /** The platform of an app: its `frigear.platform` field, else the first platform whose `detect` matches (`web` last). */
350
+ declare const detectAppPlatform: (registry: PlatformRegistry, pkg: PackageJson) => PlatformDefinition | undefined;
351
+ /** The apps of the workspace (folders with a package.json in the apps folder) and their platforms. */
352
+ declare const listWorkspaceApps: (appsDir: string, registry: PlatformRegistry) => Promise<WorkspaceApp[]>;
353
+ interface ResolvePlatformAppOptions {
354
+ cwd: string;
355
+ root: string;
356
+ appsDir: string;
357
+ registry: PlatformRegistry;
358
+ target: string;
359
+ /** A folder name under the apps folder, or a path relative to `cwd`. */
360
+ app?: string;
361
+ }
362
+ /** The app to set a target up in: `app`, else the app `cwd` is in, else the only app whose platform has the target. */
363
+ declare const resolvePlatformApp: (options: ResolvePlatformAppOptions) => Promise<WorkspaceApp>;
364
+ interface InitPlatformOptions {
365
+ /** Any folder of the workspace. */
366
+ cwd: string;
367
+ /** `ios`, `android`, `apple-watch`, `tauri`, or a target of a project's own platform. */
368
+ target: string;
369
+ /** The app: a folder name under the apps folder, or a path. */
370
+ app?: string;
371
+ /** The folder apps live in: `auto` (default) or a path relative to `cwd`. */
372
+ appsDir?: string;
373
+ /** Extra arguments for the script or binary. */
374
+ args?: string[];
375
+ /** Only work out what would run. */
376
+ dryRun?: boolean;
377
+ logger?: ConsolaInstance;
378
+ }
379
+ interface InitPlatformResult {
380
+ root: string;
381
+ app: WorkspaceApp;
382
+ platform: string;
383
+ target: string;
384
+ /** What runs (or would run): `script <name> ...` or `exec <bin> ...`. */
385
+ command: {
386
+ kind: 'script' | 'exec';
387
+ name: string;
388
+ args: string[];
389
+ };
390
+ }
391
+ /** How a target runs in an app: its script when the app has it, else the binary. */
392
+ declare const targetCommand: (target: PlatformTarget, pkg: PackageJson, extra?: string[]) => InitPlatformResult["command"] | undefined;
393
+ /** Sets up a target (`ios`, `apple-watch`, `tauri`, ...) in an app of the workspace, through the app's own tooling. */
394
+ declare const initPlatform: (options: InitPlatformOptions) => Promise<InitPlatformResult>;
395
+
396
+ interface AppsDir {
397
+ /** Absolute path of the folder new apps go into. */
398
+ dir: string;
399
+ /** Whether a `pnpm-workspace.yaml` glob covers its subfolders; if not, pnpm will not install an app put there. */
400
+ covered: boolean;
401
+ }
402
+ /**
403
+ * The folder apps live in. `appsDir` (resolved against `cwd`) when given and not `auto`; else the apps folder `cwd` is
404
+ * in (so the command works from the root and from inside `apps/`); else `apps`, or the first other folder of a
405
+ * one-level `pnpm-workspace.yaml` glob that is not `packages`.
406
+ */
407
+ declare const resolveAppsDir: ({ cwd, root, appsDir }: {
408
+ cwd: string;
409
+ root: string;
410
+ appsDir?: string;
411
+ }) => Promise<AppsDir>;
412
+
413
+ /**
414
+ * How a secret is generated: a spec string or a function.
415
+ *
416
+ * - `random:<bytes>`: random bytes, base64 (`random:32` gives 44 characters)
417
+ * - `hex:<bytes>`: random bytes, hex
418
+ * - `uuid`: a random UUID
419
+ * - `rsa`: a 2048-bit PKCS#8 RSA private key on one line with `\n` escapes, in double quotes
420
+ */
421
+ type SecretGenerator = string | (() => string);
422
+ /** The secrets filled in when their line is empty, unless a project turns them off. */
423
+ declare const BUILTIN_SECRETS: Record<string, SecretGenerator>;
424
+ /** The folders whose direct subfolders are searched for `.env.example`. */
425
+ declare const DEFAULT_ENV_DIRS: string[];
426
+ /** A new value for `key` from its generator. Throws for an unknown spec. */
427
+ declare const generateSecret: (key: string, generator: SecretGenerator) => string;
428
+ interface EnvConfig {
429
+ /** The secrets to fill in, built-ins included; a project's `false` has removed a built-in. */
430
+ secrets: Record<string, SecretGenerator>;
431
+ dirs: string[];
432
+ }
433
+ /**
434
+ * The secrets and folders of a workspace: the built-ins, then `frigear.env` of its root package.json
435
+ * (`secrets`: key → spec, or `false` to drop a built-in; `dirs`: the folders to search).
436
+ */
437
+ declare const resolveEnvConfig: (rootPkg?: PackageJson) => EnvConfig;
438
+ interface PrepareEnvOptions {
439
+ /** The workspace root. */
440
+ root: string;
441
+ /** Its root package.json; read from `root` when left out. Its `frigear.env` is applied before `secrets`. */
442
+ rootPkg?: PackageJson;
443
+ /** More secrets, or other generators for existing ones (functions allowed), applied last. */
444
+ secrets?: Record<string, SecretGenerator | false>;
445
+ /** The folders whose direct subfolders are searched; default `frigear.env.dirs`, else `apps` and `packages`. */
446
+ dirs?: string[];
447
+ /** Report what would change without writing anything. */
448
+ dryRun?: boolean;
449
+ }
450
+ interface PrepareEnvResult {
451
+ /** The `.env` file, relative to the root. */
452
+ file: string;
453
+ /** Whether it was (or would be) created from `.env.example`. */
454
+ created: boolean;
455
+ /** The keys that got a generated value. */
456
+ generated: string[];
457
+ }
458
+ /**
459
+ * Creates each app's and package's `.env` from its `.env.example` (when it has none) and fills in empty secrets, in new
460
+ * and existing files. A value that is set is never changed, so running it again is safe.
461
+ */
462
+ declare const prepareEnv: (options: PrepareEnvOptions) => Promise<PrepareEnvResult[]>;
463
+ /** One line per file, as the command prints it. */
464
+ declare const describeEnvResult: (result: PrepareEnvResult) => string;
465
+
466
+ export { APP_TEMPLATES, BUILTIN_PLATFORMS, BUILTIN_SECRETS, DEFAULT_ENV_DIRS, PLATFORMS, PlatformError, STARTERS, addPlatform, main as default, definePlatform, describeEnvResult, detectAppPlatform, fillPlaceholders, findTarget, generateSecret, _default as initCmd, initPlatform, isTemplateSource, listWorkspaceApps, mainCmd, mergeRootScripts, migrations, platformRegistry, platformScripts, prepareEnv, resolveAppScope, resolveAppsDir, resolveEnvConfig, resolvePlatform, resolvePlatformApp, resolveStarter, resolveTemplateSource, targetCommand, upgradeWorkspace };
467
+ export type { AddPlatformOptions, AddPlatformResult, AppTemplate, AppsDir, EnvConfig, InitPlatformOptions, InitPlatformResult, Migration, NextStepsContext, Platform, PlatformDefinition, PlatformErrorCode, PlatformRegistry, PlatformTarget, PrepareEnvOptions, PrepareEnvResult, ResolvePlatformAppOptions, Rule, SecretGenerator, Starter, UpgradeOptions, WorkspaceApp };
package/dist/index.mjs CHANGED
@@ -1,19 +1,25 @@
1
- export { m as default, a as mainCmd } from './shared/cli.B_BErT55.mjs';
1
+ export { m as default, a as mainCmd } from './shared/cli.CIFLvzV1.mjs';
2
2
  export { PLATFORMS, STARTERS, default as initCmd, resolveStarter } from './chunks/init.mjs';
3
3
  export { m as migrations, u as upgradeWorkspace } from './chunks/upgrade.mjs';
4
+ export { a as addPlatform, f as fillPlaceholders, m as mergeRootScripts, p as platformScripts, r as resolveAppScope, b as resolvePlatform, c as resolveTemplateSource } from './shared/cli.DhcObGQf.mjs';
5
+ export { A as APP_TEMPLATES, B as BUILTIN_PLATFORMS, d as definePlatform, f as findTarget, i as isTemplateSource, p as platformRegistry } from './shared/cli.DnhGPz3G.mjs';
6
+ export { P as PlatformError, r as resolveAppsDir } from './shared/cli.B7bXD3w0.mjs';
7
+ export { d as detectAppPlatform, i as initPlatform, l as listWorkspaceApps, r as resolvePlatformApp, t as targetCommand } from './shared/cli.fvLpSH0v.mjs';
8
+ export { B as BUILTIN_SECRETS, D as DEFAULT_ENV_DIRS, d as describeEnvResult, g as generateSecret, p as prepareEnv, r as resolveEnvConfig } from './shared/cli.s0Wk6nL9.mjs';
4
9
  import 'citty';
5
10
  import 'consola';
6
11
  import 'node:path';
7
- import './shared/cli.Cfkcp0w9.mjs';
8
- import 'scule';
9
- import 'node:fs';
10
- import 'node:fs/promises';
11
- import 'pkg-types';
12
- import './shared/cli.CkMCvUCp.mjs';
12
+ import './shared/cli.C-q4Gf2K.mjs';
13
13
  import 'nypm';
14
- import './shared/cli.C_0i5HKZ.mjs';
14
+ import 'tinyexec';
15
+ import './shared/cli.B9jOPxYC.mjs';
15
16
  import 'giget';
17
+ import 'node:fs/promises';
16
18
  import 'node:os';
19
+ import 'node:fs';
17
20
  import 'magicast';
18
21
  import 'magicast/helpers';
19
- import './shared/cli.DUmSgMcB.mjs';
22
+ import 'pkg-types';
23
+ import './shared/cli.BLUxtpPi.mjs';
24
+ import 'scule';
25
+ import 'node:crypto';