Generate Model
Generates a new model with all the boilerplate files: actions, reducer, epics, selectors, and an index barrel export. The model is also automatically registered in your models index file.
Usage
Interactive:
remodel
# then select "Create Model"Non-interactive:
remodel generate model --name user --ts --dir ./src/modelsShort alias:
remodel g model --name user --tsOptions
| Flag | Type | Default | Description |
|---|---|---|---|
--name <name> | string | (required) | Model name (e.g., user, product) |
--dir <directory> | string | from .remodel config | Directory where models live |
--ts | boolean | from config | Use TypeScript |
--js | boolean | from config | Use JavaScript |
If a .remodel config file exists, the CLI reads language and modelsDirectory from it. You only need to pass --name.
Generated Files
Running remodel generate model --name user --ts --dir ./src/models creates:
- index.ts
- actions.ts
- index.ts
- reducer.ts
- epics.ts
- selectors.ts
The model name is automatically pluralized for the folder name (user becomes users, category becomes categories).
Auto-Registration
When a models index file (index.ts or index.js) exists in the target directory, the CLI automatically updates it to import and register the new model.
Before:
import type { ModelProps } from '@blue-functor/remodel';
const config: ModelProps = {
reducers: {},
epics: {},
};
export default config;After generating user and product models:
import type { ModelProps } from '@blue-functor/remodel';
import * as users from './users';
import * as products from './products';
const config: ModelProps = {
reducers: {
users: users.reducer,
products: products.reducer,
},
epics: {
users: users.epics,
products: products.epics,
},
};
export default config;Each model’s reducer and epics are imported and added to the config object. No manual wiring required.
Generated File Contents
actions.ts
import { generateScopedActions } from '@blue-functor/remodel';
const { createAction, createEffectAction } = generateScopedActions('USERS');
export { createAction, createEffectAction };Provides scoped action creators. All actions created in this file are automatically prefixed with USERS/.
reducer.ts
import { createReducer } from '@reduxjs/toolkit';
import * as actions from './actions';
const initState = {};
const reducer = createReducer(initState, (builder) => builder);
export default reducer;epics.ts
import { combineEpics } from 'redux-observable';
const epics = combineEpics(
// Add epics here
);
export default epics;selectors.ts
// Add your selectors here
// Example:
// export const selectData = (state: RootState) => state.yourModel.data;index.ts
export { default as reducer } from './reducer';
export { default as epics } from './epics';
export * from './selectors';
export * from './actions';Barrel file that re-exports everything from the model.
Interactive Flow
When running interactively, the Create Model screen walks you through:
- Model name — text input with validation (must start with a letter, alphanumeric only)
- Directory — uses config default or shows a directory picker with filesystem autocomplete
- Language — skipped if
.remodelconfig has a language set - Generate — creates the files and updates the models index
- Success — shows a summary of all created files