package lib import ( "fmt" "log" "os" "path/filepath" "git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ" "git.ymnuktech.ru/ymnuk/yt-gen-app/structs" ) func generateFrontendAngularTmpl() { if Project.Frontend.Lang == "angular" { dirs := []string{ filepath.Join(AppConfig.OutdirFrontend, ".vscode"), filepath.Join(AppConfig.OutdirFrontend, "src", "assets"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "guard"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "module", "primeng"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "service"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "interfaces"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "template", "main"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "login"), filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user-form"), } if len(dirs) > 0 { for _, dir := range dirs { if err := os.MkdirAll(dir, 0775); err != nil { log.Fatal(err) } } } } staticTmpls := []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/vscode/extensions.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, ".vscode", "extensions.json"), }, { FileIn: "tmpl/frontend/angular/vscode/launch.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, ".vscode", "launch.json"), }, { FileIn: "tmpl/frontend/angular/vscode/tasks.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, ".vscode", "tasks.json"), }, { FileIn: "tmpl/frontend/angular/src/app/module/primeng/primeng.module.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "module", "primeng", "primeng.module.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/guard/auth.guard.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "guard", "auth.guard.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/service/notify.service.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "service", "notify.service.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/service/token-interceptor.service.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "service", "token-interceptor.service.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/template/main/main.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "template", "main", "main.component.scss"), }, { FileIn: "tmpl/frontend/angular/src/app/page/login/login.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "login", "login.component.html"), }, { FileIn: "tmpl/frontend/angular/src/app/page/login/login.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "login", "login.component.scss"), }, { FileIn: "tmpl/frontend/angular/src/app/app.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app.component.html"), }, { FileIn: "tmpl/frontend/angular/src/app/app.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app.component.scss"), }, { FileIn: "tmpl/frontend/angular/src/app/app.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app.component.ts"), }, { FileIn: "tmpl/frontend/angular/src/assets/gitkeep.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "assets", ".gitkeep"), }, { FileIn: "tmpl/frontend/angular/src/favicon.ico.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "favicon.ico"), }, { FileIn: "tmpl/frontend/angular/src/index.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "index.html"), }, { FileIn: "tmpl/frontend/angular/src/main.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "main.ts"), }, { FileIn: "tmpl/frontend/angular/src/styles.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "styles.scss"), }, { FileIn: "tmpl/frontend/angular/editorconfig.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, ".editorconfig"), }, { FileIn: "tmpl/frontend/angular/gitignore.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, ".gitignore"), }, { FileIn: "tmpl/frontend/angular/README.md.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "README.md"), }, { FileIn: "tmpl/frontend/angular/proxy.conf.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "proxy.conf.json"), }, { FileIn: "tmpl/frontend/angular/tsconfig.app.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "tsconfig.app.json"), }, { FileIn: "tmpl/frontend/angular/tsconfig.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "tsconfig.json"), }, { FileIn: "tmpl/frontend/angular/tsconfig.spec.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "tsconfig.spec.json"), }, { FileIn: "tmpl/frontend/angular/options.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "options.json"), }, { FileIn: "tmpl/frontend/swagger-codegen-cli-2.4.32.jar", FileOut: filepath.Join(AppConfig.OutdirFrontend, "swagger-codegen-cli-2.4.32.jar"), }, } templ.PrepareTmplFile("tmpl/frontend/angular/src/app/app.module.ts.tmpl", Project, filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app.module.ts")) if len(staticTmpls) > 0 { for _, staticTmpl := range staticTmpls { if err := templ.WriteTmplFile(staticTmpl.FileIn, staticTmpl.FileOut); err != nil { log.Fatal(err) } } } staticTmpls = []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/src/app/page/user/user-form/user-form.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user-form", "user-form.component.html"), }, { FileIn: "tmpl/frontend/angular/src/app/page/user/user-form/user-form.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user-form", "user-form.component.scss"), }, { FileIn: "tmpl/frontend/angular/src/app/page/user/user-form/user-form.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user-form", "user-form.component.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/page/user/user.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user.component.html"), }, { FileIn: "tmpl/frontend/angular/src/app/page/user/user.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user.component.scss"), }, { FileIn: "tmpl/frontend/angular/src/app/page/user/user.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "user", "user.component.ts"), }, { FileIn: "tmpl/frontend/angular/package-lock.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "package-lock.json"), }, { FileIn: "tmpl/frontend/angular/package.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "package.json"), }, { FileIn: "tmpl/frontend/angular/angular.json.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "angular.json"), }, { FileIn: "tmpl/frontend/angular/src/app/module/other/other.module.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "module", "other", "other.module.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/template/main/main.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "template", "main", "main.component.ts"), }, } for _, item := range staticTmpls { if err := templ.PrepareTmplIsNotExists(item.FileIn, Project, item.FileOut); err != nil { log.Fatal(err) } } templs := []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/src/app/app-routing.module.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app-routing.module.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/template/main/main.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "template", "main", "main.component.html"), }, { FileIn: "tmpl/frontend/angular/src/app/service/auth.service.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "service", "auth.service.ts"), }, { FileIn: "tmpl/frontend/angular/src/app/page/login/login.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", "login", "login.component.ts"), }, } for _, staticTmpls := range templs { err := templ.PrepareTmplFile(staticTmpls.FileIn, Project, staticTmpls.FileOut) if err != nil { log.Fatal(err) } } // Сервис аутентификации /*err := templ.PrepareTmplFile("tmpl/frontend/angular/src/app/service/auth.service.ts.tmpl", Project, filepath.Join(AppConfig.OutdirFrontend, "src", "app", "service", "auth.service.ts")) if err != nil { log.Fatal(err) }*/ /*templs = []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/src/app/page/page.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "app-routing.module.ts"), }, }*/ for i, rest := range Project.Backend.Rest { restStruct := structs.RestStruct{ Path: i, Project: Project, Rest: rest, } templs := []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/src/app/page/page/page.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), fmt.Sprintf("%s.component.ts", templ.AngularFilename(i))), }, { FileIn: "tmpl/frontend/angular/src/app/page/page/page.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), fmt.Sprintf("%s.component.scss", templ.AngularFilename(i))), }, { FileIn: "tmpl/frontend/angular/src/app/page/page/page.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), fmt.Sprintf("%s.component.html", templ.AngularFilename(i))), }, } for _, item := range templs { if err := templ.PrepareTmplIsNotExists(item.FileIn, restStruct, item.FileOut); err != nil { log.Fatal(err) } } if rest.Editable { templs := []structs.TmplInOut{ { FileIn: "tmpl/frontend/angular/src/app/page/page/form/form.component.ts.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), "form", fmt.Sprintf("%s-form.component.ts", templ.AngularFilename(i))), }, { FileIn: "tmpl/frontend/angular/src/app/page/page/form/form.component.scss.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), "form", fmt.Sprintf("%s-form.component.scss", templ.AngularFilename(i))), }, { FileIn: "tmpl/frontend/angular/src/app/page/page/form/form.component.html.tmpl", FileOut: filepath.Join(AppConfig.OutdirFrontend, "src", "app", "page", templ.BackendFsPath(templ.RemoveFirstChar(i)), "form", fmt.Sprintf("%s-form.component.html", templ.AngularFilename(i))), }, } for _, item := range templs { if err := templ.PrepareTmplIsNotExists(item.FileIn, restStruct, item.FileOut); err != nil { log.Fatal(err) } } } } }