@chronoter/main 0.1.3 → 0.1.5
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 +32 -60
- package/dist/index.js +23 -48
- package/dist/server/client/main.css +5373 -0
- package/dist/server/client/main.js +1643 -0
- package/dist/server/templates/index.html +3 -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, resolve, join, relative, extname, basename } from 'path';
|
|
6
|
+
import { dirname, resolve, join, relative, extname, basename, normalize, 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';
|
|
@@ -15,7 +15,7 @@ import { createServer, defineConfig } from 'vite';
|
|
|
15
15
|
import { z } from 'zod';
|
|
16
16
|
import react from '@vitejs/plugin-react';
|
|
17
17
|
import mdx from '@mdx-js/rollup';
|
|
18
|
-
import {
|
|
18
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
19
19
|
import { watch } from 'chokidar';
|
|
20
20
|
import { homedir } from 'os';
|
|
21
21
|
import { createInterface } from 'readline';
|
|
@@ -589,7 +589,28 @@ var init_routing_middleware = __esm({
|
|
|
589
589
|
req.chronoterRoute = route;
|
|
590
590
|
}
|
|
591
591
|
const templatePath = __dirname$1.endsWith("dist") ? resolve(__dirname$1, "server/templates/index.html") : resolve(__dirname$1, "templates/index.html");
|
|
592
|
-
|
|
592
|
+
let html = await readFile(templatePath, "utf-8");
|
|
593
|
+
const normalizedDirname = normalize(__dirname$1);
|
|
594
|
+
const isProduction = normalizedDirname.includes(`${sep}dist${sep}`) || normalizedDirname.endsWith(`${sep}dist`);
|
|
595
|
+
if (isProduction) {
|
|
596
|
+
html = html.replace(
|
|
597
|
+
"<!--__CHRONOTER_STYLES__-->",
|
|
598
|
+
'<link rel="stylesheet" href="/server/client/main.css" />'
|
|
599
|
+
);
|
|
600
|
+
html = html.replace(
|
|
601
|
+
"<!--__CHRONOTER_SCRIPTS__-->",
|
|
602
|
+
'<script type="module" src="/server/client/main.js"></script>'
|
|
603
|
+
);
|
|
604
|
+
} else {
|
|
605
|
+
html = html.replace("<!--__CHRONOTER_STYLES__-->", "");
|
|
606
|
+
html = html.replace(
|
|
607
|
+
"<!--__CHRONOTER_SCRIPTS__-->",
|
|
608
|
+
'<script type="module" src="/src/server/client/main.tsx"></script>'
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
const safeConfigJson = JSON.stringify(config).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
612
|
+
const configScript = `<script type="application/json" id="chronoter-config">${safeConfigJson}</script>`;
|
|
613
|
+
html = html.replace("<!--__CHRONOTER_CONFIG__-->", configScript);
|
|
593
614
|
const transformedHtml = await server.transformIndexHtml(url, html);
|
|
594
615
|
res.statusCode = route ? 200 : 404;
|
|
595
616
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -921,50 +942,6 @@ Please create a chronoter.config.json file.`
|
|
|
921
942
|
|
|
922
943
|
// src/server/vite-config.ts
|
|
923
944
|
init_ignore_patterns();
|
|
924
|
-
|
|
925
|
-
// src/server/plugins/config-virtual-module.ts
|
|
926
|
-
var VIRTUAL_CONFIG_MODULE_ID = "virtual:chronoter-config";
|
|
927
|
-
var RESOLVED_VIRTUAL_CONFIG_MODULE_ID = "\0" + VIRTUAL_CONFIG_MODULE_ID;
|
|
928
|
-
var createConfigVirtualModulePlugin = (config) => {
|
|
929
|
-
return {
|
|
930
|
-
name: "chronoter-config-virtual-module",
|
|
931
|
-
/**
|
|
932
|
-
* Virtual moduleのIDを解決
|
|
933
|
-
*/
|
|
934
|
-
resolveId(id) {
|
|
935
|
-
if (id === VIRTUAL_CONFIG_MODULE_ID) {
|
|
936
|
-
return RESOLVED_VIRTUAL_CONFIG_MODULE_ID;
|
|
937
|
-
}
|
|
938
|
-
return null;
|
|
939
|
-
},
|
|
940
|
-
/**
|
|
941
|
-
* Virtual moduleのコードを生成
|
|
942
|
-
*/
|
|
943
|
-
load(id) {
|
|
944
|
-
if (id === RESOLVED_VIRTUAL_CONFIG_MODULE_ID) {
|
|
945
|
-
const configCode = `
|
|
946
|
-
// Auto-generated by chronoter-config-virtual-module plugin
|
|
947
|
-
// This module provides access to the Chronoter configuration
|
|
948
|
-
|
|
949
|
-
export const config = ${JSON.stringify(config, null, 2)};
|
|
950
|
-
|
|
951
|
-
// HMR\u5BFE\u5FDC
|
|
952
|
-
if (import.meta.hot) {
|
|
953
|
-
import.meta.hot.accept((newModule) => {
|
|
954
|
-
if (newModule) {
|
|
955
|
-
console.log('[chronoter] Configuration updated');
|
|
956
|
-
// \u8A2D\u5B9A\u304C\u5909\u66F4\u3055\u308C\u305F\u5834\u5408\u306F\u30DA\u30FC\u30B8\u5168\u4F53\u3092\u30EA\u30ED\u30FC\u30C9
|
|
957
|
-
window.location.reload();
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
`;
|
|
962
|
-
return configCode;
|
|
963
|
-
}
|
|
964
|
-
return null;
|
|
965
|
-
}
|
|
966
|
-
};
|
|
967
|
-
};
|
|
968
945
|
var __filename2 = fileURLToPath(import.meta.url);
|
|
969
946
|
var __dirname2 = dirname(__filename2);
|
|
970
947
|
var isMediaFileRequest = (url) => {
|
|
@@ -1022,8 +999,6 @@ var createViteConfig = (config, options = {}) => {
|
|
|
1022
999
|
// MDXファイルもReactコンポーネントとして扱う
|
|
1023
1000
|
include: /\.(jsx|tsx|mdx)$/
|
|
1024
1001
|
}),
|
|
1025
|
-
// 設定情報をクライアントに注入するVirtual Moduleプラグイン
|
|
1026
|
-
createConfigVirtualModulePlugin(config),
|
|
1027
1002
|
// ルーティングミドルウェアを登録するプラグイン
|
|
1028
1003
|
{
|
|
1029
1004
|
name: "chronoter-routing",
|
|
@@ -1632,8 +1607,10 @@ var runVersionCheck = async (packageName, currentVersion) => {
|
|
|
1632
1607
|
} catch {
|
|
1633
1608
|
}
|
|
1634
1609
|
};
|
|
1610
|
+
|
|
1611
|
+
// src/cli/index.ts
|
|
1635
1612
|
var PACKAGE_NAME = "chronoter";
|
|
1636
|
-
var CURRENT_VERSION = "0.1.
|
|
1613
|
+
var CURRENT_VERSION = "0.1.5";
|
|
1637
1614
|
var createCliProgram = () => {
|
|
1638
1615
|
const program = new Command();
|
|
1639
1616
|
program.name("chronoter").description("Chronoter - MDX-based documentation site generator").version(CURRENT_VERSION);
|
|
@@ -1686,18 +1663,13 @@ var main = async () => {
|
|
|
1686
1663
|
await runVersionCheck(PACKAGE_NAME, CURRENT_VERSION);
|
|
1687
1664
|
}
|
|
1688
1665
|
const program = createCliProgram();
|
|
1666
|
+
if (args.length === 0) {
|
|
1667
|
+
program.help();
|
|
1668
|
+
}
|
|
1689
1669
|
await program.parseAsync(process.argv);
|
|
1690
1670
|
};
|
|
1691
|
-
var
|
|
1692
|
-
|
|
1693
|
-
const realArgv1 = realpathSync(process.argv[1]);
|
|
1694
|
-
const currentFile = fileURLToPath(import.meta.url);
|
|
1695
|
-
return currentFile === realArgv1;
|
|
1696
|
-
} catch {
|
|
1697
|
-
return false;
|
|
1698
|
-
}
|
|
1699
|
-
})();
|
|
1700
|
-
if (isMainModule) {
|
|
1671
|
+
var isDirectRun = process.argv[1]?.includes("chronoter-main") ?? false;
|
|
1672
|
+
if (isDirectRun) {
|
|
1701
1673
|
main().catch((error) => {
|
|
1702
1674
|
console.error(chalk2.red("An unexpected error occurred:"));
|
|
1703
1675
|
console.error(error);
|
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, extname, relative, basename } from 'path';
|
|
5
|
+
import { dirname, resolve, join, normalize, sep, extname, 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';
|
|
@@ -584,7 +584,28 @@ var init_routing_middleware = __esm({
|
|
|
584
584
|
req.chronoterRoute = route;
|
|
585
585
|
}
|
|
586
586
|
const templatePath = __dirname$1.endsWith("dist") ? resolve(__dirname$1, "server/templates/index.html") : resolve(__dirname$1, "templates/index.html");
|
|
587
|
-
|
|
587
|
+
let html = await readFile(templatePath, "utf-8");
|
|
588
|
+
const normalizedDirname = normalize(__dirname$1);
|
|
589
|
+
const isProduction = normalizedDirname.includes(`${sep}dist${sep}`) || normalizedDirname.endsWith(`${sep}dist`);
|
|
590
|
+
if (isProduction) {
|
|
591
|
+
html = html.replace(
|
|
592
|
+
"<!--__CHRONOTER_STYLES__-->",
|
|
593
|
+
'<link rel="stylesheet" href="/server/client/main.css" />'
|
|
594
|
+
);
|
|
595
|
+
html = html.replace(
|
|
596
|
+
"<!--__CHRONOTER_SCRIPTS__-->",
|
|
597
|
+
'<script type="module" src="/server/client/main.js"></script>'
|
|
598
|
+
);
|
|
599
|
+
} else {
|
|
600
|
+
html = html.replace("<!--__CHRONOTER_STYLES__-->", "");
|
|
601
|
+
html = html.replace(
|
|
602
|
+
"<!--__CHRONOTER_SCRIPTS__-->",
|
|
603
|
+
'<script type="module" src="/src/server/client/main.tsx"></script>'
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
const safeConfigJson = JSON.stringify(config).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
607
|
+
const configScript = `<script type="application/json" id="chronoter-config">${safeConfigJson}</script>`;
|
|
608
|
+
html = html.replace("<!--__CHRONOTER_CONFIG__-->", configScript);
|
|
588
609
|
const transformedHtml = await server.transformIndexHtml(url, html);
|
|
589
610
|
res.statusCode = route ? 200 : 404;
|
|
590
611
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -916,50 +937,6 @@ Please create a chronoter.config.json file.`
|
|
|
916
937
|
|
|
917
938
|
// src/server/vite-config.ts
|
|
918
939
|
init_ignore_patterns();
|
|
919
|
-
|
|
920
|
-
// src/server/plugins/config-virtual-module.ts
|
|
921
|
-
var VIRTUAL_CONFIG_MODULE_ID = "virtual:chronoter-config";
|
|
922
|
-
var RESOLVED_VIRTUAL_CONFIG_MODULE_ID = "\0" + VIRTUAL_CONFIG_MODULE_ID;
|
|
923
|
-
var createConfigVirtualModulePlugin = (config) => {
|
|
924
|
-
return {
|
|
925
|
-
name: "chronoter-config-virtual-module",
|
|
926
|
-
/**
|
|
927
|
-
* Virtual moduleのIDを解決
|
|
928
|
-
*/
|
|
929
|
-
resolveId(id) {
|
|
930
|
-
if (id === VIRTUAL_CONFIG_MODULE_ID) {
|
|
931
|
-
return RESOLVED_VIRTUAL_CONFIG_MODULE_ID;
|
|
932
|
-
}
|
|
933
|
-
return null;
|
|
934
|
-
},
|
|
935
|
-
/**
|
|
936
|
-
* Virtual moduleのコードを生成
|
|
937
|
-
*/
|
|
938
|
-
load(id) {
|
|
939
|
-
if (id === RESOLVED_VIRTUAL_CONFIG_MODULE_ID) {
|
|
940
|
-
const configCode = `
|
|
941
|
-
// Auto-generated by chronoter-config-virtual-module plugin
|
|
942
|
-
// This module provides access to the Chronoter configuration
|
|
943
|
-
|
|
944
|
-
export const config = ${JSON.stringify(config, null, 2)};
|
|
945
|
-
|
|
946
|
-
// HMR\u5BFE\u5FDC
|
|
947
|
-
if (import.meta.hot) {
|
|
948
|
-
import.meta.hot.accept((newModule) => {
|
|
949
|
-
if (newModule) {
|
|
950
|
-
console.log('[chronoter] Configuration updated');
|
|
951
|
-
// \u8A2D\u5B9A\u304C\u5909\u66F4\u3055\u308C\u305F\u5834\u5408\u306F\u30DA\u30FC\u30B8\u5168\u4F53\u3092\u30EA\u30ED\u30FC\u30C9
|
|
952
|
-
window.location.reload();
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
`;
|
|
957
|
-
return configCode;
|
|
958
|
-
}
|
|
959
|
-
return null;
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
};
|
|
963
940
|
var __filename2 = fileURLToPath(import.meta.url);
|
|
964
941
|
var __dirname2 = dirname(__filename2);
|
|
965
942
|
var isMediaFileRequest = (url) => {
|
|
@@ -1017,8 +994,6 @@ var createViteConfig = (config, options = {}) => {
|
|
|
1017
994
|
// MDXファイルもReactコンポーネントとして扱う
|
|
1018
995
|
include: /\.(jsx|tsx|mdx)$/
|
|
1019
996
|
}),
|
|
1020
|
-
// 設定情報をクライアントに注入するVirtual Moduleプラグイン
|
|
1021
|
-
createConfigVirtualModulePlugin(config),
|
|
1022
997
|
// ルーティングミドルウェアを登録するプラグイン
|
|
1023
998
|
{
|
|
1024
999
|
name: "chronoter-routing",
|