@chronoter/main 0.1.6 → 0.1.8
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/dist/cli.js +41 -2
- package/dist/index.js +40 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import ignore from 'ignore';
|
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
4
|
import { readFile } from 'fs/promises';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
-
import { dirname, basename, normalize, resolve, join, relative,
|
|
6
|
+
import { dirname, basename, normalize, resolve, extname, join, relative, sep } from 'path';
|
|
7
7
|
import { visit } from 'unist-util-visit';
|
|
8
8
|
import { compile } from '@mdx-js/mdx';
|
|
9
9
|
import matter from 'gray-matter';
|
|
@@ -1015,6 +1015,45 @@ var createViteConfig = (config, options = {}) => {
|
|
|
1015
1015
|
);
|
|
1016
1016
|
}
|
|
1017
1017
|
},
|
|
1018
|
+
// ビルド済みクライアントファイル配信ミドルウェアを登録するプラグイン
|
|
1019
|
+
// npmパッケージとして使用時、/server/client/ へのリクエストをdist内のファイルから配信
|
|
1020
|
+
{
|
|
1021
|
+
name: "chronoter-built-client",
|
|
1022
|
+
configureServer(server) {
|
|
1023
|
+
server.middlewares.use((req, res, next) => {
|
|
1024
|
+
const url = req.url || "";
|
|
1025
|
+
if (url.startsWith("/server/client/")) {
|
|
1026
|
+
const fileName = url.replace("/server/client/", "").split("?")[0];
|
|
1027
|
+
const allowedFiles = ["main.js", "main.css"];
|
|
1028
|
+
if (!allowedFiles.includes(fileName)) {
|
|
1029
|
+
return next();
|
|
1030
|
+
}
|
|
1031
|
+
const clientFilePath = resolve(__dirname2, "server/client", fileName);
|
|
1032
|
+
if (!existsSync(clientFilePath)) {
|
|
1033
|
+
return next();
|
|
1034
|
+
}
|
|
1035
|
+
try {
|
|
1036
|
+
const content = readFileSync(clientFilePath);
|
|
1037
|
+
const ext = extname(clientFilePath).toLowerCase();
|
|
1038
|
+
const mimeTypes = {
|
|
1039
|
+
".js": "application/javascript",
|
|
1040
|
+
".css": "text/css"
|
|
1041
|
+
};
|
|
1042
|
+
const mimeType = mimeTypes[ext] || "application/octet-stream";
|
|
1043
|
+
res.setHeader("Content-Type", mimeType);
|
|
1044
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
1045
|
+
res.end(content);
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
console.error("Error reading built client file:", error);
|
|
1048
|
+
res.statusCode = 500;
|
|
1049
|
+
res.end("Error reading built client file");
|
|
1050
|
+
}
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
next();
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1018
1057
|
// ロゴアセット配信ミドルウェアを登録するプラグイン(メディアファイルミドルウェアより前に配置)
|
|
1019
1058
|
{
|
|
1020
1059
|
name: "chronoter-logo-assets",
|
|
@@ -1610,7 +1649,7 @@ var runVersionCheck = async (packageName, currentVersion) => {
|
|
|
1610
1649
|
|
|
1611
1650
|
// src/cli/index.ts
|
|
1612
1651
|
var PACKAGE_NAME = "chronoter";
|
|
1613
|
-
var CURRENT_VERSION = "0.1.
|
|
1652
|
+
var CURRENT_VERSION = "0.1.8";
|
|
1614
1653
|
var createCliProgram = () => {
|
|
1615
1654
|
const program = new Command();
|
|
1616
1655
|
program.name("chronoter").description("Chronoter - MDX-based documentation site generator").version(CURRENT_VERSION);
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import ignore from 'ignore';
|
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import { readFile } from 'fs/promises';
|
|
4
4
|
import * as path from 'path';
|
|
5
|
-
import { dirname, resolve, join, normalize, sep,
|
|
5
|
+
import { dirname, resolve, extname, join, normalize, sep, relative, basename } from 'path';
|
|
6
6
|
import { visit } from 'unist-util-visit';
|
|
7
7
|
import { compile } from '@mdx-js/mdx';
|
|
8
8
|
import matter from 'gray-matter';
|
|
@@ -1010,6 +1010,45 @@ var createViteConfig = (config, options = {}) => {
|
|
|
1010
1010
|
);
|
|
1011
1011
|
}
|
|
1012
1012
|
},
|
|
1013
|
+
// ビルド済みクライアントファイル配信ミドルウェアを登録するプラグイン
|
|
1014
|
+
// npmパッケージとして使用時、/server/client/ へのリクエストをdist内のファイルから配信
|
|
1015
|
+
{
|
|
1016
|
+
name: "chronoter-built-client",
|
|
1017
|
+
configureServer(server) {
|
|
1018
|
+
server.middlewares.use((req, res, next) => {
|
|
1019
|
+
const url = req.url || "";
|
|
1020
|
+
if (url.startsWith("/server/client/")) {
|
|
1021
|
+
const fileName = url.replace("/server/client/", "").split("?")[0];
|
|
1022
|
+
const allowedFiles = ["main.js", "main.css"];
|
|
1023
|
+
if (!allowedFiles.includes(fileName)) {
|
|
1024
|
+
return next();
|
|
1025
|
+
}
|
|
1026
|
+
const clientFilePath = resolve(__dirname2, "server/client", fileName);
|
|
1027
|
+
if (!existsSync(clientFilePath)) {
|
|
1028
|
+
return next();
|
|
1029
|
+
}
|
|
1030
|
+
try {
|
|
1031
|
+
const content = readFileSync(clientFilePath);
|
|
1032
|
+
const ext = extname(clientFilePath).toLowerCase();
|
|
1033
|
+
const mimeTypes = {
|
|
1034
|
+
".js": "application/javascript",
|
|
1035
|
+
".css": "text/css"
|
|
1036
|
+
};
|
|
1037
|
+
const mimeType = mimeTypes[ext] || "application/octet-stream";
|
|
1038
|
+
res.setHeader("Content-Type", mimeType);
|
|
1039
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
1040
|
+
res.end(content);
|
|
1041
|
+
} catch (error) {
|
|
1042
|
+
console.error("Error reading built client file:", error);
|
|
1043
|
+
res.statusCode = 500;
|
|
1044
|
+
res.end("Error reading built client file");
|
|
1045
|
+
}
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
next();
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1013
1052
|
// ロゴアセット配信ミドルウェアを登録するプラグイン(メディアファイルミドルウェアより前に配置)
|
|
1014
1053
|
{
|
|
1015
1054
|
name: "chronoter-logo-assets",
|