From 5549a0ce83ad7eccdcfefa809b5e905f7d599253 Mon Sep 17 00:00:00 2001 From: maticzav Date: Mon, 15 Feb 2021 19:08:01 +0100 Subject: [PATCH] TOC formatter --- README.md | 5 ++--- package.json | 1 + scripts/index.ts | 18 ++++++++++++++++-- scripts/tsconfig.json | 2 +- yarn.lock | 8 ++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 06b2de88..533dde0f 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ You can also run `swift-graphql help` to learn more about options and how it wor --- - + - [Why?](#why) - [How does it work?](#howdoesitwork) @@ -142,8 +142,7 @@ You can also run `swift-graphql help` to learn more about options and how it wor - [What are the pitfalls in Apollo iOS that you were referring to at the top?](#whatarethepitfallsinapolloiosthatyouwerereferringtoatthetop) - [Roadmap and Contributing](#roadmapandcontributing) - [Thank you](#thankyou) - - [License](#license) - +- [License](#license) ## Why? diff --git a/package.json b/package.json index d1267ba7..cdf179a4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "devDependencies": { "@types/marked": "^1.2.2", + "@types/prettier": "^2.2.1", "husky": "^4.3.6", "marked": "^2.0.0", "prettier": "^2.2.1", diff --git a/scripts/index.ts b/scripts/index.ts index ca7a87d8..e4b4d871 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -1,6 +1,7 @@ import fs from 'fs' -import path from 'path' import marked from 'marked' +import path from 'path' +import prettier from 'prettier' import { promisify } from 'util' const readfile = promisify(fs.readFile) @@ -35,7 +36,20 @@ main() * Updates table of contents with a given index. */ function update(raw: string, index: string): string { - return raw.replace(/([\w\W]*)/, index) + index = ` + + ${index} + + ` + + const source = raw.replace( + /([\w\W]*)/, + index, + ) + + return prettier.format(source, { + parser: 'markdown', + }) } /** diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 0bb0b250..35da856d 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -8,5 +8,5 @@ "esModuleInterop": true }, - "include": ["./**/*.ts"] + "include": ["./*.ts"] } diff --git a/yarn.lock b/yarn.lock index a3c35f73..ba058d20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3064,6 +3064,13 @@ __metadata: languageName: node linkType: hard +"@types/prettier@npm:^2.2.1": + version: 2.2.1 + resolution: "@types/prettier@npm:2.2.1" + checksum: 9dc257dfc51eab6bc1e9ce58df94b309a206b2cdc6768709de3d20f70ae545c616bbc46add6d66f66cfa6cfbb0613dd09e6b6028ff6ff8ba9d3625f38d85cc66 + languageName: node + linkType: hard + "@types/prop-types@npm:*": version: 15.7.3 resolution: "@types/prop-types@npm:15.7.3" @@ -14863,6 +14870,7 @@ fsevents@~2.3.1: resolution: "swift-graphql@workspace:." dependencies: "@types/marked": ^1.2.2 + "@types/prettier": ^2.2.1 husky: ^4.3.6 marked: ^2.0.0 prettier: ^2.2.1