slidev-workspace 0.1.8 → 0.1.9

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli.js +75 -8
  3. package/package.json +1 -1
  4. package/README.md +0 -145
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Leo Chiu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli.js CHANGED
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { dirname, join, resolve } from "node:path";
4
+ import { existsSync, mkdirSync, readdirSync } from "node:fs";
5
+ import { cp } from "node:fs/promises";
6
+ import { execSync } from "node:child_process";
4
7
  import { build, createServer } from "vite";
5
8
  import vue from "@vitejs/plugin-vue";
6
9
  import tailwindcss from "@tailwindcss/vite";
7
- import { existsSync, readFileSync, readdirSync, watch } from "fs";
10
+ import { existsSync as existsSync$1, readFileSync, readdirSync as readdirSync$1, watch } from "fs";
8
11
  import { basename, join as join$1, resolve as resolve$1 } from "path";
9
12
  import { parse } from "yaml";
10
13
 
@@ -25,7 +28,7 @@ function loadConfig(workingDir) {
25
28
  const projectRoot = workingDir || process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
26
29
  for (const configPath of configPaths) {
27
30
  const fullPath = join$1(projectRoot, configPath);
28
- if (existsSync(fullPath)) try {
31
+ if (existsSync$1(fullPath)) try {
29
32
  if (configPath.endsWith(".yml") || configPath.endsWith(".yaml")) {
30
33
  const content = readFileSync(fullPath, "utf8");
31
34
  const config = parse(content);
@@ -46,7 +49,7 @@ function resolveSlidesDirs(config, workingDir) {
46
49
  if (resolve$1(dir) === dir) return dir;
47
50
  else return resolve$1(projectRoot, dir);
48
51
  }).filter((dir) => {
49
- const exists = existsSync(dir);
52
+ const exists = existsSync$1(dir);
50
53
  return exists;
51
54
  });
52
55
  return resolvedDirs;
@@ -57,7 +60,7 @@ function resolveSlidesDirs(config, workingDir) {
57
60
  function getSlideFrontmatterByPath(slideDir, slideName) {
58
61
  try {
59
62
  const fullPath = join$1(slideDir, slideName, "slides.md");
60
- if (!existsSync(fullPath)) {
63
+ if (!existsSync$1(fullPath)) {
61
64
  console.warn(`File not found: ${fullPath}`);
62
65
  return null;
63
66
  }
@@ -89,12 +92,12 @@ function getAllSlidesFrontmatter() {
89
92
  const slidesDirs = resolveSlidesDirs(config);
90
93
  const slides = [];
91
94
  for (const slidesDir of slidesDirs) {
92
- if (!existsSync(slidesDir)) {
95
+ if (!existsSync$1(slidesDir)) {
93
96
  console.warn(`Slides directory not found: ${slidesDir}`);
94
97
  continue;
95
98
  }
96
99
  try {
97
- const slideDirs = readdirSync(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).filter((dirent) => !(config.exclude || []).includes(dirent.name)).map((dirent) => dirent.name);
100
+ const slideDirs = readdirSync$1(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).filter((dirent) => !(config.exclude || []).includes(dirent.name)).map((dirent) => dirent.name);
98
101
  for (const slideDir of slideDirs) {
99
102
  const slideInfo = getSlideFrontmatterByPath(slidesDir, slideDir);
100
103
  if (slideInfo) slides.push(slideInfo);
@@ -181,11 +184,72 @@ function createViteConfig() {
181
184
  }
182
185
  };
183
186
  }
187
+ async function buildAllSlides() {
188
+ const workspaceCwd = process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
189
+ const config = loadConfig(workspaceCwd);
190
+ const slidesDirs = resolveSlidesDirs(config, workspaceCwd);
191
+ console.log("🔨 Building all slides...");
192
+ for (const slidesDir of slidesDirs) {
193
+ if (!existsSync(slidesDir)) {
194
+ console.warn(`⚠️ Slides directory not found: ${slidesDir}`);
195
+ continue;
196
+ }
197
+ const slides = readdirSync(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
198
+ for (const slideName of slides) {
199
+ const slideDir = join(slidesDir, slideName);
200
+ const packageJsonPath = join(slideDir, "package.json");
201
+ if (!existsSync(packageJsonPath)) {
202
+ console.warn(`⚠️ Skipping ${slideName}: no package.json found`);
203
+ continue;
204
+ }
205
+ console.log(`📦 Building slide: ${slideName}`);
206
+ try {
207
+ const buildCmd = `pnpm --filter "./slides/${slideName}" run build --base ${config.baseUrl}${slideName}/`;
208
+ execSync(buildCmd, {
209
+ cwd: workspaceCwd,
210
+ stdio: "inherit"
211
+ });
212
+ console.log(`✅ Built slide: ${slideName}`);
213
+ } catch (error) {
214
+ console.error(`❌ Failed to build slide ${slideName}:`, error);
215
+ process.exit(1);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ async function copyToGhPages() {
221
+ const workspaceCwd = process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
222
+ const config = loadConfig(workspaceCwd);
223
+ const slidesDirs = resolveSlidesDirs(config, workspaceCwd);
224
+ const ghPagesDir = join(workspaceCwd, "_gh-pages");
225
+ console.log("📁 Copying files to _gh-pages directory...");
226
+ if (!existsSync(ghPagesDir)) mkdirSync(ghPagesDir, { recursive: true });
227
+ for (const slidesDir of slidesDirs) {
228
+ if (!existsSync(slidesDir)) continue;
229
+ const slides = readdirSync(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
230
+ for (const slideName of slides) {
231
+ const slideDistDir = join(slidesDir, slideName, "dist");
232
+ const targetDir = join(ghPagesDir, slideName);
233
+ if (existsSync(slideDistDir)) {
234
+ console.log(`📋 Copying ${slideName} to _gh-pages...`);
235
+ await cp(slideDistDir, targetDir, { recursive: true });
236
+ }
237
+ }
238
+ }
239
+ const previewDistDir = join(workspaceCwd, config.outputDir);
240
+ if (existsSync(previewDistDir)) {
241
+ console.log("📋 Copying preview app as index...");
242
+ await cp(previewDistDir, ghPagesDir, { recursive: true });
243
+ }
244
+ console.log("✅ All files copied to _gh-pages successfully!");
245
+ }
184
246
  async function runViteBuild() {
185
247
  try {
248
+ await buildAllSlides();
186
249
  console.log("📦 Building Slidev Workspace for production...");
187
250
  const config = createViteConfig();
188
251
  await build(config);
252
+ await copyToGhPages();
189
253
  console.log("✅ Build completed successfully!");
190
254
  } catch (error) {
191
255
  console.error("❌ Build failed:", error);
@@ -217,8 +281,11 @@ Commands:
217
281
  help Show this help message
218
282
 
219
283
  Examples:
220
- slidev-workspace dev # Start development server
221
- slidev-workspace build # Build for production
284
+ slidev-workspace dev # Start development server
285
+ slidev-workspace build # Build all slides and preview app
286
+
287
+ Configuration:
288
+ Use slidev-workspace.yml to set baseUrl for all builds
222
289
 
223
290
  For more information, visit: https://github.com/author/slidev-workspace
224
291
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slidev-workspace",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A workspace tool for managing multiple Slidev presentations with API-based content management",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/README.md DELETED
@@ -1,145 +0,0 @@
1
- # Slidev Workspace
2
-
3
- 一個用於管理多個 Slidev 演示文稿的工作區工具,提供類似 Contentful API 的內容管理介面。
4
-
5
- ## 功能特色
6
-
7
- ✨ **自動發現 Slides**: 自動掃描配置目錄中的所有 Slidev 演示文稿
8
- 🔍 **智慧搜尋**: 支援按標題、描述、作者和主題搜尋
9
- 📊 **Frontmatter 解析**: 完整解析每個 slide 的 YAML frontmatter
10
- 🌐 **類 Contentful API**: 提供結構化的 API 介面來存取 slides
11
- 🎨 **現代介面**: 使用 Vue 3 + Tailwind CSS 的響應式介面
12
- 🔥 **熱重載**: 開發時自動檢測 slides 變更
13
-
14
- ## 安裝和使用
15
-
16
- ### 1. 基本使用
17
-
18
- ```bash
19
- # 開發模式
20
- pnpm run slidev-workspace:dev
21
-
22
- # 建置
23
- pnpm run slidev-workspace:build
24
- ```
25
-
26
- ### 2. CLI 工具 (計劃中)
27
-
28
- ```bash
29
- # 全域安裝後
30
- slidev-workspace dev
31
- slidev-workspace build
32
- ```
33
-
34
- ## 配置
35
-
36
- 在專案根目錄創建 `slidev-workspace.yml` 來配置 slides 來源:
37
-
38
- ```yaml
39
- # Slidev Workspace 配置
40
- slidesDir:
41
- - "../../demo/slides" # 相對路徑到 slides 目錄
42
- - "./slides" # 本地 slides 目錄
43
-
44
- outputDir: "./slide-decks/dist"
45
- baseUrl: "/"
46
-
47
- exclude:
48
- - "node_modules"
49
- - ".git"
50
- - ".DS_Store"
51
- ```
52
-
53
- ## API 介面
54
-
55
- ### 基本 API
56
-
57
- ```typescript
58
- import { slidesApi } from '@/composables/useSlidesApi'
59
-
60
- // 獲取所有 slides
61
- const { data: slides } = await slidesApi.getEntries()
62
-
63
- // 搜尋 slides
64
- const results = await slidesApi.getEntries({
65
- search: 'Vue.js',
66
- theme: 'seriph',
67
- limit: 10
68
- })
69
-
70
- // 獲取特定 slide
71
- const { data: slide } = await slidesApi.getEntry('slides/my-presentation')
72
- ```
73
-
74
- ### 響應式查詢
75
-
76
- ```vue
77
- <script setup>
78
- import { ref } from 'vue'
79
- import { slidesApi } from '@/composables/useSlidesApi'
80
-
81
- const searchOptions = ref({
82
- search: '',
83
- theme: 'seriph',
84
- sort: 'title'
85
- })
86
-
87
- // 即時搜尋結果
88
- const slides = slidesApi.createLiveQuery(searchOptions)
89
- </script>
90
- ```
91
-
92
- ## 專案結構
93
-
94
- ```
95
- packages/slidev-workspace/
96
- ├── scripts/ # 核心腳本
97
- │ ├── config.ts # 配置管理
98
- │ ├── getSlideFrontmatter.ts # Slides 解析
99
- │ └── vite-plugin-slides.ts # Vite 插件
100
- ├── slide-decks/ # Vue 應用
101
- │ ├── src/
102
- │ │ ├── components/ # UI 組件
103
- │ │ ├── composables/ # API 邏輯
104
- │ │ └── utils/ # 工具函數
105
- │ └── package.json
106
- ├── src/ # 庫匯出
107
- │ ├── index.ts # 主要匯出
108
- │ └── cli.ts # CLI 工具
109
- └── slidev-workspace.yml # 配置檔案
110
- ```
111
-
112
- ## 測試
113
-
114
- ```bash
115
- # 測試核心功能
116
- npx tsx test-slides.js
117
-
118
- # 預期輸出
119
- 🔍 Testing Slidev Workspace functionality...
120
- 📁 Loading slides...
121
- ✅ Found 2 slides:
122
-
123
- 1. Welcome to Slidev
124
- ID: slides/slidev-starter-1
125
- Source: /Users/.../demo/slides
126
- Theme: seriph
127
- ```
128
-
129
- ## 開發
130
-
131
- 這個工具是基於以下技術棧開發:
132
-
133
- - **後端**: Node.js + TypeScript
134
- - **前端**: Vue 3 + Composition API
135
- - **樣式**: Tailwind CSS
136
- - **建置**: Vite + tsdown
137
- - **包管理**: pnpm workspace
138
-
139
- ## 貢獻
140
-
141
- 歡迎提交 Issues 和 Pull Requests!
142
-
143
- ## 許可證
144
-
145
- MIT License