minista 1.1.2 → 2.0.0-alpha.2

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 (50) hide show
  1. package/README.md +13 -270
  2. package/bin/minista.js +10 -0
  3. package/dist/app.d.ts +1 -0
  4. package/dist/app.js +7 -0
  5. package/dist/build.d.ts +30 -0
  6. package/dist/build.js +210 -0
  7. package/dist/clean.d.ts +3 -0
  8. package/dist/clean.js +25 -0
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +108 -0
  11. package/dist/config.d.ts +32 -0
  12. package/dist/config.js +24 -0
  13. package/dist/dummy.js +8 -0
  14. package/dist/empty.d.ts +1 -0
  15. package/dist/empty.js +10 -0
  16. package/dist/esbuild.d.ts +5 -0
  17. package/dist/esbuild.js +38 -0
  18. package/dist/head.d.ts +4 -0
  19. package/dist/head.js +37 -0
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.js +4 -0
  22. package/dist/link.d.ts +4 -0
  23. package/dist/link.js +46 -0
  24. package/dist/mdx.d.ts +3 -0
  25. package/dist/mdx.js +20 -0
  26. package/dist/optimize.d.ts +1 -0
  27. package/dist/optimize.js +20 -0
  28. package/dist/page.d.ts +10 -0
  29. package/dist/page.js +112 -0
  30. package/dist/pages.d.ts +1 -0
  31. package/dist/pages.js +45 -0
  32. package/dist/path.d.ts +3 -0
  33. package/dist/path.js +26 -0
  34. package/dist/render.d.ts +2 -0
  35. package/{main.js → dist/render.js} +13 -15
  36. package/dist/server.d.ts +2 -0
  37. package/dist/server.js +10 -0
  38. package/dist/types.d.ts +40 -0
  39. package/dist/types.js +1 -0
  40. package/dist/utils.d.ts +2 -0
  41. package/dist/utils.js +28 -0
  42. package/dist/vite.d.ts +52 -0
  43. package/dist/vite.js +71 -0
  44. package/lib/index.html +21 -0
  45. package/lib/shim-fetch.js +2 -0
  46. package/lib/shim-react.js +2 -0
  47. package/package.json +49 -35
  48. package/cli.js +0 -150
  49. package/index.d.ts +0 -4
  50. package/webpack.config.js +0 -279
package/README.md CHANGED
@@ -16,40 +16,16 @@
16
16
 
17
17
  minista(ミニスタ)は、React (TSX/JSX)で書けるスタティックサイトジェネレーターです。SaaS の web テンプレートコーディング業務を想定し、ビルド時の納品用データが綺麗(ヒューマンリーダブル)であることを重視しています。CSS と JavaScript は個別に出力されます。
18
18
 
19
- - ゼロコンフィグで始められる
20
- - React (TSX/JSX)から 100%静的な HTML を出力
21
- - CSS と JavaScript を個別に Minify 出力
22
- - SVG スプライトアイコンを自動生成
23
- - Next.js 風のディレクトリ構成
24
-
25
19
  ## How To Use
26
20
 
27
21
  ### Automatic
28
22
 
29
- コマンド `npm init minista` を入力するだけでいくつかのテンプレートから選び始められます。テンプレートは[オフィシャル](https://github.com/qrac/create-minista/tree/main/templates)以外にも任意の GitHub パブリックリポジトリに対応していますので、自分用のテンプレートを作っておくと効率的です。
30
-
31
- ```bash
32
- # Use interactive CLI
33
- npm init minista
34
-
35
- # Use Official Template
36
- npm init minista -- --template [OFFICIAL_TEMPLATE_NAME]
37
-
38
- # Use GitHub Template
39
- npm init minista -- --template [GITHUB_USER]/[REPO_NAME]
40
- npm init minista -- --template [GITHUB_USER]/[REPO_NAME]/path/to/example
41
- ```
42
-
43
- - `create-minista`: [repo](https://github.com/qrac/create-minista) / [npm](https://www.npmjs.com/package/create-minista)
23
+ not supported
44
24
 
45
25
  ### Manual
46
26
 
47
- 手動でセッティングする場合は `minista` `react` `react-dom` をインストールしてください。
48
-
49
- - `minista`: [npm](https://www.npmjs.com/package/minista)
50
-
51
27
  ```bash
52
- $ npm install --save-dev minista react react-dom
28
+ $ npm install --save-dev minista@next react react-dom
53
29
  ```
54
30
 
55
31
  ```bash
@@ -57,16 +33,12 @@ $ npm install --save-dev minista react react-dom
57
33
  # Directory Example
58
34
  # ----------------------------------------------------
59
35
 
60
- public # Copy root
36
+ public # Copy dist
61
37
  src
62
- ├── assets
63
- │ └── index.js # Required!
64
- ├── components
65
- │ └── layout.js
66
38
  └── pages # Required!
67
39
  ├── about
68
- │ └── index.js
69
- └── index.js
40
+ │ └── index.tsx
41
+ └── index.tsx
70
42
  ```
71
43
 
72
44
  <!-- prettier-ignore -->
@@ -75,23 +47,19 @@ src
75
47
  // Page Example
76
48
  //----------------------------------------------------
77
49
 
78
- import { render } from "minista" // Required!
79
-
80
50
  const PageHome = () => {
81
51
  return (
82
- <h1>Hello</h1>
52
+ <h1>Home</h1>
83
53
  )
84
54
  }
85
55
 
86
- export default render(<PageHome />) // Required!
56
+ export default PageHome
87
57
  ```
88
58
 
89
59
  ## Commands
90
60
 
91
61
  ### Develop
92
62
 
93
- `webpack-dev-server` でプレビューします。
94
-
95
63
  ```bash
96
64
  # Start
97
65
  $ minista
@@ -102,244 +70,17 @@ Press Ctrl+C
102
70
 
103
71
  ### Build
104
72
 
105
- 納品用にビルド。HTML には `js-beautify` 処理が施され見やすくなります。
106
-
107
73
  ```bash
108
74
  $ minista build
109
75
  ```
110
76
 
111
77
  ## Components
112
78
 
113
- ### Comment
114
-
115
- `<Comment text="" />` を使うと React では作りにくい HTML コメントが残せます。
116
-
117
- <!-- prettier-ignore -->
118
- ```js
119
- import { render, Comment } from "minista"
120
-
121
- const PageHome = () => {
122
- return (
123
- <>
124
- <Comment text="Comment Test" />
125
- <h1>Hello</h1>
126
- </>
127
- )
128
- }
129
-
130
- export default render(<PageHome />)
131
- ```
132
-
133
- ```html
134
- <body>
135
- <!-- Comment Test -->
136
- <h1>Hello</h1>
137
- </body>
138
- ```
139
-
140
- ### Sitemap
141
-
142
- 納品用のサイトマップを簡単に作るコンポーネントを npm で追加可能です。納品物に追加の CSS や JavaScript をバンドルさせません。
143
-
144
- - `minista-sitemap`: [repo](https://github.com/qrac/minista-sitemap) / [npm](https://www.npmjs.com/package/minista-sitemap)
79
+ undecided
145
80
 
146
81
  ## Customize
147
82
 
148
- ### webpack
149
-
150
- プロジェクトの root に `webpack.config.js` を配置することで設定をマージできます。
151
-
152
- ```js
153
- //----------------------------------------------------
154
- // Example: User > webpack.config.js
155
- //----------------------------------------------------
156
-
157
- // No installation required.
158
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
159
- const CopyPlugin = require("copy-webpack-plugin")
160
-
161
- // Example of dev mode
162
- const isDev = process.env.NODE_ENV !== "production"
163
-
164
- const webpackConfig = {
165
- // Merge
166
- devServer: {
167
- open: ["/index.html"],
168
- },
169
- // Replace
170
- entry: { custom: "./src/assets/index.js" },
171
- plugins: [
172
- // Replace
173
- new MiniCssExtractPlugin({
174
- filename: "assets/css/[name].css",
175
- }),
176
- // Replace
177
- new CopyPlugin({
178
- patterns: [{ from: "./static", to: "./", noErrorOnMissing: true }],
179
- }),
180
- ],
181
-
182
- // All optimization is replaced.
183
- optimization: {
184
- minimize: !isDev,
185
- minimizer: [
186
- /* Replace plugins */
187
- ],
188
- },
189
- }
190
-
191
- module.exports = webpackConfig
192
- ```
193
-
194
- ### TypeScript
195
-
196
- TypeScript `.tsx` でページを作成する場合はモジュールを追加し `tsconfig.json` をプロジェクトの root に配置。エントリーポイントとして `src/assets/index.ts` があれば `src/assets/index.js` の代わりに使用します。
197
-
198
- ```bash
199
- $ npm install --save-dev typescript @types/react @types/react-dom
200
- ```
201
-
202
- ```json
203
- {
204
- "compilerOptions": {
205
- "target": "esnext",
206
- "module": "esnext",
207
- "baseUrl": ".",
208
- "allowJs": true,
209
- "strict": true,
210
- "noImplicitAny": false,
211
- "strictNullChecks": true,
212
- "noUnusedLocals": true,
213
- "noUnusedParameters": true,
214
- "noImplicitReturns": true,
215
- "moduleResolution": "node",
216
- "esModuleInterop": true,
217
- "isolatedModules": false,
218
- "skipLibCheck": true,
219
- "forceConsistentCasingInFileNames": true,
220
- "resolveJsonModule": true,
221
- "jsx": "react-jsx"
222
- },
223
- "include": ["**/*.ts", "**/*.tsx"],
224
- "exclude": ["node_modules", "dist", "webpack.config.js"]
225
- }
226
- ```
227
-
228
- ```bash
229
- # ----------------------------------------------------
230
- # Directory Example
231
- # ----------------------------------------------------
232
-
233
- public # Copy root
234
- src
235
- ├── assets
236
- │ └── index.ts (or index.js) # Required!
237
- ├── components
238
- │ └── layout.js
239
- └── pages # Required!
240
- ├── about
241
- │ └── index.tsx
242
- └── index.tsx
243
- ```
244
-
245
- ### Babel
246
-
247
- Babel はプロジェクトの root に `.babelrc` もしくは `babel.config.js` を配置することで設定を上書きできます。カスタマイズしない場合は以下の設定が適応されます。
248
-
249
- ```js
250
- // JavaScript
251
- const babelJsxOptions = {
252
- presets: [
253
- "@babel/preset-env",
254
- [
255
- "@babel/preset-react",
256
- {
257
- runtime: "automatic",
258
- },
259
- ],
260
- ],
261
- }
262
-
263
- // TypeScript
264
- const babelTsxOptions = {
265
- presets: [
266
- "@babel/preset-env",
267
- [
268
- "@babel/preset-react",
269
- {
270
- runtime: "automatic",
271
- },
272
- ],
273
- ["@babel/preset-typescript"],
274
- ],
275
- }
276
- ```
277
-
278
- ### PostCSS
279
-
280
- PostCSS はゼロコンフィグで以下のプラグインが適応されますが、プロジェクトの root に `postcss.config.js` を配置することで設定を上書きできます。
281
-
282
- ```js
283
- module.exports = {
284
- plugins: [
285
- "postcss-import",
286
- "postcss-flexbugs-fixes",
287
- "postcss-sort-media-queries",
288
- "postcss-preset-env",
289
- ],
290
- }
291
- ```
292
-
293
- ### Sass / SCSS
294
-
295
- `sass-loader` と `sass`(または `node-sass`)を追加することで使えます。
296
-
297
- ```bash
298
- $ npm install --save-dev sass-loader sass
299
- ```
300
-
301
- ### Style only
302
-
303
- プロジェクトに JavaScript が全く必要ない場合はエントリーポイントを CSS ファイルに変更します。これにより空の JavaScript ファイルを出力することなく納品用データを生成できます。
304
-
305
- ```js
306
- //----------------------------------------------------
307
- // Example: User > webpack.config.js
308
- //----------------------------------------------------
309
-
310
- const webpackConfig = {
311
- entry: { bundle: "./src/assets/index.css" },
312
- }
313
-
314
- module.exports = webpackConfig
315
- ```
316
-
317
- ### SVG sprite icons
318
-
319
- `src/assets/icons` ディレクトリに SVG ファイルを置くと SVG スプライトアイコンの `dist/assets/icons.svg` が生成されます。以下のようなコンポーネントを作ることでアイコンを呼び出せます。
320
-
321
- ```js
322
- // Example: ./src/components/svg-sprite-icon.tsx
323
- export interface SvgSpriteIconProps {
324
- iconId?: string;
325
- }
326
-
327
- export const SvgSpriteIcon = (props: SvgSpriteIconProps) => {
328
- const { iconId } = props
329
- return (
330
- <svg className="icon" role="img">
331
- <use xlinkHref={`/assets/icons.svg#${iconId}`} />
332
- </svg>
333
- )
334
- }
335
- ```
336
-
337
- ```html
338
- <!-- dist html -->
339
- <svg role="img" class="icon">
340
- <use xlink:href="/assets/icons.svg#star"></use>
341
- </svg>
342
- ```
83
+ not supported
343
84
 
344
85
  ## Media
345
86
 
@@ -349,11 +90,13 @@ export const SvgSpriteIcon = (props: SvgSpriteIconProps) => {
349
90
  ## Respect
350
91
 
351
92
  - [Next.js by Vercel - The React Framework](https://nextjs.org/)
93
+ - [Remix - Build Better Websites](https://remix.run/)
94
+ - [Vite](https://vitejs.dev/)
95
+ - [esbuild - An extremely fast JavaScript bundler](https://esbuild.github.io/)
96
+ - [Astro](https://astro.build/)
352
97
  - [Charge — an opinionated, zero-config static site generator](https://charge.js.org/)
353
98
  - [Eleventy, a simpler static site generator.](https://www.11ty.dev/)
354
- - [Node Interface | webpack](https://webpack.js.org/api/node/)
355
99
  - [natemoo-re/microsite](https://github.com/natemoo-re/microsite)
356
- - [Astro](https://astro.build/)
357
100
  - [テンプレートエンジンに React を使いつつ、きれいな HTML を生成したいんじゃ!!](https://zenn.dev/otsukayuhi/articles/e52651b4e2c5ae7c4a17)
358
101
  - [EJS をやめて React で HTML を書く](https://zenn.dev/hisho/scraps/4ef6c6106a6395)
359
102
  - [MPA(マルチページアプリ)で webpack を使う](https://www.key-p.com/blog/staff/archives/107125)
package/bin/minista.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ "use strict"
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
+ }
package/dist/app.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/app.js ADDED
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+ import { Pages } from "./pages.js";
4
+ ReactDOM.render(/* @__PURE__ */ React.createElement(Pages, null), document.getElementById("root"));
5
+ if (import.meta.hot) {
6
+ import.meta.hot.accept();
7
+ }
@@ -0,0 +1,30 @@
1
+ import type { Options as MdxOptions } from "@mdx-js/esbuild";
2
+ import type { InlineConfig } from "vite";
3
+ import type { RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData } from "./types.js";
4
+ export declare function buildTempPages(entryPoints: string[], buildOptions: {
5
+ outbase: string;
6
+ outdir: string;
7
+ mdxConfig: MdxOptions;
8
+ }): Promise<void>;
9
+ export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
10
+ outbase: string;
11
+ outdir: string;
12
+ }, assetsTagStr?: string): Promise<void>;
13
+ export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
14
+ component: RootJsxContent;
15
+ staticData: GlobalStaticData;
16
+ }>;
17
+ export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
18
+ export declare function buildStaticPage(entryPoint: string, outFile: string, rootStaticContent: RootStaticContent, assetsTagStr?: string): Promise<void>;
19
+ export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
20
+ export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr?: string): Promise<void>;
21
+ export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
22
+ fileName: string;
23
+ outdir: string;
24
+ assetDir: string;
25
+ }): Promise<void>;
26
+ export declare function buildAssetsTagStr(entryPoints: string[], buildOptions: {
27
+ outbase: string;
28
+ outdir: string;
29
+ }): Promise<string>;
30
+ export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
package/dist/build.js ADDED
@@ -0,0 +1,210 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import React from "react";
18
+ import fs from "fs-extra";
19
+ import path from "path";
20
+ import url from "url";
21
+ import pc from "picocolors";
22
+ import { Fragment } from "react";
23
+ import { build as esBuild } from "esbuild";
24
+ import mdx from "@mdx-js/esbuild";
25
+ import { build as viteBuild, mergeConfig } from "vite";
26
+ import { resolvePlugin } from "./esbuild.js";
27
+ import { renderHtml } from "./render.js";
28
+ const __filename = url.fileURLToPath(import.meta.url);
29
+ const __dirname = path.dirname(__filename);
30
+ async function buildTempPages(entryPoints, buildOptions) {
31
+ const ministaPkgURL = new URL(path.resolve(__dirname + "/../package.json"), import.meta.url);
32
+ const ministaPkg = JSON.parse(fs.readFileSync(ministaPkgURL, "utf8"));
33
+ const userPkgURL = new URL(path.resolve("package.json"), import.meta.url);
34
+ const userPkg = JSON.parse(fs.readFileSync(userPkgURL, "utf8"));
35
+ const esbuildExternal = [
36
+ ...Object.keys(ministaPkg.dependencies || {}),
37
+ ...Object.keys(ministaPkg.devDependencies || {}),
38
+ ...Object.keys(ministaPkg.peerDependencies || {}),
39
+ ...Object.keys(userPkg.dependencies || {}),
40
+ ...Object.keys(userPkg.devDependencies || {}),
41
+ ...Object.keys(userPkg.peerDependencies || {}),
42
+ "*.css",
43
+ "*.scss",
44
+ "*.sass"
45
+ ];
46
+ await esBuild({
47
+ entryPoints,
48
+ outbase: buildOptions.outbase,
49
+ outdir: buildOptions.outdir,
50
+ outExtension: { ".js": ".mjs" },
51
+ bundle: true,
52
+ format: "esm",
53
+ platform: "node",
54
+ inject: [
55
+ path.resolve(__dirname + "/../lib/shim-react.js"),
56
+ path.resolve(__dirname + "/../lib/shim-fetch.js")
57
+ ],
58
+ external: esbuildExternal,
59
+ plugins: [
60
+ mdx(buildOptions.mdxConfig),
61
+ resolvePlugin({
62
+ "react/jsx-runtime": "react/jsx-runtime.js"
63
+ })
64
+ ]
65
+ }).catch(() => process.exit(1));
66
+ }
67
+ async function buildStaticPages(entryPoints, tempRootFilePath, buildOptions, assetsTagStr) {
68
+ const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
69
+ await Promise.all(entryPoints.map(async (entryPoint) => {
70
+ const extname = path.extname(entryPoint);
71
+ const basename = path.basename(entryPoint, extname);
72
+ const dirname = path.dirname(entryPoint).replace(buildOptions.outbase, buildOptions.outdir);
73
+ const filename = path.join(dirname, basename + ".html");
74
+ await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr);
75
+ }));
76
+ }
77
+ async function buildRootEsmContent(tempRootFilePath) {
78
+ const defaultRootEsmContent = {
79
+ component: Fragment,
80
+ staticData: { props: {} }
81
+ };
82
+ if (!tempRootFilePath) {
83
+ return defaultRootEsmContent;
84
+ } else {
85
+ const rootEsmContent = await import(tempRootFilePath);
86
+ const rootJsxContent = rootEsmContent.default ? rootEsmContent.default : Fragment;
87
+ const staticData = rootEsmContent.getStaticData ? await buildGlobalStaticData(rootEsmContent.getStaticData) : { props: {} };
88
+ return { component: rootJsxContent, staticData };
89
+ }
90
+ }
91
+ async function buildGlobalStaticData(getGlobalStaticData) {
92
+ const response = await getGlobalStaticData();
93
+ return response;
94
+ }
95
+ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr) {
96
+ const pageEsmContent = await import(path.resolve(entryPoint));
97
+ const pageJsxContent = pageEsmContent.default;
98
+ const defaultStaticDataItem = { props: {}, paths: {} };
99
+ const staticData = pageEsmContent.getStaticData ? await buildStaticData(pageEsmContent.getStaticData) : void 0;
100
+ if (!staticData) {
101
+ const staticDataItem = defaultStaticDataItem;
102
+ return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr);
103
+ }
104
+ if ("props" in staticData && "paths" in staticData === false) {
105
+ const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
106
+ return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr);
107
+ }
108
+ if ("paths" in staticData) {
109
+ const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
110
+ let fixedOutfile = outFile;
111
+ for await (const [key, value] of Object.entries(staticDataItem.paths)) {
112
+ const reg = new RegExp("\\[" + key + "\\]", "g");
113
+ fixedOutfile = fixedOutfile.replace(reg, `${value}`);
114
+ }
115
+ return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr);
116
+ }
117
+ if (Array.isArray(staticData) && staticData.length > 0) {
118
+ const entryPoints = staticData;
119
+ await Promise.all(entryPoints.map(async (entryPoint2) => {
120
+ const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), entryPoint2);
121
+ let fixedOutfile = outFile;
122
+ for await (const [key, value] of Object.entries(staticDataItem.paths)) {
123
+ const reg = new RegExp("\\[" + key + "\\]", "g");
124
+ fixedOutfile = fixedOutfile.replace(reg, `${value}`);
125
+ }
126
+ return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr);
127
+ }));
128
+ }
129
+ }
130
+ async function buildStaticData(getStaticData) {
131
+ const response = await getStaticData();
132
+ return response;
133
+ }
134
+ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr) {
135
+ const RootComponent = rootStaticContent.component;
136
+ const globalStaticData = rootStaticContent.staticData;
137
+ const PageComponent = pageJsxContent;
138
+ const staticProps = staticDataItem.props;
139
+ const html = await renderHtml(/* @__PURE__ */ React.createElement(RootComponent, __spreadValues(__spreadValues({}, globalStaticData == null ? void 0 : globalStaticData.props), staticProps), /* @__PURE__ */ React.createElement(PageComponent, __spreadValues(__spreadValues({}, globalStaticData == null ? void 0 : globalStaticData.props), staticProps))), assetsTagStr);
140
+ await fs.outputFile(routePath, html).then(() => {
141
+ console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
142
+ }).catch((err) => {
143
+ console.error(err);
144
+ });
145
+ }
146
+ async function buildTempAssets(viteConfig, buildOptions) {
147
+ const customConfig = {
148
+ build: {
149
+ write: false,
150
+ rollupOptions: {
151
+ input: {
152
+ __minista_auto_bundle_asset_pages: path.resolve(__dirname + "/../dist/pages.js")
153
+ }
154
+ }
155
+ }
156
+ };
157
+ const mergedConfig = mergeConfig(viteConfig, customConfig);
158
+ const result = await viteBuild(mergedConfig);
159
+ const items = result.output;
160
+ if (Array.isArray(items) && items.length > 0) {
161
+ items.map((item) => {
162
+ if (item.fileName.match(/__minista_auto_bundle_asset_pages\.css/)) {
163
+ const customFileName = `${buildOptions.outdir}/${buildOptions.fileName}.css`;
164
+ return (item == null ? void 0 : item.source) && fs.outputFile(customFileName, item == null ? void 0 : item.source);
165
+ } else if (item.fileName.match(/__minista_auto_bundle_asset_pages\.js/)) {
166
+ return;
167
+ } else {
168
+ const customFileName = buildOptions.outdir + item.fileName.replace(buildOptions.assetDir, "");
169
+ 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 : "";
170
+ return customCode && fs.outputFile(customFileName, customCode);
171
+ }
172
+ });
173
+ }
174
+ }
175
+ async function buildAssetsTagStr(entryPoints, buildOptions) {
176
+ const assetsTags = entryPoints.map((entryPoint) => {
177
+ const assetPath = entryPoint.replace(buildOptions.outbase, buildOptions.outdir);
178
+ if (assetPath.endsWith(".css")) {
179
+ return `<link rel="stylesheet" href="/${assetPath}">`;
180
+ } else if (assetPath.endsWith(".js")) {
181
+ return `<script defer src="/${assetPath}"><\/script>`;
182
+ }
183
+ });
184
+ const assetsTagStr = assetsTags.join("");
185
+ return assetsTagStr;
186
+ }
187
+ async function buildCopyDir(targetDir, outDir, log) {
188
+ return fs.copy(targetDir, outDir).then(() => {
189
+ if (log === "public") {
190
+ console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(targetDir + "/**/* -> " + outDir)}`);
191
+ }
192
+ if (log === "assets") {
193
+ console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outDir)}`);
194
+ }
195
+ }).catch((err) => {
196
+ console.error(err);
197
+ });
198
+ }
199
+ export {
200
+ buildAssetsTagStr,
201
+ buildCopyDir,
202
+ buildGlobalStaticData,
203
+ buildHtmlPage,
204
+ buildRootEsmContent,
205
+ buildStaticData,
206
+ buildStaticPage,
207
+ buildStaticPages,
208
+ buildTempAssets,
209
+ buildTempPages
210
+ };
@@ -0,0 +1,3 @@
1
+ import type { HTMLBeautifyOptions } from "js-beautify";
2
+ export declare function cleanHtmlPages(entryPoints: string[], options?: HTMLBeautifyOptions): Promise<void>;
3
+ export declare function cleanHtmlPage(entryPoint: string, options?: HTMLBeautifyOptions): Promise<void>;
package/dist/clean.js ADDED
@@ -0,0 +1,25 @@
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 cleanHtmlPages(entryPoints, options = {
6
+ indent_size: 2,
7
+ max_preserve_newlines: 0
8
+ }) {
9
+ await Promise.all(entryPoints.map(async (entryPoint) => {
10
+ await cleanHtmlPage(entryPoint, options);
11
+ }));
12
+ }
13
+ async function cleanHtmlPage(entryPoint, options) {
14
+ const html = await fs.readFile(entryPoint, "utf8");
15
+ const result = beautify.html(html, options);
16
+ await fs.outputFile(entryPoint, result).then(() => {
17
+ console.log(`${pc.bold(pc.blue("CLEAN"))} ${pc.bold(entryPoint)}`);
18
+ }).catch((err) => {
19
+ console.error(err);
20
+ });
21
+ }
22
+ export {
23
+ cleanHtmlPage,
24
+ cleanHtmlPages
25
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};