go_yarn

package module
v0.0.0-...-3eba059 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2018 License: MIT Imports: 10 Imported by: 0

README

go-yarn

A Go (golang) library to manage client dependencies using yarn registry

It can be used as a library or as a bin command.

Installation

As a library

go get github.com/rgobbo/go-yarn

or if you want to use it as a bin command

go get github.com/rgobbo/go-yarn/cmd/go-yarn

Usage

Add a configuration yarn.json file to your project:

{
  "dependencies": [
    {
      "lib": "angular",
      "version": "1.6.4"
    },
    {
      "lib": "jquery",
      "version": "3.2.1"
    }
  ]
}

Then in your Go app you can do something like

package main

import (
    goyarn "github.com/rgobbo/go-yarn"
    "log"
    "os"
)

func main() {
  configFile := "./yarn.json"
  destPath := "./static/vendor"
  err := 	err := goyarn.YarnInstall(configFile, destPath)
  if err != nil {
    log.Fatal("Error processing yarn :", err)
  }

  log.Println("Yarn processed successfully !!"


}
Command Mode

Assuming you've installed the command as above and you've got $GOPATH/bin in your $PATH There is a sample file (yarn.json) in sample folder.

go-yarn -c yarn.json -f ./static/vendor/

Where -c is the configuration file and -f is the path where the libs will be installed.

Writing Config Files

The file yarn.json is a json file with array of objects containing lib name and version.

{
  "dependencies": [
    {
      "lib": "angular",
      "version": "1.6.4"
    },
    {
      "lib": "jquery",
      "version": "3.2.1"
    }
  ]
}

After the file was processed, it will change adding lines like :

{
      "lib": "angular",
      "version": "1.6.4",
      "resolved": "https://registry.npmjs.org/angular/-/angular-1.6.4.tgz"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(url string, fileName string) error

DownloadFile - function to downlaod and save file from a given url

func YarnInstall

func YarnInstall(confPath string, publishPath string) error

YarnInstall - function to install libraries from yarn.conf Example : - YarnInstall("./conf/yarn.json","./static/vendor/")

Types

type Dist

type Dist struct {
	Shasum  string `json:"shasum"`
	Tarball string `json:"tarball"`
}

type DistTag

type DistTag struct {
	Latest string `json:"latest"`
	Old    string `json:"old"`
	Next   string `json:"next"`
}

type Version

type Version struct {
	Name    string `json:"name"`
	Ver     string `json:"version"`
	Distrib Dist   `json:"dist"`
}

type Yarn

type Yarn struct {
	ID          string  `json:"_id"`
	Rev         string  `json:"_rev"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	DistTags    DistTag `json:"dist-tags"`
	Versions    map[string]Version
}

Yarn - Struture to hold yarn.json configuration

type YarnConf

type YarnConf struct {
	Dependencies []YarnConfItem `json:"dependencies"`
}

type YarnConfItem

type YarnConfItem struct {
	Lib      string `json:"lib"`
	Version  string `json:"version"`
	Resolved string `json:"resolved"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL