minista 2.0.0-alpha.13 → 2.0.0-alpha.16
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 +2 -2
- package/dist/build.d.ts +6 -1
- package/dist/build.js +76 -1
- package/dist/cli.js +18 -62
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -2
- package/dist/define.d.ts +1 -1
- package/dist/define.js +2 -2
- package/dist/empty.js +1 -1
- package/dist/generate.d.ts +11 -0
- package/dist/generate.js +86 -0
- package/dist/pages.js +27 -17
- package/dist/types.d.ts +17 -0
- package/dist/vite.js +6 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -72,9 +72,9 @@ Open `package.json` and add the following scripts:
|
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
74
|
// minista.config.ts
|
|
75
|
-
import {
|
|
75
|
+
import { defineConfig } from "minista"
|
|
76
76
|
|
|
77
|
-
export default
|
|
77
|
+
export default defineConfig({
|
|
78
78
|
entry: undefined, // string | string[] | { [key: string]: string }
|
|
79
79
|
outDir: "dist", // string
|
|
80
80
|
publicDir: "public", // string
|
package/dist/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 { MinistaConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData } from "./types.js";
|
|
4
4
|
export declare function buildTempPages(entryPoints: string[], buildOptions: {
|
|
5
5
|
outbase: string;
|
|
6
6
|
outdir: string;
|
|
@@ -27,4 +27,9 @@ export declare function buildAssetsTagStr(entryPoints: string[], buildOptions: {
|
|
|
27
27
|
outbase: string;
|
|
28
28
|
outdir: string;
|
|
29
29
|
}): Promise<string>;
|
|
30
|
+
export declare function buildViteImporterRoots(config: MinistaConfig): Promise<void>;
|
|
31
|
+
export declare function buildViteImporterRoutes(config: MinistaConfig): Promise<void>;
|
|
32
|
+
export declare function buildViteImporterAssets(config: MinistaConfig, entry: {
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
}): Promise<void>;
|
|
30
35
|
export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
|
package/dist/build.js
CHANGED
|
@@ -213,6 +213,78 @@ async function buildAssetsTagStr(entryPoints, buildOptions) {
|
|
|
213
213
|
const assetsTagStr = assetsTags.join("");
|
|
214
214
|
return assetsTagStr;
|
|
215
215
|
}
|
|
216
|
+
async function buildViteImporterRoots(config) {
|
|
217
|
+
const outFile = config.tempViteImporterDir + "/roots.js";
|
|
218
|
+
const rootFileDir = config.rootFileDir;
|
|
219
|
+
const rootFileName = config.rootFileName;
|
|
220
|
+
const rootFileExtStr = config.rootFileExt.join();
|
|
221
|
+
const template = `export const getRoots = () => {
|
|
222
|
+
const ROOTS = import.meta.globEager("/${rootFileDir}/${rootFileName}.{${rootFileExtStr}}")
|
|
223
|
+
const roots =
|
|
224
|
+
Object.keys(ROOTS).length === 0
|
|
225
|
+
? [{ RootComponent: Fragment, getGlobalStaticData: undefined }]
|
|
226
|
+
: Object.keys(ROOTS).map((root) => {
|
|
227
|
+
return {
|
|
228
|
+
RootComponent: ROOTS[root].default ? ROOTS[root].default : Fragment,
|
|
229
|
+
getGlobalStaticData: ROOTS[root].getStaticData
|
|
230
|
+
? ROOTS[root].getStaticData
|
|
231
|
+
: undefined,
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
return roots
|
|
235
|
+
}`;
|
|
236
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
237
|
+
console.error(err);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async function buildViteImporterRoutes(config) {
|
|
241
|
+
const outFile = config.tempViteImporterDir + "/routes.js";
|
|
242
|
+
const pagesDir = config.pagesDir;
|
|
243
|
+
const pagesExtStr = config.pagesExt.join();
|
|
244
|
+
const pagesDirRegStr = config.pagesDir.replace(/\//g, "\\/");
|
|
245
|
+
const replaceArray = config.pagesExt.map((ext) => {
|
|
246
|
+
return `.replace(/\\/${pagesDirRegStr}|index|\\.${ext}$/g, "")`;
|
|
247
|
+
});
|
|
248
|
+
const replaceArrayStr = replaceArray.join("\n ");
|
|
249
|
+
const template = `export const getRoutes = () => {
|
|
250
|
+
const ROUTES = import.meta.globEager("/${pagesDir}/**/[a-z[]*.{${pagesExtStr}}")
|
|
251
|
+
const routes = Object.keys(ROUTES).map((route) => {
|
|
252
|
+
const routePath = route
|
|
253
|
+
${replaceArrayStr}
|
|
254
|
+
.replace(/\\[\\.{3}.+\\]/, "*")
|
|
255
|
+
.replace(/\\[(.+)\\]/, ":$1")
|
|
256
|
+
return {
|
|
257
|
+
routePath: routePath,
|
|
258
|
+
PageComponent: ROUTES[route].default,
|
|
259
|
+
getStaticData: ROUTES[route].getStaticData
|
|
260
|
+
? ROUTES[route].getStaticData
|
|
261
|
+
: undefined,
|
|
262
|
+
frontmatter: ROUTES[route].frontmatter
|
|
263
|
+
? ROUTES[route].frontmatter
|
|
264
|
+
: undefined,
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
return routes
|
|
268
|
+
}`;
|
|
269
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
270
|
+
console.error(err);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async function buildViteImporterAssets(config, entry) {
|
|
274
|
+
const outFile = config.tempViteImporterDir + "/assets.js";
|
|
275
|
+
const assetsPathArray = Object.values(entry);
|
|
276
|
+
const filteredAssetsPathArray = assetsPathArray.filter((path2) => path2.match(/\.(js|cjs|mjs|jsx|ts|tsx)$/));
|
|
277
|
+
const importArray = filteredAssetsPathArray.map((path2) => {
|
|
278
|
+
return `import("/${path2}")`;
|
|
279
|
+
});
|
|
280
|
+
const importArrayStr = importArray.join("\n ");
|
|
281
|
+
const template = `export const getAssets = () => {
|
|
282
|
+
${importArrayStr}
|
|
283
|
+
}`;
|
|
284
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
285
|
+
console.error(err);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
216
288
|
async function buildCopyDir(targetDir, outDir, log) {
|
|
217
289
|
const checkTargetDir = await fs.pathExists(targetDir);
|
|
218
290
|
if (checkTargetDir) {
|
|
@@ -240,5 +312,8 @@ export {
|
|
|
240
312
|
buildStaticPage,
|
|
241
313
|
buildStaticPages,
|
|
242
314
|
buildTempAssets,
|
|
243
|
-
buildTempPages
|
|
315
|
+
buildTempPages,
|
|
316
|
+
buildViteImporterAssets,
|
|
317
|
+
buildViteImporterRoots,
|
|
318
|
+
buildViteImporterRoutes
|
|
244
319
|
};
|
package/dist/cli.js
CHANGED
|
@@ -5,18 +5,18 @@ import { getUserConfig } from "./user.js";
|
|
|
5
5
|
import { getConfig } from "./config.js";
|
|
6
6
|
import { getViteConfig } from "./vite.js";
|
|
7
7
|
import { getMdxConfig } from "./mdx.js";
|
|
8
|
-
import { getFilePath, getFilePaths, getSameFilePaths } from "./path.js";
|
|
9
8
|
import { emptyResolveDir } from "./empty.js";
|
|
10
|
-
import { cleanHtmlPages } from "./clean.js";
|
|
11
|
-
import { optimizeCommentOutStyleImport } from "./optimize.js";
|
|
12
9
|
import { createDevServer } from "./server.js";
|
|
13
10
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
generateViteImporters,
|
|
12
|
+
generateTempRoot,
|
|
13
|
+
generateTempPages,
|
|
14
|
+
generateAssets,
|
|
15
|
+
generateNoStyleTemp,
|
|
16
|
+
generateHtmlPages,
|
|
17
|
+
generatePublic,
|
|
18
|
+
generateCleanHtml
|
|
19
|
+
} from "./generate.js";
|
|
20
20
|
import { previewLocal } from "./preview.js";
|
|
21
21
|
function printVersion() {
|
|
22
22
|
const pkgURL = new URL("../package.json", import.meta.url);
|
|
@@ -28,8 +28,11 @@ const cli = cac("minista");
|
|
|
28
28
|
cli.command("[root]").alias("dev").action(async () => {
|
|
29
29
|
try {
|
|
30
30
|
const userConfig = await getUserConfig();
|
|
31
|
+
const config = await getConfig(userConfig);
|
|
31
32
|
const mdxConfig = await getMdxConfig(userConfig);
|
|
32
33
|
const viteConfig = await getViteConfig(userConfig, mdxConfig);
|
|
34
|
+
await Promise.all([emptyResolveDir(config.tempViteImporterDir)]);
|
|
35
|
+
await generateViteImporters(config, userConfig);
|
|
33
36
|
await createDevServer(viteConfig);
|
|
34
37
|
} catch (err) {
|
|
35
38
|
console.log(err);
|
|
@@ -42,51 +45,6 @@ cli.command("build [root]").action(async () => {
|
|
|
42
45
|
const config = await getConfig(userConfig);
|
|
43
46
|
const mdxConfig = await getMdxConfig(userConfig);
|
|
44
47
|
const viteConfig = await getViteConfig(userConfig, mdxConfig);
|
|
45
|
-
const generateTempRoot = async () => {
|
|
46
|
-
const srcRootFilePaths = await getSameFilePaths(config.rootFileDir, config.rootFileName, config.rootFileExt);
|
|
47
|
-
if (srcRootFilePaths.length > 0) {
|
|
48
|
-
await buildTempPages([srcRootFilePaths[0]], {
|
|
49
|
-
outbase: config.rootFileDir,
|
|
50
|
-
outdir: config.tempRootFileDir,
|
|
51
|
-
mdxConfig
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const generateTempPages = async () => {
|
|
56
|
-
const srcPageFilePaths = await getFilePaths(config.pagesDir, config.pagesExt);
|
|
57
|
-
await buildTempPages(srcPageFilePaths, {
|
|
58
|
-
outbase: config.pagesDir,
|
|
59
|
-
outdir: config.tempPagesDir,
|
|
60
|
-
mdxConfig
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
const generateAssets = async () => {
|
|
64
|
-
await buildTempAssets(viteConfig, {
|
|
65
|
-
fileName: config.autoAssetsName,
|
|
66
|
-
outdir: config.tempAssetsDir,
|
|
67
|
-
assetDir: config.assetsDir
|
|
68
|
-
});
|
|
69
|
-
await buildCopyDir(config.tempAssetsDir, `${config.outDir}/${config.assetsDir}`, "assets");
|
|
70
|
-
};
|
|
71
|
-
const generateHtmlPages = async () => {
|
|
72
|
-
const tempPageFilePaths = await getFilePaths(config.tempPagesDir, "mjs");
|
|
73
|
-
const tempRootFilePath = getFilePath(config.tempRootFileDir, config.rootFileName, "mjs");
|
|
74
|
-
const tempAssetsFilePaths = await getFilePaths(config.tempAssetsDir, [
|
|
75
|
-
"css",
|
|
76
|
-
"js"
|
|
77
|
-
]);
|
|
78
|
-
const assetsTagStr = await buildAssetsTagStr(tempAssetsFilePaths, {
|
|
79
|
-
outbase: config.tempAssetsDir,
|
|
80
|
-
outdir: config.assetsDir
|
|
81
|
-
});
|
|
82
|
-
await buildStaticPages(tempPageFilePaths, tempRootFilePath, {
|
|
83
|
-
outbase: config.tempPagesDir,
|
|
84
|
-
outdir: config.outDir
|
|
85
|
-
}, assetsTagStr);
|
|
86
|
-
};
|
|
87
|
-
const generatePublic = async () => {
|
|
88
|
-
await buildCopyDir(config.publicDir, config.outDir, "public");
|
|
89
|
-
};
|
|
90
48
|
await Promise.all([
|
|
91
49
|
emptyResolveDir(config.tempRootFileDir),
|
|
92
50
|
emptyResolveDir(config.tempAssetsDir),
|
|
@@ -94,15 +52,13 @@ cli.command("build [root]").action(async () => {
|
|
|
94
52
|
emptyResolveDir(config.outDir)
|
|
95
53
|
]);
|
|
96
54
|
await Promise.all([
|
|
97
|
-
generateTempRoot(),
|
|
98
|
-
generateTempPages(),
|
|
99
|
-
generateAssets()
|
|
55
|
+
generateTempRoot(config, mdxConfig),
|
|
56
|
+
generateTempPages(config, mdxConfig),
|
|
57
|
+
generateAssets(config, viteConfig)
|
|
100
58
|
]);
|
|
101
|
-
|
|
102
|
-
await
|
|
103
|
-
await Promise.all([
|
|
104
|
-
const htmlPageFilePaths = await getFilePaths(config.outDir, "html");
|
|
105
|
-
await cleanHtmlPages(htmlPageFilePaths);
|
|
59
|
+
await Promise.all([generateNoStyleTemp(config)]);
|
|
60
|
+
await Promise.all([generateHtmlPages(config), generatePublic(config)]);
|
|
61
|
+
await Promise.all([generateCleanHtml(config)]);
|
|
106
62
|
} catch (err) {
|
|
107
63
|
console.log(err);
|
|
108
64
|
process.exit(1);
|
package/dist/config.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const defaultConfig: {
|
|
|
11
11
|
pagesExt: string[];
|
|
12
12
|
tempDir: string;
|
|
13
13
|
tempConfigDir: string;
|
|
14
|
+
tempViteImporterDir: string;
|
|
14
15
|
tempAssetsDir: string;
|
|
15
16
|
tempRootFileDir: string;
|
|
16
17
|
tempPagesDir: string;
|
|
@@ -27,6 +28,7 @@ export declare function getConfig(userConfig: MinistaUserConfig): Promise<{
|
|
|
27
28
|
pagesExt: string[];
|
|
28
29
|
tempDir: string;
|
|
29
30
|
tempConfigDir: string;
|
|
31
|
+
tempViteImporterDir: string;
|
|
30
32
|
tempAssetsDir: string;
|
|
31
33
|
tempRootFileDir: string;
|
|
32
34
|
tempPagesDir: string;
|
package/dist/config.js
CHANGED
|
@@ -25,11 +25,12 @@ const defaultConfig = {
|
|
|
25
25
|
autoAssetsName: "bundle",
|
|
26
26
|
rootFileDir: "src",
|
|
27
27
|
rootFileName: "root",
|
|
28
|
-
rootFileExt: ["
|
|
28
|
+
rootFileExt: ["jsx", "tsx"],
|
|
29
29
|
pagesDir: "src/pages",
|
|
30
|
-
pagesExt: ["
|
|
30
|
+
pagesExt: ["jsx", "tsx", "md", "mdx"],
|
|
31
31
|
tempDir: "node_modules/.minista",
|
|
32
32
|
tempConfigDir: "node_modules/.minista/optimized-config",
|
|
33
|
+
tempViteImporterDir: "node_modules/.minista/vite-importer",
|
|
33
34
|
tempAssetsDir: "node_modules/.minista/bundled-react-assets",
|
|
34
35
|
tempRootFileDir: "node_modules/.minista/bundled-react-root",
|
|
35
36
|
tempPagesDir: "node_modules/.minista/bundled-react-pages"
|
package/dist/define.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MinistaUserConfig } from "./types.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function defineConfig(config: MinistaUserConfig): MinistaUserConfig;
|
package/dist/define.js
CHANGED
package/dist/empty.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Options as MdxOptions } from "@mdx-js/esbuild";
|
|
2
|
+
import type { InlineConfig } from "vite";
|
|
3
|
+
import { MinistaConfig, MinistaUserConfig } from "./types.js";
|
|
4
|
+
export declare function generateViteImporters(config: MinistaConfig, userConfig: MinistaUserConfig): Promise<void>;
|
|
5
|
+
export declare function generateTempRoot(config: MinistaConfig, mdxConfig: MdxOptions): Promise<void>;
|
|
6
|
+
export declare function generateTempPages(config: MinistaConfig, mdxConfig: MdxOptions): Promise<void>;
|
|
7
|
+
export declare function generateAssets(config: MinistaConfig, viteConfig: InlineConfig): Promise<void>;
|
|
8
|
+
export declare function generateNoStyleTemp(config: MinistaConfig): Promise<void>;
|
|
9
|
+
export declare function generateHtmlPages(config: MinistaConfig): Promise<void>;
|
|
10
|
+
export declare function generatePublic(config: MinistaConfig): Promise<void>;
|
|
11
|
+
export declare function generateCleanHtml(config: MinistaConfig): Promise<void>;
|
package/dist/generate.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { getFilePath, getFilePaths, getSameFilePaths } from "./path.js";
|
|
3
|
+
import {
|
|
4
|
+
buildTempPages,
|
|
5
|
+
buildStaticPages,
|
|
6
|
+
buildCopyDir,
|
|
7
|
+
buildTempAssets,
|
|
8
|
+
buildAssetsTagStr,
|
|
9
|
+
buildViteImporterRoots,
|
|
10
|
+
buildViteImporterRoutes,
|
|
11
|
+
buildViteImporterAssets
|
|
12
|
+
} from "./build.js";
|
|
13
|
+
import { optimizeCommentOutStyleImport } from "./optimize.js";
|
|
14
|
+
import { cleanHtmlPages } from "./clean.js";
|
|
15
|
+
async function generateViteImporters(config, userConfig) {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
const viteEntry = typeof userConfig.vite === "object" ? ((_c = (_b = (_a = userConfig.vite) == null ? void 0 : _a.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input) ? (_f = (_e = (_d = userConfig.vite) == null ? void 0 : _d.build) == null ? void 0 : _e.rollupOptions) == null ? void 0 : _f.input : {} : {};
|
|
18
|
+
await Promise.all([
|
|
19
|
+
buildViteImporterRoots(config),
|
|
20
|
+
buildViteImporterRoutes(config),
|
|
21
|
+
typeof viteEntry === "object" && !Array.isArray(viteEntry) && buildViteImporterAssets(config, viteEntry)
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
async function generateTempRoot(config, mdxConfig) {
|
|
25
|
+
const srcRootFilePaths = await getSameFilePaths(config.rootFileDir, config.rootFileName, config.rootFileExt);
|
|
26
|
+
if (srcRootFilePaths.length > 0) {
|
|
27
|
+
await buildTempPages([srcRootFilePaths[0]], {
|
|
28
|
+
outbase: config.rootFileDir,
|
|
29
|
+
outdir: config.tempRootFileDir,
|
|
30
|
+
mdxConfig
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function generateTempPages(config, mdxConfig) {
|
|
35
|
+
const srcPageFilePaths = await getFilePaths(config.pagesDir, config.pagesExt);
|
|
36
|
+
await buildTempPages(srcPageFilePaths, {
|
|
37
|
+
outbase: config.pagesDir,
|
|
38
|
+
outdir: config.tempPagesDir,
|
|
39
|
+
mdxConfig
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function generateAssets(config, viteConfig) {
|
|
43
|
+
await buildTempAssets(viteConfig, {
|
|
44
|
+
fileName: config.autoAssetsName,
|
|
45
|
+
outdir: config.tempAssetsDir,
|
|
46
|
+
assetDir: config.assetsDir
|
|
47
|
+
});
|
|
48
|
+
await buildCopyDir(config.tempAssetsDir, `${config.outDir}/${config.assetsDir}`, "assets");
|
|
49
|
+
}
|
|
50
|
+
async function generateNoStyleTemp(config) {
|
|
51
|
+
const tempMjsFiles = await getFilePaths(config.tempDir, "mjs");
|
|
52
|
+
await optimizeCommentOutStyleImport(tempMjsFiles);
|
|
53
|
+
}
|
|
54
|
+
async function generateHtmlPages(config) {
|
|
55
|
+
const tempPageFilePaths = await getFilePaths(config.tempPagesDir, "mjs");
|
|
56
|
+
const tempRootFilePath = getFilePath(config.tempRootFileDir, config.rootFileName, "mjs");
|
|
57
|
+
const tempAssetsFilePaths = await getFilePaths(config.tempAssetsDir, [
|
|
58
|
+
"css",
|
|
59
|
+
"js"
|
|
60
|
+
]);
|
|
61
|
+
const assetsTagStr = await buildAssetsTagStr(tempAssetsFilePaths, {
|
|
62
|
+
outbase: config.tempAssetsDir,
|
|
63
|
+
outdir: config.assetsDir
|
|
64
|
+
});
|
|
65
|
+
await buildStaticPages(tempPageFilePaths, tempRootFilePath, {
|
|
66
|
+
outbase: config.tempPagesDir,
|
|
67
|
+
outdir: config.outDir
|
|
68
|
+
}, assetsTagStr);
|
|
69
|
+
}
|
|
70
|
+
async function generatePublic(config) {
|
|
71
|
+
await buildCopyDir(config.publicDir, config.outDir, "public");
|
|
72
|
+
}
|
|
73
|
+
async function generateCleanHtml(config) {
|
|
74
|
+
const htmlPageFilePaths = await getFilePaths(config.outDir, "html");
|
|
75
|
+
await cleanHtmlPages(htmlPageFilePaths);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
generateAssets,
|
|
79
|
+
generateCleanHtml,
|
|
80
|
+
generateHtmlPages,
|
|
81
|
+
generateNoStyleTemp,
|
|
82
|
+
generatePublic,
|
|
83
|
+
generateTempPages,
|
|
84
|
+
generateTempRoot,
|
|
85
|
+
generateViteImporters
|
|
86
|
+
};
|
package/dist/pages.js
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Fragment } from "react";
|
|
2
|
+
import { useState, useEffect, Fragment } from "react";
|
|
3
3
|
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
|
4
4
|
import { Page } from "./page.js";
|
|
5
5
|
const Pages = () => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const [roots, setRoots] = useState([
|
|
7
|
+
{ RootComponent: Fragment, getGlobalStaticData: void 0 }
|
|
8
|
+
]);
|
|
9
|
+
const [routes, setRoutes] = useState([]);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const data = async () => {
|
|
12
|
+
const { getRoots } = await import(
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
"/@minista-temp/vite-importer/roots.js"
|
|
15
|
+
);
|
|
16
|
+
const { getRoutes } = await import(
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
"/@minista-temp/vite-importer/routes.js"
|
|
19
|
+
);
|
|
20
|
+
try {
|
|
21
|
+
const { getAssets } = await import(
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
"/@minista-temp/vite-importer/assets.js"
|
|
24
|
+
);
|
|
25
|
+
getAssets();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
}
|
|
28
|
+
setRoots(getRoots);
|
|
29
|
+
setRoutes(getRoutes);
|
|
11
30
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const routes = Object.keys(ROUTES).map((route) => {
|
|
15
|
-
const routePath = route.replace(/\/src\/pages|index|\.js$/g, "").replace(/\/src\/pages|index|\.jsx$/g, "").replace(/\/src\/pages|index|\.ts$/g, "").replace(/\/src\/pages|index|\.tsx$/g, "").replace(/\/src\/pages|index|\.md$/g, "").replace(/\/src\/pages|index|\.mdx$/g, "").replace(/\[\.{3}.+\]/, "*").replace(/\[(.+)\]/, ":$1");
|
|
16
|
-
return {
|
|
17
|
-
routePath,
|
|
18
|
-
PageComponent: ROUTES[route].default,
|
|
19
|
-
getStaticData: ROUTES[route].getStaticData ? ROUTES[route].getStaticData : void 0,
|
|
20
|
-
frontmatter: ROUTES[route].frontmatter ? ROUTES[route].frontmatter : void 0
|
|
21
|
-
};
|
|
22
|
-
});
|
|
31
|
+
data();
|
|
32
|
+
}, []);
|
|
23
33
|
return /* @__PURE__ */ React.createElement(Fragment, null, routes.length > 0 && /* @__PURE__ */ React.createElement(BrowserRouter, null, /* @__PURE__ */ React.createElement(Routes, null, routes == null ? void 0 : routes.map(({
|
|
24
34
|
routePath,
|
|
25
35
|
PageComponent = Fragment,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { ExoticComponent } from "react";
|
|
2
2
|
import type vite from "vite";
|
|
3
3
|
import type { Options as MdxOptions } from "@mdx-js/esbuild";
|
|
4
|
+
export declare type MinistaConfig = {
|
|
5
|
+
outDir: string;
|
|
6
|
+
publicDir: string;
|
|
7
|
+
assetsDir: string;
|
|
8
|
+
autoAssetsName: string;
|
|
9
|
+
rootFileDir: string;
|
|
10
|
+
rootFileName: string;
|
|
11
|
+
rootFileExt: string[];
|
|
12
|
+
pagesDir: string;
|
|
13
|
+
pagesExt: string[];
|
|
14
|
+
tempDir: string;
|
|
15
|
+
tempConfigDir: string;
|
|
16
|
+
tempViteImporterDir: string;
|
|
17
|
+
tempAssetsDir: string;
|
|
18
|
+
tempRootFileDir: string;
|
|
19
|
+
tempPagesDir: string;
|
|
20
|
+
};
|
|
4
21
|
export declare type MinistaUserConfig = {
|
|
5
22
|
entry?: string | string[] | {
|
|
6
23
|
[key: string]: string;
|
package/dist/vite.js
CHANGED
|
@@ -49,6 +49,10 @@ const defaultViteConfig = defineConfig({
|
|
|
49
49
|
find: "/@minista",
|
|
50
50
|
replacement: path.resolve(__dirname + "/../")
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
find: "/@minista-temp",
|
|
54
|
+
replacement: path.resolve("node_modules/.minista/")
|
|
55
|
+
},
|
|
52
56
|
{
|
|
53
57
|
find: "react/jsx-runtime",
|
|
54
58
|
replacement: "react/jsx-runtime.js"
|
|
@@ -112,7 +116,7 @@ function getAssetsTagStr(input) {
|
|
|
112
116
|
return tags.push(tag);
|
|
113
117
|
});
|
|
114
118
|
}
|
|
115
|
-
const sortedTags = tags.sort((a, b) => a < b ? -1 : 1);
|
|
119
|
+
const sortedTags = tags.length >= 2 ? tags.filter((item) => !!item).sort((a, b) => a < b ? -1 : 1) : tags;
|
|
116
120
|
return sortedTags.join("\n");
|
|
117
121
|
}
|
|
118
122
|
function getAssetsTag(input) {
|
|
@@ -120,7 +124,7 @@ function getAssetsTag(input) {
|
|
|
120
124
|
if (input.match(/\.(css|sass|scss)$/)) {
|
|
121
125
|
return `<link rel="stylesheet" href="/${input}">`;
|
|
122
126
|
} else if (input.match(/\.(js|cjs|mjs|jsx|ts|tsx)$/)) {
|
|
123
|
-
return
|
|
127
|
+
return;
|
|
124
128
|
} else {
|
|
125
129
|
console.log("Could not insert the entry [vite.build.rollupOptions.input] into the dev server.");
|
|
126
130
|
return "";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minista",
|
|
3
3
|
"description": "Next.js Like Development with 100% Static Generate",
|
|
4
|
-
"version": "2.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.16",
|
|
5
5
|
"bin": {
|
|
6
6
|
"minista": "./bin/minista.js"
|
|
7
7
|
},
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"test:v": "cd ./test && npx minista -v",
|
|
54
54
|
"test:h": "cd ./test && npx minista -h",
|
|
55
55
|
"prepublishOnly": "npm run build:all",
|
|
56
|
-
"clean": "trash ./dist ./test/dist ./test/node_modules/.minista"
|
|
56
|
+
"clean": "trash ./dist ./test/dist ./test/node_modules/.minista ./test/node_modules/.vite"
|
|
57
57
|
},
|
|
58
58
|
"prettier": {
|
|
59
59
|
"semi": false
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"@mdx-js/rollup": "^2.0.0",
|
|
69
69
|
"@vitejs/plugin-react": "^1.2.0",
|
|
70
70
|
"cac": "^6.7.12",
|
|
71
|
-
"esbuild": "^0.14.
|
|
71
|
+
"esbuild": "^0.14.25",
|
|
72
72
|
"fs-extra": "^10.0.1",
|
|
73
73
|
"js-beautify": "^1.14.0",
|
|
74
|
-
"node-fetch": "^3.2.
|
|
74
|
+
"node-fetch": "^3.2.3",
|
|
75
75
|
"picocolors": "^1.0.0",
|
|
76
76
|
"react-helmet": "^6.1.0",
|
|
77
77
|
"react-router-dom": "^6.2.2",
|
|
@@ -86,12 +86,12 @@
|
|
|
86
86
|
"@types/fs-extra": "^9.0.13",
|
|
87
87
|
"@types/js-beautify": "^1.13.3",
|
|
88
88
|
"@types/node": "^17.0.21",
|
|
89
|
-
"@types/react": "^17.0.
|
|
90
|
-
"@types/react-dom": "^17.0.
|
|
89
|
+
"@types/react": "^17.0.40",
|
|
90
|
+
"@types/react-dom": "^17.0.13",
|
|
91
91
|
"@types/react-helmet": "^6.1.5",
|
|
92
92
|
"react": "^17.0.2",
|
|
93
93
|
"react-dom": "^17.0.2",
|
|
94
|
-
"tsup": "^5.
|
|
94
|
+
"tsup": "^5.12.1",
|
|
95
95
|
"typescript": "^4.6.2"
|
|
96
96
|
}
|
|
97
97
|
}
|