From 8de09d8e4d88077516cbf865a318de4569070b8a Mon Sep 17 00:00:00 2001 From: arthurlw Date: Tue, 2 Dec 2025 10:23:46 -0800 Subject: [PATCH 1/2] Implement dependency injection for file paths --- go.mod | 3 ++- go.sum | 4 ++++ internal/cli/root.go | 4 ++-- internal/fsutil/fsutil.go | 17 ++++++++++------- internal/git/git.go | 3 ++- internal/nodepkg/nodepkg.go | 8 +++++--- internal/stacks/express/express.go | 14 +++++++------- internal/stacks/mongodb/mongodb.go | 12 ++++++------ internal/stacks/nextjs/nextjs.go | 12 ++++++------ 9 files changed, 44 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 7b03e1c..4dfbddb 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/montanaflynn/stats v0.7.1 // indirect + github.com/spf13/afero v1.15.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect @@ -35,5 +36,5 @@ require ( golang.org/x/sync v0.17.0 golang.org/x/sys v0.23.0 // indirect golang.org/x/term v0.23.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/text v0.28.0 // indirect ) diff --git a/go.sum b/go.sum index 7a93120..ccaaac6 100644 --- a/go.sum +++ b/go.sum @@ -44,6 +44,8 @@ github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= @@ -98,6 +100,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= +golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/cli/root.go b/internal/cli/root.go index 6d077f4..70d55a5 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -3,12 +3,12 @@ package cli import ( "context" "fmt" - "os" "strconv" "strings" "time" "github.com/AlecAivazis/survey/v2" + "github.com/b-jonathan/taco/internal/fsutil" "github.com/b-jonathan/taco/internal/gh" "github.com/b-jonathan/taco/internal/git" "github.com/b-jonathan/taco/internal/logx" @@ -160,7 +160,7 @@ func initCmd() *cobra.Command { } projectRoot := params.Name - if err := os.MkdirAll(projectRoot, 0o755); err != nil { + if err := fsutil.Fs.MkdirAll(projectRoot, 0o755); err != nil { return fmt.Errorf("mkdir project root: %w", err) } diff --git a/internal/fsutil/fsutil.go b/internal/fsutil/fsutil.go index a90c476..6580109 100644 --- a/internal/fsutil/fsutil.go +++ b/internal/fsutil/fsutil.go @@ -11,16 +11,19 @@ import ( "text/template" "github.com/b-jonathan/taco/internal/stacks/templates" + "github.com/spf13/afero" ) +var Fs = afero.NewOsFs() + // TODO: Some of these were completely vibe coded, just need to refactor a bit to make more consistent func EnsureFile(path string) error { // Create parent directories if needed. - if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + if err := Fs.MkdirAll(filepath.Dir(path), 0o755); err != nil { return err } // Create the file if missing. O_EXCL prevents clobbering if a race happens. - f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL, 0o644) + f, err := Fs.OpenFile(path, os.O_CREATE|os.O_EXCL, 0o644) if err != nil { // If it already exists, that’s fine. if os.IsExist(err) { @@ -39,7 +42,7 @@ func WriteFile(file FileInfo) error { } // log.Println("Ensuring file complete") // log.Printf("Writing File: %s", path) - if err := os.WriteFile(file.Path, file.Content, 0o644); err != nil { + if err := afero.WriteFile(Fs, file.Path, file.Content, 0o644); err != nil { return fmt.Errorf("write %s file: %w", filename, err) } // log.Println("Writing file complete") @@ -56,7 +59,7 @@ func WriteMultipleFiles(files []FileInfo) error { } func AppendUniqueLines(path string, lines []string) error { - buf, _ := os.ReadFile(path) + buf, _ := afero.ReadFile(Fs, path) for _, line := range lines { if !bytes.Contains(buf, []byte(line+"\n")) && !bytes.Equal(bytes.TrimSpace(buf), []byte(line)) { if len(buf) > 0 && buf[len(buf)-1] != '\n' { @@ -65,7 +68,7 @@ func AppendUniqueLines(path string, lines []string) error { buf = append(buf, []byte(line+"\n")...) } } - return os.WriteFile(path, buf, 0o644) + return afero.WriteFile(Fs, path, buf, 0o644) } // in a shared package or file @@ -161,10 +164,10 @@ func GenerateFromTemplateDir(templateRoot, outputRoot string) error { return fmt.Errorf("render template %s: %w", path, err) } - if err := os.MkdirAll(filepath.Dir(finalPath), 0755); err != nil { + if err := Fs.MkdirAll(filepath.Dir(finalPath), 0755); err != nil { return err } - return os.WriteFile(finalPath, content, 0644) + return afero.WriteFile(Fs, finalPath, content, 0644) }) } diff --git a/internal/git/git.go b/internal/git/git.go index 5282eac..2c61787 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/b-jonathan/taco/internal/execx" + "github.com/b-jonathan/taco/internal/fsutil" ) // TODO: There is absolutely no reason for init and push to be in one function, gonna have to refactor this for sure @@ -14,7 +15,7 @@ import ( func Init(ctx context.Context, projectRoot string) error { // If already a repo, skip init - if _, err := os.Stat(filepath.Join(projectRoot, ".git")); os.IsNotExist(err) { + if _, err := fsutil.Fs.Stat(filepath.Join(projectRoot, ".git")); os.IsNotExist(err) { if err := execx.RunCmd(ctx, projectRoot, "git init"); err != nil { return fmt.Errorf("git init: %w", err) } diff --git a/internal/nodepkg/nodepkg.go b/internal/nodepkg/nodepkg.go index 098f96b..dc493d1 100644 --- a/internal/nodepkg/nodepkg.go +++ b/internal/nodepkg/nodepkg.go @@ -2,13 +2,15 @@ package nodepkg import ( "encoding/json" - "os" "path/filepath" + + "github.com/b-jonathan/taco/internal/fsutil" + "github.com/spf13/afero" ) func InitPackage(dir string, params InitPackageParams) error { path := filepath.Join(dir, "package.json") - b, err := os.ReadFile(path) + b, err := afero.ReadFile(fsutil.Fs, path) if err != nil { return err } @@ -42,5 +44,5 @@ func InitPackage(dir string, params InitPackageParams) error { if err != nil { return err } - return os.WriteFile(path, out, 0o644) + return afero.WriteFile(fsutil.Fs, path, out, 0o644) } diff --git a/internal/stacks/express/express.go b/internal/stacks/express/express.go index 045eb7f..f92f759 100644 --- a/internal/stacks/express/express.go +++ b/internal/stacks/express/express.go @@ -3,12 +3,12 @@ package express import ( "context" "fmt" - "os" "path/filepath" "strings" "github.com/b-jonathan/taco/internal/execx" "github.com/b-jonathan/taco/internal/fsutil" + "github.com/spf13/afero" "github.com/b-jonathan/taco/internal/stacks" ) @@ -27,7 +27,7 @@ func (express) Init(ctx context.Context, opts *Options) error { backendDir := filepath.Join(opts.ProjectRoot, "backend") srcDir := filepath.Join(backendDir, "src") - if err := os.MkdirAll(srcDir, 0o755); err != nil { + if err := fsutil.Fs.MkdirAll(srcDir, 0o755); err != nil { return fmt.Errorf("mkdir: %w", err) } @@ -85,14 +85,14 @@ func (express) Post(ctx context.Context, opts *Options) error { []string{"backend/node_modules/", "backend/dist/", "backend/.env*"}) path := filepath.Join(opts.ProjectRoot, "backend", ".env") dir := filepath.Dir(path) - if err := os.MkdirAll(dir, 0o755); err != nil { + if err := fsutil.Fs.MkdirAll(dir, 0o755); err != nil { return fmt.Errorf("mkdir %s: %w", dir, err) } content := ` - PORT=4000 - FRONTEND_ORIGIN=http://localhost:3000 - ` - if err := os.WriteFile(path, []byte(content), 0o644); err != nil { + PORT=4000 + FRONTEND_ORIGIN=http://localhost:3000 + ` + if err := afero.WriteFile(fsutil.Fs, path, []byte(content), 0o644); err != nil { return fmt.Errorf("write %s: %w", path, err) } return nil diff --git a/internal/stacks/mongodb/mongodb.go b/internal/stacks/mongodb/mongodb.go index f3f0f1e..a301037 100644 --- a/internal/stacks/mongodb/mongodb.go +++ b/internal/stacks/mongodb/mongodb.go @@ -3,7 +3,6 @@ package mongodb import ( "context" "fmt" - "os" "path/filepath" "strings" "time" @@ -13,6 +12,7 @@ import ( "github.com/b-jonathan/taco/internal/fsutil" "github.com/b-jonathan/taco/internal/prompt" "github.com/b-jonathan/taco/internal/stacks" + "github.com/spf13/afero" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) @@ -150,7 +150,7 @@ func (mongodb) Generate(ctx context.Context, opts *Options) error { } indexPath := filepath.Join(backendDir, "src", "index.ts") - indexBytes, err := os.ReadFile(indexPath) + indexBytes, err := afero.ReadFile(fsutil.Fs, indexPath) if err != nil { return fmt.Errorf("read index.ts: %w", err) } @@ -181,19 +181,19 @@ import { connectDB } from "./db/client";`, 1) func (mongodb) Post(ctx context.Context, opts *Options) error { // gitignorePath := filepath.Join(opts.ProjectRoot, ".gitignore") // if err := fsutil.EnsureFile(gitignorePath); err != nil { - // return fmt.Errorf("ensure gitignore file: %w", err) + // return fmt.Errorf("ensure gitignore file: %w", err) // } // _ = fsutil.AppendUniqueLines(gitignorePath, - // []string{"backend/node_modules/", "backend/dist/", "backend/.env*"}) + // []string{"backend/node_modules/", "backend/dist/", "backend/.env*"}) path := filepath.Join(opts.ProjectRoot, "backend", ".env") // dir := filepath.Dir(path) // if err := os.MkdirAll(dir, 0o755); err != nil { - // return fmt.Errorf("mkdir %s: %w", dir, err) + // return fmt.Errorf("mkdir %s: %w", dir, err) // } // TODO: Make this not as scuffed lol content := fmt.Sprintf(` - MONGODB_URI=%s/%s`, opts.DatabaseURI, opts.AppName) + MONGODB_URI=%s/%s`, opts.DatabaseURI, opts.AppName) _ = fsutil.AppendUniqueLines(path, []string{content}) return nil } diff --git a/internal/stacks/nextjs/nextjs.go b/internal/stacks/nextjs/nextjs.go index ff14509..ab41456 100644 --- a/internal/stacks/nextjs/nextjs.go +++ b/internal/stacks/nextjs/nextjs.go @@ -3,7 +3,6 @@ package nextjs import ( "context" "fmt" - "os" "path/filepath" "strings" @@ -11,6 +10,7 @@ import ( "github.com/b-jonathan/taco/internal/fsutil" "github.com/b-jonathan/taco/internal/nodepkg" "github.com/b-jonathan/taco/internal/stacks" + "github.com/spf13/afero" ) type Stack = stacks.Stack @@ -25,7 +25,7 @@ func (nextjs) Type() string { return "frontend" } func (nextjs) Name() string { return "express" } func (nextjs) Init(ctx context.Context, opts *Options) error { - if err := os.MkdirAll(opts.ProjectRoot, 0o755); err != nil { + if err := fsutil.Fs.MkdirAll(opts.ProjectRoot, 0o755); err != nil { return fmt.Errorf("mkdir: %w", err) } // 1) Scaffold Next.js in TS, without ESLint, noninteractive @@ -105,12 +105,12 @@ func (nextjs) Post(ctx context.Context, opts *Options) error { } dir := filepath.Dir(envPath) - if err := os.MkdirAll(dir, 0o755); err != nil { + if err := fsutil.Fs.MkdirAll(dir, 0o755); err != nil { return fmt.Errorf("mkdir %s: %w", dir, err) } - content := `NEXT_PUBLIC_BACKEND_URL=http://localhost:4000 - ` - if err := os.WriteFile(envPath, []byte(content), 0o644); err != nil { + content := `NEXT_PUBLIC_BACKEND_URL=http://localhost:4000 + ` + if err := afero.WriteFile(fsutil.Fs, envPath, []byte(content), 0o644); err != nil { return fmt.Errorf("write %s: %w", envPath, err) } From 8022248e57b3799cb4ffa9079ddf43954827a5f6 Mon Sep 17 00:00:00 2001 From: "ribellye@gmail.com" Date: Mon, 2 Feb 2026 21:13:05 -0800 Subject: [PATCH 2/2] minor fixes --- .github/PULL_REQUEST_TEMPLATE.md | 39 ++----------------- internal/cli/root.go | 4 +- internal/fsutil/fsutil.go | 13 ++++--- internal/prompt/prompt.go | 4 +- internal/stacks/express/express.go | 26 +++++++++++-- internal/stacks/firebase/firebase.go | 2 +- internal/stacks/mongodb/mongodb.go | 7 ++-- internal/stacks/nextjs/nextjs.go | 10 ++--- .../templates/express/src/index.ts.tmpl | 2 +- 9 files changed, 48 insertions(+), 59 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 05e33a4..1f7d6bc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,38 +1,5 @@ -## Summary +- [ ] Closes #(issue number) if applicable. +- [ ] Passes all code checks +- [ ] Added new tests Describe the purpose of this pull request. What does it do, and why is it needed? - -Closes #(issue number) if applicable. - ---- - -## Changes Made - -- [ ] Added new stack: `` -- [ ] Updated existing functionality -- [ ] Improved documentation -- [ ] Refactored internal code -- [ ] Fixed a bug - -Briefly summarize the major changes: - -- -- -- - ---- - -## Testing - -How was this change tested? - -- [ ] `go test ./...` passes locally -- [ ] Manual testing done with `taco` CLI -- [ ] CI checks pass - -Provide details: - -```bash -# Example test commands -go test ./... -taco init test-app diff --git a/internal/cli/root.go b/internal/cli/root.go index 70d55a5..6e30a1d 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -197,6 +197,8 @@ func initCmd() *cobra.Command { ProjectRoot: projectRoot, AppName: params.Name, Frontend: stack["frontend"], + Backend: stack["backend"], + Database: stack["database"], FrontendURL: "http://localhost:3000", BackendURL: "http://localhost:4000", Port: 4000, @@ -275,7 +277,7 @@ func initCmd() *cobra.Command { return fmt.Errorf("create repo: %w", err) } - fmt.Println(cmd.OutOrStdout(), "Created:", repo.GetHTMLURL()) + fmt.Println("Created:", repo.GetHTMLURL()) remoteURL := repo.GetSSHURL() if params.Remote == "https" { remoteURL = repo.GetCloneURL() diff --git a/internal/fsutil/fsutil.go b/internal/fsutil/fsutil.go index 6580109..b7e2aa0 100644 --- a/internal/fsutil/fsutil.go +++ b/internal/fsutil/fsutil.go @@ -5,6 +5,7 @@ import ( "fmt" "io/fs" "os" + "path" "path/filepath" "strings" "sync" @@ -106,11 +107,13 @@ func ValidateDependency(stack, dependency string) bool { if stack == "none" || dependency == "none" { return true } - stackPath := filepath.Join("internal", "stacks", "templates", stack) + if stack == "" || dependency == "" { + return false + } - info, err := os.ReadDir(stackPath) + info, err := templates.FS.ReadDir(stack) if err != nil { - fmt.Printf("path does not exist %s\n", stackPath) + fmt.Printf("embedded path does not exist %s\n", stack) return false } //check if subfolder is "src", "db" or doesn't exist -> true. @@ -129,8 +132,8 @@ func ValidateDependency(stack, dependency string) bool { return true } //else, check if dependency is in subfolders of stack. - dependencyPath := filepath.Join(stackPath, dependency) - if info, err := os.Stat(dependencyPath); err == nil && info.IsDir() { + dependencyPath := path.Join(stack, dependency) + if _, err := templates.FS.ReadDir(dependencyPath); err == nil { return true } return false diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index a0cdd4d..3d9bdfe 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -71,14 +71,14 @@ func CreateSurveyMultiSelect(message string, choices []string, options AskOpts) return nil, fmt.Errorf("options cannot be empty") } - prompt := &survey.Select{ + prompt := &survey.MultiSelect{ Message: message, Options: choices, //choices, this is a bit weird AHHAHA Help: options.Help, PageSize: options.PageSize, } - if v, ok := options.Default.(string); ok { + if v, ok := options.Default.([]string); ok { prompt.Default = v } return askManyString(prompt, options) diff --git a/internal/stacks/express/express.go b/internal/stacks/express/express.go index f92f759..40ba0c7 100644 --- a/internal/stacks/express/express.go +++ b/internal/stacks/express/express.go @@ -8,6 +8,7 @@ import ( "github.com/b-jonathan/taco/internal/execx" "github.com/b-jonathan/taco/internal/fsutil" + "github.com/b-jonathan/taco/internal/nodepkg" "github.com/spf13/afero" "github.com/b-jonathan/taco/internal/stacks" @@ -55,6 +56,7 @@ func (express) Init(ctx context.Context, opts *Options) error { "eslint-plugin-n", "eslint-config-prettier", "prettier", + "tsx", } //TODO: Prob can Refactor this somewhere, like keeping track of depencies to be installed, not urgent tho if err := execx.RunCmd(ctx, backendDir, "npm install -D "+strings.Join(devDependencies, " ")); err != nil { @@ -88,12 +90,28 @@ func (express) Post(ctx context.Context, opts *Options) error { if err := fsutil.Fs.MkdirAll(dir, 0o755); err != nil { return fmt.Errorf("mkdir %s: %w", dir, err) } - content := ` - PORT=4000 - FRONTEND_ORIGIN=http://localhost:3000 - ` + content := `PORT=4000 +FRONTEND_ORIGIN=http://localhost:3000` if err := afero.WriteFile(fsutil.Fs, path, []byte(content), 0o644); err != nil { return fmt.Errorf("write %s: %w", path, err) } + + params := nodepkg.InitPackageParams{ + Name: "backend", + Main: "src/index.ts", + Scripts: map[string]string{ + "build": "tsc -p tsconfig.json", + "dev": "tsx watch src/index.ts", + "lint-check": "eslint . && prettier --check .", + "lint-fix": "eslint . --fix && prettier --write .", + "start": "node dist/index.js", + "test": "echo \"Error: no test specified\" && exit 1", + }, + } + backendDir := filepath.Join(opts.ProjectRoot, "backend") + if err := nodepkg.InitPackage(backendDir, params); err != nil { + return fmt.Errorf("init express package.json: %w", err) + } + return nil } diff --git a/internal/stacks/firebase/firebase.go b/internal/stacks/firebase/firebase.go index 70cdb24..44b3946 100644 --- a/internal/stacks/firebase/firebase.go +++ b/internal/stacks/firebase/firebase.go @@ -141,7 +141,7 @@ func (firebase) Generate(ctx context.Context, opts *Options) error { } templateDir := "firebase/nextjs" - outputDir := filepath.Join(frontendDir, "src") + outputDir := filepath.Join(frontendDir) if err := fsutil.GenerateFromTemplateDir(templateDir, outputDir); err != nil { return fmt.Errorf("generate firebase nextjs templates: %w", err) diff --git a/internal/stacks/mongodb/mongodb.go b/internal/stacks/mongodb/mongodb.go index a301037..8a53fa1 100644 --- a/internal/stacks/mongodb/mongodb.go +++ b/internal/stacks/mongodb/mongodb.go @@ -134,7 +134,9 @@ func (mongodb) Init(ctx context.Context, opts *Options) error { func (mongodb) Generate(ctx context.Context, opts *Options) error { backendDir := filepath.Join(opts.ProjectRoot, "backend") - + if !fsutil.ValidateDependency("mongodb", opts.Backend) { + return fmt.Errorf("mongodb cannot be used with backend '%s'", opts.Backend) + } if err := execx.RunCmd(ctx, backendDir, "npm install mongodb"); err != nil { return fmt.Errorf("npm install mongodb: %w", err) } @@ -192,8 +194,7 @@ func (mongodb) Post(ctx context.Context, opts *Options) error { // return fmt.Errorf("mkdir %s: %w", dir, err) // } // TODO: Make this not as scuffed lol - content := fmt.Sprintf(` - MONGODB_URI=%s/%s`, opts.DatabaseURI, opts.AppName) + content := fmt.Sprintf(`MONGODB_URI=%s/%s`, opts.DatabaseURI, opts.AppName) _ = fsutil.AppendUniqueLines(path, []string{content}) return nil } diff --git a/internal/stacks/nextjs/nextjs.go b/internal/stacks/nextjs/nextjs.go index ab41456..9aafb79 100644 --- a/internal/stacks/nextjs/nextjs.go +++ b/internal/stacks/nextjs/nextjs.go @@ -22,7 +22,7 @@ func New() Stack { return &nextjs{} } func (nextjs) Type() string { return "frontend" } -func (nextjs) Name() string { return "express" } +func (nextjs) Name() string { return "nextjs" } func (nextjs) Init(ctx context.Context, opts *Options) error { if err := fsutil.Fs.MkdirAll(opts.ProjectRoot, 0o755); err != nil { @@ -81,15 +81,14 @@ func (nextjs) Generate(ctx context.Context, opts *Options) error { } packageParams := nodepkg.InitPackageParams{ - Name: "express", - Main: "dist/index.js", + Name: "nextjs", Scripts: map[string]string{ "lint-check": "next lint && prettier --check .", "lint-fix": "(next lint --fix || true) && prettier --write .", }} if err := nodepkg.InitPackage(frontendDir, packageParams); err != nil { - return fmt.Errorf("write src/index.ts: %w", err) + return fmt.Errorf("init nextjs package.json: %w", err) } return nil @@ -108,8 +107,7 @@ func (nextjs) Post(ctx context.Context, opts *Options) error { if err := fsutil.Fs.MkdirAll(dir, 0o755); err != nil { return fmt.Errorf("mkdir %s: %w", dir, err) } - content := `NEXT_PUBLIC_BACKEND_URL=http://localhost:4000 - ` + content := `NEXT_PUBLIC_BACKEND_URL=http://localhost:4000` if err := afero.WriteFile(fsutil.Fs, envPath, []byte(content), 0o644); err != nil { return fmt.Errorf("write %s: %w", envPath, err) } diff --git a/internal/stacks/templates/express/src/index.ts.tmpl b/internal/stacks/templates/express/src/index.ts.tmpl index 7559191..dce0cc4 100644 --- a/internal/stacks/templates/express/src/index.ts.tmpl +++ b/internal/stacks/templates/express/src/index.ts.tmpl @@ -4,7 +4,7 @@ import cors from "cors"; // connects to frontend // [DATABASE IMPORT] const app = express(); -const PORT = process.env.PORT || 3000; +const PORT = process.env.PORT || 4000; app.use(express.json());