Skip to main content
The strapi2front CLI provides commands to initialize your project and sync types, services, and actions from your Strapi schema.

Installation

npm install -D strapi2front

Commands

init

Initialize strapi2front in your project. Creates configuration files, sets up environment variables, and installs dependencies.
npx strapi2front init [options]
If you run strapi2front without any command, it defaults to running init.

Options

-y, --yes
boolean
default:false
Skip interactive prompts and use default values for all options.
--url
string
Strapi URL to connect to (e.g., http://localhost:1337). If not provided, you’ll be prompted during setup.
--token
string
Strapi sync token with STRAPI_SYNC_TOKEN permissions. Required for fetching schema. If not provided, you’ll be prompted.
--framework
string
Framework to use for action generation. Currently supports astro. Auto-detected if not specified.

What it does

The init command performs the following steps:
  1. Detects project configuration: Framework, TypeScript usage, and package manager
  2. Runs interactive prompts: Collects configuration options through guided questions
  3. Creates configuration file: Generates strapi.config.ts (or .js for JSDoc projects)
  4. Updates environment files:
    • Appends variables to .env (creates if needed)
    • Creates .env.example with token documentation
  5. Creates output directory: Sets up the directory structure for generated files
  6. Installs dependencies: Optionally installs strapi2front (dev) and @strapi/client

Environment Variables

The init command creates the following environment variables:
STRAPI_URL
string
required
Your Strapi backend URL (e.g., http://localhost:1337 or https://api.example.com)
STRAPI_SYNC_TOKEN
string
required
Development only - Token for syncing schema from Strapi.Permissions required:
  • content-type-builder.getContentTypes
  • content-type-builder.getComponents
  • i18n.listLocales
Do NOT deploy this token to production
STRAPI_TOKEN
string
Production - Token for your frontend app to fetch content. Configure with only the permissions your app needs.
PUBLIC_STRAPI_URL
string
Public URL for browser-side uploads (only if upload feature is enabled)
PUBLIC_STRAPI_UPLOAD_TOKEN
string
Upload token with Upload > upload permission only (no delete/update)

Examples

npx strapi2front init

sync

Sync types, schemas, services, actions, and upload helpers from your Strapi schema. This is the main command you’ll run after making changes to your Strapi content types.
npx strapi2front sync [options]

Options

-f, --force
boolean
default:false
Force regeneration of all files, even if they haven’t changed.
--types-only
boolean
default:false
Only generate TypeScript type definitions. Skips services, actions, schemas, and upload helpers.
--services-only
boolean
default:false
Only generate service files for API calls. Skips types, actions, schemas, and upload helpers.
--actions-only
boolean
default:false
Only generate framework actions (Astro actions). Skips types, services, schemas, and upload helpers.
Only available when outputFormat: "typescript" in config
--schemas-only
boolean
default:false
Only generate Zod validation schemas. Skips types, services, actions, and upload helpers.
--upload-only
boolean
default:false
Only generate upload helpers (action + public client). Skips types, services, actions, and schemas.

What it does

The sync command:
  1. Loads configuration from strapi.config.ts
  2. Detects Strapi version (v4 or v5) and warns if config mismatch
  3. Fetches schema from Strapi API (content types, components, locales)
  4. Checks for Blocks fields and prompts to install @strapi/blocks-react-renderer if needed
  5. Generates files based on your feature configuration:
    • Types: TypeScript interfaces for all content types and components
    • Services: API client methods for CRUD operations
    • Actions: Framework-specific server actions (Astro)
    • Schemas: Zod validation schemas for forms
    • Upload: File upload helpers for client and server
  6. Displays summary of generated files

Generated File Structure

With all features enabled, sync generates:
src/strapi/
├── collections/
│   ├── article.ts         # Types, service, action, schema
│   ├── author.ts
│   └── ...
├── singles/
│   ├── homepage.ts
│   └── ...
├── components/
│   ├── layout/
│   │   └── hero.ts
│   └── ...
└── upload/
    ├── action.ts          # Server action for uploads
    └── client.ts          # Public upload client

Examples

npx strapi2front sync
Add strapi2front sync to your package.json scripts for easier access:
{
  "scripts": {
    "strapi:sync": "strapi2front sync"
  }
}

Global Options

These options are available for all commands:
--help, -h
boolean
Display help information for a command.
--version, -V
boolean
Display the installed strapi2front version.

Exit Codes

0
success
Command completed successfully
1
error
Command failed with error (check error message)

Package Manager Detection

The CLI automatically detects your package manager based on lockfiles:
  • bun.lockb → Bun
  • pnpm-lock.yaml → pnpm
  • yarn.lock → Yarn
  • Default → npm
Install commands are adjusted accordingly for dependency installation.

TypeScript Interfaces

The CLI exports TypeScript interfaces for programmatic usage:
import type { InitCommandOptions, SyncCommandOptions } from 'strapi2front';

const initOptions: InitCommandOptions = {
  yes: true,
  url: 'http://localhost:1337',
  token: 'your-token',
  framework: 'astro'
};

const syncOptions: SyncCommandOptions = {
  force: false,
  typesOnly: false,
  servicesOnly: false,
  actionsOnly: false,
  schemasOnly: false,
  uploadOnly: false
};
See the Types Reference for complete type definitions.