@nuxtus/nuxtus 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -4
- package/TODO +13 -2
- package/changelog.md +16 -0
- package/client/package.json +3 -1
- package/client/plugins/{directusLogin.ts → directusLogin.client.ts} +2 -2
- package/client/server/api/directus/collection.post.ts +17 -0
- package/client/server/api/directus/field.post.ts +32 -0
- package/package.json +2 -2
- package/server/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# Nuxtus
|
|
2
2
|
|
|
3
|
-
A website w/ CMS boilerplate using [Directus](https://directus.io) for backend CMS and [Nuxt](https://nuxtjs.org) (w/ Tailwind CSS) for frontend.
|
|
3
|
+
A website w/ CMS boilerplate using [Directus](https://directus.io) for backend CMS and [Nuxt](https://nuxtjs.org) (w/ Tailwind CSS) for frontend that can also **automagically** create pages when you create Directus collections.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
https://user-images.githubusercontent.com/324026/175020548-57ee94b3-dee4-4b12-a8c8-6c0f1a94fab4.mov
|
|
7
|
+
|
|
4
8
|
|
|
5
9
|
The purpose of this template is to be a quick-start for developing a website with Nuxt.js using Directus as the backend. The end result can be a static website or dynamically pull data from Directus depending on your preference.
|
|
6
10
|
|
|
7
11
|
It also includes [nuxtus/cli]("https://github.com/nuxtus/cli") which provides a command line interface for quickly creating multiple index/detail pages from any Directus collections.
|
|
8
12
|
|
|
13
|
+
https://user-images.githubusercontent.com/324026/175452950-46bd51a6-3fd9-441d-80fd-c6bbfaa01929.mp4
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
9
17
|
- [Directus](https://directus.io)
|
|
10
18
|
- [Nuxt](https://nuxtjs.org)
|
|
11
19
|
- [Tailwind CSS](https://tailwindcss.nuxtjs.org/)
|
|
@@ -13,6 +21,7 @@ It also includes [nuxtus/cli]("https://github.com/nuxtus/cli") which provides a
|
|
|
13
21
|
- [HeroIcons](https://heroicons.com/)
|
|
14
22
|
- [Google Fonts](https://github.com/nuxt-community/google-fonts-module)
|
|
15
23
|
- [Nuxtus CLI](https://github.com/nuxtus/cli)
|
|
24
|
+
- Typescript types
|
|
16
25
|
|
|
17
26
|
## Quickstart (preferred)
|
|
18
27
|
|
|
@@ -22,7 +31,7 @@ $ npx create-nuxtus app-name
|
|
|
22
31
|
|
|
23
32
|
> Replace `app-name` with the name of your website or application.
|
|
24
33
|
|
|
25
|
-
Nuxtus will automatically
|
|
34
|
+
Nuxtus will automatically migrate the Directus DB if you are using SQLite. Otherwise follow the directions below to manually configure your database and get started.
|
|
26
35
|
|
|
27
36
|
Your project will contain 2 folders server (Directus) and client (Nuxt).
|
|
28
37
|
|
|
@@ -49,9 +58,24 @@ From inside your project folder:
|
|
|
49
58
|
$ npm start
|
|
50
59
|
```
|
|
51
60
|
|
|
52
|
-
###
|
|
61
|
+
### Automatically creating pages
|
|
62
|
+
|
|
63
|
+
**Nuxtus automagically creates Nuxt pages as soon as you create a new Directus collection!**
|
|
64
|
+
|
|
65
|
+
Nuxtus includes a POST endpoint located /api/directus/collection that will run in development. If you used `npx create-nuxtus` to create your Nuxtus project and selected "yes" to automatically creating pages from Directus then this is already configured in Directus for you.
|
|
66
|
+
|
|
67
|
+
Collections are also typed automatically, simply prepend "Items" to the collection name as per below:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { components } from "../interfaces/nuxtus";
|
|
71
|
+
type Test = components["schemas"]["ItemsTest"];
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> Because OpenAPI schemas may have invalid TypeScript characters as names, the square brackets are a safe way to access every property.
|
|
53
75
|
|
|
54
|
-
|
|
76
|
+
### Manually creating pages
|
|
77
|
+
|
|
78
|
+
Nuxtus includes Nuxtus CLI which will generate listing and view pages of any Directus collection on demand. To use it:
|
|
55
79
|
|
|
56
80
|
1. Log in to Directus ([http://0.0.0.0:8055/admin/login](http://0.0.0.0:8055/admin/login)) and [create a collection](https://docs.directus.io/configuration/data-model/#creating-a-collection)
|
|
57
81
|
2. From the client folder (`cd client`) run `nuxtus create` and follow the prompts
|
|
@@ -64,10 +88,19 @@ For more details on [Nuxtus CLI](https://github.com/nuxtus/cli) click [here](htt
|
|
|
64
88
|
|
|
65
89
|
By default Directus is configured to accept CORS from any origin. Nuxtus suggests modifying this for your production deployment.
|
|
66
90
|
|
|
91
|
+
If you chose to install, remove the Nuxtus hook extension by deleting the folder `server/extensions/hooks/nuxtus-hook` from your project.
|
|
92
|
+
|
|
67
93
|
## Manual setup
|
|
68
94
|
|
|
69
95
|
Clone this repo onto your local machine, remove the remote git origin and add a new one. Then follow the [manual install instructions](#directus).
|
|
70
96
|
|
|
71
97
|
> For further instructions visit `[http://localhost:3000](http://localhost:3000)`
|
|
72
98
|
|
|
99
|
+
## Acknowledgements
|
|
100
|
+
|
|
101
|
+
Nuxtus wouldn't be possible without the following amazing technologies:
|
|
73
102
|
|
|
103
|
+
[Directus](https://directus.io)
|
|
104
|
+
[Nuxt](https://nuxt.js.org)
|
|
105
|
+
[Nuxt-Directus](https://nuxt-directus.netlify.app/)
|
|
106
|
+
[OpenApi Typescript](https://www.npmjs.com/package/openapi-typescript)
|
package/TODO
CHANGED
|
@@ -7,8 +7,19 @@ Todo:
|
|
|
7
7
|
✔ Set up [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) @done(22-06-16 20:23)
|
|
8
8
|
☐ Setup [semantic release](https://github.com/semantic-release/semantic-release)
|
|
9
9
|
✔ Add interactive/pretty CLI for create-app.js @done(22-06-16 20:23)
|
|
10
|
-
|
|
10
|
+
✔ Query database use (via interactive shell) in create-app.js @done(22-06-21 20:26)
|
|
11
11
|
✔ Check node version for compatibility in create-app.js @done(22-06-16 22:07)
|
|
12
12
|
☐ Look at https://renovatebot.com/
|
|
13
13
|
☐ Documentation: https://docusaurus.io/ or https://vuepress.vuejs.org/
|
|
14
|
-
|
|
14
|
+
✔ Create Directus flow via Directus API @done(22-07-04 17:46)
|
|
15
|
+
☐ Add ability to automatically update .env for none SQLite databases
|
|
16
|
+
☐ Can I HMR when adding new pages/routes? - requires Nuxt to fix bug
|
|
17
|
+
☐ Add all questions in create-app to start of process for better user flow
|
|
18
|
+
☐ Allow use of different ports/URLs for Directus and Nuxt (currently hard-coded)
|
|
19
|
+
☐ Add "types" to cli to update types from Directus when not using hook
|
|
20
|
+
☐ Make opening browser window on start optional using npm run start
|
|
21
|
+
☐ Make sure separate packages can be used without Nuxt Boilerplate if required
|
|
22
|
+
☐ Console.log messages from directus extension should be formatted like other directus messages
|
|
23
|
+
☐ When adding a new collection the new page triggers a nuxt restart then directus tries to send a field.create which fails. We get around this by getting the create field first but Directus still returns a 404 for the second request.
|
|
24
|
+
✔ interfaces/nuxtus.ts should not be in .gitignore other than during my development (remove in create-nuxtus?) @done(22-07-11 12:52)
|
|
25
|
+
☐ Add test coverage
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Nuxtus
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- Automatically generate types from collections
|
|
6
|
+
- Tidy up server end point
|
|
7
|
+
- Automatically open browser window on Nuxt start
|
|
8
|
+
|
|
9
|
+
## 1.0.6
|
|
10
|
+
|
|
11
|
+
- Add server api endpoint to be used as Directus webhook
|
|
12
|
+
- Update to Directus 9.13.0
|
|
13
|
+
- Update readme with details on using Collections hook
|
|
14
|
+
|
|
15
|
+
## 1.0.5
|
|
16
|
+
|
|
17
|
+
- Update nuxtus-cli to v1.0.3
|
|
18
|
+
|
|
3
19
|
## 1.0.4
|
|
4
20
|
|
|
5
21
|
- Hard delete the data.db file
|
package/client/package.json
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@nuxtjs/google-fonts": "^1.3.0",
|
|
11
11
|
"@nuxtjs/tailwindcss": "^5.0.4",
|
|
12
|
+
"@nuxtus/cli": "^1.0.6",
|
|
13
|
+
"@nuxtus/generator": "1.1.0",
|
|
12
14
|
"nuxt": "3.0.0-rc.4",
|
|
13
|
-
"
|
|
15
|
+
"openapi-typescript": "^5.4.1"
|
|
14
16
|
},
|
|
15
17
|
"dependencies": {
|
|
16
18
|
"@headlessui/vue": "^1.6.1",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
2
|
-
const config = useRuntimeConfig()
|
|
3
|
-
const { login } = useDirectusAuth()
|
|
4
2
|
try {
|
|
3
|
+
const config = useRuntimeConfig()
|
|
4
|
+
const { login } = useDirectusAuth()
|
|
5
5
|
await login({
|
|
6
6
|
email: config.public.directusEmail,
|
|
7
7
|
password: config.public.directusPassword,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createPage } from "@nuxtus/generator"
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
if (process.env.NODE_ENV !== "production") {
|
|
5
|
+
const body = await useBody(event)
|
|
6
|
+
try {
|
|
7
|
+
const collection = body.collection
|
|
8
|
+
createPage(collection, body.singleton)
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err.message)
|
|
11
|
+
throw new Error("Unable to create page: " + err.message)
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
api: "ok",
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from "axios"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import openapiTS from "openapi-typescript"
|
|
4
|
+
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
if (process.env.NODE_ENV !== "production") {
|
|
7
|
+
const config = useRuntimeConfig()
|
|
8
|
+
// TODO: Can't seem to share login from directusLogin (currently client only plugin)
|
|
9
|
+
try {
|
|
10
|
+
const { data } = await axios.post("http://localhost:8055/auth/login", {
|
|
11
|
+
email: config.public.directusEmail,
|
|
12
|
+
password: config.public.directusPassword,
|
|
13
|
+
})
|
|
14
|
+
axios.defaults.headers.common[
|
|
15
|
+
"Authorization"
|
|
16
|
+
] = `Bearer ${data.data.access_token}`
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error("Failed to login to Directus: " + err.message)
|
|
19
|
+
throw err
|
|
20
|
+
}
|
|
21
|
+
const openapi = await axios.get("http://localhost:8055/server/specs/oas")
|
|
22
|
+
// console.log(JSON.stringify(openapi.data.components.schemas))
|
|
23
|
+
const types = await openapiTS(openapi.data)
|
|
24
|
+
if (!fs.existsSync("interfaces")) {
|
|
25
|
+
fs.mkdirSync("interfaces")
|
|
26
|
+
}
|
|
27
|
+
fs.writeFileSync("interfaces/nuxtus.ts", types)
|
|
28
|
+
return {
|
|
29
|
+
api: "ok",
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtus/nuxtus",
|
|
3
3
|
"description": "Directus/Nuxt boilerplate with Tailwind CSS.",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/nuxtus/nuxtus.git"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"client": "cd client && npm run dev",
|
|
27
|
+
"client": "cd client && npm run dev -- -o",
|
|
28
28
|
"server": "cd server && npx directus start",
|
|
29
29
|
"start": "concurrently \"npm run client\" \"npm run server\""
|
|
30
30
|
},
|