/
bundler.go
59 lines (52 loc) · 1.34 KB
/
bundler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors
// Package bundler defines behavior for bundling packages
package bundler
import (
"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/uds-cli/src/types"
)
// Bundler is used for bundling packages
type Bundler struct {
bundle *types.UDSBundle
output string
tmpDstDir string
sourceDir string
}
// Pusher is the interface for pushing bundles
type Pusher interface {
}
// Options are the options for creating a bundler
type Options struct {
Bundle *types.UDSBundle
Output string
TmpDstDir string
SourceDir string
}
// NewBundler creates a new bundler
func NewBundler(opts *Options) *Bundler {
b := Bundler{
bundle: opts.Bundle,
output: opts.Output,
tmpDstDir: opts.TmpDstDir,
sourceDir: opts.SourceDir,
}
return &b
}
// Create creates a bundle
func (b *Bundler) Create() error {
if utils.IsRegistryURL(b.output) {
remoteBundle := NewRemoteBundle(&RemoteBundleOpts{Bundle: b.bundle, Output: b.output})
err := remoteBundle.create(nil)
if err != nil {
return err
}
} else {
localBundle := NewLocalBundle(&LocalBundleOpts{Bundle: b.bundle, TmpDstDir: b.tmpDstDir, SourceDir: b.sourceDir, OutputDir: b.output})
err := localBundle.create(nil)
if err != nil {
return err
}
}
return nil
}