Skip to content

Commit

Permalink
feat: add cliInitializedAt field to project metadata (#6538)
Browse files Browse the repository at this point in the history
* feat: add cliInitializedAt field to project metadata

* feat: send cliInitializedAt only once
  • Loading branch information
svirs committed May 3, 2024
1 parent 154d90b commit 15486f7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/@sanity/cli/src/actions/init-project/initProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {existsSync, readFileSync} from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'

import {type DatasetAclMode} from '@sanity/client'
import {type DatasetAclMode, type SanityProject} from '@sanity/client'
import {type Framework} from '@vercel/frameworks'
import dotenv from 'dotenv'
import execa, {type CommonOptions} from 'execa'
Expand Down Expand Up @@ -610,6 +610,21 @@ export default async function initSanity(
print(`sanity help - to explore the CLI manual`)
}

try {
const client = apiClient({api: {projectId: projectId}})
const project = await client.request<SanityProject>({uri: `/projects/${projectId}`})
if (!project?.metadata?.cliInitializedAt) {
await apiClient({api: {projectId}}).request({
method: 'PATCH',
uri: `/projects/${projectId}`,
body: {metadata: {cliInitializedAt: new Date().toISOString()}},
})
}
} catch (err: unknown) {
// Non-critical update
debug('Failed to update cliInitializedAt metadata')
}

const sendInvite =
isFirstProject &&
(await prompt.single({
Expand Down

0 comments on commit 15486f7

Please sign in to comment.