-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add non-studio app template
- Loading branch information
1 parent
3c3fa08
commit c90602e
Showing
11 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/@sanity/cli/src/actions/init-project/templates/coreApp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {type ProjectTemplate} from '../initProject' | ||
|
||
const coreAppTemplate: ProjectTemplate = { | ||
scripts: { | ||
dev: 'vite', | ||
build: 'vite build', | ||
preview: 'vite preview', | ||
}, | ||
dependencies: { | ||
'react': '^19', | ||
'react-dom': '^19', | ||
'@sanity/sdk': '^0.0.0-alpha', | ||
'@sanity/sdk-react': '^0.0.0-alpha', | ||
}, | ||
devDependencies: { | ||
'vite': '^6', | ||
'@vitejs/plugin-react': '^4.3.4', | ||
}, | ||
} | ||
|
||
export default coreAppTemplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {createSanityInstance} from '@sanity/sdk' | ||
import {SanityProvider} from '@sanity/sdk-react/context' | ||
import {useCurrentUser, useLogOut} from '@sanity/sdk-react/hooks' | ||
import {Button, Flex, Spinner, Text, ThemeProvider} from '@sanity/ui' | ||
import {buildTheme} from '@sanity/ui/theme' | ||
import {Suspense} from 'react' | ||
|
||
const theme = buildTheme({}) | ||
const sanityInstance = createSanityInstance({ | ||
projectId: '<your-project-id>', | ||
dataset: '<your-dataset>', | ||
// optional auth config set projectId and dataset to '' and authScope to 'org' for a global token | ||
// auth: { | ||
// authScope: 'org', | ||
// ... | ||
// }, | ||
}) | ||
|
||
export function App() { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Suspense fallback={<Spinner />}> | ||
<SanityProvider sanityInstance={sanityInstance}> | ||
{/* You will need to implement an auth boundary */} | ||
<AuthBoundary header={<Text>My Sanity App</Text>}> | ||
<Authenticated /> | ||
</AuthBoundary> | ||
</SanityProvider> | ||
</Suspense> | ||
</ThemeProvider> | ||
) | ||
} | ||
|
||
function Authenticated() { | ||
const currentUser = useCurrentUser() | ||
const logout = useLogOut() | ||
|
||
return ( | ||
<Flex direction="column" gap={2}> | ||
<Text>Hello, {currentUser?.name}!</Text> | ||
<Button text="Logout" onClick={logout} mode="ghost" /> | ||
</Flex> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { StrictMode } from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import App from './App.tsx' | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vite.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters