tinyzoo 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 +10 -0
- package/README.md +46 -2
- package/app/app.config.ts +35 -0
- package/app/assets/brand/characters/bright/bird.svg +1 -0
- package/app/assets/brand/characters/bright/bunny.svg +1 -0
- package/app/assets/brand/characters/bright/elephant.svg +1 -0
- package/app/assets/brand/characters/bright/fox.svg +1 -0
- package/app/assets/brand/characters/bright/frog.svg +1 -0
- package/app/assets/brand/characters/bright/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/bee.svg +1 -0
- package/app/assets/brand/characters/muted/bird.svg +1 -0
- package/app/assets/brand/characters/muted/butterfly.svg +1 -0
- package/app/assets/brand/characters/muted/chick.svg +1 -0
- package/app/assets/brand/characters/muted/cow.svg +1 -0
- package/app/assets/brand/characters/muted/deer.svg +1 -0
- package/app/assets/brand/characters/muted/duck.svg +1 -0
- package/app/assets/brand/characters/muted/elephant.svg +1 -0
- package/app/assets/brand/characters/muted/fox.svg +1 -0
- package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
- package/app/assets/brand/characters/muted/koala.svg +1 -0
- package/app/assets/brand/characters/muted/ladybug.svg +1 -0
- package/app/assets/brand/characters/muted/lion.svg +1 -0
- package/app/assets/brand/characters/muted/mouse.svg +1 -0
- package/app/assets/brand/characters/muted/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/owl.svg +1 -0
- package/app/assets/brand/characters/muted/panda.svg +1 -0
- package/app/assets/brand/characters/muted/penguin.svg +1 -0
- package/app/assets/brand/characters/muted/pig.svg +1 -0
- package/app/assets/brand/characters/muted/poodle.svg +1 -0
- package/app/assets/brand/characters/muted/raccoon.svg +1 -0
- package/app/assets/brand/characters/muted/seal.svg +1 -0
- package/app/assets/brand/characters/muted/sheep.svg +1 -0
- package/app/assets/brand/characters/muted/snail.svg +1 -0
- package/app/assets/brand/characters/muted/turtle.svg +1 -0
- package/app/assets/brand/characters/muted/whale.svg +1 -0
- package/app/assets/brand/logo/favicon.svg +1 -0
- package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
- package/app/assets/brand/logo/logo-primary.svg +1 -0
- package/app/assets/brand/logo/mascot-reversed.svg +1 -0
- package/app/assets/brand/logo/mascot.svg +1 -0
- package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
- package/app/assets/brand/logo/wordmark.svg +1 -0
- package/app/assets/css/cms-admin.css +607 -0
- package/app/components/CmsBlocks.vue +30 -0
- package/app/components/CmsCell.vue +16 -0
- package/app/components/CmsCellBadge.vue +18 -0
- package/app/components/CmsCellBlocks.vue +9 -0
- package/app/components/CmsCellBoolean.vue +12 -0
- package/app/components/CmsCellCode.vue +7 -0
- package/app/components/CmsCellColor.vue +13 -0
- package/app/components/CmsCellDate.vue +10 -0
- package/app/components/CmsCellExcerpt.vue +21 -0
- package/app/components/CmsCellGallery.vue +10 -0
- package/app/components/CmsCellGroup.vue +23 -0
- package/app/components/CmsCellNumber.vue +7 -0
- package/app/components/CmsCellRelation.vue +8 -0
- package/app/components/CmsCellText.vue +12 -0
- package/app/components/CmsCellThumb.vue +18 -0
- package/app/components/CmsConfirmDialog.vue +55 -0
- package/app/components/CmsContent.vue +103 -0
- package/app/components/CmsDayPicker.vue +44 -0
- package/app/components/CmsEmptyState.vue +35 -0
- package/app/components/CmsField.vue +111 -0
- package/app/components/CmsFieldBlocks.vue +353 -0
- package/app/components/CmsFieldBoolean.vue +8 -0
- package/app/components/CmsFieldColor.vue +42 -0
- package/app/components/CmsFieldDate.vue +131 -0
- package/app/components/CmsFieldGallery.vue +114 -0
- package/app/components/CmsFieldGroup.vue +53 -0
- package/app/components/CmsFieldMedia.vue +219 -0
- package/app/components/CmsFieldNumber.vue +11 -0
- package/app/components/CmsFieldRelationMany.vue +54 -0
- package/app/components/CmsFieldRelationOne.vue +47 -0
- package/app/components/CmsFieldRichText.vue +45 -0
- package/app/components/CmsFieldSelect.vue +41 -0
- package/app/components/CmsFieldSlug.vue +46 -0
- package/app/components/CmsFieldText.vue +75 -0
- package/app/components/CmsFormSections.vue +150 -0
- package/app/components/CmsHighlight.vue +22 -0
- package/app/components/CmsImage.vue +39 -0
- package/app/components/CmsLinkPicker.vue +122 -0
- package/app/components/CmsLinkTarget.vue +35 -0
- package/app/components/CmsListFilters.vue +107 -0
- package/app/components/CmsLiveNotice.vue +64 -0
- package/app/components/CmsLoadError.vue +24 -0
- package/app/components/CmsMascot.vue +10 -0
- package/app/components/CmsMediaLibrary.vue +114 -0
- package/app/components/CmsMediaPreview.vue +34 -0
- package/app/components/CmsMediaThumb.vue +22 -0
- package/app/components/CmsMoment.vue +42 -0
- package/app/components/CmsNav.vue +39 -0
- package/app/components/CmsPage.vue +86 -0
- package/app/components/CmsPasswordInput.vue +22 -0
- package/app/components/CmsPresence.vue +29 -0
- package/app/components/CmsPreviewPanel.vue +131 -0
- package/app/components/CmsPublishReview.vue +102 -0
- package/app/components/CmsRevisions.vue +195 -0
- package/app/components/CmsRichTextEditor.vue +290 -0
- package/app/components/CmsSearch.vue +99 -0
- package/app/components/CmsSection.vue +20 -0
- package/app/components/CmsSingletonForm.vue +283 -0
- package/app/components/CmsStatusBadge.vue +21 -0
- package/app/components/CmsTime.vue +16 -0
- package/app/components/CmsTranslationRef.vue +27 -0
- package/app/components/CmsTreeList.vue +453 -0
- package/app/components/CmsUnsavedText.vue +34 -0
- package/app/components/CmsWordmark.vue +10 -0
- package/app/composables/useCmsAdminHead.ts +18 -0
- package/app/composables/useCmsCollab.ts +165 -0
- package/app/composables/useCmsConfirm.ts +39 -0
- package/app/composables/useCmsEntryActions.ts +75 -0
- package/app/composables/useCmsFocus.ts +13 -0
- package/app/composables/useCmsForm.ts +273 -0
- package/app/composables/useCmsI18n.ts +185 -0
- package/app/composables/useCmsLinkTargets.ts +84 -0
- package/app/composables/useCmsLive.ts +199 -0
- package/app/composables/useCmsSearch.ts +62 -0
- package/app/composables/useCmsSeo.ts +99 -0
- package/app/composables/useCmsSignedIn.ts +24 -0
- package/app/composables/useCmsUiLocale.ts +24 -0
- package/app/i18n/cs.ts +781 -0
- package/app/i18n/de.ts +781 -0
- package/app/i18n/en.ts +782 -0
- package/app/i18n/types.ts +22 -0
- package/app/layouts/admin.vue +224 -0
- package/app/layouts/cms-auth.vue +37 -0
- package/app/middleware/cms-api-not-a-page.global.ts +10 -0
- package/app/middleware/cms-auth.global.ts +16 -0
- package/app/pages/admin/[entity]/[id].vue +1109 -0
- package/app/pages/admin/[entity]/index.vue +733 -0
- package/app/pages/admin/account.vue +117 -0
- package/app/pages/admin/forgot.vue +50 -0
- package/app/pages/admin/index.vue +184 -0
- package/app/pages/admin/invite/[token].vue +73 -0
- package/app/pages/admin/login.vue +84 -0
- package/app/pages/admin/media.vue +494 -0
- package/app/pages/admin/privacy.vue +193 -0
- package/app/pages/admin/reset/[token].vue +52 -0
- package/app/pages/admin/setup.vue +87 -0
- package/app/pages/admin/styleguide.vue +261 -0
- package/app/pages/admin/team.vue +258 -0
- package/app/plugins/cmsLivePreview.client.ts +20 -0
- package/app/plugins/cmsSignedOut.client.ts +31 -0
- package/app/utils/cmsBlockType.ts +11 -0
- package/app/utils/cmsBrand.ts +38 -0
- package/app/utils/cmsDiff.ts +83 -0
- package/app/utils/cmsFetch.ts +7 -0
- package/app/utils/cmsFocusInvalid.ts +22 -0
- package/app/utils/cmsIssues.ts +128 -0
- package/app/utils/cmsJson.ts +28 -0
- package/app/utils/cmsMedia.ts +63 -0
- package/app/utils/cmsSections.ts +154 -0
- package/app/utils/cmsTime.ts +41 -0
- package/cli/backup.ts +713 -0
- package/cli/breaking.ts +174 -0
- package/cli/content-migrate.ts +239 -0
- package/cli/db.ts +86 -0
- package/cli/export.ts +336 -0
- package/cli/generate.ts +146 -0
- package/cli/import.ts +643 -0
- package/cli/index.ts +140 -0
- package/cli/links-convert.ts +291 -0
- package/cli/seed-engine.ts +705 -0
- package/cli/seed.ts +339 -0
- package/cli/status.ts +49 -0
- package/cli/tar.ts +304 -0
- package/cli/transfer.ts +677 -0
- package/cli/up.ts +27 -0
- package/cli/upgrade.ts +60 -0
- package/cli/versions.ts +60 -0
- package/forms/components/CmsForm.vue +186 -0
- package/forms/index.ts +203 -0
- package/forms/messages.ts +104 -0
- package/forms/retention.ts +48 -0
- package/forms/server/form.get.ts +12 -0
- package/forms/server/form.post.ts +109 -0
- package/forms/server/formSettings.ts +12 -0
- package/forms/server/forms.ts +127 -0
- package/module.ts +373 -0
- package/nuxt.config.ts +43 -0
- package/package.json +99 -3
- package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
- package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
- package/server/api/cms/[entity]/[id].delete.ts +52 -0
- package/server/api/cms/[entity]/[id].get.ts +21 -0
- package/server/api/cms/[entity]/[id].patch.ts +116 -0
- package/server/api/cms/[entity]/_export.get.ts +69 -0
- package/server/api/cms/[entity]/_move.post.ts +81 -0
- package/server/api/cms/[entity]/_order.post.ts +49 -0
- package/server/api/cms/[entity]/_tree.get.ts +41 -0
- package/server/api/cms/[entity]/index.get.ts +62 -0
- package/server/api/cms/[entity]/index.post.ts +38 -0
- package/server/api/cms/[entity]/options.get.ts +55 -0
- package/server/api/cms/_auth/accept.post.ts +33 -0
- package/server/api/cms/_auth/forgot.post.ts +39 -0
- package/server/api/cms/_auth/invite/[token].get.ts +18 -0
- package/server/api/cms/_auth/login.post.ts +42 -0
- package/server/api/cms/_auth/logout.post.ts +7 -0
- package/server/api/cms/_auth/me.get.ts +5 -0
- package/server/api/cms/_auth/me.patch.ts +32 -0
- package/server/api/cms/_auth/password.post.ts +29 -0
- package/server/api/cms/_auth/reset.post.ts +34 -0
- package/server/api/cms/_auth/setup.post.ts +46 -0
- package/server/api/cms/_auth/status.get.ts +18 -0
- package/server/api/cms/_collab/session.get.ts +30 -0
- package/server/api/cms/_collab/socket.ts +51 -0
- package/server/api/cms/_collab/unsaved.delete.ts +16 -0
- package/server/api/cms/_graph.get.ts +20 -0
- package/server/api/cms/_links/resolve.post.ts +17 -0
- package/server/api/cms/_links.get.ts +81 -0
- package/server/api/cms/_live.ts +30 -0
- package/server/api/cms/_media/[id]/usage.get.ts +14 -0
- package/server/api/cms/_media/[id].delete.ts +29 -0
- package/server/api/cms/_media/[id].get.ts +13 -0
- package/server/api/cms/_media/[id].patch.ts +64 -0
- package/server/api/cms/_media/exists.post.ts +15 -0
- package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
- package/server/api/cms/_media/index.get.ts +44 -0
- package/server/api/cms/_media/index.post.ts +147 -0
- package/server/api/cms/_media/raw/[...key].get.ts +85 -0
- package/server/api/cms/_media/raw/[...key].head.ts +2 -0
- package/server/api/cms/_overview.get.ts +87 -0
- package/server/api/cms/_preview.post.ts +17 -0
- package/server/api/cms/_privacy/delete.post.ts +14 -0
- package/server/api/cms/_privacy/export.post.ts +25 -0
- package/server/api/cms/_privacy/lookup.post.ts +27 -0
- package/server/api/cms/_search.get.ts +17 -0
- package/server/api/cms/_singleton/[name].get.ts +19 -0
- package/server/api/cms/_singleton/[name].put.ts +76 -0
- package/server/api/cms/_users/[id]/resend.post.ts +25 -0
- package/server/api/cms/_users/[id].delete.ts +21 -0
- package/server/api/cms/_users/[id].patch.ts +45 -0
- package/server/api/cms/_users/index.get.ts +28 -0
- package/server/api/cms/_users/index.post.ts +39 -0
- package/server/api/content/[entity]/[slug].get.ts +74 -0
- package/server/api/content/[entity]/index.get.ts +100 -0
- package/server/api/content/_global/[name].get.ts +23 -0
- package/server/api/content/_search.get.ts +28 -0
- package/server/api/content/_sitemap.get.ts +8 -0
- package/server/api/content/_tree/[entity].get.ts +31 -0
- package/server/api/content-types.ts.get.ts +17 -0
- package/server/api/health/live.get.ts +10 -0
- package/server/api/health/ready.get.ts +21 -0
- package/server/api/openapi.get.ts +48 -0
- package/server/api/openapi.json.get.ts +32 -0
- package/server/db/driver.ts +8 -0
- package/server/mail/mailer.ts +43 -0
- package/server/middleware/cms-0-headers.ts +37 -0
- package/server/middleware/cms-0-migrate-gate.ts +14 -0
- package/server/middleware/cms-csrf.ts +28 -0
- package/server/middleware/cms-limits.ts +20 -0
- package/server/middleware/cms-redirects.ts +21 -0
- package/server/middleware/cms-session.ts +41 -0
- package/server/middleware/cms-z-plugin-access.ts +15 -0
- package/server/plugins/cms-0-config-check.ts +35 -0
- package/server/plugins/cms-changes.ts +53 -0
- package/server/plugins/cms-content-etag.ts +21 -0
- package/server/plugins/cms-errors.ts +45 -0
- package/server/plugins/cms-migrate.ts +5 -0
- package/server/plugins/cms-plugins.ts +17 -0
- package/server/plugins/cms-search.ts +12 -0
- package/server/plugins/cms-setup-code.ts +15 -0
- package/server/routes/sitemap.xml.get.ts +25 -0
- package/server/store/redis.ts +95 -0
- package/server/store/types.ts +21 -0
- package/server/tasks/cms/retention.ts +10 -0
- package/server/tasks/cms/scheduled.ts +10 -0
- package/server/tasks/cms/search-reindex.ts +12 -0
- package/server/utils/cmsAudit.ts +29 -0
- package/server/utils/cmsAuth.ts +143 -0
- package/server/utils/cmsBlocks.ts +47 -0
- package/server/utils/cmsChanges.ts +222 -0
- package/server/utils/cmsCollab.ts +286 -0
- package/server/utils/cmsCollabServer.ts +451 -0
- package/server/utils/cmsCollate.ts +27 -0
- package/server/utils/cmsContent.ts +376 -0
- package/server/utils/cmsCrud.ts +361 -0
- package/server/utils/cmsCsv.ts +24 -0
- package/server/utils/cmsDb.ts +23 -0
- package/server/utils/cmsDemo.ts +36 -0
- package/server/utils/cmsEmails.ts +125 -0
- package/server/utils/cmsErrors.ts +40 -0
- package/server/utils/cmsFold.ts +17 -0
- package/server/utils/cmsImageSizes.ts +51 -0
- package/server/utils/cmsJson.ts +6 -0
- package/server/utils/cmsLinkAddress.ts +50 -0
- package/server/utils/cmsLinks.ts +248 -0
- package/server/utils/cmsListQuery.ts +93 -0
- package/server/utils/cmsLive.ts +392 -0
- package/server/utils/cmsLocales.ts +96 -0
- package/server/utils/cmsMail.ts +28 -0
- package/server/utils/cmsMediaGc.ts +188 -0
- package/server/utils/cmsMediaKeys.ts +62 -0
- package/server/utils/cmsMigrate.ts +86 -0
- package/server/utils/cmsPreviewDraft.ts +72 -0
- package/server/utils/cmsPrivacy.ts +176 -0
- package/server/utils/cmsPublished.ts +57 -0
- package/server/utils/cmsRange.ts +38 -0
- package/server/utils/cmsRateLimit.ts +82 -0
- package/server/utils/cmsRedirects.ts +160 -0
- package/server/utils/cmsRetention.ts +61 -0
- package/server/utils/cmsRevisions.ts +103 -0
- package/server/utils/cmsScheduler.ts +45 -0
- package/server/utils/cmsScrub.ts +107 -0
- package/server/utils/cmsSearch.ts +354 -0
- package/server/utils/cmsSession.ts +102 -0
- package/server/utils/cmsSetupCode.ts +97 -0
- package/server/utils/cmsSitemap.ts +176 -0
- package/server/utils/cmsStorage.ts +580 -0
- package/server/utils/cmsStore.ts +109 -0
- package/server/utils/cmsTooMany.ts +9 -0
- package/server/utils/cmsTranslationWrite.ts +186 -0
- package/server/utils/cmsTree.ts +251 -0
- package/server/utils/cmsTreeAddress.ts +65 -0
- package/server/utils/cmsUpload.ts +197 -0
- package/server/utils/cmsWebhooks.ts +101 -0
- package/shared/json.ts +11 -0
- package/shared/richtext-editor.ts +56 -0
- package/shared/richtext-normalize.ts +33 -0
- package/shared/richtext-paste.ts +151 -0
- package/shared/storage-delivery.ts +53 -0
- package/src/blocks.ts +624 -0
- package/src/changes.ts +54 -0
- package/src/content-shape.ts +340 -0
- package/src/deprecate.ts +64 -0
- package/src/descriptor.ts +149 -0
- package/src/docs.ts +27 -0
- package/src/emitter.ts +94 -0
- package/src/entity.ts +624 -0
- package/src/errorReport.ts +41 -0
- package/src/fields.ts +465 -0
- package/src/i18n.ts +26 -0
- package/src/index.ts +54 -0
- package/src/linkref.ts +31 -0
- package/src/links.ts +179 -0
- package/src/locales.ts +39 -0
- package/src/media.ts +48 -0
- package/src/migrate.ts +236 -0
- package/src/openapi.ts +377 -0
- package/src/paths.ts +88 -0
- package/src/plugin.ts +505 -0
- package/src/presets.ts +230 -0
- package/src/richtext.ts +88 -0
- package/src/sdk.ts +181 -0
- package/src/search.ts +312 -0
- package/src/seed.ts +225 -0
- package/src/setupCode.ts +30 -0
- package/src/system.ts +219 -0
- package/src/tree.ts +421 -0
- package/src/upgrades.ts +137 -0
- package/starter/.env.example +10 -0
- package/starter/README.md +65 -0
- package/starter/app/app.config.ts +10 -0
- package/starter/app/app.vue +12 -0
- package/starter/app/assets/css/main.css +15 -0
- package/starter/app/components/global/BlockContact.vue +15 -0
- package/starter/app/components/global/BlockCta.vue +15 -0
- package/starter/app/components/global/BlockHero.vue +23 -0
- package/starter/app/components/global/BlockImage.vue +13 -0
- package/starter/app/components/global/BlockText.vue +12 -0
- package/starter/app/composables/useSite.ts +77 -0
- package/starter/app/error.vue +28 -0
- package/starter/app/layouts/default.vue +106 -0
- package/starter/app/lib/cms-content.ts +152 -0
- package/starter/app/pages/[...slug].vue +66 -0
- package/starter/app/pages/hledat.vue +59 -0
- package/starter/app/pages/index.vue +20 -0
- package/starter/cms.config.ts +137 -0
- package/starter/compose.yaml +15 -0
- package/starter/drizzle.config.ts +8 -0
- package/starter/gitignore.txt +8 -0
- package/starter/nuxt.config.ts +13 -0
- package/starter/package.json +38 -0
- package/starter/scripts/typecheck.mjs +38 -0
- package/starter/seed/index.ts +297 -0
- package/starter/seed/media/about.jpg +0 -0
- package/starter/seed/media/hero.jpg +0 -0
- package/starter/seed/media/logo.png +0 -0
- package/starter/seed/media/news-bread.jpg +0 -0
- package/starter/seed/media/news-morning.jpg +0 -0
- package/starter/server/db/migrations/0000_init.sql +269 -0
- package/starter/server/db/migrations/0001_page_tree.sql +5 -0
- package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
- package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
- package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
- package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
- package/starter/server/db/migrations/meta/_journal.json +27 -0
- package/starter/server/db/schema.ts +253 -0
- package/starter/server/plugins/sitemap.ts +11 -0
- package/starter/server/routes/robots.txt.get.ts +12 -0
- package/starter/tsconfig.json +9 -0
package/cli/seed.ts
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tinyzoo seed [file]` — put a site's seed content (`seed/index.ts`, written with
|
|
3
|
+
* `defineSeed`) into a running site.
|
|
4
|
+
*
|
|
5
|
+
* SEED_PASSWORD=… tinyzoo seed --url http://localhost:3000 --email you@example.com
|
|
6
|
+
*
|
|
7
|
+
* [file] the seed (default seed/index.ts)
|
|
8
|
+
* --url where the site runs (default $SEED_URL, else http://localhost:3000)
|
|
9
|
+
* --email the administrator to sign in as ($SEED_EMAIL); the password is
|
|
10
|
+
* $SEED_PASSWORD only — never an argument, which would show in `ps`
|
|
11
|
+
* --name the first administrator's name when the site has none yet ($SEED_NAME)
|
|
12
|
+
* --setup-code the code a new production site asks for before its first account
|
|
13
|
+
* (the server's log prints it, or it is NUXT_CMS_AUTH_SETUP_TOKEN).
|
|
14
|
+
* Prefer $SEED_SETUP_CODE: an argument shows in `ps` (the command says so)
|
|
15
|
+
* --dry-run sign in, read, and say what would be created, changed or uploaded;
|
|
16
|
+
* nothing is written
|
|
17
|
+
* --reset first remove the entries and files this seed made (found by their
|
|
18
|
+
* key / name, and made by the account the seed signs in with: a page
|
|
19
|
+
* an editor made with the same address stays), then seed again. It
|
|
20
|
+
* lists every entry and file first and asks (`--yes` skips the
|
|
21
|
+
* question); if anything would be refused (a page another page still
|
|
22
|
+
* links to) it stops before removing anything
|
|
23
|
+
* --verbose also list what was already up to date
|
|
24
|
+
* --wait <sec> how long to wait for the site to answer (default 30)
|
|
25
|
+
*
|
|
26
|
+
* Why over HTTP and not straight into the database: the seed goes through the admin's own
|
|
27
|
+
* API, so each write is checked, stored and indexed by the same code an editor's save
|
|
28
|
+
* runs (validation, translations, media handling and sizes, the search index, saved
|
|
29
|
+
* versions, webhooks, access rules) — a seeded site cannot differ from one an editor
|
|
30
|
+
* filled in. It also works against a site that is deployed, where the database is not
|
|
31
|
+
* reachable from here, and needs nothing but the site's address and an administrator.
|
|
32
|
+
*/
|
|
33
|
+
import { existsSync } from 'node:fs'
|
|
34
|
+
import { createInterface } from 'node:readline/promises'
|
|
35
|
+
import { resolve } from 'node:path'
|
|
36
|
+
import { pathToFileURL } from 'node:url'
|
|
37
|
+
import { buildRegistry } from '../src/index'
|
|
38
|
+
import { isSeed, type SeedDefinition } from '../src/seed'
|
|
39
|
+
import { parseArgs } from './transfer'
|
|
40
|
+
import {
|
|
41
|
+
describeReset, planReset, resetDeclared, runSeed, SeedError,
|
|
42
|
+
type MediaRow, type Row, type SeedBackend, type SeedOp,
|
|
43
|
+
} from './seed-engine'
|
|
44
|
+
|
|
45
|
+
export class HttpError extends Error {
|
|
46
|
+
constructor(message: string, readonly status: number) { super(message) }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
|
|
50
|
+
|
|
51
|
+
/** A readable one-liner out of an error response (validation issues listed by field). */
|
|
52
|
+
function errorMessage(status: number, body: any, text: string): string {
|
|
53
|
+
const issues = Array.isArray(body?.data) ? body.data : Array.isArray(body?.data?.issues) ? body.data.issues : []
|
|
54
|
+
const listed = issues.slice(0, 6).map((i: any) => `${Array.isArray(i?.path) && i.path.length ? `${i.path.join('.')}: ` : ''}${i?.message ?? JSON.stringify(i)}`).join('; ')
|
|
55
|
+
const base = body?.statusMessage ?? body?.message ?? (typeof text === 'string' ? text.slice(0, 200) : '')
|
|
56
|
+
return `${status === 0 ? '' : `${status} `}${base}${listed ? ` — ${listed}` : ''}`.trim()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Cookie-keeping JSON client for the admin API. */
|
|
60
|
+
export class SiteClient {
|
|
61
|
+
private cookie = ''
|
|
62
|
+
constructor(readonly base: string) {}
|
|
63
|
+
|
|
64
|
+
async request<T = any>(method: string, path: string, body?: unknown, opts: { notFound?: boolean } = {}): Promise<T> {
|
|
65
|
+
for (let attempt = 1; ; attempt++) {
|
|
66
|
+
const headers: Record<string, string> = { accept: 'application/json', origin: this.base }
|
|
67
|
+
if (this.cookie) headers.cookie = this.cookie
|
|
68
|
+
let payload: BodyInit | undefined
|
|
69
|
+
if (body instanceof FormData) payload = body
|
|
70
|
+
else if (body !== undefined) { headers['content-type'] = 'application/json'; payload = JSON.stringify(body) }
|
|
71
|
+
const res = await fetch(this.base + path, { method, headers, body: payload, redirect: 'manual', signal: AbortSignal.timeout(120_000) })
|
|
72
|
+
const set = res.headers.getSetCookie?.() ?? []
|
|
73
|
+
if (set.length) this.cookie = set.map((c) => c.split(';')[0]).join('; ')
|
|
74
|
+
const text = await res.text()
|
|
75
|
+
let json: any = null
|
|
76
|
+
try { json = text ? JSON.parse(text) : null } catch { /* not JSON */ }
|
|
77
|
+
// The upload limit (60 a minute) clears within the minute: wait and go on. The sign-in
|
|
78
|
+
// limits last fifteen minutes; waiting here would only look like a hang.
|
|
79
|
+
if (res.status === 429 && path === '/api/cms/_media' && attempt <= 4) {
|
|
80
|
+
await sleep(Math.min(10 * attempt, 30) * 1000)
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
if (res.status === 404 && opts.notFound) return null as T
|
|
84
|
+
if (res.status >= 300) throw new HttpError(`${method} ${path} → ${errorMessage(res.status, json, text)}`, res.status)
|
|
85
|
+
return json as T
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const enc = encodeURIComponent
|
|
91
|
+
|
|
92
|
+
/** The seed's reads and writes as calls to the admin API. */
|
|
93
|
+
export function httpBackend(site: SiteClient): SeedBackend {
|
|
94
|
+
return {
|
|
95
|
+
async account() { return (await site.request<{ user: { id?: string } | null }>('GET', '/api/cms/_auth/me')).user?.id ?? null },
|
|
96
|
+
async list(entity) {
|
|
97
|
+
const rows: Row[] = []
|
|
98
|
+
for (let page = 1; ; page++) {
|
|
99
|
+
const r = await site.request<{ rows: Row[]; total: number }>('GET', `/api/cms/${enc(entity)}?limit=100&page=${page}&sort=createdAt&dir=asc`)
|
|
100
|
+
rows.push(...r.rows)
|
|
101
|
+
if (!r.rows.length || rows.length >= r.total) return rows
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async get(entity, id, locale) {
|
|
105
|
+
const r = await site.request<{ row: Row }>('GET', `/api/cms/${enc(entity)}/${enc(id)}${locale ? `?locale=${enc(locale)}` : ''}`, undefined, { notFound: true })
|
|
106
|
+
return r?.row ?? null
|
|
107
|
+
},
|
|
108
|
+
async create(entity, data) { return (await site.request<{ row: Row }>('POST', `/api/cms/${enc(entity)}`, data)).row },
|
|
109
|
+
async update(entity, id, data, locale) {
|
|
110
|
+
return (await site.request<{ row: Row }>('PATCH', `/api/cms/${enc(entity)}/${enc(id)}${locale ? `?locale=${enc(locale)}` : ''}`, data)).row
|
|
111
|
+
},
|
|
112
|
+
async remove(entity, id) { await site.request('DELETE', `/api/cms/${enc(entity)}/${enc(id)}`) },
|
|
113
|
+
async getGlobal(entity, locale) {
|
|
114
|
+
const r = await site.request<{ row: Row | null }>('GET', `/api/cms/_singleton/${enc(entity)}${locale ? `?locale=${enc(locale)}` : ''}`)
|
|
115
|
+
return r.row ?? null
|
|
116
|
+
},
|
|
117
|
+
async putGlobal(entity, data, locale) {
|
|
118
|
+
return (await site.request<{ row: Row }>('PUT', `/api/cms/_singleton/${enc(entity)}${locale ? `?locale=${enc(locale)}` : ''}`, data)).row
|
|
119
|
+
},
|
|
120
|
+
async findMedia(q) {
|
|
121
|
+
for (let page = 1; ; page++) {
|
|
122
|
+
const r = await site.request<{ items: MediaRow[]; total: number }>(
|
|
123
|
+
'GET', `/api/cms/_media?limit=60&page=${page}&q=${enc(q.name.slice(0, 100))}&folder=${enc(q.folder ?? 'none')}`,
|
|
124
|
+
)
|
|
125
|
+
const hit = r.items.find((m) => m.name === q.name && (m.folder ?? null) === q.folder && Number(m.size) === q.size && m.mime === q.mime)
|
|
126
|
+
if (hit) return hit
|
|
127
|
+
if (page * 60 >= r.total) return null
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
async uploadMedia(file) {
|
|
131
|
+
const form = new FormData()
|
|
132
|
+
form.append('file', new Blob([file.data as Uint8Array<ArrayBuffer>], { type: file.mime }), file.name)
|
|
133
|
+
if (file.folder) form.append('folder', file.folder)
|
|
134
|
+
if (file.library) form.append('library', '1')
|
|
135
|
+
return site.request<MediaRow>('POST', '/api/cms/_media', form)
|
|
136
|
+
},
|
|
137
|
+
async patchMedia(id, details) { return site.request<MediaRow>('PATCH', `/api/cms/_media/${enc(id)}`, details) },
|
|
138
|
+
async removeMedia(id) { await site.request('DELETE', `/api/cms/_media/${enc(id)}`) },
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A site with nothing in it: what a dry run sees before the first administrator exists. */
|
|
143
|
+
export function emptyBackend(): SeedBackend {
|
|
144
|
+
const refuse = () => { throw new Error('read-only run') }
|
|
145
|
+
return {
|
|
146
|
+
account: async () => null, list: async () => [], get: async () => null, getGlobal: async () => null, findMedia: async () => null,
|
|
147
|
+
create: refuse, update: refuse, remove: refuse, putGlobal: refuse, uploadMedia: refuse, patchMedia: refuse, removeMedia: refuse,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── signing in ──────────────────────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
interface AuthStatus { mode: string; needsSetup: boolean; needsToken?: boolean; codeIn?: 'config' | 'log' }
|
|
154
|
+
|
|
155
|
+
async function waitForSite(site: SiteClient, seconds: number): Promise<AuthStatus> {
|
|
156
|
+
const until = Date.now() + seconds * 1000
|
|
157
|
+
let last: unknown
|
|
158
|
+
for (;;) {
|
|
159
|
+
try { return await site.request<AuthStatus>('GET', '/api/cms/_auth/status') }
|
|
160
|
+
catch (err) {
|
|
161
|
+
last = err
|
|
162
|
+
// A refused connection or a start-up error: the site may still be coming up. A real answer (4xx) is final.
|
|
163
|
+
if (err instanceof HttpError && err.status < 500) throw err
|
|
164
|
+
if (Date.now() > until) break
|
|
165
|
+
await sleep(500)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const reason = last instanceof Error ? ((last as any).cause?.code ?? last.message) : String(last)
|
|
169
|
+
throw new SeedError(`The site at ${site.base} does not answer (${reason}). Start it first (pnpm dev), or pass --url.`)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function ask(question: string): Promise<string> {
|
|
173
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
174
|
+
try { return (await rl.question(question)).trim() }
|
|
175
|
+
finally { rl.close() }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface SeedConnection {
|
|
179
|
+
email?: string
|
|
180
|
+
password?: string
|
|
181
|
+
name: string
|
|
182
|
+
setupCode?: string
|
|
183
|
+
dryRun: boolean
|
|
184
|
+
/** Whether a person can be asked (a terminal). */
|
|
185
|
+
interactive: boolean
|
|
186
|
+
log: (line: string) => void
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Sign in, or set up the first administrator on a fresh site. Null: a dry run on a site with no account yet. */
|
|
190
|
+
export async function connect(site: SiteClient, c: SeedConnection, status: AuthStatus): Promise<'signed-in' | 'created' | null> {
|
|
191
|
+
if (status.mode !== 'builtin') {
|
|
192
|
+
throw new SeedError('This site signs people in with an external provider; the seed needs the CMS\'s own sign-in (it signs in with an email and a password).')
|
|
193
|
+
}
|
|
194
|
+
if (status.needsSetup) {
|
|
195
|
+
if (c.dryRun) return null
|
|
196
|
+
if (!c.email || !c.password) throw new SeedError('The site has no administrator yet. Set SEED_EMAIL (or --email) and SEED_PASSWORD: the seed creates the first account with them.')
|
|
197
|
+
let token = c.setupCode
|
|
198
|
+
if (status.needsToken && !token) {
|
|
199
|
+
const where = status.codeIn === 'log'
|
|
200
|
+
? 'The server printed it in its log when it started ("No administrator yet. Setup code: …")'
|
|
201
|
+
: 'It is the site\'s NUXT_CMS_AUTH_SETUP_TOKEN'
|
|
202
|
+
if (!c.interactive) throw new SeedError(`This site asks for its setup code before the first account. ${where}. Pass it with --setup-code or SEED_SETUP_CODE.`)
|
|
203
|
+
token = await ask(`Setup code (${where}): `)
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
await site.request('POST', '/api/cms/_auth/setup', { name: c.name, email: c.email, password: c.password, token: token || undefined })
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (err instanceof HttpError && err.status === 403) throw new SeedError('The setup code is missing or wrong.')
|
|
210
|
+
throw err
|
|
211
|
+
}
|
|
212
|
+
c.log(`✓ created the first administrator ${c.email}`)
|
|
213
|
+
return 'created'
|
|
214
|
+
}
|
|
215
|
+
if (!c.email || !c.password) throw new SeedError('Set SEED_EMAIL (or --email) and SEED_PASSWORD: an administrator of the site to sign in as.')
|
|
216
|
+
try {
|
|
217
|
+
await site.request('POST', '/api/cms/_auth/login', { email: c.email, password: c.password })
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
if (err instanceof HttpError && err.status === 401) throw new SeedError(`Wrong email or password for ${site.base}.`)
|
|
221
|
+
throw err
|
|
222
|
+
}
|
|
223
|
+
return 'signed-in'
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ── the command ─────────────────────────────────────────────────────────────────
|
|
227
|
+
|
|
228
|
+
/** The seed definition a file exports (`export default defineSeed(…)`). */
|
|
229
|
+
export async function loadSeed(file: string): Promise<SeedDefinition> {
|
|
230
|
+
const mod = await import(pathToFileURL(file).href)
|
|
231
|
+
const def = mod.default ?? mod.seed
|
|
232
|
+
if (isSeed(def)) return def
|
|
233
|
+
throw new SeedError(`${file} must export a seed: export default defineSeed(async (s) => { … })`)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const VERB: Record<string, [string, string]> = {
|
|
237
|
+
created: ['created', 'would create'], updated: ['updated', 'would update'], unchanged: ['unchanged', 'unchanged'],
|
|
238
|
+
kept: ['kept', 'would keep'], uploaded: ['uploaded', 'would upload'],
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function formatOp(op: SeedOp, dryRun: boolean): string {
|
|
242
|
+
const [done, would] = VERB[op.action]!
|
|
243
|
+
const verb = (dryRun ? would : done).padEnd(13)
|
|
244
|
+
const mark = op.action === 'unchanged' || op.action === 'kept' ? '·' : '✓'
|
|
245
|
+
return `${mark} ${verb}${op.label}${op.fields?.length && op.action === 'updated' ? ` (${op.fields.join(', ')})` : ''}`
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function summarize(ops: SeedOp[], dryRun: boolean): string {
|
|
249
|
+
const n = (a: string, kind?: SeedOp['kind']) => ops.filter((o) => o.action === a && (!kind || o.kind === kind)).length
|
|
250
|
+
const parts = [
|
|
251
|
+
[n('created'), dryRun ? 'to create' : 'created'],
|
|
252
|
+
[n('updated'), dryRun ? 'to update' : 'updated'],
|
|
253
|
+
[n('unchanged'), 'already up to date'],
|
|
254
|
+
[n('kept'), 'left as they are'],
|
|
255
|
+
].filter(([c]) => c as number > 0).map(([c, w]) => `${c} ${w}`)
|
|
256
|
+
const files = n('uploaded')
|
|
257
|
+
if (files) parts.push(`${files} ${dryRun ? 'files to upload' : files === 1 ? 'file uploaded' : 'files uploaded'}`)
|
|
258
|
+
return parts.length ? parts.join(', ') : 'nothing to do'
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Is this the machine itself: `localhost`, `*.localhost`, 127.0.0.1, ::1? Compared as a whole name, never as the start of one (`localhost.example.com` is somebody else's). */
|
|
262
|
+
export function isLocalHostname(hostname: string): boolean {
|
|
263
|
+
const h = hostname.toLowerCase().replace(/^\[|\]$/g, '')
|
|
264
|
+
return h === 'localhost' || h.endsWith('.localhost') || h === '127.0.0.1' || h === '::1'
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Does this address send the password over the internet unencrypted? (http:// to anything but the machine itself.) */
|
|
268
|
+
export function sendsPasswordInTheClear(base: string): boolean {
|
|
269
|
+
const url = new URL(base)
|
|
270
|
+
return url.protocol === 'http:' && !isLocalHostname(url.hostname)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function seedCommand(config: Record<string, any>, argv: string[], io: { log?: (line: string) => void; env?: NodeJS.ProcessEnv; cwd?: string } = {}): Promise<void> {
|
|
274
|
+
const log = io.log ?? ((line: string) => console.log(line))
|
|
275
|
+
const env = io.env ?? process.env
|
|
276
|
+
const cwd = io.cwd ?? process.cwd()
|
|
277
|
+
const args = parseArgs(argv, ['url', 'email', 'name', 'setup-code', 'wait'], ['reset', 'dry-run', 'yes', 'verbose'])
|
|
278
|
+
const dryRun = args.flags.has('dry-run')
|
|
279
|
+
const reset = args.flags.has('reset')
|
|
280
|
+
const verbose = args.flags.has('verbose')
|
|
281
|
+
|
|
282
|
+
const file = resolve(cwd, args.positional[0] ?? ['seed/index.ts', 'seed/index.mjs', 'seed/index.js'].find((f) => existsSync(resolve(cwd, f))) ?? 'seed/index.ts')
|
|
283
|
+
if (!existsSync(file)) {
|
|
284
|
+
throw new SeedError(`No seed file (${file}). Create seed/index.ts with: export default defineSeed(async (s) => { … })`)
|
|
285
|
+
}
|
|
286
|
+
const base = (args.values.url ?? env.SEED_URL ?? 'http://localhost:3000').replace(/\/+$/, '')
|
|
287
|
+
try { new URL(base) } catch { throw new SeedError(`"${base}" is not a web address; pass --url http://localhost:3000.`) }
|
|
288
|
+
if (sendsPasswordInTheClear(base)) {
|
|
289
|
+
log(`! ${base} is not encrypted: the password travels in the clear. Use https:// for a site on the internet.`)
|
|
290
|
+
}
|
|
291
|
+
if (args.values['setup-code']) log('! --setup-code shows in the process list (ps) while the command runs; set SEED_SETUP_CODE in the environment instead.')
|
|
292
|
+
|
|
293
|
+
const reg = buildRegistry(config)
|
|
294
|
+
const def = await loadSeed(file)
|
|
295
|
+
const site = new SiteClient(base)
|
|
296
|
+
const status = await waitForSite(site, Number(args.values.wait ?? 30) || 30)
|
|
297
|
+
const connected = await connect(site, {
|
|
298
|
+
email: args.values.email ?? env.SEED_EMAIL,
|
|
299
|
+
password: env.SEED_PASSWORD,
|
|
300
|
+
name: args.values.name ?? env.SEED_NAME ?? 'Admin',
|
|
301
|
+
setupCode: args.values['setup-code'] ?? env.SEED_SETUP_CODE ?? env.SEED_SETUP_TOKEN,
|
|
302
|
+
dryRun,
|
|
303
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
304
|
+
log,
|
|
305
|
+
}, status)
|
|
306
|
+
const backend = connected ? httpBackend(site) : emptyBackend()
|
|
307
|
+
if (!connected) log('· The site has no administrator yet: a real run creates the first one. Everything below is new.')
|
|
308
|
+
|
|
309
|
+
const print = (op: SeedOp) => { if (verbose || (op.action !== 'unchanged' && op.action !== 'kept')) log(formatOp(op, dryRun)) }
|
|
310
|
+
|
|
311
|
+
if (reset) {
|
|
312
|
+
const scanned = (await runSeed(def, { reg, backend, root: cwd, apply: false })).declared
|
|
313
|
+
const plan = await planReset(reg, backend, scanned)
|
|
314
|
+
const files = plan.media.length
|
|
315
|
+
const count = `${plan.entries.length} ${plan.entries.length === 1 ? 'entry' : 'entries'} and ${files} ${files === 1 ? 'file' : 'files'}`
|
|
316
|
+
if (dryRun) {
|
|
317
|
+
log(`· --reset would first remove ${count} the seed made${plan.blocked.length ? ' (but it cannot go through as things are)' : ''}.`)
|
|
318
|
+
for (const line of describeReset(plan, base)) log(line)
|
|
319
|
+
}
|
|
320
|
+
else if (plan.entries.length || plan.media.length || plan.blocked.length) {
|
|
321
|
+
log(`--reset removes ${count} this seed made on ${base}, then seeds again. Everything else stays.`)
|
|
322
|
+
for (const line of describeReset(plan, base)) log(line)
|
|
323
|
+
if (plan.blocked.length) throw new SeedError('Nothing was removed. Change what is listed above, or remove those entries by hand, and run it again.')
|
|
324
|
+
if (!args.flags.has('yes')) {
|
|
325
|
+
if (!process.stdin.isTTY) throw new SeedError('--reset deletes content: add --yes to confirm without a terminal.')
|
|
326
|
+
if (!/^y(es)?$/i.test(await ask('Remove them? [y/N] '))) throw new SeedError('Stopped; nothing was removed.')
|
|
327
|
+
}
|
|
328
|
+
const out = await resetDeclared(backend, plan, log)
|
|
329
|
+
log(`✓ removed ${out.entries} ${out.entries === 1 ? 'entry' : 'entries'} and ${out.media} ${out.media === 1 ? 'file' : 'files'}${out.keptMedia ? ` (${out.keptMedia} still in use stay)` : ''}`)
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
log('· Nothing of this seed is on the site yet; nothing to remove.')
|
|
333
|
+
for (const line of describeReset(plan, base)) log(line)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const result = await runSeed(def, { reg, backend, root: cwd, apply: !dryRun && Boolean(connected), onOp: print })
|
|
338
|
+
log(dryRun ? `Dry run, nothing written: ${summarize(result.ops, true)}.` : `✓ Seeded ${base}: ${summarize(result.ops, false)}.`)
|
|
339
|
+
}
|
package/cli/status.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tinyzoo status`: what the database in DATABASE_URL has applied and what is still to do.
|
|
3
|
+
* Exit code 0: nothing pending. 1: something is pending or out of order (usable in CI and
|
|
4
|
+
* deploy scripts). 2: the database could not be read.
|
|
5
|
+
*/
|
|
6
|
+
import { docsUrl } from '../src/docs'
|
|
7
|
+
import { inspectMigrations, ORDER_FIX, type MigrationStatus } from '../src/index'
|
|
8
|
+
import { databaseUrl, describeDatabase, diskSource, errorText, siteUpgradeSteps, withDatabase } from './db'
|
|
9
|
+
|
|
10
|
+
/** Whose step it is: tinyzoo's own, or the plugin named in front of the id. */
|
|
11
|
+
const stepOwner = (id: string) => (id.includes(':') ? id.slice(0, id.indexOf(':')) : 'tinyzoo')
|
|
12
|
+
|
|
13
|
+
/** The report as text, and whether everything is up to date. */
|
|
14
|
+
export function formatStatus(status: MigrationStatus): { text: string; clean: boolean } {
|
|
15
|
+
const lines: string[] = []
|
|
16
|
+
const pendingSteps = status.steps.filter((s) => s.state === 'pending')
|
|
17
|
+
const appliedSteps = status.steps.filter((s) => s.state === 'applied')
|
|
18
|
+
lines.push(`Migrations: ${status.applied.length} applied, ${status.pending.length} pending${status.freshInstall ? ' (empty database)' : ''}`)
|
|
19
|
+
for (const tag of status.pending) lines.push(` pending ${tag}`)
|
|
20
|
+
lines.push(`Upgrade steps: ${appliedSteps.length} applied, ${pendingSteps.length} pending`)
|
|
21
|
+
for (const s of pendingSteps) lines.push(` pending ${s.id} (${stepOwner(s.id)} ${s.since}) — ${s.description}${status.freshInstall ? ' [recorded without running on an empty database]' : ''}`)
|
|
22
|
+
if (status.outOfOrder.length) {
|
|
23
|
+
lines.push('', 'Out of order — these migrations were never applied, yet a newer one was, so they would be skipped:')
|
|
24
|
+
for (const tag of status.outOfOrder) lines.push(` ✗ ${tag}.sql`)
|
|
25
|
+
const files = status.outOfOrder.map((t) => `${t}.sql`).join(', ')
|
|
26
|
+
lines.push(` ${ORDER_FIX.regenerate(files)}`, ` ${ORDER_FIX.appliedElsewhere}`, ` More: ${docsUrl('neverApplied')}`)
|
|
27
|
+
}
|
|
28
|
+
if (status.unknown) lines.push('', `Note: the database has ${status.unknown} migration${status.unknown > 1 ? 's' : ''} this code does not know — a newer version of the site ran here.`)
|
|
29
|
+
const clean = !status.pending.length && !pendingSteps.length && !status.outOfOrder.length
|
|
30
|
+
lines.push('', clean ? '✓ up to date' : '✗ not up to date — run `tinyzoo up`, or start the app with NUXT_CMS_MIGRATIONS_ON_START=true')
|
|
31
|
+
return { text: lines.join('\n'), clean }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Returns the process exit code. */
|
|
35
|
+
export async function status(cwd: string): Promise<number> {
|
|
36
|
+
try {
|
|
37
|
+
const url = databaseUrl(cwd)
|
|
38
|
+
const source = diskSource(cwd)
|
|
39
|
+
const steps = await siteUpgradeSteps(cwd)
|
|
40
|
+
const result = await withDatabase(url, ({ run }) => inspectMigrations(source, run, steps))
|
|
41
|
+
const { text, clean } = formatStatus(result)
|
|
42
|
+
console.log(`Database: ${describeDatabase(url)}\n${text}`)
|
|
43
|
+
return clean ? 0 : 1
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.error(`✗ could not read the database: ${errorText(err)}`)
|
|
47
|
+
return 2
|
|
48
|
+
}
|
|
49
|
+
}
|