Skip to content

🗜️ ArchiveProject

Creates an archive file (e.g. zip or tar) for the current project, equivalent to running composer archive --dir=<directory> --format=<format>.

When to use

Use when you need to package the current project into a distributable archive. You can specify the output directory and compression format. Commonly used for release artifacts or backing up project snapshots.

Signature

go
func (c *Composer) ArchiveProject(directory string, format string) error

Parameters

ParameterTypeDescription
directorystringArchive output directory; pass an empty string to use the current directory
formatstringArchive format, e.g. zip or tar; pass an empty string to use the default format

Return value

error: Returns the corresponding error message if an error occurs while creating the archive; nil on success.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	// Create a zip archive into the ./dist directory
	if err := comp.ArchiveProject("./dist", "zip"); err != nil {
		log.Fatalf("failed to create archive: %v", err)
	}

	fmt.Println("Project archive created")
}

Advanced

  • To create an archive for an arbitrary package/version (rather than the current project), use ArchivePackage(packageName, version, destination).
  • When you need more custom options (e.g. --ignore-filters), use the ArchiveWithOptions variant.
  • When you only want to specify a format without a directory, use ArchiveWithFormat(destination, format).

Released under the MIT License