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 smallweb init command

pomdtr 4a9d0e01 1265febd

+84 -1
+7
cmd/embed/workspace/vscode/main.ts
··· 1 + import { VSCode } from "jsr:@smallweb/vscode@0.1.7" 2 + 3 + const vscode = new VSCode({ 4 + rootDir: Deno.env.get("SMALLWEB_DIR") 5 + }); 6 + 7 + export default vscode;
+3
cmd/embed/workspace/www/index.md
··· 1 + # Welcome to Smallweb! 2 + 3 + This is a simple markdown file served by Smallweb.
+72
cmd/init.go
··· 1 + package cmd 2 + 3 + import ( 4 + "embed" 5 + "encoding/json" 6 + "fmt" 7 + "io/fs" 8 + "os" 9 + "path" 10 + 11 + "github.com/google/uuid" 12 + "github.com/joho/godotenv" 13 + "github.com/spf13/cobra" 14 + ) 15 + 16 + //go:embed embed/workspace 17 + var embedFS embed.FS 18 + 19 + func NewCmdInit() *cobra.Command { 20 + cmd := &cobra.Command{ 21 + Use: "init <domain>", 22 + Short: "Initialize a new workspace", 23 + Args: cobra.ExactArgs(1), 24 + RunE: func(cmd *cobra.Command, args []string) error { 25 + workspaceFS, err := fs.Sub(embedFS, "embed/workspace") 26 + if err != nil { 27 + return fmt.Errorf("failed to read workspace embed: %w", err) 28 + } 29 + 30 + workspaceDir := k.String("dir") 31 + if _, err := fs.Stat(workspaceFS, workspaceDir); err == nil { 32 + return fmt.Errorf("directory %s already exists", workspaceDir) 33 + } 34 + 35 + if err := os.CopyFS(workspaceDir, workspaceFS); err != nil { 36 + return fmt.Errorf("failed to copy workspace embed: %w", err) 37 + } 38 + 39 + configPath := path.Join(workspaceDir, ".smallweb", "config.json") 40 + if err := os.MkdirAll(path.Dir(configPath), 0755); err != nil { 41 + return fmt.Errorf("failed to create config directory: %w", err) 42 + } 43 + 44 + configFile, err := os.Create(configPath) 45 + if err != nil { 46 + return fmt.Errorf("failed to create config file: %w", err) 47 + } 48 + 49 + encoder := json.NewEncoder(configFile) 50 + encoder.SetIndent("", " ") 51 + if err := encoder.Encode(map[string]interface{}{ 52 + "domain": args[0], 53 + "adminApps": []string{ 54 + "vscode", 55 + }, 56 + }); err != nil { 57 + return fmt.Errorf("failed to write config file: %w", err) 58 + } 59 + 60 + if err := godotenv.Write(map[string]string{ 61 + "VSCODE_TOKEN": uuid.NewString(), 62 + }, path.Join(workspaceDir, "vscode", ".env")); err != nil { 63 + return fmt.Errorf("failed to write .env file: %w", err) 64 + } 65 + 66 + fmt.Fprintf(os.Stderr, "Workspace initialized at %s\n", workspaceDir) 67 + return nil 68 + }, 69 + } 70 + 71 + return cmd 72 + }
+1
cmd/root.go
··· 156 156 rootCmd.AddCommand(NewCmdList()) 157 157 rootCmd.AddCommand(NewCmdFetch()) 158 158 rootCmd.AddCommand(NewCmdCrons()) 159 + rootCmd.AddCommand(NewCmdInit()) 159 160 rootCmd.AddCommand(NewCmdInstall()) 160 161 rootCmd.AddCommand(NewCmdLogs()) 161 162 rootCmd.AddCommand(NewCmdSync())
+1 -1
worker/worker.go
··· 58 58 59 59 cli := fmt.Sprintf(`#!/bin/sh 60 60 61 - SMALLWEB_DISABLE_PLUGINS=1 SMALLWEB_DISABLED_COMMANDS=upgrade,up,service,sync,secrets,doctor,open,completion exec %s "$@" 61 + SMALLWEB_DISABLE_PLUGINS=1 SMALLWEB_DISABLED_COMMANDS=upgrade,up,service,sync,secrets,doctor,open,completion,init exec %s "$@" 62 62 `, executable) 63 63 64 64 cliPath = filepath.Join(xdg.CacheHome, "smallweb", "cli", hash([]byte(cli)))