Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tzmfreedom committed Oct 29, 2016
0 parents commit 3c5b6d0
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
spm
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Makoto Tajitsu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPM

Salesforce Package Manager

## Install

Download binary file and copy it to executable path.

If you want to use latest version, execute following command.

```bash
$ go get github.com/tzmfreedom/spm
```

## Usage

Install Package

```bash
$ spm install github.com/tzmfreedom/apex-util
Enter Username: {USERNAME}
Enter Password: {PASSWORD}
Production/Developer?(y/n): y
```

```bash
$ spm install -c package.yml
Enter Username: {USERNAME}
Enter Password: {PASSWORD}
Production/Developer?(y/n): y
```

Package.yml format

```yaml
packages:
- github.com/tzmfreedom/apex-util1
- github.com/tzmfreedom/apex-util2
- github.com/tzmfreedom/apex-util3
```
UnInstall Package
```bash
$ spm uninstall github.com/tzmfreedom/apex-util
```

108 changes: 108 additions & 0 deletions spm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import (
"os"
"path/filepath"
"fmt"
"io"

"github.com/urfave/cli"
"gopkg.in/src-d/go-git.v4"
)

type Config struct {
username string
password string
endpoint string
api_version string
}

func main() {
app := cli.NewApp()
app.Name = "spm"
app.Usage = "salesforce package manager"
app.Commands = []cli.Command{
{
Name: "install",
Aliases: []string{"i"},
Usage: "install salesforce package",
//Flags: []cli.Flag {
// cli.StringFlag{
// Name: "lang, l",
// Value: "english",
// Usage: "language for the greeting",
// },
//},
Action: func(c *cli.Context) error {
var username string
var password string
fmt.Print("Enter Username: ")
fmt.Scanln(&username)
fmt.Printf("Enter Password: ")
fmt.Scanln(&password)
fmt.Printf("%q %q", username, password)
os.Exit(0)

install("https://" + c.Args().First(), nil)
return nil
},
},
}

app.Run(os.Args)
}

func install(url string, options []string) {
cloneFromRemoteRepository(url, url, options)
deployToSalesforce(url, Config{})
}

func cloneFromRemoteRepository(directory string, url string, option []string) {
r, err := git.NewFilesystemRepository(directory)
err = r.Clone(&git.CloneOptions{
URL: url,
})
if err != nil {
panic(err)
}

// ... retrieving the branch being pointed by HEAD
ref, _ := r.Head()

// ... retrieving the commit object
commit, _ := r.Commit(ref.Hash())

// ... we get all the files from the commit
files, _ := commit.Files()

_, err = r.Head()
err = files.ForEach(func(f *git.File) error {
abs := filepath.Join(directory, f.Name)
dir := filepath.Dir(abs)

os.MkdirAll(dir, 0777)
file, err := os.Create(abs)
if err != nil {
return err
}

defer file.Close()
r, err := f.Reader()
if err != nil {
return err
}

defer r.Close()

if err := file.Chmod(f.Mode); err != nil {
return err
}

_, err = io.Copy(file, r)
return err
})
}

func deployToSalesforce(directory string, config Config) {

}

0 comments on commit 3c5b6d0

Please sign in to comment.