Skip to content

Commit a73f371

Browse files
committed
refactor: organize files into commands and config
1 parent 066f29b commit a73f371

15 files changed

Lines changed: 60 additions & 60 deletions

File tree

src/api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
export { cleanCache } from "./clean";
2-
export { cleanGitCache } from "./clean-git-cache";
31
export { parseArgs } from "./cli/parse-args";
2+
export { cleanCache } from "./commands/clean";
3+
export { cleanGitCache } from "./commands/clean-git-cache";
4+
export { initConfig } from "./commands/init";
5+
export { pruneCache } from "./commands/prune";
6+
export { removeSources } from "./commands/remove";
7+
export { printSyncPlan, runSync } from "./commands/sync";
8+
export { verifyCache } from "./commands/verify";
49
export { loadConfig } from "./config";
510
export { redactRepoUrl } from "./git/redact";
611
export { enforceHostAllowlist, parseLsRemote } from "./git/resolve-remote";
7-
export { initConfig } from "./init";
812
export { DEFAULT_LOCK_FILENAME } from "./lock";
9-
export { pruneCache } from "./prune";
10-
export { removeSources } from "./remove";
1113
export { resolveRepoInput } from "./resolve-repo";
12-
export { printSyncPlan, runSync } from "./sync";
1314
export { applyTargetDir } from "./targets";
14-
export { verifyCache } from "./verify";

src/cli/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const printError = (message: string) => {
5151

5252
const runAdd = async (parsed: Extract<CliCommand, { command: "add" }>) => {
5353
const options = parsed.options;
54-
const { addSources } = await import("../add");
55-
const { runSync } = await import("../sync");
54+
const { addSources } = await import("../commands/add");
55+
const { runSync } = await import("../commands/sync");
5656
if (parsed.entries.length === 0) {
5757
throw new Error(
5858
"Usage: docs-cache add [--source <repo> --target <dir>] <repo...>",
@@ -111,8 +111,8 @@ const runRemove = async (
111111
parsed: Extract<CliCommand, { command: "remove" }>,
112112
) => {
113113
const options = parsed.options;
114-
const { removeSources } = await import("../remove");
115-
const { pruneCache } = await import("../prune");
114+
const { removeSources } = await import("../commands/remove");
115+
const { pruneCache } = await import("../commands/prune");
116116
if (parsed.ids.length === 0) {
117117
throw new Error("Usage: docs-cache remove <id...>");
118118
}
@@ -158,7 +158,7 @@ const runStatus = async (
158158
parsed: Extract<CliCommand, { command: "status" }>,
159159
) => {
160160
const options = parsed.options;
161-
const { getStatus, printStatus } = await import("../status");
161+
const { getStatus, printStatus } = await import("../commands/status");
162162
const status = await getStatus({
163163
configPath: options.config,
164164
cacheDirOverride: options.cacheDir,
@@ -173,7 +173,7 @@ const runStatus = async (
173173

174174
const runClean = async (parsed: Extract<CliCommand, { command: "clean" }>) => {
175175
const options = parsed.options;
176-
const { cleanCache } = await import("../clean");
176+
const { cleanCache } = await import("../commands/clean");
177177
const result = await cleanCache({
178178
configPath: options.config,
179179
cacheDirOverride: options.cacheDir,
@@ -196,7 +196,7 @@ const runCleanCache = async (
196196
parsed: Extract<CliCommand, { command: "clean-cache" }>,
197197
) => {
198198
const options = parsed.options;
199-
const { cleanGitCache } = await import("../clean-git-cache");
199+
const { cleanGitCache } = await import("../commands/clean-git-cache");
200200
const result = await cleanGitCache();
201201
if (options.json) {
202202
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
@@ -224,7 +224,7 @@ const runCleanCache = async (
224224

225225
const runPrune = async (parsed: Extract<CliCommand, { command: "prune" }>) => {
226226
const options = parsed.options;
227-
const { pruneCache } = await import("../prune");
227+
const { pruneCache } = await import("../commands/prune");
228228
const result = await pruneCache({
229229
configPath: options.config,
230230
cacheDirOverride: options.cacheDir,
@@ -247,7 +247,7 @@ const runSyncCommand = async (
247247
parsed: Extract<CliCommand, { command: "sync" }>,
248248
) => {
249249
const options = parsed.options;
250-
const { printSyncPlan, runSync } = await import("../sync");
250+
const { printSyncPlan, runSync } = await import("../commands/sync");
251251
const plan = await runSync({
252252
configPath: options.config,
253253
cacheDirOverride: options.cacheDir,
@@ -269,7 +269,7 @@ const runVerify = async (
269269
parsed: Extract<CliCommand, { command: "verify" }>,
270270
) => {
271271
const options = parsed.options;
272-
const { printVerify, verifyCache } = await import("../verify");
272+
const { printVerify, verifyCache } = await import("../commands/verify");
273273
const report = await verifyCache({
274274
configPath: options.config,
275275
cacheDirOverride: options.cacheDir,
@@ -287,7 +287,7 @@ const runVerify = async (
287287

288288
const runInit = async (parsed: Extract<CliCommand, { command: "init" }>) => {
289289
const options = parsed.options;
290-
const { initConfig } = await import("../init");
290+
const { initConfig } = await import("../commands/init");
291291
if (options.config) {
292292
throw new Error("Init does not accept --config. Use the project root.");
293293
}

src/add.ts renamed to src/commands/add.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import path from "node:path";
2-
import { DEFAULT_CACHE_DIR, type DocsCacheConfig } from "./config";
2+
import { DEFAULT_CACHE_DIR, type DocsCacheConfig } from "../config";
33
import {
44
mergeConfigBase,
55
readConfigAtPath,
66
resolveConfigTarget,
77
writeConfigFile,
8-
} from "./config-io";
9-
import { ensureGitignoreEntry } from "./gitignore";
10-
import { resolveTargetDir } from "./paths";
11-
import { resolveRepoInput } from "./resolve-repo";
12-
import { assertSafeSourceId } from "./source-id";
8+
} from "../config/config-io";
9+
import { ensureGitignoreEntry } from "../gitignore";
10+
import { resolveTargetDir } from "../paths";
11+
import { resolveRepoInput } from "../resolve-repo";
12+
import { assertSafeSourceId } from "../source-id";
1313

1414
const buildNewSources = (
1515
entries: Array<{ id?: string; repo: string; targetDir?: string }>,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readdir, rm, stat } from "node:fs/promises";
22
import path from "node:path";
33

4-
import { exists, resolveGitCacheDir } from "./git/cache-dir";
4+
import { exists, resolveGitCacheDir } from "../git/cache-dir";
55

66
const getDirSize = async (dirPath: string): Promise<number> => {
77
try {

src/clean.ts renamed to src/commands/clean.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { access, rm } from "node:fs/promises";
2-
import { DEFAULT_CACHE_DIR, loadConfig } from "./config";
3-
import { resolveCacheDir } from "./paths";
2+
import { DEFAULT_CACHE_DIR, loadConfig } from "../config";
3+
import { resolveCacheDir } from "../paths";
44

55
type CleanOptions = {
66
configPath?: string;

src/init.ts renamed to src/commands/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
type DocsCacheConfig,
1313
stripDefaultConfigValues,
1414
writeConfig,
15-
} from "./config";
16-
import { ensureGitignoreEntry, getGitignoreStatus } from "./gitignore";
15+
} from "../config";
16+
import { ensureGitignoreEntry, getGitignoreStatus } from "../gitignore";
1717

1818
type InitOptions = {
1919
cacheDirOverride?: string;

src/prune.ts renamed to src/commands/prune.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { access, readdir, rm } from "node:fs/promises";
22
import path from "node:path";
3-
import { DEFAULT_CACHE_DIR, loadConfig } from "./config";
4-
import { resolveCacheDir } from "./paths";
3+
import { DEFAULT_CACHE_DIR, loadConfig } from "../config";
4+
import { resolveCacheDir } from "../paths";
55

66
type PruneOptions = {
77
configPath?: string;

src/remove.ts renamed to src/commands/remove.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { rm } from "node:fs/promises";
2-
import type { DocsCacheConfig } from "./config";
2+
import type { DocsCacheConfig } from "../config";
33
import {
44
mergeConfigBase,
55
readConfigAtPath,
66
resolveConfigTarget,
77
writeConfigFile,
8-
} from "./config-io";
9-
import { resolveTargetDir } from "./paths";
10-
import { resolveRepoInput } from "./resolve-repo";
8+
} from "../config/config-io";
9+
import { resolveTargetDir } from "../paths";
10+
import { resolveRepoInput } from "../resolve-repo";
1111

1212
const resolveIdsToRemove = (ids: string[], config: DocsCacheConfig) => {
1313
const sourcesById = new Map(

src/status.ts renamed to src/commands/status.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { access } from "node:fs/promises";
22
import pc from "picocolors";
3-
import { symbols, ui } from "./cli/ui";
4-
import { DEFAULT_CACHE_DIR, loadConfig } from "./config";
5-
import { DEFAULT_LOCK_FILENAME, readLock, resolveLockPath } from "./lock";
6-
import { getCacheLayout, resolveCacheDir } from "./paths";
3+
import { symbols, ui } from "../cli/ui";
4+
import { DEFAULT_CACHE_DIR, loadConfig } from "../config";
5+
import { DEFAULT_LOCK_FILENAME, readLock, resolveLockPath } from "../lock";
6+
import { getCacheLayout, resolveCacheDir } from "../paths";
77

88
type StatusOptions = {
99
configPath?: string;

src/sync.ts renamed to src/commands/sync.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ import { createHash } from "node:crypto";
22
import { access, mkdir, readFile } from "node:fs/promises";
33
import path from "node:path";
44
import pc from "picocolors";
5-
import { TaskReporter } from "./cli/task-reporter";
6-
import { isSilentMode, symbols, ui } from "./cli/ui";
5+
import { TaskReporter } from "../cli/task-reporter";
6+
import { isSilentMode, symbols, ui } from "../cli/ui";
77
import {
88
DEFAULT_CACHE_DIR,
99
DEFAULT_CONFIG,
1010
type DocsCacheDefaults,
1111
type DocsCacheResolvedSource,
1212
loadConfig,
13-
} from "./config";
14-
import { fetchSource } from "./git/fetch-source";
15-
import { resolveRemoteCommit } from "./git/resolve-remote";
16-
import type { DocsCacheLock } from "./lock";
17-
import { readLock, resolveLockPath, writeLock } from "./lock";
18-
import { MANIFEST_FILENAME } from "./manifest";
19-
import { computeManifestHash, materializeSource } from "./materialize";
20-
import { resolveCacheDir, resolveTargetDir } from "./paths";
21-
import type { SyncOptions, SyncResult } from "./sync-types";
22-
import { applyTargetDir } from "./targets";
23-
import { writeToc } from "./toc";
13+
} from "../config";
14+
import type { SyncOptions, SyncResult } from "../config/sync-types";
15+
import { fetchSource } from "../git/fetch-source";
16+
import { resolveRemoteCommit } from "../git/resolve-remote";
17+
import type { DocsCacheLock } from "../lock";
18+
import { readLock, resolveLockPath, writeLock } from "../lock";
19+
import { MANIFEST_FILENAME } from "../manifest";
20+
import { computeManifestHash, materializeSource } from "../materialize";
21+
import { resolveCacheDir, resolveTargetDir } from "../paths";
22+
import { applyTargetDir } from "../targets";
23+
import { writeToc } from "../toc";
2424
import { verifyCache } from "./verify";
2525

2626
type SyncDeps = {

0 commit comments

Comments
 (0)