ddonche/goblin-lang
0.46.24
1
0
docs keyword
[[zip-dir]]

zip_dir


zip_dir creates a zip archive from a directory on disk. It is a mutation action, so it must be used with the ! operator.


Syntax

:zip_dir!(source_dir, destination_zip)
:zip_dir!(source_dir, destination_zip)


Behavior

  • Recursively reads all files and directories inside source_dir
  • Creates a zip archive at destination_zip
  • Stores only the contents of source_dir (no wrapper folder)
  • Overwrites the destination zip file if it already exists

Example

:zip_dir!("dist/vekke", "data/backups/vekke/2026-03-23_15-40-00.zip")
:zip_dir!("dist/vekke", "data/backups/vekke/2026-03-23_15-40-00.zip")

If dist/vekke contains:

index.html
docs/
assets/
index.html
docs/
assets/

The resulting zip will contain:

index.html
docs/
assets/
index.html
docs/
assets/


Common Use Cases

Backup Before Rebuild

act backup_and_rebuild(portal)
    backup_dir | "data/backups/{portal}"
    timestamp  | :now()
    zip_path   | "{backup_dir}/{timestamp}.zip"

    :create_dir!(backup_dir)
    :zip_dir!("dist/{portal}", zip_path)
    :delete_path!("dist/{portal}")

    return :build(portal)
xx
act backup_and_rebuild(portal)
    backup_dir | "data/backups/{portal}"
    timestamp  | :now()
    zip_path   | "{backup_dir}/{timestamp}.zip"

    :create_dir!(backup_dir)
    :zip_dir!("dist/{portal}", zip_path)
    :delete_path!("dist/{portal}")

    return :build(portal)
xx

Archiving Generated Output

:zip_dir!("dist/site", "site_backup.zip")
:zip_dir!("dist/site", "site_backup.zip")


Requirements

  • source_dir must exist
  • source_dir must be a directory
  • The destination path must be writable

If any of these conditions fail, an error is raised.


Error Behavior

Missing Bang Operator

:zip_dir("dist/vekke", "backup.zip")
:zip_dir("dist/vekke", "backup.zip")

Error:

‘zip_dir’ requires the bang form: use zip_dir!(…)
‘zip_dir’ requires the bang form: use zip_dir!(…)


Invalid Source Directory

:zip_dir!("missing_dir", "backup.zip")
:zip_dir!("missing_dir", "backup.zip")

Error:

source directory does not exist or is not a directory
source directory does not exist or is not a directory


Notes

  • The archive contains only the contents of the directory, not the directory itself
  • This makes restoration straightforward when targeting a specific output directory
  • File paths are normalized for cross-platform compatibility

Best Practices

1. Use Before Destructive Operations

:zip_dir!("dist/{portal}", backup_path)
:delete_path!("dist/{portal}")
:zip_dir!("dist/{portal}", backup_path)
:delete_path!("dist/{portal}")

Always back up before deleting build output.

2. Store Backups Outside dist

data/backups/goblin/...
data/backups/goblin/...

Avoid placing backups inside dist/ to prevent accidental serving or deletion.

3. Use Timestamps for Versioning

"{portal}_{:now()}.zip"
"{portal}_{:now()}.zip"

Ensures unique and ordered backups.


Summary

Feature Behavior
Mutation required Yes (!)
Recursion Yes
Includes root folder No
Overwrites destination Yes

zip_dir provides a simple, reliable way to archive directory contents for backup and deployment workflows.