Skip to content

Commit 9a28a9c

Browse files
author
Exponential-Workload
committed
feat: initial template commit
0 parents  commit 9a28a9c

8 files changed

+431
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "ytdl",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "rollup -c --bundleConfigAsCjs",
8+
"dev": "echo $ build && rollup -c --bundleConfigAsCjs && echo $ start && node .",
9+
"start": "node ."
10+
},
11+
"keywords": [],
12+
"author": "Exponential-Workload",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"@rollup/plugin-typescript": "^11.0.0",
16+
"@types/node": "^18.11.18",
17+
"@types/prompts": "^2.4.2",
18+
"rollup": "^3.13.0",
19+
"tslib": "^2.5.0",
20+
"typescript": "^4.9.5"
21+
},
22+
"dependencies": {
23+
"chalk": "^4.1.2",
24+
"get-cursor-position": "^2.0.0",
25+
"prompts": "^2.4.2"
26+
}
27+
}

pnpm-lock.yaml

+223
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
3+
export default {
4+
input: 'src/index.ts',
5+
output: {
6+
dir: 'dist',
7+
format: 'cjs'
8+
},
9+
plugins: [typescript({
10+
allowSyntheticDefaultImports: true
11+
})]
12+
};

src/Logger/gcp.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'get-cursor-position' {
2+
export const sync: ()=>{
3+
row:number,
4+
col:number,
5+
}
6+
export const async: (...param: Parameters<typeof sync>)=>Promise<ReturnType<typeof sync>>
7+
}

src/Logger/index.ts

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import chalk from 'chalk'
2+
import { sync as getCursorPos } from 'get-cursor-position'
3+
type RGB = {
4+
r: number,
5+
g: number,
6+
b: number,
7+
}
8+
const pendingOperationSymbols = [
9+
// '●',
10+
// '◕',
11+
// '◑',
12+
// '◔',
13+
// '○',
14+
// '◒'
15+
'◜',
16+
'◟',
17+
'◡',
18+
'◞',
19+
'◝',
20+
'◠'
21+
]
22+
23+
export default class Logger {
24+
static format(status: string, colour: RGB, loggerName: string | undefined, prestatus: string | undefined, post: boolean, bold: boolean = true) {
25+
return (loggerName?(chalk.grey(`${loggerName} › `)):'') + (bold?chalk.bold:chalk).rgb(colour.r,colour.g,colour.b)(status) + (prestatus ? (chalk.bold(' ' + prestatus) + ((this.postGuillemet && post) ? chalk.grey(' ›') : '')) : '')
26+
}
27+
loggerName: string | undefined;
28+
static postGuillemet = false;
29+
success(msg: string, postmsg?:string) {
30+
console.log(Logger.format('✔', {
31+
r: 122,
32+
g: 255,
33+
b: 122,
34+
},this.loggerName,msg, !!postmsg,false),postmsg??'');
35+
}
36+
question(msg: string,postmsg?:string) {
37+
console.log(Logger.format('?', {
38+
r: 122,
39+
g: 122,
40+
b: 255,
41+
},this.loggerName,msg, !!postmsg),postmsg??'');
42+
}
43+
info(msg: string,postmsg?:string) {
44+
console.log(Logger.format('i', {
45+
r: 122,
46+
g: 122,
47+
b: 255,
48+
},this.loggerName,msg, !!postmsg),postmsg??'');
49+
}
50+
warn(msg: string,postmsg?:string) {
51+
console.log(Logger.format('⚠', {
52+
r: 255,
53+
g: 255,
54+
b: 122,
55+
},this.loggerName,msg, !!postmsg),postmsg??'');
56+
}
57+
error(msg: string,postmsg?:string) {
58+
console.log(Logger.format('✖', {
59+
r: 255,
60+
g: 122,
61+
b: 122,
62+
},this.loggerName,msg, !!postmsg),postmsg??'');
63+
}
64+
log(msg: string,postmsg?:string) {
65+
console.log(Logger.format('🗎', {
66+
r: 180,
67+
g: 180,
68+
b: 180,
69+
},this.loggerName,msg, !!postmsg),postmsg??'');
70+
}
71+
status(msg: string, postmsg?: string) {
72+
const cursorPos = getCursorPos()
73+
let i=0;
74+
let char:string;
75+
let rgb: RGB = {
76+
r: 122,
77+
g: 122,
78+
b: 255,
79+
}
80+
const writeMessage = ()=>console.log(Logger.format(char ?? pendingOperationSymbols[i], rgb,this.loggerName,msg, !!postmsg),postmsg??'');
81+
writeMessage()
82+
const rerenderMessage = ()=>{
83+
i=i+1;
84+
if (i >= pendingOperationSymbols.length) i=0
85+
process.stdout.cursorTo(cursorPos.col-1,cursorPos.row-2)
86+
process.stdout.clearLine(1)
87+
writeMessage()
88+
}
89+
rerenderMessage()
90+
setInterval(rerenderMessage,50).unref()
91+
const updateStatus = (newMsg?:string, newPostMsg?:string)=>{
92+
msg=newMsg ?? msg;
93+
postmsg=postmsg??newPostMsg
94+
rerenderMessage();
95+
}
96+
return {
97+
updateStatus,
98+
done: (success: boolean = true, newMsg?:string, newPostMsg?:string)=>{
99+
rgb = {
100+
r: success ? 122 : 255,
101+
g: success ? 255 : 122,
102+
b: 122
103+
}
104+
char=success?'✔':'✖'
105+
updateStatus(newMsg,newPostMsg)
106+
}
107+
}
108+
}
109+
constructor(name?: string | undefined) {
110+
this.loggerName=name
111+
}
112+
}

0 commit comments

Comments
 (0)