From 865dc14eace30c1960c4623e695f1c6b83c183b7 Mon Sep 17 00:00:00 2001 From: Don Date: Wed, 18 Dec 2019 15:59:48 -0800 Subject: [PATCH] Add boilr template stubs --- cmd/drone-npm/config.go | 29 +++++++++++++++++++++ cmd/drone-npm/main.go | 58 +++++++++++++++++++++++++++++++++++++++++ pkg/npm/plugin.go | 26 ++++++++++++++++++ pkg/npm/plugin_impl.go | 21 +++++++++++++++ pkg/npm/plugin_test.go | 12 +++++++++ 5 files changed, 146 insertions(+) create mode 100644 cmd/drone-npm/config.go create mode 100644 cmd/drone-npm/main.go create mode 100644 pkg/npm/plugin.go create mode 100644 pkg/npm/plugin_impl.go create mode 100644 pkg/npm/plugin_test.go diff --git a/cmd/drone-npm/config.go b/cmd/drone-npm/config.go new file mode 100644 index 0000000..fa85828 --- /dev/null +++ b/cmd/drone-npm/config.go @@ -0,0 +1,29 @@ +// Copyright (c) 2019, the Drone Plugins project authors. +// Please see the AUTHORS file for details. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license that can be +// found in the LICENSE file. + +package main + +import ( + "github.com/urfave/cli/v2" + + "github.com/drone-plugins/drone-npm/pkg/npm" +) + +const ( + // Add all the flag names here as const strings. +) + +// settingsFlags has the cli.Flags for the plugin.Settings. +func settingsFlags() []cli.Flag { + // Replace below with all the flags required for the plugin's specific + // settings. + return []cli.Flag{} +} + +// settingsFromContext creates a plugin.Settings from the cli.Context. +func settingsFromContext(ctx *cli.Context) npm.Settings { + // Replace below with the parsing of the + return npm.Settings{} +} diff --git a/cmd/drone-npm/main.go b/cmd/drone-npm/main.go new file mode 100644 index 0000000..130e64b --- /dev/null +++ b/cmd/drone-npm/main.go @@ -0,0 +1,58 @@ +// Copyright (c) 2019, the Drone Plugins project authors. +// Please see the AUTHORS file for details. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license that can be +// found in the LICENSE file. + +// DO NOT MODIFY THIS FILE DIRECTLY + +package main + +import ( + "os" + + "github.com/drone-plugins/drone-plugin-lib/pkg/urfave" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + + "github.com/drone-plugins/drone-npm/pkg/npm" +) + +var ( + version = "unknown" +) + +func main() { + app := cli.NewApp() + app.Name = "npm plugin" + app.Usage = "pushes a package to a npm repository" + app.Action = run + app.Flags = append(settingsFlags(), urfave.Flags()...) + + // Run the application + if err := app.Run(os.Args); err != nil { + logrus.Fatal(err) + } +} + +func run(ctx *cli.Context) error { + urfave.LoggingFromContext(ctx) + + plugin := npm.New( + settingsFromContext(ctx), + urfave.PipelineFromContext(ctx), + urfave.NetworkFromContext(ctx), + ) + + // Validate the settings + if err := plugin.Validate(); err != nil { + return errors.Wrap(err, "validation failed") + } + + // Run the plugin + if err := plugin.Exec(); err != nil { + return errors.Wrap(err, "exec failed") + } + + return nil +} diff --git a/pkg/npm/plugin.go b/pkg/npm/plugin.go new file mode 100644 index 0000000..21a1cfd --- /dev/null +++ b/pkg/npm/plugin.go @@ -0,0 +1,26 @@ +// Copyright (c) 2019, the Drone Plugins project authors. +// Please see the AUTHORS file for details. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license that can be +// found in the LICENSE file. + +package npm + +import ( + "github.com/drone-plugins/drone-plugin-lib/pkg/plugin" + "github.com/drone-plugins/drone-plugin-lib/pkg/urfave" +) + +type pluginImpl struct { + settings Settings + pipeline plugin.Pipeline + network urfave.Network +} + +// New Plugin from the given Settings, Pipeline, and Network. +func New(settings Settings, pipeline plugin.Pipeline, network urfave.Network) plugin.Plugin { + return &pluginImpl{ + settings: settings, + pipeline: pipeline, + network: network, + } +} diff --git a/pkg/npm/plugin_impl.go b/pkg/npm/plugin_impl.go new file mode 100644 index 0000000..d91d8fc --- /dev/null +++ b/pkg/npm/plugin_impl.go @@ -0,0 +1,21 @@ +// Copyright (c) 2019, the Drone Plugins project authors. +// Please see the AUTHORS file for details. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license that can be +// found in the LICENSE file. + +package npm + +// Settings for the Plugin. +type Settings struct { + // Fill in the data structure with appropriate values +} + +func (p *pluginImpl) Validate() error { + // Validate the Config and return an error if there are issues. + return nil +} + +func (p *pluginImpl) Exec() error { + // Implementation of the plugin. + return nil +} diff --git a/pkg/npm/plugin_test.go b/pkg/npm/plugin_test.go new file mode 100644 index 0000000..dffdf4a --- /dev/null +++ b/pkg/npm/plugin_test.go @@ -0,0 +1,12 @@ +// Copyright (c) 2019, the Drone Plugins project authors. +// Please see the AUTHORS file for details. All rights reserved. +// Use of this source code is governed by an Apache 2.0 license that can be +// found in the LICENSE file. + +package npm + +import "testing" + +func TestPlugin(t *testing.T) { + t.Skip() +}