-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2bf4ecc
Showing
9 changed files
with
3,085 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI & CD | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
jobs: | ||
Build-and-Publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
registry-url: https://registry.npmjs.org | ||
cache: pnpm | ||
- name: Install Dependencies | ||
run: pnpm i --frozen-lockfile | ||
|
||
- name: Build & Publish | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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 @@ | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock |
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,5 @@ | ||
#!/bin/sh | ||
|
||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm test |
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,2 @@ | ||
.husky/ | ||
.github/ |
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 @@ | ||
auto-install-peers = false |
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,88 @@ | ||
# Parcel MDX transformer | ||
|
||
Unofficial [MDX][1] 3 [transformer plugin][2] for [Parcel][3] 2 | ||
|
||
## React usage | ||
|
||
### Installation | ||
|
||
```shell | ||
npm init -y | ||
npm i react react-dom | ||
npm i parcel @parcel/config-default parcel-transformer-mdx -D | ||
``` | ||
|
||
### `package.json` | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"start": "parcel ./src/index.html", | ||
"build": "parcel build ./src/index.html --public-url ." | ||
} | ||
} | ||
``` | ||
|
||
### `.parcelrc` | ||
|
||
```json | ||
{ | ||
"extends": "@parcel/config-default", | ||
"transformers": { | ||
"*.{md,mdx}": ["parcel-transformer-mdx"] | ||
} | ||
} | ||
``` | ||
|
||
### `index.html` | ||
|
||
```html | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/prismjs@1.29.0/themes/prism-okaidia.css" | ||
/> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
||
<script type="module" src="index.jsx"></script> | ||
</body> | ||
</html> | ||
``` | ||
|
||
### `index.jsx` | ||
|
||
```jsx | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import Index from './index.mdx'; | ||
|
||
const root = createRoot(document.querySelector('#root')); | ||
|
||
root.render(<Index />); | ||
``` | ||
|
||
### `index.mdx` | ||
|
||
```markdown | ||
--- | ||
title: Hello MDX | ||
--- | ||
|
||
# Hello MDX | ||
|
||
https://react.dev/ | ||
|
||
https://www.youtube.com/watch?v=VEoMT8pAxMA | ||
``` | ||
|
||
## JSX compatible engines usage | ||
|
||
- WebCell example: https://github.com/EasyWebApp/BootCell-document | ||
|
||
[1]: https://mdxjs.com/ | ||
[2]: https://parceljs.org/plugin-system/transformer/ | ||
[3]: https://parceljs.org/ |
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,41 @@ | ||
import { Transformer } from '@parcel/plugin'; | ||
import { compile } from '@mdx-js/mdx'; | ||
import RemarkGFM from 'remark-gfm'; | ||
import RehypePrism from '@mapbox/rehype-prism'; | ||
import remarkEmbedder from '@remark-embedder/core'; | ||
import oembedTransformer from '@remark-embedder/transformer-oembed'; | ||
import RemarkFrontmatter from 'remark-frontmatter'; | ||
|
||
const RemarkEmbedder = remarkEmbedder['default'], | ||
OembedTransformer = oembedTransformer['default']; | ||
|
||
export default new Transformer({ | ||
async loadConfig({ config }) { | ||
const { contents } = await config.getConfig(['tsconfig.json']); | ||
|
||
return contents; | ||
}, | ||
async transform({ asset, config }) { | ||
/** | ||
* @type {import('types-tsconfig').TSConfigJSON['compilerOptions']} | ||
*/ | ||
const { jsx, jsxImportSource } = config.compilerOptions; | ||
|
||
const source = await asset.getCode(); | ||
|
||
const vFile = await compile(source, { | ||
jsxRuntime: jsx === 'react' ? 'classic' : 'automatic', | ||
jsxImportSource, | ||
remarkPlugins: [ | ||
RemarkGFM, | ||
[RemarkEmbedder, { transformers: [OembedTransformer] }], | ||
RemarkFrontmatter | ||
], | ||
rehypePlugins: [RehypePrism] | ||
}); | ||
asset.type = 'jsx'; | ||
asset.setCode(vFile + ''); | ||
|
||
return [asset]; | ||
} | ||
}); |
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 @@ | ||
{ | ||
"name": "parcel-transformer-mdx", | ||
"version": "0.3.0", | ||
"license": "LGPL-3.0-or-later", | ||
"author": "shiy2008@gmail.com", | ||
"type": "module", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@mapbox/rehype-prism": "^0.9.0", | ||
"@mdx-js/mdx": "^3.0.0", | ||
"@parcel/plugin": "^2.11.0", | ||
"@remark-embedder/core": "^3.0.2", | ||
"@remark-embedder/transformer-oembed": "^3.0.0", | ||
"remark-frontmatter": "^5.0.0", | ||
"remark-gfm": "^4.0.0", | ||
"types-tsconfig": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"husky": "^8.0.3", | ||
"lint-staged": "^15.2.0", | ||
"prettier": "^3.2.4" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"arrowParens": "avoid", | ||
"tabWidth": 4 | ||
}, | ||
"lint-staged": { | ||
"*.{md,json,yml,js}": "prettier --write" | ||
}, | ||
"scripts": { | ||
"prepare": "husky install", | ||
"test": "lint-staged" | ||
} | ||
} |
Oops, something went wrong.