Skip to content

Commit

Permalink
refactor(cli): rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Dec 13, 2023
1 parent 2ced436 commit 78a4b88
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 110 deletions.
62 changes: 34 additions & 28 deletions packages/cli/src/Action/BackupAction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Config } from "../Config/Config";
import { PackageConfig } from "../Config/PackageConfig";
import { RepositoryConfig } from "../Config/RepositoryConfig";
import { createRepo } from "../Factory/RepositoryFactory";
import { createTask } from "../Factory/TaskFactory";
import { PreSnapshot } from "../Repository/RepositoryAbstract";
import { DataFormat } from "../utils/DataFormat";
import { renderError, renderObject, renderResult } from "../utils/cli";
Expand All @@ -11,6 +9,8 @@ import {
findRepositoryOrFail,
resolvePackages,
} from "../utils/datatruck/config";
import { createRepo } from "../utils/datatruck/repository";
import { createTask } from "../utils/datatruck/task";
import { duration } from "../utils/date";
import { ensureExistsDir } from "../utils/fs";
import { Listr3, Listr3TaskResultEnd } from "../utils/list";
Expand Down Expand Up @@ -184,32 +184,38 @@ export class BackupAction<TRequired extends boolean = true> {
`${item.data.pruned}/${item.data.total}`,
)}`
: item.key === "snapshot"
? item.data.id
: item.key === "task"
? `${item.data.packageName} ${g(item.data.taskName)}`
: item.key === "backup"
? `${item.data.packageName} ${g(item.data.repositoryName)}`
: item.key === "copy"
? `${item.data.packageName} ${g(item.data.mirrorRepositoryName)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
backups: result.filter((r) => !r.error && r.key === "backup")
.length,
copies: result.filter((r) => !r.error && r.key === "copy").length,
prunes: result
.filter((r) => !r.error && r.key === "prune")
.reduce((result, item) => {
if (item.key === "prune") result += item.data.pruned;
return result;
}, 0),
},
color,
)
: item.key === "report"
? item.data.type
: "";
? item.data.id
: item.key === "task"
? `${item.data.packageName} ${g(item.data.taskName)}`
: item.key === "backup"
? `${item.data.packageName} ${g(item.data.repositoryName)}`
: item.key === "copy"
? `${item.data.packageName} ${g(
item.data.mirrorRepositoryName,
)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
backups: result.filter(
(r) => !r.error && r.key === "backup",
).length,
copies: result.filter(
(r) => !r.error && r.key === "copy",
).length,
prunes: result
.filter((r) => !r.error && r.key === "prune")
.reduce((result, item) => {
if (item.key === "prune")
result += item.data.pruned;
return result;
}, 0),
},
color,
)
: item.key === "report"
? item.data.type
: "";
};
return new DataFormat({
streams: options.streams,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Action/ConfigAction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GlobalOptions } from "../Command/CommandAbstract";
import type { Config } from "../Config/Config";
import { RepositoryConfig } from "../Config/RepositoryConfig";
import { AppError } from "../Error/AppError";
import { configSchema } from "../config.schema";
import { findRepositoryOrFail } from "../utils/datatruck/config";
import { AppError } from "../utils/datatruck/error";
import { findFile, parseFile, parseFileExtensions } from "../utils/fs";
import { IfRequireKeys } from "../utils/ts";
import Ajv from "ajv";
Expand Down
42 changes: 21 additions & 21 deletions packages/cli/src/Action/CopyAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Config } from "../Config/Config";
import { createRepo } from "../Factory/RepositoryFactory";
import { Snapshot } from "../Repository/RepositoryAbstract";
import { DataFormat } from "../utils/DataFormat";
import { renderError, renderObject, renderResult } from "../utils/cli";
Expand All @@ -8,6 +7,7 @@ import {
filterRepository,
findRepositoryOrFail,
} from "../utils/datatruck/config";
import { createRepo } from "../utils/datatruck/repository";
import { groupAndFilter } from "../utils/datatruck/snapshot";
import { duration } from "../utils/date";
import { Listr3, Listr3TaskResultEnd } from "../utils/list";
Expand Down Expand Up @@ -74,26 +74,26 @@ export class CopyAction<TRequired extends boolean = true> {
return item.key === "snapshots"
? item.data.snapshots.length
: item.key === "copy"
? `${item.data.packageName} ${g(
[
item.data.snapshotId.slice(0, 8),
item.data.mirrorRepositoryName,
].join(" "),
)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
copied: items.filter(
(i) => i.key === "copy" && !i.error && !i.data.skipped,
).length,
skipped: items.filter(
(i) => i.key === "copy" && !i.error && i.data.skipped,
).length,
},
color,
)
: "";
? `${item.data.packageName} ${g(
[
item.data.snapshotId.slice(0, 8),
item.data.mirrorRepositoryName,
].join(" "),
)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
copied: items.filter(
(i) => i.key === "copy" && !i.error && !i.data.skipped,
).length,
skipped: items.filter(
(i) => i.key === "copy" && !i.error && i.data.skipped,
).length,
},
color,
)
: "";
};
return new DataFormat({
streams: options.streams,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Action/InitAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Config } from "../Config/Config";
import { createRepo } from "../Factory/RepositoryFactory";
import { filterRepository } from "../utils/datatruck/config";
import { createRepo } from "../utils/datatruck/repository";
import { IfRequireKeys } from "../utils/ts";

export type InitActionOptions = {
Expand Down
34 changes: 17 additions & 17 deletions packages/cli/src/Action/PruneAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Config } from "../Config/Config";
import { RepositoryConfig } from "../Config/RepositoryConfig";
import { createRepo } from "../Factory/RepositoryFactory";
import { createRepo } from "../utils/datatruck/repository";
import { groupAndFilter } from "../utils/datatruck/snapshot";
import { KeepObject, createFilterByLastOptions } from "../utils/date";
import { groupBy } from "../utils/object";
Expand Down Expand Up @@ -82,22 +82,22 @@ export class PruneAction<TRequired extends boolean = true> {
const keepSnapshots = hasKeepFilter
? groupAndFilter(snapshots, this.options.groupBy, keepFilter)
: prunePolicy
? groupAndFilter(snapshots, this.options.groupBy, (groups) => {
const [snapshot] = groups;
const packageName = snapshot.packageName;
const config = this.config.packages.find(
(pkg) => pkg.name === packageName,
);
const prunePolicy =
config?.prunePolicy ?? this.config.prunePolicy ?? {};
const hasPrunePolicy = Object.values(prunePolicy).some(
(v) => typeof v === "number",
);
return hasPrunePolicy
? createFilterByLastOptions(prunePolicy)
: "no-policy";
})
: [];
? groupAndFilter(snapshots, this.options.groupBy, (groups) => {
const [snapshot] = groups;
const packageName = snapshot.packageName;
const config = this.config.packages.find(
(pkg) => pkg.name === packageName,
);
const prunePolicy =
config?.prunePolicy ?? this.config.prunePolicy ?? {};
const hasPrunePolicy = Object.values(prunePolicy).some(
(v) => typeof v === "number",
);
return hasPrunePolicy
? createFilterByLastOptions(prunePolicy)
: "no-policy";
})
: [];

const result: PruneResult = {
total: snapshots.length,
Expand Down
31 changes: 16 additions & 15 deletions packages/cli/src/Action/RestoreAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Config } from "../Config/Config";
import { PackageConfig } from "../Config/PackageConfig";
import { createRepo } from "../Factory/RepositoryFactory";
import { createTask } from "../Factory/TaskFactory";
import { Snapshot } from "../Repository/RepositoryAbstract";
import { TaskAbstract } from "../Task/TaskAbstract";
import { DataFormat } from "../utils/DataFormat";
Expand All @@ -11,6 +9,8 @@ import {
findRepositoryOrFail,
resolvePackage,
} from "../utils/datatruck/config";
import { createRepo } from "../utils/datatruck/repository";
import { createTask } from "../utils/datatruck/task";
import { duration } from "../utils/date";
import { ensureFreeDiskSpace, initEmptyDir } from "../utils/fs";
import { Listr3, Listr3TaskResultEnd } from "../utils/list";
Expand Down Expand Up @@ -180,19 +180,20 @@ export class RestoreAction<TRequired extends boolean = true> {
return item.key === "snapshots"
? `${item.data.id.slice(0, 8)} ${g(`${item.data.packages} packages`)}`
: item.key === "task"
? `${item.data.packageName} ${g(item.data.taskName)}`
: item.key === "restore"
? `${item.data.packageName} ${g(item.data.repositoryName)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
restores: result.filter((r) => !r.error && r.key === "restore")
.length,
},
color,
)
: "";
? `${item.data.packageName} ${g(item.data.taskName)}`
: item.key === "restore"
? `${item.data.packageName} ${g(item.data.repositoryName)}`
: item.key === "summary"
? renderObject(
{
errors: item.data.errors,
restores: result.filter(
(r) => !r.error && r.key === "restore",
).length,
},
color,
)
: "";
};
return new DataFormat({
streams: options.streams,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Action/SnapshotsAction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Config } from "../Config/Config";
import { RepositoryConfigEnabledAction } from "../Config/RepositoryConfig";
import { createRepo } from "../Factory/RepositoryFactory";
import { Snapshot } from "../Repository/RepositoryAbstract";
import { filterRepository } from "../utils/datatruck/config";
import { createRepo } from "../utils/datatruck/repository";
import { groupAndFilter } from "../utils/datatruck/snapshot";
import { IfRequireKeys } from "../utils/ts";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Repository/DatatruckRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppError } from "../Error/AppError";
import { logExec } from "../utils/cli";
import { calcFileHash } from "../utils/crypto";
import { createFs } from "../utils/datatruck/client";
import { AppError } from "../utils/datatruck/error";
import { BackupPathsOptions, parseBackupPaths } from "../utils/datatruck/paths";
import {
createFileScanner,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Repository/ResticRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppError } from "../Error/AppError";
import { ResticRepositoryUri, Restic } from "../utils/Restic";
import { logExec } from "../utils/cli";
import { AppError } from "../utils/datatruck/error";
import { BackupPathsOptions, parseBackupPaths } from "../utils/datatruck/paths";
import {
fastglobToGitIgnore,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Task/MssqlTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppError } from "../Error/AppError";
import { resolveDatabaseName } from "../utils/datatruck/config";
import { AppError } from "../utils/datatruck/error";
import { readDir } from "../utils/fs";
import { exec } from "../utils/process";
import { mkTmpDir } from "../utils/temp";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Task/MysqlDumpTask.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AppError } from "../Error/AppError";
import { runParallel } from "../utils/async";
import { logExec } from "../utils/cli";
import {
ResolveDatabaseNameParams,
resolveDatabaseName,
} from "../utils/datatruck/config";
import { AppError } from "../utils/datatruck/error";
import {
ensureEmptyDir,
ensureSingleFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Task/SqlDumpTaskAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppError } from "../Error/AppError";
import { logExec } from "../utils/cli";
import { resolveDatabaseName } from "../utils/datatruck/config";
import { AppError } from "../utils/datatruck/error";
import {
ensureEmptyDir,
existsDir,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ConfigAction } from "./Action/ConfigAction";
import { GlobalOptions } from "./Command/CommandAbstract";
import { AppError } from "./Error/AppError";
import globalData from "./globalData";
import { DataFormatType } from "./utils/DataFormat";
import { OptionsConfig, showCursorCommand } from "./utils/cli";
Expand All @@ -9,6 +8,7 @@ import {
InferDatatruckCommandOptions,
createCommand,
} from "./utils/datatruck/command";
import { AppError } from "./utils/datatruck/error";
import { onExit } from "./utils/exit";
import { parsePackageFile } from "./utils/fs";
import { snakeCase } from "./utils/string";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/DataFormat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppError } from "../Error/AppError";
import { AppError } from "./datatruck/error";
import { Streams, createStreams } from "./stream";
import TtyTable, { Header } from "tty-table";
import { formatWithOptions } from "util";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/datatruck/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { PruneCommand } from "../../Command/PruneCommand";
import { RestoreCommand } from "../../Command/RestoreCommand";
import { SnapshotsCommand } from "../../Command/SnapshotsCommand";
import { StartServerCommand } from "../../Command/StartServerCommand";
import { AppError } from "../../Error/AppError";
import { Streams } from "../stream";
import { AppError } from "./error";
import { Writable } from "stream";

export const datatruckCommandMap = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/datatruck/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
RepositoryConfigEnabledAction,
RepositoryConfig,
} from "../../Config/RepositoryConfig";
import { AppError } from "../../Error/AppError";
import { checkMatch, makePathPatterns, render } from "../string";
import { tmpDir } from "../temp";
import { AppError } from "./error";
import { isMatch } from "micromatch";

export function findRepositoryOrFail(config: Config, repositoryName: string) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import type { RepositoryConfig } from "../Config/RepositoryConfig";
import { AppError } from "../Error/AppError";
import type { RepositoryConfig } from "../../Config/RepositoryConfig";
import {
DatatruckRepository,
datatruckRepositoryName,
} from "../Repository/DatatruckRepository";
import { GitRepository, gitRepositoryName } from "../Repository/GitRepository";
import type { RepositoryAbstract } from "../Repository/RepositoryAbstract";
} from "../../Repository/DatatruckRepository";
import {
GitRepository,
gitRepositoryName,
} from "../../Repository/GitRepository";
import type { RepositoryAbstract } from "../../Repository/RepositoryAbstract";
import {
ResticRepository,
resticRepositoryName,
} from "../Repository/ResticRepository";
} from "../../Repository/ResticRepository";
import { AppError } from "./error";

export function createRepo(
repository: RepositoryConfig,
Expand Down
Loading

0 comments on commit 78a4b88

Please sign in to comment.