mirror of
https://github.com/drone-plugins/drone-npm.git
synced 2026-06-04 18:23:52 +08:00
Added support for setting tag on npm publish
This commit is contained in:
@@ -11,6 +11,8 @@ The following parameters are used to configure the plugin:
|
||||
* **registry** - the registry URL to use (https://registry.npmjs.org by default)
|
||||
* **folder** - the folder, relative to the workspace, containing the library
|
||||
(uses the workspace directory, by default)
|
||||
* **tag** - the tag to use when publishing the package (does not set
|
||||
one by default)
|
||||
|
||||
The following secret values can be set to configure the plugin.
|
||||
|
||||
|
||||
@@ -58,6 +58,11 @@ func main() {
|
||||
Name: "env-file",
|
||||
Usage: "source env file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tag",
|
||||
Usage: "NPM publish tag",
|
||||
EnvVar: "PLUGIN_TAG",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -79,6 +84,7 @@ func run(c *cli.Context) error {
|
||||
Registry: c.String("registry"),
|
||||
Folder: c.String("folder"),
|
||||
SkipVerify: c.Bool("skip_verify"),
|
||||
Tag: c.String("tag"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ type (
|
||||
Registry string
|
||||
Folder string
|
||||
SkipVerify bool
|
||||
Tag string
|
||||
}
|
||||
|
||||
npmPackage struct {
|
||||
@@ -81,7 +82,7 @@ func (p Plugin) Exec() error {
|
||||
log.Info("Publishing package")
|
||||
|
||||
// run the publish command
|
||||
return runCommand(publishCommand(), p.Config.Folder)
|
||||
return runCommand(publishCommand(p.Config), p.Config.Folder)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -307,8 +308,12 @@ func packageVersionsCommand(name string) *exec.Cmd {
|
||||
}
|
||||
|
||||
// publishCommand runs the publish command
|
||||
func publishCommand() *exec.Cmd {
|
||||
return exec.Command("npm", "publish")
|
||||
func publishCommand(config Config) *exec.Cmd {
|
||||
if len(config.Tag) == 0 {
|
||||
return exec.Command("npm", "publish");
|
||||
} else {
|
||||
return exec.Command("npm", "publish", "--tag", config.Tag);
|
||||
}
|
||||
}
|
||||
|
||||
// trace writes each command to standard error (preceded by a ‘$ ’) before it
|
||||
|
||||
Reference in New Issue
Block a user