alpha p1
This commit is contained in:
57
src/new/new.go
Normal file
57
src/new/new.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getName() string {
|
||||
out, err := exec.Command("git", "config", "user.name").Output()
|
||||
if err == nil {
|
||||
s := strings.TrimSpace(string(out))
|
||||
if s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
u, err := user.Current()
|
||||
if err == nil && u.Username != "" {
|
||||
return u.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Project(dir string) error {
|
||||
if err := os.MkdirAll(filepath.Join(dir, "www"), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
indexLua := filepath.Join(dir, "www", "index.lua")
|
||||
if _, err := os.Stat(indexLua); os.IsNotExist(err) {
|
||||
content := `local fes = require("fes")
|
||||
local site = fes.fes()
|
||||
|
||||
site:h1("Hello, World!")
|
||||
|
||||
return site
|
||||
`
|
||||
if err := os.WriteFile(indexLua, []byte(content), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
indexFes := filepath.Join(dir, "Fes.toml")
|
||||
if _, err := os.Stat(indexFes); os.IsNotExist(err) {
|
||||
content := fmt.Sprintf(`[app]
|
||||
|
||||
name = "%s"
|
||||
version = "0.0.1"
|
||||
authors = ["%s"]`, dir, getName())
|
||||
if err := os.WriteFile(indexFes, []byte(content), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Println("Created new project at", dir)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user