Skip to content

Commit

Permalink
feat: rdme docs upload (#1159)
Browse files Browse the repository at this point in the history
| 🚥 Resolves RM-11796, RM-11797 |
| :------------------- |

## 🧰 Changes

### 🚧 outstanding work

- [x] core command + helper logic
- [x] tests
- [x] loading states
- [x] complete error messages
- [x] docs 
- [x] migration guide (see #1161)
- [x] callouts in `documentation/rdme.md` (see
#1163)


### 🔜 to be addressed in follow-up PRs

- [ ] safeguards for users that use bidirectional syncing (ticketed in
RM-11883 and RM-11901)
- [ ] updating the v9 migration guide + deprecation warnings (ticketed
in RM-11902)

### things to call out

- on a high level, we're mostly matching the functionality of v9's `rdme
docs` in that we're just taking markdown files and sending its contents
as a body payload to the ReadMe API. inferring page hierarchy from
directory/file structure is out of scope for this work.
- one big change from `rdme@9` is that we now validate page front matter
against the schemas from our OAS before making any API requests and
prompt the user to migrate any frontmatter that we recognize as legacy
APIv1 attributes. i'm open to reevaluating this paradigm, but i think
it'll be helpful for folks migrating. as an interim escape hatch, this
command has a hidden `--skip-validation` flag, just in case.
- our API expects category and parent page URIs to be a full URI (e.g.,
`/versions/stable/categories/guides/some-uri`), but that's a bit arduous
for `rdme` users since most of the URI can be inferred from the `rdme`
command context. as a result, `rdme` will automatically expand any
category/parent URIs that don't match that pattern (i.e., a category URI
front matter value of `some-uri` will be changed to
`/versions/stable/categories/guides/some-uri` before we make the
`POST`/`PATCH` request)
- the vast majority of this diff is tests + fixtures + our OAS. the
three files of note are:
   - `src/lib/syncPagePath.ts`
   - `src/lib/frontmatter.ts`
   - `src/commands/docs/upload.ts`
- i've tried to build this in a testable and robust way where we can
easily add support for reference pages, custom pages, etc. in the future
- `PATCH` requests to our API (i.e., for making updates to guide pages)
that include `slug` in the body payload will always rename the page. so
if you have a slug called `some-page` and your body payload contains
`some-page`, the API will change your slug to `some-page-1`. this is
most likely unexpected behavior for users of `rdme`, so i'm **always**
removing the slug from the body payload in favor of using the URL
instead. the trade-off is that page renaming isn't really a thing via
`rdme`, but that's why we support bidirectional syncing, right?

## 🧬 QA & Testing

we're at nearly 100% test coverage with this work 📈 to QA it yourself,
check out this branch and run the following:

```sh
# install + set up 
npm ci
npm run build
```

```sh
# grab an API key from a readme-refactored-enabled project and pop it at the end of this command:
bin/run.js docs upload __tests__/__fixtures__/docs/mixed-docs --key <key>
```
  • Loading branch information
kanadgupta authored Feb 4, 2025
1 parent 47988b7 commit 69f9c7e
Show file tree
Hide file tree
Showing 32 changed files with 7,953 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ npm run build && npm run build:docs

* [`rdme autocomplete`](documentation/commands/autocomplete.md) - Display autocomplete installation instructions.
* [`rdme changelogs`](documentation/commands/changelogs.md) - Upload Markdown files to your ReadMe project as Changelog posts.
* [`rdme docs`](documentation/commands/docs.md) - Upload Markdown files to the Guides section of your ReadMe project.
* [`rdme help`](documentation/commands/help.md) - Display help for rdme.
* [`rdme login`](documentation/commands/login.md) - Login to a ReadMe project.
* [`rdme logout`](documentation/commands/logout.md) - Logs the currently authenticated user out of ReadMe.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
title: This is another document title
category:
uri: /versions/stable/categories/guides/category-slug
---

Another body
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Body
8 changes: 8 additions & 0 deletions __tests__/__fixtures__/docs/mixed-docs/invalid-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
category:
uri: some-category-uri
is-this-a-valid-property: nope
title: This is the document title
---

Body
6 changes: 6 additions & 0 deletions __tests__/__fixtures__/docs/mixed-docs/legacy-category.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: 5ae122e10fdf4e39bb34db6f
title: This is the document title
---

Body
8 changes: 8 additions & 0 deletions __tests__/__fixtures__/docs/mixed-docs/new-doc-slug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
category:
uri: some-category-uri
title: This is the document title
slug: some-slug
---

Body
Empty file.
5 changes: 5 additions & 0 deletions __tests__/__fixtures__/docs/mixed-docs/simple-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: This is the document title
---

Body
5 changes: 3 additions & 2 deletions __tests__/__fixtures__/docs/multiple-docs/child.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Child
parentDocSlug: parent
parent:
uri: parent
---

# Child Body
Body
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/docs/multiple-docs/friend.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: Friend
---

# Friend Body
Body
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/docs/multiple-docs/grandparent.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: Grandparent
---

# Grandparent Body
Body
5 changes: 3 additions & 2 deletions __tests__/__fixtures__/docs/multiple-docs/parent.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Parent
parentDocSlug: grandparent
parent:
uri: grandparent
---

# Parent Body
Body
3 changes: 2 additions & 1 deletion __tests__/__fixtures__/docs/new-docs/new-doc.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
category: 5ae122e10fdf4e39bb34db6f
category:
uri: category-slug
title: This is the document title
---

Expand Down
5 changes: 3 additions & 2 deletions __tests__/__fixtures__/docs/slug-docs/new-doc-slug.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
category: CATEGORY_ID
category:
uri: some-category-uri
title: This is the document title
slug: marc-actually-wrote-a-test
slug: some-slug
---

Body
Loading

0 comments on commit 69f9c7e

Please sign in to comment.