@datatruck/cli 0.32.3 → 0.33.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.
Files changed (127) hide show
  1. package/config.schema.json +374 -31
  2. package/lib/{Action → actions}/BackupAction.d.ts +5 -17
  3. package/lib/{Action → actions}/BackupAction.js +32 -85
  4. package/lib/{Action → actions}/ConfigAction.d.ts +4 -2
  5. package/lib/{Action → actions}/ConfigAction.js +16 -8
  6. package/lib/{Action → actions}/CopyAction.d.ts +17 -13
  7. package/lib/actions/CopyAction.js +285 -0
  8. package/lib/{Action → actions}/InitAction.d.ts +1 -1
  9. package/lib/{Action → actions}/InitAction.js +3 -3
  10. package/lib/{Action → actions}/PruneAction.d.ts +1 -2
  11. package/lib/{Action → actions}/PruneAction.js +2 -2
  12. package/lib/{Action → actions}/RestoreAction.d.ts +4 -13
  13. package/lib/{Action → actions}/RestoreAction.js +17 -17
  14. package/lib/{Action → actions}/SnapshotsAction.d.ts +2 -3
  15. package/lib/{Action → actions}/SnapshotsAction.js +3 -3
  16. package/lib/cli.d.ts +3 -3
  17. package/lib/cli.js +18 -17
  18. package/lib/commands/BackupCommand.d.ts +43 -0
  19. package/lib/{Command → commands}/BackupCommand.js +7 -6
  20. package/lib/{Command → commands}/CleanCacheCommand.d.ts +4 -2
  21. package/lib/{Command → commands}/CleanCacheCommand.js +6 -5
  22. package/lib/{Command → commands}/CommandAbstract.d.ts +10 -6
  23. package/lib/{Command → commands}/CommandAbstract.js +5 -3
  24. package/lib/commands/ConfigCommand.d.ts +22 -0
  25. package/lib/{Command → commands}/ConfigCommand.js +5 -5
  26. package/lib/commands/CopyCommand.d.ts +17 -0
  27. package/lib/{Command → commands}/CopyCommand.js +7 -6
  28. package/lib/commands/InitCommand.d.ts +19 -0
  29. package/lib/{Command → commands}/InitCommand.js +9 -9
  30. package/lib/{Command → commands}/PruneCommand.d.ts +7 -4
  31. package/lib/{Command → commands}/PruneCommand.js +11 -11
  32. package/lib/commands/RestoreCommand.d.ts +38 -0
  33. package/lib/{Command → commands}/RestoreCommand.js +7 -6
  34. package/lib/{Command → commands}/SnapshotsCommand.d.ts +8 -6
  35. package/lib/{Command → commands}/SnapshotsCommand.js +12 -12
  36. package/lib/{Command → commands}/StartServerCommand.d.ts +4 -2
  37. package/lib/{Command → commands}/StartServerCommand.js +5 -5
  38. package/lib/index.d.ts +20 -23
  39. package/lib/index.js +8 -8
  40. package/lib/{Repository → repositories}/DatatruckRepository.js +2 -2
  41. package/lib/{Repository → repositories}/RepositoryAbstract.d.ts +7 -7
  42. package/lib/{Repository → repositories}/ResticRepository.js +7 -6
  43. package/lib/{Task → tasks}/MssqlTask.js +2 -2
  44. package/lib/{Task → tasks}/MysqlDumpTask.js +4 -4
  45. package/lib/{Task → tasks}/ScriptTask.d.ts +2 -2
  46. package/lib/{Task → tasks}/SqlDumpTaskAbstract.js +4 -4
  47. package/lib/{Task → tasks}/TaskAbstract.d.ts +4 -4
  48. package/lib/utils/DataFormat.js +3 -3
  49. package/lib/utils/Restic.d.ts +1 -0
  50. package/lib/utils/Restic.js +12 -2
  51. package/lib/utils/cli.d.ts +9 -3
  52. package/lib/utils/cli.js +17 -1
  53. package/lib/utils/cron.d.ts +11 -0
  54. package/lib/utils/cron.js +27 -0
  55. package/lib/utils/datatruck/command.d.ts +29 -0
  56. package/lib/utils/datatruck/command.js +61 -0
  57. package/lib/{Config/RepositoryConfig.d.ts → utils/datatruck/config-repository-type.d.ts} +19 -8
  58. package/lib/{Config/TaskConfig.d.ts → utils/datatruck/config-task-type.d.ts} +6 -6
  59. package/lib/utils/datatruck/config-type.d.ts +50 -0
  60. package/lib/utils/datatruck/config.d.ts +19 -10
  61. package/lib/utils/datatruck/config.js +43 -7
  62. package/lib/utils/datatruck/cron-server.d.ts +27 -6
  63. package/lib/utils/datatruck/cron-server.js +38 -20
  64. package/lib/utils/datatruck/paths.d.ts +2 -2
  65. package/lib/utils/datatruck/report-list.d.ts +12 -0
  66. package/lib/utils/datatruck/report-list.js +57 -0
  67. package/lib/utils/datatruck/repository-server.js +3 -2
  68. package/lib/utils/datatruck/repository.d.ts +16 -0
  69. package/lib/utils/datatruck/repository.js +30 -0
  70. package/lib/utils/datatruck/snapshot.d.ts +2 -2
  71. package/lib/utils/datatruck/task.d.ts +3 -0
  72. package/lib/{Factory/TaskFactory.js → utils/datatruck/task.js} +8 -8
  73. package/lib/utils/date.js +6 -2
  74. package/lib/utils/fs.d.ts +3 -0
  75. package/lib/utils/fs.js +24 -4
  76. package/lib/utils/list.d.ts +5 -5
  77. package/lib/utils/mysql.js +5 -5
  78. package/lib/utils/object.d.ts +13 -0
  79. package/lib/utils/object.js +32 -1
  80. package/lib/utils/process.js +4 -1
  81. package/lib/utils/string.d.ts +1 -0
  82. package/lib/utils/string.js +7 -3
  83. package/lib/utils/ts.d.ts +16 -0
  84. package/lib/utils/watcher.d.ts +10 -0
  85. package/lib/utils/watcher.js +34 -0
  86. package/package.json +3 -3
  87. package/lib/Action/CopyAction.js +0 -164
  88. package/lib/Command/BackupCommand.d.ts +0 -19
  89. package/lib/Command/ConfigCommand.d.ts +0 -15
  90. package/lib/Command/CopyCommand.d.ts +0 -16
  91. package/lib/Command/InitCommand.d.ts +0 -13
  92. package/lib/Command/RestoreCommand.d.ts +0 -17
  93. package/lib/Config/Config.d.ts +0 -28
  94. package/lib/Config/PackageConfig.d.ts +0 -24
  95. package/lib/Config/PackageRepositoryConfig.d.ts +0 -15
  96. package/lib/Config/PrunePolicyConfig.d.ts +0 -2
  97. package/lib/Config/RepositoryConfig.js +0 -2
  98. package/lib/Config/TaskConfig.js +0 -2
  99. package/lib/Factory/CommandFactory.d.ts +0 -45
  100. package/lib/Factory/CommandFactory.js +0 -96
  101. package/lib/Factory/RepositoryFactory.d.ts +0 -3
  102. package/lib/Factory/RepositoryFactory.js +0 -23
  103. package/lib/Factory/TaskFactory.d.ts +0 -3
  104. /package/lib/{Action → actions}/CleanCacheAction.d.ts +0 -0
  105. /package/lib/{Action → actions}/CleanCacheAction.js +0 -0
  106. /package/lib/{Repository → repositories}/DatatruckRepository.d.ts +0 -0
  107. /package/lib/{Repository → repositories}/GitRepository.d.ts +0 -0
  108. /package/lib/{Repository → repositories}/GitRepository.js +0 -0
  109. /package/lib/{Repository → repositories}/RepositoryAbstract.js +0 -0
  110. /package/lib/{Repository → repositories}/ResticRepository.d.ts +0 -0
  111. /package/lib/{Task → tasks}/GitTask.d.ts +0 -0
  112. /package/lib/{Task → tasks}/GitTask.js +0 -0
  113. /package/lib/{Task → tasks}/MariadbTask.d.ts +0 -0
  114. /package/lib/{Task → tasks}/MariadbTask.js +0 -0
  115. /package/lib/{Task → tasks}/MssqlTask.d.ts +0 -0
  116. /package/lib/{Task → tasks}/MysqlDumpTask.d.ts +0 -0
  117. /package/lib/{Task → tasks}/PostgresqlDumpTask.d.ts +0 -0
  118. /package/lib/{Task → tasks}/PostgresqlDumpTask.js +0 -0
  119. /package/lib/{Task → tasks}/ScriptTask.js +0 -0
  120. /package/lib/{Task → tasks}/SqlDumpTaskAbstract.d.ts +0 -0
  121. /package/lib/{Task → tasks}/TaskAbstract.js +0 -0
  122. /package/lib/{Config/Config.js → utils/datatruck/config-repository-type.js} +0 -0
  123. /package/lib/{Config/PackageConfig.js → utils/datatruck/config-task-type.js} +0 -0
  124. /package/lib/{Config/PackageRepositoryConfig.js → utils/datatruck/config-type.js} +0 -0
  125. /package/lib/{Error/AppError.d.ts → utils/datatruck/error.d.ts} +0 -0
  126. /package/lib/{Error/AppError.js → utils/datatruck/error.js} +0 -0
  127. /package/lib/{Config/PrunePolicyConfig.js → utils/ts.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PruneAction = void 0;
4
- const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
4
+ const repository_1 = require("../utils/datatruck/repository");
5
5
  const snapshot_1 = require("../utils/datatruck/snapshot");
6
6
  const date_1 = require("../utils/date");
7
7
  const object_1 = require("../utils/object");
@@ -17,7 +17,7 @@ class PruneAction {
17
17
  const repository = (0, object_1.groupBy)(this.config.repositories, "name", true);
18
18
  for (const snapshot of snapshots) {
19
19
  if (!snapshot.exclusionReasons?.length) {
20
- const repo = (0, RepositoryFactory_1.createRepo)(repository[snapshot.repositoryName]);
20
+ const repo = await (0, repository_1.createAndInitRepo)(repository[snapshot.repositoryName], this.options.verbose);
21
21
  await repo.prune({
22
22
  snapshot: snapshot,
23
23
  options: { verbose: this.options.verbose },
@@ -1,8 +1,7 @@
1
- import type { Config } from "../Config/Config";
2
- import { PackageConfig } from "../Config/PackageConfig";
3
- import { Snapshot } from "../Repository/RepositoryAbstract";
4
- import { TaskAbstract } from "../Task/TaskAbstract";
1
+ import { Snapshot } from "../repositories/RepositoryAbstract";
2
+ import { TaskAbstract } from "../tasks/TaskAbstract";
5
3
  import { DataFormat } from "../utils/DataFormat";
4
+ import type { Config, PackageConfig } from "../utils/datatruck/config-type";
6
5
  import { Listr3TaskResultEnd } from "../utils/list";
7
6
  import { Progress, ProgressMode } from "../utils/progress";
8
7
  import { Streams } from "../utils/stream";
@@ -57,14 +56,6 @@ export declare class RestoreAction<TRequired extends boolean = true> {
57
56
  streams?: Streams;
58
57
  verbose?: number;
59
58
  }): DataFormat;
60
- exec(): Promise<({
61
- key: "summary";
62
- keyIndex?: string | undefined;
63
- data: {
64
- errors: number;
65
- };
66
- elapsed: number;
67
- error?: Error | undefined;
68
- } | import("../utils/list").Listr3TaskResult<Context>)[]>;
59
+ exec(): Promise<(import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[]>;
69
60
  }
70
61
  export {};
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RestoreAction = void 0;
7
- const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
8
- const TaskFactory_1 = require("../Factory/TaskFactory");
9
7
  const DataFormat_1 = require("../utils/DataFormat");
10
8
  const cli_1 = require("../utils/cli");
11
9
  const config_1 = require("../utils/datatruck/config");
10
+ const repository_1 = require("../utils/datatruck/repository");
11
+ const task_1 = require("../utils/datatruck/task");
12
12
  const date_1 = require("../utils/date");
13
13
  const fs_1 = require("../utils/fs");
14
14
  const list_1 = require("../utils/list");
@@ -68,7 +68,7 @@ class RestoreAction {
68
68
  async restore(data) {
69
69
  let { snapshot, pkg, task } = data;
70
70
  const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
71
- const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
71
+ const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
72
72
  if (this.options.initial)
73
73
  pkg = { ...pkg, restorePath: pkg.path };
74
74
  let snapshotPath = pkg.restorePath ?? pkg.path;
@@ -103,19 +103,19 @@ class RestoreAction {
103
103
  };
104
104
  const renderData = (item, color, result = []) => {
105
105
  const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
106
- return item.key === "snapshots"
107
- ? `${item.data.id.slice(0, 8)} ${g(`${item.data.packages} packages`)}`
108
- : item.key === "task"
109
- ? `${item.data.packageName} ${g(item.data.taskName)}`
110
- : item.key === "restore"
111
- ? `${item.data.packageName} ${g(item.data.repositoryName)}`
112
- : item.key === "summary"
113
- ? (0, cli_1.renderObject)({
114
- errors: item.data.errors,
115
- restores: result.filter((r) => !r.error && r.key === "restore")
116
- .length,
117
- }, color)
118
- : "";
106
+ return (0, cli_1.renderListTaskItem)(item, color, {
107
+ snapshots: (data) => [
108
+ data.id.slice(0, 8),
109
+ g(`${data.packages} packages`),
110
+ ],
111
+ task: (data) => [data.packageName, g(data.taskName)],
112
+ restore: (data) => [data.packageName, g(data.repositoryName)],
113
+ summary: (data) => ({
114
+ errors: data.errors,
115
+ restores: result.filter((r) => !r.error && r.key === "restore")
116
+ .length,
117
+ }),
118
+ });
119
119
  };
120
120
  return new DataFormat_1.DataFormat({
121
121
  streams: options.streams,
@@ -191,7 +191,7 @@ class RestoreAction {
191
191
  action: "restore",
192
192
  });
193
193
  const gc = new temp_1.GargabeCollector();
194
- const task = pkg.task ? (0, TaskFactory_1.createTask)(pkg.task) : undefined;
194
+ const task = pkg.task ? (0, task_1.createTask)(pkg.task) : undefined;
195
195
  const restore = await this.restore({
196
196
  gc,
197
197
  pkg,
@@ -1,6 +1,5 @@
1
- import type { Config } from "../Config/Config";
2
- import { RepositoryConfigEnabledAction } from "../Config/RepositoryConfig";
3
- import { Snapshot } from "../Repository/RepositoryAbstract";
1
+ import { Snapshot } from "../repositories/RepositoryAbstract";
2
+ import type { Config, RepositoryConfigEnabledAction } from "../utils/datatruck/config-type";
4
3
  import { IfRequireKeys } from "../utils/ts";
5
4
  export type SnapshotGroupByType = keyof Pick<ExtendedSnapshot, "packageName" | "repositoryName" | "repositoryType">;
6
5
  export type SnapshotsActionOptions = {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SnapshotsAction = void 0;
4
- const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
5
4
  const config_1 = require("../utils/datatruck/config");
5
+ const repository_1 = require("../utils/datatruck/repository");
6
6
  const snapshot_1 = require("../utils/datatruck/snapshot");
7
7
  class SnapshotsAction {
8
8
  config;
@@ -16,7 +16,7 @@ class SnapshotsAction {
16
16
  sourceAction = "snapshots";
17
17
  let result = [];
18
18
  for (const repoConfig of this.config.repositories) {
19
- if (!(0, config_1.filterRepository)(repoConfig, sourceAction))
19
+ if (!(0, config_1.filterRepositoryByEnabled)(repoConfig, sourceAction))
20
20
  continue;
21
21
  if (this.options.repositoryNames &&
22
22
  !this.options.repositoryNames.includes(repoConfig.name))
@@ -24,7 +24,7 @@ class SnapshotsAction {
24
24
  if (this.options.repositoryTypes &&
25
25
  !this.options.repositoryTypes.includes(repoConfig.type))
26
26
  continue;
27
- const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
27
+ const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
28
28
  const configPackageNames = this.config.packages.map((pkg) => pkg.name);
29
29
  const packageNames = this.options.packageConfig
30
30
  ? this.options.packageNames?.filter((name) => configPackageNames.includes(name)) || configPackageNames
package/lib/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OptionsMap } from "./Factory/CommandFactory";
2
- export declare function buildArgs<TCommand extends keyof OptionsMap>(input: TCommand, options: OptionsMap[TCommand]): any[];
1
+ import { DatatruckCommandMap, InferDatatruckCommandOptions } from "./utils/datatruck/command";
2
+ export declare function buildArgs<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): any[];
3
3
  export declare function parseArgs(args: string[]): void;
4
- export declare function exec<TCommand extends keyof OptionsMap>(input: TCommand, options: OptionsMap[TCommand]): Promise<void>;
4
+ export declare function exec<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): Promise<void>;
package/lib/cli.js CHANGED
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.exec = exports.parseArgs = exports.buildArgs = void 0;
7
- const ConfigAction_1 = require("./Action/ConfigAction");
8
- const AppError_1 = require("./Error/AppError");
9
- const CommandFactory_1 = require("./Factory/CommandFactory");
7
+ const ConfigAction_1 = require("./actions/ConfigAction");
10
8
  const globalData_1 = __importDefault(require("./globalData"));
11
9
  const cli_1 = require("./utils/cli");
10
+ const command_1 = require("./utils/datatruck/command");
11
+ const error_1 = require("./utils/datatruck/error");
12
12
  const exit_1 = require("./utils/exit");
13
13
  const fs_1 = require("./utils/fs");
14
14
  const string_1 = require("./utils/string");
@@ -28,8 +28,8 @@ function getGlobalOptions() {
28
28
  }
29
29
  function makeCommand(command) {
30
30
  const programCommand = program.command(command);
31
- const instance = (0, CommandFactory_1.CommandFactory)(command, getGlobalOptions(), null);
32
- const options = instance.onOptions();
31
+ const instance = (0, command_1.createCommand)(command, getGlobalOptions(), null);
32
+ const options = instance.optionsConfig();
33
33
  for (const key in options) {
34
34
  const option = options[key];
35
35
  const description = `${option.description}${option.defaults ? ` (defaults: ${option.defaults})` : ""}`;
@@ -56,10 +56,11 @@ function makeCommandAction(command) {
56
56
  globalData_1.default.tempDir = (0, path_1.isAbsolute)(config.data.tempDir)
57
57
  ? config.data.tempDir
58
58
  : (0, path_1.join)((0, path_1.dirname)(config.path), config.data.tempDir);
59
- exitCode = await (0, CommandFactory_1.CommandFactory)(command, {
59
+ const response = await (0, command_1.createCommand)(command, {
60
60
  ...globalOptions,
61
61
  config: config.data,
62
- }, options, {}, globalOptions.config).onExec();
62
+ }, options, {}, globalOptions.config).exec();
63
+ exitCode = response.exitCode;
63
64
  }
64
65
  catch (e) {
65
66
  const error = e;
@@ -67,7 +68,7 @@ function makeCommandAction(command) {
67
68
  console.error((0, chalk_1.red)(error.stack));
68
69
  }
69
70
  else {
70
- if (error instanceof AppError_1.AppError) {
71
+ if (error instanceof error_1.AppError) {
71
72
  console.error((0, chalk_1.red)(error.message));
72
73
  }
73
74
  else {
@@ -90,15 +91,15 @@ program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFI
90
91
  program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
91
92
  program.option("--progress <value>", "Progress type (auto, true, false, interval, interval:[ms])", "auto");
92
93
  program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
93
- makeCommand(CommandFactory_1.CommandEnum.startServer).alias("start");
94
- makeCommand(CommandFactory_1.CommandEnum.config).alias("c");
95
- makeCommand(CommandFactory_1.CommandEnum.init).alias("i");
96
- makeCommand(CommandFactory_1.CommandEnum.snapshots).alias("s");
97
- makeCommand(CommandFactory_1.CommandEnum.prune).alias("p");
98
- makeCommand(CommandFactory_1.CommandEnum.backup).alias("b");
99
- makeCommand(CommandFactory_1.CommandEnum.restore).alias("r");
100
- makeCommand(CommandFactory_1.CommandEnum.copy).alias("cp");
101
- makeCommand(CommandFactory_1.CommandEnum.cleanCache).alias("cc");
94
+ makeCommand("startServer").alias("start");
95
+ makeCommand("config").alias("c");
96
+ makeCommand("init").alias("i");
97
+ makeCommand("snapshots").alias("s");
98
+ makeCommand("prune").alias("p");
99
+ makeCommand("backup").alias("b");
100
+ makeCommand("restore").alias("r");
101
+ makeCommand("copy").alias("cp");
102
+ makeCommand("cleanCache").alias("cc");
102
103
  function buildArgs(input, options) {
103
104
  const optionsArray = Object.keys(options).flatMap((name) => [
104
105
  `--${(0, string_1.snakeCase)(name, "-")}`,
@@ -0,0 +1,43 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type BackupCommandOptions<TResolved = false> = {
5
+ package?: If<TResolved, string[]>;
6
+ packageTask?: If<TResolved, string[]>;
7
+ repository?: If<TResolved, string[]>;
8
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
9
+ tag?: If<TResolved, string[]>;
10
+ dryRun?: boolean;
11
+ date?: string;
12
+ prune?: boolean;
13
+ };
14
+ export declare class BackupCommand extends CommandAbstract<BackupCommandOptions<false>, BackupCommandOptions<true>> {
15
+ optionsConfig(): import("../utils/cli").OptionsConfig<BackupCommandOptions<false>, BackupCommandOptions<true>>;
16
+ exec(): Promise<{
17
+ result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
18
+ snapshot: {
19
+ id: string;
20
+ };
21
+ task: {
22
+ taskName: string;
23
+ packageName: string;
24
+ };
25
+ backup: {
26
+ packageName: string;
27
+ repositoryName: string;
28
+ };
29
+ cleanup: {};
30
+ copy: {
31
+ packageName: string;
32
+ repositoryName: string;
33
+ mirrorRepositoryName: string;
34
+ };
35
+ prune: {
36
+ packageName: string;
37
+ total: number;
38
+ pruned: number;
39
+ };
40
+ } & import("../utils/datatruck/report-list").ReportListTaskContext>)[];
41
+ exitCode: number;
42
+ }>;
43
+ }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BackupCommand = void 0;
4
- const BackupAction_1 = require("../Action/BackupAction");
5
- const ConfigAction_1 = require("../Action/ConfigAction");
4
+ const BackupAction_1 = require("../actions/BackupAction");
5
+ const ConfigAction_1 = require("../actions/ConfigAction");
6
6
  const string_1 = require("../utils/string");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class BackupCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({
11
11
  dryRun: {
12
12
  description: "Skip execution",
13
13
  option: "--dryRun",
@@ -47,7 +47,7 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
47
47
  },
48
48
  });
49
49
  }
50
- async onExec() {
50
+ async exec() {
51
51
  const verbose = this.globalOptions.verbose ?? 0;
52
52
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
53
53
  const backup = new BackupAction_1.BackupAction(config, {
@@ -69,7 +69,8 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
69
69
  backup
70
70
  .dataFormat(result, { streams: this.streams, verbose })
71
71
  .log(this.globalOptions.outputFormat);
72
- return result.some((item) => item.error) ? 1 : 0;
72
+ const exitCode = result.some((item) => item.error) ? 1 : 0;
73
+ return { result, exitCode };
73
74
  }
74
75
  }
75
76
  exports.BackupCommand = BackupCommand;
@@ -1,6 +1,8 @@
1
1
  import { CommandAbstract } from "./CommandAbstract";
2
2
  export type CleanCacheCommandOptions<TResolved = false> = {};
3
3
  export declare class CleanCacheCommand extends CommandAbstract<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>> {
4
- onOptions(): import("../utils/cli").OptionsType<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>>;
5
- onExec(): Promise<1 | 0>;
4
+ optionsConfig(): import("../utils/cli").OptionsConfig<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>>;
5
+ exec(): Promise<{
6
+ exitCode: number;
7
+ }>;
6
8
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CleanCacheCommand = void 0;
4
- const CleanCacheAction_1 = require("../Action/CleanCacheAction");
4
+ const CleanCacheAction_1 = require("../actions/CleanCacheAction");
5
5
  const DataFormat_1 = require("../utils/DataFormat");
6
6
  const bytes_1 = require("../utils/bytes");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({});
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({});
11
11
  }
12
- async onExec() {
12
+ async exec() {
13
13
  const cleanCache = new CleanCacheAction_1.CleanCacheAction({
14
14
  verbose: !!this.globalOptions.verbose,
15
15
  });
@@ -32,7 +32,8 @@ class CleanCacheCommand extends CommandAbstract_1.CommandAbstract {
32
32
  await cleanCache.exec();
33
33
  if (this.globalOptions.outputFormat)
34
34
  dataFormat.log(this.globalOptions.outputFormat);
35
- return result.errors.length ? 1 : 0;
35
+ const exitCode = result.errors.length ? 1 : 0;
36
+ return { exitCode };
36
37
  }
37
38
  }
38
39
  exports.CleanCacheCommand = CleanCacheCommand;
@@ -1,6 +1,6 @@
1
- import { Config } from "../Config/Config";
2
1
  import { DataFormatType } from "../utils/DataFormat";
3
- import { OptionsType } from "../utils/cli";
2
+ import { OptionsConfig } from "../utils/cli";
3
+ import type { Config } from "../utils/datatruck/config-type";
4
4
  import { ProgressMode } from "../utils/progress";
5
5
  import { Streams } from "../utils/stream";
6
6
  import { If, SimilarObject } from "../utils/ts";
@@ -16,11 +16,15 @@ export type CommandConstructor<TUnresolvedOptions, TOptions extends SimilarObjec
16
16
  };
17
17
  export declare abstract class CommandAbstract<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> {
18
18
  readonly globalOptions: GlobalOptions<true>;
19
+ readonly inputOptions: TUnresolvedOptions;
19
20
  readonly configPath?: string | undefined;
20
21
  readonly options: TOptions;
21
22
  readonly streams: Streams;
22
- constructor(globalOptions: GlobalOptions<true>, options: TUnresolvedOptions, streams?: Partial<Streams>, configPath?: string | undefined);
23
- abstract onOptions(): OptionsType<TUnresolvedOptions, TOptions>;
24
- protected returnsOptions(options: OptionsType<TUnresolvedOptions, TOptions>): OptionsType<TUnresolvedOptions, TOptions>;
25
- abstract onExec(): Promise<number>;
23
+ constructor(globalOptions: GlobalOptions<true>, inputOptions: TUnresolvedOptions, streams?: Partial<Streams>, configPath?: string | undefined);
24
+ abstract optionsConfig(): OptionsConfig<TUnresolvedOptions, TOptions>;
25
+ protected castOptionsConfig(options: OptionsConfig<TUnresolvedOptions, TOptions>): OptionsConfig<TUnresolvedOptions, TOptions>;
26
+ abstract exec(): Promise<{
27
+ exitCode: number;
28
+ result?: any;
29
+ }>;
26
30
  }
@@ -5,16 +5,18 @@ const cli_1 = require("../utils/cli");
5
5
  const stream_1 = require("../utils/stream");
6
6
  class CommandAbstract {
7
7
  globalOptions;
8
+ inputOptions;
8
9
  configPath;
9
10
  options;
10
11
  streams;
11
- constructor(globalOptions, options, streams = {}, configPath) {
12
+ constructor(globalOptions, inputOptions, streams = {}, configPath) {
12
13
  this.globalOptions = globalOptions;
14
+ this.inputOptions = inputOptions;
13
15
  this.configPath = configPath;
14
- this.options = (0, cli_1.parseOptions)(options, this.onOptions());
16
+ this.options = (0, cli_1.parseOptions)(inputOptions, this.optionsConfig());
15
17
  this.streams = (0, stream_1.createStreams)(streams);
16
18
  }
17
- returnsOptions(options) {
19
+ castOptionsConfig(options) {
18
20
  return options;
19
21
  }
20
22
  }
@@ -0,0 +1,22 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type ConfigCommandOptions<TResolved = false> = {
5
+ package?: If<TResolved, string[]>;
6
+ packageTask?: If<TResolved, string[]>;
7
+ repository?: If<TResolved, string[]>;
8
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
9
+ };
10
+ export declare class ConfigCommand extends CommandAbstract<ConfigCommandOptions<false>, ConfigCommandOptions<true>> {
11
+ optionsConfig(): import("../utils/cli").OptionsConfig<ConfigCommandOptions<false>, ConfigCommandOptions<true>>;
12
+ exec(): Promise<{
13
+ result: {
14
+ path: string;
15
+ data: import("../utils/datatruck/config-type").Config;
16
+ } | {
17
+ path: null;
18
+ data: import("../utils/datatruck/config-type").Config;
19
+ };
20
+ exitCode: number;
21
+ }>;
22
+ }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
5
  const DataFormat_1 = require("../utils/DataFormat");
6
6
  const config_1 = require("../utils/datatruck/config");
7
7
  const string_1 = require("../utils/string");
8
8
  const CommandAbstract_1 = require("./CommandAbstract");
9
9
  class ConfigCommand extends CommandAbstract_1.CommandAbstract {
10
- onOptions() {
11
- return this.returnsOptions({
10
+ optionsConfig() {
11
+ return this.castOptionsConfig({
12
12
  package: {
13
13
  description: "Filter by package names",
14
14
  option: "-p,--package <values>",
@@ -31,7 +31,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
31
31
  },
32
32
  });
33
33
  }
34
- async onExec() {
34
+ async exec() {
35
35
  const result = await ConfigAction_1.ConfigAction.fromGlobalOptionsWithPath(this.globalOptions);
36
36
  const packages = (0, config_1.filterPackages)(result.data, {
37
37
  packageNames: this.options.package,
@@ -66,7 +66,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
66
66
  pkgNames: () => summaryConfig.map((i) => i.packageName).join(),
67
67
  },
68
68
  });
69
- return 0;
69
+ return { result, exitCode: 0 };
70
70
  }
71
71
  }
72
72
  exports.ConfigCommand = ConfigCommand;
@@ -0,0 +1,17 @@
1
+ import { If } from "../utils/ts";
2
+ import { CommandAbstract } from "./CommandAbstract";
3
+ export type CopyCommandOptions<TResolved = false> = {
4
+ id?: If<TResolved, string[]>;
5
+ last?: number;
6
+ package?: If<TResolved, string[]>;
7
+ packageTask?: If<TResolved, string[]>;
8
+ repository: string;
9
+ repository2?: If<TResolved, string[]>;
10
+ };
11
+ export declare class CopyCommand extends CommandAbstract<CopyCommandOptions<false>, CopyCommandOptions<true>> {
12
+ optionsConfig(): import("../utils/cli").OptionsConfig<CopyCommandOptions<false>, CopyCommandOptions<true>>;
13
+ exec(): Promise<{
14
+ result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<import("../actions/CopyAction").Context>)[];
15
+ exitCode: number;
16
+ }>;
17
+ }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CopyCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const CopyAction_1 = require("../Action/CopyAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const CopyAction_1 = require("../actions/CopyAction");
6
6
  const string_1 = require("../utils/string");
7
7
  const CommandAbstract_1 = require("./CommandAbstract");
8
8
  class CopyCommand extends CommandAbstract_1.CommandAbstract {
9
- onOptions() {
10
- return this.returnsOptions({
9
+ optionsConfig() {
10
+ return this.castOptionsConfig({
11
11
  id: {
12
12
  option: "-i,--id <ids>",
13
13
  description: "Filter by identifiers",
@@ -40,7 +40,7 @@ class CopyCommand extends CommandAbstract_1.CommandAbstract {
40
40
  },
41
41
  });
42
42
  }
43
- async onExec() {
43
+ async exec() {
44
44
  const verbose = this.globalOptions.verbose ?? 0;
45
45
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
46
46
  const copy = new CopyAction_1.CopyAction(config, {
@@ -59,7 +59,8 @@ class CopyCommand extends CommandAbstract_1.CommandAbstract {
59
59
  copy
60
60
  .dataFormat(result, { streams: this.streams, verbose })
61
61
  .log(this.globalOptions.outputFormat);
62
- return result.some((item) => item.error) ? 1 : 0;
62
+ const exitCode = result.some((item) => item.error) ? 1 : 0;
63
+ return { result, exitCode };
63
64
  }
64
65
  }
65
66
  exports.CopyCommand = CopyCommand;
@@ -0,0 +1,19 @@
1
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
2
+ import { If } from "../utils/ts";
3
+ import { CommandAbstract } from "./CommandAbstract";
4
+ export type InitCommandOptions<TResolved = false> = {
5
+ repository?: If<TResolved, string[]>;
6
+ repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
7
+ };
8
+ export declare class InitCommand extends CommandAbstract<InitCommandOptions<false>, InitCommandOptions<true>> {
9
+ optionsConfig(): import("../utils/cli").OptionsConfig<InitCommandOptions<false>, InitCommandOptions<true>>;
10
+ exec(): Promise<{
11
+ result: {
12
+ repositoryName: string;
13
+ repositoryType: string;
14
+ repositorySource: string;
15
+ error: Error | null;
16
+ }[];
17
+ exitCode: number;
18
+ }>;
19
+ }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InitCommand = void 0;
4
- const ConfigAction_1 = require("../Action/ConfigAction");
5
- const InitAction_1 = require("../Action/InitAction");
4
+ const ConfigAction_1 = require("../actions/ConfigAction");
5
+ const InitAction_1 = require("../actions/InitAction");
6
6
  const DataFormat_1 = require("../utils/DataFormat");
7
7
  const cli_1 = require("../utils/cli");
8
8
  const string_1 = require("../utils/string");
9
9
  const CommandAbstract_1 = require("./CommandAbstract");
10
10
  class InitCommand extends CommandAbstract_1.CommandAbstract {
11
- onOptions() {
12
- return this.returnsOptions({
11
+ optionsConfig() {
12
+ return this.castOptionsConfig({
13
13
  repository: {
14
14
  description: "Filter by repository names",
15
15
  option: "-r,--repository <values>",
@@ -22,7 +22,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
22
22
  },
23
23
  });
24
24
  }
25
- async onExec() {
25
+ async exec() {
26
26
  const verbose = this.globalOptions.verbose ?? 0;
27
27
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
28
28
  const init = new InitAction_1.InitAction(config, {
@@ -30,10 +30,10 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
30
30
  repositoryTypes: this.options.repositoryType,
31
31
  verbose: verbose > 0,
32
32
  });
33
- const response = await init.exec();
33
+ const result = await init.exec();
34
34
  const dataFormat = new DataFormat_1.DataFormat({
35
35
  streams: this.streams,
36
- json: response,
36
+ json: result,
37
37
  table: {
38
38
  headers: [
39
39
  { value: "", width: 3 },
@@ -42,7 +42,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
42
42
  { value: "Repository source" },
43
43
  { value: "Error", width: 50 },
44
44
  ],
45
- rows: () => response.map((item) => [
45
+ rows: () => result.map((item) => [
46
46
  (0, cli_1.renderResult)(item.error),
47
47
  item.repositoryName,
48
48
  item.repositoryType,
@@ -53,7 +53,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
53
53
  });
54
54
  if (this.globalOptions.outputFormat)
55
55
  dataFormat.log(this.globalOptions.outputFormat);
56
- return 0;
56
+ return { result, exitCode: 0 };
57
57
  }
58
58
  }
59
59
  exports.InitCommand = InitCommand;
@@ -1,5 +1,5 @@
1
- import { SnapshotGroupByType } from "../Action/SnapshotsAction";
2
- import { RepositoryConfig } from "../Config/RepositoryConfig";
1
+ import { SnapshotGroupByType } from "../actions/SnapshotsAction";
2
+ import type { RepositoryConfig } from "../utils/datatruck/config-type";
3
3
  import { KeepObject } from "../utils/date";
4
4
  import { If } from "../utils/ts";
5
5
  import { CommandAbstract } from "./CommandAbstract";
@@ -16,6 +16,9 @@ export type PruneCommandOptions<TResolved = false> = KeepObject & {
16
16
  confirm?: boolean;
17
17
  };
18
18
  export declare class PruneCommand extends CommandAbstract<PruneCommandOptions<false>, PruneCommandOptions<true>> {
19
- onOptions(): import("../utils/cli").OptionsType<PruneCommandOptions<false>, PruneCommandOptions<true>>;
20
- onExec(): Promise<number>;
19
+ optionsConfig(): import("../utils/cli").OptionsConfig<PruneCommandOptions<false>, PruneCommandOptions<true>>;
20
+ exec(): Promise<{
21
+ result: import("../actions/PruneAction").PruneResult;
22
+ exitCode: number;
23
+ }>;
21
24
  }