-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): easier plugin theme components swizzling (#1436)
* feat(v2): easier plugin theme components override * add context * refactor again * rename eject -> swizzle * nits
- Loading branch information
Showing
11 changed files
with
91 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const fs = require('fs-extra'); | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
const importFresh = require('import-fresh'); | ||
|
||
module.exports = async function swizzle(siteDir, themeName, componentName) { | ||
const Plugin = importFresh(themeName); | ||
const context = {siteDir}; | ||
const PluginInstance = new Plugin(context); | ||
let fromPath = PluginInstance.getThemePath(); | ||
|
||
if (fromPath) { | ||
let toPath = path.resolve(siteDir, 'theme'); | ||
if (componentName) { | ||
fromPath = path.join(fromPath, componentName); | ||
toPath = path.join(toPath, componentName); | ||
} | ||
await fs.copy(fromPath, toPath); | ||
|
||
const relativeDir = path.relative(process.cwd(), toPath); | ||
const fromMsg = chalk.blue( | ||
componentName ? `${themeName}/${componentName}` : themeName, | ||
); | ||
const toMsg = chalk.cyan(relativeDir); | ||
console.log( | ||
`\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters