Code Monkey home page Code Monkey logo

bundle's Introduction

bundle

Bundle merges multiple Go source files into single one.

Install

go get -u github.com/bbrodriges/bundle

Usage

As a separate command:

$ bundle --help
Usage: bundle -p <package_name> [-d] pattern...
Available options:
  -d	Delete source files after bundling
  -p string
    	Package name to be written into result file. Required

$ bundle -d -p main *_gen.go > bundle.go # bundle all autogenerated files in current folder
$ bundle -d -p main -o bundle.go user.msgp.go user.str.go # bundle only specific files

As a go generate flag:

package types

//go:generate msgp -o=user.msgp.go -tests=false -io=false
//go:generate stringer -type=User -output=user.str.go -linecomment
//msgp:shim UserState as:string using:(UserState).String/UserStateFromString

//go:generate bundle -d -p=types -o=user_gen.go user.msgp.go user.str.go

type User struct {
    Username string `msg:"username"`
    Email string `msg:"email"`
    State UserState `msg:"state"`
}

type UserState int

const (
    Unknown UserState = iota -1 // UNKNOWN
    Inactive                    // INACTIVE
    Active                      // ACTIVE
    Banned                      // BANNED
)

func UserStateFromString(s string) UserState {
    switch s {
    case "INACTIVE":
        return Inactive
    case "ACTIVE":
        return Active
    case "BANNED":
        return Banned
    }
    return Unknown
}

The above code upon calling go generate . will:

  1. create files called user.msgp.go and user.str.go with containing autogenerated code
  2. bundle these two files into single user_gen.go and delete source files user.msgp.go and user.str.go

Limitations

  • bundle cannot handle definition conflicts (e.g. structs, functions, constants of the same names)
  • bundle cannot handle import cycle conflicts

All it does is collects and strips out import declarations from every given source files AST and concats them into single file with helping comments.

bundle's People

Contributors

bbrodriges avatar ei-grad avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.