From 5950ea04507171262ffdffbad49a733c4e03a04f Mon Sep 17 00:00:00 2001 From: lotus64yt Date: Sun, 17 May 2026 00:03:05 +0200 Subject: [PATCH] feat: support includes settings in orion config for deploy --- src/commands/deploy.ts | 2 +- src/utils/files.ts | 22 ++++++++++++++++++++++ src/utils/zip.ts | 39 +++++++++++++++++++++++++-------------- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/utils/files.ts diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index c6913f5..8773d95 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -138,7 +138,7 @@ async function compressFiles(_ctx: Context, config: DeploymentConfig) { try { await makeDirectory(config.archivePath); - await zipDirectory(config.projectDir, config.archivePath, config.project.userConfig.deploy?.exclude ?? []); + await zipDirectory(config.projectDir, config.archivePath, config.project.userConfig.deploy?.exclude ?? [], config.project.userConfig.deploy?.include ?? []); const sizeMb = statSync(config.archivePath).size / 1024 / 1024; const sizeMbString = sizeMb.toFixed(2); diff --git a/src/utils/files.ts b/src/utils/files.ts new file mode 100644 index 0000000..d5ea577 --- /dev/null +++ b/src/utils/files.ts @@ -0,0 +1,22 @@ +import { readdirSync, statSync } from "node:fs"; +import { join } from "node:path"; + +export function getAllFiles(dirPath: string, basePath = ""): string[] { + let results: string[] = []; + const list = readdirSync(dirPath); + + list.forEach((file) => { + const filePath = join(dirPath, file); + const stat = statSync(filePath); + + const relativePath = basePath ? join(basePath, file) : file; + + if (stat && stat.isDirectory()) { + results = results.concat(getAllFiles(filePath, relativePath)); + } else { + results.push(relativePath); + } + }); + + return results; +} \ No newline at end of file diff --git a/src/utils/zip.ts b/src/utils/zip.ts index 4804814..b9cb310 100644 --- a/src/utils/zip.ts +++ b/src/utils/zip.ts @@ -1,12 +1,15 @@ import { createWriteStream } from "node:fs"; import archiver from "archiver"; +import { minimatch } from "minimatch"; +import { getAllFiles } from "./files"; +import { join } from "node:path"; const DEFAULT_IGNORE = ["node_modules", ".git"]; /** * Zip a directory. */ -export function zipDirectory(sourceDir: string, outputPath: string, ignore: string[]): Promise { +export function zipDirectory(sourceDir: string, outputPath: string, ignore: string[], include: string[]): Promise { return new Promise((resolve, reject) => { const output = createWriteStream(outputPath); const archive = archiver("zip", { zlib: { level: 9 } }); @@ -20,24 +23,32 @@ export function zipDirectory(sourceDir: string, outputPath: string, ignore: stri archive.on("error", reject); archive.pipe(output); - archive.glob("**/*", { - cwd: sourceDir, - ignore: allIgnore.flatMap(p => { - if (p.includes("/") || p.includes("**")) return [p]; - if (p.startsWith("*.")) return [`**/${p}`]; - return [`**/${p}`, `**/${p}/**`, `${p}`, `${p}/**`]; - }), - dot: true, - }); + const allFiles = getAllFiles(sourceDir, ""); + + for (const filePath of allFiles) { + const isIgnored = allIgnore.some(pattern => + minimatch(filePath, pattern, { dot: true, matchBase: true }) || + minimatch(filePath + "/**", pattern, { dot: true }) + ); + + if (isIgnored) continue; + + if (include.length > 0) { + const isIncluded = include.some(pattern => + minimatch(filePath, pattern, { dot: true, matchBase: true }) + ); + + if (!isIncluded) continue; + } + + const fullPath = join(sourceDir, filePath); + archive.file(fullPath, { name: filePath }); + } archive.finalize(); }); } -// Paths patterns utils - -import { minimatch } from "minimatch"; - export function getDeletableFiles(rootFiles: string[], exclude: string[]) { const toDelete = rootFiles.filter(item => { const shouldIgnore = exclude.some(