Ir al contenido

CLI Commands

Esta página aún no está disponible en tu idioma.

strapi2front provides a CLI for initializing projects and generating code from your Strapi schema.

Terminal window
npm install -D strapi2front

Initialize a new strapi2front configuration file.

Terminal window
npx strapi2front init

What it does:

  • Creates strapi.config.ts in your project root
  • Prompts for Strapi URL and token
  • Detects your Strapi version
  • Configures output options

Options:

OptionDescription
--force, -fOverwrite existing config file

Example:

Terminal window
# Create new config
npx strapi2front init
# Overwrite existing config
npx strapi2front init --force

Fetch schema from Strapi and generate types, services, and schemas.

Terminal window
npx strapi2front sync

What it does:

  • Loads configuration from strapi.config.ts
  • Connects to your Strapi instance
  • Fetches the content-type schema
  • Generates TypeScript/JavaScript files

Options:

OptionDescription
--types-onlyOnly generate type definitions
--services-onlyOnly generate service functions
--actions-onlyOnly generate Astro actions
--schemas-onlyOnly generate Zod validation schemas
--upload-onlyOnly generate upload helpers
--force, -fForce regeneration even if no changes

Examples:

Terminal window
# Full sync (types + services + schemas + actions)
npx strapi2front sync
# Only regenerate types
npx strapi2front sync --types-only
# Only regenerate services
npx strapi2front sync --services-only
# Only regenerate schemas
npx strapi2front sync --schemas-only

Display the current version of strapi2front.

Terminal window
npx strapi2front --version

Display help information.

Terminal window
npx strapi2front --help
npx strapi2front sync --help

Add convenient scripts to your package.json:

{
"scripts": {
"strapi:init": "strapi2front init",
"strapi:sync": "strapi2front sync",
"strapi:types": "strapi2front sync --types-only"
}
}

Run sync in CI pipelines:

# GitHub Actions example
- name: Generate Strapi types
env:
STRAPI_URL: ${{ secrets.STRAPI_URL }}
STRAPI_TOKEN: ${{ secrets.STRAPI_TOKEN }}
run: npx strapi2front sync
CodeMeaning
0Success
1Error (connection failed, invalid config, etc.)

For troubleshooting, set the DEBUG environment variable:

Terminal window
DEBUG=strapi2front:* npx strapi2front sync

Run npx strapi2front init to create the configuration file.

  • Verify your Strapi server is running
  • Check the URL in your config
  • Ensure no firewall is blocking the connection
  • Your API token may be invalid or expired
  • Generate a new token in Strapi admin
  • Ensure the token has access to Content-Type Builder