fix(v2): swizzle should be able to handle single js file (#1846)

* fix(v2): swizzle should be able to handle single js file

* nits
This commit is contained in:
Endi 2019-10-16 22:56:36 +07:00 committed by Yangshun Tay
parent d96b5f99b9
commit 7e60a283f1
2 changed files with 8 additions and 1 deletions

View file

@ -5,6 +5,7 @@
- Fix `keywords` frontmatter for SEO not working properly.
- Fix `swizzle` command not passing context properly to theme packages.
- Add `extendCli` api for plugins. This will allow plugin to further extend Docusaurus CLI.
- Fix `swizzle` command not being able to swizzle single js file.
## 2.0.0-alpha.27

View file

@ -28,12 +28,18 @@ export async function swizzle(
if (componentName) {
fromPath = path.join(fromPath, componentName);
toPath = path.join(toPath, componentName);
// Handle single js file only.
// E.g: if <fromPath> does not exist, we try to swizzle <fromPath>.js instead
if (!fs.existsSync(fromPath) && fs.existsSync(`${fromPath}.js`)) {
[fromPath, toPath] = [`${fromPath}.js`, `${toPath}.js`];
}
}
await fs.copy(fromPath, toPath);
const relativeDir = path.relative(process.cwd(), toPath);
const fromMsg = chalk.blue(
componentName ? `${themeName}/${componentName}` : themeName,
componentName ? `${themeName} ${chalk.yellow(componentName)}` : themeName,
);
const toMsg = chalk.cyan(relativeDir);
console.log(