inlaycms 0.0.0-stage → 0.2.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 +469 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { parseArgs, promisify } from 'node:util';
|
|
9
|
+
import { sql } from 'kysely';
|
|
10
|
+
import { bootInlay, isFresh } from '../../core/boot.js';
|
|
11
|
+
import { systemCtx } from '../../core/auth/roles.js';
|
|
12
|
+
import { createBackup } from '../../core/backup/backup.js';
|
|
13
|
+
import { databaseInUse, restoreBackup } from '../../core/backup/restore.js';
|
|
14
|
+
import { checkBundle, checkDatabase, checkWithoutDatabase } from '../../core/check.js';
|
|
15
|
+
import { openDatabase } from '../../core/db/connection.js';
|
|
16
|
+
import { migrateSystem, pendingSystemMigrations } from '../../core/db/migrate.js';
|
|
17
|
+
import { createCore } from '../../core/core.js';
|
|
18
|
+
import { dryRunImport } from '../../core/export/import.js';
|
|
19
|
+
import { exportFileName } from '../../core/export/format.js';
|
|
20
|
+
import { formatImportReport } from '../../core/export/report.js';
|
|
21
|
+
import { InlayError } from '../../core/errors.js';
|
|
22
|
+
import { t } from '../../core/messages/index.js';
|
|
23
|
+
import { formatReport } from '../../core/report.js';
|
|
24
|
+
import { buildRegistry } from '../../core/registry/registry.js';
|
|
25
|
+
import { generateKeyPair, publicKeyOf } from '../../core/release/keys.js';
|
|
26
|
+
import { packRelease, releaseName } from '../../core/release/pack.js';
|
|
27
|
+
import { loadRelease } from '../../core/release/read.js';
|
|
28
|
+
import { loadConfig } from '../../config.js';
|
|
29
|
+
import { activateRelease } from '../../host/activate.js';
|
|
30
|
+
import { EMPTY_SITE } from '../../host/app.js';
|
|
31
|
+
import { ensureDataDir, hostPaths, readDataDir, readHostConfig, readTrustedKeys } from '../../host/config.js';
|
|
32
|
+
import { dev } from '../../host/dev.js';
|
|
33
|
+
import { formatDiff } from '../../host/diff.js';
|
|
34
|
+
import { serve } from '../../host/serve.js';
|
|
35
|
+
import { currentRelease, getRelease, listReleases, releaseDir, storeRelease } from '../../host/store.js';
|
|
36
|
+
import { activateRemote, checkTransport, isRemote, listRemoteReleases, pushFile } from './remote.js';
|
|
37
|
+
function usage(io) {
|
|
38
|
+
for (const line of t('cli.usage').split('\n'))
|
|
39
|
+
io.err(line);
|
|
40
|
+
return 2;
|
|
41
|
+
}
|
|
42
|
+
function findConfig(io, explicit) {
|
|
43
|
+
if (explicit)
|
|
44
|
+
return resolve(io.cwd, explicit);
|
|
45
|
+
for (const name of ['inlay.config.ts', 'inlay.config.js', 'inlay.config.mjs']) {
|
|
46
|
+
const candidate = join(io.cwd, name);
|
|
47
|
+
if (existsSync(candidate))
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
throw new InlayError('not_found', 'error.configMissing', { path: join(io.cwd, 'inlay.config.ts') });
|
|
51
|
+
}
|
|
52
|
+
/** Config and database errors exit 2; exit 1 is reserved for a check that found problems. */
|
|
53
|
+
function fail(io, e, id, path) {
|
|
54
|
+
if (e instanceof InlayError)
|
|
55
|
+
io.err(e.message);
|
|
56
|
+
else
|
|
57
|
+
io.err(t(id, { path, error: e instanceof Error ? e.message : String(e) }));
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
async function keygen(io, outDir, name) {
|
|
61
|
+
const dir = resolve(io.cwd, outDir ?? '.');
|
|
62
|
+
const keyFile = join(dir, `${name}.key`);
|
|
63
|
+
const pubFile = join(dir, `${name}.pub`);
|
|
64
|
+
for (const path of [keyFile, pubFile]) {
|
|
65
|
+
if (existsSync(path)) {
|
|
66
|
+
io.err(t('cli.keygenExists', { path }));
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const { privateKey, publicKey } = generateKeyPair();
|
|
71
|
+
await mkdir(dir, { recursive: true });
|
|
72
|
+
try {
|
|
73
|
+
await writeFile(keyFile, privateKey, { mode: 0o600, flag: 'wx' });
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
if (e.code === 'EEXIST') {
|
|
77
|
+
io.err(t('cli.keygenExists', { path: keyFile }));
|
|
78
|
+
return 2;
|
|
79
|
+
}
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await writeFile(pubFile, publicKey + '\n', { flag: 'wx' });
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
if (e.code === 'EEXIST') {
|
|
87
|
+
io.err(t('cli.keygenExists', { path: pubFile }));
|
|
88
|
+
return 2;
|
|
89
|
+
}
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
for (const line of t('cli.keygenDone', { key: keyFile, pub: pubFile, publicKey }).split('\n'))
|
|
93
|
+
io.out(line);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
async function createOwner(io, target, email, name) {
|
|
97
|
+
if (!io.readSecret) {
|
|
98
|
+
io.err(t('cli.noSecretInput'));
|
|
99
|
+
return 2;
|
|
100
|
+
}
|
|
101
|
+
const password = await io.readSecret(t('cli.passwordPrompt'));
|
|
102
|
+
const { db, auth } = await bootInlay({
|
|
103
|
+
site: target.site,
|
|
104
|
+
db: target.db,
|
|
105
|
+
backups: target.backups,
|
|
106
|
+
...(target.media !== undefined && { media: target.media }),
|
|
107
|
+
...(target.content && { content: target.content }),
|
|
108
|
+
auth: { secret: randomBytes(32).toString('hex'), baseUrl: 'http://localhost' },
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
await auth.createOwner({ email, name, password });
|
|
112
|
+
io.out(t('cli.ownerCreated', { email }));
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (e instanceof InlayError && (e.code === 'validation' || e.code === 'invalid_operation')) {
|
|
117
|
+
io.err(e.message);
|
|
118
|
+
const issues = e.details.issues ?? [];
|
|
119
|
+
for (const issue of issues)
|
|
120
|
+
io.err(issue.message);
|
|
121
|
+
return 1;
|
|
122
|
+
}
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await db.destroy();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function printImportReport(io, report, json) {
|
|
130
|
+
if (json)
|
|
131
|
+
io.out(JSON.stringify(report, null, 2));
|
|
132
|
+
else
|
|
133
|
+
for (const line of formatImportReport(report))
|
|
134
|
+
io.out(line);
|
|
135
|
+
return report.ok ? 0 : 1;
|
|
136
|
+
}
|
|
137
|
+
async function importFile(io, target, file, flags) {
|
|
138
|
+
const dbPath = target.db;
|
|
139
|
+
if (!existsSync(dbPath))
|
|
140
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: dbPath });
|
|
141
|
+
if (!flags.serverStopped && (await databaseInUse(dbPath))) {
|
|
142
|
+
throw new InlayError('invalid_operation', 'error.databaseInUse', { path: dbPath });
|
|
143
|
+
}
|
|
144
|
+
const { db, core } = await bootInlay({
|
|
145
|
+
site: target.site,
|
|
146
|
+
db: dbPath,
|
|
147
|
+
backups: target.backups,
|
|
148
|
+
...(target.media !== undefined && { media: target.media }),
|
|
149
|
+
...(target.content && { content: target.content }),
|
|
150
|
+
});
|
|
151
|
+
try {
|
|
152
|
+
const result = await core.importContent(file, systemCtx('import'));
|
|
153
|
+
for (const line of formatImportReport(result.report))
|
|
154
|
+
io.out(line);
|
|
155
|
+
io.out(t('cli.imported', { file, backup: result.backup.path }));
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
if (e instanceof InlayError && e.code === 'check_failed' && e.details.importReport) {
|
|
160
|
+
for (const line of formatImportReport(e.details.importReport))
|
|
161
|
+
io.out(line);
|
|
162
|
+
io.err(e.message);
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
await db.destroy();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** The private key in PEM form: `--key` names a file; `INLAY_SIGNING_KEY` holds the key itself or a path to it. */
|
|
172
|
+
async function signingKey(io, flag) {
|
|
173
|
+
const env = process.env.INLAY_SIGNING_KEY?.trim();
|
|
174
|
+
if (!flag && !env) {
|
|
175
|
+
io.err(t('cli.packKey'));
|
|
176
|
+
return 2;
|
|
177
|
+
}
|
|
178
|
+
const path = flag ? resolve(io.cwd, flag) : env.includes('PRIVATE KEY') ? null : resolve(io.cwd, env);
|
|
179
|
+
try {
|
|
180
|
+
const pem = path === null ? env : await readFile(path, 'utf8');
|
|
181
|
+
publicKeyOf(pem);
|
|
182
|
+
return pem;
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
io.err(t('cli.packKeyUnreadable', { path: path ?? 'INLAY_SIGNING_KEY', error: e instanceof Error ? e.message : String(e) }));
|
|
186
|
+
return 2;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The JS file of the site's own `tsc`: the `typescript` package Node finds from `dir`, by its `bin` entry. Run with
|
|
191
|
+
* this Node rather than as `node_modules/.bin/tsc`, which is a symlink, a shell script or a `.cmd` file depending on
|
|
192
|
+
* the package manager and the system, and needs `/usr/bin/env node` to start.
|
|
193
|
+
*/
|
|
194
|
+
function findTsc(dir) {
|
|
195
|
+
try {
|
|
196
|
+
const pkg = createRequire(join(dir, 'inlay.config.js')).resolve('typescript/package.json');
|
|
197
|
+
const { bin } = JSON.parse(readFileSync(pkg, 'utf8'));
|
|
198
|
+
const tsc = typeof bin === 'string' ? bin : bin?.tsc;
|
|
199
|
+
return tsc === undefined ? null : join(dirname(pkg), tsc);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Type-checks the site in `dir` (unless `typecheck` is false or it has no tsconfig.json) and packs it into a release
|
|
207
|
+
* file at `out`. Answers the exit code when that failed, having said why.
|
|
208
|
+
*/
|
|
209
|
+
async function packTo(io, file, dir, values) {
|
|
210
|
+
const tsc = values.typecheck && existsSync(join(dir, 'tsconfig.json')) ? findTsc(dir) : null;
|
|
211
|
+
if (tsc !== null) {
|
|
212
|
+
try {
|
|
213
|
+
await promisify(execFile)(process.execPath, [tsc, '--noEmit', '-p', dir], { cwd: dir });
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
const { stdout, stderr } = e;
|
|
217
|
+
for (const line of `${stdout ?? ''}${stderr ?? ''}`.split('\n'))
|
|
218
|
+
if (line.trim() !== '')
|
|
219
|
+
io.err(line);
|
|
220
|
+
io.err(t('cli.packTypecheck'));
|
|
221
|
+
return 1;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const { manifest } = await packRelease({ configFile: file, privateKey: values.privateKey, out: values.out, name: values.name });
|
|
226
|
+
return { files: Object.keys(manifest.files).length };
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
if (e instanceof InlayError && e.code === 'release') {
|
|
230
|
+
io.err(e.message);
|
|
231
|
+
return 1;
|
|
232
|
+
}
|
|
233
|
+
return fail(io, e, 'cli.configFailed', file);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function pack(io, file, dir, values) {
|
|
237
|
+
const privateKey = await signingKey(io, values.key);
|
|
238
|
+
if (typeof privateKey === 'number')
|
|
239
|
+
return privateKey;
|
|
240
|
+
const name = values.name ?? (await releaseName(dir, new Date()));
|
|
241
|
+
const out = values.out ? resolve(io.cwd, values.out) : join(io.cwd, `${name}.tgz`);
|
|
242
|
+
const packed = await packTo(io, file, dir, { privateKey, out, name, typecheck: values.typecheck });
|
|
243
|
+
if (typeof packed === 'number')
|
|
244
|
+
return packed;
|
|
245
|
+
io.out(t('cli.packDone', { out, name, files: packed.files }));
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
/** The host's settings for `activate` and `releases`: the `INLAY_` variables, with `--data` for INLAY_DATA_DIR. */
|
|
249
|
+
function hostConfig(io, data, needKeys) {
|
|
250
|
+
const env = data === undefined ? process.env : { ...process.env, INLAY_DATA_DIR: resolve(io.cwd, data) };
|
|
251
|
+
return readHostConfig(env, { needKeys });
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Makes a release live without the server (Review Focus 5: refused while the database is open, since a running
|
|
255
|
+
* worker wouldn't see the swap). A file is stored first; anything else names a stored release by its ID.
|
|
256
|
+
*/
|
|
257
|
+
async function activate(io, arg, flags) {
|
|
258
|
+
const config = hostConfig(io, flags.data, true);
|
|
259
|
+
const { paths } = config;
|
|
260
|
+
if (!flags.serverStopped && (await databaseInUse(paths.db))) {
|
|
261
|
+
io.err(t('cli.serverRunning', { path: paths.db }));
|
|
262
|
+
return 2;
|
|
263
|
+
}
|
|
264
|
+
await ensureDataDir(config);
|
|
265
|
+
const db = openDatabase(paths.db);
|
|
266
|
+
try {
|
|
267
|
+
const systemMigrations = await pendingSystemMigrations(db);
|
|
268
|
+
// As boot does: a database that is updated first gets a backup first.
|
|
269
|
+
if (systemMigrations.length > 0 && !(await isFresh(db))) {
|
|
270
|
+
const backup = await createBackup({
|
|
271
|
+
db,
|
|
272
|
+
backups: paths.backups,
|
|
273
|
+
media: paths.media,
|
|
274
|
+
reason: 'pre-migration',
|
|
275
|
+
ctx: systemCtx('system'),
|
|
276
|
+
});
|
|
277
|
+
io.out(t('cli.backupCreated', { path: backup.path }));
|
|
278
|
+
}
|
|
279
|
+
await migrateSystem(db);
|
|
280
|
+
const file = resolve(io.cwd, arg);
|
|
281
|
+
let id;
|
|
282
|
+
if (await stat(file).then((s) => s.isFile(), () => false)) {
|
|
283
|
+
const stored = await storeRelease({ db, releasesDir: paths.releases, trustedKeys: config.trustedKeys, now: () => new Date() }, file, { pushedBy: null, ...(flags.name !== undefined && { name: flags.name }) });
|
|
284
|
+
io.out(t('cli.activateStored', { name: stored.name, id: stored.id }));
|
|
285
|
+
id = stored.id;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
if (flags.name !== undefined) {
|
|
289
|
+
io.err(t('cli.activateName'));
|
|
290
|
+
return 2;
|
|
291
|
+
}
|
|
292
|
+
const row = await getRelease(db, arg);
|
|
293
|
+
if (row === null) {
|
|
294
|
+
io.err(t('cli.activateNotFound', { path: file, id: arg }));
|
|
295
|
+
return 2;
|
|
296
|
+
}
|
|
297
|
+
// Its folder is gone, so say so before trying to load it.
|
|
298
|
+
if (row.state === 'deleted')
|
|
299
|
+
throw new InlayError('release', 'error.releaseDeleted', { name: row.name });
|
|
300
|
+
id = row.id;
|
|
301
|
+
}
|
|
302
|
+
const result = await activateRelease({
|
|
303
|
+
db,
|
|
304
|
+
loaded: await loadRelease(releaseDir(paths.releases, id)),
|
|
305
|
+
releasesDir: paths.releases,
|
|
306
|
+
backupsDir: paths.backups,
|
|
307
|
+
mediaDir: paths.media,
|
|
308
|
+
secretsEnv: config.secrets,
|
|
309
|
+
now: () => new Date(),
|
|
310
|
+
}, id);
|
|
311
|
+
if (result.pointerError !== null)
|
|
312
|
+
io.err(t('host.pointerWriteFailed', { name: result.release.name, problem: result.pointerError }));
|
|
313
|
+
if (result.noop) {
|
|
314
|
+
io.out(t('cli.activateNoop', { name: result.release.name }));
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
if (result.backup)
|
|
318
|
+
io.out(t('cli.activateBackup', { path: result.backup.path }));
|
|
319
|
+
for (const line of formatReport({ ok: true, systemMigrations, shipped: result.shipped, problems: [], warnings: [] })) {
|
|
320
|
+
io.out(line);
|
|
321
|
+
}
|
|
322
|
+
if (result.migrations.length > 0)
|
|
323
|
+
io.out(t('cli.activateMigrations', { names: result.migrations.join(', ') }));
|
|
324
|
+
io.out(t('cli.activated', { name: result.release.name }));
|
|
325
|
+
return 0;
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
await db.destroy();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async function hasReleasesTable(db) {
|
|
332
|
+
const { rows } = await sql `SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'releases'`.execute(db);
|
|
333
|
+
return rows.length > 0;
|
|
334
|
+
}
|
|
335
|
+
/** The data folder of a host: `--data`, or INLAY_DATA_DIR. */
|
|
336
|
+
function dataDir(io, data) {
|
|
337
|
+
return resolve(io.cwd, data ?? readDataDir(process.env));
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Lists the releases on the host, newest first. Only reads, so it works with the server running, and needs only
|
|
341
|
+
* the data folder.
|
|
342
|
+
*/
|
|
343
|
+
async function releases(io, flags) {
|
|
344
|
+
const paths = hostPaths(dataDir(io, flags.data));
|
|
345
|
+
let rows = [];
|
|
346
|
+
if (existsSync(paths.db)) {
|
|
347
|
+
// Not read-only: a read-only connection can't remove the write-ahead log when it closes, and the database would
|
|
348
|
+
// then look in use to `activate`. It only reads, and leaves the log alone while the server has it open.
|
|
349
|
+
const db = openDatabase(paths.db);
|
|
350
|
+
try {
|
|
351
|
+
if (await hasReleasesTable(db))
|
|
352
|
+
rows = await listReleases(db);
|
|
353
|
+
}
|
|
354
|
+
finally {
|
|
355
|
+
await db.destroy();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
printReleases(io, rows, flags.json);
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
function printReleases(io, rows, json) {
|
|
362
|
+
const listed = rows.map((r) => ({ id: r.id, name: r.name, state: r.state, pushedAt: r.pushed_at, activatedAt: r.activated_at }));
|
|
363
|
+
if (json)
|
|
364
|
+
return io.out(JSON.stringify(listed, null, 2));
|
|
365
|
+
if (listed.length === 0)
|
|
366
|
+
io.out(t('cli.releasesNone'));
|
|
367
|
+
for (const r of listed) {
|
|
368
|
+
io.out(t('cli.releaseLine', {
|
|
369
|
+
id: r.id,
|
|
370
|
+
name: r.name,
|
|
371
|
+
state: t(`cli.releaseState.${r.state}`),
|
|
372
|
+
pushedAt: r.pushedAt,
|
|
373
|
+
activatedAt: r.activatedAt ?? t('cli.releaseNeverLive'),
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/** The push token: `--token`, or INLAY_PUSH_TOKEN. Answers exit code 2, having said so, when there is neither. */
|
|
378
|
+
function pushToken(io, flag) {
|
|
379
|
+
const token = (flag ?? process.env.INLAY_PUSH_TOKEN ?? '').trim();
|
|
380
|
+
if (token !== '')
|
|
381
|
+
return token;
|
|
382
|
+
io.err(t('cli.pushToken'));
|
|
383
|
+
return 2;
|
|
384
|
+
}
|
|
385
|
+
/** What making a release live on the server did, as the offline `activate` says it. */
|
|
386
|
+
function printActivation(io, name, a) {
|
|
387
|
+
if (a.noop)
|
|
388
|
+
return io.out(t('cli.activateNoop', { name }));
|
|
389
|
+
if (a.backup !== null)
|
|
390
|
+
io.out(t('cli.activateBackup', { path: a.backup }));
|
|
391
|
+
if (a.shipped.created > 0)
|
|
392
|
+
io.out(t('report.shippedCreated', { count: a.shipped.created }));
|
|
393
|
+
if (a.shipped.replaced > 0)
|
|
394
|
+
io.out(t('report.shippedReplaced', { count: a.shipped.replaced }));
|
|
395
|
+
if (a.shipped.skipped > 0)
|
|
396
|
+
io.out(t('report.shippedSkipped', { count: a.shipped.skipped }));
|
|
397
|
+
if (a.warnings > 0)
|
|
398
|
+
io.out(t('cli.activationWarnings', { count: a.warnings }));
|
|
399
|
+
if (a.migrations.length > 0)
|
|
400
|
+
io.out(t('cli.activateMigrations', { names: a.migrations.join(', ') }));
|
|
401
|
+
io.out(t('cli.activated', { name }));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* A server that refused, or couldn't be reached, exits 1 with its message (2 for a usage problem, such as plain http);
|
|
405
|
+
* anything else exits 1 with `error.remoteUnexpected`, never a stack trace.
|
|
406
|
+
*/
|
|
407
|
+
function remoteFailed(io, host, e) {
|
|
408
|
+
if (e instanceof InlayError) {
|
|
409
|
+
io.err(e.message);
|
|
410
|
+
return e.code === 'config' ? 2 : 1;
|
|
411
|
+
}
|
|
412
|
+
io.err(t('error.remoteUnexpected', { host, problem: e instanceof Error ? e.message : String(e) }));
|
|
413
|
+
return 1;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* `inlaycms push <host>`: packs the site into a temporary file (unless `--file` names a release file), sends it to the
|
|
417
|
+
* server and prints what it changes; with `--activate` the server then makes it live. Exits 1 when the server
|
|
418
|
+
* refused, 2 for a missing token, key or file.
|
|
419
|
+
*/
|
|
420
|
+
async function push(io, host, values) {
|
|
421
|
+
const token = pushToken(io, values.token);
|
|
422
|
+
if (typeof token === 'number')
|
|
423
|
+
return token;
|
|
424
|
+
let tmp = null;
|
|
425
|
+
try {
|
|
426
|
+
let file;
|
|
427
|
+
if (values.file !== undefined) {
|
|
428
|
+
file = resolve(io.cwd, values.file);
|
|
429
|
+
if (!(await stat(file).then((s) => s.isFile(), () => false))) {
|
|
430
|
+
io.err(t('cli.pushFile', { path: file }));
|
|
431
|
+
return 2;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
const privateKey = await signingKey(io, values.key);
|
|
436
|
+
if (typeof privateKey === 'number')
|
|
437
|
+
return privateKey;
|
|
438
|
+
let configFile = '';
|
|
439
|
+
let dir;
|
|
440
|
+
try {
|
|
441
|
+
configFile = findConfig(io, values.config);
|
|
442
|
+
({ file: configFile, dir } = await loadConfig(configFile));
|
|
443
|
+
}
|
|
444
|
+
catch (e) {
|
|
445
|
+
return fail(io, e, 'cli.configFailed', configFile);
|
|
446
|
+
}
|
|
447
|
+
tmp = await mkdtemp(join(tmpdir(), 'inlay-push-'));
|
|
448
|
+
const name = values.name ?? (await releaseName(dir, new Date()));
|
|
449
|
+
file = join(tmp, 'release.tgz');
|
|
450
|
+
const packed = await packTo(io, configFile, dir, { privateKey, out: file, name, typecheck: values['no-typecheck'] !== true });
|
|
451
|
+
if (typeof packed === 'number')
|
|
452
|
+
return packed;
|
|
453
|
+
io.out(t('cli.pushPacked', { name, files: packed.files }));
|
|
454
|
+
}
|
|
455
|
+
const answer = await pushFile(host, token, file, {
|
|
456
|
+
activate: values.activate === true,
|
|
457
|
+
dryRun: values['dry-run'] === true,
|
|
458
|
+
insecure: values.insecure === true,
|
|
459
|
+
...(values.name !== undefined && { name: values.name }),
|
|
460
|
+
});
|
|
461
|
+
const { release } = answer;
|
|
462
|
+
if (release === null)
|
|
463
|
+
io.out(t('cli.pushDryRun'));
|
|
464
|
+
else
|
|
465
|
+
io.out(t(values.activate ? 'cli.activateStored' : 'cli.pushStaged', { name: release.name, id: release.id }));
|
|
466
|
+
io.out(t('cli.pushChanges'));
|
|
467
|
+
for (const line of formatDiff(answer.diff))
|
|
468
|
+
io.out(` ${line}`);
|
|
469
|
+
for (const warning of answer.warnings)
|
|
470
|
+
io.out(t('diff.release.warning', { message: warning }));
|
|
471
|
+
if (answer.previewUrl !== null)
|
|
472
|
+
io.out(t('cli.pushPreview', { url: answer.previewUrl }));
|
|
473
|
+
if (answer.failed !== null) {
|
|
474
|
+
io.err(answer.failed);
|
|
475
|
+
return 1;
|
|
476
|
+
}
|
|
477
|
+
if (release !== null && answer.activation !== null)
|
|
478
|
+
printActivation(io, release.name, answer.activation);
|
|
479
|
+
else if (release !== null)
|
|
480
|
+
io.out(t('cli.pushActivateHint', { host, id: release.id }));
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
catch (e) {
|
|
484
|
+
return remoteFailed(io, host, e);
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
if (tmp !== null)
|
|
488
|
+
await rm(tmp, { recursive: true, force: true });
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/** `inlaycms activate <host> <id>`: makes a release on the server live, also to roll back to an earlier one. */
|
|
492
|
+
async function activateOnHost(io, host, id, flags) {
|
|
493
|
+
const token = pushToken(io, flags.token);
|
|
494
|
+
if (typeof token === 'number')
|
|
495
|
+
return token;
|
|
496
|
+
try {
|
|
497
|
+
const { release, activation } = await activateRemote(host, token, id, { insecure: flags.insecure });
|
|
498
|
+
printActivation(io, release.name, activation);
|
|
499
|
+
return 0;
|
|
500
|
+
}
|
|
501
|
+
catch (e) {
|
|
502
|
+
return remoteFailed(io, host, e);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/** `inlaycms releases <host>`: the releases on the server, newest first. */
|
|
506
|
+
async function releasesOnHost(io, host, flags) {
|
|
507
|
+
const token = pushToken(io, flags.token);
|
|
508
|
+
if (typeof token === 'number')
|
|
509
|
+
return token;
|
|
510
|
+
try {
|
|
511
|
+
printReleases(io, (await listRemoteReleases(host, token, { insecure: flags.insecure })).releases, flags.json);
|
|
512
|
+
return 0;
|
|
513
|
+
}
|
|
514
|
+
catch (e) {
|
|
515
|
+
return remoteFailed(io, host, e);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Makes an API key for the user with `email` and prints it, the only time it is shown: alone on standard output,
|
|
520
|
+
* so a script can capture it, with what it is on standard error. With `push`, a push token, which only an owner
|
|
521
|
+
* may have. Only inserts the key, so it works with the server running or stopped.
|
|
522
|
+
*/
|
|
523
|
+
async function createToken(io, target, flags) {
|
|
524
|
+
const { db, auth } = await bootInlay({
|
|
525
|
+
site: target.site,
|
|
526
|
+
db: target.db,
|
|
527
|
+
backups: target.backups,
|
|
528
|
+
...(target.media !== undefined && { media: target.media }),
|
|
529
|
+
...(target.content && { content: target.content }),
|
|
530
|
+
auth: { secret: randomBytes(32).toString('hex'), baseUrl: 'http://localhost' },
|
|
531
|
+
});
|
|
532
|
+
try {
|
|
533
|
+
const user = await db.selectFrom('user').select(['id', 'role']).where('email', '=', flags.email.toLowerCase()).executeTakeFirst();
|
|
534
|
+
if (user === undefined) {
|
|
535
|
+
io.err(t('cli.tokenNoUser', { email: flags.email }));
|
|
536
|
+
return 1;
|
|
537
|
+
}
|
|
538
|
+
if (flags.push && user.role !== 'owner') {
|
|
539
|
+
io.err(t('cli.tokenNotOwner', { email: flags.email }));
|
|
540
|
+
return 1;
|
|
541
|
+
}
|
|
542
|
+
const key = await auth.createApiKey(user.id, flags.name, flags.push ? { permissions: { release: ['push'] } } : {});
|
|
543
|
+
io.out(key);
|
|
544
|
+
io.err(t(flags.push ? 'cli.pushTokenCreated' : 'cli.tokenCreated', { name: flags.name.trim(), email: flags.email }));
|
|
545
|
+
return 0;
|
|
546
|
+
}
|
|
547
|
+
catch (e) {
|
|
548
|
+
if (e instanceof InlayError && (e.code === 'validation' || e.code === 'forbidden')) {
|
|
549
|
+
io.err(e.message);
|
|
550
|
+
for (const issue of e.details.issues ?? [])
|
|
551
|
+
io.err(issue.message);
|
|
552
|
+
return 1;
|
|
553
|
+
}
|
|
554
|
+
throw e;
|
|
555
|
+
}
|
|
556
|
+
finally {
|
|
557
|
+
await db.destroy();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/** Sets a new password for the user with this email, read from the terminal or stdin. Ends their sessions and API keys. */
|
|
561
|
+
async function resetPassword(io, target, email) {
|
|
562
|
+
if (!io.readSecret) {
|
|
563
|
+
io.err(t('cli.noSecretInput'));
|
|
564
|
+
return 2;
|
|
565
|
+
}
|
|
566
|
+
const password = await io.readSecret(t('cli.passwordPrompt'));
|
|
567
|
+
const { db, auth } = await bootInlay({
|
|
568
|
+
site: target.site,
|
|
569
|
+
db: target.db,
|
|
570
|
+
backups: target.backups,
|
|
571
|
+
...(target.media !== undefined && { media: target.media }),
|
|
572
|
+
...(target.content && { content: target.content }),
|
|
573
|
+
auth: { secret: randomBytes(32).toString('hex'), baseUrl: 'http://localhost' },
|
|
574
|
+
});
|
|
575
|
+
try {
|
|
576
|
+
const user = await db.selectFrom('user').select('id').where('email', '=', email.toLowerCase()).executeTakeFirst();
|
|
577
|
+
if (user === undefined) {
|
|
578
|
+
io.err(t('cli.resetNoUser', { email }));
|
|
579
|
+
return 1;
|
|
580
|
+
}
|
|
581
|
+
await auth.setPassword(systemCtx('system').actor, user.id, password);
|
|
582
|
+
io.out(t('cli.passwordReset', { email }));
|
|
583
|
+
return 0;
|
|
584
|
+
}
|
|
585
|
+
catch (e) {
|
|
586
|
+
if (e instanceof InlayError && e.code === 'validation') {
|
|
587
|
+
io.err(e.message);
|
|
588
|
+
for (const issue of e.details.issues ?? [])
|
|
589
|
+
io.err(issue.message);
|
|
590
|
+
return 1;
|
|
591
|
+
}
|
|
592
|
+
throw e;
|
|
593
|
+
}
|
|
594
|
+
finally {
|
|
595
|
+
await db.destroy();
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/** The commands that also run on a host, from its data folder, without a config file. */
|
|
599
|
+
const HOST_COMMANDS = ['backup', 'export', 'import', 'restore-backup', 'create-owner', 'create-token', 'reset-password'];
|
|
600
|
+
function hasConfigFile(io) {
|
|
601
|
+
return ['inlay.config.ts', 'inlay.config.js', 'inlay.config.mjs'].some((name) => existsSync(join(io.cwd, name)));
|
|
602
|
+
}
|
|
603
|
+
/** The site of the release the database says is current; null without one, or when its files are gone. */
|
|
604
|
+
async function releaseSite(paths) {
|
|
605
|
+
if (!existsSync(paths.db))
|
|
606
|
+
return null;
|
|
607
|
+
const db = openDatabase(paths.db);
|
|
608
|
+
let id;
|
|
609
|
+
try {
|
|
610
|
+
id = (await hasReleasesTable(db)) ? ((await currentRelease(db))?.id ?? null) : null;
|
|
611
|
+
}
|
|
612
|
+
finally {
|
|
613
|
+
await db.destroy();
|
|
614
|
+
}
|
|
615
|
+
if (id === null)
|
|
616
|
+
return null;
|
|
617
|
+
const dir = releaseDir(paths.releases, id);
|
|
618
|
+
if (!existsSync(join(dir, 'site.js')) || !existsSync(join(dir, 'manifest.json')))
|
|
619
|
+
return null;
|
|
620
|
+
return (await loadRelease(dir)).site;
|
|
621
|
+
}
|
|
622
|
+
async function backup(io, target) {
|
|
623
|
+
if (!existsSync(target.db))
|
|
624
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: target.db });
|
|
625
|
+
const db = openDatabase(target.db);
|
|
626
|
+
try {
|
|
627
|
+
const made = await createBackup({
|
|
628
|
+
db,
|
|
629
|
+
backups: target.backups,
|
|
630
|
+
...(target.media !== undefined && { media: target.media }),
|
|
631
|
+
...(target.releases !== undefined && { releases: target.releases }),
|
|
632
|
+
reason: 'manual',
|
|
633
|
+
ctx: systemCtx('system'),
|
|
634
|
+
});
|
|
635
|
+
io.out(t('cli.backupCreated', { path: made.path }));
|
|
636
|
+
return 0;
|
|
637
|
+
}
|
|
638
|
+
finally {
|
|
639
|
+
await db.destroy();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
async function exportContent(io, target, out) {
|
|
643
|
+
if (!existsSync(target.db))
|
|
644
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: target.db });
|
|
645
|
+
const db = openDatabase(target.db);
|
|
646
|
+
try {
|
|
647
|
+
const core = createCore({ site: target.site, db, ...(target.media !== undefined && { media: target.media }) });
|
|
648
|
+
const file = out ? resolve(io.cwd, out) : join(io.cwd, exportFileName(new Date()));
|
|
649
|
+
const summary = await core.exportContent(file, systemCtx('system'));
|
|
650
|
+
io.out(t('cli.exported', { path: summary.path, documents: summary.counts.documents, media: summary.counts.media }));
|
|
651
|
+
return 0;
|
|
652
|
+
}
|
|
653
|
+
finally {
|
|
654
|
+
await db.destroy();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
async function restore(io, target, arg, serverStopped) {
|
|
658
|
+
const trustedKeys = readTrustedKeys(process.env);
|
|
659
|
+
const result = await restoreBackup({
|
|
660
|
+
// A bare file name that isn't in the current directory is looked up in the backups folder.
|
|
661
|
+
archive: existsSync(resolve(io.cwd, arg)) ? resolve(io.cwd, arg) : arg,
|
|
662
|
+
...target,
|
|
663
|
+
trustedKeys,
|
|
664
|
+
serverStopped,
|
|
665
|
+
});
|
|
666
|
+
io.out(t('cli.backupRestored', { createdAt: result.restored.createdAt }));
|
|
667
|
+
if (result.release) {
|
|
668
|
+
io.out(t('cli.backupRestoredRelease', { name: result.release.name }));
|
|
669
|
+
if (!result.release.verified)
|
|
670
|
+
io.out(t('cli.restoreUnsigned'));
|
|
671
|
+
}
|
|
672
|
+
if (result.previous.db)
|
|
673
|
+
io.out(t('cli.backupRestoredDb', { db: result.previous.db }));
|
|
674
|
+
if (result.previous.media)
|
|
675
|
+
io.out(t('cli.backupRestoredMedia', { media: result.previous.media }));
|
|
676
|
+
return 0;
|
|
677
|
+
}
|
|
678
|
+
/** `backup`, `export`, `import`, `restore-backup`, `create-owner`, `create-token` and `reset-password` on a host: everything is in its data folder. */
|
|
679
|
+
async function onHost(io, command, dir, values, arg) {
|
|
680
|
+
const paths = hostPaths(dir);
|
|
681
|
+
const serverStopped = values['server-stopped'] === true;
|
|
682
|
+
try {
|
|
683
|
+
if (command === 'backup')
|
|
684
|
+
return await backup(io, paths);
|
|
685
|
+
if (command === 'restore-backup') {
|
|
686
|
+
await mkdir(dir, { recursive: true });
|
|
687
|
+
return await restore(io, paths, arg, serverStopped);
|
|
688
|
+
}
|
|
689
|
+
const site = await releaseSite(paths);
|
|
690
|
+
if (command === 'import') {
|
|
691
|
+
if (site === null) {
|
|
692
|
+
io.err(t('cli.importNoRelease'));
|
|
693
|
+
return 2;
|
|
694
|
+
}
|
|
695
|
+
const file = resolve(io.cwd, arg);
|
|
696
|
+
if (values['dry-run'])
|
|
697
|
+
return printImportReport(io, await dryRunImport(site, file), values.json);
|
|
698
|
+
return await importFile(io, { ...paths, site, content: 'none' }, file, { serverStopped });
|
|
699
|
+
}
|
|
700
|
+
// Without a live release, the empty site's admin: the content stays as it is.
|
|
701
|
+
const target = { ...paths, site: site ?? EMPTY_SITE, content: 'none' };
|
|
702
|
+
if (command === 'create-owner') {
|
|
703
|
+
await mkdir(dir, { recursive: true });
|
|
704
|
+
return await createOwner(io, target, values.email ?? '', values.name ?? '');
|
|
705
|
+
}
|
|
706
|
+
if (command === 'create-token') {
|
|
707
|
+
if (!existsSync(paths.db))
|
|
708
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: paths.db });
|
|
709
|
+
return await createToken(io, target, { email: values.email ?? '', name: values.name ?? '', push: values.push === true });
|
|
710
|
+
}
|
|
711
|
+
if (command === 'reset-password') {
|
|
712
|
+
if (!existsSync(paths.db))
|
|
713
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: paths.db });
|
|
714
|
+
return await resetPassword(io, target, values.email ?? '');
|
|
715
|
+
}
|
|
716
|
+
return await exportContent(io, target, values.out);
|
|
717
|
+
}
|
|
718
|
+
catch (e) {
|
|
719
|
+
return fail(io, e, 'cli.databaseFailed', paths.db);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
export async function runCli(argv, io) {
|
|
723
|
+
// Before parseArgs: a cluster worker runs this same command line again, and serve takes its settings from INLAY_*.
|
|
724
|
+
if (argv[0] === 'serve')
|
|
725
|
+
return argv.length === 1 ? await serve(argv.slice(1), io) : usage(io);
|
|
726
|
+
// Before parseArgs too: dev has its own flags, and its child runs this same command line again.
|
|
727
|
+
if (argv[0] === 'dev')
|
|
728
|
+
return await dev(argv.slice(1), io);
|
|
729
|
+
let parsed;
|
|
730
|
+
try {
|
|
731
|
+
parsed = parseArgs({
|
|
732
|
+
args: argv,
|
|
733
|
+
allowPositionals: true,
|
|
734
|
+
options: {
|
|
735
|
+
config: { type: 'string' },
|
|
736
|
+
db: { type: 'string' },
|
|
737
|
+
data: { type: 'string' },
|
|
738
|
+
json: { type: 'boolean' },
|
|
739
|
+
help: { type: 'boolean' },
|
|
740
|
+
email: { type: 'string' },
|
|
741
|
+
name: { type: 'string' },
|
|
742
|
+
out: { type: 'string' },
|
|
743
|
+
export: { type: 'string' },
|
|
744
|
+
'dry-run': { type: 'boolean' },
|
|
745
|
+
'server-stopped': { type: 'boolean' },
|
|
746
|
+
key: { type: 'string' },
|
|
747
|
+
'no-typecheck': { type: 'boolean' },
|
|
748
|
+
token: { type: 'string' },
|
|
749
|
+
file: { type: 'string' },
|
|
750
|
+
activate: { type: 'boolean' },
|
|
751
|
+
push: { type: 'boolean' },
|
|
752
|
+
insecure: { type: 'boolean' },
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
catch (e) {
|
|
757
|
+
io.err(e instanceof Error ? e.message : String(e));
|
|
758
|
+
return usage(io);
|
|
759
|
+
}
|
|
760
|
+
const { values, positionals } = parsed;
|
|
761
|
+
const [command, ...rest] = positionals;
|
|
762
|
+
const commands = [
|
|
763
|
+
'check',
|
|
764
|
+
'backup',
|
|
765
|
+
'export',
|
|
766
|
+
'import',
|
|
767
|
+
'restore-backup',
|
|
768
|
+
'create-owner',
|
|
769
|
+
'create-token',
|
|
770
|
+
'reset-password',
|
|
771
|
+
'keygen',
|
|
772
|
+
'pack',
|
|
773
|
+
'push',
|
|
774
|
+
'activate',
|
|
775
|
+
'releases',
|
|
776
|
+
];
|
|
777
|
+
if (values.help || !command || !commands.includes(command))
|
|
778
|
+
return usage(io);
|
|
779
|
+
// A server address first selects the remote form of activate and releases; push only has that form.
|
|
780
|
+
const remote = (command === 'push' || command === 'activate' || command === 'releases') && isRemote(rest[0]);
|
|
781
|
+
if (command === 'push' && !remote) {
|
|
782
|
+
if (rest.length === 1)
|
|
783
|
+
io.err(t('cli.pushHost', { host: rest[0] ?? '' }));
|
|
784
|
+
return usage(io);
|
|
785
|
+
}
|
|
786
|
+
const takesFile = command === 'import' || command === 'restore-backup' || command === 'activate';
|
|
787
|
+
const wanted = remote ? (command === 'activate' ? 2 : 1) : takesFile ? 1 : 0;
|
|
788
|
+
if (rest.length !== wanted)
|
|
789
|
+
return usage(io);
|
|
790
|
+
const only = (flag, ...allowed) => flag === undefined || allowed.includes(command);
|
|
791
|
+
const offline = remote ? '' : command;
|
|
792
|
+
if (!only(values.out, 'export', 'keygen', 'pack') ||
|
|
793
|
+
!only(values.name, 'create-owner', 'create-token', 'keygen', 'pack', 'push', offline === 'activate' ? 'activate' : '') ||
|
|
794
|
+
!only(values.key, 'pack', 'push') ||
|
|
795
|
+
!only(values['no-typecheck'], 'pack', 'push') ||
|
|
796
|
+
!only(values.db, 'check', 'backup', 'export', 'import', 'restore-backup', 'create-owner', 'create-token', 'reset-password') ||
|
|
797
|
+
!only(values.export, 'check') ||
|
|
798
|
+
!only(values['dry-run'], 'import', 'push') ||
|
|
799
|
+
!only(values['server-stopped'], 'import', 'restore-backup', offline === 'activate' ? 'activate' : '') ||
|
|
800
|
+
!only(values.data, offline === 'activate' || offline === 'releases' ? offline : '', ...HOST_COMMANDS) ||
|
|
801
|
+
!only(values.email, 'create-owner', 'create-token', 'reset-password') ||
|
|
802
|
+
!only(values.token, remote ? command : '') ||
|
|
803
|
+
!only(values.insecure, remote ? command : '') ||
|
|
804
|
+
!only(values.file, 'push') ||
|
|
805
|
+
!only(values.activate, 'push') ||
|
|
806
|
+
!only(values.push, 'create-token') ||
|
|
807
|
+
(values.config !== undefined && (command === 'activate' || command === 'releases')) ||
|
|
808
|
+
(values.file !== undefined && (values.key !== undefined || values.config !== undefined || values['no-typecheck'] !== undefined)) ||
|
|
809
|
+
(values.data !== undefined && (values.config !== undefined || values.db !== undefined)) ||
|
|
810
|
+
(values.export !== undefined && values.db !== undefined)) {
|
|
811
|
+
return usage(io);
|
|
812
|
+
}
|
|
813
|
+
if ((command === 'create-owner' || command === 'create-token') && (!values.email || !values.name))
|
|
814
|
+
return usage(io);
|
|
815
|
+
if (command === 'reset-password' && !values.email)
|
|
816
|
+
return usage(io);
|
|
817
|
+
if ((command === 'pack' || command === 'activate' || command === 'push') && values.name !== undefined && values.name.trim() === '') {
|
|
818
|
+
io.err(t('cli.packName'));
|
|
819
|
+
return 2;
|
|
820
|
+
}
|
|
821
|
+
if (remote) {
|
|
822
|
+
const host = rest[0] ?? '';
|
|
823
|
+
if (command === 'push' && values['dry-run'] && values.activate) {
|
|
824
|
+
io.err(t('cli.pushDryRunActivate'));
|
|
825
|
+
return 2;
|
|
826
|
+
}
|
|
827
|
+
try {
|
|
828
|
+
checkTransport(host, values.insecure === true);
|
|
829
|
+
}
|
|
830
|
+
catch (e) {
|
|
831
|
+
return remoteFailed(io, host, e);
|
|
832
|
+
}
|
|
833
|
+
const insecure = values.insecure === true;
|
|
834
|
+
if (command === 'push') {
|
|
835
|
+
return await push(io, host, {
|
|
836
|
+
insecure,
|
|
837
|
+
file: values.file,
|
|
838
|
+
activate: values.activate,
|
|
839
|
+
'dry-run': values['dry-run'],
|
|
840
|
+
name: values.name,
|
|
841
|
+
token: values.token,
|
|
842
|
+
key: values.key,
|
|
843
|
+
'no-typecheck': values['no-typecheck'],
|
|
844
|
+
config: values.config,
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
if (command === 'activate')
|
|
848
|
+
return await activateOnHost(io, host, rest[1] ?? '', { token: values.token, insecure });
|
|
849
|
+
return await releasesOnHost(io, host, { token: values.token, json: values.json === true, insecure });
|
|
850
|
+
}
|
|
851
|
+
if (command === 'activate' || command === 'releases') {
|
|
852
|
+
try {
|
|
853
|
+
return command === 'activate'
|
|
854
|
+
? await activate(io, rest[0] ?? '', { data: values.data, name: values.name, serverStopped: values['server-stopped'] === true })
|
|
855
|
+
: await releases(io, { data: values.data, json: values.json === true });
|
|
856
|
+
}
|
|
857
|
+
catch (e) {
|
|
858
|
+
return fail(io, e, 'cli.databaseFailed', values.data ?? process.env.INLAY_DATA_DIR ?? '');
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (command === 'keygen') {
|
|
862
|
+
try {
|
|
863
|
+
return await keygen(io, values.out, values.name ?? 'inlay');
|
|
864
|
+
}
|
|
865
|
+
catch (e) {
|
|
866
|
+
return fail(io, e, 'cli.configFailed', io.cwd);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
// On a host there's no config file: `--data`, or INLAY_DATA_DIR when no config file is given or found.
|
|
870
|
+
let usingConfig = false;
|
|
871
|
+
if (HOST_COMMANDS.includes(command)) {
|
|
872
|
+
const env = process.env.INLAY_DATA_DIR;
|
|
873
|
+
const configFile = values.config !== undefined || hasConfigFile(io);
|
|
874
|
+
const host = values.data !== undefined
|
|
875
|
+
? values.data
|
|
876
|
+
: values.config === undefined && values.db === undefined && env && !hasConfigFile(io)
|
|
877
|
+
? env
|
|
878
|
+
: undefined;
|
|
879
|
+
if (host !== undefined) {
|
|
880
|
+
if (configFile)
|
|
881
|
+
io.err(t('cli.usingData', { path: resolve(io.cwd, host) }));
|
|
882
|
+
return await onHost(io, command, resolve(io.cwd, host), values, rest[0] ?? '');
|
|
883
|
+
}
|
|
884
|
+
// Both are there: say which one this command works on.
|
|
885
|
+
usingConfig = Boolean(env) && values.db === undefined;
|
|
886
|
+
}
|
|
887
|
+
let config;
|
|
888
|
+
let file = '';
|
|
889
|
+
let dir = '';
|
|
890
|
+
try {
|
|
891
|
+
file = findConfig(io, values.config);
|
|
892
|
+
({ config, file, dir } = await loadConfig(file));
|
|
893
|
+
}
|
|
894
|
+
catch (e) {
|
|
895
|
+
return fail(io, e, 'cli.configFailed', file);
|
|
896
|
+
}
|
|
897
|
+
if (usingConfig)
|
|
898
|
+
io.err(t('cli.usingConfig', { file }));
|
|
899
|
+
if (command === 'pack') {
|
|
900
|
+
return await pack(io, file, dir, {
|
|
901
|
+
...(values.key !== undefined && { key: values.key }),
|
|
902
|
+
...(values.out !== undefined && { out: values.out }),
|
|
903
|
+
...(values.name !== undefined && { name: values.name }),
|
|
904
|
+
typecheck: values['no-typecheck'] !== true,
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
const given = values.db ? resolve(io.cwd, values.db) : config.db;
|
|
908
|
+
try {
|
|
909
|
+
if (command === 'check' && values.export !== undefined) {
|
|
910
|
+
return printImportReport(io, await dryRunImport(config.site, resolve(io.cwd, values.export)), values.json);
|
|
911
|
+
}
|
|
912
|
+
if (command === 'import' && values['dry-run']) {
|
|
913
|
+
return printImportReport(io, await dryRunImport(config.site, resolve(io.cwd, rest[0] ?? '')), values.json);
|
|
914
|
+
}
|
|
915
|
+
if (command === 'check') {
|
|
916
|
+
try {
|
|
917
|
+
buildRegistry(config.site);
|
|
918
|
+
}
|
|
919
|
+
catch (e) {
|
|
920
|
+
if (!(e instanceof InlayError) || e.code !== 'definition')
|
|
921
|
+
throw e;
|
|
922
|
+
io.err(e.message);
|
|
923
|
+
return 1;
|
|
924
|
+
}
|
|
925
|
+
// A config's database may not exist yet (a fresh checkout, CI); only --db insists on one.
|
|
926
|
+
const db = values.db !== undefined || (given !== undefined && existsSync(given)) ? given : undefined;
|
|
927
|
+
const report = db !== undefined ? await checkDatabase({ site: config.site, db }) : await checkWithoutDatabase({ site: config.site });
|
|
928
|
+
const problems = await checkBundle(file);
|
|
929
|
+
if (problems.length > 0) {
|
|
930
|
+
report.problems.push(...problems);
|
|
931
|
+
report.ok = false;
|
|
932
|
+
}
|
|
933
|
+
if (values.json)
|
|
934
|
+
io.out(JSON.stringify(report, null, 2));
|
|
935
|
+
else
|
|
936
|
+
for (const line of formatReport(report))
|
|
937
|
+
io.out(line);
|
|
938
|
+
return report.ok ? 0 : 1;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
catch (e) {
|
|
942
|
+
return fail(io, e, 'cli.databaseFailed', given ?? file);
|
|
943
|
+
}
|
|
944
|
+
if (given === undefined) {
|
|
945
|
+
io.err(t('cli.configDb', { path: file }));
|
|
946
|
+
return 2;
|
|
947
|
+
}
|
|
948
|
+
const dbPath = given;
|
|
949
|
+
const target = {
|
|
950
|
+
db: dbPath,
|
|
951
|
+
backups: config.backups ?? join(dbPath, '..', 'backups'),
|
|
952
|
+
...(config.media !== undefined && { media: config.media }),
|
|
953
|
+
site: config.site,
|
|
954
|
+
};
|
|
955
|
+
try {
|
|
956
|
+
if (command === 'create-owner')
|
|
957
|
+
return await createOwner(io, target, values.email ?? '', values.name ?? '');
|
|
958
|
+
if (command === 'create-token') {
|
|
959
|
+
if (!existsSync(dbPath))
|
|
960
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: dbPath });
|
|
961
|
+
return await createToken(io, target, { email: values.email ?? '', name: values.name ?? '', push: values.push === true });
|
|
962
|
+
}
|
|
963
|
+
if (command === 'reset-password') {
|
|
964
|
+
if (!existsSync(dbPath))
|
|
965
|
+
throw new InlayError('not_found', 'error.noDatabase', { path: dbPath });
|
|
966
|
+
return await resetPassword(io, target, values.email ?? '');
|
|
967
|
+
}
|
|
968
|
+
if (command === 'import') {
|
|
969
|
+
return await importFile(io, target, resolve(io.cwd, rest[0] ?? ''), { serverStopped: values['server-stopped'] === true });
|
|
970
|
+
}
|
|
971
|
+
if (command === 'restore-backup') {
|
|
972
|
+
const media = config.media ?? join(dbPath, '..', 'media');
|
|
973
|
+
return await restore(io, { db: dbPath, media, backups: target.backups }, rest[0] ?? '', values['server-stopped'] === true);
|
|
974
|
+
}
|
|
975
|
+
if (command === 'export')
|
|
976
|
+
return await exportContent(io, target, values.out);
|
|
977
|
+
return await backup(io, target);
|
|
978
|
+
}
|
|
979
|
+
catch (e) {
|
|
980
|
+
return fail(io, e, 'cli.databaseFailed', dbPath);
|
|
981
|
+
}
|
|
982
|
+
}
|