Skip to content

Commit

Permalink
TOC formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Feb 15, 2021
1 parent 9934ab2 commit 5549a0c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ You can also run `swift-graphql help` to learn more about options and how it wor

---

<!-- index-start -->
<!-- index-start -->

- [Why?](#why)
- [How does it work?](#howdoesitwork)
Expand All @@ -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)
<!-- index-end -->

## Why?
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions scripts/index.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -35,7 +36,20 @@ main()
* Updates table of contents with a given index.
*/
function update(raw: string, index: string): string {
return raw.replace(/<!-- index-start -->([\w\W]*)<!-- index-end -->/, index)
index = `
<!-- index-start -->
${index}
<!-- index-end -->
`

const source = raw.replace(
/<!-- index-start -->([\w\W]*)<!-- index-end -->/,
index,
)

return prettier.format(source, {
parser: 'markdown',
})
}

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

"esModuleInterop": true
},
"include": ["./**/*.ts"]
"include": ["./*.ts"]
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5549a0c

Please sign in to comment.