Command Line Interface
- Initializing Foscia on your project
- Creating files related to Foscia (models, composables, etc.)
Installation
The Foscia CLI is provided by @foscia/cli package.
- NPM
- YARN
- PNPM
- Bun
npm install -D @foscia/cli
yarn add -D @foscia/cli
pnpm add -D @foscia/cli
bun add -D @foscia/cli
Usage
The foscia command can be called from command line once Foscia CLI is
installed. When called without arguments, it will list available commands.
- NPM
- YARN
- PNPM
- Bun
npx foscia
yarn foscia
pnpm foscia
bun foscia
Since Foscia CLI is not installed globally, you will need to prefix foscia
with your package runner.
Commands
init [path]
Initialize Foscia in your project. The command will ask you multiple things about your project to set up an adapted Foscia environment (creating the configuration file, installing dependencies, creating a first model and creating an action factory).
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia init
# Init with specific usage and write to dedicated configuration.
npx foscia init src/api --config=.fosciarc.api.json --usage=jsonapi
yarn foscia init
# Init with specific usage and write to dedicated configuration.
yarn foscia init src/api --config=.fosciarc.api.json --usage=jsonapi
pnpm foscia init
# Init with specific usage and write to dedicated configuration.
pnpm foscia init src/api --config=.fosciarc.api.json --usage=jsonapi
bun foscia init
# Init with specific usage and write to dedicated configuration.
bun foscia init src/api --config=.fosciarc.api.json --usage=jsonapi
Arguments
[path]Directory to put new Foscia files in (models, composables, actions). If absent, will be requested during initialization process.
Options
--usage <usage>Define your usage of Foscia (CLI will ask for it if not provided)--manualDisable environment detection (language and modules organizations)--showOutput the files instead of writing them on filesystem--forceOverwrite existing files instead of prompting user
make model <name>
Create a Foscia model using the name argument.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make model post
# Make model and show file content instead of writing to filesystem.
npx foscia make model post --show
# Make model and update models list file.
npx foscia make model post --write-models
yarn foscia make model post
# Make model and show file content instead of writing to filesystem.
yarn foscia make model post --show
# Make model and update models list file.
yarn foscia make model post --write-models
pnpm foscia make model post
# Make model and show file content instead of writing to filesystem.
pnpm foscia make model post --show
# Make model and update models list file.
pnpm foscia make model post --write-models
bun foscia make model post
# Make model and show file content instead of writing to filesystem.
bun foscia make model post --show
# Make model and update models list file.
bun foscia make model post --write-models
Arguments
<name>Name of the model (class, file and type will be determined from it)
Options
--write-modelsUpdate themodels.tsfile after creating model. This will only occur ifshowoption is disabled and if your models are discover manually (seefoscia make models).--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make composable <name>
Create a Foscia composable using the name argument.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make composable publishable
yarn foscia make composable publishable
pnpm foscia make composable publishable
bun foscia make composable publishable
Arguments
<name>Name of the composable (file will be determined from it)
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make transformer <name>
Create a Foscia value transformer (for IDs and attributes).
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make transformer toDateTime
yarn foscia make transformer toDateTime
pnpm foscia make transformer toDateTime
bun foscia make transformer toDateTime
Arguments
<name>Name of the transformer (file will be determined from it)
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make loader [name]
Create a Foscia relation loader.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make loader
yarn foscia make loader
pnpm foscia make loader
bun foscia make loader
Arguments
[name]Name of the transformer (default name is built on chosen loader)
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make reducer
Create a Foscia models reducer.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make reducer
yarn foscia make reducer
pnpm foscia make reducer
bun foscia make reducer
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make reviver
Create a Foscia models reviver.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make reviver
yarn foscia make reviver
pnpm foscia make reviver
bun foscia make reviver
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make model-factory
Create a Foscia model factory.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make model-factory
yarn foscia make model-factory
pnpm foscia make model-factory
bun foscia make model-factory
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make models
Create the models list file (models.ts) which export an array of available
models in your project. This is used by registry, revivers, etc.
You will prompt to select one way to discover models:
- Automatically using
import.meta.glob(ESM only). This is preferred for Vite projects. - Automatically using
require.context. This is preferred for Webpack projects. - Manually by importing and returning models by yourself. You are still able to
call
make:modelsto generate an up-to-date file. When usingfoscia make model, you will be prompt for models list update on each model creation.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make models
yarn foscia make models
pnpm foscia make models
bun foscia make models
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user--explorerExplorer to generate within:import,requireormanual
make action [name]
Create a Foscia action factory.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make action
# Make an action for a specific usage.
npx foscia make action --usage=http
yarn foscia make action
# Make an action for a specific usage.
yarn foscia make action --usage=http
pnpm foscia make action
# Make an action for a specific usage.
pnpm foscia make action --usage=http
bun foscia make action
# Make an action for a specific usage.
bun foscia make action --usage=http
Arguments
[name]Name of the action factory file (default toaction)
Options
--usage <usage>Define your usage of Foscia (default to your configuration defined usage)--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make enhancer <name>
Create a Foscia action enhancer.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make enhancer
yarn foscia make enhancer
pnpm foscia make enhancer
bun foscia make enhancer
Arguments
<name>Name of the enhancer
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
make runner <name>
Create a Foscia action runner.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia make runner
yarn foscia make runner
pnpm foscia make runner
bun foscia make runner
Arguments
<name>Name of the runner
Options
--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
integrate nuxt
Publish all integrations for Nuxt:
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia integrate nuxt
yarn foscia integrate nuxt
pnpm foscia integrate nuxt
bun foscia integrate nuxt
Options
--payload-plugin <name>Name of the payload plugin (default tofosciaPayloadPlugin)--plugins-directory <directory>Path to plugins directory (default to detected automatically)--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
integrate nuxt payload-plugin [name]
Publish only payload plugin for Nuxt integration.
Examples
- NPM
- YARN
- PNPM
- Bun
npx foscia integrate nuxt payload-plugin
yarn foscia integrate nuxt payload-plugin
pnpm foscia integrate nuxt payload-plugin
bun foscia integrate nuxt payload-plugin
Arguments
[name]Name of the plugin (default tofosciaPayloadPlugin)
Options
--directory <directory>Path to plugins directory (default to detected automatically)--showOutput the file instead of writing it on filesystem--forceOverwrite existing files instead of prompting user
Configuration
Foscia CLI uses a configuration file which help generating files correctly for
all make:* commands using many options, such as:
- Path to store your files
- Language you are using (TS or JS)
- Modules organization (ESM or CommonJS)
- etc.
This configuration can be set up using foscia init [path]
command and will be stored in a .fosciarc.json.
You should name your @foscia/cli configuration file either for
.fosciarc.json or .fosciarc.<name>.json (where name is an alphanumerical
string). @foscia/cli will try to automatically resolve the first config it
founds.
If you are using a name like .fosciarc.api.json, you can just use the option
--config=api (instead of .fosciarc.api.json) as a shortcut.
Available options
Example of a Foscia CLI configuration:
{
"path": "src/api",
"alias": "@/api",
"packageManager": "npm",
"usage": "jsonapi",
"language": "ts",
"modules": "esm"
}
Description of each configuration options:
| Key | Type | Description |
|---|---|---|
path | string | Directory to put your Foscia files in (action factory, models, etc.) |
alias | string|undefined | Alias to use when importing models in files (instead of relative import path). |
packageManager | 'npm'|'yarn'|'pnpm'|'bun' | Package manager to use when installing Foscia dependencies |
usage | 'jsonapi'|'jsonrest'|'http'|undefined | Your usage of Foscia for this configuration. |
language | 'ts'|'js' | The language to use when generating files. |
modules | 'esm'|'commonjs' | The modules organization to use when generating files. |
tabSize | number | The tab size to use when generating files (defaults to 2). |
Multiple configurations
Using a configuration file also allow you to use multiple configurations files for multiple purposes (e.g. one for your client-side, another for your server-side).
To init a multiple configurations setup, you can call init with a config
option:
- NPM
- YARN
- PNPM
- Bun
npx foscia init --config=.fosciarc.api.json
yarn foscia init --config=.fosciarc.api.json
pnpm foscia init --config=.fosciarc.api.json
bun foscia init --config=.fosciarc.api.json
Once your configuration is set up, you can run other commands using the same
config option:
- NPM
- YARN
- PNPM
- Bun
npx foscia make model --config=api post
yarn foscia make model --config=api post
pnpm foscia make model --config=api post
bun foscia make model --config=api post