Skip to content

Commit f72fe79

Browse files
authored
Merge pull request #1469 from strapi/main
Production release week 5
2 parents edd2273 + 346dfe6 commit f72fe79

File tree

11 files changed

+126
-315
lines changed

11 files changed

+126
-315
lines changed

docs/developer-docs/latest/developer-resources/cli/CLI.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ canonicalUrl: https://docs.strapi.io/developer-docs/latest/developer-resources/c
66

77
# Command Line Interface (CLI)
88

9-
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. The CLI works with both the `yarn` and `npm` package managers.
10+
11+
:::caution
12+
Interactive commands such as `strapi admin:create-user` don't display prompts with `npm`. A fix for the `npm` package manager is anticipated by March 2023. In the meantime, consider using the `yarn` package manager.
13+
:::
1014

1115
::: note
1216
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`).
17+
18+
To pass options with `npm` use the syntax: `npm run strapi <command> -- --<option>`
19+
20+
To pass options with `yarn` use the syntax: `yarn run strapi <command> --<option>`
21+
1322
:::
1423

1524
## strapi new

docs/developer-docs/latest/developer-resources/content-api/integrations/nuxt-js.md

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ canonicalUrl: https://docs.strapi.io/developer-docs/latest/developer-resources/c
88

99
This integration guide is following the [Quick Start Guide](/developer-docs/latest/getting-started/quick-start.md). We assume that you have fully completed its "Hands-on" path, and therefore can consume the API by browsing this [url](http://localhost:1337/api/restaurants).
1010

11-
If you haven't gone through the Quick Start Guide, the way you request a Strapi API with [Nuxt 3](https://v3.nuxtjs.org/) remains the same except that you will not fetch the same content.
11+
If you haven't gone through the Quick Start Guide, the way you request a Strapi API with [Nuxt 3](https://nuxtjs.org/) remains the same except that you will not fetch the same content.
1212

1313
## Create a Nuxt 3 app
1414

@@ -20,7 +20,7 @@ npx nuxi init nuxt-app
2020

2121
## Use an HTTP client
2222

23-
For this example we are using the awesome [@nuxt/strapi](https://strapi.nuxtjs.org/) module and Nuxt helper function [$fetch](https://v3.nuxtjs.org/api/utils/dollarfetch/) (based on `ohmyfetch`). You may choose any of this variants.
23+
For this example we are using the awesome [@nuxt/strapi](https://strapi.nuxtjs.org/) module and Nuxt helper function [$fetch](https://nuxt.com/docs/api/utils/dollarfetch/) (based on `ohmyfetch`). You may choose any of this variants.
2424

2525
:::: tabs card
2626

@@ -62,15 +62,15 @@ Be sure that you activated the `find` and `findOne` permission for the `restaura
6262

6363
`@nuxtjs/strapi` exposes composables that are auto-imported by Nuxt 3. Note that `delete` function must be renamed because it's reserved word in JavaScript.
6464

65+
::: request Example GET request with @nuxtjs/strapi
66+
6567
```js
6668
<script setup lang="ts">
6769
import type { Restaurant } from '~/types'
6870
const { find, findOne, create, update, delete: remove } = useStrapi()
6971
</script>
7072
```
7173

72-
::: request Example GET request with @nuxtjs/strapi
73-
7474
```js
7575
// Get all restaurants
7676
const response = await find<Restaurant>('restaurants')
@@ -266,29 +266,28 @@ Consider an example of a simple CRUD Nuxt application that implements the functi
266266

267267
`./pages/index.vue`
268268

269-
```js
269+
```html
270270
<template>
271271
<div>
272-
<ul v-if="!pending">
273-
<li v-for="restaurant in restaurants.data" :key="restaurant.id">
272+
<ul>
273+
<li v-for="restaurant in restaurants?.data" :key="restaurant.id">
274274
{{ restaurant.attributes.name }}
275275
<button @click="$router.push(`${$route.path}/restaurant/${restaurant.id}`)">Edit</button>
276276
<button @click="deleteRestaurant(restaurant.id)">Delete</button>
277277
</li>
278278
</ul>
279-
<div v-else>Loading...</div>
280279
<nuxt-link :to="`${$route.path}/restaurant/create`">Create</nuxt-link>
281280
</div>
282281
</template>
283282

284283
<script setup lang="ts">
285-
import type { Restaurant } from "~/types"
286-
const { find, delete: remove } = useStrapi()
287-
const { data: restaurants, pending, refresh, error } = await useAsyncData(
284+
import type { Restaurant } from '~/types'
285+
const { find, delete: remove } = useStrapi() // delete is keyword in JS, must not be used
286+
const { data: restaurants, refresh } = await useAsyncData(
288287
'restaurants',
289288
() => find<Restaurant>('restaurants')
290289
)
291-
onMounted(() => refresh())
290+
292291
const deleteRestaurant = async (restaurantId: number) => {
293292
await remove<Restaurant>("restaurants", restaurantId);
294293
refresh()
@@ -298,52 +297,58 @@ const deleteRestaurant = async (restaurantId: number) => {
298297

299298
`./pages/restaurant/create.vue`
300299

301-
```js
300+
```html
302301
<template>
303302
<div>
304-
<div><input type="text" v-model="restaurant.name" /></div>
305-
<div><textarea v-model="restaurant.description"></textarea></div>
303+
<div><input type="text" v-model="name" /></div>
304+
<div><textarea v-model="description"></textarea></div>
306305
<button @click="createRestaurant();$router.go(-1)">Create</button>
307306
<button @click="$router.go(-1)">Cancel</button>
308-
{{ restaurant }}
309307
</div>
310308
</template>
311309

312310
<script setup lang="ts">
313311
import type { Restaurant } from "~/types"
314312
const { create } = useStrapi()
315-
const restaurant = ref({ name: "", description: "" })
313+
const name = ref("")
314+
const description = ref("")
316315
const createRestaurant = async () => {
317316
await create<Restaurant>("restaurants", {
318-
name: restaurant.value.name,
319-
description: restaurant.value.description })
317+
name: name.value,
318+
description: description.value
319+
})
320320
}
321321
</script>
322322
```
323323

324324
`./pages/restaurant/[id].vue`
325325

326-
```js
326+
```html
327327
<template>
328328
<div>
329-
<div><input type="text" v-model="restaurant.name" /></div>
330-
<div><textarea v-model="restaurant.description"></textarea></div>
329+
<div><input type="text" v-model="name" /></div>
330+
<div><textarea v-model="description"></textarea></div>
331331
<button @click="updateRestaurant();$router.go(-1)">Update</button>
332332
<button @click="$router.go(-1)">Cancel</button>
333-
{{ restaurant }}
334333
</div>
335334
</template>
336335

337336
<script setup lang="ts">
338337
import type { Restaurant } from '~/types'
339-
const route = useRoute()
338+
340339
const { findOne, update } = useStrapi()
341-
const response = await findOne<Restaurant>("restaurants", route.params.id)
342-
const restaurant : Restaurant = ref(response.data.attributes)
340+
341+
const route = useRoute()
342+
const restaurantId: number = +route.params.id // cast to number
343+
344+
const response = await findOne<Restaurant>("restaurants", restaurantId)
345+
const name = ref(response.data.attributes.name)
346+
const description = ref(response.data.attributes.description)
343347
const updateRestaurant = async () => {
344-
await update<Restaurant>("restaurants", route.params.id, {
345-
name: restaurant.value.name,
346-
description: restaurant.value.description })
348+
await update<Restaurant>("restaurants", restaurantId, {
349+
name: name.value,
350+
description: description.value
351+
})
347352
}
348353
</script>
349354
```
@@ -354,27 +359,26 @@ const updateRestaurant = async () => {
354359

355360
`./pages/index.vue`
356361

357-
```js
362+
```html
358363
<template>
359364
<div>
360-
<ul v-if="!pending">
365+
<ul>
361366
<li v-for="restaurant in restaurants.data" :key="restaurant.id">
362367
{{ restaurant.attributes.name }}
363368
<button @click="$router.push(`${$route.path}/restaurant/${restaurant.id}`)">Edit</button>
364369
<button @click="deleteRestaurant(restaurant.id)">Delete</button>
365370
</li>
366371
</ul>
367-
<div v-else>Loading...</div>
368372
<nuxt-link :to="`${$route.path}/restaurant/create`">Create</nuxt-link>
369373
</div>
370374
</template>
371375

372376
<script setup>
373-
const { data: restaurants, pending, refresh } = await useAsyncData(
377+
const { data: restaurants, refresh } = await useAsyncData(
374378
'restaurants',
375379
() => $fetch("http://localhost:1337/api/restaurants")
376380
)
377-
onMounted(() => refresh())
381+
378382
const deleteRestaurant = async (restaurantId) => {
379383
await $fetch(`http://localhost:1337/api/restaurants/${restaurantId}`, {
380384
method: 'DELETE'
@@ -386,14 +390,13 @@ const deleteRestaurant = async (restaurantId) => {
386390

387391
`./pages/restaurant/create.vue`
388392

389-
```js
393+
```html
390394
<template>
391395
<div>
392396
<div><input type="text" v-model="restaurant.name" /></div>
393397
<div><textarea v-model="restaurant.description"></textarea></div>
394398
<button @click="createRestaurant();$router.go(-1)">Create</button>
395399
<button @click="$router.go(-1)">Cancel</button>
396-
{{ restaurant }}
397400
</div>
398401
</template>
399402

@@ -415,14 +418,13 @@ const createRestaurant = async () => {
415418

416419
`./pages/restaurant/[id].vue`
417420

418-
```js
421+
```html
419422
<template>
420423
<div>
421424
<div><input type="text" v-model="restaurant.name" /></div>
422425
<div><textarea v-model="restaurant.description"></textarea></div>
423426
<button @click="updateRestaurant();$router.go(-1)">Update</button>
424427
<button @click="$router.go(-1)">Cancel</button>
425-
{{ restaurant }}
426428
</div>
427429
</template>
428430

docs/developer-docs/latest/developer-resources/data-management.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Occasionally you need to move data out of or into a Strapi instance. The data ma
2323
The `strapi export` and `strapi import` CLI commands with all of the available options are listed in the [Command Line Interface documentation](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-export).
2424
:::
2525

26+
:::caution
27+
Interactive CLI commands do not currently work with the `npm` package manager. For `strapi export` and `strapi import` this means the encryption key prompt is not visible in the CLI. A fix is anticipated by early March 2023. In the meantime consider using the `yarn` package manager.
28+
:::
29+
2630
## Export data using the CLI tool
2731

2832
The `strapi export` command, by default, exports data as an encrypted and compressed `.tar.gz.enc` file. The default export command exports:
@@ -56,7 +60,7 @@ yarn strapi export --file my-strapi-export
5660
<code-block title="NPM">
5761

5862
```bash
59-
npm strapi export --file my-strapi-export
63+
npm run strapi export -- --file my-strapi-export
6064
```
6165

6266
</code-block>
@@ -87,7 +91,7 @@ yarn strapi export --no-encrypt
8791
<code-block title="NPM">
8892

8993
```bash
90-
npm strapi export --no-encrypt
94+
npm run strapi export -- --no-encrypt
9195
```
9296

9397
</code-block>
@@ -108,7 +112,7 @@ yarn strapi export --key my-encryption-key
108112
<code-block title="NPM">
109113

110114
```bash
111-
npm strapi export --key my-encryption-key
115+
npm run strapi export -- --key my-encryption-key
112116
```
113117

114118
</code-block>
@@ -134,7 +138,7 @@ yarn strapi export --no-compress
134138
<code-block title="NPM">
135139

136140
```bash
137-
npm strapi export --no-compress
141+
npm run strapi export -- --no-compress
138142
```
139143

140144
</code-block>
@@ -163,7 +167,7 @@ yarn strapi export --only content
163167
<code-block title="NPM">
164168

165169
```bash
166-
npm strapi export --only content
170+
npm run strapi export -- --only content
167171
```
168172

169173
</code-block>
@@ -192,7 +196,7 @@ yarn strapi export --exclude files,content
192196
<code-block title="NPM">
193197

194198
```bash
195-
npm strapi export --exclude files,content
199+
npm run strapi export -- --exclude files,content
196200
```
197201

198202
</code-block>
@@ -231,7 +235,7 @@ yarn strapi import -f export_20221213105643.tar.gz.enc
231235
<code-block title="NPM">
232236

233237
```bash
234-
npm strapi import -f export_20221213105643.tar.gz.enc
238+
npm run strapi import -- -f export_20221213105643.tar.gz.enc
235239
```
236240

237241
</code-block>
@@ -255,7 +259,7 @@ yarn strapi import -f export_20221213105643.tar.gz.enc --key my-encryption-key
255259
<code-block title="NPM">
256260

257261
```bash
258-
npm strapi import -f export_20221213105643.tar.gz.enc --key my-encryption-key
262+
npm run strapi import -- -f export_20221213105643.tar.gz.enc --key my-encryption-key
259263
```
260264

261265
</code-block>
@@ -280,7 +284,7 @@ yarn strapi import -f export_20221213105643.tar.gz.enc --force --key my-encrypti
280284
<code-block title="NPM">
281285

282286
```bash
283-
npm strapi import -f export_20221213105643.tar.gz.enc --force --key my-encryption-key
287+
npm run strapi import -- -f export_20221213105643.tar.gz.enc --force --key my-encryption-key
284288
```
285289

286290
</code-block>
@@ -313,7 +317,7 @@ yarn strapi import -f export_20221213105643.tar.gz.enc --exclude files
313317
<code-block title="NPM">
314318

315319
```bash
316-
npm strapi import -f export_20221213105643.tar.gz.enc --exclude files
320+
npm run strapi import -- -f export_20221213105643.tar.gz.enc --exclude files
317321
```
318322

319323
</code-block>
@@ -342,7 +346,7 @@ yarn strapi import -f export_20221213105643.tar.gz.enc --only config
342346
<code-block title="NPM">
343347

344348
```bash
345-
npm strapi import -f export_20221213105643.tar.gz.enc --only config
349+
npm run strapi import -- -f export_20221213105643.tar.gz.enc --only config
346350
```
347351

348352
</code-block>

docs/developer-docs/latest/developer-resources/plugin-api-reference/server.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To tap into the Server API, create a `strapi-server.js` file at the root of the
2121
| Parameter type | Available parameters |
2222
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2323
| Lifecycle functions | <ul><li> [register](#register)</li><li>[bootstrap](#bootstrap)</li><li>[destroy](#destroy)</li></ul> |
24-
| Configuration | [config](#configuration) object |
24+
| Configuration | <ul><li>[config](#configuration) object </li> <li>[Cron](#cron)</li></ul> |
2525
| Backend customizations | <ul><li>[contentTypes](#content-types)</li><li>[routes](#routes)</li><li>[controllers](#controllers)</li><li>[services](#services)</li><li>[policies](#policies)</li><li>[middlewares](#middlewares)</li></ul> |
2626

2727
## Lifecycle functions
@@ -115,6 +115,25 @@ Once defined, the configuration can be accessed:
115115
* with `strapi.plugin('plugin-name').config('some-key')` for a specific configuration property,
116116
* or with `strapi.config.get('plugin.plugin-name')` for the whole configuration object.
117117

118+
## Cron
119+
120+
The `cron` object allows you to add cron jobs to the Strapi instance.
121+
122+
```js
123+
// path: ./src/plugins/my-plugin/strapi-server.js
124+
125+
module.exports = () => ({
126+
bootstrap({ strapi }) {
127+
strapi.cron.add({
128+
// runs every second
129+
'* * * * * *': ({ strapi }) => {
130+
console.log("hello from plugin")
131+
},
132+
})
133+
},
134+
});
135+
```
136+
118137
## Backend customization
119138

120139
### Content-types

0 commit comments

Comments
 (0)