Astro Schematics CLI is here to make your life easier by taking care of repetitive tasks. With it, you can quickly create components, layouts, and pages for your Astro projects. This magic is brought to you by Project Builder.
Just run this command in your project folder:
npx @pbuilder/cli add @pbuilder/astro
-
Installing the CLI: When you run the above command, it might ask if you want to install something called a CLI (Command Line Interface). Here’s why you should say yes:
-
@pbuilder/astro-cli
(or pastro): This special tool is made just for Astro. It makes making new parts of your website (like pages and components) super easy with simple commands. - Learning More: If you're curious about what commands you can do, just add --help to see all your options.
-
Want to make a new component? Easy peasy:
pastro g c <component-name>
Or:
npx @pbuilder/astro-cli g c <component-name>
Need a new layout? Just as easy:
pastro g l <layout-name>
Alternatively:
npx @pbuilder/astro-cli g l <layout-name>
For page creation, specify the type (astro is the default one) and layout:
pastro g pg <page-name> --type [md, mdx, astro] --layout <layout file name>
Or use the direct method:
npx @pbuilder/astro-cli g pg <page-name> --type [md, mdx, astro] --layout <layout file name>
Sometimes, you might need a tool that isn't just for Astro. That’s where @pbuilder/cli
comes in. It’s a more general tool that works for a bunch of different projects.
Here’s how you use it:
npx @pbuilder/cli exec @pbuilder/astro <schematic-name> --name=<name> [options]
Like making a component without the Astro-specific tool:
npx @pbuilder/cli exec @pbuilder/astro c --name=MyComponent2