-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecf470d
commit 776950e
Showing
6 changed files
with
98 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Preset: ui | ||
|
||
## Usage | ||
|
||
### Inject into existing package | ||
|
||
`npx @sanity/plugin-kit inject --preset-only --preset ui` | ||
|
||
### Use to init plugin | ||
|
||
`npx @sanity/plugin-kit init --preset ui <new-plugin-name>` | ||
|
||
## What does it do? | ||
|
||
Sets up your package with [`@sanity/ui`](https://github.com/sanity-io/ui) to build plugin UIs. | ||
|
||
- Adds [`@sanity/ui`](https://github.com/sanity-io/ui) dependency. | ||
- Add required dev and peer dependencies. | ||
|
||
## Manual steps after inject | ||
|
||
- Run `npm i` to install dependencies. | ||
- Refer to @sanity/ui [README](https://github.com/sanity-io/ui) for more. |
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
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,68 @@ | ||
import {Preset} from './presets' | ||
import {InjectOptions} from '../actions/inject' | ||
import {forceDependencyVersions, getPackage, sortKeys, writePackageJsonDirect} from '../npm/package' | ||
import log from '../util/log' | ||
import chalk from 'chalk' | ||
import {resolveLatestVersions} from '../npm/resolveLatestVersions' | ||
import {forcedDevPackageVersions, forcedPackageVersions} from '../configs/forced-package-versions' | ||
|
||
export const ui: Preset = { | ||
name: 'ui', | ||
description: '`@sanity/ui` and dependencies', | ||
apply: applyPreset, | ||
} | ||
|
||
async function applyPreset(options: InjectOptions) { | ||
await addDependencies(options) | ||
await addDevDependencies(options) | ||
|
||
log.info(chalk.green('ui preset injected')) | ||
} | ||
|
||
async function addDependencies(options: InjectOptions) { | ||
const pkg = await getPackage(options) | ||
const newDeps = sortKeys( | ||
forceDependencyVersions( | ||
{ | ||
...pkg.dependencies, | ||
...(await resolveDependencyList()), | ||
}, | ||
forcedPackageVersions | ||
) | ||
) | ||
const newPkg = {...pkg} | ||
newPkg.dependencies = newDeps | ||
await writePackageJsonDirect(newPkg, options) | ||
log.info('Updated dependencies.') | ||
} | ||
|
||
async function addDevDependencies(options: InjectOptions) { | ||
const pkg = await getPackage(options) | ||
const newDeps = sortKeys( | ||
forceDependencyVersions( | ||
{ | ||
...pkg.devDependencies, | ||
...(await resolveDevDependencyList()), | ||
}, | ||
forcedDevPackageVersions | ||
) | ||
) | ||
const newPkg = {...pkg} | ||
newPkg.devDependencies = newDeps | ||
await writePackageJsonDirect(newPkg, options) | ||
log.info('Updated devDependencies.') | ||
} | ||
|
||
async function resolveDependencyList(): Promise<Record<string, string>> { | ||
return resolveLatestVersions(['@sanity/icons', '@sanity/ui']) | ||
} | ||
|
||
async function resolveDevDependencyList(): Promise<Record<string, string>> { | ||
return resolveLatestVersions([ | ||
// install the peer dependencies of `@sanity/ui` as dev dependencies | ||
'react', | ||
'react-dom', | ||
'react-is', | ||
'styled-components', | ||
]) | ||
} |