alpha p7
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -10,8 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func getName() string {
|
||||
out, err := exec.Command("git", "config", "user.name").Output()
|
||||
if err == nil {
|
||||
out, err := exec.Command("git", "config", "user.name").Output(); if err == nil {
|
||||
s := strings.TrimSpace(string(out))
|
||||
if s != "" {
|
||||
return s
|
||||
@@ -24,36 +22,71 @@ func getName() string {
|
||||
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 := fmt.Sprintf(`local fes = require("fes")
|
||||
// local site = fes.fes()
|
||||
//
|
||||
// site.title = "%s"
|
||||
//
|
||||
// site:h1("Hello, World!")
|
||||
//
|
||||
// return site
|
||||
// `, dir)
|
||||
// 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
|
||||
// }
|
||||
|
||||
func write(path string, format string, args ...interface{}) error {
|
||||
dir := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = fmt.Fprintf(f, format, args...)
|
||||
return err
|
||||
}
|
||||
|
||||
func Project(dir string) error {
|
||||
if err := os.MkdirAll(filepath.Join(dir, "www"), 0755); err != nil {
|
||||
if err := os.Mkdir(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
indexLua := filepath.Join(dir, "www", "index.lua")
|
||||
if _, err := os.Stat(indexLua); os.IsNotExist(err) {
|
||||
content := fmt.Sprintf(`local fes = require("fes")
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
write("www/index.lua", `local fes = require("fes")
|
||||
local site = fes.fes()
|
||||
|
||||
site.title = "%s"
|
||||
|
||||
site:h1("Hello, World!")
|
||||
|
||||
return site
|
||||
`, dir)
|
||||
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]
|
||||
return site`)
|
||||
write("Fes.toml", `[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