polywrap / documentation

8 stars 14 forks source link

Extract doc-snippets package #235

Closed pileks closed 1 year ago

pileks commented 1 year ago

Closes #232

Due to an unfortunate series of commands, I've locked myself out of publishing the doc-snippets package under the doc-snippets name for the next 24 hours. This PR will be updated with the appropriate package once NPM lets me.

TODO:

New repository

https://github.com/polywrap/doc-snippets

PR description

This PR aims to extract the logic behind snippet extraction/injection into its own package. Additionally, the package exposes a simple CLI tool that combines the extraction and injection logic which allows devs to run the "default" behavior without much hassle.

Exported functions:

extractSnippets(dir) //Returns a `Record<string, string>` of all snippets found within `dir`.

injectSnippets(snippets, dir) //Injects snippets into .md files found inside `dir`

The CLI can be called as follows:

doc-snippets combine <snippetsDir> <docsDir> <outputDir>

# Example used within the documentation package
# Extracts snippets from ./snippets and outputs a copy of ./src/docs into ./docs with injected snippets
doc-snippets combine ./snippets ./src/docs ./docs