Skip to content

Commit

Permalink
feat!: studio v3 version
Browse files Browse the repository at this point in the history
BREAKING CHANGE: No longer works in Studio V3
  • Loading branch information
snorrees committed Jun 15, 2022
1 parent 3e0f201 commit b96bc92
Show file tree
Hide file tree
Showing 31 changed files with 20,707 additions and 28,877 deletions.
13 changes: 13 additions & 0 deletions .eslintignore
@@ -0,0 +1,13 @@
.eslintrc.js
commitlint.config.js
lib
lint-staged.config.js
rollup.config.js
node_modules
tools/
docs
jest.config.js
babel.config.js
coverage
*.md
*.js
45 changes: 45 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,45 @@
module.exports = {
env: {
browser: true,
node: false,
jest: true,
},
extends: [
'sanity/react', // must come before sanity/typescript
'sanity/typescript',
'plugin:prettier/recommended',
'plugin:react-hooks/recommended',
],
overrides: [
{
files: ['*.{ts,tsx}'],
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.json',
},
plugins: ['prettier'],
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': 1,
'no-shadow': 'off',
'react/display-name': 0,
'react/jsx-no-bind': 0,
'react/jsx-handler-names': 0,
'react/no-array-index-key': 0,
},
settings: {
'import/ignore': ['\\.css$', '.*node_modules.*', '.*:.*'],
'import/resolver': {
node: {
paths: ['src'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
}
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,27 @@
name: CI
on:
- push
- pull_request
jobs:
test:
runs-on: ${{ matrix.platform }}
name: Node.js ${{ matrix.node-version }} / ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
node-version:
- 16
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run lint
- run: npm run build
#- run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,5 @@ compiled
.awcache
.rpt2_cache
docs
lib
.parcel-cache
4 changes: 4 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ""
4 changes: 4 additions & 0 deletions .husky/pre-commit
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.2.2](https://github.com/sanity-io/sanity-plugin-asset-source-unsplash/compare/v0.2.1...v0.2.2) (2022-05-05)


### Features

* v3 upgrade ([e3d1bdb](https://github.com/sanity-io/sanity-plugin-asset-source-unsplash/commit/e3d1bdbb38a8764e0cf89f6e61feb9e06cf0379d))
98 changes: 74 additions & 24 deletions README.md
@@ -1,44 +1,67 @@
# Sanity Asset Source Plugin: Unsplash

> **NOTE**
>
> This is the **Sanity Studio v3 version** of sanity-plugin-asset-source-unsplash.
>
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-asset-source-unsplash).
## What is it?
Search for photos on Unsplash and add them to your project right inside Sanity Studio.

[![Build Status](https://travis-ci.org/sanity-io/sanity-plugin-asset-source-unsplash.svg?branch=master)](https://travis-ci.org/sanity-io/sanity-plugin-asset-source-unsplash)
![Unsplash image selector](assets/unsplash-selector.png)

## Installation

`sanity install asset-source-unsplash`

## Part name
`npm install --save sanity-plugin-asset-source-unsplash@studio-v3`

If you need to do customize available asset sources, the plugin part name for this asset source is:
or

`part:sanity-plugin-asset-source-unsplash/image-asset-source`
`yarn add sanity-plugin-asset-source-unsplash@studio-v3`

## Developing on this module
## Usage

To simulate using your development version as a real module inside a studio, you can do the following:
Add it as a plugin in sanity.config.ts (or .js):

* Run `npm install && npm link` from the root of this repository.
* Run `npm run watch` to start developing and build the module when changes are made.
```js
import { unsplashImageAsset } from "sanity-plugin-asset-source-unsplash";

#### Displaying your development version inside a studio
export default createConfig({
// ...
plugins: [
unsplashImageAsset(),
]
})
```

**With the mono-repo's `test-studio`:**
This will add [unsplashAssetSource](src/index.ts) to all image-fields in Sanity Studio

* Bootstrap the monorepo: `npm run bootstrap`
* Add `sanity-plugin-asset-source-unsplash` with the current version number to `package.json` in the `test-studio` root folder (but don't run `npm install` afterwards)
* Run `npm link sanity-plugin-asset-source-unsplash` inside the mono-repo's root.
* Add `asset-source-unsplash` to the list of the studios plugins in `sanity.json`.
* Restart the `test-studio`
### Manually configure asset sources

**With a regular Sanity Studio:**
* Run `npm install`
* Add `sanity-plugin-asset-source-unsplash` with the current version number to `package.json`.
* Run `npm link sanity-plugin-asset-source-unsplash`
* Add `asset-source-unsplash` to the list of the studios plugins in `sanity.json`.
* Start the studio
If you need to configure when Unsplash should be available as an asset source, filter it out as needed in
`formbuilder.image.assetSources`:

When you are done and have published your new version, you can run `npm unlink` inside this repo, and `npm unlink sanity-plugin-asset-source-unsplash` inside the mono-repo or studio to get back to the normal state. Then run `npm run bootstrap` for the mono-repo or `npm install` inside the regular studio to use the published version.
```js
import { unsplashImageAsset, unsplashAssetSource } from "sanity-plugin-asset-source-unsplash";

export default createConfig({
// ...
plugins: [
unsplashImageAsset(),
],
formBuilder: {
image: {
assetSources: (previousAssetSources, {schema}) => {
if (schema.name === 'movie-image') {
// remove unsplash from movie-image types
return previousAssetSources.filter(assetSource => assetSource !== unsplashAssetSource)
}
return previousAssetSources
},
},
},
})
```

## Example Unsplash API Photo result

Expand Down Expand Up @@ -206,5 +229,32 @@ When you are done and have published your new version, you can run `npm unlink`
* https://unsplash.com/documentation
* https://www.sanity.io/docs/custom-asset-sources

## License

MIT-licensed. See LICENSE.

## Develop & test

Make sure to run `npm run build` once, then run

```bash
npm run link-watch
```

In another shell, `cd` to your test studio and run:

```bash
npx yalc add sanity-plugin-asset-source-unsplash --link && yarn install
```

Now, changes in this repo will be automatically built and pushed to the studio,
triggering hotreload. Yalc avoids issues with react-hooks that are typical when using yarn/npm link.

### About build & watch

This plugin uses [@sanity/plugin-sdk](https://github.com/sanity-io/plugin-sdk)
with default configuration for build & watch scripts.




Binary file added assets/unsplash-selector.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions commitlint.config.js
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
}
21 changes: 0 additions & 21 deletions jest.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions lint-staged.config.js
@@ -0,0 +1,4 @@
module.exports = {
'**/*.{js,jsx}': ['eslint'],
'**/*.{ts,tsx}': ['eslint', () => 'tsc --noEmit'],
}

0 comments on commit b96bc92

Please sign in to comment.