starship-butler-utils 0.0.1-beta.2 → 0.0.1-beta.4

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 (2) hide show
  1. package/dist/index.mjs +16 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -55,7 +55,8 @@ function ensureDir(dirPath) {
55
55
  return false;
56
56
  }
57
57
  function copyFile(sourcePath, targetPath, force = false) {
58
- if (existsSync(targetPath)) {
58
+ const isExist = existsSync(targetPath);
59
+ if (isExist) {
59
60
  if (!force) {
60
61
  consola.warn(`COPY: File already exists: ${highlight.info(targetPath)}, skip`);
61
62
  return false;
@@ -65,16 +66,21 @@ function copyFile(sourcePath, targetPath, force = false) {
65
66
  }
66
67
  try {
67
68
  copyFileSync(sourcePath, targetPath, force ? constants.COPYFILE_FICLONE : constants.COPYFILE_EXCL);
68
- removeFile(`${targetPath}.bak`);
69
+ if (isExist) {
70
+ removeFile(`${targetPath}.bak`);
71
+ }
69
72
  } catch (error) {
70
- renameSync(`${targetPath}.bak`, targetPath);
73
+ if (isExist) {
74
+ renameSync(`${targetPath}.bak`, targetPath);
75
+ }
71
76
  consola.error(error);
72
77
  return false;
73
78
  }
74
79
  return true;
75
80
  }
76
81
  async function createSymlink(sourcePath, targetPath, force = false) {
77
- if (existsSync(targetPath)) {
82
+ const isExist = existsSync(targetPath);
83
+ if (isExist) {
78
84
  if (!force) {
79
85
  consola.warn(`LINK: File already exists: ${highlight.info(targetPath)}, skip`);
80
86
  return false;
@@ -84,9 +90,13 @@ async function createSymlink(sourcePath, targetPath, force = false) {
84
90
  }
85
91
  try {
86
92
  await promises.symlink(sourcePath, targetPath, "file");
87
- removeFile(`${targetPath}.bak`);
93
+ if (isExist) {
94
+ removeFile(`${targetPath}.bak`);
95
+ }
88
96
  } catch (error) {
89
- renameSync(`${targetPath}.bak`, targetPath);
97
+ if (isExist) {
98
+ renameSync(`${targetPath}.bak`, targetPath);
99
+ }
90
100
  consola.error(error);
91
101
  return false;
92
102
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "starship-butler-utils",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.2",
4
+ "version": "0.0.1-beta.4",
5
5
  "description": "Your best starship butler.",
6
6
  "author": "Lumirelle <shabbyacc@outlook.com>",
7
7
  "license": "MIT",