-
Notifications
You must be signed in to change notification settings - Fork 430
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
base: next
Are you sure you want to change the base?
Conversation
Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
--template
--template
No changes to documentation |
Component Testing Report Updated Nov 25, 2024 3:23 PM (UTC) ✅ All Tests Passed -- expand for details
|
⚡️ Editor Performance ReportUpdated Mon, 25 Nov 2024 15:25:10 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
'--dataset', | ||
testRunArgs.dataset, | ||
'--template', | ||
'https://github.com/SimeonGriggs/sanity-remix-template', |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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']) { |
There was a problem hiding this comment.
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
pathSegments.length >= 2 && | ||
(pathSegments.length > 2 ? pathSegments[2] === 'tree' && pathSegments.length >= 4 : true) | ||
) | ||
} catch (_) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
Introducing Support for Remote Templates in
--template
FlagWhat is a remote template?
A remote template is really any GitHub repo that passes a given set of requirements.
The requirements are:
Monorepo Repositories
package.json
package.json
.sanity
in itsdependencies
ordevDependencies
.Sanity Configuration Files
sanity.config.js/ts
andsanity.cli.js/ts
.Environment Template Files
.env.template
.env.example
.env.local.example
Single-Package Repositories
package.json
package.json
withsanity
listed independencies
ordevDependencies
.Sanity Configuration Files
sanity.config.js/ts
andsanity.cli.js/ts
.Environment Template File
.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
orSANITY_STUDIO_PROJECT_ID
SANITY_DATASET
orSANITY_STUDIO_DATASET
If any of these criteria are not met, the validation will fail with a detailed error message.
What to review
--template
flag works for both built in schema type templates and remote templatesTesting
Shorthand Example
GitHub URL
Nested Directory in a Repository
Notes for release
No notes afaik for now