mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-25 15:07:17 +02:00
refactor: prefer fs.outputFile to ensureDir + writeFile (#6880)
* refactor: prefer fs.outputFile to ensureDir + writeFile * fix test * fix
This commit is contained in:
parent
73df485aec
commit
23a34c1a07
15 changed files with 66 additions and 108 deletions
|
@ -186,8 +186,7 @@ describe('docsVersion', () => {
|
|||
|
||||
test('first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
const ensureMock = jest.spyOn(fs, 'ensureDir').mockImplementation();
|
||||
const writeMock = jest.spyOn(fs, 'writeFile');
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
writeMock.mockImplementationOnce((filepath, content) => {
|
||||
|
@ -238,13 +237,11 @@ describe('docsVersion', () => {
|
|||
copyMock.mockRestore();
|
||||
writeMock.mockRestore();
|
||||
consoleMock.mockRestore();
|
||||
ensureMock.mockRestore();
|
||||
});
|
||||
|
||||
test('not the first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
const ensureMock = jest.spyOn(fs, 'ensureDir').mockImplementation();
|
||||
const writeMock = jest.spyOn(fs, 'writeFile');
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
writeMock.mockImplementationOnce((filepath, content) => {
|
||||
|
@ -295,15 +292,13 @@ describe('docsVersion', () => {
|
|||
copyMock.mockRestore();
|
||||
writeMock.mockRestore();
|
||||
consoleMock.mockRestore();
|
||||
ensureMock.mockRestore();
|
||||
});
|
||||
|
||||
test('second docs instance versioning', async () => {
|
||||
const pluginId = 'community';
|
||||
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
const ensureMock = jest.spyOn(fs, 'ensureDir').mockImplementation();
|
||||
const writeMock = jest.spyOn(fs, 'writeFile');
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
writeMock.mockImplementationOnce((filepath, content) => {
|
||||
|
@ -350,6 +345,5 @@ describe('docsVersion', () => {
|
|||
copyMock.mockRestore();
|
||||
writeMock.mockRestore();
|
||||
consoleMock.mockRestore();
|
||||
ensureMock.mockRestore();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,8 +47,7 @@ async function createVersionedSidebarFile({
|
|||
versionedSidebarsDir,
|
||||
`version-${version}-sidebars.json`,
|
||||
);
|
||||
await fs.ensureDir(path.dirname(newSidebarFile));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
newSidebarFile,
|
||||
`${JSON.stringify(sidebars, null, 2)}\n`,
|
||||
'utf8',
|
||||
|
@ -140,8 +139,7 @@ export async function cliDocsVersionCommand(
|
|||
|
||||
// Update versions.json file.
|
||||
versions.unshift(version);
|
||||
await fs.ensureDir(path.dirname(versionsJSONFile));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
versionsJSONFile,
|
||||
`${JSON.stringify(versions, null, 2)}\n`,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue