{"id":30770087,"url":"https://github.com/cpcf/weft","last_synced_at":"2025-09-04T23:05:07.537Z","repository":{"id":309616675,"uuid":"1035535829","full_name":"cpcf/weft","owner":"cpcf","description":"Code gen kit for Go","archived":false,"fork":false,"pushed_at":"2025-08-11T22:43:10.000Z","size":273,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T22:32:34.481Z","etag":null,"topics":["build-tool","code-generation","codegen","content-pipeline","developer-tools","devtools","go","golang","pipeline-processing","source-code-generation","templating","text-processing","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpcf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-10T15:54:53.000Z","updated_at":"2025-08-11T21:47:02.000Z","dependencies_parsed_at":"2025-08-12T22:32:48.314Z","dependency_job_id":"fa1f7b9a-51c2-4bf7-9ba4-61cd9616c6ad","html_url":"https://github.com/cpcf/weft","commit_stats":null,"previous_names":["cpcf/weft"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cpcf/weft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpcf%2Fweft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpcf%2Fweft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpcf%2Fweft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpcf%2Fweft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpcf","download_url":"https://codeload.github.com/cpcf/weft/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpcf%2Fweft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273685604,"owners_count":25149722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-tool","code-generation","codegen","content-pipeline","developer-tools","devtools","go","golang","pipeline-processing","source-code-generation","templating","text-processing","yaml"],"created_at":"2025-09-04T23:03:14.634Z","updated_at":"2025-09-04T23:05:07.519Z","avatar_url":"https://github.com/cpcf.png","language":"Go","readme":"\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./weft.png\" /\u003e\n\u003c/p\u003e\n\n\u003e _noun_ - the horizontal threads in weaving, creating the fabric's structure.\n\n# weft \n\nA Go template engine for code generation with extensible post-processing, state management, debugging, and testing utilities.\n\n## Packages\n\n- **[config](config/)** - Generic YAML configuration loading with validation support\n- **[engine](engine/)** - Core template processing with caching and concurrent rendering\n- **[postprocess](postprocess/)** - Extensible post-processing framework for transforming generated content\n- **[processors](processors/)** - Built-in post-processors (Go imports, whitespace cleanup, headers, etc.)\n- **[render](render/)** - Template discovery, blocks, includes, and function registry  \n- **[write](write/)** - File writing with coordination, locking, and composite operations\n- **[state](state/)** - File tracking, manifest management, and cleanup operations\n- **[debug](debug/)** - Debugging, error handling, and template validation\n- **[testing](testing/)** - Testing utilities, benchmarks, mocks, and snapshots\n\n## Basic Usage\n\n```go\npackage main\n\nimport (\n    \"github.com/cpcf/weft/engine\"\n    \"github.com/cpcf/weft/processors\"\n)\n\nfunc main() {\n    // Create template engine\n    eng := engine.New(\n        engine.WithOutputRoot(\"./generated\"),\n        engine.WithFailureMode(engine.FailFast),\n    )\n\n    // Add post-processors for generated content\n    eng.AddPostProcessor(processors.NewGoImports())                // Fix Go imports \u0026 formatting\n    eng.AddPostProcessor(processors.NewTrimWhitespace())           // Clean whitespace\n    eng.AddPostProcessor(processors.NewAddGeneratedHeader(\"myapp\", \".go\")) // Add headers\n    \n    // Create context\n    ctx := engine.NewContext(templateFS, \"./generated\", \"mypackage\")\n    \n    // Render templates with post-processing\n    if err := eng.RenderDir(ctx, \"templates\", data); err != nil {\n        log.Fatal(err)\n    }\n}\n```\n\n### Custom Template Functions\n\nweft supports custom template functions alongside its built-in functions:\n\n```go\nimport (\n    \"text/template\"\n    \"time\"\n    \"github.com/cpcf/weft/engine\"\n)\n\n// Define custom functions\ncustomFuncs := template.FuncMap{\n    \"formatDate\": func(t time.Time) string {\n        return t.Format(\"2006-01-02\")\n    },\n    \"calculateTax\": func(amount float64, rate float64) float64 {\n        return amount * rate\n    },\n}\n\n// Create engine with custom functions\neng := engine.New(\n    engine.WithCustomFunctions(customFuncs),\n    engine.WithOutputRoot(\"./generated\"),\n)\n\n// Use in templates:\n// {{formatDate .CreatedAt}}\n// {{calculateTax .Amount 0.08}}\n```\n\n## Post-Processing System\n\nweft includes an extensible post-processing framework that transforms generated content:\n\n### Built-in Processors\n\n- **Go Imports** - Automatically fixes imports and formats Go code using `goimports`\n- **Trim Whitespace** - Removes trailing whitespace from all lines\n- **Generated Headers** - Adds \"Code generated\" headers to files\n- **Regex Replace** - Custom regex-based transformations\n\n### Custom Processors\n\nCreate custom processors by implementing the `postprocess.Processor` interface:\n\n```go\ntype MyProcessor struct{}\n\nfunc (p *MyProcessor) ProcessContent(filePath string, content []byte) ([]byte, error) {\n    if strings.HasSuffix(filePath, \".go\") {\n        // Custom Go transformations\n        return transformGoCode(content), nil\n    }\n    return content, nil\n}\n\n// Add to engine\neng.AddPostProcessor(\u0026MyProcessor{})\n```\n\n### Function-based Processors\n\nFor simple transformations, use function processors:\n\n```go\neng.AddPostProcessorFunc(func(filePath string, content []byte) ([]byte, error) {\n    // Convert line endings to Unix style\n    return bytes.ReplaceAll(content, []byte(\"\\r\\n\"), []byte(\"\\n\")), nil\n})\n```\n\nSee [postprocess/README.md](postprocess/README.md) for comprehensive documentation.\n\n## Configuration Loading\n\nThe config package provides utilities for loading YAML configuration files into your custom types:\n\n```go\nimport \"github.com/cpcf/weft/config\"\n\ntype MyConfig struct {\n    Name    string            `yaml:\"name\"`\n    Version string            `yaml:\"version\"`\n    Options map[string]string `yaml:\"options\"`\n}\n\nfunc main() {\n    var cfg MyConfig\n    \n    // Load configuration from YAML file\n    err := config.LoadYAML(\"config.yaml\", \u0026cfg)\n    if err != nil {\n        log.Fatal(err)\n    }\n    \n    // Use configuration with template engine\n    eng := engine.New(engine.WithOutputRoot(cfg.Options[\"output_dir\"]))\n    // ...\n}\n```\n\nSee [config/README.md](config/README.md) for detailed documentation including validation and testing utilities.\n\n## Examples\n\n- **[api-client-generator](examples/api-client-generator/)** - Generates a Go API client from a structured configuration.\n\n- **[yaml-tutorial-guide](examples/yaml-tutorial-guide/)** - Example of building YAML-based configuration systems.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpcf%2Fweft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpcf%2Fweft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpcf%2Fweft/lists"}