-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
119 lines (104 loc) · 3.9 KB
/
index.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {search} from '@inquirer/prompts'
import fs from "node:fs";
import * as process from "node:process";
import * as path from "node:path";
type Choice<Value> = {
value: Value;
name?: string;
description?: string;
short?: string;
disabled?: boolean | string;
};
async function main(day: string | undefined, part : string | undefined, input: string | undefined) {
if ((day ?? null) == null) {
day = await search({
message: "Select a day",
source: async (input) => {
if (!input) return fs.readdirSync("./", {withFileTypes: true})
.filter(value => value.isDirectory())
.filter(value => {
return !value.name.match("node_modules")
}).filter(value => {
return !value.name.startsWith(".")
}).map(value => value.name)
return fs.readdirSync("./", {withFileTypes: true})
.filter(value => {
return (path.join(value.parentPath, value.name)).match(input)
})
.filter(value => value.isDirectory())
.filter(value => {
return !value.name.match("node_modules")
}).filter(value => {
return !value.name.startsWith(".")
}).map(value => value.name)
}
})
}
if ((part ?? null) == null) {
part = await search({
message: "Select a Part",
source: async (input) => {
if (!input) return fs.readdirSync(`./${day}`, {withFileTypes: true})
.filter(value => value.isDirectory())
.filter(value => {
return !value.name.match("node_modules")
}).filter(value => {
return !value.name.startsWith(".")
}).map(value => value.name)
return fs.readdirSync("./", {withFileTypes: true})
.filter(value => {
return (path.join(value.parentPath, value.name)).match(input)
})
.filter(value => value.isDirectory())
.filter(value => {
return !value.name.startsWith(".")
}).map(value => value.name)
}
})
}
if ((input ?? null) == null) {
const inputs = fs.readdirSync(`./${day}`, {withFileTypes: true})
.filter(value => value.isFile())
.filter(value => value.isFile()).filter(value => {
return !value.parentPath.match("node_modules")
}).filter(value => {
return !value.parentPath.startsWith(".") || value.parentPath.startsWith("./")
}).filter(value => {
return !value.name.startsWith(".")
}).map<Choice<string>>(value => {
return {
name: value.name,
value: path.join(value.parentPath, value.name)
}
})
input = await search({
message: `Select file (Select within ./${day} or search within ./*))`,
source: async (input) => {
if (!input) return inputs;
return fs.readdirSync("./", {recursive: true, withFileTypes: true})
.filter(value => {
return (path.join(value.parentPath, value.name)).match(input)
}).filter(value => value.isFile())
.filter(value => value.isFile()).filter(value => {
return !value.parentPath.match("node_modules")
}).filter(value => {
return !value.parentPath.startsWith(".") || value.parentPath.startsWith("./")
}).filter(value => {
return !value.name.startsWith(".")
}).map<Choice<string>>(value => {
return {
name: path.join(value.parentPath, value.name),
value: path.join(value.parentPath, value.name)
}
})
}
})
}
console.log(input)
const {default: runner} = await import(`./${day}/${part}/index.js`)
runner(input)
}
const day = process.argv[2] === undefined ? process.argv[2] : 'Day ' + process.argv[2]
const part = process.argv[3] === undefined ? process.argv[3] : 'Part ' + process.argv[3]
const input = process.argv[4] === undefined ? process.argv[4] : `./${day}/` + process.argv[4]
main(day, part, input).then()