🗜️ 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
| Parameter | Type | Description |
|---|---|---|
destination | string | Target directory path where the archive file is stored |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Output of the archive command |
| Second return value | error | Returned 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 methodArchiveWithFormatfrom ArchiveWithFormat. - To archive a specific package (rather than the whole project), use ArchivePackage.
- When you need to customize multiple options, use
ArchiveWithOptions(located inarchive.go).