hay-kot / scaffold

A cookie cutter alternative with in-project scaffolding for generating components, controllers, or other common code patterns.
https://hay-kot.github.io/scaffold/
MIT License
63 stars 8 forks source link

Tool stopped generating files and errors when attempting to write snapshot to stdout or file #205

Open jmmills opened 2 months ago

jmmills commented 2 months ago

Was evaluating this tool to see if I can use it to generate some boilerplate, and it seemed to be working fine as I was developing a set of templates, then suddenly just stopped generating files with no error.

I removed the cache, removed all template files from my scaffold sans the templated directory names and README files, still not working.

$ scaffold --log-level="error" --output-dir=":memory:" new --snapshot="stdout " service                      
  ? Which domain is this service in? platform
  ? What is the top level namespace of this service? document
  ? Additional namespace directory path parse
  ? What is the package name of this service pdf

fatal: write stdout : file already closed
$ env | grep SCAFFOLD                                                                                        
SCAFFOLDRC=.scaffoldrc.yaml
SCAFFOLD_LOG_LEVEL=error
$ scaffold dev dump                                                                                         

   Scaffold RC

    settings:
       theme: scaffold
       run_hooks: prompt
       log_file: stdout
       log_level: warn
    defaults:
       Project: .
    aliases: {}
    shorts: {}
    auth: []
$ scaffold --no-clobber="false" --log-level="debug" --output-dir=":memory:" new --snapshot="stdout" service
8:59PM DBG question key=Project type=string value=.
8:59PM DBG question key=Domain type=string value=platform
8:59PM DBG question key=Namespace type=string value=document
8:59PM DBG question key=NestedNamespace type=string value=parse
8:59PM DBG question key=ServiceName type=string value=pdf
  ? Which domain is this service in? platform
  ? What is the top level namespace of this service? document
  ? Additional namespace directory path parse
  ? What is the package name of this service pdf

8:59PM DBG guard guard=0 outpath="{{ .Project }}"
8:59PM DBG guard guard=1 outpath=.
8:59PM DBG guard guard=2 outpath=.
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}"
8:59PM DBG guard guard=1 outpath=./platform
8:59PM DBG guard guard=2 outpath=./platform
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}/{{ .Scaffold.Namespace }}"
8:59PM DBG guard guard=1 outpath=./platform/document
8:59PM DBG guard guard=2 outpath=./platform/document
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}/{{ .Scaffold.Namespace }}/{{ .Scaffold.NestedNamespace }}"
8:59PM DBG guard guard=1 outpath=./platform/document/parse
8:59PM DBG guard guard=2 outpath=./platform/document/parse
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}/{{ .Scaffold.Namespace }}/{{ .Scaffold.NestedNamespace }}/{{ .Scaffold.ServiceName }}"
8:59PM DBG guard guard=1 outpath=./platform/document/parse/pdf
8:59PM DBG guard guard=2 outpath=./platform/document/parse/pdf
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}/{{ .Scaffold.Namespace }}/{{ .Scaffold.NestedNamespace }}/{{ .Scaffold.ServiceName }}/app"
8:59PM DBG guard guard=1 outpath=./platform/document/parse/pdf/app
8:59PM DBG guard guard=2 outpath=./platform/document/parse/pdf/app
8:59PM DBG guard guard=0 outpath="{{ .Project }}/{{ .Scaffold.Domain }}/{{ .Scaffold.Namespace }}/{{ .Scaffold.NestedNamespace }}/{{ .Scaffold.ServiceName }}/app/README.md"
8:59PM DBG guard guard=1 outpath=./platform/document/parse/pdf/app/README.md
8:59PM DBG guard guard=2 outpath=./platform/document/parse/pdf/app/README.md
8:59PM DBG guard guard=3 outpath=./platform/document/parse/pdf/app/README.md
8:59PM DBG guard guard=4 outpath=./platform/document/parse/pdf/app/README.md
$ ls ./platform/document/parse/pdf/app/README.md                                                             
ls: cannot access './platform/document/parse/pdf/app/README.md': No such file or directory
jmmills commented 2 months ago

After some digging, I figured out that it was being prevented by the guardDirectories function in the scaffold render funcs set.

Apparently me using . as the project name was causing the problems, I worked around this by setting the project name to my checkout directory name and setting my output dir to ../.

This is likely because my use case is generating boilerplate from within a monorepo.

hay-kot commented 2 months ago

Hey! I'm having a little trouble understand exactly what the issue is. Would it be possible to get a reproducible example? Or possible a better explication of where your current directory is and where you .scaffold directory is.

In your first example

--snapshot="stdout " has an extra space which may be part of the issue? In the second example, --output-dir=":memory:" would prevent the file from rendering so this:

$ ls ./platform/document/parse/pdf/app/README.md
ls: cannot access './platform/document/parse/pdf/app/README.md': No such file or directory

would be expected.

Like I said, I'm probably missing something here.

jmmills commented 2 months ago

Hey! I'm having a little trouble understand exactly what the issue is. Would it be possible to get a reproducible example? Or possible a better explication of where your current directory is and where you .scaffold directory is.

In your first example

--snapshot="stdout " has an extra space which may be part of the issue? In the second example, --output-dir=":memory:" would prevent the file from rendering so this:

$ ls ./platform/document/parse/pdf/app/README.md ls: cannot access './platform/document/parse/pdf/app/README.md': No such file or directory

would be expected.

Like I said, I'm probably missing something here.

No problem, let me spin up an example project structure that replicates my workaround for the monorepo usecase.