You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds.
9
+
Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds.
10
10
11
11
::: note
12
12
It is recommended to install Strapi locally only, which requires prefixing all of the following `strapi` commands with the package manager used for the project setup (e.g `npm run strapi help` or `yarn strapi help`) or a dedicated node package executor (e.g. `npx strapi help`).
@@ -230,7 +230,7 @@ strapi generate
230
230
231
231
## strapi templates:generate
232
232
233
-
Create a template from the current strapi project
233
+
Create a template from the current Strapi project.
Example: `strapi templates:generate ../strapi-template-name` will copy the required files and folders to a `template` directory inside `../strapi-template-name`
243
243
244
+
## strapi ts:generate-types
245
+
246
+
Generate [TypeScript](/developer-docs/latest/development/typescript.md) typings for the project schemas.
247
+
248
+
```sh
249
+
strapi ts:generate-types
250
+
```
251
+
252
+
***strapi ts:generate-types --verbose**<br/>
253
+
Generate typings with the verbose mode enabled, displaying a detailed table of the generated schemas.
254
+
***strapi ts:generate-types --silent** or **strapi ts:generate-types -s**<br/>
255
+
Generate typings with the silent mode enabled, completely removing all the logs in the terminal.
256
+
***strapi ts:generate-types --out-dir <path>** or **strapi ts:generate-types -o <path>**<br/>
257
+
Generate typings specifying the output directory in which the file will be created.
258
+
***strapi ts:generate-types --file <filename>** or **strapi ts:generate-types -f <filename>**<br/>
259
+
Generate typings specifiying the name of the file to contain the types declarations.
260
+
244
261
## strapi routes:list
245
262
246
263
Display a list of all the available [routes](/developer-docs/latest/development/backend-customization/routes.md).
Copy file name to clipboardExpand all lines: docs/developer-docs/latest/development/backend-customization/models.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,10 @@ The content-types has the following models files:
34
34
35
35
These models files are stored in `./src/api/[api-name]/content-types/[content-type-name]/`, and any JavaScript or JSON file found in these folders will be loaded as a content-type's model (see [project structure](/developer-docs/latest/setup-deployment-guides/file-structure.md)).
36
36
37
+
:::note
38
+
In [TypeScript](/developer-docs/latest/development/typescript.md)-enabled projects schema typings can be generated using the `ts:generate-types` command.
39
+
:::
40
+
37
41
### Components
38
42
39
43
Component models can't be created with CLI tools. Use the [Content-type Builder](/user-docs/latest/content-types-builder/introduction-to-content-types-builder.md) or create them manually.
Copy file name to clipboardExpand all lines: docs/developer-docs/latest/development/typescript.md
+31-89Lines changed: 31 additions & 89 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,126 +67,68 @@ To experience TypeScript-based autocomplete while developing Strapi applications
67
67
3. Choose `runLifecyclesfunction` from the list.
68
68
4. When the `strapi.runLifecyclesFunctions` method is added, a list of available lifecycle types (i.e. `register`, `bootstrap` and `destroy`) are returned by the code editor. Use keyboard arrows to choose one of the lifecycles and the code will autocomplete.
69
69
70
-
## Develop a plugin using TypeScript
71
-
72
-
New plugins can be generated following the [plugins development documentation](/developer-docs/latest/development/plugins-development.md). There are 2 important distinctions for TypeScript applications:
73
-
74
-
- After creating the plugin, run `yarn install` or `npm run install`in the plugin directory `src/admin/plugins/[my-plugin-name]` to install the dependencies for the plugin.
75
-
- Run `yarn build` or `npm run build`in the plugin directory `src/admin/plugins/[my-plugin-name]` to build the admin panel including the plugin.
76
-
77
-
::: note
78
-
It is not necessary to repeat the `yarn install` or `npm run install` command after the initial installation. The`yarn build` or `npm run build` command is necessary to implement any plugin development that affects the admin panel.
79
-
:::
80
-
81
-
## Start Strapi programmatically
82
-
83
-
Instantiating Strapi programmatically in a TypeScript project requires additional configurations to load everything correctly. The primary difference for TypeScript programmatic use is that the codebase and compiled code are stored in separate directories, whereas the same directory is used to read and write in native JavaScript.
84
-
85
-
### Understand programatic use
86
-
87
-
When instantiating Strapi programmatically using the default exportof`@strapi/strapi`, differentparameterssuchasthe`app`directoryandthe`dist`directorycanbepassed. The`app`directoryistheprojectrootdirectoryand`dist`isasubdirectoryof`app`. The`dist`directoryrepresentsthecompiledproject, withthesamedirectorystructureasthe`app`directory, andthe`app`directoryrepresentsthecodebase (TypeScriptorJavaScript). Themaindifferencesare:
70
+
## Generate typings for project schemas
88
71
89
-
- When using the Content-type Builder to create, update, delete content types (or any other service that creates files), Strapi uses the `app` folder to write the files.
90
-
- When reading what content types exist on the system Strapi reads the `dist` folder.
91
-
- When the `develop` command is used only the `app` directory is watched. In TypeScript, a compilation will be triggered when a change is detected in the `app` directory and the output will be written to the `dist` directory.
72
+
To generate typings for your project schemas use the [`ts:generate-types`CLI command](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-ts-generate-types). The`ts:generate-types` command creates the file `schemas.d.ts`, at the project root, which stores the schema typings. The optional `--verbose` flag returns a detailed table of the generated schemas.
92
73
93
-
::: note
94
-
The public folder is considered static and thus ignores the `app` and `dist` directories.
95
-
:::
74
+
To use `ts:generate-types`run the following code in a terminal at the project root:
96
75
97
-
The default values for the `app` and `dist` directories are transformed and assigned using one of the following options:
98
-
99
-
```js
100
-
101
-
const resolveWorkingDirectories = opts => {
102
-
const cwd = process.cwd(); // Neither the appDir or distDir are passed. Both the appDir and distDir are set to process.cwd().
103
-
104
-
const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd; // Only appDir is defined distDir matches appDir.
105
-
106
-
const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir; // Only distDir is defined, appDir is set to process.cwd().
76
+
<code-group>
77
+
<code-block title="NPM">
107
78
108
-
return { appDir, distDir };
109
-
}
79
+
```sh
80
+
npm run strapi ts:generate-types --verbose #optional flag
110
81
111
82
```
112
83
113
-
For example, if the compiled code is stored in a separate directory (eg: when using TypeScript) Strapi should be instantiated with a specific `distDir` value which matches the path of your build directory.
114
-
115
-
::: caution
116
-
Do not set the `appDir` to the `build` or `dist` directory as it could cause issues when the app tries to write some files.
yarn strapi ts:generate-types --verbose #optional flag
128
90
129
91
```
130
92
131
-
Start Strapi using a custom `dist` directory:
93
+
</code-block>
94
+
</code-group>
132
95
133
-
```js
134
-
const strapi = require('@strapi/strapi');
96
+
## Develop a plugin using TypeScript
135
97
136
-
strapi({ distDir: './dist' });
137
-
// appDir => process.cwd() | distDir => './dist'
138
-
```
98
+
New plugins can be generated following the [plugins development documentation](/developer-docs/latest/development/plugins-development.md). There are 2 important distinctions for TypeScript applications:
139
99
140
-
Start Strapi using custom `app` and `dist` directories:
100
+
- After creating the plugin, run `yarn` or `npm install`in the plugin directory `src/admin/plugins/[my-plugin-name]` to install the dependencies for the plugin.
101
+
- Run `yarn build` or `npm run build`in the plugin directory `src/admin/plugins/[my-plugin-name]` to build the admin panel including the plugin.
141
102
142
-
```js
103
+
::: note
104
+
It is not necessary to repeat the `yarn` or `npm install` command after the initial installation. The`yarn build` or `npm run build` command is necessary to implement any plugin development that affects the admin panel.
105
+
:::
143
106
144
-
const strapi = require('@strapi/strapi');
107
+
## Start Strapi programmatically
145
108
146
-
strapi({ distDir: './dist' });
147
-
// appDir => process.cwd() | distDir => './dist'
109
+
To start Strapi programmatically in a TypeScript project the Strapi instance requires the compiled code location. This section describes how to set and indicate the compiled code directory.
148
110
149
-
```
111
+
### Use the `strapi()` factory
150
112
151
-
Start Strapi using a custom `app` directory:
113
+
Strapi can be run programmatically by using the `strapi()`factory. Since the code of TypeScript projects is compiled in a specific directory, the parameter `distDir` should be passed to the factory to indicate where the compiled code should be read:
### Use both JavaScript and TypeScript codebases when starting Strapi programmatically
123
+
### Use the `strapi.compile()`function
163
124
164
-
Adding the package`@strapi/typescript-utils` allows forboth JavaScript and TypeScript codebases to be used programatically. A common use is for creating command line interface tools or developing a plugin. Examplesof how to incorporate both code bases:
125
+
The `strapi.compile()` function should be mostly used for developing tools that need to start a Strapi instance and detect whether the project includes TypeScript code. `strapi.compile()` automatically detects the project language. If the project code contains any TypeScript code, `strapi.compile()` compiles the code and returns a context with specific values for the directories that Strapi requires:
Copy file name to clipboardExpand all lines: docs/developer-docs/latest/plugins/email.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,7 @@ When using community providers, pass the full package name to the `provider` key
107
107
Here is an example of a configuration made for the provider [@strapi/provider-email-sendgrid](https://www.npmjs.com/package/@strapi/provider-email-sendgrid).
If you're using a different provider depending on your environment, you can specify the correct configuration in `./config/env/${yourEnvironment}/plugins.js`. More info here: [Environments](/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.md)
0 commit comments