mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 12:22:45 +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
|
@ -144,8 +144,7 @@ export default function ${wrapperComponentName}(props) {
|
|||
}
|
||||
`;
|
||||
|
||||
await fs.ensureDir(path.dirname(toPath));
|
||||
await fs.writeFile(toPath, content);
|
||||
await fs.outputFile(toPath, content);
|
||||
|
||||
return {createdFiles: [toPath]};
|
||||
}
|
||||
|
|
|
@ -552,8 +552,7 @@ describe('extractSiteSourceCodeTranslations', () => {
|
|||
SRC_DIR_NAME,
|
||||
'site-component-1.jsx',
|
||||
);
|
||||
await fs.ensureDir(path.dirname(siteComponentFile1));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
siteComponentFile1,
|
||||
`
|
||||
import Translate from '@docusaurus/Translate';
|
||||
|
@ -586,8 +585,7 @@ export default function MySiteComponent1() {
|
|||
|
||||
const plugin1Dir = await createTmpDir();
|
||||
const plugin1File1 = path.join(plugin1Dir, 'subpath', 'file1.jsx');
|
||||
await fs.ensureDir(path.dirname(plugin1File1));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
plugin1File1,
|
||||
`
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
|
@ -606,8 +604,7 @@ export default function MyComponent() {
|
|||
`,
|
||||
);
|
||||
const plugin1File2 = path.join(plugin1Dir, 'src', 'theme', 'file2.jsx');
|
||||
await fs.ensureDir(path.dirname(plugin1File2));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
plugin1File2,
|
||||
`
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
|
@ -624,8 +621,7 @@ export default function MyComponent() {
|
|||
|
||||
// This one should not be found! On purpose!
|
||||
const plugin1File3 = path.join(plugin1Dir, 'unscannedFolder', 'file3.jsx');
|
||||
await fs.ensureDir(path.dirname(plugin1File3));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
plugin1File3,
|
||||
`
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
|
@ -643,8 +639,7 @@ export default function MyComponent() {
|
|||
|
||||
const plugin2Dir = await createTmpDir();
|
||||
const plugin2File = path.join(plugin1Dir, 'subpath', 'file.tsx');
|
||||
await fs.ensureDir(path.dirname(plugin2File));
|
||||
await fs.writeFile(
|
||||
await fs.outputFile(
|
||||
plugin2File,
|
||||
`
|
||||
import Translate, {translate} from '@docusaurus/Translate';
|
||||
|
|
|
@ -131,8 +131,10 @@ Maybe you should remove them? ${unknownKeys}`;
|
|||
} translations will be written at path=${toMessageRelativeFilePath(
|
||||
filePath,
|
||||
)}.`;
|
||||
await fs.ensureDir(path.dirname(filePath));
|
||||
await fs.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
|
||||
await fs.outputFile(
|
||||
filePath,
|
||||
`${JSON.stringify(mergedContent, null, 2)}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue