pack

package
v2.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TemplateTarballURL = "https://codeload.github.com/Shoplazza/Nova-2023/tar.gz/refs/heads/main"

TemplateTarballURL is the public, immutable Nova-2023 main-branch tarball.

Variables

View Source
var (
	// ErrTargetDirNotEmpty rejects extraction into an existing non-empty directory.
	ErrTargetDirNotEmpty = errors.New("target directory already exists and is not empty")
	// ErrTemplateDownload flags a non-200 response from the template host.
	ErrTemplateDownload = errors.New("template download failed")
)

Typed sentinels for CloneTemplate failure classes; callers branch with errors.Is.

View Source
var (
	// ErrUnsafeArchivePath flags a zip entry that would escape the target directory.
	// The wrapping message names the offending entry, not the archive file.
	ErrUnsafeArchivePath = errors.New("unsafe path in archive")
	// ErrSizeLimit flags an archive whose cumulative extracted bytes exceed the limit.
	ErrSizeLimit = errors.New("extracted size limit exceeded")
)

Typed sentinels for Unpack failure classes; callers branch with errors.Is.

View Source
var ThemeDirs = []string{
	"assets", "blocks", "config", "layout",
	"locales", "sections", "snippets", "templates",
}

ThemeDirs lists the 8 standard top-level directories a Shoplazza theme has.

Functions

func CloneTemplate

func CloneTemplate(ctx context.Context, targetDir string) error

CloneTemplate streams the Nova-2023 tarball from GitHub codeload and extracts it into targetDir, stripping the top-level "Shoplazza-Nova-2023-<sha>/" prefix. targetDir must be absent or an empty directory (ErrTargetDirNotEmpty otherwise).

func EnumerateThemeFiles

func EnumerateThemeFiles(srcDir string) ([]string, error)

EnumerateThemeFiles returns the list of forward-slash relative paths under srcDir that fall inside any of the 8 standard ThemeDirs.

func Pack

func Pack(srcDir, outputName string, opts PackOptions) (string, error)

Pack writes a zip archive containing all files under srcDir that belong to a theme directory (per ThemeDirs) and are not excluded by .themeignore. Returns the absolute path to the produced zip.

func Unpack

func Unpack(zipPath, targetDir string, opts UnpackOptions) error

Unpack extracts zipPath into targetDir. See UnpackOptions for semantics. Existing files are always overwritten.

Types

type Ignorer

type Ignorer interface {
	MatchesPath(rel string) bool
}

Ignorer matches relative (forward-slash) paths against compiled .themeignore rules, hiding the third-party gitignore type from callers.

func LoadThemeIgnorer

func LoadThemeIgnorer(srcDir, explicitPath string) (Ignorer, error)

LoadThemeIgnorer compiles the .themeignore matcher with the same PackOptions.IgnoreFile semantics Pack uses ("" → auto-detect at srcDir, "/dev/null" → force-disable, explicit path → that file). Returns a nil Ignorer when no ignore file applies — callers must nil-check.

type PackOptions

type PackOptions struct {
	IncludeHidden bool
	// IgnoreFile is the path to a gitignore-syntax ignore file.
	//   "" (empty)              → auto-detect srcDir/.themeignore if present
	//   explicit path           → use that file
	//   "/dev/null" or missing  → force-disable all ignore filtering
	IgnoreFile string
}

PackOptions controls Pack behavior.

type UnpackOptions

type UnpackOptions struct {
	StripTopDir        bool  // If true, strip the first path segment of every entry.
	MaxTotalSize       int64 // Cumulative extracted bytes limit; 0 = default 200 MB.
	PathTraversalCheck bool  // If true, reject entries that escape targetDir.
}

UnpackOptions controls Unpack behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL