From 7e60a283f13d92d1edfaf9d5698a5ff721db29da Mon Sep 17 00:00:00 2001 From: Endi Date: Wed, 16 Oct 2019 22:56:36 +0700 Subject: [PATCH] fix(v2): swizzle should be able to handle single js file (#1846) * fix(v2): swizzle should be able to handle single js file * nits --- CHANGELOG-2.x.md | 1 + packages/docusaurus/src/commands/swizzle.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 5700b740b7..04e843d69e 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -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 diff --git a/packages/docusaurus/src/commands/swizzle.ts b/packages/docusaurus/src/commands/swizzle.ts index 0a08b62d57..556aee920d 100644 --- a/packages/docusaurus/src/commands/swizzle.ts +++ b/packages/docusaurus/src/commands/swizzle.ts @@ -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 does not exist, we try to swizzle .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(