Sails API Generator
sails-generate-api is a command-line interface (CLI) generator for the Sails.js framework, designed to scaffold boilerplate files for API models and controllers. Specifically, it creates `api/models/Foo.js` and `api/controllers/FooController.js` for a given API name. This package is from the 0.x era of Sails.js, with its last publication being 9 years ago and current version 0.10.1. The current stable version of Sails.js is 1.5.x, which introduced significant breaking changes from its 0.x predecessors, including a revamped generator architecture. Therefore, `sails-generate-api` is not compatible with modern Sails.js applications (v1.x and above) and should be considered abandoned.
Common errors
-
Error: sails-generate-api@0.10.1 requires a peer of sails@~0.10.0 but none was installed.
cause Attempting to install or use `sails-generate-api` with a newer version of Sails.js (e.g., v1.x+) or without any Sails.js installation, which is a peer dependency.fixEnsure you are using Sails.js v0.x (specifically, within the ~0.10.0 range) with this generator. For example, `npm install sails@~0.10.0` globally or locally alongside the generator. -
Error: sails-generate-api not found. Error: Generator "api" could not be loaded from "sails-generate-api"
cause The `sails-generate-api` package was installed but the `.sailsrc` file was not correctly configured to point to it, or it was configured for a local installation but `sails generate` was run in a different directory.fixVerify that `sails-generate-api` is installed and that your `.sailsrc` file (either local `./.sailsrc` or global `~/.sailsrc`) correctly maps `"api": "sails-generate-api"` within the `generators.modules` section. Ensure the `sails generate` command is executed from a directory where the `.sailsrc` configuration is active.
Warnings
- breaking This package is designed for Sails.js versions 0.x and is incompatible with Sails.js v1.x and later. Major architectural changes, especially regarding the generator system, occurred in Sails v1.0.
- deprecated The `sails-generate-api` package has not been updated in 9 years and is considered abandoned. Its dependencies and internal logic may rely on outdated Node.js features or insecure third-party packages.
- gotcha The `.sailsrc` configuration method for overriding or adding generators, as described in this package's README, is primarily for Sails 0.x. While `.sailsrc` still exists in Sails v1.x, the generator module structure and registration process have changed substantially.
Install
-
npm install sails-generate-api -
yarn add sails-generate-api -
pnpm add sails-generate-api
Imports
- generatorDefinition
const generatorDefinition = require('sails-generate-api'); - generate
import { generate } from 'sails-generate-api';const { generate } = require('sails-generate-api'); // If an internal `generate` function were exposed - ApiGeneratorModule
import ApiGeneratorModule from 'sails-generate-api';
// No direct application-level import for CLI generators. // Configured via .sailsrc instead.
Quickstart
{
"generators": {
"modules": {
"api": "sails-generate-api"
}
}
}
// Save the above JSON to ./.sailsrc in your project directory
// or ~/.sailsrc for global use.
// Then, from your Sails project directory:
// $ npm install sails-generate-api
// $ sails generate api foobar
// This will create:
// - api/models/Foobar.js
// - api/controllers/FoobarController.js