github.com/kvattikuti/drone@v0.2.1-0.20140603034306-d400229a327a/pkg/plugin/publish/npm.go (about) 1 package publish 2 3 import ( 4 "fmt" 5 6 "github.com/drone/drone/pkg/build/buildfile" 7 ) 8 9 // use npm trick instead of running npm adduser that requires stdin 10 var npmLoginCmd = ` 11 cat <<EOF > ~/.npmrc 12 _auth = $(echo "%s:%s" | tr -d "\r\n" | base64) 13 email = %s 14 EOF 15 ` 16 17 type NPM struct { 18 // The Email address used by NPM to connect 19 // and publish to a repository 20 Email string `yaml:"email,omitempty"` 21 22 // The Username used by NPM to connect 23 // and publish to a repository 24 Username string `yaml:"username,omitempty"` 25 26 // The Password used by NPM to connect 27 // and publish to a repository 28 Password string `yaml:"password,omitempty"` 29 30 // Fails if the package name and version combination already 31 // exists in the registry. Overwrites when the "--force" flag is set. 32 Force bool `yaml:"force"` 33 34 // The registry URL of custom npm repository 35 Registry string `yaml:"registry,omitempty"` 36 37 // A folder containing the package.json file 38 Folder string `yaml:"folder,omitempty"` 39 40 // Registers the published package with the given tag 41 Tag string `yaml:"tag,omitempty"` 42 43 Branch string `yaml:"branch,omitempty"` 44 } 45 46 func (n *NPM) Write(f *buildfile.Buildfile) { 47 48 if len(n.Email) == 0 || len(n.Username) == 0 || len(n.Password) == 0 { 49 return 50 } 51 52 npmPublishCmd := "npm publish %s" 53 54 if n.Tag != "" { 55 npmPublishCmd += fmt.Sprintf(" --tag %s", n.Tag) 56 } 57 58 if n.Force { 59 npmPublishCmd += " --force" 60 } 61 62 f.WriteCmdSilent("echo 'publishing to NPM ...'") 63 64 // Login to registry 65 f.WriteCmdSilent(fmt.Sprintf(npmLoginCmd, n.Username, n.Password, n.Email)) 66 67 // Setup custom npm registry 68 if n.Registry != "" { 69 f.WriteCmdSilent(fmt.Sprintf("npm config set registry %s", n.Registry)) 70 } 71 72 f.WriteCmd(fmt.Sprintf(npmPublishCmd, n.Folder)) 73 }