2019-01-01 19:41:03 +01:00
|
|
|
package initer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2023-03-05 14:04:02 +01:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-01-08 21:26:47 +01:00
|
|
|
finstr "git.gutmet.org/finstr.git/initer"
|
2020-10-11 13:35:13 +02:00
|
|
|
goutil "git.gutmet.org/goutil.git/misc"
|
2019-01-01 19:41:03 +01:00
|
|
|
"git.gutmet.org/wombat.git/gallery"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
initflag = ".wombat"
|
|
|
|
)
|
|
|
|
|
2023-03-05 14:04:02 +01:00
|
|
|
var checkpaths []string = []string{initflag, "stage0", "template", "style.css", "script.js"}
|
2019-01-01 19:41:03 +01:00
|
|
|
|
2023-03-05 14:04:02 +01:00
|
|
|
func dumpInitFiles() error {
|
|
|
|
err := goutil.WriteFile("template", defaultTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-01-01 19:41:03 +01:00
|
|
|
}
|
2023-03-05 14:04:02 +01:00
|
|
|
err = goutil.WriteFile("rssTemplate", defaultRSSTemplate)
|
2019-01-01 19:41:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-05 14:04:02 +01:00
|
|
|
err = goutil.WriteFile("style.css", defaultStyle)
|
2020-10-29 12:01:30 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-05 14:04:02 +01:00
|
|
|
err = goutil.WriteFile("script.js", defaultScript)
|
2019-01-01 19:41:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = goutil.WriteFile(filepath.Join("stage0", "index.md"), defaultIndex)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-08 21:26:47 +01:00
|
|
|
return gallery.New(finstr.IniterFlags{})
|
2019-01-01 19:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func isInitialized() bool {
|
|
|
|
for _, path := range checkpaths {
|
|
|
|
if !goutil.PathExists(path) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-03-05 14:04:02 +01:00
|
|
|
func initialize() error {
|
2019-01-01 19:41:03 +01:00
|
|
|
var err error
|
|
|
|
if !isInitialized() {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Initializing " + dir)
|
|
|
|
err = goutil.WriteFile(initflag, "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = os.Mkdir("stage0", 0755)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-28 21:52:50 +02:00
|
|
|
err = os.Mkdir("stage0/blog", 0755)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-05 14:04:02 +01:00
|
|
|
err = dumpInitFiles()
|
2019-01-01 19:41:03 +01:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitializedOrDie() {
|
|
|
|
if !isInitialized() {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err == nil {
|
|
|
|
err = errors.New(dir + " is not an initialized wombat directory")
|
|
|
|
}
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type initializeFlags struct {
|
|
|
|
style string
|
|
|
|
}
|
|
|
|
|
|
|
|
func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) {
|
|
|
|
flagsInit := func(s *flag.FlagSet) {
|
|
|
|
}
|
|
|
|
return flagsInit, func([]string) error {
|
2023-03-05 14:04:02 +01:00
|
|
|
return initialize()
|
2019-01-01 19:41:03 +01:00
|
|
|
}
|
|
|
|
}
|