Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: staticcheck ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ main
bin/
gogen
.env
dist/
dist/
go-ts-types-out
.golangci.local.json
68 changes: 68 additions & 0 deletions .golangci.bck.v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
run:
timeout: 5m
issues-exit-code: 1
tests: true
modules-download-mode: readonly

output:
formats:
- format: colored-line-number

linters-settings:
depguard:
rules:
main:
files:
- $all
allow:
- $gostd
- github.com/luigimorel/gogen
- github.com/urfave/cli/v2
gofmt:
simplify: true
goimports:
local-prefixes: github.com/luigimorel/gogen
misspell:
locale: US

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- goimports
- misspell
- goconst
- gosec
- unconvert
- dupl
- gocritic
- gocyclo
- whitespace
- bodyclose
- depguard
- dogsled

disable:
- funlen
- gochecknoglobals
- gocognit
- godot
- godox
- nestif

issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- dupl
- linters:
- lll
source: "^//go:generate "
max-issues-per-linter: 0
max-same-issues: 0
105 changes: 58 additions & 47 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,79 @@
version: "2"
run:
timeout: 5m
modules-download-mode: readonly
issues-exit-code: 1
tests: true
modules-download-mode: readonly

output:
formats:
- format: colored-line-number

linters-settings:
depguard:
rules:
main:
files:
- $all
allow:
- $gostd
- github.com/luigimorel/gogen
- github.com/urfave/cli/v2
gofmt:
simplify: true
goimports:
local-prefixes: github.com/luigimorel/gogen
misspell:
locale: US

text:
path: stdout
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- goimports
- misspell
- goconst
- gosec
- unconvert
- bodyclose
- depguard
- dogsled
- dupl
- goconst
- gocritic
- gocyclo
- gosec
- misspell
- unconvert
- whitespace
- bodyclose
- depguard
- dogsled

disable:
- funlen
- gochecknoglobals
- gocognit
- godot
- godox
- nestif

settings:
depguard:
rules:
main:
files:
- $all
allow:
- $gostd
- github.com/luigimorel/gogen
- github.com/urfave/cli/v2
misspell:
locale: US
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- gosec
path: _test\.go
- linters:
- lll
source: '^//go:generate '
paths:
- third_party$
- builtin$
- examples$
issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- dupl
- linters:
- lll
source: "^//go:generate "
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofmt
- goimports
settings:
gofmt:
simplify: true
goimports:
local-prefixes:
- github.com/luigimorel/gogen
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
64 changes: 64 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"errors"
"fmt"
"path/filepath"

gentstypes "github.com/luigimorel/gogen/internal/gen-ts-types"
"github.com/urfave/cli/v2"
)

func GenerateCommand() *cli.Command {
return &cli.Command{
Name: "generate",
Usage: "Utilities to generate code, go or ts",
ArgsUsage: "<command>",
Description: `Utilities to generate code, go or ts`,
Subcommands: []*cli.Command{
typeGenCommand(),
},
}
}

func typeGenCommand() *cli.Command {
return &cli.Command{
Name: "types",
Usage: "Generate TypeScript types from Go code",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "Go package path, local dir/file, or package.Type (like go doc)",
Required: true,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output .d.ts file or directory",
Value: "./go-ts-types-out",
},
},
Action: func(c *cli.Context) error {
input := c.String("input")
output := c.String("output")

if input == "" {
return errors.New("missing -input: provide a go package path, local dir/file, or package.Type")
}

absOut, err := filepath.Abs(output)
if err != nil {
return fmt.Errorf("failed to resolve absolute path for output: %w", err)
}

err = gentstypes.Generate(input, absOut)
if err != nil {
return fmt.Errorf("failed to generate typescript types: %w", err)
}

fmt.Println("Generation complete:", absOut)
return nil
},
}
}
9 changes: 5 additions & 4 deletions cmd/frontend.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"os/exec"
"strings"
Expand Down Expand Up @@ -85,7 +86,7 @@ Usage:
},
Action: func(c *cli.Context) error {
if c.NArg() == 0 {
return fmt.Errorf("framework type is required. Usage: gogen frontend <framework-type>")
return errors.New("framework type is required. Usage: gogen frontend <framework-type>")
}

frameworkType := c.Args().Get(0)
Expand Down Expand Up @@ -122,14 +123,14 @@ func (fm *FrontendManager) validateSetup() error {
switch fm.Runtime {
case node:
if !fm.commandExists("node") {
return fmt.Errorf("node.js is required but not installed. Please install Node.js from https://nodejs.org/")
return errors.New("node.js is required but not installed. Please install Node.js from https://nodejs.org/")
}
if !fm.commandExists("npm") {
return fmt.Errorf("npm is required but not installed. Please install npm")
return errors.New("npm is required but not installed. Please install npm")
}
case bun:
if !fm.commandExists("bun") {
return fmt.Errorf("bun is required but not installed. Please install Bun from https://bun.sh/")
return errors.New("bun is required but not installed. Please install Bun from https://bun.sh/")
}
default:
return fmt.Errorf("unsupported runtime: %s. Supported runtimes: node, bun", fm.Runtime)
Expand Down
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func App() *cli.App {
NewCommand(),
InstallCommand(),
FrontendCommand(),
GenerateCommand(),
},
}
}
5 changes: 3 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -133,7 +134,7 @@ func (i *Installer) binaryInstall() error {

func (i *Installer) nixInstall() error {
if !i.commandExists("nix-env") && !i.commandExists("nix") {
return fmt.Errorf("nix is not installed on this system")
return errors.New("nix is not installed on this system")
}

fmt.Println("Nix package not available yet, using binary installation...")
Expand All @@ -142,7 +143,7 @@ func (i *Installer) nixInstall() error {

func (i *Installer) brewInstall() error {
if !i.commandExists("brew") {
return fmt.Errorf("homebrew is not installed on this system")
return errors.New("homebrew is not installed on this system")
}

fmt.Println("Homebrew formula not available yet, using binary installation...")
Expand Down
Loading
Loading