vovk dev
$ npx vovk dev --help
Usage: vovk dev|d [options] [nextArgs...]
Start schema watcher (optional flag --next-dev to start it with Next.js)
Arguments:
nextArgs extra arguments for the dev command
Options:
--next-dev start schema watcher and Next.js with automatic port allocation
--exit kill the processes when schema and client is generated
--schema-out <path> path to schema output directory (default: .vovk-schema)
--https, --dev-https use HTTPS for the dev server (default: false)
-h, --help display help for command
The vovk dev
command runs a script that watches for changes at controllers and updates the schema and the client accordingly if needed by making HTTP GET requests to /api/<segment-name>/_schema_
where <segment-name>
is the name of the segment being affected. If schema is changed the watcher updates the schema JSON files and the client modules.
How it works
vovk dev
andnext dev
are run together with concurrentlyΒ .vovk dev
watches for changes at /src/modules folder (can be configured withmodulesDir
config option).- When a change is detected, the script checks if the file contains a controller and if it belongs to a segment by making some simple RegExp checks.
- If the file is a controller and belongs to a segment, the script sends a GET request to
/api/<segment-name>/_schema_
to get the updated schema. - The script checks if the schema is changed and if so:
- If list of controllers is changed (added, removed, renamed), or method definition (including validation) is changed, the script updates the schema by saving it to .vovk-schema folder as a .json file making it fast to serialize and import after.
- If list of controllers is changed (added, removed, renamed), the script updates the client. The client imports the schema in order build the exported library properly. The client is generated at node_modules/.vovk-client folder and is re-exported by vovk-client package.
Since vovk dev
command is expected to be run together with Next.js dev server, it can be run two ways, both of them involve concurrentlyΒ :
- Explicit way. This way might be pleasant for those who want to have less abstraction. The downside of this option is that you need to define the
PORT
variable explicitly:
PORT=3000 npx concurrently 'vovk dev' 'next dev' --kill-others
At this case next dev
flags can be defined as expected:
PORT=3000 npx concurrently 'vovk dev --https' 'next dev --experimental-https --turbo' --kill-others
- Implicit way. At this case the port is assigned automatically and checks if a port (3000 by default) is already in use and attempts to find the next available one:
npx vovk dev --next-dev
In order to define additional flags to next dev
you can pass them after --
:
npx vovk dev --https --next-dev -- --experimental-https --turbo
Behind the scenes the implicit way uses concurrently API making both approaches almost identical.
Read more about HTTPS in development.
When vovk init is used, the dev
script is modified at the package.json
file preserving the previous value flags.
{
"scripts": {
// was
// "dev": "next dev --experimental-https --turbo",
// becomes
"dev": "vovk dev --next-dev -- --experimental-https --turbo"
}
}
Run and exit
--exit
flag can be used to kill the process created by vovk dev
after the schema and the client were generated. This is useful when you want to run the script once and donβt want to keep it running.
npx vovk dev --next-dev --exit
You can create a separate script in package.json
for this purpose:
{
"scripts": {
// ...
"dev-exit": "vovk dev --next-dev --exit",
// or
"dev-exit": "PORT=3000 concurrently 'vovk dev --exit' 'next dev' --kill-others"
}
}