this repo has no description smallweb.run
smallweb
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

add a new create command

pomdtr c857a62c c3cdc06c

+54
+53
cmd/create.go
··· 1 + package cmd 2 + 3 + import ( 4 + "fmt" 5 + "os" 6 + "path/filepath" 7 + 8 + "github.com/spf13/cobra" 9 + ) 10 + 11 + var appCode = `export default { 12 + fetch: (_req: Request) => { 13 + return new Response("Welcome to Smallweb!"); 14 + }, 15 + run: (_args: string[]) => { 16 + console.log("Welcome to Smallweb!"); 17 + }, 18 + }; 19 + ` 20 + 21 + func NewCmdCreate() *cobra.Command { 22 + cmd := &cobra.Command{ 23 + Use: "create <app>", 24 + Short: "Create a new app", 25 + Args: cobra.ExactArgs(1), 26 + RunE: func(cmd *cobra.Command, args []string) error { 27 + dir := k.String("dir") 28 + appDir := filepath.Join(dir, args[0]) 29 + if _, err := os.Stat(appDir); err == nil { 30 + cmd.PrintErrf("Directory %s already exists\n", appDir) 31 + return ErrSilent 32 + } 33 + 34 + if err := os.MkdirAll(appDir, 0755); err != nil { 35 + cmd.PrintErrf("Failed to create directory %s: %v\n", appDir, err) 36 + return ErrSilent 37 + } 38 + 39 + if err := os.WriteFile(filepath.Join(appDir, "main.ts"), []byte(appCode), 0644); err != nil { 40 + cmd.PrintErrf("Failed to create main.ts: %v\n", err) 41 + return ErrSilent 42 + } 43 + 44 + appDomain := fmt.Sprintf("%s.%s", args[0], k.String("domain")) 45 + 46 + cmd.PrintErrf("App Directory: %s\n", appDir) 47 + cmd.PrintErrf("App URL: https://%s\n/", appDomain) 48 + return nil 49 + }, 50 + } 51 + 52 + return cmd 53 + }
+1
cmd/root.go
··· 139 139 rootCmd.PersistentFlags().String("domain", "", "The domain for smallweb") 140 140 141 141 rootCmd.AddCommand(NewCmdRun()) 142 + rootCmd.AddCommand(NewCmdCreate()) 142 143 rootCmd.AddCommand(NewCmdOpen()) 143 144 rootCmd.AddCommand(NewCmdDocs()) 144 145 rootCmd.AddCommand(NewCmdUp())