2023-01-09 20:30:13 +01:00
|
|
|
import ScriptUtils from "./ScriptUtils"
|
|
|
|
|
|
|
|
export default abstract class Script {
|
|
|
|
private readonly _docs: string
|
|
|
|
|
|
|
|
constructor(docs: string) {
|
|
|
|
this._docs = docs
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract main(args: string[]): Promise<void>
|
|
|
|
|
|
|
|
public run(): void {
|
|
|
|
ScriptUtils.fixUtils()
|
|
|
|
const args = [...process.argv]
|
|
|
|
args.splice(0, 2)
|
2024-01-23 22:03:22 +01:00
|
|
|
const start = new Date()
|
2023-10-11 04:16:52 +02:00
|
|
|
this.main(args)
|
2024-04-13 02:40:21 +02:00
|
|
|
.then((_) => {
|
2024-01-23 22:03:22 +01:00
|
|
|
const end = new Date()
|
|
|
|
const millisNeeded = end.getTime() - start.getTime()
|
|
|
|
|
|
|
|
const green = (s) => "\x1b[92m" + s + "\x1b[0m"
|
|
|
|
console.log(green("All done! (" + millisNeeded + " ms)"))
|
|
|
|
})
|
2024-08-08 22:40:43 +02:00
|
|
|
.catch((e) => {
|
|
|
|
console.log(`ERROR in script ${process.argv[1]}:`, e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2023-01-09 20:30:13 +01:00
|
|
|
}
|
2023-06-11 19:04:40 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
public printHelp() {
|
2023-06-11 19:04:40 +02:00
|
|
|
console.log(this._docs)
|
|
|
|
}
|
2023-01-09 20:30:13 +01:00
|
|
|
}
|