-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
854 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.unstable": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno", | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const Tsv = "tsv"; | ||
export const Csv = "csv"; | ||
export const Table = "table"; | ||
export const MarkdownFile = "markdown"; | ||
export type FileFormat = typeof Tsv | typeof Csv | ||
export type Format = FileFormat | typeof Table | typeof MarkdownFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Repository } from "./domains/repository.ts"; | ||
import { FileFormat, Tsv, Csv } from "./domains/Format.ts"; | ||
|
||
export class SeparatedFileCreator { | ||
private format: FileFormat; | ||
private separator: string; | ||
private outputFilePath: string; | ||
|
||
constructor(format: FileFormat, outputFilePath: string) { | ||
this.format = format; | ||
this.outputFilePath = outputFilePath === "" | ||
? `./examples/ranking_result.${format}` | ||
: outputFilePath; | ||
switch (format) { | ||
case Tsv: | ||
this.separator = '"\t"'; | ||
break; | ||
case Csv: | ||
this.separator = ', '; | ||
break; | ||
default: | ||
throw Error(`Cannot use the format, ${format}`); | ||
} | ||
} | ||
|
||
generateFile = async (result: Repository[]) => { | ||
const encoder = new TextEncoder(); | ||
const escapeQuote = (s: string) => s.replaceAll('"', '""'); | ||
const doubleQuote = (s: string) => `"${escapeQuote(s)}"`; | ||
const data = result.map((r) => | ||
[ | ||
r.name, | ||
r.full_name, | ||
r.html_url, | ||
r.stargazers_count, | ||
r.forks, | ||
r.watchers, | ||
r.subscribers_count, | ||
r.archived, | ||
r.description ?? "", | ||
] | ||
.map((s) => doubleQuote(s.toString())) | ||
.join(this.separator) | ||
).join("\n"); | ||
await Deno.writeFile(this.outputFilePath, encoder.encode(data)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
args, | ||
EarlyExitFlag, | ||
Option, | ||
Choice, | ||
PartialOption, | ||
} from "../../deps.ts"; | ||
import { Text } from "../../deps.ts"; | ||
import { Format, Tsv, Table, MarkdownFile, Csv } from "../domains/Format.ts"; | ||
|
||
export const parseArgs = () => { | ||
const parser = args | ||
.describe("Add or subtract two numbers") | ||
.with( | ||
EarlyExitFlag("help", { | ||
describe: "Show help", | ||
alias: ["h"], | ||
exit() { | ||
console.log(parser.help()); | ||
return Deno.exit(); | ||
}, | ||
}), | ||
) | ||
.with( | ||
Option("username", { | ||
type: Text, | ||
describe: "Github account username without '@'. required token", | ||
alias: ["u"], | ||
}), | ||
) | ||
.with( | ||
Option("token", { | ||
type: Text, | ||
describe: "Github account token. required username", | ||
alias: ["t"], | ||
}), | ||
) | ||
.with( | ||
Option("format", { | ||
type: Choice<Format>( | ||
{ | ||
value: Tsv, | ||
describe: "Output tsv file", | ||
}, | ||
{ | ||
value: Csv, | ||
describe: "Output csv file", | ||
}, | ||
{ | ||
value: Table, | ||
describe: "Output console table", | ||
}, | ||
{ | ||
value: MarkdownFile, | ||
describe: "Output markdown file", | ||
}, | ||
), | ||
alias: ["f"], | ||
describe: "Choice output format", | ||
}), | ||
).with( | ||
PartialOption("outputFile", { | ||
type: Text, | ||
describe: | ||
"Output file path. Only file like tsv and csv.", | ||
alias: ["o"], | ||
default: "", | ||
}), | ||
).with( | ||
PartialOption("sampling", { | ||
type: Text, | ||
describe: | ||
"For testing, fetch a little sample from API. --sampling true", | ||
default: "false", | ||
}), | ||
); | ||
return parser; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.