9.3 KiB
Command Line Interface (CLI)
Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds.
strapi new
Create a new project
strapi new <name>
options: [--dev|--dbclient <dbclient> --dbhost <dbhost> --dbport <dbport> --dbname <dbname> --dbusername <dbusername> --dbpassword <dbpassword>]
-
strapi new <name>
Generates a new project called <name> and installs the default plugins through the npm registry. -
strapi new <name> --dev
Generates a new project called <name> and creates symlinks for the./adminfolder and each plugin inside the./pluginfolder. It means that the Strapi's development workflow has been set up on the machine earlier. -
strapi new <name> --dbclient <dbclient> --dbhost <dbhost> --dbport <dbport> --dbname <dbname> --dbusername <dbusername> --dbpassword <dbpassword>
Generates a new project called <name> and skip the interactive database configuration and initilize with these options. <dbclient> can bemongo,postgres,mysql,sqlite3orredis. <dbusername> and <dbpassword> are optional.See the CONTRIBUTING guide for more details.
strapi generate:api
Scaffold a complete API with its configurations, controller, model and service.
strapi generate:api <name> [<attribute:type>]
options: [--tpl <name>|--plugin <name>]
-
strapi generate:api <name>
Generates an API called <name> in the./apifolder at the root of your project. -
strapi generate:api <name> <attribute:type>
Generates an API called <name> in the./apifolder at the root of your project. The model will already contain an attribute called <attribute> with the type property set to <type>.Example:
strapi generate:api product name:string description:text price:integer -
strapi generate:api <name> --plugin <plugin>
Generates an API called <name> in the./plugins/<plugin>folder.Example:
strapi generate:api product --plugin content-manager -
strapi generate:api <name> --tpl <template>
Generates an API called <name> in the./apifolder which works with the given <template>. By default, the generated APIs are based on Mongoose.Example:
strapi generate:api product --tpl bookshelf
Note: The first letter of the filename will be uppercased.
strapi generate:controller
Create a new controller
strapi generate:controller <name>
options: [--api <name>|--plugin <name>]
-
strapi generate:controller <name>
Generates an empty controller called <name> in the./api/<name>/controllersfolder.Example:
strapi generate:controller categorywill create the controller at./api/category/controllers/Category.js. -
strapi generate:controller <name> --api <api>
Generates an empty controller called <name> in the./api/<api>/controllersfolder.Example:
strapi generate:controller category --api productwill create the controller at./api/product/controllers/Category.js. -
strapi generate:controller <name> --plugin <plugin>
Generates an empty controller called <name> in the./plugins/<plugin>/controllersfolder.
Note: The first letter of the filename will be uppercased.
strapi generate:model
Create a new model
strapi generate:model <name> [<attribute:type>]
options: [--api <name>|--plugin <name>]
-
strapi generate:model <name>
Generates an empty model called <name> in the./api/<name>/modelsfolder. It will create two files. The first one will be <name>.js which contains your lifecycle callbacks and another <name>.settings.json that will list your attributes and options.Example:
strapi generate:model categorywill create these two files./api/category/models/Category.jsand./api/category/models/Category.settings.json. -
strapi generate:model <name> <attribute:type>
Generates an empty model called <name> in the./api/<name>/modelsfolder. The file <name>.settings.json will already contain a list of attribute with their associated <type>.Example:
strapi generate:model category name:string description:textwill create these two files./api/category/models/Category.jsand./api/category/models/Category.settings.json. This last file will contain two attributesnamewith the typestringanddescriptionwith typetext. -
strapi generate:model <name> --api <api>
Generates an empty model called <name> in the./api/<api>/modelsfolder.Example:
strapi generate:model category --api productwill create these two files:./api/product/models/Category.js./api/product/models/Category.settings.json.
-
strapi generate:model <name> --plugin <plugin>
Generates an empty model called <name> in the./plugins/<plugin>/modelsfolder.
Note: The first letter of the filename will be uppercased.
strapi generate:service
Create a new service
strapi generate:service <name>
options: [--api <name>|--plugin <name>]
-
strapi generate:service <name>
Generates an empty service called <name> in the./api/<name>/servicesfolder.Example:
strapi generate:service categorywill create the service at./api/category/services/Category.js. -
strapi generate:service <name> --api <api>
Generates an empty service called <name> in the./api/<api>/servicesfolder.Example:
strapi generate:service category --api productwill create the service at./api/product/services/Category.js. -
strapi generate:service <name> --plugin <plugin>
Generates an empty service called <name> in the./plugins/<plugin>/servicesfolder.
Note: The first letter of the filename will be uppercased.
strapi generate:policy
Create a new policy
strapi generate:policy <name>
options: [--api <name>|--plugin <name>]
-
strapi generate:policy <name>
Generates an empty policy called <name> in the./config/policiesfolder.Example:
strapi generate:policy isAuthenticatedwill create the policy at./config/policies/isAuthenticated.js. -
strapi generate:policy <name> --api <api>
Generates an empty policy called <name> in the./api/<api>/config/policiesfolder. This policy will be scoped and only accessible by the <api> routes.Example:
strapi generate:policy isAuthenticated --api productwill create the policy at./api/product/config/policies/isAuthenticated.js. -
strapi generate:policy <name> --plugin <plugin>
Generates an empty policy called <name> in the./plugins/<plugin>/config/policiesfolder. This policy will be scoped and accessible only by the <plugin> routes.
strapi generate:plugin
Create a new plugin skeleton.
strapi generate:plugin <name>
-
strapi generate:plugin <name>
Generates an empty plugin called <name> in the./pluginsfolder.Example:
strapi generate:plugin userwill create the plugin at./plugins/user.
Please refer to the plugin develoment documentation to know more.
strapi install
Install a plugin in the project.
strapi install <name>
options: [--dev]
-
strapi install <name>
Installs a plugin called <name> in the./pluginsfolder.Example:
strapi install content-type-builderwill install the plugin at./plugins/content-type-builder. -
strapi install <name> --dev
It will create a symlink from the local Strapi repository plugin folder called <name> in the./pluginsfolder.Example:
strapi install content-type-builder --devwill create a symlink from/path/to/the/repository/packages/strapi-plugin-content-type-builderto./plugins/content-type-builder.
Checkout the CONTRIBUTING guide for more details about the local Strapi development workflow.
Note: You have to restart the server to load the plugin into your project.
Please refer to the plugins documentation to know more.
strapi uninstall
Uninstall a plugin from the project.
strapi uninstall <name>
-
strapi uninstall <name>
Uninstalls a plugin called <name> in the./pluginsfolder.Example:
strapi uninstall content-type-builderwill remove the folder at./plugins/content-type-builder.
Please refer to the plugins documentation to know more.
strapi version
Print the current globally installed Strapi version.
strapi version
strapi help
List CLI commands.
strapi help