Skip to content

Commit 8ee6fdf

Browse files
committed
fmt
1 parent dd64333 commit 8ee6fdf

File tree

3 files changed

+78
-56
lines changed

3 files changed

+78
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"start": "ts-node index.ts . --ignore",
88
"lint": "npx prettier . -w",
99
"build": "tsc index.ts --esModuleInterop true --allowJs true --outDir ./dist",
10-
"build-exe" : "pkg ./dist/index.js"
10+
"build-exe": "pkg ./dist/index.js"
1111
},
1212
"repository": {
1313
"type": "git",

src/gists/create.ts

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,79 @@
1-
import { Octokit } from '@octokit/core'
2-
import { greenBright, redBright, yellowBright } from 'chalk';
3-
import { readdirSync, readFileSync, statSync } from 'fs';
4-
import inquirer from 'inquirer';
5-
import { join } from 'path';
6-
import { cwd } from 'process';
7-
import { clearPreviousLine } from '../utils';
1+
import { Octokit } from "@octokit/core";
2+
import { greenBright, redBright, yellowBright } from "chalk";
3+
import { readdirSync, readFileSync, statSync } from "fs";
4+
import inquirer from "inquirer";
5+
import { join } from "path";
6+
import { cwd } from "process";
7+
import { clearPreviousLine } from "../utils";
88

99
export class CreateGist {
10-
private client:Octokit
10+
private client: Octokit;
1111

12-
/**
13-
* @constructor
14-
* @param {Octokit} client The client object
15-
*/
16-
constructor(client:Octokit) {
17-
this.client = client;
18-
this.collectFiles()
19-
}
12+
/**
13+
* @constructor
14+
* @param {Octokit} client The client object
15+
*/
16+
constructor(client: Octokit) {
17+
this.client = client;
18+
this.collectFiles();
19+
}
2020

21-
private collectFiles():void {
22-
const directoryContent:Array<string> = readdirSync(cwd()).filter((filename:string):boolean => {
23-
return statSync(join(cwd(), filename)).isFile()
24-
})
25-
for(let index=0; index<directoryContent.length; index++){
26-
const currentFilename:string = directoryContent[index]
27-
console.log(`${yellowBright((index + 1) + ":")} ${greenBright(currentFilename)}`)
28-
}
29-
inquirer.prompt({
30-
type: "input",
31-
message: "Enter the file indexes(seperated by comma)",
32-
name: "inputFiles"
33-
}).then((response:{inputFiles:any}):void => {
34-
const filenames:Array<string> = response.inputFiles.split(",").map((currentFile:string):string => {
35-
return currentFile.trim()
36-
})
37-
const selectedFiles:Array<string> = filenames.map((fileIndex:string):string | undefined => {
38-
const fileIndexNumber:number = parseInt(fileIndex)
39-
return directoryContent[fileIndexNumber-1]
40-
}).filter((value:string | undefined):boolean => {
41-
return value != undefined
42-
})
43-
let fileContent:any = {}
44-
for(let selectedFileIndex=0; selectedFileIndex<selectedFiles.length; selectedFileIndex++){
45-
const currentSelectedFile = join(cwd(), selectedFiles[selectedFileIndex])
46-
fileContent[selectedFiles[selectedFileIndex]] = {content:readFileSync(currentSelectedFile).toString()}
47-
}
48-
console.log(yellowBright("Publishing the gist..."))
49-
this.client.request("POST /gists", { files: fileContent }).then((response:any):void => {
50-
clearPreviousLine()
51-
console.log(greenBright("Published"))
52-
}).catch((error):void => {
53-
console.log(redBright(error))
54-
})
55-
})
21+
private collectFiles(): void {
22+
const directoryContent: Array<string> = readdirSync(cwd()).filter(
23+
(filename: string): boolean => {
24+
return statSync(join(cwd(), filename)).isFile();
25+
}
26+
);
27+
for (let index = 0; index < directoryContent.length; index++) {
28+
const currentFilename: string = directoryContent[index];
29+
console.log(
30+
`${yellowBright(index + 1 + ":")} ${greenBright(currentFilename)}`
31+
);
5632
}
57-
}
33+
inquirer
34+
.prompt({
35+
type: "input",
36+
message: "Enter the file indexes(seperated by comma)",
37+
name: "inputFiles",
38+
})
39+
.then((response: { inputFiles: any }): void => {
40+
const filenames: Array<string> = response.inputFiles
41+
.split(",")
42+
.map((currentFile: string): string => {
43+
return currentFile.trim();
44+
});
45+
const selectedFiles: Array<string> = filenames
46+
.map((fileIndex: string): string | undefined => {
47+
const fileIndexNumber: number = parseInt(fileIndex);
48+
return directoryContent[fileIndexNumber - 1];
49+
})
50+
.filter((value: string | undefined): boolean => {
51+
return value != undefined;
52+
});
53+
let fileContent: any = {};
54+
for (
55+
let selectedFileIndex = 0;
56+
selectedFileIndex < selectedFiles.length;
57+
selectedFileIndex++
58+
) {
59+
const currentSelectedFile = join(
60+
cwd(),
61+
selectedFiles[selectedFileIndex]
62+
);
63+
fileContent[selectedFiles[selectedFileIndex]] = {
64+
content: readFileSync(currentSelectedFile).toString(),
65+
};
66+
}
67+
console.log(yellowBright("Publishing the gist..."));
68+
this.client
69+
.request("POST /gists", { files: fileContent })
70+
.then((response: any): void => {
71+
clearPreviousLine();
72+
console.log(greenBright("Published"));
73+
})
74+
.catch((error): void => {
75+
console.log(redBright(error));
76+
});
77+
});
78+
}
79+
}

src/gists/gists.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class GithubGist {
2424
if (command == "reset") {
2525
this.github.reset();
2626
process.exit();
27-
} else if(command == "new"){
28-
new CreateGist(this.client)
29-
}else {
27+
} else if (command == "new") {
28+
new CreateGist(this.client);
29+
} else {
3030
this.github
3131
.authenticate(this.client)
3232
.then((value: any): void => {

0 commit comments

Comments
 (0)