@react-consulting/rc-kit 0.0.0-stage → 0.13.0
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/LICENSE +21 -0
- package/README.md +94 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +212 -0
- package/devkit/lib/kit-migrate.ts +617 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { emitKeypressEvents } from "node:readline"
|
|
2
|
+
import type { ReadStream } from "node:tty"
|
|
3
|
+
|
|
4
|
+
import type { DevConfig } from "./config"
|
|
5
|
+
import { closureOf, devCompanions, devTargetNames, inOrder } from "./dev"
|
|
6
|
+
|
|
7
|
+
export interface MenuItem {
|
|
8
|
+
name: string
|
|
9
|
+
label: string
|
|
10
|
+
url?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MenuPreset {
|
|
14
|
+
name: string
|
|
15
|
+
targets: string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MenuModel {
|
|
19
|
+
title: string
|
|
20
|
+
items: MenuItem[]
|
|
21
|
+
presets: MenuPreset[]
|
|
22
|
+
companions: Record<string, string[]>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MenuState {
|
|
26
|
+
cursor: number
|
|
27
|
+
selected: string[]
|
|
28
|
+
message?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MenuKey {
|
|
32
|
+
name?: string
|
|
33
|
+
ctrl?: boolean
|
|
34
|
+
sequence?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MenuKeyResult {
|
|
38
|
+
state: MenuState
|
|
39
|
+
outcome?: "start" | "quit"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function menuModelOf(title: string, dev: DevConfig): MenuModel {
|
|
43
|
+
return {
|
|
44
|
+
title,
|
|
45
|
+
items: devTargetNames(dev).map((name) => ({
|
|
46
|
+
name,
|
|
47
|
+
label: dev.targets[name]?.label ?? name,
|
|
48
|
+
url: dev.targets[name]?.url,
|
|
49
|
+
})),
|
|
50
|
+
presets: Object.entries(dev.presets ?? {}).map(([name, targets]) => ({
|
|
51
|
+
name,
|
|
52
|
+
targets,
|
|
53
|
+
})),
|
|
54
|
+
companions: devCompanions(dev),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function order(model: MenuModel): string[] {
|
|
59
|
+
return model.items.map((item) => item.name)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function startedBy(
|
|
63
|
+
model: MenuModel,
|
|
64
|
+
selected: readonly string[]
|
|
65
|
+
): string[] {
|
|
66
|
+
return closureOf(order(model), model.companions, selected)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function withState(state: MenuState, changes: Partial<MenuState>): MenuState {
|
|
70
|
+
return { ...state, message: undefined, ...changes }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function toggleCurrent(model: MenuModel, state: MenuState): MenuState {
|
|
74
|
+
const name = model.items[state.cursor]?.name
|
|
75
|
+
|
|
76
|
+
if (!name) {
|
|
77
|
+
return state
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const selected = state.selected.includes(name)
|
|
81
|
+
? state.selected.filter((item) => item !== name)
|
|
82
|
+
: inOrder(order(model), [...state.selected, name])
|
|
83
|
+
|
|
84
|
+
return withState(state, { selected })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function toggleAll(model: MenuModel, state: MenuState): MenuState {
|
|
88
|
+
const everything = order(model)
|
|
89
|
+
const allSelected = everything.every((name) => state.selected.includes(name))
|
|
90
|
+
|
|
91
|
+
return withState(state, { selected: allSelected ? [] : everything })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function applyPreset(
|
|
95
|
+
model: MenuModel,
|
|
96
|
+
state: MenuState,
|
|
97
|
+
index: number
|
|
98
|
+
): MenuState {
|
|
99
|
+
const preset = model.presets[index]
|
|
100
|
+
|
|
101
|
+
if (!preset) {
|
|
102
|
+
return state
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return withState(state, { selected: inOrder(order(model), preset.targets) })
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function moveCursor(
|
|
109
|
+
model: MenuModel,
|
|
110
|
+
state: MenuState,
|
|
111
|
+
step: number
|
|
112
|
+
): MenuState {
|
|
113
|
+
const count = model.items.length
|
|
114
|
+
|
|
115
|
+
return withState(state, { cursor: (state.cursor + step + count) % count })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function reduceMenuKey(
|
|
119
|
+
model: MenuModel,
|
|
120
|
+
state: MenuState,
|
|
121
|
+
key: MenuKey
|
|
122
|
+
): MenuKeyResult {
|
|
123
|
+
if (
|
|
124
|
+
(key.ctrl && key.name === "c") ||
|
|
125
|
+
key.name === "q" ||
|
|
126
|
+
key.name === "escape"
|
|
127
|
+
) {
|
|
128
|
+
return { state, outcome: "quit" }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (key.name === "up") {
|
|
132
|
+
return { state: moveCursor(model, state, -1) }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (key.name === "down") {
|
|
136
|
+
return { state: moveCursor(model, state, 1) }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (key.name === "space") {
|
|
140
|
+
return { state: toggleCurrent(model, state) }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (key.name === "a") {
|
|
144
|
+
return { state: toggleAll(model, state) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (key.name === "return" || key.name === "enter") {
|
|
148
|
+
if (state.selected.length === 0) {
|
|
149
|
+
return {
|
|
150
|
+
state: withState(state, {
|
|
151
|
+
message: "Sélectionne au moins un service.",
|
|
152
|
+
}),
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { state, outcome: "start" }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (/^[1-9]$/.test(key.sequence ?? "")) {
|
|
160
|
+
return { state: applyPreset(model, state, Number(key.sequence) - 1) }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return { state }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const CODES = {
|
|
167
|
+
bold: "1",
|
|
168
|
+
dim: "2",
|
|
169
|
+
red: "31",
|
|
170
|
+
green: "32",
|
|
171
|
+
yellow: "33",
|
|
172
|
+
cyan: "36",
|
|
173
|
+
} as const
|
|
174
|
+
|
|
175
|
+
type Style = keyof typeof CODES
|
|
176
|
+
|
|
177
|
+
function paint(text: string, style: Style, color: boolean): string {
|
|
178
|
+
return color ? `\x1b[${CODES[style]}m${text}\x1b[0m` : text
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function itemRow(
|
|
182
|
+
item: MenuItem,
|
|
183
|
+
state: MenuState,
|
|
184
|
+
focused: boolean,
|
|
185
|
+
width: number,
|
|
186
|
+
color: boolean
|
|
187
|
+
): string {
|
|
188
|
+
const pointer = focused ? paint("❯", "cyan", color) : " "
|
|
189
|
+
const box = state.selected.includes(item.name)
|
|
190
|
+
? paint("◉", "green", color)
|
|
191
|
+
: paint("○", "dim", color)
|
|
192
|
+
const padded = item.label.padEnd(width)
|
|
193
|
+
const label = focused ? paint(padded, "bold", color) : padded
|
|
194
|
+
const url = item.url ? paint(item.url, "dim", color) : ""
|
|
195
|
+
|
|
196
|
+
return ` ${pointer} ${box} ${label} ${paint(item.name, "dim", color)} ${url}`.trimEnd()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function presetLine(model: MenuModel, color: boolean): string {
|
|
200
|
+
if (model.presets.length === 0) {
|
|
201
|
+
return ` ${paint("Préréglages", "dim", color)} ${paint("aucun", "dim", color)}`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const separator = paint(" · ", "dim", color)
|
|
205
|
+
const presets = model.presets.map(
|
|
206
|
+
(preset, index) =>
|
|
207
|
+
`${paint(String(index + 1), "bold", color)} ${preset.name}`
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return ` ${paint("Préréglages", "dim", color)} ${presets.join(separator)}`
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function summaryLine(
|
|
214
|
+
model: MenuModel,
|
|
215
|
+
state: MenuState,
|
|
216
|
+
color: boolean
|
|
217
|
+
): string {
|
|
218
|
+
if (state.selected.length === 0) {
|
|
219
|
+
return ` ${paint("Aucun service sélectionné.", "yellow", color)}`
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const started = startedBy(model, state.selected)
|
|
223
|
+
const extra = started.filter((name) => !state.selected.includes(name))
|
|
224
|
+
const count = paint(
|
|
225
|
+
`${started.length} service${started.length > 1 ? "s" : ""}`,
|
|
226
|
+
"bold",
|
|
227
|
+
color
|
|
228
|
+
)
|
|
229
|
+
const also = extra.length > 0 ? ` · démarrent aussi ${extra.join(", ")}` : ""
|
|
230
|
+
|
|
231
|
+
return ` ${count}${also}`
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const HINTS =
|
|
235
|
+
"↑↓ déplacer · espace cocher · a tout · 1-9 préréglage · entrée lancer · q quitter"
|
|
236
|
+
|
|
237
|
+
export function renderDevMenu(
|
|
238
|
+
model: MenuModel,
|
|
239
|
+
state: MenuState,
|
|
240
|
+
color: boolean
|
|
241
|
+
): string[] {
|
|
242
|
+
const width = Math.max(...model.items.map((item) => item.label.length))
|
|
243
|
+
const rows = model.items.map((item, index) =>
|
|
244
|
+
itemRow(item, state, index === state.cursor, width, color)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
return [
|
|
248
|
+
` ${paint(model.title, "bold", color)}`,
|
|
249
|
+
"",
|
|
250
|
+
` ${paint("Services", "dim", color)}`,
|
|
251
|
+
...rows,
|
|
252
|
+
"",
|
|
253
|
+
presetLine(model, color),
|
|
254
|
+
"",
|
|
255
|
+
summaryLine(model, state, color),
|
|
256
|
+
state.message
|
|
257
|
+
? ` ${paint(state.message, "red", color)}`
|
|
258
|
+
: ` ${paint(HINTS, "dim", color)}`,
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const HIDE_CURSOR = "\x1b[?25l"
|
|
263
|
+
const SHOW_CURSOR = "\x1b[?25h"
|
|
264
|
+
|
|
265
|
+
function eraseLines(count: number): string {
|
|
266
|
+
return count > 0 ? `\x1b[${count}A\x1b[J` : ""
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface DevMenuOptions {
|
|
270
|
+
model: MenuModel
|
|
271
|
+
initialSelected: string[]
|
|
272
|
+
input?: ReadStream
|
|
273
|
+
output?: NodeJS.WriteStream
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function runDevMenu(
|
|
277
|
+
options: DevMenuOptions
|
|
278
|
+
): Promise<string[] | undefined> {
|
|
279
|
+
const input = options.input ?? (process.stdin as ReadStream)
|
|
280
|
+
const output = options.output ?? process.stdout
|
|
281
|
+
const color = Boolean(output.isTTY) && !process.env.NO_COLOR
|
|
282
|
+
|
|
283
|
+
return new Promise((resolve) => {
|
|
284
|
+
let state: MenuState = { cursor: 0, selected: options.initialSelected }
|
|
285
|
+
let drawnLines = 0
|
|
286
|
+
|
|
287
|
+
function draw(): void {
|
|
288
|
+
const lines = renderDevMenu(options.model, state, color)
|
|
289
|
+
|
|
290
|
+
output.write(`${eraseLines(drawnLines)}${lines.join("\n")}\n`)
|
|
291
|
+
drawnLines = lines.length
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function finish(selected: string[] | undefined): void {
|
|
295
|
+
input.off("keypress", onKeypress)
|
|
296
|
+
input.setRawMode(false)
|
|
297
|
+
input.pause()
|
|
298
|
+
output.write(`${eraseLines(drawnLines)}${SHOW_CURSOR}`)
|
|
299
|
+
resolve(selected)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function onKeypress(sequence: string, key: MenuKey | undefined): void {
|
|
303
|
+
const result = reduceMenuKey(options.model, state, {
|
|
304
|
+
...key,
|
|
305
|
+
sequence: key?.sequence ?? sequence,
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
state = result.state
|
|
309
|
+
|
|
310
|
+
if (result.outcome === "start") {
|
|
311
|
+
finish(inOrder(order(options.model), state.selected))
|
|
312
|
+
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (result.outcome === "quit") {
|
|
317
|
+
finish(undefined)
|
|
318
|
+
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
draw()
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
emitKeypressEvents(input)
|
|
326
|
+
input.setRawMode(true)
|
|
327
|
+
input.resume()
|
|
328
|
+
input.on("keypress", onKeypress)
|
|
329
|
+
output.write(HIDE_CURSOR)
|
|
330
|
+
draw()
|
|
331
|
+
})
|
|
332
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test"
|
|
2
|
+
import { readFileSync, writeFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
|
|
5
|
+
import type { LoadedConfig } from "./config"
|
|
6
|
+
import { syncDevSecrets } from "./dev-secrets"
|
|
7
|
+
import { cleanupTempDirs, fakeRunner, tempDir, writeTree } from "./test-utils"
|
|
8
|
+
|
|
9
|
+
afterAll(cleanupTempDirs)
|
|
10
|
+
|
|
11
|
+
const PROJECT_ID = "22222222-2222-4222-8222-222222222222"
|
|
12
|
+
|
|
13
|
+
const EXPORT = JSON.stringify([
|
|
14
|
+
{ key: "TURNSTILE_SECRET_KEY", value: "fake-turnstile-secret" },
|
|
15
|
+
{ key: "PUBLIC_TURNSTILE_SITE_KEY", value: "fake-turnstile-site" },
|
|
16
|
+
{ key: "WHATSAPP_ACCESS_TOKEN", value: "" },
|
|
17
|
+
{ key: "not a key", value: "ignored" },
|
|
18
|
+
{ key: "MULTILINE", value: "a\nb" },
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
function infisicalRunner(secrets = EXPORT) {
|
|
22
|
+
return fakeRunner((command) => {
|
|
23
|
+
if (command[1] === "--version") {
|
|
24
|
+
return { stdout: "0.45.4" }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (command[1] === "export") {
|
|
28
|
+
return { stdout: secrets }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { exitCode: 1 }
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function project(
|
|
36
|
+
devEnvFiles: NonNullable<LoadedConfig["config"]["devEnvFiles"]>
|
|
37
|
+
): LoadedConfig {
|
|
38
|
+
const root = writeTree(tempDir(), {
|
|
39
|
+
"apps/admin/.dev.vars": "# local\nTURNSTILE_SECRET_KEY=old\nMINE=kept\n",
|
|
40
|
+
"apps/web/package.json": "{}",
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
root,
|
|
45
|
+
configPath: join(root, "rc.config.json"),
|
|
46
|
+
config: {
|
|
47
|
+
project: "fabrikam-motors",
|
|
48
|
+
prefix: "adv",
|
|
49
|
+
account: "contoso",
|
|
50
|
+
apps: { admin: { path: "apps/admin" } },
|
|
51
|
+
infisical: { projectId: PROJECT_ID },
|
|
52
|
+
devEnvFiles,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("syncDevSecrets", () => {
|
|
58
|
+
test("merges the dev environment into each file, filtered, and generates machine secrets", () => {
|
|
59
|
+
const loaded = project([
|
|
60
|
+
{
|
|
61
|
+
path: "apps/admin/.dev.vars",
|
|
62
|
+
exclude: ["PUBLIC_*"],
|
|
63
|
+
generate: ["BETTER_AUTH_SECRET"],
|
|
64
|
+
},
|
|
65
|
+
{ path: "apps/web/.env", include: ["PUBLIC_*"] },
|
|
66
|
+
{ path: "apps/missing/.env" },
|
|
67
|
+
])
|
|
68
|
+
const lines: string[] = []
|
|
69
|
+
const results = syncDevSecrets({
|
|
70
|
+
loaded,
|
|
71
|
+
runner: infisicalRunner().runner,
|
|
72
|
+
env: {},
|
|
73
|
+
log: (line) => lines.push(line),
|
|
74
|
+
generateSecret: () => "generated",
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
expect(
|
|
78
|
+
readFileSync(join(loaded.root, "apps/admin/.dev.vars"), "utf8")
|
|
79
|
+
).toBe(
|
|
80
|
+
'# local\nTURNSTILE_SECRET_KEY="fake-turnstile-secret"\nMINE=kept\nBETTER_AUTH_SECRET="generated"\n'
|
|
81
|
+
)
|
|
82
|
+
expect(readFileSync(join(loaded.root, "apps/web/.env"), "utf8")).toBe(
|
|
83
|
+
'PUBLIC_TURNSTILE_SITE_KEY="fake-turnstile-site"\n'
|
|
84
|
+
)
|
|
85
|
+
expect(
|
|
86
|
+
results.map((result) => [result.path, result.synced, result.generated])
|
|
87
|
+
).toEqual([
|
|
88
|
+
["apps/admin/.dev.vars", 1, 1],
|
|
89
|
+
["apps/web/.env", 1, 0],
|
|
90
|
+
])
|
|
91
|
+
expect(lines.join("\n")).toContain("MULTILINE ignorée")
|
|
92
|
+
expect(lines.join("\n")).toContain("apps/missing/.env ignoré")
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test("never regenerates a machine secret that already has a value", () => {
|
|
96
|
+
const loaded = project([
|
|
97
|
+
{ path: "apps/admin/.dev.vars", generate: ["MINE"] },
|
|
98
|
+
])
|
|
99
|
+
|
|
100
|
+
syncDevSecrets({
|
|
101
|
+
loaded,
|
|
102
|
+
runner: infisicalRunner().runner,
|
|
103
|
+
env: {},
|
|
104
|
+
log: () => {},
|
|
105
|
+
generateSecret: () => "new",
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(
|
|
109
|
+
readFileSync(join(loaded.root, "apps/admin/.dev.vars"), "utf8")
|
|
110
|
+
).toContain("MINE=kept")
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test("leaves the files alone without the Infisical CLI, but still generates", () => {
|
|
114
|
+
const loaded = project([
|
|
115
|
+
{ path: "apps/admin/.dev.vars", generate: ["BETTER_AUTH_SECRET"] },
|
|
116
|
+
{ path: "apps/web/.env" },
|
|
117
|
+
])
|
|
118
|
+
const lines: string[] = []
|
|
119
|
+
|
|
120
|
+
syncDevSecrets({
|
|
121
|
+
loaded,
|
|
122
|
+
runner: fakeRunner(() => ({ exitCode: 127 })).runner,
|
|
123
|
+
env: {},
|
|
124
|
+
log: (line) => lines.push(line),
|
|
125
|
+
generateSecret: () => "generated",
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
expect(
|
|
129
|
+
readFileSync(join(loaded.root, "apps/admin/.dev.vars"), "utf8")
|
|
130
|
+
).toBe(
|
|
131
|
+
'# local\nTURNSTILE_SECRET_KEY=old\nMINE=kept\nBETTER_AUTH_SECRET="generated"\n'
|
|
132
|
+
)
|
|
133
|
+
expect(() => readFileSync(join(loaded.root, "apps/web/.env"))).toThrow()
|
|
134
|
+
expect(lines[0]).toContain("introuvable")
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test("reads the dev environment, overridable per machine", () => {
|
|
138
|
+
const loaded = project([{ path: "apps/admin/.dev.vars" }])
|
|
139
|
+
const { runner, calls } = infisicalRunner()
|
|
140
|
+
|
|
141
|
+
writeFileSync(join(loaded.root, "apps/admin/.dev.vars"), "")
|
|
142
|
+
syncDevSecrets({
|
|
143
|
+
loaded,
|
|
144
|
+
runner,
|
|
145
|
+
env: { INFISICAL_PROJECT_ID: "33333333-3333-4333-8333-333333333333" },
|
|
146
|
+
log: () => {},
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
expect(calls[1]?.command.slice(2, 6)).toEqual([
|
|
150
|
+
"--projectId",
|
|
151
|
+
"33333333-3333-4333-8333-333333333333",
|
|
152
|
+
"--env",
|
|
153
|
+
"dev",
|
|
154
|
+
])
|
|
155
|
+
})
|
|
156
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto"
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs"
|
|
3
|
+
import { dirname, resolve } from "node:path"
|
|
4
|
+
|
|
5
|
+
import { type LoadedConfig, infisicalTarget } from "./config"
|
|
6
|
+
import { applyEnvValues, isWritableEnvValue, parseEnvFile } from "./env-file"
|
|
7
|
+
import { filterKeys } from "./glob"
|
|
8
|
+
import { readProjectSecrets } from "./infisical"
|
|
9
|
+
import { type Runner, runCommand } from "./process"
|
|
10
|
+
|
|
11
|
+
export interface SyncInput {
|
|
12
|
+
loaded: LoadedConfig
|
|
13
|
+
runner?: Runner
|
|
14
|
+
env?: Record<string, string | undefined>
|
|
15
|
+
log?: (line: string) => void
|
|
16
|
+
generateSecret?: () => string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SyncedFile {
|
|
20
|
+
path: string
|
|
21
|
+
synced: number
|
|
22
|
+
generated: number
|
|
23
|
+
changed: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function randomSecret(): string {
|
|
27
|
+
return randomBytes(32).toString("base64")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function syncDevSecrets(input: SyncInput): SyncedFile[] {
|
|
31
|
+
const log = input.log ?? console.log
|
|
32
|
+
const { config, root } = input.loaded
|
|
33
|
+
const files = config.devEnvFiles ?? []
|
|
34
|
+
|
|
35
|
+
if (files.length === 0) {
|
|
36
|
+
log("Infisical : aucun devEnvFiles dans rc.config.json, rien à écrire.")
|
|
37
|
+
return []
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const target = infisicalTarget(config, "dev", input.env)
|
|
41
|
+
const secrets = readProjectSecrets(target, root, input.runner ?? runCommand)
|
|
42
|
+
const values: Record<string, string> = {}
|
|
43
|
+
|
|
44
|
+
if (secrets.ok) {
|
|
45
|
+
for (const [key, value] of Object.entries(secrets.values)) {
|
|
46
|
+
if (isWritableEnvValue(value)) {
|
|
47
|
+
values[key] = value
|
|
48
|
+
} else {
|
|
49
|
+
log(
|
|
50
|
+
`Infisical : ${key} ignorée, sa valeur tient sur plusieurs lignes ou mélange tous les guillemets.`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
log(
|
|
56
|
+
`Infisical : ${secrets.reason}\n Les fichiers existants restent tels quels.`
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return files.flatMap((file) => {
|
|
61
|
+
const path = resolve(root, file.path)
|
|
62
|
+
|
|
63
|
+
if (!existsSync(dirname(path))) {
|
|
64
|
+
log(`Infisical : ${file.path} ignoré, le dossier n'existe pas.`)
|
|
65
|
+
return []
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const before = existsSync(path) ? readFileSync(path, "utf8") : ""
|
|
69
|
+
const synced = filterKeys(values, file.include, file.exclude)
|
|
70
|
+
const current = parseEnvFile(before)
|
|
71
|
+
const missing = (file.generate ?? []).filter(
|
|
72
|
+
(key) => !(synced[key] || current.get(key))
|
|
73
|
+
)
|
|
74
|
+
const generated = Object.fromEntries(
|
|
75
|
+
missing.map((key) => [key, (input.generateSecret ?? randomSecret)()])
|
|
76
|
+
)
|
|
77
|
+
const after = applyEnvValues(
|
|
78
|
+
applyEnvValues(before, synced),
|
|
79
|
+
generated,
|
|
80
|
+
true
|
|
81
|
+
)
|
|
82
|
+
const changed = after !== before
|
|
83
|
+
|
|
84
|
+
if (changed) {
|
|
85
|
+
writeFileSync(path, after)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
path: file.path,
|
|
91
|
+
synced: Object.keys(synced).length,
|
|
92
|
+
generated: missing.length,
|
|
93
|
+
changed,
|
|
94
|
+
},
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
}
|