@frigear-nu/cli 0.2.5 → 0.2.7
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/chunks/add.mjs +4 -4
- package/dist/chunks/add2.mjs +1 -1
- package/dist/chunks/app-create.mjs +5 -5
- package/dist/chunks/env.mjs +38 -0
- package/dist/chunks/init.mjs +3 -3
- package/dist/chunks/init2.mjs +4 -4
- package/dist/chunks/list.mjs +4 -4
- package/dist/chunks/module-create.mjs +1 -1
- package/dist/chunks/module-folder.mjs +1 -1
- package/dist/chunks/module-move.mjs +1 -1
- package/dist/chunks/package-rename.mjs +1 -1
- package/dist/chunks/prepare.mjs +13 -0
- package/dist/chunks/upgrade.mjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.mjs +7 -5
- package/dist/shared/{cli.CU1tZqxU.mjs → cli.B7bXD3w0.mjs} +1 -1
- package/dist/shared/{cli.DX_up8fP.mjs → cli.BH-_0Ga9.mjs} +3 -2
- package/dist/shared/{cli.CJ66durw.mjs → cli.Cbq-hdVL.mjs} +1 -1
- package/dist/shared/{cli.DEhqG8Aw.mjs → cli.DhcObGQf.mjs} +2 -2
- package/dist/shared/{cli.B8wGY3pU.mjs → cli.DnhGPz3G.mjs} +2 -1
- package/dist/shared/{cli.BVDx1SIR.mjs → cli.fvLpSH0v.mjs} +2 -2
- package/dist/shared/cli.s0Wk6nL9.mjs +104 -0
- package/package.json +1 -1
package/dist/chunks/add.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { relative } from 'node:path';
|
|
4
|
-
import { a as addPlatform } from '../shared/cli.
|
|
5
|
-
import { P as PlatformError, t as toPackageName, d as defineCommandArgs, c as templateArgs } from '../shared/cli.
|
|
6
|
-
import { e as exitWith, a as appsDirArg } from '../shared/cli.
|
|
4
|
+
import { a as addPlatform } from '../shared/cli.DhcObGQf.mjs';
|
|
5
|
+
import { P as PlatformError, t as toPackageName, d as defineCommandArgs, c as templateArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
6
|
+
import { e as exitWith, a as appsDirArg } from '../shared/cli.Cbq-hdVL.mjs';
|
|
7
7
|
import 'pkg-types';
|
|
8
8
|
import '../shared/cli.C-q4Gf2K.mjs';
|
|
9
9
|
import 'nypm';
|
|
@@ -14,7 +14,7 @@ import 'node:fs/promises';
|
|
|
14
14
|
import '../shared/cli.B9jOPxYC.mjs';
|
|
15
15
|
import 'giget';
|
|
16
16
|
import 'node:os';
|
|
17
|
-
import '../shared/cli.
|
|
17
|
+
import '../shared/cli.DnhGPz3G.mjs';
|
|
18
18
|
import 'scule';
|
|
19
19
|
|
|
20
20
|
const add = defineCommand({
|
package/dist/chunks/add2.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { readFile, writeFile } from 'node:fs/promises';
|
|
|
5
5
|
import { resolve, join, relative } from 'node:path';
|
|
6
6
|
import { parseModule, generateCode } from 'magicast';
|
|
7
7
|
import { getDefaultExportOptions, addNuxtModule } from 'magicast/helpers';
|
|
8
|
-
import { b as readPackage, d as defineCommandArgs, f as findWorkspaceRoot, l as listDirs } from '../shared/cli.
|
|
8
|
+
import { b as readPackage, d as defineCommandArgs, f as findWorkspaceRoot, l as listDirs } from '../shared/cli.B7bXD3w0.mjs';
|
|
9
9
|
import { a as addDeps } from '../shared/cli.C-q4Gf2K.mjs';
|
|
10
10
|
import 'scule';
|
|
11
11
|
import 'pkg-types';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
|
-
import { a as addPlatform } from '../shared/cli.
|
|
4
|
-
export { r as resolveAppScope } from '../shared/cli.
|
|
5
|
-
import { A as APP_TEMPLATES } from '../shared/cli.
|
|
6
|
-
import { d as defineCommandArgs, c as templateArgs } from '../shared/cli.
|
|
7
|
-
import { e as exitWith, a as appsDirArg } from '../shared/cli.
|
|
3
|
+
import { a as addPlatform } from '../shared/cli.DhcObGQf.mjs';
|
|
4
|
+
export { r as resolveAppScope } from '../shared/cli.DhcObGQf.mjs';
|
|
5
|
+
import { A as APP_TEMPLATES } from '../shared/cli.DnhGPz3G.mjs';
|
|
6
|
+
import { d as defineCommandArgs, c as templateArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
7
|
+
import { e as exitWith, a as appsDirArg } from '../shared/cli.Cbq-hdVL.mjs';
|
|
8
8
|
import 'node:path';
|
|
9
9
|
import 'pkg-types';
|
|
10
10
|
import '../shared/cli.C-q4Gf2K.mjs';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { p as prepareEnv, d as describeEnvResult } from '../shared/cli.s0Wk6nL9.mjs';
|
|
4
|
+
import { f as findWorkspaceRoot, d as defineCommandArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
5
|
+
import 'node:fs';
|
|
6
|
+
import 'node:fs/promises';
|
|
7
|
+
import 'node:crypto';
|
|
8
|
+
import 'node:path';
|
|
9
|
+
import 'scule';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
|
|
12
|
+
const env = defineCommand({
|
|
13
|
+
meta: {
|
|
14
|
+
name: "env",
|
|
15
|
+
description: "Create each app's .env from its .env.example and fill in empty secrets"
|
|
16
|
+
},
|
|
17
|
+
args: defineCommandArgs({
|
|
18
|
+
"dry-run": {
|
|
19
|
+
type: "boolean",
|
|
20
|
+
description: "Show what would change without writing anything",
|
|
21
|
+
default: false
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
async run({ args }) {
|
|
25
|
+
const logger = consola.withTag("prepare env");
|
|
26
|
+
const root = await findWorkspaceRoot(args.cwd) ?? args.cwd;
|
|
27
|
+
try {
|
|
28
|
+
const results = await prepareEnv({ root, dryRun: args["dry-run"] });
|
|
29
|
+
if (!results.length) logger.info("No .env.example files found.");
|
|
30
|
+
for (const result of results) logger.log(`${args["dry-run"] ? "(dry run) " : ""}${describeEnvResult(result)}`);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export { env as default };
|
package/dist/chunks/init.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { resolve, basename, relative } from 'node:path';
|
|
4
|
-
import { i as isEmptyDir, h as hasPackage, a as renamePackage, t as toPackageName, b as readPackage, d as defineCommandArgs, c as templateArgs } from '../shared/cli.
|
|
4
|
+
import { i as isEmptyDir, h as hasPackage, a as renamePackage, t as toPackageName, b as readPackage, d as defineCommandArgs, c as templateArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
5
5
|
import { i as installDeps, r as runPackageScript } from '../shared/cli.C-q4Gf2K.mjs';
|
|
6
6
|
import { d as downloadTemplateToDir, r as repoSource } from '../shared/cli.B9jOPxYC.mjs';
|
|
7
7
|
import 'scule';
|
|
@@ -27,11 +27,11 @@ const nextSteps = {
|
|
|
27
27
|
"mobile": [" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/mobile/.env"],
|
|
28
28
|
"desktop": [
|
|
29
29
|
" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/desktop/.env, or DESKTOP_MODE=local",
|
|
30
|
-
" pnpm desktop:
|
|
30
|
+
" pnpm desktop:setup"
|
|
31
31
|
],
|
|
32
32
|
"multi-platform": [
|
|
33
33
|
" put your email in NUXT_ACL_ADMINS in apps/web/.env",
|
|
34
|
-
" pnpm desktop:
|
|
34
|
+
" pnpm desktop:setup"
|
|
35
35
|
]
|
|
36
36
|
};
|
|
37
37
|
const isStarter = (value) => value in STARTERS;
|
package/dist/chunks/init2.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
|
-
import { i as initPlatform } from '../shared/cli.
|
|
4
|
-
import { P as PlatformError, d as defineCommandArgs } from '../shared/cli.
|
|
5
|
-
import { p as passThroughArgs, e as exitWith, a as appsDirArg } from '../shared/cli.
|
|
3
|
+
import { i as initPlatform } from '../shared/cli.fvLpSH0v.mjs';
|
|
4
|
+
import { P as PlatformError, d as defineCommandArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
5
|
+
import { p as passThroughArgs, e as exitWith, a as appsDirArg } from '../shared/cli.Cbq-hdVL.mjs';
|
|
6
6
|
import 'node:fs';
|
|
7
7
|
import 'node:path';
|
|
8
8
|
import '../shared/cli.C-q4Gf2K.mjs';
|
|
@@ -10,7 +10,7 @@ import 'nypm';
|
|
|
10
10
|
import 'tinyexec';
|
|
11
11
|
import '../shared/cli.BLUxtpPi.mjs';
|
|
12
12
|
import 'node:fs/promises';
|
|
13
|
-
import '../shared/cli.
|
|
13
|
+
import '../shared/cli.DnhGPz3G.mjs';
|
|
14
14
|
import '../shared/cli.B9jOPxYC.mjs';
|
|
15
15
|
import 'giget';
|
|
16
16
|
import 'node:os';
|
package/dist/chunks/list.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { relative } from 'node:path';
|
|
4
|
-
import { p as platformRegistry } from '../shared/cli.
|
|
5
|
-
import { l as listWorkspaceApps } from '../shared/cli.
|
|
6
|
-
import { f as findWorkspaceRoot, b as readPackage, r as resolveAppsDir, d as defineCommandArgs } from '../shared/cli.
|
|
7
|
-
import { e as exitWith, a as appsDirArg } from '../shared/cli.
|
|
4
|
+
import { p as platformRegistry } from '../shared/cli.DnhGPz3G.mjs';
|
|
5
|
+
import { l as listWorkspaceApps } from '../shared/cli.fvLpSH0v.mjs';
|
|
6
|
+
import { f as findWorkspaceRoot, b as readPackage, r as resolveAppsDir, d as defineCommandArgs } from '../shared/cli.B7bXD3w0.mjs';
|
|
7
|
+
import { e as exitWith, a as appsDirArg } from '../shared/cli.Cbq-hdVL.mjs';
|
|
8
8
|
import '../shared/cli.B9jOPxYC.mjs';
|
|
9
9
|
import 'giget';
|
|
10
10
|
import 'node:fs/promises';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import { t as toPackageName, f as findWorkspaceRoot, h as hasPackage, a as renamePackage, d as defineCommandArgs, p as packageScope, b as readPackage } from '../shared/cli.
|
|
3
|
+
import { t as toPackageName, f as findWorkspaceRoot, h as hasPackage, a as renamePackage, d as defineCommandArgs, p as packageScope, b as readPackage } from '../shared/cli.B7bXD3w0.mjs';
|
|
4
4
|
import { d as downloadTemplateToDir } from '../shared/cli.B9jOPxYC.mjs';
|
|
5
5
|
import consola from 'consola';
|
|
6
6
|
import 'scule';
|
|
@@ -3,7 +3,7 @@ import consola from 'consola';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { relative, extname, join, dirname } from 'node:path';
|
|
6
|
-
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.
|
|
6
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.B7bXD3w0.mjs';
|
|
7
7
|
import { r as resolveLocalModule } from '../shared/cli.DAggATZw.mjs';
|
|
8
8
|
import { r as resolveArg, a as applyPlan, t as toPosix, p as printPlan, b as planChanges } from '../shared/cli.BLUxtpPi.mjs';
|
|
9
9
|
import 'scule';
|
|
@@ -3,7 +3,7 @@ import consola from 'consola';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { relative, join, extname, sep, dirname } from 'node:path';
|
|
6
|
-
import { d as defineCommandArgs, f as findWorkspaceRoot, w as workspaceGlobs, b as readPackage } from '../shared/cli.
|
|
6
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot, w as workspaceGlobs, b as readPackage } from '../shared/cli.B7bXD3w0.mjs';
|
|
7
7
|
import { r as resolveLocalModule } from '../shared/cli.DAggATZw.mjs';
|
|
8
8
|
import { r as resolveArg, a as applyPlan, p as printPlan, t as toPosix, f as findNuxtRoot, b as planChanges, w as workspaceFiles } from '../shared/cli.BLUxtpPi.mjs';
|
|
9
9
|
import 'scule';
|
|
@@ -3,7 +3,7 @@ import consola from 'consola';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { relative, join, dirname, basename } from 'node:path';
|
|
6
|
-
import { d as defineCommandArgs, f as findWorkspaceRoot, e as workspacePackageDirs, b as readPackage, p as packageScope } from '../shared/cli.
|
|
6
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot, e as workspacePackageDirs, b as readPackage, p as packageScope } from '../shared/cli.B7bXD3w0.mjs';
|
|
7
7
|
import { r as resolveArg, a as applyPlan, p as printPlan, t as toPosix, b as planChanges } from '../shared/cli.BLUxtpPi.mjs';
|
|
8
8
|
import 'scule';
|
|
9
9
|
import 'pkg-types';
|
|
@@ -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 };
|
package/dist/chunks/upgrade.mjs
CHANGED
|
@@ -5,7 +5,7 @@ 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 { 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.
|
|
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
9
|
import { i as installDeps } from '../shared/cli.C-q4Gf2K.mjs';
|
|
10
10
|
|
|
11
11
|
const DOCS = "https://docs.frigear.dev";
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -410,5 +410,58 @@ declare const resolveAppsDir: ({ cwd, root, appsDir }: {
|
|
|
410
410
|
appsDir?: string;
|
|
411
411
|
}) => Promise<AppsDir>;
|
|
412
412
|
|
|
413
|
-
|
|
414
|
-
|
|
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
|
@@ -410,5 +410,58 @@ declare const resolveAppsDir: ({ cwd, root, appsDir }: {
|
|
|
410
410
|
appsDir?: string;
|
|
411
411
|
}) => Promise<AppsDir>;
|
|
412
412
|
|
|
413
|
-
|
|
414
|
-
|
|
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,10 +1,11 @@
|
|
|
1
|
-
export { m as default, a as mainCmd } from './shared/cli.
|
|
1
|
+
export { m as default, a as mainCmd } from './shared/cli.BH-_0Ga9.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.
|
|
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.
|
|
6
|
-
export { P as PlatformError, r as resolveAppsDir } from './shared/cli.
|
|
7
|
-
export { d as detectAppPlatform, i as initPlatform, l as listWorkspaceApps, r as resolvePlatformApp, t as targetCommand } from './shared/cli.
|
|
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';
|
|
8
9
|
import 'citty';
|
|
9
10
|
import 'consola';
|
|
10
11
|
import 'node:path';
|
|
@@ -21,3 +22,4 @@ import 'magicast/helpers';
|
|
|
21
22
|
import 'pkg-types';
|
|
22
23
|
import './shared/cli.BLUxtpPi.mjs';
|
|
23
24
|
import 'scule';
|
|
25
|
+
import 'node:crypto';
|
|
@@ -2,7 +2,7 @@ import { kebabCase } from 'scule';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { readFile, readdir } from 'node:fs/promises';
|
|
4
4
|
import { join, dirname, resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { findNearestFile, readPackageJSON, writePackageJSON } from 'pkg-types';
|
|
6
6
|
|
|
7
7
|
const getDefaultCommandArgs = () => {
|
|
8
8
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
2
|
|
|
3
|
-
const version = "0.2.
|
|
3
|
+
const version = "0.2.7";
|
|
4
4
|
const pkg = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
@@ -19,7 +19,8 @@ const mainCmd = defineCommand({
|
|
|
19
19
|
"module:move": () => import('../chunks/module-move.mjs').then((module) => module.default),
|
|
20
20
|
"package:rename": () => import('../chunks/package-rename.mjs').then((module) => module.default),
|
|
21
21
|
"add": () => import('../chunks/add2.mjs').then((module) => module.default),
|
|
22
|
-
"upgrade": () => import('../chunks/upgrade.mjs').then(function (n) { return n.a; }).then((module) => module.default)
|
|
22
|
+
"upgrade": () => import('../chunks/upgrade.mjs').then(function (n) { return n.a; }).then((module) => module.default),
|
|
23
|
+
"prepare": () => import('../chunks/prepare.mjs').then((module) => module.default)
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
async function main() {
|
|
@@ -4,8 +4,8 @@ import { readPackageJSON, writePackageJSON } from 'pkg-types';
|
|
|
4
4
|
import { i as installDeps, r as runPackageScript } from './cli.C-q4Gf2K.mjs';
|
|
5
5
|
import { t as toPosix } from './cli.BLUxtpPi.mjs';
|
|
6
6
|
import { d as downloadTemplateToDir } from './cli.B9jOPxYC.mjs';
|
|
7
|
-
import { f as findWorkspaceRoot, P as PlatformError, b as readPackage, r as resolveAppsDir, t as toPackageName, h as hasPackage, l as listDirs, p as packageScope } from './cli.
|
|
8
|
-
import { p as platformRegistry, i as isTemplateSource } from './cli.
|
|
7
|
+
import { f as findWorkspaceRoot, P as PlatformError, b as readPackage, r as resolveAppsDir, t as toPackageName, h as hasPackage, l as listDirs, p as packageScope } from './cli.B7bXD3w0.mjs';
|
|
8
|
+
import { p as platformRegistry, i as isTemplateSource } from './cli.DnhGPz3G.mjs';
|
|
9
9
|
|
|
10
10
|
const resolveAppScope = async (root, appsDir = join(root, "apps")) => {
|
|
11
11
|
for (const dir of await listDirs(appsDir)) {
|
|
@@ -64,6 +64,7 @@ const BUILTIN_PLATFORMS = {
|
|
|
64
64
|
template: "desktop",
|
|
65
65
|
scripts: {
|
|
66
66
|
"dev:<name>": "pnpm --filter <dir> dev",
|
|
67
|
+
"<name>:setup": "pnpm --filter <dir> run setup",
|
|
67
68
|
"<name>:doctor": "pnpm --filter <dir> run doctor",
|
|
68
69
|
"<name>:init": "pnpm --filter <dir> run native",
|
|
69
70
|
"<name>:sync": "pnpm --filter <dir> run native:sync",
|
|
@@ -71,7 +72,7 @@ const BUILTIN_PLATFORMS = {
|
|
|
71
72
|
"<name>:build": "pnpm --filter <dir> run native:build",
|
|
72
73
|
"<name>:sidecar": "pnpm --filter <dir> run sidecar"
|
|
73
74
|
},
|
|
74
|
-
nextSteps: (context) => clientSteps(context, "
|
|
75
|
+
nextSteps: (context) => clientSteps(context, "setup", "desktop"),
|
|
75
76
|
targets: {
|
|
76
77
|
tauri: { description: "The Tauri project (src-tauri/)", aliases: ["desktop"], script: "native", bin: ["frigear-desktop", "init"] }
|
|
77
78
|
},
|
|
@@ -3,8 +3,8 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import { relative, join, resolve } from 'node:path';
|
|
4
4
|
import { r as runPackageScript, e as execBin } from './cli.C-q4Gf2K.mjs';
|
|
5
5
|
import { t as toPosix } from './cli.BLUxtpPi.mjs';
|
|
6
|
-
import { l as listDirs, b as readPackage, f as findWorkspaceRoot, P as PlatformError, r as resolveAppsDir, h as hasPackage, g as isInside } from './cli.
|
|
7
|
-
import { p as platformRegistry, f as findTarget } from './cli.
|
|
6
|
+
import { l as listDirs, b as readPackage, f as findWorkspaceRoot, P as PlatformError, r as resolveAppsDir, h as hasPackage, g as isInside } from './cli.B7bXD3w0.mjs';
|
|
7
|
+
import { p as platformRegistry, f as findTarget } from './cli.DnhGPz3G.mjs';
|
|
8
8
|
|
|
9
9
|
const detectAppPlatform = (registry, pkg) => {
|
|
10
10
|
const own = pkg.frigear?.platform;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile, writeFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { randomUUID, randomBytes, generateKeyPairSync } from 'node:crypto';
|
|
4
|
+
import { join, dirname, relative } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const BUILTIN_SECRETS = {
|
|
7
|
+
// Nuxt's appSecret: nuxt-auth-utils seals the session cookie with it, at least 32 characters.
|
|
8
|
+
NUXT_APP_SECRET: "random:32",
|
|
9
|
+
// @frigear-nu/oauth-server signs its tokens with it.
|
|
10
|
+
NUXT_OAUTH_SERVER_PRIVATE_KEY: "rsa"
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_ENV_DIRS = ["apps", "packages"];
|
|
13
|
+
const rsaKey = () => {
|
|
14
|
+
const { privateKey } = generateKeyPairSync("rsa", {
|
|
15
|
+
modulusLength: 2048,
|
|
16
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
17
|
+
publicKeyEncoding: { type: "spki", format: "pem" }
|
|
18
|
+
});
|
|
19
|
+
return `"${privateKey.trim().replaceAll("\n", "\\n")}"`;
|
|
20
|
+
};
|
|
21
|
+
const byteCount = (key, spec, value) => {
|
|
22
|
+
const bytes = Number(value);
|
|
23
|
+
if (!Number.isInteger(bytes) || bytes < 1)
|
|
24
|
+
throw new Error(`${key}: "${spec}" needs a positive number of bytes, e.g. "${spec.split(":")[0]}:32"`);
|
|
25
|
+
return bytes;
|
|
26
|
+
};
|
|
27
|
+
const generateSecret = (key, generator) => {
|
|
28
|
+
if (typeof generator === "function") return generator();
|
|
29
|
+
const [kind, value] = generator.split(":", 2);
|
|
30
|
+
switch (kind) {
|
|
31
|
+
case "random":
|
|
32
|
+
return randomBytes(byteCount(key, generator, value)).toString("base64");
|
|
33
|
+
case "hex":
|
|
34
|
+
return randomBytes(byteCount(key, generator, value)).toString("hex");
|
|
35
|
+
case "uuid":
|
|
36
|
+
return randomUUID();
|
|
37
|
+
case "rsa":
|
|
38
|
+
return rsaKey();
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(`${key}: unknown secret generator "${generator}" (use random:<bytes>, hex:<bytes>, uuid or rsa)`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const mergeSecrets = (base, overrides = {}) => Object.fromEntries(Object.entries({ ...base, ...overrides }).filter((entry) => entry[1] !== false));
|
|
44
|
+
const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
45
|
+
const resolveEnvConfig = (rootPkg) => {
|
|
46
|
+
const env = record(record(rootPkg?.frigear).env);
|
|
47
|
+
const own = record(env.secrets);
|
|
48
|
+
for (const [key, value] of Object.entries(own)) {
|
|
49
|
+
if (value !== false && typeof value !== "string")
|
|
50
|
+
throw new Error(`frigear.env.secrets.${key} in package.json must be a generator spec or false`);
|
|
51
|
+
}
|
|
52
|
+
const secrets = mergeSecrets(BUILTIN_SECRETS, own);
|
|
53
|
+
const dirs = Array.isArray(env.dirs) ? env.dirs.filter((dir) => typeof dir === "string") : DEFAULT_ENV_DIRS;
|
|
54
|
+
return { secrets, dirs };
|
|
55
|
+
};
|
|
56
|
+
const isEmpty = (value) => ["", '""', "''"].includes(value.trim());
|
|
57
|
+
const findExamples = async (root, dirs) => {
|
|
58
|
+
const found = [];
|
|
59
|
+
for (const group of dirs) {
|
|
60
|
+
const dir = join(root, group);
|
|
61
|
+
if (!existsSync(dir)) continue;
|
|
62
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
63
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
64
|
+
const example = join(dir, entry.name, ".env.example");
|
|
65
|
+
if (entry.isDirectory() && existsSync(example)) found.push(example);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
};
|
|
70
|
+
const prepareEnv = async (options) => {
|
|
71
|
+
const { root } = options;
|
|
72
|
+
const rootPkg = options.rootPkg ?? (existsSync(join(root, "package.json")) ? JSON.parse(await readFile(join(root, "package.json"), "utf8")) : void 0);
|
|
73
|
+
const config = resolveEnvConfig(rootPkg);
|
|
74
|
+
const secrets = mergeSecrets(config.secrets, options.secrets);
|
|
75
|
+
const results = [];
|
|
76
|
+
for (const example of await findExamples(root, options.dirs ?? config.dirs)) {
|
|
77
|
+
const target = join(dirname(example), ".env");
|
|
78
|
+
const created = !existsSync(target);
|
|
79
|
+
const text = await readFile(created ? example : target, "utf8");
|
|
80
|
+
const generated = [];
|
|
81
|
+
const lines = text.split("\n").map((line) => {
|
|
82
|
+
const match = /^(\s*)([A-Z0-9_]+)\s*=(.*)$/.exec(line);
|
|
83
|
+
if (!match) return line;
|
|
84
|
+
const [, indent, key, value] = match;
|
|
85
|
+
const generator = secrets[key];
|
|
86
|
+
if (generator === void 0 || !isEmpty(value)) return line;
|
|
87
|
+
generated.push(key);
|
|
88
|
+
return `${indent}${key}=${generateSecret(key, generator)}`;
|
|
89
|
+
});
|
|
90
|
+
if (!options.dryRun && (created || generated.length))
|
|
91
|
+
await writeFile(target, lines.join("\n"), { mode: 384 });
|
|
92
|
+
results.push({ file: relative(root, target), created, generated });
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
};
|
|
96
|
+
const describeEnvResult = (result) => {
|
|
97
|
+
const what = [
|
|
98
|
+
result.created && "created from .env.example",
|
|
99
|
+
result.generated.length && `generated ${result.generated.join(", ")}`
|
|
100
|
+
].filter(Boolean);
|
|
101
|
+
return `${result.file}: ${what.length ? what.join("; ") : "up to date, nothing changed"}`;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { BUILTIN_SECRETS as B, DEFAULT_ENV_DIRS as D, describeEnvResult as d, generateSecret as g, prepareEnv as p, resolveEnvConfig as r };
|