feat(v2): add support for sync to npm2yarn tabs (#3705)

This commit is contained in:
Alexey Pyltsyn 2020-11-06 19:30:32 +03:00 committed by GitHub
parent f31dcb6844
commit 3aeb90fcac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View file

@ -10,14 +10,15 @@ const npmToYarn = require('npm-to-yarn');
// E.g. global install: 'npm i' -> 'yarn'
const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn');
const transformNode = (node) => {
const transformNode = (node, isSync) => {
const groupIdProp = isSync ? 'groupId="npm2yarn" ' : '';
const npmCode = node.value;
const yarnCode = convertNpmToYarn(node.value);
return [
{
type: 'jsx',
value:
`<Tabs defaultValue="npm" ` +
`<Tabs defaultValue="npm" ${groupIdProp}` +
`values={[
{ label: 'npm', value: 'npm', },
{ label: 'Yarn', value: 'yarn', },
@ -53,12 +54,13 @@ const nodeForImport = {
"import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';",
};
module.exports = () => {
module.exports = (options = {}) => {
const {sync = false} = options;
let transformed = false;
const transformer = (node) => {
if (matchNode(node)) {
transformed = true;
return transformNode(node);
return transformNode(node, sync);
}
if (Array.isArray(node.children)) {
let index = 0;