diff --git a/app/gitignore-gen/src/templates/loader.rs b/app/gitignore-gen/src/templates/loader.rs new file mode 100644 index 0000000..49fc93a --- /dev/null +++ b/app/gitignore-gen/src/templates/loader.rs @@ -0,0 +1,1638 @@ +use crate::core::error::AppError; +use crate::templates::{Category, Template, TemplateCollection, TemplateSet}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::fs::{self, File}; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; + +pub struct TemplateLoader { + base_path: PathBuf, + embedded_templates: HashMap<&'static str, &'static str>, + template_cache: Option, +} + +impl TemplateLoader { + pub fn new(base_path: Option) -> Self { + let mut loader = Self { + base_path: base_path.unwrap_or_else(|| PathBuf::from("resources/templates")), + embedded_templates: HashMap::new(), + template_cache: None, + }; + loader.init_embedded_templates(); + loader + } + + fn init_embedded_templates(&mut self) { + self.embedded_templates.insert( + "rust", + r#"# Generated by gitignore-gen + +# Build results +/target +**/target/ +Cargo.lock + +# IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ +.DS_Store + +# IDE - CLion +/.idea/ +cmake-build-*/ + +# IDE - VSCode +.vscode/ + +# IDE - IntelliJ +*.iml +*.ipr +*.iws +.idea/ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +# Editor +*.orig +*.rej +*.bak +*~ + +# Testing +coverage/ + +# Misc +*.pem +.env +.env.local +.env.*.local +"#, + ); + + self.embedded_templates.insert( + "python", + r#"# Generated by gitignore-gen + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.json + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +Pipfile.lock + +# poetry +poetry.lock + +# pdm +.pdm.toml + +# PEP 582 +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs docs +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "javascript", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ +jspm_packages/ + +# Build outputs +dist/ +build/ +*.local + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage/ +*.lcov +.nyc_output/ + +# nyc test coverage +.nyc_output/ + +# Grunt intermediate storage +.grunt + +# Bower dependency directory +bower_components/ + +# node-waf configuration +.lock-wscript + +# Compiled binary addons +*.node + +# Debug logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Dependency directories +node_modules/ +jspm_packages/ + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "typescript", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ + +# Build outputs +dist/ +build/ +*.local + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage/ +*.lcov +.nyc_output/ + +# Compiled output +*.tsbuildinfo + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "go", + r#"# Generated by gitignore-gen + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary (built with go test -c) +*.test + +# Output of go coverage tool +*.out + +# Go workspace file +go.work + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "java", + r#"# Generated by gitignore-gen + +# Compiled class files +*.class + +# Log files +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +# Gradle +.gradle/ +build/ +!gradle-wrapper.jar + +# IDE +.idea/ +*.iml +*.ipr +*.iws +.project +.classpath +.settings/ +.vscode/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "nodejs", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ +jspm_packages/ + +# Build outputs +dist/ +build/ +*.local + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory +coverage/ +.nyc_output/ + +# Grunt +.grunt/ + +# Bower +bower_components/ + +# dotenv +.env +.env.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "ruby", + r#"# Generated by gitignore-gen + +/.bundle +/vendor/bundle/ +/.yardoc +/Yardoc.db +/doc/ +/rdoc/ +/.bundle/ +/vendor/bundle/ +/.rspec +/coverage/ + +# RVM and RBenv +.rvmrc +.rbenv-vars +.ruby-version +.ruby-gemset + +# Gemfiles +Gemfile +Gemfile.lock + +# Bundler +vendor/bundle/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "php", + r#"# Generated by gitignore-gen + +/vendor/ +composer.lock +.env +.env.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "csharp", + r#"# Generated by gitignore-gen + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +.vs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ + +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test Files +*_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Openshift files +*.orig +*.rej + +# Sublime Text files +*~ +"#, + ); + + self.embedded_templates.insert( + "cpp", + r#"# Generated by gitignore-gen + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "swift", + r#"# Generated by gitignore-gen + +# Xcode +*.xcodeproj/ +!*.xcodeproj/project.pbxproj +*.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +*.xcuserstate +*.xcscmblueprint +*.xcscheme + +# Build +build/ +DerivedData/ + +# Swift Package Manager +.build/ +.swiftpm/ + +# Carthage +Carthage/Build/ +Carthage/Checkouts/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "kotlin", + r#"# Generated by gitignore-gen + +# Compiled class files +*.class + +# Log files +*.log + +# Kotlin +*.kotlin/ + +# Gradle +.gradle/ +build/ + +# IDE +.idea/ +*.iml +*.ipr +*.iws +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "scala", + r#"# Generated by gitignore-gen + +# Compiled class files +*.class + +# Log files +*.log + +# Scala +*.scala_history +project/plugins/ +target/ +lib_managed/ +src_managed/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "dart", + r#"# Generated by gitignore-gen + +# Dart stuff +.dart_tool/ +.pub-cache/ +.pub/ +build/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "docker", + r#"# Generated by gitignore-gen + +# Docker +.docker/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "kubernetes", + r#"# Generated by gitignore-gen + +# Kubernetes +*.kubeconfig +/kube/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "terraform", + r#"# Generated by gitignore-gen + +# Terraform +*.tfstate +*.tfvars +.terraform/ +*.tfplan + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "django", + r#"# Generated by gitignore-gen + +# Python +__pycache__/ +*.py[cod] +*$py.class + +# Django +*.log +*.pot +*.pyc +db.json +local_settings.py + +# Media +media/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "rails", + r#"# Generated by gitignore-gen + +# Ruby +.bundle +vendor/bundle/ +/.ruby-version +.ruby-gemset + +# Rails +/log/* +/tmp/* +/vendor/bundle/* +/node_modules/ + +# Storage +/storage/* +/config/master.key + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "react", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ + +# Build +build/ +*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "vue", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ + +# Build +dist/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "angular", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ + +# Build +dist/ +*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "nextjs", + r#"# Generated by gitignore-gen + +# Dependencies +node_modules/ + +# Build +.next/ +out/ +build/ + +# Testing +coverage/ + +# Misc +*.pem +.env + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "flask", + r#"# Generated by gitignore-gen + +# Python +__pycache__/ +*.py[cod] +*$py.class + +# Flask +instance/ +.webassets-cache + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "laravel", + r#"# Generated by gitignore-gen + +# PHP +/vendor/ +node_modules/ + +# Laravel +/bootstrap/cache/* +/storage/* +.env +.env.local +.env.*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "vscode", + r#"# Generated by gitignore-gen + +# VSCode +.vscode/ +*.code-workspace + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "jetbrains", + r#"# Generated by gitignore-gen + +# JetBrains +*.iml +*.ipr +*.iws +.idea/ + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "eclipse", + r#"# Generated by gitignore-gen + +# Eclipse +*.pydevproject +.project +.metadata/ +*.launch + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "vim", + r#"# Generated by gitignore-gen + +# Vim +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "emacs", + r#"# Generated by gitignore-gen + +# Emacs +*~ +\#*\# +/.elpa/ + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "windows", + r#"# Generated by gitignore-gen + +# Windows +*.tmp +*.tmp.* +*.log +*.log.* +*.user +*.userosscache +*.suo + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "macos", + r#"# Generated by gitignore-gen + +# macOS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "linux", + r#"# Generated by gitignore-gen + +# Linux +*~ +core + +# IDE +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "mysql", + r#"# Generated by gitignore-gen + +# MySQL +*.sql +*.dump +*.mysqldump + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "postgresql", + r#"# Generated by gitignore-gen + +# PostgreSQL +*.sql +*.dump +*.psql + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "mongodb", + r#"# Generated by gitignore-gen + +# MongoDB +*.dump + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "redis", + r#"# Generated by gitignore-gen + +# Redis +*.rdb + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "cmake", + r#"# Generated by gitignore-gen + +# CMake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "maven", + r#"# Generated by gitignore-gen + +# Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.next +release.properties + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "gradle", + r#"# Generated by gitignore-gen + +# Gradle +.gradle/ +build/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "webpack", + r#"# Generated by gitignore-gen + +# Webpack +node_modules/ +dist/ +build/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "yarn", + r#"# Generated by gitignore-gen + +# Yarn +.yarn-cache/ +.yarn-integrity +node_modules/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "npm", + r#"# Generated by gitignore-gen + +# NPM +node_modules/ +*.log + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "poetry", + r#"# Generated by gitignore-gen + +# Poetry +poetry.lock + +# Python +__pycache__/ +.venv/ +venv/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "yarn", + r#"# Generated by gitignore-gen + +# Yarn +.yarn/ +.yarn-cache/ +.yarn-integrity +node_modules/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "bun", + r#"# Generated by gitignore-gen + +# Bun +bun.lockb +node_modules/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "deno", + r#"# Generated by gitignore-gen + +# Deno +.deno/ +deno.lock + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "elixir", + r#"# Generated by gitignore-gen + +# Elixir +/_build/ +/deps/ + +# Mix +mix.lock + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "clojure", + r#"# Generated by gitignore-gen + +# Clojure +/target +/classes +/checkouts +/profile.boot + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "haskell", + r#"# Generated by gitignore-gen + +# Haskell +/dist +/dist-* +/cabal-dev + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +"#, + ); + + self.embedded_templates.insert( + "rust", + r#"# Generated by gitignore-gen + +# Build results +/target +**/target/ +Cargo.lock + +# IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ +.DS_Store + +# Editor +*.orig +*.rej +*.bak +*~ + +# Testing +coverage/ + +# Misc +*.pem +.env +.env.local +.env.*.local +"#, + ); + } + + pub fn list_templates(&self) -> Vec<&str> { + self.embedded_templates.keys().cloned().collect() + } + + pub fn get_template(&self, name: &str) -> Option