@datatruck/cli 0.9.0 → 0.10.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.
@@ -25,6 +25,7 @@ export declare class BackupAction<TRequired extends boolean = true> {
25
25
  protected init(session: BackupSessionManager): Promise<[SnapshotType, PackageConfigType[]]>;
26
26
  protected execTask(session: BackupSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
27
27
  protected execRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
28
+ protected execCopyRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, mirrorRepo: RepositoryConfigType, snapshot: SnapshotType): Promise<boolean>;
28
29
  protected getError(pkg: PackageConfigType): AppError | null;
29
30
  exec(session: BackupSessionManager): Promise<{
30
31
  total: number;
@@ -144,6 +144,50 @@ class BackupAction {
144
144
  });
145
145
  return error ? false : true;
146
146
  }
147
+ async execCopyRepository(session, pkg, repo, mirrorRepo, snapshot) {
148
+ const repositoryId = session.findRepositoryId({
149
+ packageName: pkg.name,
150
+ repositoryName: mirrorRepo.name,
151
+ });
152
+ await session.startRepository({
153
+ id: repositoryId,
154
+ });
155
+ let error;
156
+ if (this.taskErrors[pkg.name]?.length) {
157
+ error = new AppError_1.AppError("Task failed");
158
+ }
159
+ else {
160
+ try {
161
+ const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
162
+ await repoInstance.onCopyBackup({
163
+ options: this.options,
164
+ package: pkg,
165
+ snapshot,
166
+ mirrorRepositoryConfig: mirrorRepo.config,
167
+ onProgress: async (data) => {
168
+ await session.progressRepository({
169
+ id: repositoryId,
170
+ progressCurrent: data.current,
171
+ progressPercent: data.percent,
172
+ progressStep: data.step,
173
+ progressStepPercent: data.stepPercent,
174
+ progressTotal: data.total,
175
+ });
176
+ },
177
+ });
178
+ }
179
+ catch (_) {
180
+ if (!this.repoErrors[pkg.name])
181
+ this.repoErrors[pkg.name] = [];
182
+ this.repoErrors[pkg.name].push((error = _));
183
+ }
184
+ }
185
+ await session.endRepository({
186
+ id: repositoryId,
187
+ error: error?.stack,
188
+ });
189
+ return error ? false : true;
190
+ }
147
191
  getError(pkg) {
148
192
  const taskErrors = this.taskErrors[pkg.name]?.length;
149
193
  const repoErrors = this.repoErrors[pkg.name]?.length;
@@ -182,10 +226,33 @@ class BackupAction {
182
226
  });
183
227
  await this.execTask(session, pkg, pkg.task, snapshot, (targetPath = result?.targetPath));
184
228
  }
185
- for (const repoName of pkg.repositoryNames ?? []) {
229
+ const mirrorRepoMap = {};
230
+ const allMirrorRepoNames = [];
231
+ const repoNames = pkg.repositoryNames ?? [];
232
+ for (const repoName of repoNames) {
233
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
234
+ if (repo.mirrorRepoNames)
235
+ mirrorRepoMap[repoName] = repo.mirrorRepoNames.filter((mirrorRepoName) => {
236
+ allMirrorRepoNames.push(mirrorRepoName);
237
+ return repoNames.includes(mirrorRepoName);
238
+ });
239
+ }
240
+ for (const repoName of repoNames) {
241
+ if (allMirrorRepoNames.includes(repoName))
242
+ continue;
186
243
  const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
187
244
  await this.execRepository(session, pkg, repo, snapshot, targetPath);
188
245
  }
246
+ for (const repoName of repoNames) {
247
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
248
+ const mirrorRepoNames = mirrorRepoMap[repoName];
249
+ if (mirrorRepoNames) {
250
+ for (const mirrorRepoName of mirrorRepoNames) {
251
+ const mirrorRepo = (0, config_util_1.findRepositoryOrFail)(this.config, mirrorRepoName);
252
+ await this.execCopyRepository(session, pkg, repo, mirrorRepo, snapshot);
253
+ }
254
+ }
255
+ }
189
256
  const error = this.getError(pkg);
190
257
  if (error)
191
258
  errors++;
@@ -22,11 +22,27 @@ class ConfigAction {
22
22
  }
23
23
  static check(config) {
24
24
  const repositoryNames = [];
25
+ const mirrorRepoNames = [];
26
+ const repos = {};
25
27
  for (const repo of config.repositories) {
28
+ repos[repo.name] = repo;
26
29
  if (repositoryNames.includes(repo.name))
27
30
  throw new AppError_1.AppError(`Duplicated repository name: ${repo.name}`);
28
31
  repositoryNames.push(repo.name);
29
32
  }
33
+ for (const repo of config.repositories) {
34
+ if (repo.mirrorRepoNames) {
35
+ for (const mirrorRepoName of repo.mirrorRepoNames) {
36
+ if (!repos[mirrorRepoName])
37
+ throw new AppError_1.AppError(`Mirror repository name not found: ${mirrorRepoName}`);
38
+ if (repos[mirrorRepoName].type !== repo.type)
39
+ throw new AppError_1.AppError(`Mirror repository type is incompatible: ${mirrorRepoName}`);
40
+ if (mirrorRepoNames.includes(mirrorRepoName))
41
+ throw new AppError_1.AppError(`Mirror repository is already used`);
42
+ mirrorRepoNames.push(mirrorRepoName);
43
+ }
44
+ }
45
+ }
30
46
  const packageNames = [];
31
47
  for (const pkg of config.packages) {
32
48
  if (packageNames.includes(pkg.name))
@@ -77,7 +77,7 @@ class BackupSessionsCommand extends CommandAbstract_1.CommandAbstract {
77
77
  },
78
78
  });
79
79
  if (this.globalOptions.outputFormat)
80
- console.log(dataFormat.format(this.globalOptions.outputFormat));
80
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
81
81
  return 0;
82
82
  }
83
83
  }
@@ -56,7 +56,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
56
56
  },
57
57
  });
58
58
  if (this.globalOptions.outputFormat)
59
- console.log(dataFormat.format(this.globalOptions.outputFormat));
59
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
60
60
  return 0;
61
61
  }
62
62
  }
@@ -56,7 +56,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
56
56
  },
57
57
  });
58
58
  if (this.globalOptions.outputFormat)
59
- console.log(dataFormat.format(this.globalOptions.outputFormat));
59
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
60
60
  return 0;
61
61
  }
62
62
  }
@@ -144,7 +144,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
144
144
  },
145
145
  });
146
146
  if (this.globalOptions.outputFormat)
147
- console.log(dataFormat.format(this.globalOptions.outputFormat));
147
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
148
148
  if (!this.options.confirm && !this.options.dryRun) {
149
149
  const answer = await (0, cli_util_1.confirm)(`Delete ${pruneResult.prune}/${pruneResult.total} snapshots?`);
150
150
  if (answer)
@@ -76,7 +76,7 @@ class RestoreSessionsCommand extends CommandAbstract_1.CommandAbstract {
76
76
  },
77
77
  });
78
78
  if (this.globalOptions.outputFormat)
79
- console.log(dataFormat.format(this.globalOptions.outputFormat));
79
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
80
80
  return 0;
81
81
  }
82
82
  }
@@ -128,7 +128,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
128
128
  },
129
129
  });
130
130
  if (this.globalOptions.outputFormat)
131
- console.log(dataFormat.format(this.globalOptions.outputFormat));
131
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
132
132
  return 0;
133
133
  }
134
134
  }
@@ -7,6 +7,7 @@ export declare type RepositoryConfigTypeType = RepositoryConfigType["type"];
7
7
  export declare type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
8
8
  export declare type RepositoryConfigType = {
9
9
  name: string;
10
+ mirrorRepoNames?: string[];
10
11
  enabled?: boolean | {
11
12
  [K in "defaults" | RepositoryConfigEnabledActionType]?: boolean;
12
13
  };
@@ -17,6 +17,7 @@ exports.repositoryConfigDefinition = {
17
17
  properties: {
18
18
  type: { type: "string" },
19
19
  name: { type: "string" },
20
+ mirrorRepoNames: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
20
21
  enabled: {
21
22
  anyOf: [
22
23
  {
@@ -35,11 +35,11 @@ exports.exec = exec;
35
35
  function makeParseLog(type) {
36
36
  const data = [];
37
37
  const consoleLog = console.log;
38
- console.log = (...items) => {
38
+ console.log = console.info = (...items) => {
39
39
  data.push(...items);
40
40
  };
41
41
  return function parseLog() {
42
- console.log = consoleLog;
42
+ console.log = console.info = consoleLog;
43
43
  return JSON.parse(data.flat().join("\n"));
44
44
  };
45
45
  }
@@ -1,4 +1,4 @@
1
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType } from "./RepositoryAbstract";
1
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export declare type GitRepositoryConfigType = {
4
4
  repo: string;
@@ -25,5 +25,6 @@ export declare class GitRepository extends RepositoryAbstract<GitRepositoryConfi
25
25
  onPrune(data: PruneDataType): Promise<void>;
26
26
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
27
27
  onBackup(data: BackupDataType<GitPackageRepositoryConfigType>): Promise<void>;
28
+ onCopyBackup(data: CopyBackupType<GitRepositoryConfigType>): Promise<void>;
28
29
  onRestore(data: RestoreDataType<GitPackageRepositoryConfigType>): Promise<void>;
29
30
  }
@@ -215,6 +215,9 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
215
215
  recursive: true,
216
216
  });
217
217
  }
218
+ onCopyBackup(data) {
219
+ throw new Error("Method not implemented.");
220
+ }
218
221
  async onRestore(data) {
219
222
  const restorePath = data.targetPath ?? data.package.restorePath;
220
223
  (0, assert_1.ok)(restorePath);
@@ -1,4 +1,4 @@
1
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType } from "./RepositoryAbstract";
1
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import type { JSONSchema7 } from "json-schema";
3
3
  export declare type MetaDataType = {
4
4
  id: string;
@@ -51,6 +51,7 @@ export declare class LocalRepository extends RepositoryAbstract<LocalRepositoryC
51
51
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
52
52
  private normalizeCompressConfig;
53
53
  onBackup(data: BackupDataType<LocalPackageRepositoryConfigType>): Promise<void>;
54
+ onCopyBackup(data: CopyBackupType<LocalRepositoryConfigType>): Promise<void>;
54
55
  onRestore(data: RestoreDataType<LocalPackageRepositoryConfigType>): Promise<void>;
55
56
  }
56
57
  export {};
@@ -122,7 +122,7 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
122
122
  async onSnapshots(data) {
123
123
  if (!(await (0, fs_util_1.checkDir)(this.config.outPath)))
124
124
  throw new Error(`Repository (${this.repository.name}) out path does not exist: ${this.config.outPath}`);
125
- const snapshotNames = await (0, promises_1.readdir)(this.config.outPath);
125
+ const snapshotNames = await (0, fs_util_1.readDir)(this.config.outPath);
126
126
  const snapshots = [];
127
127
  const packagePatterns = (0, string_util_1.makePathPatterns)(data.options.packageNames);
128
128
  const taskPatterns = (0, string_util_1.makePathPatterns)(data.options.packageTaskNames);
@@ -299,6 +299,28 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
299
299
  (0, cli_util_1.logExec)(`Writing metadata into ${metaPath}`);
300
300
  await (0, promises_1.writeFile)(metaPath, LocalRepository.stringifyMetaData(meta));
301
301
  }
302
+ async onCopyBackup(data) {
303
+ const snapshotName = LocalRepository.buildSnapshotName({
304
+ snapshotId: data.snapshot.id,
305
+ snapshotDate: data.snapshot.date,
306
+ packageName: data.package.name,
307
+ });
308
+ const sourcePath = (0, path_1.resolve)((0, path_1.join)(this.config.outPath, snapshotName));
309
+ const targetPath = (0, path_1.resolve)((0, path_1.join)(data.mirrorRepositoryConfig.outPath, snapshotName));
310
+ const sourceMetaPath = `${sourcePath}.json`;
311
+ const targetMetaPath = `${targetPath}.json`;
312
+ if (data.options.verbose)
313
+ (0, cli_util_1.logExec)(`Copying files to ${targetPath}`);
314
+ await (0, promises_1.mkdir)(targetPath);
315
+ await (0, fs_util_1.cpy)({
316
+ input: {
317
+ type: "glob",
318
+ sourcePath,
319
+ },
320
+ targetPath,
321
+ });
322
+ await (0, promises_1.copyFile)(sourceMetaPath, targetMetaPath);
323
+ }
302
324
  async onRestore(data) {
303
325
  const relRestorePath = data.targetPath ?? data.package.restorePath;
304
326
  (0, assert_1.ok)(relRestorePath);
@@ -27,6 +27,13 @@ export declare type InitDataType = {
27
27
  export declare type SnapshotsDataType = {
28
28
  options: Pick<SnapshotsActionOptionsType, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
29
29
  };
30
+ export declare type CopyBackupType<TRepositoryConfig> = {
31
+ options: BackupActionOptionsType;
32
+ snapshot: SnapshotType;
33
+ package: PackageConfigType;
34
+ mirrorRepositoryConfig: TRepositoryConfig;
35
+ onProgress: (data: ProgressDataType) => Promise<void>;
36
+ };
30
37
  export declare type BackupDataType<TPackageConfig> = {
31
38
  options: BackupActionOptionsType;
32
39
  snapshot: SnapshotType;
@@ -75,6 +82,7 @@ export declare abstract class RepositoryAbstract<TConfig> {
75
82
  abstract onInit(data: InitDataType): Promise<void>;
76
83
  abstract onPrune(data: PruneDataType): Promise<void>;
77
84
  abstract onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
85
+ abstract onCopyBackup(data: CopyBackupType<TConfig>): Promise<void>;
78
86
  abstract onBackup(data: BackupDataType<unknown>): Promise<void>;
79
87
  abstract onRestore(data: RestoreDataType<unknown>): Promise<void>;
80
88
  }
@@ -1,5 +1,5 @@
1
1
  import { RepositoryType } from "../util/ResticUtil";
2
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType } from "./RepositoryAbstract";
2
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  export declare type ResticRepositoryConfigType = {
5
5
  password: string | {
@@ -36,5 +36,6 @@ export declare class ResticRepository extends RepositoryAbstract<ResticRepositor
36
36
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
37
37
  onPrune(data: PruneDataType): Promise<void>;
38
38
  onBackup(data: BackupDataType<ResticPackageRepositoryConfigType>): Promise<void>;
39
+ onCopyBackup(data: CopyBackupType<ResticRepositoryConfigType>): Promise<void>;
39
40
  onRestore(data: RestoreDataType<ResticPackageRepositoryConfigType>): Promise<void>;
40
41
  }
@@ -271,6 +271,30 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
271
271
  percent: 100,
272
272
  });
273
273
  }
274
+ async onCopyBackup(data) {
275
+ const config = data.mirrorRepositoryConfig;
276
+ const [snapshot] = await this.onSnapshots({
277
+ options: {
278
+ ids: [data.snapshot.id],
279
+ packageNames: [data.package.name],
280
+ },
281
+ });
282
+ if (!snapshot)
283
+ throw new AppError_1.AppError(`Snapshot not found`);
284
+ const restic = new ResticUtil_1.ResticUtil({
285
+ env: {
286
+ ...(await this.buildEnv()),
287
+ ...(typeof config.password === "string"
288
+ ? { RESTIC_PASSWORD2: config.password }
289
+ : { RESTIC_PASSWORD_FILE2: (0, path_1.resolve)(config.password.path) }),
290
+ RESTIC_REPOSITORY2: await ResticUtil_1.ResticUtil.formatRepository(config.repository),
291
+ },
292
+ log: data.options.verbose,
293
+ });
294
+ await restic.copy({
295
+ id: snapshot.originalId,
296
+ });
297
+ }
274
298
  async onRestore(data) {
275
299
  const restorePath = data.targetPath ?? data.package.restorePath;
276
300
  (0, assert_1.ok)(restorePath);
@@ -137,7 +137,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
137
137
  const restorePath = data.package.restorePath;
138
138
  (0, assert_1.ok)(typeof restorePath === "string");
139
139
  await (0, fs_util_1.mkdirIfNotExists)(restorePath);
140
- const files = await (0, promises_1.readdir)(restorePath);
140
+ const files = await (0, fs_util_1.readDir)(restorePath);
141
141
  for (const file of files) {
142
142
  if (file.startsWith("ib_logfile")) {
143
143
  const filePath = (0, path_1.join)(restorePath, file);
package/Task/MssqlTask.js CHANGED
@@ -84,7 +84,7 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
84
84
  const restorePath = data.package.restorePath;
85
85
  (0, assert_1.ok)(typeof restorePath === "string");
86
86
  await (0, fs_util_1.mkdirIfNotExists)(restorePath);
87
- const files = await (0, promises_1.readdir)(restorePath);
87
+ const files = await (0, fs_util_1.readDir)(restorePath);
88
88
  for (const file of files) {
89
89
  if (!file.endsWith(MssqlTask.SUFFIX))
90
90
  continue;
@@ -160,7 +160,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
160
160
  database: database.name,
161
161
  });
162
162
  }
163
- const items = (await (0, promises_1.readdir)(restorePath))
163
+ const items = (await (0, fs_util_1.readDir)(restorePath))
164
164
  .map(parseSqlFile)
165
165
  .filter((v) => !!v);
166
166
  // Database check
package/cli.js CHANGED
@@ -104,7 +104,7 @@ function parseArgs(args) {
104
104
  (0, process_util_1.onExit)((eventName, error) => {
105
105
  if (eventName !== "exit") {
106
106
  process.stdout.write(cli_util_1.showCursorCommand);
107
- console.log(`\nClosing... (reason: ${eventName})`);
107
+ console.info(`\nClosing... (reason: ${eventName})`);
108
108
  if (error instanceof Error)
109
109
  console.error((0, chalk_1.red)(error.stack));
110
110
  }
@@ -20,6 +20,9 @@
20
20
  "name": {
21
21
  "type": "string"
22
22
  },
23
+ "mirrorRepoNames": {
24
+ "$ref": "#/definitions/stringlist-util"
25
+ },
23
26
  "enabled": {
24
27
  "anyOf": [
25
28
  {
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "dependencies": {
5
5
  "ajv": "^8.11.0",
6
6
  "async": "^3.2.4",
7
7
  "chalk": "^4.1.2",
8
8
  "cli-table3": "^0.6.2",
9
- "commander": "^9.3.0",
10
- "dayjs": "^1.11.3",
9
+ "commander": "^9.4.0",
10
+ "dayjs": "^1.11.5",
11
11
  "fast-glob": "^3.2.11",
12
12
  "micromatch": "^4.0.5",
13
- "sqlite": "^4.1.1",
14
- "sqlite3": "^5.0.8"
13
+ "sqlite": "^4.1.2",
14
+ "sqlite3": "^5.0.11"
15
15
  },
16
16
  "optionalDependencies": {
17
- "ts-node": "^10.8.2",
17
+ "ts-node": "^10.9.1",
18
18
  "yaml": "^2.1.1"
19
19
  },
20
20
  "engine": {
package/util/GitUtil.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitUtil = void 0;
4
4
  const fs_util_1 = require("./fs-util");
5
5
  const process_util_1 = require("./process-util");
6
- const promises_1 = require("fs/promises");
7
6
  class GitUtil {
8
7
  constructor(options) {
9
8
  this.options = options;
@@ -16,7 +15,7 @@ class GitUtil {
16
15
  }
17
16
  async canBeInit(repo) {
18
17
  return ((0, fs_util_1.isLocalDir)(repo) &&
19
- (!(await (0, fs_util_1.checkDir)(repo)) || !(await (0, promises_1.readdir)(repo)).length));
18
+ (!(await (0, fs_util_1.checkDir)(repo)) || !(await (0, fs_util_1.readDir)(repo)).length));
20
19
  }
21
20
  async clone(options) {
22
21
  return await this.exec([
@@ -86,6 +86,10 @@ export declare class ResticUtil {
86
86
  allowEmptySnapshot?: boolean;
87
87
  onStream?: (data: BackupStreamType) => void;
88
88
  }): Promise<ExecResultType>;
89
+ copy(options: {
90
+ id: string;
91
+ onStream?: (data: BackupStreamType) => Promise<void>;
92
+ }): Promise<ExecResultType>;
89
93
  restore(options: {
90
94
  id: string;
91
95
  target: string;
@@ -154,6 +154,22 @@ class ResticUtil {
154
154
  throw error;
155
155
  }
156
156
  }
157
+ async copy(options) {
158
+ return await this.exec(["copy", "--json", options.id], {
159
+ stderr: {
160
+ toExitCode: true,
161
+ },
162
+ stdout: {
163
+ ...(options.onStream && {
164
+ onData: async (data) => {
165
+ if (data.startsWith("{") && data.endsWith("}")) {
166
+ await options.onStream?.(JSON.parse(data));
167
+ }
168
+ },
169
+ }),
170
+ },
171
+ });
172
+ }
157
173
  async restore(options) {
158
174
  return await this.exec(["restore", "--json", options.id, "--target", options.target], {
159
175
  stderr: {
package/util/cli-util.js CHANGED
@@ -32,11 +32,11 @@ function logVars(data) {
32
32
  let first = true;
33
33
  for (const key in data) {
34
34
  if (first) {
35
- console.log();
35
+ console.info();
36
36
  first = false;
37
37
  }
38
38
  const value = data[key];
39
- console.log(`${chalk_1.default.cyan(key)}${chalk_1.default.grey(":")} ${chalk_1.default.white(value ?? "")}`);
39
+ console.info(`${chalk_1.default.cyan(key)}${chalk_1.default.grey(":")} ${chalk_1.default.white(value ?? "")}`);
40
40
  }
41
41
  }
42
42
  exports.logVars = logVars;
package/util/fs-util.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare function mkTmpDir(prefix: string, id?: string): Promise<string>;
24
24
  export declare function readPartialFile(path: string, positions: [number, number?]): Promise<string>;
25
25
  export declare function checkFile(path: string): Promise<boolean>;
26
26
  export declare function checkDir(path: string): Promise<boolean>;
27
+ export declare function readDir(path: string): Promise<string[]>;
27
28
  export declare function forEachFile(dirPath: string, cb: (path: string, dir: boolean) => void, includeDir?: boolean): Promise<void>;
28
29
  export declare function writeGitIgnoreList(options: {
29
30
  paths: NodeJS.ReadableStream | string[];
package/util/fs-util.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
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;
6
+ exports.cpy = exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.readDir = 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
7
  const globalData_1 = __importDefault(require("../globalData"));
8
8
  const path_util_1 = require("./path-util");
9
9
  const async_1 = require("async");
@@ -21,7 +21,7 @@ function isLocalDir(path) {
21
21
  }
22
22
  exports.isLocalDir = isLocalDir;
23
23
  async function isDirEmpty(path) {
24
- const files = await (0, promises_1.readdir)(path);
24
+ const files = await readDir(path);
25
25
  return !files.length;
26
26
  }
27
27
  exports.isDirEmpty = isDirEmpty;
@@ -57,7 +57,7 @@ exports.writeJSONFile = writeJSONFile;
57
57
  async function readdirIfExists(path) {
58
58
  if (!(await existsDir(path)))
59
59
  return [];
60
- return await (0, promises_1.readdir)(path);
60
+ return await readDir(path);
61
61
  }
62
62
  exports.readdirIfExists = readdirIfExists;
63
63
  exports.parseFileExtensions = ["json", "js", "ts", "yaml", "yml"];
@@ -179,8 +179,25 @@ async function checkDir(path) {
179
179
  }
180
180
  }
181
181
  exports.checkDir = checkDir;
182
+ async function readDir(path) {
183
+ try {
184
+ return await (0, promises_1.readdir)(path);
185
+ }
186
+ catch (anyError) {
187
+ const nodeError = anyError;
188
+ if (nodeError.code === "ENOENT") {
189
+ const error = new Error(nodeError.message);
190
+ error.code = nodeError.code;
191
+ error.errno = nodeError.errno;
192
+ error.path = nodeError.path;
193
+ throw error;
194
+ }
195
+ throw anyError;
196
+ }
197
+ }
198
+ exports.readDir = readDir;
182
199
  async function forEachFile(dirPath, cb, includeDir) {
183
- const files = await (0, promises_1.readdir)(dirPath);
200
+ const files = await readDir(dirPath);
184
201
  for (const file of files) {
185
202
  const filePath = (0, path_1.join)(dirPath, file);
186
203
  if ((await (0, promises_1.stat)(filePath)).isDirectory()) {