-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
Problem
As a full-stack Nuxt developer, I would like to have a way to execute commands within Nuxt's compilation context (with all imports and aliases functioning identically to Nuxt server code). A common use case would be running database migration scripts with arguments (e.g., migrate up
, migrate rollback
). Another example is running a development-time script to populate/update server assets (e.g. download and parse some external database, using common code and types under server/
).
Current workaround
Currently, what I do is:
- Create a special API endpoint (e.g.,
/api/scripts/migrate
) - Make it parse HTTP POST data to handle migration commands
- Add security with a secret token (disable checks in dev mode for convenience)
- Create a npm script that hardcodes certain port:
{
"scripts": {
"migrate": "curl localhost:3000/api/scripts/migrate -d"
}
}
This approach is cumbersome and introduces unnecessary complexity.
Proposed solution
- In dev mode:
nuxt run migrate -- up
(executingserver/scripts/migrate.ts
) - In production mode:
nuxt build
would either compile each script to a separate entrypoint (such as.output/scripts/migrate.js
), or perhaps the singleserver.js
could run scripts withnode .output/server.js run migrate -- up
.
I had long assumed #62 was meant to cover this use case, only to discover (after its closing) that it never actually had ;-)
Additional information
- Would you be willing to help implement this feature?
- Could this feature be implemented as a module?
Final checks
- Read the contribution guide.
- Check existing discussions and issues.
Metadata
Metadata
Assignees
Labels
No labels