Build Directory Archiver
zip-build is a specialized Node.js command-line utility designed for automating the archival of project build artifacts. It streamlines the process of zipping or tarring a specified output directory, making it particularly useful for deployment pipelines or versioned backups. The package automatically generates archive filenames based on the project's `name` and `version` fields extracted from `package.json`, and can optionally include a timestamp for uniqueness. Currently, at version 1.8.0, it demonstrates active maintenance through its GitHub repository, though a formal release cadence is not explicitly defined. Its key differentiators include flexible output formatting (supporting both `.zip` and `.tar`), customizable filename templating, and an optional interactive mode for guided execution. It primarily serves as a `devDependency` to be integrated into `npm scripts` for an automated build workflow, rather than offering a direct programmatic API for `import` into JavaScript or TypeScript modules.
Common errors
-
Error: Command failed with exit code 1: zip-build
cause The `zip-build` command was invoked, but either the source `buildDir` did not exist, or the destination `zipDir` was invalid, or an existing archive prevented creation without the `--override` flag.fixEnsure the `buildDir` exists before running the command. Check that `zipDir` is a valid path. If an archive already exists at the target, add the `--override` flag (e.g., `zip-build my-build my-dist --override`). -
zip-build: command not found
cause The `zip-build` package is not installed globally, or it's a local `devDependency` and the command is not being run from an npm script or via `npx`.fixInstall it as a devDependency (`npm install --save-dev zip-build`) and then run it via an npm script (e.g., `"build": "zip-build"` in `package.json` then `npm run build`), or use `npx zip-build` to execute it directly. -
Error: EEXIST: file already exists, 'my-project_1.0.0_TIMESTAMP.zip'
cause An archive with the generated filename already exists in the target `zipDir`, and the `--override` flag was not used to permit overwriting.fixTo allow overwriting existing archives, add the `--override` flag to your `zip-build` command (e.g., `zip-build --override`). Alternatively, modify the `--template` option to ensure unique filenames.
Warnings
- gotcha By default, `zip-build` will not override an existing archive file. If an output file with the generated name already exists in the `zipDir`, the command will fail.
- gotcha The default `buildDir` is `build` and `zipDir` is `dist`. If your project uses different directory names, `zip-build` will not find them or place the archive correctly.
- gotcha The `--name` option, which allows asking for a custom output archive filename, requires the `--interactive` flag to also be enabled. Using `--name` without `--interactive` will have no effect.
- gotcha This package is designed as a Command-Line Interface (CLI) tool. It does not expose a stable or documented programmatic API for direct `import` or `require` into JavaScript/TypeScript modules. Attempts to use it this way are unsupported.
Install
-
npm install zip-build -
yarn add zip-build -
pnpm add zip-build
Imports
- zipBuild
import { zipBuild } from 'zip-build';This package is a CLI tool, primarily used via npm scripts or direct terminal execution. It does not expose a documented programmatic API for direct JavaScript/TypeScript imports.
- Default Export
import zipBuildCommand from 'zip-build';
This package is a CLI tool and does not provide a default export for programmatic use.
- CommonJS Require
const zipBuild = require('zip-build');This package is a CLI tool and does not expose a CommonJS module for requiring its core functionality.
Quickstart
// package.json snippet to demonstrate integration into a build workflow
// Add this 'scripts' block to your project's package.json:
/*
{
"name": "my-project-name",
"version": "1.2.3",
"scripts": {
"clean": "rm -rf dist build",
"prebuild": "npm run clean",
"build": "mkdir build && echo 'Hello, this is a build artifact!' > build/main.txt && zip-build build dist --format zip --template 'app_%VERSION%_release_%TIMESTAMP%.%EXT%' --override",
"postbuild": "echo 'Build and archiving complete! Check the dist directory.'",
"test-zip": "npm run build && ls dist"
},
"devDependencies": {
"zip-build": "^1.8.0"
}
}
*/
// To run this quickstart example:
// 1. Ensure 'zip-build' is installed as a devDependency in your project:
// npm install --save-dev zip-build
// 2. Add the provided 'scripts' block to your project's package.json file.
// 3. Open your terminal in the project root and run:
// npm run build
// This will create a 'build' directory, place a dummy file inside, then archive
// that directory into a 'dist' folder with a name like 'app_1.2.3_release_1678886400000.zip'.
// The --override flag ensures it can run multiple times without error.