MCPcopy Create free account
hub / github.com/driangle/taskmd / ExportWithFS

Function ExportWithFS

apps/cli/internal/web/export.go:38–92  ·  view source on GitHub ↗

ExportWithFS generates a static site using the provided embedded filesystem. This is separated from Export to allow tests to inject a mock FS.

(cfg ExportConfig, embeddedFS fs.FS)

Source from the content-addressed store, hash-verified

36// ExportWithFS generates a static site using the provided embedded filesystem.
37// This is separated from Export to allow tests to inject a mock FS.
38func ExportWithFS(cfg ExportConfig, embeddedFS fs.FS) error {
39 // Validate embedded assets
40 staticFS, err := fs.Sub(embeddedFS, "static/dist")
41 if err != nil {
42 return fmt.Errorf("no embedded web assets: rebuild with `make build-full`")
43 }
44 indexHTML, err := fs.ReadFile(staticFS, "index.html")
45 if err != nil {
46 return fmt.Errorf("no embedded web assets: rebuild with `make build-full`")
47 }
48
49 // Clean/create output directory
50 if err := os.RemoveAll(cfg.OutputDir); err != nil {
51 return fmt.Errorf("failed to clean output directory: %w", err)
52 }
53 if err := os.MkdirAll(cfg.OutputDir, 0755); err != nil {
54 return fmt.Errorf("failed to create output directory: %w", err)
55 }
56
57 // Scan tasks
58 dp := NewDataProvider(cfg.ScanDir, cfg.Verbose)
59 tasks, err := dp.GetTasks()
60 if err != nil {
61 return fmt.Errorf("failed to scan tasks: %w", err)
62 }
63
64 archivedTasks, err := dp.GetArchivedTasks()
65 if err != nil {
66 return fmt.Errorf("failed to scan archived tasks: %w", err)
67 }
68
69 // Generate static JSON data files
70 if err := generateDataFiles(cfg, tasks, archivedTasks); err != nil {
71 return err
72 }
73
74 // Copy static assets (everything except index.html)
75 if err := copyStaticAssets(staticFS, cfg.OutputDir); err != nil {
76 return err
77 }
78
79 // Patch and write index.html
80 patched := patchIndexHTML(string(indexHTML), cfg.BasePath)
81 if err := os.WriteFile(filepath.Join(cfg.OutputDir, "index.html"), []byte(patched), 0644); err != nil {
82 return fmt.Errorf("failed to write index.html: %w", err)
83 }
84
85 // Generate SPA route fallback files
86 if err := generateSPAFallbacks(cfg.OutputDir, patched, tasks); err != nil {
87 return err
88 }
89
90 fmt.Printf("Exported static site to %s\n", cfg.OutputDir)
91 return nil
92}
93
94func generateDataFiles(cfg ExportConfig, tasks []*model.Task, archivedTasks []*model.Task) error {
95 apiDir := filepath.Join(cfg.OutputDir, "api")

Callers 4

ExportFunction · 0.85
exportWithMockFSFunction · 0.85

Calls 7

GetTasksMethod · 0.95
GetArchivedTasksMethod · 0.95
NewDataProviderFunction · 0.85
generateDataFilesFunction · 0.85
copyStaticAssetsFunction · 0.85
patchIndexHTMLFunction · 0.85
generateSPAFallbacksFunction · 0.85

Tested by 3

exportWithMockFSFunction · 0.68