diff --git a/__tests__/cmds/docs/prune.test.ts b/__tests__/cmds/docs/prune.test.ts index 8b71ca2db..05c840b41 100644 --- a/__tests__/cmds/docs/prune.test.ts +++ b/__tests__/cmds/docs/prune.test.ts @@ -88,7 +88,7 @@ describe('rdme docs:prune', () => { confirm: true, version, }) - ).resolves.toBe('šŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.'); + ).resolves.toBe('šŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.'); apiMocks.done(); versionMock.done(); @@ -116,7 +116,7 @@ describe('rdme docs:prune', () => { key, version, }) - ).resolves.toBe('šŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.'); + ).resolves.toBe('šŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.'); apiMocks.done(); versionMock.done(); @@ -151,7 +151,7 @@ describe('rdme docs:prune', () => { version, }) ).resolves.toBe( - 'šŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.\nšŸ—‘ļø successfully deleted `this-child-is-also-missing`.' + 'šŸ—‘ļø successfully deleted `this-child-is-also-missing`.\nšŸ—‘ļø successfully deleted `this-doc-should-be-missing-in-folder`.' ); apiMocks.done(); diff --git a/src/lib/deleteDoc.ts b/src/lib/deleteDoc.ts index 974a89f1e..9d3d4ce81 100644 --- a/src/lib/deleteDoc.ts +++ b/src/lib/deleteDoc.ts @@ -36,5 +36,5 @@ export default async function deleteDoc( ), }) .then(handleRes) - .then(() => `šŸ—‘ļø successfully deleted \`${slug}\`.`); + .then(() => `šŸ—‘ļø successfully deleted \`${slug}\`.`); } diff --git a/src/lib/getDocs.ts b/src/lib/getDocs.ts index 91d5cfd46..fa76403ce 100644 --- a/src/lib/getDocs.ts +++ b/src/lib/getDocs.ts @@ -24,6 +24,11 @@ function flatten(data: Document[][]): Document[] { }); } }); + + // Docs with children cannot be deleted unless the children are deleted first, + // so move those parent docs to the back of the list + allDocs.sort(a => (a.children?.length ? 1 : -1)); + return allDocs; }