starship-butler-utils 0.4.4 → 1.0.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.
- package/package.json +15 -9
- package/dist/chunk-C6wwvPpM.mjs +0 -18
- package/dist/index.d.mts +0 -70
- package/dist/index.mjs +0 -153
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starship-butler-utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "Utils used by starship butler.",
|
|
6
6
|
"author": "Lumirelle <shabbyacc@outlook.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -19,7 +19,12 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"exports": {
|
|
22
|
-
"
|
|
22
|
+
"./config": "./dist/config.mjs",
|
|
23
|
+
"./path": "./dist/path.mjs",
|
|
24
|
+
"./fs": "./dist/fs.mjs",
|
|
25
|
+
"./highlight": "./dist/highlight.mjs",
|
|
26
|
+
"./consola": "./dist/consola.mjs",
|
|
27
|
+
"./prompts": "./dist/prompts.mjs"
|
|
23
28
|
},
|
|
24
29
|
"main": "./dist/index.mjs",
|
|
25
30
|
"module": "./dist/index.mjs",
|
|
@@ -28,14 +33,15 @@
|
|
|
28
33
|
"dist"
|
|
29
34
|
],
|
|
30
35
|
"scripts": {
|
|
31
|
-
"dev": "bun run
|
|
32
|
-
"build": "bun run
|
|
33
|
-
"prepublishOnly": "bun run build",
|
|
34
|
-
"do-publish": "npm publish --access public"
|
|
36
|
+
"dev": "bun run tsdown --watch",
|
|
37
|
+
"build": "bun run tsdown"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
+
"@clack/prompts": "^0.11.0",
|
|
41
|
+
"ansis": "^4.2.0",
|
|
42
|
+
"c12": "^3.3.3",
|
|
43
|
+
"consola": "^3.4.2",
|
|
44
|
+
"pathe": "^2.0.3",
|
|
45
|
+
"rc9": "^2.1.2"
|
|
40
46
|
}
|
|
41
47
|
}
|
package/dist/chunk-C6wwvPpM.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (all, symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __export as t };
|
package/dist/index.d.mts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as ansis0 from "ansis";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Updates or creates a user rc file (rc file under home directory).
|
|
7
|
-
* @param name The name of the rc file.
|
|
8
|
-
* @param config The rc to write.
|
|
9
|
-
*/
|
|
10
|
-
declare function upsertUserRc(name: string, config: any): void;
|
|
11
|
-
declare namespace fs_d_exports {
|
|
12
|
-
export { copyFile, createSymlink, ensureDir, existsSync, isDirectory, removeFile, removeSymlink };
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Check if a file or directory exists. Does not dereference symlinks.
|
|
16
|
-
* @param path - The path to check
|
|
17
|
-
* @returns `true` if the file or directory exists, `false` otherwise
|
|
18
|
-
*/
|
|
19
|
-
declare function existsSync(path: string): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Check if a path is a directory. If path exists, we check the stats, if not, we check if the path ends with `/` or `\`.
|
|
22
|
-
* @param path - The path to check
|
|
23
|
-
* @returns `true` if the path is a directory, `false` otherwise
|
|
24
|
-
*/
|
|
25
|
-
declare function isDirectory(path: string): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Ensure a directory exists.
|
|
28
|
-
* @param dirPath - The path to ensure
|
|
29
|
-
* @returns `true` if the directory is created, `false` otherwise
|
|
30
|
-
*/
|
|
31
|
-
declare function ensureDir(dirPath: string): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Copy a file.
|
|
34
|
-
* @param sourcePath The path to the source file
|
|
35
|
-
* @param targetPath The path to the target file
|
|
36
|
-
* @param force Whether to force overwrite the target file
|
|
37
|
-
* @returns `true` if the file was copied, `false` otherwise
|
|
38
|
-
*/
|
|
39
|
-
declare function copyFile(sourcePath: string, targetPath: string, force?: boolean): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Create a symbolic link.
|
|
42
|
-
* @param sourcePath The path to the source file
|
|
43
|
-
* @param targetPath The path to the target symlink
|
|
44
|
-
* @param force Whether to force overwrite the target symlink
|
|
45
|
-
* @returns `true` if the symlink was created, `false` otherwise
|
|
46
|
-
*/
|
|
47
|
-
declare function createSymlink(sourcePath: string, targetPath: string, force?: boolean): Promise<boolean>;
|
|
48
|
-
/**
|
|
49
|
-
* Remove a file.
|
|
50
|
-
* @param targetPath The path to the target file
|
|
51
|
-
* @returns `true` if the file was removed, `false` otherwise
|
|
52
|
-
*/
|
|
53
|
-
declare function removeFile(targetPath: string): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Remove a symbolic link.
|
|
56
|
-
* @param targetPath The path to the target symlink
|
|
57
|
-
* @returns `true` if the symlink was removed, `false` otherwise
|
|
58
|
-
*/
|
|
59
|
-
declare function removeSymlink(targetPath: string): boolean;
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/highlight.d.ts
|
|
62
|
-
declare const highlight: {
|
|
63
|
-
green: (text: string) => string;
|
|
64
|
-
red: (text: string) => string;
|
|
65
|
-
info: (text: string) => string;
|
|
66
|
-
important: (text: string) => string;
|
|
67
|
-
reset: ansis0.Ansis;
|
|
68
|
-
};
|
|
69
|
-
//#endregion
|
|
70
|
-
export { fs_d_exports as fs, highlight, upsertUserRc };
|
package/dist/index.mjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { t as __export } from "./chunk-C6wwvPpM.mjs";
|
|
2
|
-
import { readUser, updateUser, writeUser } from "rc9";
|
|
3
|
-
import { constants, copyFileSync, lstatSync, mkdirSync, promises, renameSync, unlinkSync } from "node:fs";
|
|
4
|
-
import consola from "consola";
|
|
5
|
-
import { bold, cyan, green, magenta, red, reset } from "ansis";
|
|
6
|
-
|
|
7
|
-
//#region src/config.ts
|
|
8
|
-
/**
|
|
9
|
-
* Updates or creates a user rc file (rc file under home directory).
|
|
10
|
-
* @param name The name of the rc file.
|
|
11
|
-
* @param config The rc to write.
|
|
12
|
-
*/
|
|
13
|
-
function upsertUserRc(name, config) {
|
|
14
|
-
if (!readUser(name)) writeUser(config, name);
|
|
15
|
-
else updateUser(config, name);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/highlight.ts
|
|
20
|
-
const highlight = {
|
|
21
|
-
green: (text) => {
|
|
22
|
-
return green(text);
|
|
23
|
-
},
|
|
24
|
-
red: (text) => {
|
|
25
|
-
return red(text);
|
|
26
|
-
},
|
|
27
|
-
info: (text) => {
|
|
28
|
-
return cyan(text);
|
|
29
|
-
},
|
|
30
|
-
important: (text) => {
|
|
31
|
-
return bold(magenta(text));
|
|
32
|
-
},
|
|
33
|
-
reset
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/fs.ts
|
|
38
|
-
var fs_exports = /* @__PURE__ */ __export({
|
|
39
|
-
copyFile: () => copyFile,
|
|
40
|
-
createSymlink: () => createSymlink,
|
|
41
|
-
ensureDir: () => ensureDir,
|
|
42
|
-
existsSync: () => existsSync,
|
|
43
|
-
isDirectory: () => isDirectory,
|
|
44
|
-
removeFile: () => removeFile,
|
|
45
|
-
removeSymlink: () => removeSymlink
|
|
46
|
-
});
|
|
47
|
-
/**
|
|
48
|
-
* Check if a file or directory exists. Does not dereference symlinks.
|
|
49
|
-
* @param path - The path to check
|
|
50
|
-
* @returns `true` if the file or directory exists, `false` otherwise
|
|
51
|
-
*/
|
|
52
|
-
function existsSync(path) {
|
|
53
|
-
try {
|
|
54
|
-
lstatSync(path);
|
|
55
|
-
return true;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
if (error instanceof Error && error.message.includes("ENOENT")) return false;
|
|
58
|
-
else throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Check if a path is a directory. If path exists, we check the stats, if not, we check if the path ends with `/` or `\`.
|
|
63
|
-
* @param path - The path to check
|
|
64
|
-
* @returns `true` if the path is a directory, `false` otherwise
|
|
65
|
-
*/
|
|
66
|
-
function isDirectory(path) {
|
|
67
|
-
return existsSync(path) && lstatSync(path).isDirectory() || path.match(/\/$|\\$/) !== null;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Ensure a directory exists.
|
|
71
|
-
* @param dirPath - The path to ensure
|
|
72
|
-
* @returns `true` if the directory is created, `false` otherwise
|
|
73
|
-
*/
|
|
74
|
-
function ensureDir(dirPath) {
|
|
75
|
-
if (!existsSync(dirPath)) {
|
|
76
|
-
mkdirSync(dirPath, { recursive: true });
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Copy a file.
|
|
83
|
-
* @param sourcePath The path to the source file
|
|
84
|
-
* @param targetPath The path to the target file
|
|
85
|
-
* @param force Whether to force overwrite the target file
|
|
86
|
-
* @returns `true` if the file was copied, `false` otherwise
|
|
87
|
-
*/
|
|
88
|
-
function copyFile(sourcePath, targetPath, force = false) {
|
|
89
|
-
const isExist = existsSync(targetPath);
|
|
90
|
-
if (isExist) if (!force) {
|
|
91
|
-
consola.warn(`COPY: File already exists: ${highlight.info(targetPath)}, skip`);
|
|
92
|
-
return false;
|
|
93
|
-
} else renameSync(targetPath, `${targetPath}.bak`);
|
|
94
|
-
try {
|
|
95
|
-
copyFileSync(sourcePath, targetPath, force ? constants.COPYFILE_FICLONE : constants.COPYFILE_EXCL);
|
|
96
|
-
if (isExist) removeFile(`${targetPath}.bak`);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
if (isExist) renameSync(`${targetPath}.bak`, targetPath);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Create a symbolic link.
|
|
105
|
-
* @param sourcePath The path to the source file
|
|
106
|
-
* @param targetPath The path to the target symlink
|
|
107
|
-
* @param force Whether to force overwrite the target symlink
|
|
108
|
-
* @returns `true` if the symlink was created, `false` otherwise
|
|
109
|
-
*/
|
|
110
|
-
async function createSymlink(sourcePath, targetPath, force = false) {
|
|
111
|
-
const isExist = existsSync(targetPath);
|
|
112
|
-
if (isExist) if (!force) {
|
|
113
|
-
consola.warn(`LINK: File already exists: ${highlight.info(targetPath)}, skip`);
|
|
114
|
-
return false;
|
|
115
|
-
} else renameSync(targetPath, `${targetPath}.bak`);
|
|
116
|
-
try {
|
|
117
|
-
await promises.symlink(sourcePath, targetPath, "file");
|
|
118
|
-
if (isExist) removeFile(`${targetPath}.bak`);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (isExist) renameSync(`${targetPath}.bak`, targetPath);
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Remove a file.
|
|
127
|
-
* @param targetPath The path to the target file
|
|
128
|
-
* @returns `true` if the file was removed, `false` otherwise
|
|
129
|
-
*/
|
|
130
|
-
function removeFile(targetPath) {
|
|
131
|
-
if (!existsSync(targetPath)) {
|
|
132
|
-
consola.warn(`REMOVE: Target file not found: ${highlight.info(targetPath)}, skip`);
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
unlinkSync(targetPath);
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Remove a symbolic link.
|
|
140
|
-
* @param targetPath The path to the target symlink
|
|
141
|
-
* @returns `true` if the symlink was removed, `false` otherwise
|
|
142
|
-
*/
|
|
143
|
-
function removeSymlink(targetPath) {
|
|
144
|
-
if (!lstatSync(targetPath).isSymbolicLink()) {
|
|
145
|
-
consola.warn(`REMOVE: Target file is not a symlink: ${highlight.info(targetPath)}, skip`);
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
removeFile(targetPath);
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
export { fs_exports as fs, highlight, upsertUserRc };
|