Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -161,7 +161,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)
}

Expand Down
3 changes: 2 additions & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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

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)
}
Expand Down
8 changes: 5 additions & 3 deletions internal/nodepkg/nodepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions internal/stacks/express/express.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ 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/b-jonathan/taco/internal/nodepkg"
"github.com/spf13/afero"

"github.com/b-jonathan/taco/internal/stacks"
)
Expand All @@ -28,7 +28,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)
}

Expand Down Expand Up @@ -87,12 +87,12 @@ 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 {
if err := afero.WriteFile(fsutil.Fs, path, []byte(content), 0o644); err != nil {
return fmt.Errorf("write %s: %w", path, err)
}

Expand Down
10 changes: 5 additions & 5 deletions internal/stacks/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mongodb
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"time"
Expand All @@ -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"
)
Expand Down Expand Up @@ -152,7 +152,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)
}
Expand Down Expand Up @@ -183,15 +183,15 @@ 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)
Expand Down
Loading