diff --git a/README.md b/README.md index ebe56877..cb099b1b 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,10 @@ npx @sanity/plugin-kit init sanity-plugin-testing-it-out cd sanity-plugin-testing-it-out npm run link-watch -# In another shell, link the plugin to your Sanity studio +# In another shell, link the plugin to your Sanity studio using the command indicated by link-watch cd /path/to/my-studio -yalc add --link sanity-plugin-testing-it-out && yarn install +npx yalc add sanity-plugin-testing-it-out && npx yalc link sanity-plugin-testing-it-out && npm install + ``` Now, configure the plugin in sanity.config.ts (or .js) in Sanity Studio: diff --git a/src/actions/link-watch.ts b/src/actions/link-watch.ts index 6eeb8aa9..158a2ed1 100644 --- a/src/actions/link-watch.ts +++ b/src/actions/link-watch.ts @@ -25,6 +25,7 @@ import path from 'path' import log from '../util/log' import {getPackage} from '../npm/package' import outdent from 'outdent' +import {fileExists, mkdir} from '../util/files' interface YalcWatchConfig { folder?: string @@ -38,7 +39,7 @@ interface PackageJson { export async function linkWatch({basePath}: {basePath: string}) { const packageJson: PackageJson = JSON.parse( - fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8') + fs.readFileSync(path.join(basePath, 'package.json'), 'utf8') ) const watch: Required = { @@ -55,8 +56,16 @@ export async function linkWatch({basePath}: {basePath: string}) { //delay: 1000 }) + // ensure the folder exits so it can be watched + const folder = path.join(basePath, watch.folder) + if (!(await fileExists(folder))) { + await mkdir(folder) + } + const pkg = await getPackage({basePath, validate: false}) + concurrently([watch.command]) + nodemon .on('start', function () { log.info( @@ -75,6 +84,4 @@ export async function linkWatch({basePath}: {basePath: string}) { log.info('Found changes in files:', chalk.magentaBright(files)) log.info('Pushing new yalc package...') }) - - concurrently([watch.command]) }