From e9f136bbb0da87303a2746027ae010927a3edafd Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Wed, 7 Oct 2020 21:55:44 -0400 Subject: [PATCH] Add nav structure to docs folder --- app/src/modules/docs/composables/use-spec.ts | 26 ------ docs/build.js | 25 +++++- docs/index.d.ts | 37 +++++++++ docs/index.js | 11 +++ docs/nav-app.yaml | 84 ++++++++++++++++++++ docs/nav-web.yaml | 84 ++++++++++++++++++++ docs/package.json | 2 +- package-lock.json | 11 ++- package.json | 3 +- 9 files changed, 251 insertions(+), 32 deletions(-) delete mode 100644 app/src/modules/docs/composables/use-spec.ts create mode 100644 docs/index.d.ts create mode 100644 docs/index.js create mode 100644 docs/nav-app.yaml create mode 100644 docs/nav-web.yaml diff --git a/app/src/modules/docs/composables/use-spec.ts b/app/src/modules/docs/composables/use-spec.ts deleted file mode 100644 index a976e8b6c6..0000000000 --- a/app/src/modules/docs/composables/use-spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import api from '@/api'; -import { ref } from '@vue/composition-api'; -import { OpenAPIObject } from 'openapi3-ts'; - -const spec = ref(); -const loading = ref(false); -const error = ref(null); - -export function useSpec() { - if (loading.value === false && !spec.value) fetchOAS(); - - return { spec, loading, error }; - - async function fetchOAS() { - loading.value = true; - - try { - const response = await api.get('/server/specs/oas'); - spec.value = response.data.data; - } catch (err) { - error.value = err; - } finally { - loading.value = false; - } - } -} diff --git a/docs/build.js b/docs/build.js index de554e71ac..3662ff7beb 100644 --- a/docs/build.js +++ b/docs/build.js @@ -4,16 +4,37 @@ const { promisify } = require('util'); const copyfiles = promisify(require('copyfiles')); const rimraf = promisify(require('rimraf')); const dirTree = require('directory-tree'); +const yaml = require('js-yaml'); async function build() { const distPath = path.resolve(__dirname, './dist'); + await rimraf(distPath); + + const tree = dirTree('.', { extensions: /\.md/, exclude: /dist/ }); + await fse.ensureDir(distPath); - const tree = dirTree('.', { extensions: /\.md/ }); - await fse.writeFile('./dist/index.json', JSON.stringify(tree, null, '\t')); + await fse.writeJSON('./dist/index.json', tree); await copyfiles(['./**/*.md', distPath]); + + const yamlFiles = []; + const filesInRoot = await fse.readdir(__dirname); + + for (const file of filesInRoot) { + if (file.endsWith('.yaml')) { + yamlFiles.push(file); + } + } + + for (const yamlFile of yamlFiles) { + const yamlString = await fse.readFile(yamlFile, 'utf8'); + await fse.writeJSON( + './dist/' + yamlFile.replace('.yaml', '.json'), + yaml.safeLoad(yamlString) + ); + } } build(); diff --git a/docs/index.d.ts b/docs/index.d.ts new file mode 100644 index 0000000000..4bf0c1d792 --- /dev/null +++ b/docs/index.d.ts @@ -0,0 +1,37 @@ +export type File = { + type: 'file'; + size: number; + path: string; + name: string; + extension: string; +}; + +export type Directory = { + type: 'directory'; + size: number; + path: string; + name: string; + children: (Directory | File)[]; +}; + +export type Link = { + name: string; + to: string; +}; + +export type Group = { + name: string; + children: (Group | Link | Divider)[]; + icon?: string; +}; + +export type Divider = { + divider: true; +}; + +export const files: Directory; + +export const nav: { + app: (Group | Link | Divider)[]; + web: (Group | Link | Divider)[]; +}; diff --git a/docs/index.js b/docs/index.js new file mode 100644 index 0000000000..4a29d9988c --- /dev/null +++ b/docs/index.js @@ -0,0 +1,11 @@ +const appNav = require('./dist/nav-app.json'); +const webNav = require('./dist/nav-web.json'); +const index = require('./dist/index.json'); + +module.exports = { + files: index, + nav: { + app: appNav, + web: webNav, + }, +}; diff --git a/docs/nav-app.yaml b/docs/nav-app.yaml new file mode 100644 index 0000000000..9ac9467b7b --- /dev/null +++ b/docs/nav-app.yaml @@ -0,0 +1,84 @@ +- name: Getting Started + icon: play_arrow + children: + - name: Introduction + to: "/getting-started/introduction" + - name: Support & FAQ + to: "/getting-started/support" + - name: Contributing + to: "/getting-started/contributing" + - name: Backing Directus + to: "/getting-started/backing-directus" + +- name: Concepts + icon: school + children: + - name: Platform Overview + to: "/concepts/platform-overview" + - name: App Overview + to: "/concepts/app-overview" + - name: App Extensions + to: "/concepts/app-extensions" + - name: Activity & Versions + to: "/concepts/activity-and-versions" + - name: Files & Thumbnails + to: "/concepts/files-and-thumbnails" + - name: Internationalization + to: "/concepts/internationalization" + - name: Relationships + to: "/concepts/relationships" + - name: Users, Roles & Permissions + to: "/concepts/users-roles-and-permissions" + +- name: Guides + icon: article + children: + - name: Collections + to: "/guides/collections" + - name: Fields + to: "/guides/fields" + - name: Presets + to: "/guides/presets" + - name: Projects + to: "/guides/projects" + - name: Roles & Permissions + to: "/guides/roles-and-permissions" + - name: Users + to: "/guides/users" + - name: Webhooks + to: "/guides/webhooks" + - name: White-Labeling + to: "/guides/white-labeling" + - name: Extensions + to: "/guides/extensions" + children: + - name: Custom Displays + to: "/guides/extensions/creating-a-custom-display" + - name: Custom Interfaces + to: "/guides/extensions/creating-a-custom-interface" + - name: Custom Layouts + to: "/guides/extensions/creating-a-custom-layout" + - name: Custom Modules + to: "/guides/extensions/creating-a-custom-module" + - name: Custom API Endpoints + to: "/guides/extensions/creating-a-custom-api-endpoint" + - name: Custom API Hooks + to: "/guides/extensions/creating-a-custom-api-hook" + - name: Custom Email Templates + to: "/guides/extensions/creating-a-custom-email-template" + - name: Custom Storage Adapters + to: "/guides/extensions/creating-a-custom-storage-adapter" + - name: Accessing Data + to: "/guides/extensions/accessing-data" + +- name: Reference + icon: code + children: + - name: Environment Variables + to: "/reference/environment-variables" + - name: Command Line Interface + to: "/reference/command-line-interface" + - name: Error Codes + to: "/reference/error-codes" + - name: Item Rules + to: "/reference/item-rules" diff --git a/docs/nav-web.yaml b/docs/nav-web.yaml new file mode 100644 index 0000000000..d3248c3f12 --- /dev/null +++ b/docs/nav-web.yaml @@ -0,0 +1,84 @@ +- name: Getting Started + emoji: 🐰 + children: + - name: Introduction + to: "/getting-started/introduction" + - name: Support & FAQ + to: "/getting-started/support" + - name: Contributing + to: "/getting-started/contributing" + - name: Backing Directus + to: "/getting-started/backing-directus" + +- name: Concepts + emoji: 🎓 + children: + - name: Platform Overview + to: "/concepts/platform-overview" + - name: App Overview + to: "/concepts/app-overview" + - name: App Extensions + to: "/concepts/app-extensions" + - name: Activity & Versions + to: "/concepts/activity-and-versions" + - name: Files & Thumbnails + to: "/concepts/files-and-thumbnails" + - name: Internationalization + to: "/concepts/internationalization" + - name: Relationships + to: "/concepts/relationships" + - name: Users, Roles & Permissions + to: "/concepts/users-roles-and-permissions" + +- name: Guides + emoji: 📖 + children: + - name: Collections + to: "/guides/collections" + - name: Fields + to: "/guides/fields" + - name: Presets + to: "/guides/presets" + - name: Projects + to: "/guides/projects" + - name: Roles & Permissions + to: "/guides/roles-and-permissions" + - name: Users + to: "/guides/users" + - name: Webhooks + to: "/guides/webhooks" + - name: White-Labeling + to: "/guides/white-labeling" + - name: Extensions + to: "/guides/extensions" + children: + - name: Custom Displays + to: "/guides/extensions/creating-a-custom-display" + - name: Custom Interfaces + to: "/guides/extensions/creating-a-custom-interface" + - name: Custom Layouts + to: "/guides/extensions/creating-a-custom-layout" + - name: Custom Modules + to: "/guides/extensions/creating-a-custom-module" + - name: Custom API Endpoints + to: "/guides/extensions/creating-a-custom-api-endpoint" + - name: Custom API Hooks + to: "/guides/extensions/creating-a-custom-api-hook" + - name: Custom Email Templates + to: "/guides/extensions/creating-a-custom-email-template" + - name: Custom Storage Adapters + to: "/guides/extensions/creating-a-custom-storage-adapter" + - name: Accessing Data + to: "/guides/extensions/accessing-data" + +- name: Reference + emoji: 🚀 + children: + - name: Environment Variables + to: "/reference/environment-variables" + - name: Command Line Interface + to: "/reference/command-line-interface" + - name: Error Codes + to: "/reference/error-codes" + - name: Item Rules + to: "/reference/item-rules" diff --git a/docs/package.json b/docs/package.json index 7141f7b843..ae5a834af8 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,7 +3,7 @@ "private": false, "version": "9.0.0-beta.9", "description": "", - "main": "dist/index.json", + "main": "index.js", "scripts": { "build": "node build.js", "prepublish": "npm run build" diff --git a/package-lock.json b/package-lock.json index fd47822738..c0252edf39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26397,6 +26397,14 @@ } } }, + "openapi3-ts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/openapi3-ts/-/openapi3-ts-2.0.0.tgz", + "integrity": "sha512-q4p8OX/mD7qXeDKkhdLhpEz1Zh/IxPBDWmuq7f07fQJpo7exUW20sMrHfws1xzihYPktTXVV5MDOZkG/1uguEg==", + "requires": { + "yaml": "^1.10.0" + } + }, "opencollective-postinstall": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", @@ -37489,8 +37497,7 @@ "yaml": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", - "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==", - "dev": true + "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==" }, "yargs": { "version": "13.3.2", diff --git a/package.json b/package.json index ef425aa739..2739be3794 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,8 @@ "@directus/docs": "file:docs", "@directus/specs": "file:packages/spec", "create-directus-project": "file:packages/create-directus-project", - "directus": "file:api" + "directus": "file:api", + "openapi3-ts": "^2.0.0" }, "husky": { "hooks": {