Skip to content

🗜️ Archive

Creates an archive file (ZIP format, without development dependencies) for the current project. Equivalent to running composer archive --format=zip --dir=<destination>.

When to use

Use when you need to package the project into a distributable archive (e.g. for delivery to a customer or upload to an artifact repository).

Signature

go
func (c *Composer) Archive(destination string) (string, error)

Parameters

ParameterTypeDescription
destinationstringTarget directory path where the archive file is stored

Return value

Return valueTypeDescription
First return valuestringOutput of the archive command
Second return valueerrorReturned when archive creation fails

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)
	}

	output, err := comp.Archive("/tmp/project-archive")
	if err != nil {
		log.Fatalf("failed to create archive: %v", err)
	}
	fmt.Println("Archive result:", output)
}

Advanced

  • To specify other formats such as tar, use the sibling method ArchiveWithFormat from ArchiveWithFormat.
  • To archive a specific package (rather than the whole project), use ArchivePackage.
  • When you need to customize multiple options, use ArchiveWithOptions (located in archive.go).

Released under the MIT License