Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): Extract npm2yarn plugin (#3469)
* chore(v2): add dependency * test(v2): Add npm2yarn tests * feat(v2): Move npm2yarn to a new remark plugin * remark npm2yarn plugin => ready to release Co-authored-by: slorber <lorber.sebastien@gmail.com>
- Loading branch information
Showing
13 changed files
with
232 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Remark plugin npm2yarn | ||
|
||
## Motivation: | ||
|
||
Transforms npm bash command code blocks to Docusaurus tabs: | ||
|
||
The following (remove the `//`): | ||
|
||
````bash | ||
// ```bash npm2yarn | ||
// npm run build | ||
// ``` | ||
```` | ||
|
||
Becomes: | ||
|
||
![npm2yarn tabs example](./example.png) | ||
|
||
**Note**: it only works when used with Docusaurus themes that have the `Tabs` and `TabItems` components. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @docusaurus/remark-plugin-npm2yarn` | ||
``` | ||
|
||
It is a Remark plugin, **not a Docusaurus plugin**, so you have to install it as a Remark plugin in the config of your Docusaurus plugins. | ||
|
||
```js | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
docs: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
blog: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
pages: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
// ... | ||
}, | ||
], | ||
], | ||
// ... | ||
}; | ||
``` |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
{ | ||
"name": "@docusaurus/remark-plugin-npm2yarn", | ||
"version": "2.0.0-alpha.65", | ||
"description": "Remark plugin for convert npm commands to yarn as tabs", | ||
"main": "src/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"npm-to-yarn": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"remark": "^12.0.0", | ||
"remark-mdx": "^1.5.8", | ||
"to-vfile": "^6.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.4", | ||
"react-dom": "^16.8.4" | ||
}, | ||
"engines": { | ||
"node": ">=10.15.1" | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__snapshots__/index.test.js.snap
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,74 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`npm2yarn plugin test: installation file 1`] = ` | ||
"import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
<Tabs defaultValue=\\"npm\\" values={[ | ||
{ label: 'npm', value: 'npm', }, | ||
{ label: 'Yarn', value: 'yarn', }, | ||
]} | ||
> | ||
<TabItem value=\\"npm\\"> | ||
\`\`\`bash | ||
$ npm install --global docusaurus | ||
\`\`\` | ||
</TabItem> | ||
<TabItem value=\\"yarn\\"> | ||
\`\`\`bash | ||
$ yarn add --global docusaurus | ||
\`\`\` | ||
</TabItem> | ||
</Tabs> | ||
" | ||
`; | ||
exports[`npm2yarn plugin test: language was not setted 1`] = ` | ||
"\`\`\`npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
\`\`\`bash | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
\`\`\`shell | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
" | ||
`; | ||
exports[`npm2yarn plugin test: plugin file 1`] = ` | ||
"import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
## Installing a plugin | ||
A plugin is usually a npm package, so you install them like other npm packages using npm. | ||
<Tabs defaultValue=\\"npm\\" values={[ | ||
{ label: 'npm', value: 'npm', }, | ||
{ label: 'Yarn', value: 'yarn', }, | ||
]} | ||
> | ||
<TabItem value=\\"npm\\"> | ||
\`\`\`bash | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
</TabItem> | ||
<TabItem value=\\"yarn\\"> | ||
\`\`\`bash | ||
yarn add docusaurus-plugin-name | ||
\`\`\` | ||
</TabItem> | ||
</Tabs> | ||
" | ||
`; |
3 changes: 3 additions & 0 deletions
3
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/installation.md
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,3 @@ | ||
```bash npm2yarn | ||
$ npm install --global docusaurus | ||
``` |
7 changes: 7 additions & 0 deletions
7
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/plugin.md
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,7 @@ | ||
## Installing a plugin | ||
|
||
A plugin is usually a npm package, so you install them like other npm packages using npm. | ||
|
||
```bash npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
``` |
11 changes: 11 additions & 0 deletions
11
...saurus-remark-plugin-npm2yarn/src/__tests__/fixtures/syntax-not-properly-set.md
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,11 @@ | ||
```npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
``` | ||
|
||
```bash | ||
npm install --save docusaurus-plugin-name | ||
``` | ||
|
||
```shell | ||
npm install --save docusaurus-plugin-name | ||
``` |
53 changes: 53 additions & 0 deletions
53
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/index.test.js
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,53 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/* eslint-disable no-param-reassign */ | ||
|
||
import remark from 'remark'; | ||
import npm2yarn from '../index'; | ||
import vfile from 'to-vfile'; | ||
import {join, relative} from 'path'; | ||
import mdx from 'remark-mdx'; | ||
|
||
const staticDir = `./${relative(process.cwd(), join(__dirname, 'fixtures'))}`; | ||
|
||
const processFixture = async (name, options) => { | ||
const path = join(__dirname, 'fixtures', `${name}.md`); | ||
const file = await vfile.read(path); | ||
const result = await remark() | ||
.use(mdx) | ||
.use(npm2yarn, {...options, filePath: path}) | ||
.process(file); | ||
|
||
return result.toString(); | ||
}; | ||
|
||
describe('npm2yarn plugin', () => { | ||
test('test: installation file', async () => { | ||
const result = await processFixture('installation', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('test: plugin file', async () => { | ||
const result = await processFixture('plugin', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('test: language was not setted', async () => { | ||
const result = await processFixture('syntax-not-properly-set', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
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