Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add support for remote templates with --template #7867

Open
wants to merge 34 commits into
base: next
Choose a base branch
from

Conversation

RostiMelk
Copy link
Member

@RostiMelk RostiMelk commented Nov 22, 2024

Introducing Support for Remote Templates in --template Flag

What is a remote template?

A remote template is really any GitHub repo that passes a given set of requirements.
The requirements are:

Monorepo Repositories

  1. package.json

    • Each package must have a valid package.json.
    • At least one package must include sanity in its dependencies or devDependencies.
  2. Sanity Configuration Files

    • At least one package must include both sanity.config.js/ts and sanity.cli.js/ts.
  3. Environment Template Files

    • Each package must have at least one of the following:
      • .env.template
      • .env.example
      • .env.local.example

Single-Package Repositories

  1. package.json

    • The repository must have a valid package.json with sanity listed in dependencies or devDependencies.
  2. Sanity Configuration Files

    • The repository must include both sanity.config.js/ts and sanity.cli.js/ts.
  3. Environment Template File

    • The repository must have one of the following:
      • .env.template
      • .env.example
      • .env.local.example

Environment Variables

For both monorepos and single-package repositories, the environment file must include in all packages:

  • SANITY_PROJECT_ID or SANITY_STUDIO_PROJECT_ID
  • SANITY_DATASET or SANITY_STUDIO_DATASET

If any of these criteria are not met, the validation will fail with a detailed error message.

What to review

  • Make sure running --template flag works for both built in schema type templates and remote templates
  • Are there any other template validations that should be added?
  • Is the testing sufficient?
  • Implementation in general

Testing

Shorthand Example

npm create@latest sanity --template SimeonGriggs/sanity-remix-template

GitHub URL

npm create@latest sanity --template https://github.com/SimeonGriggs/sanity-remix-template

Nested Directory in a Repository

npm create@latest sanity --template sanity-io/sanity/templates/next-js

Notes for release

No notes afaik for now

@RostiMelk RostiMelk requested a review from a team as a code owner November 22, 2024 15:21
@RostiMelk RostiMelk requested review from juice49 and removed request for a team November 22, 2024 15:21
Copy link

vercel bot commented Nov 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2024 10:18am
performance-studio ✅ Ready (Inspect) Visit Preview Nov 27, 2024 10:18am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2024 10:18am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2024 10:18am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2024 10:18am

@RostiMelk RostiMelk marked this pull request as draft November 22, 2024 15:21
@vercel vercel bot temporarily deployed to Preview – page-building-studio November 22, 2024 15:24 Inactive
@vercel vercel bot temporarily deployed to Preview – test-next-studio November 22, 2024 15:24 Inactive
@RostiMelk RostiMelk changed the title Feat(CLI): Add support for remote templates with --template feat(cli): add support for remote templates with --template Nov 22, 2024
Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Nov 22, 2024

Component Testing Report Updated Nov 25, 2024 3:23 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 46s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 31s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 39s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 10s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 2m 32s 1 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 47s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 48s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 19s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 9s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 28s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 19s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 37s 12 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Nov 22, 2024

⚡️ Editor Performance Report

Updated Mon, 25 Nov 2024 15:25:10 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 17.2 efps (58ms) 23.8 efps (42ms) -16ms (-27.6%)
article (body) 58.1 efps (17ms) 62.9 efps (16ms) -1ms (-7.6%)
article (string inside object) 18.3 efps (55ms) 26.0 efps (39ms) -16ms (-29.4%)
article (string inside array) 16.1 efps (62ms) 21.7 efps (46ms) -16ms (-25.8%)
recipe (name) 28.6 efps (35ms) 46.5 efps (22ms) -14ms (-38.6%)
recipe (description) 31.3 efps (32ms) 52.6 efps (19ms) -13ms (-40.6%)
recipe (instructions) 99.9+ efps (7ms) 99.9+ efps (7ms) +0ms (-/-%)
synthetic (title) 14.0 efps (72ms) 18.5 efps (54ms) -18ms (-24.5%)
synthetic (string inside object) 14.4 efps (70ms) 18.9 efps (53ms) -17ms (-23.7%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 58ms 62ms 72ms 210ms 458ms 14.3s
article (body) 17ms 21ms 32ms 131ms 324ms 5.9s
article (string inside object) 55ms 57ms 62ms 219ms 259ms 8.7s
article (string inside array) 62ms 66ms 78ms 337ms 705ms 9.5s
recipe (name) 35ms 39ms 50ms 112ms 39ms 9.8s
recipe (description) 32ms 33ms 39ms 71ms 0ms 6.2s
recipe (instructions) 7ms 9ms 12ms 50ms 3ms 3.6s
synthetic (title) 72ms 78ms 90ms 413ms 1666ms 15.7s
synthetic (string inside object) 70ms 73ms 83ms 228ms 1385ms 10.0s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 42ms 45ms 55ms 198ms 204ms 12.2s
article (body) 16ms 18ms 22ms 62ms 216ms 5.5s
article (string inside object) 39ms 42ms 48ms 225ms 259ms 6.8s
article (string inside array) 46ms 50ms 58ms 184ms 171ms 7.3s
recipe (name) 22ms 23ms 28ms 52ms 0ms 17.3s
recipe (description) 19ms 22ms 23ms 32ms 0ms 4.9s
recipe (instructions) 7ms 9ms 10ms 52ms 14ms 3.5s
synthetic (title) 54ms 58ms 63ms 121ms 390ms 12.6s
synthetic (string inside object) 53ms 58ms 67ms 466ms 1032ms 8.4s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

'--dataset',
testRunArgs.dataset,
'--template',
'https://github.com/SimeonGriggs/sanity-remix-template',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to replace this with something on our org

@@ -1117,6 +1093,58 @@ export default async function initSanity(
})
}

async function updateProjectCliInitializedMetadata() {
Copy link
Member Author

@RostiMelk RostiMelk Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were defined in an array of promises. I've just defined them further down in the code as functions, but still call them in the same place as we did previously. See L622 & L623

@@ -0,0 +1,9 @@
import {type SanityUser} from '../types'

export function getProviderName(provider: SanityUser['provider']) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this for intro message

@joneidejohnsen joneidejohnsen requested a review from a team November 29, 2024 11:42
pathSegments.length >= 2 &&
(pathSegments.length > 2 ? pathSegments[2] === 'tree' && pathSegments.length >= 4 : true)
)
} catch (_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If unused we can decide to not bind an error:
catch { ...


const INITIAL_COMMIT_MESSAGE = 'Initial commit from Sanity CLI'

export async function bootstrapRemoteTemplate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly seeing the pipeline of things that need to be done serially here but unsure how failure of this half-way would look. We have a pattern of showing the error messages in the cli but if this partially completes, it might be confusing to users to know how to proceed if they have the repo down but were unable to have any of the files edited. Perhaps some try/catch around groups of this where the errors are still thrown to be printed on the cli but have some surrounding context like "Unable to edit newly downloaded files in [folder]/. See documentation on updating files from a template: some-docs link" or something else could be helpful in getting people un-stuck at certain points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants