@berlysia/vertical-writing-slide-system 0.0.12 → 0.0.14

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/cli.js CHANGED
@@ -2,16 +2,77 @@
2
2
  // @ts-check
3
3
 
4
4
  import { execSync } from "child_process";
5
- import { mkdir, mkdtemp, cp, rm } from "node:fs/promises";
5
+ import { mkdir, mkdtemp, cp, rm, writeFile, access } from "node:fs/promises";
6
6
  import { resolve } from "node:path";
7
7
  import { parseArgs } from "node:util";
8
- import { build } from "vite";
8
+ import { build, createServer } from "vite";
9
+
10
+ async function ensureIndexHtml() {
11
+ const indexHtmlPath = resolve(process.cwd(), "index.html");
12
+ try {
13
+ await access(indexHtmlPath);
14
+ // index.html already exists
15
+ return;
16
+ } catch {
17
+ // index.html doesn't exist, create it
18
+ // Use relative paths that Vite can resolve during development
19
+ const indexHtmlContent = `<!doctype html>
20
+ <html lang="ja">
21
+ <head>
22
+ <meta charset="UTF-8" />
23
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
24
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
25
+ <title>Vertical Writing Slides</title>
26
+ <link rel="preconnect" href="https://fonts.googleapis.com">
27
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
28
+ <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
29
+ <link rel="stylesheet" href="/src/index.css" />
30
+ <link rel="stylesheet" media="screen" href="/src/screen.css" />
31
+ <link rel="stylesheet" media="print" href="/src/print.css" />
32
+ </head>
33
+ <body>
34
+ <div id="root"></div>
35
+ <script type="module" src="/src/main.tsx"></script>
36
+ </body>
37
+ </html>`;
38
+
39
+ await writeFile(indexHtmlPath, indexHtmlContent);
40
+ console.log("Generated index.html for external project");
41
+ }
42
+ }
9
43
 
10
44
  async function runDev() {
11
45
  try {
12
- execSync("npx vite", { stdio: "inherit" });
46
+ const libPath = import.meta.dirname;
47
+ const projectPath = process.cwd();
48
+
49
+ const server = await createServer({
50
+ root: libPath, // Use library as root for assets
51
+ configFile: resolve(libPath, "vite.config.ts"),
52
+ server: {
53
+ fs: {
54
+ allow: [
55
+ // Allow serving files from the library directory
56
+ libPath,
57
+ // Allow serving files from the current working directory
58
+ projectPath,
59
+ ],
60
+ },
61
+ },
62
+ });
63
+
64
+ await server.listen();
65
+ server.printUrls();
66
+ console.log("Development server started. Press Ctrl+C to stop.");
67
+
68
+ // Keep the process running
69
+ process.on("SIGINT", async () => {
70
+ console.log("\nShutting down development server...");
71
+ await server.close();
72
+ process.exit(0);
73
+ });
13
74
  } catch (error) {
14
- console.error("Error during build:", error);
75
+ console.error("Error during development server startup:", error);
15
76
  process.exit(1);
16
77
  }
17
78
  }
@@ -36,7 +97,12 @@ async function runBuild() {
36
97
  outDir: resolve(process.cwd(), "pages"),
37
98
  rollupOptions: {
38
99
  input: resolve(import.meta.dirname, "src/main.tsx"),
100
+ output: {
101
+ assetFileNames: "assets/[name]-[hash][extname]",
102
+ },
39
103
  },
104
+ cssCodeSplit: true,
105
+ assetsInlineLimit: 0,
40
106
  },
41
107
  });
42
108
  } catch (error) {
package/index.html CHANGED
@@ -5,12 +5,12 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Vite + React + TS</title>
8
- <link rel="preconnect" href="https://fonts.googleapis.com">
9
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
- <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
11
- <link rel="stylesheet" href="/src/index.css" />
12
- <link rel="stylesheet" media="screen" href="/src/screen.css" />
13
- <link rel="stylesheet" media="print" href="/src/print.css" />
8
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
+ <link
11
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Noto+Sans+Mono:wght@100..900&display=swap"
12
+ rel="stylesheet"
13
+ />
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@berlysia/vertical-writing-slide-system",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "vertical-slides": "./cli.js"
package/src/index.css CHANGED
@@ -1,3 +1,6 @@
1
+ @import "screen.css" screen;
2
+ @import "print.css" print;
3
+
1
4
  * {
2
5
  box-sizing: border-box;
3
6
  }
package/src/main.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import { StrictMode } from "react";
2
2
  import { createRoot } from "react-dom/client";
3
3
  import App from "./App.tsx";
4
+ import "./index.css";
4
5
 
5
6
  createRoot(document.getElementById("root")!).render(
6
7
  <StrictMode>
@@ -322,15 +322,21 @@ export default async function slidesPlugin(
322
322
  }
323
323
  },
324
324
 
325
- generateBundle(options, bundle) {
325
+ generateBundle(_options, bundle) {
326
326
  // Generate HTML file if none exists in consumer project
327
327
  const consumerIndexHtml = path.resolve(resolvedConfig.root, "index.html");
328
328
 
329
329
  if (!fs.existsSync(consumerIndexHtml)) {
330
- // Find the main JS file in the bundle
330
+ // Find the main JS and CSS files in the bundle
331
331
  const mainJsFile = Object.keys(bundle).find(
332
332
  (fileName) =>
333
- fileName.startsWith("assets/main-") && fileName.endsWith(".js"),
333
+ fileName.startsWith("assets/") &&
334
+ fileName.includes("main-") &&
335
+ fileName.endsWith(".js"),
336
+ );
337
+ const mainCssFile = Object.keys(bundle).find(
338
+ (fileName) =>
339
+ fileName.startsWith("assets/") && fileName.endsWith(".css"),
334
340
  );
335
341
 
336
342
  if (!mainJsFile) {
@@ -338,6 +344,10 @@ export default async function slidesPlugin(
338
344
  return;
339
345
  }
340
346
 
347
+ const cssLink = mainCssFile
348
+ ? `<link rel="stylesheet" href="./${mainCssFile}">`
349
+ : "<!-- CSS is included in the JS bundle -->";
350
+
341
351
  const virtualIndexHtml = `<!doctype html>
342
352
  <html lang="ja">
343
353
  <head>
@@ -347,6 +357,7 @@ export default async function slidesPlugin(
347
357
  <link rel="preconnect" href="https://fonts.googleapis.com">
348
358
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
349
359
  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
360
+ ${cssLink}
350
361
  </head>
351
362
  <body>
352
363
  <div id="root"></div>