CLI commands
So I want to occasionally run CLI commands to pull the latest videos from my YouTube channel, and create content entries with each video.
What would be the best way to do this? I did create a simple JS script, but wondered if there was something more Nuxt native?
I come from the Laravel world, where everything is an artisan command away
5 Replies
Hi @JustSteveKing. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Nuxt does not have a direct equivalent to Laravel's artisan commands for custom CLI tasks out of the box. The built-in Nuxt CLI (nuxi/nuxt) provides commands for scaffolding, building, generating, and managing your application, but it does not natively support user-defined custom CLI commands for tasks like fetching YouTube videos and creating content entries.
However, you do have a few Nuxt-native options:
1. Use the Nuxt Content Module
If you want to create content entries, you can use the Nuxt Content module to manage markdown or JSON files. Your script that fetches YouTube videos and writes content files is still the right approach, but you can place it in a scripts/ directory and run it with node as needed. 2. Leverage the nuxi add Command (for Scaffolding)
The nuxi add command can scaffold new files (pages, components, composables, etc.), but it does not support arbitrary user-defined commands or tasks like fetching external data or running custom scripts. It is mainly for generating Nuxt-specific boilerplate files, not for running custom logic like Laravel's artisan commands nuxt add command. 3. Custom Node Scripts
The most Nuxt-native way, for now, is to keep your custom JS script and run it with node. You can add a script entry in your package.json for convenience, e.g.: Then run it with: 4. No Built-in Custom Command System
There is no built-in Nuxt CLI extension point for custom commands like Laravel's artisan. The CLI is focused on Nuxt-specific tasks (build, generate, add, etc.) Nuxt API Reference. Summary:
Your current approach (a custom JS script) is the recommended way in the Nuxt ecosystem for now. There is no direct Nuxt-native alternative for custom CLI commands like Laravel artisan, but you can integrate your script into your workflow using npm scripts for convenience. If you want to automate this further, consider running your script as part of a CI/CD pipeline or as a postinstall hook, but the script itself will remain a standard Node.js script, not a Nuxt CLI extension. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
If you want to create content entries, you can use the Nuxt Content module to manage markdown or JSON files. Your script that fetches YouTube videos and writes content files is still the right approach, but you can place it in a scripts/ directory and run it with node as needed. 2. Leverage the nuxi add Command (for Scaffolding)
The nuxi add command can scaffold new files (pages, components, composables, etc.), but it does not support arbitrary user-defined commands or tasks like fetching external data or running custom scripts. It is mainly for generating Nuxt-specific boilerplate files, not for running custom logic like Laravel's artisan commands nuxt add command. 3. Custom Node Scripts
The most Nuxt-native way, for now, is to keep your custom JS script and run it with node. You can add a script entry in your package.json for convenience, e.g.: Then run it with: 4. No Built-in Custom Command System
There is no built-in Nuxt CLI extension point for custom commands like Laravel's artisan. The CLI is focused on Nuxt-specific tasks (build, generate, add, etc.) Nuxt API Reference. Summary:
Your current approach (a custom JS script) is the recommended way in the Nuxt ecosystem for now. There is no direct Nuxt-native alternative for custom CLI commands like Laravel artisan, but you can integrate your script into your workflow using npm scripts for convenience. If you want to automate this further, consider running your script as part of a CI/CD pipeline or as a postinstall hook, but the script itself will remain a standard Node.js script, not a Nuxt CLI extension. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@533726823201243137> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Maybe you can use https://nitro.build/guide/tasks
Tasks - Nitro
Nitro tasks allow on-off operations in runtime.
I don’t know if I really understand your question 😅
I think that might do the trick!