@datatruck/cli 0.3.2 → 0.6.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 (45) hide show
  1. package/Action/BackupAction.js +1 -0
  2. package/Action/ConfigAction.d.ts +6 -1
  3. package/Action/ConfigAction.js +17 -1
  4. package/Action/InitAction.js +3 -0
  5. package/Action/PruneAction.js +1 -1
  6. package/Action/RestoreAction.js +4 -1
  7. package/Action/SnapshotsAction.d.ts +2 -1
  8. package/Action/SnapshotsAction.js +6 -1
  9. package/CHANGELOG.md +28 -0
  10. package/Command/BackupCommand.js +1 -5
  11. package/Command/BackupSessionsCommand.js +1 -5
  12. package/Command/CommandAbstract.d.ts +2 -1
  13. package/Command/ConfigCommand.js +1 -5
  14. package/Command/InitCommand.js +1 -5
  15. package/Command/PruneCommand.js +1 -5
  16. package/Command/RestoreCommand.js +1 -5
  17. package/Command/RestoreSessionsCommand.js +1 -5
  18. package/Command/SnapshotsCommand.js +1 -5
  19. package/Config/Config.d.ts +1 -0
  20. package/Config/Config.js +1 -0
  21. package/Config/RepositoryConfig.d.ts +4 -0
  22. package/Config/RepositoryConfig.js +19 -0
  23. package/Repository/GitRepository.js +2 -3
  24. package/Repository/LocalRepository.d.ts +4 -0
  25. package/Repository/LocalRepository.js +38 -37
  26. package/Repository/RepositoryAbstract.d.ts +4 -4
  27. package/Repository/ResticRepository.d.ts +7 -3
  28. package/Repository/ResticRepository.js +33 -12
  29. package/SessionDriver/ConsoleSessionDriver.js +12 -11
  30. package/Task/GitTask.d.ts +4 -0
  31. package/Task/GitTask.js +28 -29
  32. package/Task/MariadbTask.js +26 -14
  33. package/Task/MssqlTask.js +1 -2
  34. package/Task/TaskAbstract.d.ts +4 -4
  35. package/cli.js +18 -1
  36. package/config.schema.json +61 -3
  37. package/globalData.d.ts +5 -0
  38. package/globalData.js +7 -0
  39. package/package.json +2 -2
  40. package/util/GitUtil.js +2 -2
  41. package/util/ResticUtil.js +1 -2
  42. package/util/datatruck/config-util.d.ts +4 -1
  43. package/util/datatruck/config-util.js +11 -1
  44. package/util/fs-util.d.ts +33 -0
  45. package/util/fs-util.js +78 -7
package/util/fs-util.js CHANGED
@@ -1,16 +1,21 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = void 0;
6
+ exports.cpy = exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = void 0;
7
+ const globalData_1 = __importDefault(require("../globalData"));
4
8
  const path_util_1 = require("./path-util");
9
+ const async_1 = require("async");
5
10
  const crypto_1 = require("crypto");
11
+ const fast_glob_1 = __importDefault(require("fast-glob"));
6
12
  const fs_1 = require("fs");
7
13
  const fs_2 = require("fs");
8
- const fs_extra_1 = require("fs-extra");
9
14
  const promises_1 = require("fs/promises");
10
15
  const micromatch_1 = require("micromatch");
11
- const os_1 = require("os");
12
16
  const path_1 = require("path");
13
17
  const path_2 = require("path");
18
+ const readline_1 = require("readline");
14
19
  function isLocalDir(path) {
15
20
  return /^[\/\.]|([A-Z]:)/i.test(path);
16
21
  }
@@ -22,7 +27,7 @@ async function isDirEmpty(path) {
22
27
  exports.isDirEmpty = isDirEmpty;
23
28
  async function mkdirIfNotExists(path) {
24
29
  try {
25
- await (0, fs_extra_1.mkdir)(path, {
30
+ await (0, promises_1.mkdir)(path, {
26
31
  recursive: true,
27
32
  });
28
33
  }
@@ -110,8 +115,7 @@ async function existsFile(path) {
110
115
  }
111
116
  exports.existsFile = existsFile;
112
117
  function parentTmpDir() {
113
- const tmpDir = (0, os_1.tmpdir)();
114
- return (0, path_1.join)(tmpDir, "datatruck");
118
+ return (0, path_1.join)(globalData_1.default.tempDir, "datatruck-temp");
115
119
  }
116
120
  exports.parentTmpDir = parentTmpDir;
117
121
  function sessionTmpDir() {
@@ -126,7 +130,7 @@ function tmpDir(prefix, id) {
126
130
  exports.tmpDir = tmpDir;
127
131
  async function mkTmpDir(prefix, id) {
128
132
  const path = tmpDir(prefix, id);
129
- await (0, fs_extra_1.mkdir)(path, { recursive: true });
133
+ await (0, promises_1.mkdir)(path, { recursive: true });
130
134
  return path;
131
135
  }
132
136
  exports.mkTmpDir = mkTmpDir;
@@ -311,3 +315,70 @@ async function writePathLists(options) {
311
315
  };
312
316
  }
313
317
  exports.writePathLists = writePathLists;
318
+ async function cpy(options) {
319
+ const stats = { paths: 0, files: 0, dirs: 0 };
320
+ const dirs = new Set();
321
+ const makeRecursiveDir = async (path) => {
322
+ if (!dirs.has(path)) {
323
+ stats.paths++;
324
+ stats.dirs++;
325
+ await (0, promises_1.mkdir)(path, {
326
+ recursive: true,
327
+ });
328
+ dirs.add(path);
329
+ }
330
+ };
331
+ const task = async (rawEntryPath, basePath) => {
332
+ const isDir = rawEntryPath.endsWith("/");
333
+ const entryPath = (0, path_1.normalize)(rawEntryPath);
334
+ const entrySourcePath = (0, path_1.resolve)((0, path_1.join)(basePath, rawEntryPath));
335
+ const entryTargetPath = (0, path_1.resolve)((0, path_1.join)(options.targetPath, rawEntryPath));
336
+ const onPathResult = await options?.onPath?.({
337
+ isDir,
338
+ entryPath,
339
+ entrySourcePath,
340
+ entryTargetPath,
341
+ stats,
342
+ });
343
+ if (onPathResult === false) {
344
+ return;
345
+ }
346
+ else if (isDir) {
347
+ await makeRecursiveDir(entryTargetPath);
348
+ }
349
+ else {
350
+ const dir = (0, path_1.dirname)(entryTargetPath);
351
+ await makeRecursiveDir(dir);
352
+ stats.files++;
353
+ await (0, promises_1.cp)(entrySourcePath, entryTargetPath);
354
+ }
355
+ };
356
+ const { input } = options;
357
+ if (input.type === "glob") {
358
+ const stream = await (0, fast_glob_1.default)(input.include || ["**"], {
359
+ cwd: input.sourcePath,
360
+ ignore: input.exclude,
361
+ dot: true,
362
+ onlyFiles: false,
363
+ markDirectories: true,
364
+ });
365
+ await (0, async_1.eachLimit)(stream, options.concurrency ?? 1, async (entryPath) => await task(entryPath, input.sourcePath));
366
+ }
367
+ else if (input.type === "stream") {
368
+ await (0, async_1.eachLimit)(input.value, options.concurrency ?? 1, async (entryPath) => await task(entryPath, input.basePath));
369
+ }
370
+ else if (input.type === "pathList") {
371
+ const stream = (0, readline_1.createInterface)({
372
+ input: (0, fs_1.createReadStream)(input.path),
373
+ });
374
+ await cpy({
375
+ ...options,
376
+ input: {
377
+ type: "stream",
378
+ value: stream,
379
+ basePath: input.basePath,
380
+ },
381
+ });
382
+ }
383
+ }
384
+ exports.cpy = cpy;