Skip to content

Commit

Permalink
refactor: move docs to apps & top-level clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashroch committed Jan 4, 2025
1 parent 6fedbba commit 532ff6e
Show file tree
Hide file tree
Showing 137 changed files with 257 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
paths-ignore:
- 'deployment/**'
- 'docker/**'
- 'docs/**'
- 'apps/docs/**'
pull_request:
branches: [main]
paths-ignore:
- 'deployment/**'
- 'docker/**'
- 'docs/**'
- 'apps/docs/**'

permissions:
contents: read
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
push:
branches: [main]
paths:
- 'docs/**'
- 'apps/docs/**'
- 'packages/common/src/contracts/**'

permissions:
contents: write
Expand Down Expand Up @@ -32,14 +33,15 @@ jobs:
run: pnpm install

- name: Docs - build
run: pnpm docs:build
working-directory: apps/docs
run: pnpm build

- name: Set CNAME
run: echo "docs.intake24.org" > docs/.vitepress/dist/CNAME
run: echo "docs.intake24.org" > apps/docs/.vitepress/dist/CNAME

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ghp-docs
folder: docs/.vitepress/dist
folder: apps/docs/.vitepress/dist
clean: true
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vitepress';

import { description } from '../../package.json';
import { description } from '../package.json';
import { nav } from './nav';
import { sidebar } from './sidebar';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Deployable applications are in `apps` folder. Shared components are in `packages
├─ apps -> Applications
│ ├─ api -> API Server
│ ├─ admin -> Admin tool
│ ├─ docs -> Documentation
│ ├─ cli -> Command line interface
│ ├─ portal -> Portal website
│ └─ survey -> Survey application
├─ deployment - Ansible playbooks / scripts for deployment
├─ docker - Docker files for development
├─ docs -> Documentation
└─ packages
├─ api-client-v3 -> API Client (Intake24 V3)
├─ api-client-v4 -> API Client (Intake24 V4 - current)
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@intake24/docs",
"type": "module",
"version": "2024.8",
"private": true,
"description": "Intake24 documentation",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/MRC-Epid-it24/intake24.git",
"directory": "apps/docs"
},
"scripts": {
"dev": "pnpm open-api && vitepress dev",
"build": "pnpm open-api && vitepress build",
"serve": "pnpm open-api && vitepress serve",
"open-api": "pnpm tsx scripts/open-api.ts"
},
"devDependencies": {
"@ts-rest/open-api": "^3.51.0",
"@types/node": "^22.10.2",
"typescript": "^5.7.2",
"vitepress": "^1.5.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
160 changes: 160 additions & 0 deletions apps/docs/scripts/open-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';

import { generateOpenApi } from '@ts-rest/open-api';

import contract from '@intake24/common/contracts';

import pkg from '../package.json';

const defaultRecall = {
type: 'object',
properties: {
preMeals: { type: 'array', items: [] },
meals: { type: 'object', properties: {
preFoods: { type: 'array', items: [] },
foods: { type: 'array', items: [] },
postFoods: { type: 'array', items: [] },
} },
postMeals: { type: 'array', items: [] },
submission: { type: 'array', items: [] },
},
};

async function main() {
const document = generateOpenApi(contract, {
info: {
title: 'Intake24 API Reference',
description: pkg.description,
license: {
name: pkg.license,
url: 'https://opensource.org/license/apache-2-0',
},
version: pkg.version,
},
servers: [
{
url: 'https://api.example.com',
description: 'Intake24 API instance',
},
],
components: {
securitySchemes: {
bearerHttpAuthentication: {
description: 'Bearer token using a JWT',
type: 'http',
scheme: 'Bearer',
bearerFormat: 'JWT',
},
},
},
}, {
operationMapper: (operation, appRoute) => {
/*
* !!! TEMP HACKY REMOVAL OF HUGE RECALL SURVEY SCHEME OPEN API JSON SCHEME !!!
* - size of the open-api json file grows from ~15MB to ~150MB, which is due to survey scheme recall JSON schema
* - TODO: figure out how to maybe use JSON $refs with @ts-rest/open-api ?
*/
if (appRoute.path === '/surveys/:slug/parameters') {
operation.responses['200'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall };
return operation;
}

if (
appRoute.path === '/admin/survey-schemes'
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId'
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/edit'
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/copy'
|| appRoute.path === '/admin/survey-schemes/:surveySchemeId/templates'
) {
if (operation.requestBody?.content['application/json']?.schema?.properties?.prompts)
operation.requestBody.content['application/json'].schema.properties.prompts = { ...defaultRecall };

if (operation.responses['200']?.content['application/json'].schema?.properties?.data)
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' };
if (operation.responses['200']?.content['application/json'].schema?.properties?.prompts)
operation.responses['200'].content['application/json'].schema.properties.prompts = { ...defaultRecall };
if (operation.responses['201']?.content['application/json'].schema?.properties?.prompts)
operation.responses['201'].content['application/json'].schema.properties.prompts = { ...defaultRecall };

return operation;
}

if (
appRoute.path === '/admin/survey-scheme-prompts'
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId'
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId/edit'
|| appRoute.path === '/admin/survey-scheme-prompts/:surveySchemePromptId/sync'
) {
if (operation.requestBody?.content['application/json']?.schema?.properties?.prompt)
operation.requestBody.content['application/json'].schema.properties.prompt = { type: 'object' };

if (operation.responses['200']?.content['application/json'].schema?.properties?.data)
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' };
if (operation.responses['200']?.content['application/json'].schema?.properties?.prompt)
operation.responses['200'].content['application/json'].schema.properties.prompt = { type: 'object' };
if (operation.responses['201']?.content['application/json'].schema?.properties?.prompt)
operation.responses['201'].content['application/json'].schema.properties.prompt = { type: 'object' };

return operation;
}

if (
appRoute.path === '/admin/surveys'
|| appRoute.path === '/admin/surveys/:surveyId'
|| appRoute.path === '/admin/surveys/:surveyId/edit'
) {
if (operation.requestBody?.content['application/json']?.schema?.properties?.surveySchemeOverrides?.properties?.prompts)
operation.requestBody.content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' };

if (operation.responses['200']?.content['application/json'].schema?.properties?.surveySchemeOverrides?.properties?.prompts)
operation.responses['200'].content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' };
if (operation.responses['201']?.content['application/json'].schema?.properties?.surveySchemeOverrides?.properties?.prompts)
operation.responses['201'].content['application/json'].schema.properties.surveySchemeOverrides.properties.prompts = { type: 'array' };

if (operation.responses['200']?.content['application/json'].schema?.properties?.surveyScheme?.properties?.prompts)
operation.responses['200'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall };
if (operation.responses['201']?.content['application/json'].schema?.properties?.surveyScheme?.properties?.prompts)
operation.responses['201'].content['application/json'].schema.properties.surveyScheme.properties.prompts = { ...defaultRecall };

return operation;
}

if (appRoute.path === '/admin/survey-schemes/refs') {
if (operation.responses['200']?.content['application/json'].schema?.properties?.templates)
operation.responses['200'].content['application/json'].schema.properties.templates = { type: 'array' };

return operation;
}

if (appRoute.path === '/admin/survey-scheme-prompts/refs') {
if (operation.responses['200']?.content['application/json'].schema?.properties?.schemes)
operation.responses['200'].content['application/json'].schema.properties.schemes = { type: 'array' };

return operation;
}

if (appRoute.path === '/admin/references/survey-schemes') {
if (operation.responses['200']?.content['application/json'].schema?.properties?.data)
operation.responses['200'].content['application/json'].schema.properties.data = { type: 'array' };

return operation;
}

return operation;
},
});

writeFileSync(
resolve('public', 'open-api.json'),
JSON.stringify(document, null, 2),
'utf8',
);
}

main().catch((err) => {
console.error(err);

process.exitCode = process.exitCode ?? 1;
process.exit();
});
File renamed without changes.
9 changes: 9 additions & 0 deletions apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@intake24/common/*": ["../../packages/common/src/*"]
}
}
}
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
"db:system:migrate:undo": "pnpm --filter @intake24/db db:system:migrate:undo",
"cli": "pnpm --filter @intake24/cli cli",
"i18n:sync": "pnpm --filter @intake24/i18n i18n:sync",
"docs:dev": "pnpm docs:open-api && vitepress dev docs",
"docs:build": "pnpm docs:open-api && vitepress build docs",
"docs:serve": "pnpm docs:open-api && vitepress serve docs",
"docs:open-api": "pnpm tsx scripts/open-api.ts",
"changelog": "conventional-changelog -p angular",
"release": "pnpm tsx scripts/release.ts",
"lint": "eslint . --fix",
Expand All @@ -50,7 +46,6 @@
},
"devDependencies": {
"@antfu/eslint-config": "^3.12.1",
"@ts-rest/open-api": "^3.51.0",
"@types/node": "^22.10.2",
"@types/prompts": "^2.4.9",
"calver": "^24.1.0",
Expand All @@ -65,9 +60,7 @@
"rimraf": "^6.0.1",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"vite": "^6.0.5",
"vitepress": "^1.5.0"
"typescript": "^5.7.2"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged",
Expand Down
Loading

0 comments on commit 532ff6e

Please sign in to comment.