Skip to content

Commit 3c2ea56

Browse files
committed
feat: export defaultConfig
1 parent 268a3f7 commit 3c2ea56

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

mod.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// export * from "./src/deps.ts";
22
export * from "./src/compress.ts";
33
export * from "./src/decompress.ts";
4+
export * from "./src/config.ts";
45
import { tar, zip } from "./src/compress.ts";
56
import {
67
Command,
@@ -17,7 +18,8 @@ import {
1718
} from "./src/deps.ts";
1819
import { version } from "./src/version.ts";
1920
import { untar, unzip } from "./src/decompress.ts";
20-
type ExternalSkip = Array<string | RegExp>;
21+
import { defaultConfig } from "./src/config.ts";
22+
import type { Config } from "./src/config.ts";
2123

2224
if (import.meta.main) {
2325
const types = new EnumType(["tar", "zip"]);
@@ -110,16 +112,11 @@ export async function mayBeExists(output: string) {
110112

111113
export async function walkFiles(
112114
dir: string,
113-
externalskip: ExternalSkip = [],
115+
externalskip = defaultConfig.skip,
114116
) {
115117
const files: string[] = [];
116-
const skip = [
117-
/(?<=[\\\/])(node_modules|temp|cache|dist|\.(nuxt|nitro|output))(?=[\\\/])/,
118-
];
119118

120-
externalskip?.forEach((s) => {
121-
skip.push(typeof s === "string" ? new RegExp(s) : s);
122-
});
119+
const skip = externalskip?.map((s) => typeof s === "string" ? new RegExp(s) : s)
123120

124121
for await (
125122
const entry of walk(dir, {
@@ -137,9 +134,7 @@ export async function walkFiles(
137134

138135
export async function loadConfig() {
139136
const { loadConfig: _loadConfig } = await import("npm:c12@1.5.1");
140-
const { config } = await _loadConfig<
141-
{ skip?: ExternalSkip; name?: string }
142-
>({
137+
const { config } = await _loadConfig<Config>({
143138
name: "nzip",
144139
packageJson: true,
145140
});
@@ -156,7 +151,7 @@ export async function loadOptions(options: Options) {
156151

157152
if (options.withConfig) {
158153
const config = await loadConfig();
159-
const name = config?.name ?? "default";
154+
const name = config?.name ?? defaultConfig.name
160155
const output = `${name}.${options.type}`;
161156
const externalSkip = config?.skip ?? [];
162157
return {

src/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export type ExternalSkip = Array<string | RegExp>;
2+
3+
export interface Config {
4+
name?: string;
5+
skip?: ExternalSkip;
6+
}
7+
8+
export const defaultConfig: Config = {
9+
name: "default",
10+
skip: [
11+
/(?<=[\\\/])(node_modules|temp|cache|dist|\.(nuxt|nitro|output))(?=[\\\/])/,
12+
],
13+
};

0 commit comments

Comments
 (0)