Initialize project structure by creating necessary directories, default config file, and removing obsolete HTML components
This commit is contained in:
34
cmd/init.go
34
cmd/init.go
@ -36,15 +36,41 @@ var initCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("init called")
|
||||
|
||||
// Create the directories and files needed for the member-console web application in the
|
||||
// Create the directories and files needed for the member-console web application
|
||||
targetDir := args[0]
|
||||
componentsDir := filepath.Join(targetDir, "components")
|
||||
|
||||
if err := os.MkdirAll(componentsDir, 0755); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating components directory: %v\n", err)
|
||||
// Create the target directory if it doesn't exist
|
||||
if err := os.MkdirAll(targetDir, 0755); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating target directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create the templates, static, and assets directories
|
||||
directories := []string{"templates", "static", "assets"}
|
||||
for _, dir := range directories {
|
||||
dirPath := filepath.Join(targetDir, dir)
|
||||
if err := os.MkdirAll(dirPath, 0755); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating %s directory: %v\n", dir, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Create the config.yaml file
|
||||
configFilePath := filepath.Join(targetDir, "mc-config.yaml")
|
||||
configFile, err := os.Create(configFilePath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating config file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer configFile.Close()
|
||||
// Write default config to the config file
|
||||
defaultConfig := "# Default configuration for member-console\n"
|
||||
if _, err := configFile.WriteString(defaultConfig); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error writing to config file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Created config file at %s\n", configFilePath)
|
||||
|
||||
fmt.Printf("Project initialized at %s\n", targetDir)
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user