slidev-workspace 0.1.3 → 0.1.4
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 +222 -37
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -10
- package/package.json +3 -5
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,209 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
2
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { build, createServer } from "vite";
|
|
5
|
+
import vue from "@vitejs/plugin-vue";
|
|
6
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
7
|
+
import { existsSync, readFileSync, readdirSync, watch } from "fs";
|
|
8
|
+
import { basename, join as join$1, resolve as resolve$1 } from "path";
|
|
9
|
+
import { parse } from "yaml";
|
|
10
|
+
import "vue";
|
|
5
11
|
|
|
12
|
+
//#region src/scripts/config.ts
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
slidesDir: ["./slides"],
|
|
15
|
+
outputDir: "./dist",
|
|
16
|
+
baseUrl: "/",
|
|
17
|
+
exclude: ["node_modules", ".git"]
|
|
18
|
+
};
|
|
19
|
+
function loadConfig(workingDir) {
|
|
20
|
+
const configPaths = [
|
|
21
|
+
"slidev-workspace.config.js",
|
|
22
|
+
"slidev-workspace.config.ts",
|
|
23
|
+
"slidev-workspace.yml",
|
|
24
|
+
"slidev-workspace.yaml"
|
|
25
|
+
];
|
|
26
|
+
const projectRoot = workingDir || process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
|
|
27
|
+
for (const configPath of configPaths) {
|
|
28
|
+
const fullPath = join$1(projectRoot, configPath);
|
|
29
|
+
if (existsSync(fullPath)) try {
|
|
30
|
+
if (configPath.endsWith(".yml") || configPath.endsWith(".yaml")) {
|
|
31
|
+
const content = readFileSync(fullPath, "utf8");
|
|
32
|
+
const config = parse(content);
|
|
33
|
+
return {
|
|
34
|
+
...DEFAULT_CONFIG,
|
|
35
|
+
...config
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.warn(`Failed to load config from ${fullPath}:`, error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return DEFAULT_CONFIG;
|
|
43
|
+
}
|
|
44
|
+
function resolveSlidesDirs(config, workingDir) {
|
|
45
|
+
const projectRoot = workingDir || process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
|
|
46
|
+
const resolvedDirs = (config.slidesDir || []).map((dir) => {
|
|
47
|
+
if (resolve$1(dir) === dir) return dir;
|
|
48
|
+
else return resolve$1(projectRoot, dir);
|
|
49
|
+
}).filter((dir) => {
|
|
50
|
+
const exists = existsSync(dir);
|
|
51
|
+
return exists;
|
|
52
|
+
});
|
|
53
|
+
return resolvedDirs;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/scripts/getSlideFrontmatter.ts
|
|
58
|
+
function getSlideFrontmatterByPath(slideDir, slideName) {
|
|
59
|
+
try {
|
|
60
|
+
const fullPath = join$1(slideDir, slideName, "slides.md");
|
|
61
|
+
if (!existsSync(fullPath)) {
|
|
62
|
+
console.warn(`File not found: ${fullPath}`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const content = readFileSync(fullPath, "utf8");
|
|
66
|
+
const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*\n/);
|
|
67
|
+
if (!frontmatterMatch) {
|
|
68
|
+
console.warn(`Frontmatter not found in ${fullPath}`);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const frontmatterYaml = frontmatterMatch[1];
|
|
72
|
+
const frontmatter = parse(frontmatterYaml);
|
|
73
|
+
const sourceBasename = basename(slideDir);
|
|
74
|
+
const slideId = `${sourceBasename}/${slideName}`;
|
|
75
|
+
return {
|
|
76
|
+
id: slideId,
|
|
77
|
+
path: slideName,
|
|
78
|
+
fullPath,
|
|
79
|
+
sourceDir: slideDir,
|
|
80
|
+
frontmatter,
|
|
81
|
+
content: content.replace(frontmatterMatch[0], "")
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`Error parsing frontmatter for ${slideName} in ${slideDir}:`, error);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function getAllSlidesFrontmatter() {
|
|
89
|
+
const config = loadConfig();
|
|
90
|
+
const slidesDirs = resolveSlidesDirs(config);
|
|
91
|
+
const slides = [];
|
|
92
|
+
for (const slidesDir of slidesDirs) {
|
|
93
|
+
if (!existsSync(slidesDir)) {
|
|
94
|
+
console.warn(`Slides directory not found: ${slidesDir}`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const slideDirs = readdirSync(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).filter((dirent) => !(config.exclude || []).includes(dirent.name)).map((dirent) => dirent.name);
|
|
99
|
+
for (const slideDir of slideDirs) {
|
|
100
|
+
const slideInfo = getSlideFrontmatterByPath(slidesDir, slideDir);
|
|
101
|
+
if (slideInfo) slides.push(slideInfo);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(`Error reading slides directory ${slidesDir}:`, error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return slides;
|
|
108
|
+
}
|
|
109
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
110
|
+
const slides = getAllSlidesFrontmatter();
|
|
111
|
+
console.log(JSON.stringify(slides, null, 2));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/scripts/vite-plugin-slides.ts
|
|
116
|
+
function slidesPlugin() {
|
|
117
|
+
return {
|
|
118
|
+
name: "vite-plugin-slides",
|
|
119
|
+
configureServer(server) {
|
|
120
|
+
const watchers = [];
|
|
121
|
+
const config = loadConfig();
|
|
122
|
+
const slidesDirs = resolveSlidesDirs(config);
|
|
123
|
+
slidesDirs.forEach((slidesDir) => {
|
|
124
|
+
const watcher = watch(slidesDir, { recursive: true }, (eventType, filename) => {
|
|
125
|
+
if (filename && filename.endsWith("slides.md")) try {
|
|
126
|
+
const slides = getAllSlidesFrontmatter();
|
|
127
|
+
server.ws.send({
|
|
128
|
+
type: "custom",
|
|
129
|
+
event: "slides-updated",
|
|
130
|
+
data: slides
|
|
131
|
+
});
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error("❌ Error reading slides frontmatter:", error);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
watchers.push(watcher);
|
|
137
|
+
});
|
|
138
|
+
server.httpServer?.once("close", () => {
|
|
139
|
+
watchers.forEach((watcher) => watcher.close());
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
resolveId(id) {
|
|
143
|
+
if (id === "slidev:content") return id;
|
|
144
|
+
},
|
|
145
|
+
load(id) {
|
|
146
|
+
if (id === "slidev:content") try {
|
|
147
|
+
const slides = getAllSlidesFrontmatter();
|
|
148
|
+
return `export const slidesData = ${JSON.stringify(slides, null, 2)};
|
|
149
|
+
export default slidesData;`;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error("Error loading slides data:", error);
|
|
152
|
+
return `export const slidesData = [];
|
|
153
|
+
export default slidesData;`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
6
160
|
//#region src/cli.ts
|
|
7
161
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
162
|
const __dirname = dirname(__filename);
|
|
9
163
|
const args = process.argv.slice(2);
|
|
10
164
|
const command = args[0];
|
|
11
165
|
const packageRoot = join(__dirname, "..");
|
|
166
|
+
function createViteConfig() {
|
|
167
|
+
const workspaceCwd = process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
|
|
168
|
+
const config = loadConfig(workspaceCwd);
|
|
169
|
+
return {
|
|
170
|
+
root: resolve(packageRoot, "src/preview"),
|
|
171
|
+
plugins: [
|
|
172
|
+
vue(),
|
|
173
|
+
tailwindcss(),
|
|
174
|
+
slidesPlugin()
|
|
175
|
+
],
|
|
176
|
+
resolve: { alias: { "@": resolve(packageRoot, "src/preview") } },
|
|
177
|
+
build: { outDir: resolve(workspaceCwd, config.outputDir) },
|
|
178
|
+
server: {
|
|
179
|
+
port: 3e3,
|
|
180
|
+
open: true
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async function runViteBuild() {
|
|
185
|
+
try {
|
|
186
|
+
console.log("📦 Building Slidev Workspace for production...");
|
|
187
|
+
const config = createViteConfig();
|
|
188
|
+
await build(config);
|
|
189
|
+
console.log("✅ Build completed successfully!");
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error("❌ Build failed:", error);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function runVitePreview() {
|
|
196
|
+
try {
|
|
197
|
+
console.log("🚀 Starting Slidev Workspace development server...");
|
|
198
|
+
const config = createViteConfig();
|
|
199
|
+
const server = await createServer(config);
|
|
200
|
+
await server.listen();
|
|
201
|
+
server.printUrls();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error("❌ Development server failed:", error);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
12
207
|
function showHelp() {
|
|
13
208
|
console.log(`
|
|
14
209
|
Slidev Workspace - A tool for managing multiple Slidev presentations
|
|
@@ -28,42 +223,32 @@ Examples:
|
|
|
28
223
|
For more information, visit: https://github.com/author/slidev-workspace
|
|
29
224
|
`);
|
|
30
225
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
console.log("📦 Building Slidev Workspace for production...");
|
|
53
|
-
process.env.SLIDEV_WORKSPACE_CWD = process.cwd();
|
|
54
|
-
runCommand("pnpm", ["run", "slidev-workspace:build"]);
|
|
55
|
-
break;
|
|
56
|
-
case "help":
|
|
57
|
-
case "--help":
|
|
58
|
-
case "-h":
|
|
59
|
-
showHelp();
|
|
60
|
-
break;
|
|
61
|
-
default: if (!command) showHelp();
|
|
62
|
-
else {
|
|
63
|
-
console.error(`Unknown command: ${command}`);
|
|
64
|
-
console.error("Run \"slidev-workspace help\" for available commands.");
|
|
65
|
-
process.exit(1);
|
|
226
|
+
async function main() {
|
|
227
|
+
switch (command) {
|
|
228
|
+
case "preview":
|
|
229
|
+
process.env.SLIDEV_WORKSPACE_CWD = process.cwd();
|
|
230
|
+
await runVitePreview();
|
|
231
|
+
break;
|
|
232
|
+
case "build":
|
|
233
|
+
process.env.SLIDEV_WORKSPACE_CWD = process.cwd();
|
|
234
|
+
await runViteBuild();
|
|
235
|
+
break;
|
|
236
|
+
case "help":
|
|
237
|
+
case "--help":
|
|
238
|
+
case "-h":
|
|
239
|
+
showHelp();
|
|
240
|
+
break;
|
|
241
|
+
default: if (!command) showHelp();
|
|
242
|
+
else {
|
|
243
|
+
console.error(`Unknown command: ${command}`);
|
|
244
|
+
console.error("Run \"slidev-workspace help\" for available commands.");
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
66
247
|
}
|
|
67
248
|
}
|
|
249
|
+
main().catch((error) => {
|
|
250
|
+
console.error("❌ An error occurred:", error);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
});
|
|
68
253
|
|
|
69
254
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ interface SlideData$1 {
|
|
|
83
83
|
declare function useSlides(): {
|
|
84
84
|
slides: vue0.ComputedRef<SlideData$1[]>;
|
|
85
85
|
slidesCount: vue0.ComputedRef<number>;
|
|
86
|
+
loadSlidesData: () => Promise<void>;
|
|
86
87
|
};
|
|
87
88
|
//#endregion
|
|
88
89
|
export { type SlideData, type SlideFrontmatter, type SlideInfo, type SlidevWorkspaceConfig, getAllSlidesFrontmatter, getSlideFrontmatter, getSlideFrontmatterByPath, loadConfig, resolveSlidesDirs, slidesPlugin, useSlides };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, watch } from "fs";
|
|
2
2
|
import { basename, join, resolve } from "path";
|
|
3
3
|
import { parse } from "yaml";
|
|
4
|
-
import { computed } from "vue";
|
|
4
|
+
import { computed, ref } from "vue";
|
|
5
5
|
|
|
6
6
|
//#region src/scripts/config.ts
|
|
7
7
|
const DEFAULT_CONFIG = {
|
|
8
8
|
slidesDir: ["./slides"],
|
|
9
|
-
outputDir: "./
|
|
9
|
+
outputDir: "./dist",
|
|
10
10
|
baseUrl: "/",
|
|
11
11
|
exclude: ["node_modules", ".git"]
|
|
12
12
|
};
|
|
@@ -154,17 +154,23 @@ export default slidesData;`;
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region slidev:content
|
|
159
|
-
const slidesData = [];
|
|
160
|
-
var slidev_content_default = slidesData;
|
|
161
|
-
|
|
162
157
|
//#endregion
|
|
163
158
|
//#region src/preview/composables/useSlides.ts
|
|
164
159
|
function useSlides() {
|
|
160
|
+
const slidesData = ref([]);
|
|
161
|
+
const loadSlidesData = async () => {
|
|
162
|
+
try {
|
|
163
|
+
const module = await import("slidev:content");
|
|
164
|
+
slidesData.value = module.default || module.slidesData || [];
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.warn("Failed to load slides data:", error);
|
|
167
|
+
slidesData.value = [];
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
loadSlidesData();
|
|
165
171
|
const slides = computed(() => {
|
|
166
|
-
if (!
|
|
167
|
-
return
|
|
172
|
+
if (!slidesData.value || slidesData.value.length === 0) return [];
|
|
173
|
+
return slidesData.value.map((slide) => ({
|
|
168
174
|
title: slide.frontmatter.title || slide.path,
|
|
169
175
|
url: slide.path,
|
|
170
176
|
description: slide.frontmatter.info || slide.frontmatter.seoMeta?.ogDescription || "No description available",
|
|
@@ -179,7 +185,8 @@ function useSlides() {
|
|
|
179
185
|
const slidesCount = computed(() => slides.value.length);
|
|
180
186
|
return {
|
|
181
187
|
slides,
|
|
182
|
-
slidesCount
|
|
188
|
+
slidesCount,
|
|
189
|
+
loadSlidesData
|
|
183
190
|
};
|
|
184
191
|
}
|
|
185
192
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slidev-workspace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A workspace tool for managing multiple Slidev presentations with API-based content management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"tailwind-merge": "^3.3.1",
|
|
43
43
|
"tw-animate-css": "^1.3.5",
|
|
44
44
|
"vite": "npm:rolldown-vite@latest",
|
|
45
|
-
"vue": "^3.5.17"
|
|
45
|
+
"vue": "^3.5.17",
|
|
46
|
+
"@tailwindcss/vite": "^4.1.11"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"tsdown": "^0.11.9",
|
|
49
50
|
"typescript": "^5.8.3",
|
|
50
51
|
"vitest": "^3.1.3",
|
|
51
52
|
"vue-tsc": "^3.0.3",
|
|
52
|
-
"@tailwindcss/vite": "^4.1.11",
|
|
53
53
|
"@tsconfig/node22": "^22.0.2",
|
|
54
54
|
"@types/node": "^22.15.32",
|
|
55
55
|
"@vue/eslint-config-prettier": "^10.2.0",
|
|
@@ -71,8 +71,6 @@
|
|
|
71
71
|
"build": "tsdown",
|
|
72
72
|
"dev": "pnpm run dev",
|
|
73
73
|
"dev:watch": "tsdown --watch",
|
|
74
|
-
"slidev-workspace:preview": "vite",
|
|
75
|
-
"slidev-workspace:build": "vite build --config vite.config.ts",
|
|
76
74
|
"test": "vitest",
|
|
77
75
|
"typecheck": "vue-tsc --noEmit",
|
|
78
76
|
"lint": "eslint . --fix",
|