minista 2.0.0-alpha.9 → 2.0.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/README.md CHANGED
@@ -12,20 +12,26 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
+ ## Site & Documentation
16
+
17
+ https://minista.qranoko.jp
18
+
15
19
  ## About
16
20
 
17
- Next.js Like Development with 100% Static Generate.
21
+ minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的な出力を行えます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
18
22
 
19
23
  ## How To Use
20
24
 
21
25
  ### Automatic Setup
22
26
 
23
- not supported
27
+ ```bash
28
+ $ npm init minista@latest
29
+ ```
24
30
 
25
31
  ### Manual Setup
26
32
 
27
33
  ```bash
28
- $ npm install --save-dev minista@next react react-dom
34
+ $ npm install --save-dev minista react react-dom
29
35
  ```
30
36
 
31
37
  ```bash
@@ -48,7 +54,7 @@ const PageHome = () => {
48
54
  export default PageHome
49
55
  ```
50
56
 
51
- Open `package.json` and add the following scripts:
57
+ `package.json` を開き、以下のスクリプトを追加します。
52
58
 
53
59
  ```json
54
60
  "scripts": {
@@ -70,19 +76,101 @@ Open `package.json` and add the following scripts:
70
76
 
71
77
  ```js
72
78
  // minista.config.ts
73
- import { defineMinistaUserConfig } from "minista"
74
-
75
- export default defineMinistaUserConfig({
76
- entry: undefined, // string | string[] | { [key: string]: string }
77
- outDir: "dist", // string
78
- publicDir: "public", // string
79
- assetsDir: "assets", // string
80
- autoAssetsName: "bundle", // string
81
- vite: undefined, // https://vitejs.dev/config/
82
- markdown: { remarkPlugins: [] }, // https://mdxjs.com/packages/mdx/#optionsremarkplugins
79
+ import { defineConfig } from "minista"
80
+
81
+ export default defineConfig({
82
+ base: "/", // string
83
+ public: "public", // string
84
+ out: "dist", // string
85
+ root: {
86
+ srcDir: "src", // string
87
+ srcName: "root", // string
88
+ srcExt: ["tsx", "jsx"], // string[]
89
+ },
90
+ pages: {
91
+ srcDir: "src/pages", // string
92
+ srcExt: ["tsx", "jsx", "md", "mdx"], // string[]
93
+ },
94
+ assets: {
95
+ entry: "", // string | string[] | { [key: string]: string }
96
+ outDir: "assets", // string
97
+ bundle: {
98
+ outName: "bundle", // string
99
+ },
100
+ images: {
101
+ outDir: "assets/images", // string
102
+ outName: "[name]", // string
103
+ },
104
+ fonts: {
105
+ outDir: "assets/fonts", // string
106
+ outName: "[name]", // string
107
+ },
108
+ icons: {
109
+ useSprite: true, // boolean
110
+ srcDir: "src/assets/icons", // string
111
+ outDir: "assets/images", // string
112
+ outName: "icons", // string
113
+ svgstoreOptions: {
114
+ cleanSymbols: ["fill", "stroke", "stroke-linejoin", "stroke-width"],
115
+ }, // https://github.com/svgstore/svgstore#svgstore-options
116
+ },
117
+ download: {
118
+ useRemote: false, // boolean
119
+ remoteUrl: ["https://", "http://"], // string[]
120
+ remoteName: "remote-[index]", // string
121
+ outDir: "assets/images", // string
122
+ },
123
+ },
124
+ vite: {}, // https://vitejs.dev/config/
125
+ markdown: {
126
+ syntaxHighlighter: "highlight", // "highlight" | "none"
127
+ highlightOptions: {}, // https://github.com/rehypejs/rehype-highlight#options
128
+ mdxOptions: {
129
+ remarkPlugins: [], // https://mdxjs.com/packages/mdx/#optionsremarkplugins
130
+ rehypePlugins: [], // https://mdxjs.com/packages/mdx/#optionsrehypeplugins
131
+ },
132
+ },
133
+ beautify: {
134
+ useHtml: true, // boolean
135
+ useAssets: false, // boolean
136
+ htmlOptions: {
137
+ indent_size: 2,
138
+ max_preserve_newlines: 0,
139
+ indent_inner_html: true,
140
+ extra_liners: [],
141
+ inline: ["span", "b", "br", "code", "del", "s", "small", "strong", "wbr"],
142
+ }, // https://github.com/beautify-web/js-beautify#css--html
143
+ cssOptions: {}, // https://github.com/beautify-web/js-beautify#css--html
144
+ jsOptions: {}, // https://github.com/beautify-web/js-beautify#options
145
+ },
83
146
  })
84
147
  ```
85
148
 
149
+ ## Libraries
150
+
151
+ - `minista-sitemap`: [repo](https://github.com/qrac/minista-sitemap) / [npm](https://www.npmjs.com/package/minista-sitemap)
152
+ - `minista-markdown`: [repo](https://github.com/qrac/minista-markdown) / [npm](https://www.npmjs.com/package/minista-markdown)
153
+
154
+ ## Media
155
+
156
+ - v1
157
+ - [React で書ける SSG 改善点と今後について - minista v1](https://zenn.dev/qrac/articles/a24de970148c7e)
158
+ - [React(JSX)で書けるコーディング用 SSG - minista v0](https://zenn.dev/qrac/articles/7537521afcd1bf)
159
+
160
+ ## Respect
161
+
162
+ - [Next.js by Vercel - The React Framework](https://nextjs.org/)
163
+ - [Charge — an opinionated, zero-config static site generator](https://charge.js.org/)
164
+ - [Eleventy, a simpler static site generator.](https://www.11ty.dev/)
165
+ - [Node Interface | webpack](https://webpack.js.org/api/node/)
166
+ - [natemoo-re/microsite](https://github.com/natemoo-re/microsite)
167
+ - [Astro](https://astro.build/)
168
+ - [テンプレートエンジンに React を使いつつ、きれいな HTML を生成したいんじゃ!!](https://zenn.dev/otsukayuhi/articles/e52651b4e2c5ae7c4a17)
169
+ - [EJS をやめて React で HTML を書く](https://zenn.dev/hisho/scraps/4ef6c6106a6395)
170
+ - [MPA(マルチページアプリ)で webpack を使う](https://www.key-p.com/blog/staff/archives/107125)
171
+ - [HTML コーディングでも React+TypeScript の開発体験を得る](https://zenn.dev/nanaki14/articles/html-template-react)
172
+ - [Astro と microCMS でポートフォリオサイトを作る](https://zenn.dev/takanorip/articles/c75717c280c81d)
173
+
86
174
  ## License
87
175
 
88
176
  - MIT
@@ -0,0 +1,3 @@
1
+ import type { HTMLBeautifyOptions, CSSBeautifyOptions, JSBeautifyOptions } from "js-beautify";
2
+ export declare function beautifyFiles(entryPoints: string[], target: "html" | "css" | "js", options: HTMLBeautifyOptions | CSSBeautifyOptions | JSBeautifyOptions): Promise<void>;
3
+ export declare function beautifyFile(entryPoint: string, target: "html" | "css" | "js", options: HTMLBeautifyOptions | CSSBeautifyOptions | JSBeautifyOptions): Promise<void>;
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import fs from "fs-extra";
3
+ import pc from "picocolors";
4
+ import beautify from "js-beautify";
5
+ async function beautifyFiles(entryPoints, target, options) {
6
+ await Promise.all(entryPoints.map(async (entryPoint) => {
7
+ await beautifyFile(entryPoint, target, options);
8
+ }));
9
+ }
10
+ async function beautifyFile(entryPoint, target, options) {
11
+ const source = await fs.readFile(entryPoint, "utf8");
12
+ const runBeautify = target === "html" ? beautify.html : target === "css" ? beautify.css : beautify;
13
+ const result = runBeautify(source, options);
14
+ await fs.outputFile(entryPoint, result).then(() => {
15
+ console.log(`${pc.bold(pc.blue("BEAUT"))} ${pc.bold(entryPoint)}`);
16
+ }).catch((err) => {
17
+ console.error(err);
18
+ });
19
+ }
20
+ export {
21
+ beautifyFile,
22
+ beautifyFiles
23
+ };
package/dist/build.d.ts CHANGED
@@ -1,30 +1,36 @@
1
1
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
2
2
  import type { InlineConfig } from "vite";
3
- import type { RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData } from "./types.js";
3
+ import type { MinistaResolveConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData } from "./types.js";
4
4
  export declare function buildTempPages(entryPoints: string[], buildOptions: {
5
- outbase: string;
6
- outdir: string;
5
+ outBase: string;
6
+ outDir: string;
7
7
  mdxConfig: MdxOptions;
8
8
  }): Promise<void>;
9
9
  export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
10
- outbase: string;
11
- outdir: string;
12
- }, assetsTagStr?: string): Promise<void>;
10
+ outBase: string;
11
+ outDir: string;
12
+ }, assetsTagStr: string): Promise<void>;
13
13
  export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
14
14
  component: RootJsxContent;
15
15
  staticData: GlobalStaticData;
16
16
  }>;
17
17
  export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
18
- export declare function buildStaticPage(entryPoint: string, outFile: string, rootStaticContent: RootStaticContent, assetsTagStr?: string): Promise<void>;
18
+ export declare function buildStaticPage(entryPoint: string, outFile: string, rootStaticContent: RootStaticContent, assetsTagStr: string, outDir: string): Promise<void>;
19
19
  export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
20
- export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr?: string, frontmatter?: {}): Promise<void>;
20
+ export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr: string, frontmatter: any, outDir: string): Promise<void>;
21
21
  export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
22
- fileName: string;
23
- outdir: string;
22
+ bundleOutName: string;
23
+ outDir: string;
24
24
  assetDir: string;
25
25
  }): Promise<void>;
26
26
  export declare function buildAssetsTagStr(entryPoints: string[], buildOptions: {
27
- outbase: string;
28
- outdir: string;
27
+ outBase: string;
28
+ outDir: string;
29
29
  }): Promise<string>;
30
+ export declare function buildViteImporterRoots(config: MinistaResolveConfig): Promise<void>;
31
+ export declare function buildViteImporterRoutes(config: MinistaResolveConfig): Promise<void>;
32
+ export declare function buildViteImporterAssets(entry: {
33
+ [key: string]: string;
34
+ }): Promise<void>;
35
+ export declare function buildViteImporterBlankAssets(): Promise<void>;
30
36
  export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
package/dist/build.js CHANGED
@@ -25,9 +25,11 @@ import pc from "picocolors";
25
25
  import { Fragment } from "react";
26
26
  import { build as esBuild } from "esbuild";
27
27
  import mdx from "@mdx-js/esbuild";
28
- import { build as viteBuild, mergeConfig } from "vite";
28
+ import { build as viteBuild, mergeConfig as mergeViteConfig } from "vite";
29
+ import { systemConfig } from "./system.js";
29
30
  import { resolvePlugin } from "./esbuild.js";
30
31
  import { renderHtml } from "./render.js";
32
+ import { slashEnd } from "./utils.js";
31
33
  const __filename = url.fileURLToPath(import.meta.url);
32
34
  const __dirname = path.dirname(__filename);
33
35
  async function buildTempPages(entryPoints, buildOptions) {
@@ -48,8 +50,8 @@ async function buildTempPages(entryPoints, buildOptions) {
48
50
  ];
49
51
  await esBuild({
50
52
  entryPoints,
51
- outbase: buildOptions.outbase,
52
- outdir: buildOptions.outdir,
53
+ outbase: buildOptions.outBase,
54
+ outdir: buildOptions.outDir,
53
55
  outExtension: { ".js": ".mjs" },
54
56
  bundle: true,
55
57
  format: "esm",
@@ -72,9 +74,9 @@ async function buildStaticPages(entryPoints, tempRootFilePath, buildOptions, ass
72
74
  await Promise.all(entryPoints.map(async (entryPoint) => {
73
75
  const extname = path.extname(entryPoint);
74
76
  const basename = path.basename(entryPoint, extname);
75
- const dirname = path.dirname(entryPoint).replace(buildOptions.outbase, buildOptions.outdir);
77
+ const dirname = path.dirname(entryPoint).replace(buildOptions.outBase, buildOptions.outDir);
76
78
  const filename = path.join(dirname, basename + ".html");
77
- await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr);
79
+ await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr, buildOptions.outDir);
78
80
  }));
79
81
  }
80
82
  async function buildRootEsmContent(tempRootFilePath) {
@@ -95,7 +97,7 @@ async function buildGlobalStaticData(getGlobalStaticData) {
95
97
  const response = await getGlobalStaticData();
96
98
  return response;
97
99
  }
98
- async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr) {
100
+ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr, outDir) {
99
101
  const pageEsmContent = await import(path.resolve(entryPoint));
100
102
  const pageJsxContent = pageEsmContent.default;
101
103
  const frontmatter = pageEsmContent.frontmatter ? pageEsmContent.frontmatter : void 0;
@@ -103,11 +105,11 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
103
105
  const staticData = pageEsmContent.getStaticData ? await buildStaticData(pageEsmContent.getStaticData) : void 0;
104
106
  if (!staticData) {
105
107
  const staticDataItem = defaultStaticDataItem;
106
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter);
108
+ return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
107
109
  }
108
110
  if ("props" in staticData && "paths" in staticData === false) {
109
111
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
110
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter);
112
+ return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
111
113
  }
112
114
  if ("paths" in staticData) {
113
115
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
@@ -116,7 +118,7 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
116
118
  const reg = new RegExp("\\[" + key + "\\]", "g");
117
119
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
118
120
  }
119
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter);
121
+ return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
120
122
  }
121
123
  if (Array.isArray(staticData) && staticData.length > 0) {
122
124
  const entryPoints = staticData;
@@ -127,7 +129,7 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
127
129
  const reg = new RegExp("\\[" + key + "\\]", "g");
128
130
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
129
131
  }
130
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter);
132
+ return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
131
133
  }));
132
134
  }
133
135
  }
@@ -135,11 +137,18 @@ async function buildStaticData(getStaticData) {
135
137
  const response = await getStaticData();
136
138
  return response;
137
139
  }
138
- async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter) {
140
+ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir) {
141
+ if (frontmatter == null ? void 0 : frontmatter.draft) {
142
+ return;
143
+ }
139
144
  const RootComponent = rootStaticContent.component;
140
145
  const globalStaticData = rootStaticContent.staticData;
141
146
  const PageComponent = pageJsxContent;
142
147
  const staticProps = staticDataItem.props;
148
+ const reg1 = new RegExp(`^${outDir}|index.html`, "g");
149
+ const reg2 = new RegExp(`.html`, "g");
150
+ const pathname = routePath.replace(reg1, "").replace(reg2, "");
151
+ const location = { pathname };
143
152
  const RenderComponent = () => {
144
153
  if (RootComponent === Fragment) {
145
154
  return /* @__PURE__ */ React.createElement(Fragment, null, (() => {
@@ -147,26 +156,30 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
147
156
  return /* @__PURE__ */ React.createElement(Fragment, null);
148
157
  } else {
149
158
  return /* @__PURE__ */ React.createElement(PageComponent, __spreadProps(__spreadValues(__spreadValues({}, globalStaticData == null ? void 0 : globalStaticData.props), staticProps), {
150
- frontmatter: RootComponent !== Fragment && frontmatter
159
+ frontmatter,
160
+ location
151
161
  }));
152
162
  }
153
163
  })());
154
164
  } else {
155
165
  return /* @__PURE__ */ React.createElement(RootComponent, __spreadProps(__spreadValues(__spreadValues({}, globalStaticData == null ? void 0 : globalStaticData.props), staticProps), {
156
- frontmatter: RootComponent !== Fragment && frontmatter
166
+ frontmatter,
167
+ location
157
168
  }), (() => {
158
169
  if (PageComponent === Fragment) {
159
170
  return /* @__PURE__ */ React.createElement(Fragment, null);
160
171
  } else {
161
172
  return /* @__PURE__ */ React.createElement(PageComponent, __spreadProps(__spreadValues(__spreadValues({}, globalStaticData == null ? void 0 : globalStaticData.props), staticProps), {
162
- frontmatter: RootComponent !== Fragment && frontmatter
173
+ frontmatter,
174
+ location
163
175
  }));
164
176
  }
165
177
  })());
166
178
  }
167
179
  };
168
180
  const html = await renderHtml(/* @__PURE__ */ React.createElement(RenderComponent, null), assetsTagStr);
169
- await fs.outputFile(routePath, html).then(() => {
181
+ const replacedHtml = html.replace(/<div class="minista-comment" hidden="">(.+?)<\/div>/g, "\n<!-- $1 -->");
182
+ await fs.outputFile(routePath, replacedHtml).then(() => {
170
183
  console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
171
184
  }).catch((err) => {
172
185
  console.error(err);
@@ -178,23 +191,23 @@ async function buildTempAssets(viteConfig, buildOptions) {
178
191
  write: false,
179
192
  rollupOptions: {
180
193
  input: {
181
- __minista_auto_bundle_asset_pages: path.resolve(__dirname + "/../dist/pages.js")
194
+ __minista_bundle_assets: path.resolve(__dirname + "/../dist/bundle.js")
182
195
  }
183
196
  }
184
197
  }
185
198
  };
186
- const mergedConfig = mergeConfig(viteConfig, customConfig);
199
+ const mergedConfig = mergeViteConfig(viteConfig, customConfig);
187
200
  const result = await viteBuild(mergedConfig);
188
201
  const items = result.output;
189
202
  if (Array.isArray(items) && items.length > 0) {
190
203
  items.map((item) => {
191
- if (item.fileName.match(/__minista_auto_bundle_asset_pages\.css/)) {
192
- const customFileName = `${buildOptions.outdir}/${buildOptions.fileName}.css`;
204
+ if (item.fileName.match(/__minista_bundle_assets\.css/)) {
205
+ const customFileName = slashEnd(buildOptions.outDir) + buildOptions.bundleOutName + ".css";
193
206
  return (item == null ? void 0 : item.source) && fs.outputFile(customFileName, item == null ? void 0 : item.source);
194
- } else if (item.fileName.match(/__minista_auto_bundle_asset_pages\.js/)) {
207
+ } else if (item.fileName.match(/__minista_bundle_assets\.js/)) {
195
208
  return;
196
209
  } else {
197
- const customFileName = buildOptions.outdir + item.fileName.replace(buildOptions.assetDir, "");
210
+ const customFileName = buildOptions.outDir + item.fileName.replace(buildOptions.assetDir, "");
198
211
  const customCode = (item == null ? void 0 : item.source) ? item == null ? void 0 : item.source : (item == null ? void 0 : item.code) ? item == null ? void 0 : item.code : "";
199
212
  return customCode && fs.outputFile(customFileName, customCode);
200
213
  }
@@ -203,28 +216,116 @@ async function buildTempAssets(viteConfig, buildOptions) {
203
216
  }
204
217
  async function buildAssetsTagStr(entryPoints, buildOptions) {
205
218
  const assetsTags = entryPoints.map((entryPoint) => {
206
- const assetPath = entryPoint.replace(buildOptions.outbase, buildOptions.outdir);
219
+ const assetPath = entryPoint.replace(buildOptions.outBase, buildOptions.outDir);
207
220
  if (assetPath.endsWith(".css")) {
208
- return `<link rel="stylesheet" href="/${assetPath}">`;
221
+ return `<link rel="stylesheet" href="${assetPath}">`;
209
222
  } else if (assetPath.endsWith(".js")) {
210
- return `<script defer src="/${assetPath}"><\/script>`;
223
+ return `<script defer src="${assetPath}"><\/script>`;
211
224
  }
212
225
  });
213
226
  const assetsTagStr = assetsTags.join("");
214
227
  return assetsTagStr;
215
228
  }
216
- async function buildCopyDir(targetDir, outDir, log) {
217
- return fs.copy(targetDir, outDir).then(() => {
218
- if (log === "public") {
219
- console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(targetDir + "/**/* -> " + outDir)}`);
220
- }
221
- if (log === "assets") {
222
- console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outDir)}`);
229
+ async function buildViteImporterRoots(config) {
230
+ const outFile = systemConfig.temp.viteImporter.outDir + "/roots.js";
231
+ const rootSrcDir = slashEnd(config.rootSrcDir);
232
+ const rootSrcName = config.root.srcName;
233
+ const rootExtStr = config.root.srcExt.join();
234
+ const template = `import { Fragment } from "react"
235
+ export const getRoots = () => {
236
+ const ROOTS = import.meta.globEager("/${rootSrcDir}${rootSrcName}.{${rootExtStr}}")
237
+ const roots =
238
+ Object.keys(ROOTS).length === 0
239
+ ? [{ RootComponent: Fragment, getGlobalStaticData: undefined }]
240
+ : Object.keys(ROOTS).map((root) => {
241
+ return {
242
+ RootComponent: ROOTS[root].default ? ROOTS[root].default : Fragment,
243
+ getGlobalStaticData: ROOTS[root].getStaticData
244
+ ? ROOTS[root].getStaticData
245
+ : undefined,
246
+ }
247
+ })
248
+ return roots
249
+ }`;
250
+ await fs.outputFile(outFile, template).catch((err) => {
251
+ console.error(err);
252
+ });
253
+ }
254
+ async function buildViteImporterRoutes(config) {
255
+ const outFile = systemConfig.temp.viteImporter.outDir + "/routes.js";
256
+ const pagesDir = slashEnd(config.pagesSrcDir);
257
+ const pagesExtStr = config.pages.srcExt.join();
258
+ const pagesDirRegStr = config.pagesSrcDir.replace(/\//g, "\\/");
259
+ const replacePagesStr = `.replace(/^\\/${pagesDirRegStr}\\//g, "${config.base}")`;
260
+ const replaceFileNameArray = config.pages.srcExt.map((ext) => {
261
+ return `.replace(/\\index|\\.${ext}$/g, "")`;
262
+ });
263
+ const replaceFileNameArrayStr = replaceFileNameArray.join("\n ");
264
+ const template = `export const getRoutes = () => {
265
+ const ROUTES = import.meta.globEager("/${pagesDir}**/[a-z[]*.{${pagesExtStr}}")
266
+ const routes = Object.keys(ROUTES).map((route) => {
267
+ const routePath = route
268
+ ${replacePagesStr}
269
+ ${replaceFileNameArrayStr}
270
+ .replace(/\\[\\.{3}.+\\]/, "*")
271
+ .replace(/\\[(.+)\\]/, ":$1")
272
+ return {
273
+ routePath: routePath,
274
+ PageComponent: ROUTES[route].default,
275
+ getStaticData: ROUTES[route].getStaticData
276
+ ? ROUTES[route].getStaticData
277
+ : undefined,
278
+ frontmatter: ROUTES[route].frontmatter
279
+ ? ROUTES[route].frontmatter
280
+ : undefined,
223
281
  }
224
- }).catch((err) => {
282
+ })
283
+ return routes
284
+ }`;
285
+ await fs.outputFile(outFile, template).catch((err) => {
286
+ console.error(err);
287
+ });
288
+ }
289
+ async function buildViteImporterAssets(entry) {
290
+ const outFile = systemConfig.temp.viteImporter.outDir + "/assets.js";
291
+ const assetsPathArray = Object.values(entry);
292
+ const filteredAssetsPathArray = assetsPathArray.filter((path2) => path2.match(/\.(js|cjs|mjs|jsx|ts|tsx)$/));
293
+ const importArray = filteredAssetsPathArray.map((path2) => {
294
+ return `import("/${path2}")`;
295
+ });
296
+ const importArrayStr = importArray.join("\n ");
297
+ const template = `export const getAssets = () => {
298
+ ${importArrayStr}
299
+ }`;
300
+ await fs.outputFile(outFile, template).catch((err) => {
301
+ console.error(err);
302
+ });
303
+ }
304
+ async function buildViteImporterBlankAssets() {
305
+ const outFile = systemConfig.temp.viteImporter.outDir + "/assets.js";
306
+ const template = `export const getAssets = () => {
307
+ }`;
308
+ await fs.outputFile(outFile, template).catch((err) => {
225
309
  console.error(err);
226
310
  });
227
311
  }
312
+ async function buildCopyDir(targetDir, outDir, log) {
313
+ const checkTargetDir = await fs.pathExists(targetDir);
314
+ if (checkTargetDir) {
315
+ return await fs.copy(targetDir, outDir).then(() => {
316
+ if (log === "public") {
317
+ console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(targetDir + "/**/* -> " + outDir)}`);
318
+ }
319
+ if (log === "assets") {
320
+ console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outDir)}`);
321
+ }
322
+ }).catch((err) => {
323
+ console.error(err);
324
+ });
325
+ } else {
326
+ return;
327
+ }
328
+ }
228
329
  export {
229
330
  buildAssetsTagStr,
230
331
  buildCopyDir,
@@ -235,5 +336,9 @@ export {
235
336
  buildStaticPage,
236
337
  buildStaticPages,
237
338
  buildTempAssets,
238
- buildTempPages
339
+ buildTempPages,
340
+ buildViteImporterAssets,
341
+ buildViteImporterBlankAssets,
342
+ buildViteImporterRoots,
343
+ buildViteImporterRoutes
239
344
  };
@@ -0,0 +1,2 @@
1
+ import "/@minista-temp/vite-importer/roots.js";
2
+ import "/@minista-temp/vite-importer/routes.js";
package/dist/bundle.js ADDED
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import "/@minista-temp/vite-importer/roots.js";
3
+ import "/@minista-temp/vite-importer/routes.js";