minista 2.8.2 → 3.0.0-alpha.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.
Files changed (131) hide show
  1. package/bin/minista.js +1 -7
  2. package/client.d.ts +11 -72
  3. package/dist/cli/build.js +101 -0
  4. package/dist/cli/develop.js +20 -0
  5. package/dist/cli/index.js +74 -0
  6. package/dist/cli/preview.js +10 -0
  7. package/dist/compile/app.js +107 -0
  8. package/dist/compile/comment.js +20 -0
  9. package/dist/compile/fetch.js +34 -0
  10. package/dist/compile/markdown.js +38 -0
  11. package/dist/compile/tags.js +164 -0
  12. package/dist/config/alias.js +34 -0
  13. package/dist/config/entry.js +104 -0
  14. package/dist/config/index.js +28 -0
  15. package/dist/config/main.js +130 -0
  16. package/dist/{mdx.js → config/mdx.js} +19 -18
  17. package/dist/config/sub.js +24 -0
  18. package/dist/{system.js → config/system.js} +0 -2
  19. package/dist/config/user.js +52 -0
  20. package/dist/config/vite.js +131 -0
  21. package/dist/plugins/bundle.js +24 -0
  22. package/dist/plugins/serve.js +56 -0
  23. package/dist/plugins/ssg.js +110 -0
  24. package/dist/plugins/svgr.js +30 -0
  25. package/dist/server/bundle.js +17 -0
  26. package/dist/server/global.js +38 -0
  27. package/dist/server/pages.js +97 -0
  28. package/dist/server/sources.js +15 -0
  29. package/dist/shared/comment.js +11 -0
  30. package/dist/{define.js → shared/define.js} +0 -2
  31. package/dist/shared/head.js +12 -0
  32. package/dist/{main.d.ts → shared/index.js} +1 -3
  33. package/dist/shared/markdown.js +11 -0
  34. package/dist/types/@types/index.d.ts +1 -0
  35. package/dist/types/cli/build.d.ts +2 -0
  36. package/dist/types/cli/develop.d.ts +2 -0
  37. package/dist/{app.d.ts → types/cli/index.d.ts} +0 -0
  38. package/dist/types/cli/preview.d.ts +2 -0
  39. package/dist/types/compile/app.d.ts +14 -0
  40. package/dist/types/compile/comment.d.ts +1 -0
  41. package/dist/types/compile/fetch.d.ts +5 -0
  42. package/dist/types/compile/markdown.d.ts +2 -0
  43. package/dist/types/compile/tags.d.ts +27 -0
  44. package/dist/types/config/alias.d.ts +12 -0
  45. package/dist/types/config/entry.d.ts +25 -0
  46. package/dist/types/config/index.d.ts +17 -0
  47. package/dist/types/config/main.d.ts +104 -0
  48. package/dist/types/config/mdx.d.ts +5 -0
  49. package/dist/types/config/sub.d.ts +9 -0
  50. package/dist/types/config/system.d.ts +33 -0
  51. package/dist/types/config/user.d.ts +105 -0
  52. package/dist/types/config/vite.d.ts +13 -0
  53. package/dist/types/plugins/bundle.d.ts +2 -0
  54. package/dist/types/plugins/serve.d.ts +3 -0
  55. package/dist/types/plugins/ssg.d.ts +3 -0
  56. package/dist/types/plugins/svgr.d.ts +4 -0
  57. package/dist/{cli.d.ts → types/server/bundle.d.ts} +0 -0
  58. package/dist/types/server/global.d.ts +16 -0
  59. package/dist/types/server/pages.d.ts +26 -0
  60. package/dist/types/server/sources.d.ts +9 -0
  61. package/dist/types/shared/comment.d.ts +11 -0
  62. package/dist/types/shared/define.d.ts +2 -0
  63. package/dist/types/shared/head.d.ts +6 -0
  64. package/dist/types/shared/index.d.ts +4 -0
  65. package/dist/types/shared/markdown.d.ts +11 -0
  66. package/dist/types/utility/path.d.ts +1 -0
  67. package/dist/utility/path.js +9 -0
  68. package/package.json +30 -75
  69. package/LICENSE +0 -21
  70. package/README.md +0 -249
  71. package/dist/app.js +0 -8
  72. package/dist/beautify.d.ts +0 -3
  73. package/dist/beautify.js +0 -24
  74. package/dist/build.d.ts +0 -120
  75. package/dist/build.js +0 -914
  76. package/dist/bundle.d.ts +0 -2
  77. package/dist/bundle.js +0 -4
  78. package/dist/cli.js +0 -120
  79. package/dist/comment.d.ts +0 -6
  80. package/dist/comment.js +0 -11
  81. package/dist/config.d.ts +0 -8
  82. package/dist/config.js +0 -283
  83. package/dist/css.d.ts +0 -3
  84. package/dist/css.js +0 -139
  85. package/dist/define.d.ts +0 -2
  86. package/dist/download.d.ts +0 -3
  87. package/dist/download.js +0 -133
  88. package/dist/empty.d.ts +0 -1
  89. package/dist/empty.js +0 -11
  90. package/dist/esbuild.d.ts +0 -11
  91. package/dist/esbuild.js +0 -131
  92. package/dist/generate.d.ts +0 -15
  93. package/dist/generate.js +0 -268
  94. package/dist/head.d.ts +0 -5
  95. package/dist/head.js +0 -12
  96. package/dist/index.d.ts +0 -7
  97. package/dist/index.js +0 -9
  98. package/dist/link.d.ts +0 -5
  99. package/dist/link.js +0 -21
  100. package/dist/main.js +0 -8
  101. package/dist/mdx.d.ts +0 -5
  102. package/dist/migrate.d.ts +0 -2
  103. package/dist/migrate.js +0 -8
  104. package/dist/optimize.d.ts +0 -1
  105. package/dist/optimize.js +0 -14
  106. package/dist/page.d.ts +0 -11
  107. package/dist/page.js +0 -123
  108. package/dist/pages.d.ts +0 -2
  109. package/dist/pages.js +0 -57
  110. package/dist/path.d.ts +0 -9
  111. package/dist/path.js +0 -43
  112. package/dist/preview.d.ts +0 -2
  113. package/dist/preview.js +0 -10
  114. package/dist/render.d.ts +0 -2
  115. package/dist/render.js +0 -33
  116. package/dist/search.d.ts +0 -50
  117. package/dist/search.js +0 -251
  118. package/dist/server.d.ts +0 -5
  119. package/dist/server.js +0 -65
  120. package/dist/system.d.ts +0 -2
  121. package/dist/types.d.ts +0 -374
  122. package/dist/types.js +0 -2
  123. package/dist/user.d.ts +0 -2
  124. package/dist/user.js +0 -37
  125. package/dist/utils.d.ts +0 -9
  126. package/dist/utils.js +0 -80
  127. package/dist/vite.d.ts +0 -17
  128. package/dist/vite.js +0 -257
  129. package/lib/index.html +0 -23
  130. package/lib/shim-fetch.js +0 -2
  131. package/lib/shim-react.js +0 -2
package/bin/minista.js CHANGED
@@ -1,10 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict"
3
3
 
4
- if (typeof __dirname !== "undefined") {
5
- const version = process.versions.node
6
- console.error(`\nNode.js v${version} is not supported by minista
7
- Please upgrade to a version of Node.js with complete ESM support: "^14.15.0 || >=16.0.0"\n`)
8
- } else {
9
- import("../dist/cli.js")
10
- }
4
+ import("../dist/cli/index.js")
package/client.d.ts CHANGED
@@ -1,91 +1,30 @@
1
- // CSS modules
2
- type CSSModuleClasses = { readonly [key: string]: string }
3
-
4
- declare module "*.module.css" {
5
- const classes: CSSModuleClasses
6
- export default classes
7
- }
8
- declare module "*.module.scss" {
9
- const classes: CSSModuleClasses
10
- export default classes
11
- }
12
- declare module "*.module.sass" {
13
- const classes: CSSModuleClasses
14
- export default classes
15
- }
16
- declare module "*.module.less" {
17
- const classes: CSSModuleClasses
18
- export default classes
19
- }
20
- declare module "*.module.styl" {
21
- const classes: CSSModuleClasses
22
- export default classes
23
- }
24
- declare module "*.module.stylus" {
25
- const classes: CSSModuleClasses
26
- export default classes
27
- }
28
- declare module "*.module.pcss" {
29
- const classes: CSSModuleClasses
30
- export default classes
31
- }
32
-
33
- // CSS
34
- declare module "*.css" {
35
- const css: string
36
- export default css
37
- }
38
- declare module "*.scss" {
39
- const css: string
40
- export default css
41
- }
42
- declare module "*.sass" {
43
- const css: string
44
- export default css
45
- }
46
- declare module "*.less" {
47
- const css: string
48
- export default css
49
- }
50
- declare module "*.styl" {
51
- const css: string
52
- export default css
53
- }
54
- declare module "*.stylus" {
55
- const css: string
56
- export default css
57
- }
58
- declare module "*.pcss" {
59
- const css: string
60
- export default css
61
- }
1
+ /// <reference types="vite/client" />
62
2
 
3
+ // MDX
63
4
  declare module "*.mdx" {
64
5
  import { MDXProps } from "mdx/types"
6
+
65
7
  export default function MDXContent(props: MDXProps): JSX.Element
66
8
  }
67
-
68
9
  declare module "*.md" {
69
- export { default } from "*.mdx"
10
+ import { MDXProps } from "mdx/types"
11
+
12
+ export default function MDXContent(props: MDXProps): JSX.Element
70
13
  }
71
14
 
15
+ // SVGR
72
16
  declare module "*.svg" {
73
17
  import * as React from "react"
74
18
 
75
- const ReactComponent: React.FunctionComponent<
19
+ export const ReactComponent: React.FunctionComponent<
76
20
  React.SVGProps<SVGSVGElement> & { title?: string }
77
21
  >
78
- export default ReactComponent
79
22
  }
80
23
 
24
+ // Partial Hydration
81
25
  declare module "*?ph" {
82
26
  import * as React from "react"
83
27
 
84
- const ReactComponent: React.FunctionComponent<React.PropsWithChildren>
85
- export default ReactComponent
86
- }
87
-
88
- declare module "*?raw" {
89
- const src: string
90
- export default src
28
+ const ph: React.FunctionComponent<React.PropsWithChildren>
29
+ export default ph
91
30
  }
@@ -0,0 +1,101 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ import pc from "picocolors";
4
+ import {
5
+ defineConfig as defineViteConfig,
6
+ mergeConfig as mergeViteConfig,
7
+ build as viteBuild
8
+ } from "vite";
9
+ import beautify from "js-beautify";
10
+ import { resolveConfig } from "../config/index.js";
11
+ import { pluginSsg } from "../plugins/ssg.js";
12
+ import { pluginBundle } from "../plugins/bundle.js";
13
+ async function build(inlineConfig = {}) {
14
+ const config = await resolveConfig(inlineConfig);
15
+ const mergedViteConfig = mergeViteConfig(
16
+ config.vite,
17
+ defineViteConfig({
18
+ build: { write: false },
19
+ plugins: [pluginSsg(config), pluginBundle()]
20
+ })
21
+ );
22
+ const result = await viteBuild(mergedViteConfig);
23
+ const items = result.output;
24
+ if (items.length === 0) {
25
+ return console.log("No content to build.");
26
+ }
27
+ const resolvedOut = path.join(config.sub.resolvedRoot, config.main.out);
28
+ const resolvedPublic = path.join(config.sub.resolvedRoot, config.main.public);
29
+ const hasPublic = await fs.pathExists(resolvedPublic);
30
+ await fs.emptyDir(resolvedOut);
31
+ hasPublic && await fs.copy(resolvedPublic, resolvedOut);
32
+ const bundleCssName = path.join(
33
+ config.main.assets.outDir,
34
+ config.main.assets.bundle.outName + ".css"
35
+ );
36
+ const vite3BugBundleCssName = path.join(
37
+ config.main.assets.outDir,
38
+ "bundle.css"
39
+ );
40
+ const hasBundle = items.some(
41
+ (item) => item.fileName === bundleCssName || item.fileName === vite3BugBundleCssName
42
+ );
43
+ await Promise.all(
44
+ items.map(async (item) => {
45
+ const isPage = item.fileName.match(/src\/pages\/.*\.html$/);
46
+ const isJs = item.fileName.match(/.*\.js$/);
47
+ const isCss = item.fileName.match(/.*\.css$/);
48
+ const isBundleJs = item.fileName.match(/__minista_bundle_assets\.js$/);
49
+ const isBundleCss = item.fileName.match(/__minista_bundle_assets\.css$/);
50
+ const isVite3BugBundleCss = item.fileName === vite3BugBundleCssName;
51
+ if (isBundleJs) {
52
+ return;
53
+ }
54
+ let fileName = item.fileName;
55
+ isPage && (fileName = item.fileName.replace(/src\/pages\//, ""));
56
+ isBundleCss && (fileName = bundleCssName);
57
+ isVite3BugBundleCss && (fileName = bundleCssName);
58
+ let data = "";
59
+ item.source && (data = item.source);
60
+ item.code && (data = item.code);
61
+ if (!data) {
62
+ return;
63
+ }
64
+ if (isPage && !hasBundle) {
65
+ data = data.replace(
66
+ /<link.*data-minista-build-bundle-href=.*?>/g,
67
+ "\n\n"
68
+ );
69
+ }
70
+ if (isPage) {
71
+ data = data.replace(/data-minista-build-bundle-href=/g, "href=").replace(/data-minista-build-css-href=/g, "href=").replace(/data-minista-build-js-src=/g, "src=");
72
+ }
73
+ if (isPage && config.main.beautify.useHtml) {
74
+ data = beautify.html(data, config.main.beautify.htmlOptions);
75
+ }
76
+ if (isJs && config.main.beautify.useAssets) {
77
+ data = beautify.js(data, config.main.beautify.jsOptions);
78
+ }
79
+ if (isCss && config.main.beautify.useAssets) {
80
+ data = beautify.css(data, config.main.beautify.cssOptions);
81
+ }
82
+ const routePath = path.join(
83
+ config.sub.resolvedRoot,
84
+ config.main.out,
85
+ fileName
86
+ );
87
+ const relativePath = path.relative(process.cwd(), routePath);
88
+ const dataSize = (data.length / 1024).toFixed(2);
89
+ return await fs.outputFile(routePath, data).then(() => {
90
+ console.log(
91
+ `${pc.bold(pc.green("BUILD"))} ${pc.bold(relativePath)} ` + pc.gray(`${dataSize} KiB`)
92
+ );
93
+ }).catch((err) => {
94
+ console.error(err);
95
+ });
96
+ })
97
+ );
98
+ }
99
+ export {
100
+ build
101
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ createServer as createViteServer,
3
+ defineConfig as defineViteConfig,
4
+ mergeConfig as mergeViteConfig
5
+ } from "vite";
6
+ import { resolveConfig } from "../config/index.js";
7
+ import { pluginServe } from "../plugins/serve.js";
8
+ async function develop(inlineConfig = {}) {
9
+ const config = await resolveConfig(inlineConfig);
10
+ const mergedViteConfig = mergeViteConfig(
11
+ config.vite,
12
+ defineViteConfig({ plugins: [pluginServe(config)] })
13
+ );
14
+ const viteServer = await createViteServer(mergedViteConfig);
15
+ await viteServer.listen();
16
+ viteServer.printUrls();
17
+ }
18
+ export {
19
+ develop
20
+ };
@@ -0,0 +1,74 @@
1
+ import fs from "fs-extra";
2
+ import { cac } from "cac";
3
+ const cli = cac("minista");
4
+ function pkgVersion() {
5
+ const pkgURL = new URL("../../package.json", import.meta.url);
6
+ const pkg = JSON.parse(fs.readFileSync(pkgURL, "utf8"));
7
+ return pkg.version;
8
+ }
9
+ cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`);
10
+ cli.command("[root]", "start dev server").alias("develop").alias("dev").alias("serve").option("--host [host]", "[string] specify hostname").option("--port <port>", "[number] specify port").option("--strictPort", "[boolean] exit if specified port is already in use").option("--https", "[boolean] use TLS + HTTP/2").option("--open [path]", "[boolean | string] open browser on startup").option("--cors", "[boolean] enable CORS").action(
11
+ async (root, options) => {
12
+ try {
13
+ const { develop } = await import("./develop.js");
14
+ await develop({
15
+ configFile: options.config,
16
+ root,
17
+ base: options.base,
18
+ vite: {
19
+ server: {
20
+ host: options.host,
21
+ port: options.port,
22
+ strictPort: options.strictPort,
23
+ https: options.https,
24
+ open: options.open,
25
+ cors: options.cors
26
+ }
27
+ }
28
+ });
29
+ } catch (err) {
30
+ console.log(err);
31
+ process.exit(1);
32
+ }
33
+ }
34
+ );
35
+ cli.command("build [root]", "build for production").action(async (root, options) => {
36
+ try {
37
+ const { build } = await import("./build.js");
38
+ await build({
39
+ configFile: options.config,
40
+ root,
41
+ base: options.base
42
+ });
43
+ } catch (err) {
44
+ console.log(err);
45
+ process.exit(1);
46
+ }
47
+ });
48
+ cli.command("preview [root]", "locally preview production build").option("--host [host]", "[string] specify hostname").option("--port <port>", "[number] specify port").option("--strictPort", "[boolean] exit if specified port is already in use").option("--https", "[boolean] use TLS + HTTP/2").option("--open [path]", "[boolean | string] open browser on startup").action(
49
+ async (root, options) => {
50
+ try {
51
+ const { preview } = await import("./preview.js");
52
+ await preview({
53
+ configFile: options.config,
54
+ root,
55
+ base: options.base,
56
+ vite: {
57
+ server: {
58
+ host: options.host,
59
+ port: options.port,
60
+ strictPort: options.strictPort,
61
+ https: options.https,
62
+ open: options.open
63
+ }
64
+ }
65
+ });
66
+ } catch (err) {
67
+ console.log(err);
68
+ process.exit(1);
69
+ }
70
+ }
71
+ );
72
+ cli.help();
73
+ cli.version(pkgVersion());
74
+ cli.parse();
@@ -0,0 +1,10 @@
1
+ import { preview as vitePreview } from "vite";
2
+ import { resolveConfig } from "../config/index.js";
3
+ async function preview(inlineConfig = {}) {
4
+ const config = await resolveConfig(inlineConfig);
5
+ const viteServer = await vitePreview(config.vite);
6
+ viteServer.printUrls();
7
+ }
8
+ export {
9
+ preview
10
+ };
@@ -0,0 +1,107 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import ReactDOMServer from "react-dom/server";
3
+ import { StaticRouter } from "react-router-dom/server.js";
4
+ import { HelmetProvider } from "react-helmet-async";
5
+ import { Route, Routes } from "react-router-dom";
6
+ function App({
7
+ resolvedGlobal,
8
+ resolvedPages
9
+ }) {
10
+ const global = resolvedGlobal;
11
+ const routes = resolvedPages;
12
+ return /* @__PURE__ */ jsx(Fragment, {
13
+ children: /* @__PURE__ */ jsx(Routes, {
14
+ children: routes.map((page) => {
15
+ const location = { pathname: page.path };
16
+ if (global.component) {
17
+ const GlobalComponent = global.component;
18
+ const PageComponent = page.component;
19
+ return /* @__PURE__ */ jsx(Route, {
20
+ path: page.path,
21
+ element: /* @__PURE__ */ jsx(GlobalComponent, {
22
+ ...global.staticData.props,
23
+ ...page.staticData.props,
24
+ frontmatter: page.frontmatter,
25
+ location,
26
+ children: /* @__PURE__ */ jsx(PageComponent, {
27
+ ...global.staticData.props,
28
+ ...page.staticData.props,
29
+ frontmatter: page.frontmatter,
30
+ location
31
+ })
32
+ })
33
+ }, page.path);
34
+ } else {
35
+ const PageComponent = page.component;
36
+ return /* @__PURE__ */ jsx(Route, {
37
+ path: page.path,
38
+ element: /* @__PURE__ */ jsx(PageComponent, {
39
+ ...global.staticData.props,
40
+ ...page.staticData.props,
41
+ frontmatter: page.frontmatter,
42
+ location
43
+ })
44
+ }, page.path);
45
+ }
46
+ })
47
+ })
48
+ });
49
+ }
50
+ function compileApp({
51
+ url,
52
+ resolvedGlobal,
53
+ resolvedPages,
54
+ headTags,
55
+ startTags,
56
+ endTags
57
+ }) {
58
+ const helmetContext = {};
59
+ const markup = ReactDOMServer.renderToString(
60
+ /* @__PURE__ */ jsx(StaticRouter, {
61
+ location: url,
62
+ children: /* @__PURE__ */ jsx(HelmetProvider, {
63
+ context: helmetContext,
64
+ children: /* @__PURE__ */ jsx(App, {
65
+ resolvedGlobal,
66
+ resolvedPages
67
+ })
68
+ })
69
+ })
70
+ );
71
+ const { helmet } = helmetContext;
72
+ const staticHelmet = (data) => {
73
+ return data.replace(/data-rh="true"/g, "");
74
+ };
75
+ const htmlAttributes = Object.hasOwn(
76
+ helmet.htmlAttributes.toComponent(),
77
+ "lang"
78
+ ) ? helmet.htmlAttributes.toString() : `lang="ja" ${helmet.htmlAttributes.toString()}`;
79
+ const insertHeadTags = headTags ? headTags : "";
80
+ const insertStartTags = startTags ? `${startTags}
81
+ ` : "";
82
+ const insertEndTags = endTags ? `
83
+ ${endTags}` : "";
84
+ const html = `
85
+ <!doctype html>
86
+ <html ${htmlAttributes}>
87
+ <head>
88
+ <meta charset="UTF-8" />
89
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
90
+ ${staticHelmet(helmet.title.toString())}
91
+ ${staticHelmet(helmet.meta.toString())}
92
+ ${insertHeadTags}
93
+ ${staticHelmet(helmet.link.toString())}
94
+ ${staticHelmet(helmet.style.toString())}
95
+ ${staticHelmet(helmet.script.toString())}
96
+ </head>
97
+ <body ${helmet.bodyAttributes.toString()}>
98
+ ${insertStartTags}${markup}${insertEndTags}
99
+ </body>
100
+ </html>
101
+ `;
102
+ return html;
103
+ }
104
+ export {
105
+ App,
106
+ compileApp
107
+ };
@@ -0,0 +1,20 @@
1
+ import { parse as parseHtml } from "node-html-parser";
2
+ function compileComment(html) {
3
+ let parsedHtml = parseHtml(html);
4
+ const targets = parsedHtml.querySelectorAll(
5
+ `[data-minista-compile-target="comment"]`
6
+ );
7
+ targets.map((target) => {
8
+ const parent = target.parentNode;
9
+ const text = target.innerText;
10
+ const space = text.includes("\n") ? "\n" : " ";
11
+ const content = "<!--" + space + text + space + "-->";
12
+ const parsedContent = parseHtml(content, { comment: true });
13
+ return parent.exchangeChild(target, parsedContent);
14
+ });
15
+ const htmlStr = parsedHtml.toString();
16
+ return htmlStr;
17
+ }
18
+ export {
19
+ compileComment
20
+ };
@@ -0,0 +1,34 @@
1
+ import { transformWithEsbuild } from "vite";
2
+ async function compileFetch(getStaticData) {
3
+ let fncStr = "" + getStaticData;
4
+ const transformedFnc = await transformWithEsbuild(fncStr, "", {
5
+ format: "esm",
6
+ platform: "node",
7
+ loader: "ts"
8
+ });
9
+ fncStr = transformedFnc.code;
10
+ fncStr = `const { fetch } = await import("undici")
11
+ ${fncStr}
12
+ return await getStaticData()`;
13
+ const AsyncFunction = Object.getPrototypeOf(async function() {
14
+ }).constructor;
15
+ const compiledFetch = new AsyncFunction("", fncStr);
16
+ return compiledFetch;
17
+ }
18
+ async function compileGlobalFetch(getStaticData) {
19
+ const compiledFetch = await compileFetch(
20
+ getStaticData
21
+ );
22
+ return compiledFetch;
23
+ }
24
+ async function compilePageFetch(getStaticData) {
25
+ const compiledFetch = await compileFetch(
26
+ getStaticData
27
+ );
28
+ return compiledFetch;
29
+ }
30
+ export {
31
+ compileFetch,
32
+ compileGlobalFetch,
33
+ compilePageFetch
34
+ };
@@ -0,0 +1,38 @@
1
+ import { parse as parseHtml } from "node-html-parser";
2
+ import { compile as compileMdx, run as runMdx } from "@mdx-js/mdx";
3
+ import { createElement } from "react";
4
+ import ReactDOMServer from "react-dom/server";
5
+ async function compileMarkdown(html, config) {
6
+ let parsedHtml = parseHtml(html);
7
+ const targets = parsedHtml.querySelectorAll(
8
+ `[data-minista-compile-target="markdown"]`
9
+ );
10
+ await Promise.all(
11
+ targets.map(async (target) => {
12
+ const parent = target.parentNode;
13
+ const childs = target.childNodes;
14
+ const childsStr = childs.toString();
15
+ const content = await compileMdx(childsStr, config);
16
+ let contentStr = content.value.toString();
17
+ contentStr = contentStr.replace(
18
+ /import {(.+?)} from "react\/jsx-runtime"/,
19
+ 'const {$1} = await import("react/jsx-runtime")'
20
+ );
21
+ contentStr = contentStr.replace(/\sas[(^const.*await import.*?)]/g, ": ");
22
+ contentStr = contentStr.replace(
23
+ /export default MDXContent/g,
24
+ "return MDXContent"
25
+ );
26
+ contentStr = contentStr.replace(/\nexport.*;/g, "\n");
27
+ const contentReact = createElement(await runMdx(contentStr, {}));
28
+ const contentHtml = ReactDOMServer.renderToString(contentReact);
29
+ const parsedContent = parseHtml(contentHtml);
30
+ return parent.exchangeChild(target, parsedContent);
31
+ })
32
+ );
33
+ const htmlStr = parsedHtml.toString();
34
+ return htmlStr;
35
+ }
36
+ export {
37
+ compileMarkdown
38
+ };
@@ -0,0 +1,164 @@
1
+ import path from "node:path";
2
+ import picomatch from "picomatch";
3
+ import { getHtmlPath } from "../utility/path.js";
4
+ function compileBundleTag({
5
+ pathname,
6
+ config
7
+ }) {
8
+ let assetPath = "";
9
+ const assetName = path.join(
10
+ config.main.assets.outDir,
11
+ config.main.assets.bundle.outName + ".css"
12
+ );
13
+ if (config.main.base === "" || config.main.base === "./") {
14
+ const fileName = getHtmlPath(pathname);
15
+ const filePath = path.dirname(fileName);
16
+ const bundleCssPath = path.join("./", assetName);
17
+ const relativePath = path.relative(filePath, bundleCssPath);
18
+ assetPath = relativePath;
19
+ } else {
20
+ assetPath = path.join(config.main.base, assetName);
21
+ }
22
+ return `<link rel="stylesheet" data-minista-build-bundle-href="${assetPath}">`;
23
+ }
24
+ function compileLinkTag({
25
+ mode,
26
+ pathname,
27
+ entry,
28
+ config
29
+ }) {
30
+ let assetPath = "";
31
+ const assetName = path.join(config.main.assets.outDir, entry.name + ".css");
32
+ if (mode === "serve") {
33
+ assetPath = path.join("/", "@minista-project-root", entry.input);
34
+ return `<link rel="stylesheet" href="${assetPath}">`;
35
+ }
36
+ if (config.main.base === "" || config.main.base === "./") {
37
+ const fileName = getHtmlPath(pathname);
38
+ const filePath = path.dirname(fileName);
39
+ const cssPath = path.join("./", assetName);
40
+ const relativePath = path.relative(filePath, cssPath);
41
+ assetPath = relativePath;
42
+ } else {
43
+ assetPath = path.join(config.main.base, assetName);
44
+ }
45
+ return `<link rel="stylesheet" data-minista-build-css-href="${assetPath}">`;
46
+ }
47
+ function compileScriptTag({
48
+ mode,
49
+ pathname,
50
+ entry,
51
+ config
52
+ }) {
53
+ let assetPath = "";
54
+ const assetName = path.join(config.main.assets.outDir, entry.name + ".js");
55
+ const deferStr = entry.loadType === "defer" ? " defer" : "";
56
+ const asyncStr = entry.loadType === "async" ? " async" : "";
57
+ if (mode === "serve") {
58
+ assetPath = path.join("/", "@minista-project-root", entry.input);
59
+ return `<script${deferStr}${asyncStr} src="${assetPath}"><\/script>`;
60
+ }
61
+ if (config.main.base === "" || config.main.base === "./") {
62
+ const fileName = getHtmlPath(pathname);
63
+ const filePath = path.dirname(fileName);
64
+ const cssPath = path.join("./", assetName);
65
+ const relativePath = path.relative(filePath, cssPath);
66
+ assetPath = relativePath;
67
+ } else {
68
+ assetPath = path.join(config.main.base, assetName);
69
+ }
70
+ return `<script${deferStr}${asyncStr} data-minista-build-js-src="${assetPath}"><\/script>`;
71
+ }
72
+ function compileEntryTags({
73
+ mode,
74
+ pathname,
75
+ config
76
+ }) {
77
+ function scriptFilter(entries, isScript) {
78
+ const regex = /\.(js|cjs|mjs|jsx|ts|tsx)$/;
79
+ if (isScript) {
80
+ return entries.filter((entry) => entry.input.match(regex));
81
+ } else {
82
+ return entries.filter((entry) => !entry.input.match(regex));
83
+ }
84
+ }
85
+ function createTags(entries) {
86
+ let linkTags = [];
87
+ let scriptTags = [];
88
+ const linkEntries = scriptFilter(entries, false);
89
+ const scriptEntries = scriptFilter(entries, true);
90
+ if (linkEntries.length > 0) {
91
+ linkTags = linkEntries.map((entry) => {
92
+ return compileLinkTag({
93
+ mode,
94
+ pathname,
95
+ entry,
96
+ config
97
+ });
98
+ });
99
+ }
100
+ if (scriptEntries.length > 0) {
101
+ scriptTags = scriptEntries.map((entry) => {
102
+ return compileScriptTag({
103
+ mode,
104
+ pathname,
105
+ entry,
106
+ config
107
+ });
108
+ });
109
+ }
110
+ return { linkTags, scriptTags };
111
+ }
112
+ let headTags = "";
113
+ let startTags = "";
114
+ let endTags = "";
115
+ let headLinkTags = [];
116
+ let headScriptTags = [];
117
+ let startLinkTags = [];
118
+ let startScriptTags = [];
119
+ let endLinkTags = [];
120
+ let endScriptTags = [];
121
+ let bundleCssTag = "";
122
+ let bundleJsTag = "";
123
+ if (mode === "ssg") {
124
+ bundleCssTag = compileBundleTag({ pathname, config });
125
+ }
126
+ if (mode === "serve") {
127
+ bundleJsTag = `<script type="module">import "/@minista/dist/server/bundle.js"<\/script>`;
128
+ }
129
+ const pageEntries = config.sub.resolvedEntry.filter((entry) => {
130
+ return picomatch.isMatch(pathname, entry.insertPages);
131
+ });
132
+ const headEntries = pageEntries.filter((entry) => entry.position === "head");
133
+ const startEntries = pageEntries.filter((entry) => entry.position === "start");
134
+ const endEntries = pageEntries.filter((entry) => entry.position === "end");
135
+ if (headEntries.length > 0) {
136
+ const { linkTags, scriptTags } = createTags(headEntries);
137
+ headLinkTags = linkTags;
138
+ headScriptTags = scriptTags;
139
+ }
140
+ if (startEntries.length > 0) {
141
+ const { linkTags, scriptTags } = createTags(startEntries);
142
+ startLinkTags = linkTags;
143
+ startScriptTags = scriptTags;
144
+ }
145
+ if (endEntries.length > 0 || mode === "serve") {
146
+ const { linkTags, scriptTags } = createTags(endEntries);
147
+ endLinkTags = linkTags;
148
+ endScriptTags = scriptTags;
149
+ }
150
+ headTags = [...headLinkTags, bundleCssTag, ...headScriptTags].filter((tag) => tag).join("\n");
151
+ startTags = [...startLinkTags, ...startScriptTags].filter((tag) => tag).join("\n");
152
+ endTags = [...endLinkTags, ...endScriptTags, bundleJsTag].filter((tag) => tag).join("\n");
153
+ return {
154
+ headTags,
155
+ startTags,
156
+ endTags
157
+ };
158
+ }
159
+ export {
160
+ compileBundleTag,
161
+ compileEntryTags,
162
+ compileLinkTag,
163
+ compileScriptTag
164
+ };