From 45b7a1b7c81a3b4a805932d93aa49dbcbcf1fdbf Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sat, 26 Mar 2022 12:51:54 +0300 Subject: [PATCH] refactor: remove copyright comment from swizzled components (#7017) * refactor: remove copyright comment from swizzled components * Update packages/docusaurus/src/commands/swizzle/actions.ts Co-authored-by: Joshua Chen Co-authored-by: Joshua Chen --- .../__fixtures__/theme/ComponentInFolder/index.css | 10 +++++++++- .../__fixtures__/theme/ComponentInFolder/index.tsx | 7 +++++++ .../__fixtures__/theme/FirstLevelComponent.css | 7 +++++++ .../__fixtures__/theme/FirstLevelComponent.tsx | 7 +++++++ packages/docusaurus/src/commands/swizzle/actions.ts | 6 +++++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.css b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.css index 7aa192f3b3..555b0869f0 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.css +++ b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.css @@ -1,3 +1,11 @@ -.testClass { + +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + .testClass { background: black; } diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.tsx b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.tsx index c8a3a86a5f..dc1a164502 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.tsx +++ b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/ComponentInFolder/index.tsx @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + import React from 'react'; export default function ComponentInFolder() { diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.css b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.css index 7aa192f3b3..29c5ece80f 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.css +++ b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.css @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + .testClass { background: black; } diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.tsx b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.tsx index 6cd8764e91..3cde34503d 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.tsx +++ b/packages/docusaurus/src/commands/swizzle/__tests__/__fixtures__/theme/FirstLevelComponent.tsx @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + import React from 'react'; export default function FirstLevelComponent() { diff --git a/packages/docusaurus/src/commands/swizzle/actions.ts b/packages/docusaurus/src/commands/swizzle/actions.ts index f85bfb7a0f..8cb8929507 100644 --- a/packages/docusaurus/src/commands/swizzle/actions.ts +++ b/packages/docusaurus/src/commands/swizzle/actions.ts @@ -81,7 +81,11 @@ export async function eject({ const fileName = path.basename(sourceFile); const targetFile = path.join(toPath, fileName); try { - await fs.copy(sourceFile, targetFile, {overwrite: true}); + const fileContents = await fs.readFile(sourceFile, 'utf-8'); + await fs.outputFile( + targetFile, + fileContents.trimStart().replace(/^\/\*.+?\*\/\s*/ms, ''), + ); } catch (err) { throw new Error( logger.interpolate`Could not copy file from ${sourceFile} to ${targetFile}`,