# @anephenix/mcg

> Model Component Generator for Objection.js

Latest version **0.0.22** (published 2026-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @anephenix/mcg
pnpm add @anephenix/mcg
yarn add @anephenix/mcg
bun add @anephenix/mcg
```

Provides the command `mcg`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.22 |
| Published | 2026-09-27 |
| First published | 2020-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 22.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Paul Jensen |
| Maintainers | paulbjensen |
| Keywords | objection, model, generator |

## Links

- npm: https://www.npmjs.com/package/@anephenix/mcg
- Repository: https://github.com/anephenix/mcg
- Issues: https://github.com/anephenix/mcg/issues
- npm.io page: https://npm.io/package/@anephenix/mcg

## Dependencies (3)

- [to-case](https://npm.io/package/to-case.md) ^2.0.0
- [commander](https://npm.io/package/commander.md) ^15.0.0
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0

## Recent versions

- 0.0.22 (latest) — 2026-09-27
- 0.0.17 — 2026-01-04
- 0.0.16 — 2025-12-03
- 0.0.15 — 2025-10-08
- 0.0.14 — 2025-10-06
- 0.0.13 — 2025-06-10
- 0.0.12 — 2025-05-26
- 0.0.11 — 2025-04-08
- 0.0.10 — 2025-03-10
- 0.0.9 — 2025-02-24
- 0.0.8 — 2025-02-15
- 0.0.7 — 2025-02-05
- 0.0.6 — 2025-02-02
- 0.0.5 — 2025-01-13
- 0.0.4 — 2025-01-08
- … 3 more at https://npm.io/package/@anephenix/mcg/versions

## README

# Model Component Generator

[![npm version](https://badge.fury.io/js/%40anephenix%2Fmcg.svg)](https://badge.fury.io/js/%40anephenix%2Fmcg) [![Node.js CI](https://github.com/anephenix/mcg/actions/workflows/node.js.yml/badge.svg)](https://github.com/anephenix/mcg/actions/workflows/node.js.yml) [![Socket Badge](https://socket.dev/api/badge/npm/package/@anephenix/mcg)](https://socket.dev/npm/package/@anephenix/mcg)

A Node.js library and CLI for generating Objection.js Models and their supporting files. It helps to save time creating Models and their migrations, so that you can focus on implementing the business logic for your Node.js server-side project.

### Features

-   Creates an Objection.js model file via the commandline
-   Creates the model's knex.js migration file for the model's database table
-   Create a test model file in the **tests** folder by default
-   Create a test seed data file in the **tests**/data folder by default

### Dependencies

-   [Node.js](https://nodejs.org)
-   [Objection.js](https://vincit.github.io/objection.js/)
-   [Knex.js](http://knexjs.org)

### Install

```shell
npm i @anephenix/mcg
```

### Usage

You can use MCG via the command line:

```shell
npx mcg Post
```

This will do the following:

-   Create a folder called models, unless it already exists
-   Create a model file called Post.js in the models folder
-   Create a folder called migrations, unless it already exists
-   Generate a migration file to create the posts table with the created_at and updated_at timestamp fields.

You can pass the following optional arguments:

-   --testFolder - specify a custom folder name to put the test model file and seed data file in (e.g. test, spec)
-   --mainDir - specify a custom folder path to generate all of the files in, in case your app's code is not in the current working directory
-   --tableName - specify a custom database table name for the model and migration file (.e.g. blog_posts)
-   --attributes - specify the fields to add to the model, migration and test seed data file, as a space-separated list of name:type pairs (e.g. title:string description:text published:boolean)

The supported attribute types are: `string`, `text`, `integer`, `float`, `boolean`, `date`, `datetime` and `json`. For example:

```shell
npx mcg Post --attributes title:string description:text published:boolean
```

This will add `title`, `description` and `published` columns to the migration file, matching properties to the model's jsonSchema, and sample values for each of them in the test seed data file.

There is also the option of setting these optional arguments in a mcg.config.js file that looks like this:

```javascript
module.exports = {
	testFolder: 'spec',
	mainDir: 'app',
};
```

You can also use MCG programmatically, like this:

```javascript
const mcg = require('@anephenix/mcg');
(async () => {
	await mcg('Post');
})();
```

The mainDir and testFolder are optional 2nd and 3rd arguments to that command, and tableName and attributes are optional 4th and 5th arguments:

```javascript
const path = require('path');
const mcg = require('@anephenix/mcg');
(async () => {
	const mainDir = path.join(process.cwd(), 'app');
	const testFolder = 'spec';
	const tableName = undefined;
	const attributes = ['title:string', 'description:text', 'published:boolean'];
	await mcg('Post', mainDir, testFolder, tableName, attributes);
})();
```

### License and Credits

&copy;2026 Anephenix Ltd. MCG is licensed under the MIT license.

---
_Source: https://npm.io/package/@anephenix/mcg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
