forked from bombshell-dev/clack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
54 lines (42 loc) · 1.1 KB
/
index.ts
File metadata and controls
54 lines (42 loc) · 1.1 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { setTimeout } from 'node:timers/promises';
import * as p from '@clack/prompts';
import color from 'picocolors';
import { resolve } from "node:path";
import { statSync } from "node:fs";
function onCancel() {
p.cancel('Operation cancelled.');
process.exit(0);
}
async function main() {
console.clear();
await setTimeout(1000);
const filePath = await p.path({
message: "Please enter file path",
initialValue: resolve("."),
}) as string;
p.log.info(filePath);
const filePathFile = await p.path({
message: "Please enter file path",
initialValue: resolve("."),
validate(val) {
if (!val || statSync(val).isDirectory()) {
return "Not a file";
}
}
}) as string;
p.log.info(filePathFile);
const filePathDict = await p.path({
message: "Please enter directory path",
initialValue: resolve("."),
directory: true,
}) as string;
p.log.info(filePathDict);
const filePathNotExists = await p.path({
message: "Please enter file path",
initialValue: resolve("."),
directory: false,
exists: false,
}) as string;
p.log.info(filePathNotExists);
}
main().catch(console.error);