@startupjs/bundler 0.52.0-alpha.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mdxExamplesLoader.js +21 -43
- package/package.json +4 -4
package/lib/mdxExamplesLoader.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
const REGEX = /(```jsx +example[\s\S]*?\n)([\s\S]*?)(```)/g
|
|
2
|
-
const PURE_REGEX = /(```jsx +pure-example[\s\S]*?\n)([\s\S]*?)(```)/g
|
|
1
|
+
const REGEX = /(```jsx +(?:example|pure-example)[\s\S]*?\n)([\s\S]*?)(```)/g
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
'
|
|
3
|
+
const FLAGS = [
|
|
4
|
+
'example',
|
|
5
|
+
'noscroll',
|
|
6
|
+
'pure-example'
|
|
6
7
|
]
|
|
7
8
|
|
|
8
9
|
const DEFAULT_MDX_RENDERER = `
|
|
@@ -11,20 +12,17 @@ import { observer as __observer } from 'startupjs'
|
|
|
11
12
|
`
|
|
12
13
|
|
|
13
14
|
module.exports = function mdxExamplesLoader (source) {
|
|
14
|
-
|
|
15
|
-
// when the text starts from the first line
|
|
16
|
-
return DEFAULT_MDX_RENDERER +
|
|
17
|
-
'\n' + source.replace(REGEX, replacer).replace(PURE_REGEX, pureReplacer)
|
|
15
|
+
return DEFAULT_MDX_RENDERER + '\n' + source.replace(REGEX, replacer)
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
function replacer (match, p1, p2, p3) {
|
|
21
19
|
const parts = p1.trim().split(' ')
|
|
22
|
-
const sectionParts = []
|
|
23
20
|
const p1Parts = []
|
|
21
|
+
const flags = {}
|
|
24
22
|
|
|
25
23
|
for (const part of parts) {
|
|
26
|
-
if (
|
|
27
|
-
|
|
24
|
+
if (FLAGS.includes(part)) {
|
|
25
|
+
flags[part] = true
|
|
28
26
|
continue
|
|
29
27
|
}
|
|
30
28
|
p1Parts.push(part)
|
|
@@ -32,42 +30,22 @@ function replacer (match, p1, p2, p3) {
|
|
|
32
30
|
|
|
33
31
|
p1 = p1Parts.join(' ')
|
|
34
32
|
|
|
35
|
-
const code =
|
|
33
|
+
const code = flags['pure-example']
|
|
34
|
+
? ''
|
|
35
|
+
: `\n\n${p1}\n[HACK EXAMPLE CODE]${p2}${p3}`
|
|
36
36
|
|
|
37
37
|
p2 = p2.trim().replace(/\n+/g, '\n')
|
|
38
38
|
if (/^</.test(p2)) p2 = 'return (<React.Fragment>' + p2 + '</React.Fragment>)'
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function pureReplacer (match, p1, p2, p3) {
|
|
52
|
-
const parts = p1.trim().split(' ')
|
|
53
|
-
const sectionParts = []
|
|
54
|
-
|
|
55
|
-
for (const part of parts) {
|
|
56
|
-
if (EXAMPLE_FLAGS.includes(part)) {
|
|
57
|
-
sectionParts.push(part)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
p2 = p2.trim().replace(/\n+/g, '\n')
|
|
62
|
-
if (/^</.test(p2)) p2 = 'return (<React.Fragment>' + p2 + '</React.Fragment>)'
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
`<section ${sectionParts.join(' ')}>
|
|
66
|
-
<React.Fragment>
|
|
67
|
-
{React.createElement(__observer(function Example () {
|
|
68
|
-
${p2}
|
|
69
|
-
}))}
|
|
70
|
-
</React.Fragment>
|
|
71
|
-
</section>`
|
|
41
|
+
`{React.createElement(
|
|
42
|
+
_components.section,
|
|
43
|
+
${JSON.stringify(flags)},
|
|
44
|
+
<React.Fragment>
|
|
45
|
+
{React.createElement(__observer(function Example () {
|
|
46
|
+
${p2}
|
|
47
|
+
}))}
|
|
48
|
+
</React.Fragment>
|
|
49
|
+
)}` + code
|
|
72
50
|
)
|
|
73
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startupjs/bundler",
|
|
3
|
-
"version": "0.52.0
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "Opinionated scripts and configs to develop a react-native-web project",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
|
|
22
22
|
"@startupjs/babel-plugin-react-css-modules": "^6.5.4-1",
|
|
23
23
|
"@startupjs/css-to-react-native-transform": "^1.9.0-1",
|
|
24
|
-
"@startupjs/plugin": "^0.
|
|
24
|
+
"@startupjs/plugin": "^0.52.0",
|
|
25
25
|
"@svgr/webpack": "~7.0.0",
|
|
26
26
|
"assets-webpack-plugin": "^7.1.1",
|
|
27
27
|
"autoprefixer": "^10.4.0",
|
|
28
28
|
"babel-loader": "^8.2.3",
|
|
29
|
-
"babel-preset-startupjs": "^0.52.0
|
|
29
|
+
"babel-preset-startupjs": "^0.52.0",
|
|
30
30
|
"css-loader": "^6.5.0",
|
|
31
31
|
"css-minimizer-webpack-plugin": "^5.0.0",
|
|
32
32
|
"file-loader": "^6.2.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react-native-svg": ">= 12.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "257155ad428542785e4d3536b77cd624425ef14a"
|
|
54
54
|
}
|