blob: ead3ff50cf61a79dbda762d69180afe6104c91c5 [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001// Package main provides a minimal command-line tool for generating bundle metafiles for analysis
2// with the esbuild analyzer at https://esbuild.github.io/analyze/
3package main
4
5import (
6 "flag"
7 "fmt"
8 "os"
9 "path/filepath"
10
11 "sketch.dev/loop/webui"
12)
13
14func main() {
15 // Use a temporary directory for output by default
16 tmp, err := os.MkdirTemp("", "bundle-analysis-")
17 if err != nil {
18 fmt.Fprintf(os.Stderr, "Error creating temp directory: %v\n", err)
19 os.Exit(1)
20 }
21
22 // Parse command line flags
23 outputDir := flag.String("output", tmp, "Directory where the bundle metafiles should be written")
24 flag.Parse()
25
26 // Ensure the output directory exists
27 if err := os.MkdirAll(*outputDir, 0755); err != nil {
28 fmt.Fprintf(os.Stderr, "Error creating output directory: %v\n", err)
29 os.Exit(1)
30 }
31
32 // Get absolute path for better user feedback
33 absOutDir, err := filepath.Abs(*outputDir)
34 if err != nil {
35 fmt.Fprintf(os.Stderr, "Error getting absolute path: %v\n", err)
36 os.Exit(1)
37 }
38
39 fmt.Println("Generating bundle metafiles...")
40
41 // Generate the metafiles
42 _, err = webui.GenerateBundleMetafile(*outputDir)
43 if err != nil {
44 fmt.Fprintf(os.Stderr, "Error generating metafiles: %v\n", err)
45 os.Exit(1)
46 }
47
48 // Print the simple usage instructions
49 fmt.Printf("\nBundle metafiles generated at: %s\n\n", absOutDir)
50 fmt.Println("To analyze bundles:")
51 fmt.Println("1. Go to https://esbuild.github.io/analyze/")
52 fmt.Println("2. Drag and drop the generated metafiles onto the analyzer")
53 fmt.Printf(" - %s/timeline.meta.json\n", absOutDir)
54 fmt.Printf(" - %s/sketch-app-shell.meta.json\n", absOutDir)
55}