-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): adds flag to delete docs from ReadMe if they're no longer…
… in local folder (#581) * feat(openapi): Add `updateSingleSpec` option to automatically update an only available spec file without any prompts * feat(docs): Updated docs * Fix eslint errors * Throw error if using --updateSingleSpec when there are multiple spec files available * Show a warning when passing both `--updateSingleSpec` and `--id` * Update tests snapshot * docs: copy edits, rename flag to `--update` * fix: add logic for if create and update flags passed together * ci: attempt to skip failing step if API key isn't present * Revert "ci: attempt to skip failing step if API key isn't present" This reverts commit 95a8148. * Add --deleteMissing option to `rdme docs` command to delete from ReadMe documents that don't exist on the local folder * Take into account only "guide" categories * chore: markdown formatting * Add warning about what the new option does * Improved typing of functions * Move "if" to a more proper location * Refactor "getSlug" to "readDoc" and reuse code * Removed unused code * Simplify code * Refactored tests to use a folder with a document that should not be deleted * Added a confirmation prompt when folder is empty * Rename --deleteMissing to --cleanup * CR * Undo accidental commit * Update index.ts Co-authored-by: Kanad Gupta <[email protected]>
- Loading branch information
1 parent
12d709b
commit 939bce6
Showing
10 changed files
with
299 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: 5ae122e10fdf4e39bb34db6f | ||
title: This is the document title | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { CommandCategories } from './baseCommand'; | ||
|
||
import config from 'config'; | ||
import { Headers } from 'node-fetch'; | ||
|
||
import fetch, { cleanHeaders, handleRes } from './fetch'; | ||
|
||
/** | ||
* Delete a document from ReadMe | ||
* | ||
* @param {String} key the project API key | ||
* @param {String} selectedVersion the project version | ||
* @param {Boolean} dryRun boolean indicating dry run mode | ||
* @param {String} slug The slug of the document to delete | ||
* @param {String} type module within ReadMe to update (e.g. docs, changelogs, etc.) | ||
* @returns {Promise<String>} a string containing the result | ||
*/ | ||
export default async function deleteDoc( | ||
key: string, | ||
selectedVersion: string, | ||
dryRun: boolean, | ||
slug: string, | ||
type: CommandCategories | ||
): Promise<string> { | ||
if (dryRun) { | ||
return Promise.resolve(`🎭 dry run! This will delete \`${slug}\`.`); | ||
} | ||
return fetch(`${config.get('host')}/api/v1/${type}/${slug}`, { | ||
method: 'delete', | ||
headers: cleanHeaders( | ||
key, | ||
new Headers({ | ||
'x-readme-version': selectedVersion, | ||
'Content-Type': 'application/json', | ||
}) | ||
), | ||
}) | ||
.then(handleRes) | ||
.then(() => `🗑️ successfully deleted \`${slug}\`.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import config from 'config'; | ||
import { Headers } from 'node-fetch'; | ||
|
||
import fetch, { cleanHeaders, handleRes } from './fetch'; | ||
import getCategories from './getCategories'; | ||
|
||
type Document = { | ||
_id: string; | ||
title: string; | ||
slug: string; | ||
order: number; | ||
hidden: boolean; | ||
children: Document[]; | ||
}; | ||
|
||
function flatten(data: Document[][]): Document[] { | ||
return [].concat(...data); | ||
} | ||
|
||
async function getCategoryDocs(key: string, selectedVersion: string, category: string): Promise<Document[]> { | ||
return fetch(`${config.get('host')}/api/v1/categories/${category}/docs`, { | ||
method: 'get', | ||
headers: cleanHeaders( | ||
key, | ||
new Headers({ | ||
'x-readme-version': selectedVersion, | ||
'Content-Type': 'application/json', | ||
}) | ||
), | ||
}).then(handleRes); | ||
} | ||
|
||
/** | ||
* Retrieve the docs under all categories or under a specific one | ||
* | ||
* @param {String} key the project API key | ||
* @param {String} selectedVersion the project version | ||
* @returns {Promise<Array<Document>>} an array containing the docs | ||
*/ | ||
export default async function getDocs(key: string, selectedVersion: string): Promise<Document[]> { | ||
return getCategories(key, selectedVersion) | ||
.then(categories => categories.filter(({ type }: { type: string }) => type === 'guide')) | ||
.then(categories => categories.map(({ slug }: { slug: string }) => getCategoryDocs(key, selectedVersion, slug))) | ||
.then(categoryDocsPromises => Promise.all(categoryDocsPromises)) | ||
.then(flatten); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.