z-packer 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-PRESENT OSpoon <https://github.com/OSpoon/zip-code>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # z-packer
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![License][license-src]][license-href]
7
+
8
+ A CLI tool to compress code projects while strictly respecting your `.gitignore`.
9
+
10
+ ## Features
11
+
12
+ - 🛠️ **Universal Support**: Works for any Git-managed project (Node.js, Python, Rust, C++, Go, etc.).
13
+ - 🔍 **Strict Filtering**: Automatically reads and follows `.gitignore` rules in the root and subdirectories.
14
+ - 🛡️ **Recursion Prevention**: Intelligently excludes the archive being generated while preserving other existing zip files.
15
+ - 📦 **Clean Archive**: Only packages necessary source files, excluding build artifacts and dependencies.
16
+ - 📊 **Visual Feedback**: Real-time progress bar and a detailed file summary table.
17
+ - 🚀 **Professional UX**: Powered by `archiver`, `globby`, and `chalk` for a premium terminal experience.
18
+
19
+ ## Usage
20
+
21
+ You can run `z-packer` directly without installation using `npx`:
22
+
23
+ ```bash
24
+ npx z-packer [directory]
25
+ ```
26
+
27
+ Or install it globally:
28
+
29
+ ```bash
30
+ pnpm add -g z-packer
31
+ # then
32
+ z-packer .
33
+ ```
34
+
35
+ ### Options
36
+
37
+ | Option | Description |
38
+ | :--- | :--- |
39
+ | `input` | Target directory to archive (defaults to `.`) |
40
+ | `--help` | Show help information |
41
+ | `--version` | Show version number |
42
+
43
+ ## Development
44
+
45
+ ```bash
46
+ # Install dependencies
47
+ pnpm install
48
+
49
+ # Build the project
50
+ pnpm run build
51
+
52
+ # Run in development
53
+ pnpm start pack .
54
+ ```
55
+
56
+ ## License
57
+
58
+ [MIT](./LICENSE) License © 2024-PRESENT [OSpoon](https://github.com/OSpoon)
59
+
60
+ <!-- Badges -->
61
+ [npm-version-src]: https://img.shields.io/npm/v/z-packer?style=flat&colorA=080f12&colorB=1fa669
62
+ [npm-version-href]: https://npmjs.com/package/z-packer
63
+ [npm-downloads-src]: https://img.shields.io/npm/dm/z-packer?style=flat&colorA=080f12&colorB=1fa669
64
+ [npm-downloads-href]: https://npmjs.com/package/z-packer
65
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/z-packer?style=flat&colorA=080f12&colorB=1fa669&label=minzip
66
+ [bundle-href]: https://bundlephobia.com/result?p=z-packer
67
+ [license-src]: https://img.shields.io/github/license/OSpoon/z-packer.svg?style=flat&colorA=080f12&colorB=1fa669
68
+ [license-href]: https://github.com/OSpoon/z-packer/blob/main/LICENSE
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/cli.mjs'
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,78 @@
1
+ import { t as compress } from "./compress-CgLYNT__.mjs";
2
+ import process from "node:process";
3
+ import chalk from "chalk";
4
+ import { Presets, SingleBar } from "cli-progress";
5
+ import Table from "cli-table3";
6
+ import { filesize } from "filesize";
7
+ import yargs from "yargs";
8
+
9
+ //#region src/cli.ts
10
+ yargs(process.argv.slice(2)).scriptName("z-packer").usage("$0 [input]").command(["$0 [input]", "pack [input]"], "Compress project (default command)", (y) => {
11
+ return y.positional("input", {
12
+ type: "string",
13
+ default: ".",
14
+ describe: "Project directory"
15
+ });
16
+ }, async (argv) => {
17
+ const input = argv.input;
18
+ let progressBar;
19
+ try {
20
+ const result = await compress({
21
+ input,
22
+ onScan: (path) => {
23
+ console.log(chalk.cyan(`🔍 Scanning project: ${chalk.bold(path)}`));
24
+ },
25
+ onFound: (count) => {
26
+ if (count === 0) console.log(chalk.yellow("⚠️ No files found (check your .gitignore rules)"));
27
+ else console.log(chalk.green(`✅ Found ${chalk.bold(count)} files`));
28
+ },
29
+ onStart: (outputPath) => {
30
+ console.log(chalk.cyan(`📦 Creating archive: ${chalk.bold(outputPath)}`));
31
+ progressBar = new SingleBar({
32
+ format: `${chalk.cyan("Compressing")} {bar} | {percentage}% | {value}/{total} files`,
33
+ hideCursor: true
34
+ }, Presets.shades_classic);
35
+ },
36
+ onProgress: (current, total) => {
37
+ if (progressBar) {
38
+ if (current === 1) progressBar.start(total, 0);
39
+ progressBar.update(current);
40
+ }
41
+ }
42
+ });
43
+ if (progressBar) progressBar.stop();
44
+ if (result.files.length > 0) {
45
+ if (result.files.length <= 20) {
46
+ const table = new Table({
47
+ head: [
48
+ chalk.cyan("Filename"),
49
+ chalk.cyan("Size"),
50
+ chalk.cyan("Status")
51
+ ],
52
+ colWidths: [
53
+ 40,
54
+ 15,
55
+ 12
56
+ ]
57
+ });
58
+ for (const file of result.files) table.push([
59
+ file.name,
60
+ filesize(file.size),
61
+ chalk.gray(file.status)
62
+ ]);
63
+ console.log(`\n${table.toString()}`);
64
+ }
65
+ console.log(chalk.green("\n✨ Project archived successfully!"));
66
+ console.log(chalk.white(` Archive: ${chalk.bold(result.zipName)}`));
67
+ console.log(chalk.white(` Total Size: ${chalk.bold(filesize(result.totalSize))}`));
68
+ }
69
+ console.log();
70
+ } catch (error) {
71
+ if (progressBar) progressBar.stop();
72
+ console.error(chalk.red("\n❌ Compression failed:"), error);
73
+ process.exit(1);
74
+ }
75
+ }).showHelpOnFail(false).help().parse();
76
+
77
+ //#endregion
78
+ export { };
@@ -0,0 +1,75 @@
1
+ import { createWriteStream } from "node:fs";
2
+ import { basename, join } from "node:path";
3
+ import process from "node:process";
4
+ import archiver from "archiver";
5
+ import fs from "fs-extra";
6
+ import { globby } from "globby";
7
+
8
+ //#region src/compress.ts
9
+ async function compress(options) {
10
+ const { input, output = ".", name } = options;
11
+ const absoluteInput = join(process.cwd(), input);
12
+ let projectName = basename(absoluteInput);
13
+ let projectVersion = "";
14
+ const pkgPath = join(absoluteInput, "package.json");
15
+ if (await fs.pathExists(pkgPath)) try {
16
+ const pkg = await fs.readJson(pkgPath);
17
+ if (pkg.name) projectName = pkg.name;
18
+ if (pkg.version) projectVersion = `_v${pkg.version}`;
19
+ } catch {}
20
+ const zipName = name || `${projectName}${projectVersion}.zip`;
21
+ const outputPath = join(process.cwd(), output, zipName);
22
+ options.onScan?.(absoluteInput);
23
+ const files = await globby(["**/*", `!${zipName}`], {
24
+ cwd: absoluteInput,
25
+ gitignore: true,
26
+ dot: true
27
+ });
28
+ options.onFound?.(files.length);
29
+ if (files.length === 0) return {
30
+ zipName,
31
+ outputPath,
32
+ totalSize: 0,
33
+ files: []
34
+ };
35
+ options.onStart?.(outputPath);
36
+ const outputStream = createWriteStream(outputPath);
37
+ const archive = archiver("zip", { zlib: { level: 9 } });
38
+ const fileResults = [];
39
+ return new Promise((resolve, reject) => {
40
+ outputStream.on("close", () => {
41
+ resolve({
42
+ zipName,
43
+ outputPath,
44
+ totalSize: fs.statSync(outputPath).size,
45
+ files: fileResults
46
+ });
47
+ });
48
+ archive.on("error", (err) => {
49
+ reject(err);
50
+ });
51
+ archive.on("entry", () => {});
52
+ archive.pipe(outputStream);
53
+ (async () => {
54
+ let current = 0;
55
+ for (const file of files) {
56
+ const filePath = join(absoluteInput, file);
57
+ const stats = await fs.stat(filePath);
58
+ const content = await fs.readFile(filePath);
59
+ archive.append(content, { name: file });
60
+ current++;
61
+ fileResults.push({
62
+ name: file,
63
+ size: stats.size,
64
+ status: "OK"
65
+ });
66
+ options.onEntry?.(file, stats.size);
67
+ options.onProgress?.(current, files.length);
68
+ }
69
+ archive.finalize();
70
+ })().catch(reject);
71
+ });
72
+ }
73
+
74
+ //#endregion
75
+ export { compress as t };
@@ -0,0 +1,25 @@
1
+ //#region src/compress.d.ts
2
+ interface FileStatus {
3
+ name: string;
4
+ size: number;
5
+ status: 'OK' | 'ERROR';
6
+ }
7
+ interface CompressResult {
8
+ zipName: string;
9
+ outputPath: string;
10
+ totalSize: number;
11
+ files: FileStatus[];
12
+ }
13
+ interface CompressOptions {
14
+ input: string;
15
+ output?: string;
16
+ name?: string;
17
+ onScan?: (absoluteInput: string) => void;
18
+ onFound?: (count: number) => void;
19
+ onStart?: (outputPath: string) => void;
20
+ onProgress?: (current: number, total: number) => void;
21
+ onEntry?: (file: string, size: number) => void;
22
+ }
23
+ declare function compress(options: CompressOptions): Promise<CompressResult>;
24
+ //#endregion
25
+ export { CompressOptions, CompressResult, FileStatus, compress };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as compress } from "./compress-CgLYNT__.mjs";
2
+
3
+ export { compress };
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "z-packer",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "A CLI tool to compress code projects while strictly respecting your .gitignore.",
6
+ "author": "OSpoon",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/OSpoon/z-packer#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/OSpoon/z-packer.git"
12
+ },
13
+ "bugs": "https://github.com/OSpoon/z-packer/issues",
14
+ "keywords": [],
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": "./dist/index.mjs",
18
+ "./cli": "./dist/cli.mjs",
19
+ "./package.json": "./package.json"
20
+ },
21
+ "types": "./dist/index.d.mts",
22
+ "bin": {
23
+ "z-packer": "./bin/z-packer.mjs"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "dependencies": {
29
+ "archiver": "^7.0.1",
30
+ "chalk": "^5.6.2",
31
+ "cli-progress": "^3.12.0",
32
+ "cli-table3": "^0.6.5",
33
+ "filesize": "^11.0.13",
34
+ "fs-extra": "^11.3.3",
35
+ "globby": "^14.1.0",
36
+ "yargs": "^18.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@antfu/eslint-config": "^7.2.0",
40
+ "@antfu/ni": "^28.0.0",
41
+ "@antfu/utils": "^9.3.0",
42
+ "@types/archiver": "^6.0.3",
43
+ "@types/cli-progress": "^3.11.6",
44
+ "@types/fs-extra": "^11.0.4",
45
+ "@types/node": "^25.0.1",
46
+ "@types/yargs": "^17.0.35",
47
+ "bumpp": "^10.3.2",
48
+ "eslint": "^9.10.0",
49
+ "lint-staged": "^16.2.7",
50
+ "publint": "^0.3.16",
51
+ "simple-git-hooks": "^2.13.1",
52
+ "tinyexec": "^1.0.2",
53
+ "tsdown": "^0.20.3",
54
+ "tsx": "^4.21.0",
55
+ "typescript": "^5.9.3",
56
+ "vite": "^7.2.7",
57
+ "vitest": "^3.0.0",
58
+ "vitest-package-exports": "^0.1.1",
59
+ "yaml": "^2.8.2"
60
+ },
61
+ "simple-git-hooks": {
62
+ "pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && npx lint-staged"
63
+ },
64
+ "lint-staged": {
65
+ "*": "eslint --fix"
66
+ },
67
+ "scripts": {
68
+ "build": "tsdown",
69
+ "dev": "tsdown --watch",
70
+ "lint": "eslint",
71
+ "release": "bumpp",
72
+ "start": "tsx src/index.ts",
73
+ "test": "vitest",
74
+ "typecheck": "tsc"
75
+ }
76
+ }