-
Notifications
You must be signed in to change notification settings - Fork 16
/
after.js
25 lines (23 loc) · 1.03 KB
/
after.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import console, { originalConsole } from "../modules/console.js";
originalConsole.info("=".repeat(120));
console.info("Initialization done.");
import git from "../modules/git.js";
import mkdtmp from "../modules/mkdtmp.js";
import fs from "node:fs";
import path from "node:path";
const packageLockFile = "package-lock.json";
console.info("Start to recover", packageLockFile);
const tmpdir = await mkdtmp({
subDir: process.env.RANDOM_UUID,
});
const backupedPackageLockFile = path.join(tmpdir, packageLockFile);
console.info("Start to check backup file:", backupedPackageLockFile);
const backupedPackageLockFileExists = await fs.promises.access(backupedPackageLockFile).then(() => true).catch(() => false);
if (backupedPackageLockFileExists) {
console.info("Backup file exists, use it to recover.");
await fs.promises.cp(backupedPackageLockFile, packageLockFile, { force: true, preserveTimestamps: true });
} else {
console.info("Backup file unexists, use `git` to recover.");
await git.checkout(packageLockFile);
}
console.info("Done.");