CLI Commands
strapi2front provides a CLI for initializing projects and generating code from your Strapi schema.
Installation
Section titled “Installation”npm install -D strapi2frontCommands
Section titled “Commands”Initialize a new strapi2front configuration file.
npx strapi2front initWhat it does:
- Creates
strapi.config.tsin your project root - Prompts for Strapi URL and token
- Detects your Strapi version
- Configures output options
Options:
| Option | Description |
|---|---|
--force, -f | Overwrite existing config file |
Example:
# Create new confignpx strapi2front init
# Overwrite existing confignpx strapi2front init --forceFetch schema from Strapi and generate types, services, and schemas.
npx strapi2front syncWhat it does:
- Loads configuration from
strapi.config.ts - Connects to your Strapi instance
- Fetches the content-type schema
- Generates TypeScript/JavaScript files
Options:
| Option | Description |
|---|---|
--types-only | Only generate type definitions |
--services-only | Only generate service functions |
--actions-only | Only generate Astro actions |
--schemas-only | Only generate Zod validation schemas |
--upload-only | Only generate upload helpers |
--force, -f | Force regeneration even if no changes |
Examples:
# Full sync (types + services + schemas + actions)npx strapi2front sync
# Only regenerate typesnpx strapi2front sync --types-only
# Only regenerate servicesnpx strapi2front sync --services-only
# Only regenerate schemasnpx strapi2front sync --schemas-onlyversion
Section titled “version”Display the current version of strapi2front.
npx strapi2front --versionDisplay help information.
npx strapi2front --helpnpx strapi2front sync --helpPackage.json Scripts
Section titled “Package.json Scripts”Add convenient scripts to your package.json:
{ "scripts": { "strapi:init": "strapi2front init", "strapi:sync": "strapi2front sync", "strapi:types": "strapi2front sync --types-only" }}CI/CD Integration
Section titled “CI/CD Integration”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 syncExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
0 | Success |
1 | Error (connection failed, invalid config, etc.) |
Debug Output
Section titled “Debug Output”For troubleshooting, set the DEBUG environment variable:
DEBUG=strapi2front:* npx strapi2front syncCommon Issues
Section titled “Common Issues””Could not find strapi.config”
Section titled “”Could not find strapi.config””Run npx strapi2front init to create the configuration file.
”Connection refused”
Section titled “”Connection refused””- Verify your Strapi server is running
- Check the URL in your config
- Ensure no firewall is blocking the connection
”401 Unauthorized”
Section titled “”401 Unauthorized””- Your API token may be invalid or expired
- Generate a new token in Strapi admin
- Ensure the token has access to Content-Type Builder