Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: page deletion order in docs:prune #737

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __tests__/cmds/docs/prune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/deleteDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export default async function deleteDoc(
),
})
.then(handleRes)
.then(() => `🗑️ successfully deleted \`${slug}\`.`);
.then(() => `🗑️ successfully deleted \`${slug}\`.`);
}
5 changes: 5 additions & 0 deletions src/lib/getDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down