@@ -9,68 +9,68 @@ import { snake4 } from "@snk/types/__fixtures__/snake";
99import { cellsToGrid } from "./cellsToGrid" ;
1010
1111export type Source =
12- | {
13- platform : "github" ;
14- username : string ;
15- githubToken : string ;
16- baseUrl ?: string ;
17- }
18- | { platform : "gitlab" ; username : string ; baseUrl ?: string }
19- | { platform : "forgejo" ; username : string ; baseUrl : string } ;
12+ | {
13+ platform : "github" ;
14+ username : string ;
15+ githubToken : string ;
16+ baseUrl ?: string ;
17+ }
18+ | { platform : "gitlab" ; username : string ; baseUrl ?: string }
19+ | { platform : "forgejo" ; username : string ; baseUrl : string } ;
2020
2121export type Output = {
22- format : "svg" | "gif" ;
23- drawOptions : DrawOptions ;
24- animationOptions : AnimationOptions ;
22+ format : "svg" | "gif" ;
23+ drawOptions : DrawOptions ;
24+ animationOptions : AnimationOptions ;
2525} ;
2626
2727export const getUserContribution = async ( source : Source ) => {
28- switch ( source . platform ) {
29- case "github" :
30- return getGithubUserContribution ( source . username , {
31- githubToken : source . githubToken ,
32- baseUrl : source . baseUrl ,
33- } ) ;
34- case "gitlab" :
35- return getGitlabUserContribution ( source . username , {
36- baseUrl : source . baseUrl ,
37- } ) ;
38- case "forgejo" :
39- return getForgejoUserContribution ( source . username , {
40- baseUrl : source . baseUrl ,
41- } ) ;
42- }
28+ switch ( source . platform ) {
29+ case "github" :
30+ return getGithubUserContribution ( source . username , {
31+ githubToken : source . githubToken ,
32+ baseUrl : source . baseUrl ,
33+ } ) ;
34+ case "gitlab" :
35+ return getGitlabUserContribution ( source . username , {
36+ baseUrl : source . baseUrl ,
37+ } ) ;
38+ case "forgejo" :
39+ return getForgejoUserContribution ( source . username , {
40+ baseUrl : source . baseUrl ,
41+ } ) ;
42+ }
4343} ;
4444
4545export const generateSnakeAnimation = async (
46- source : Source ,
47- outputs : ( Output | null ) [ ] ,
46+ source : Source ,
47+ outputs : ( Output | null ) [ ] ,
4848) => {
49- console . log ( `🎣 fetching user contribution from ${ source . platform } ` ) ;
50- const cells = await getUserContribution ( source ) ;
51- const grid = cellsToGrid ( cells ) ;
52- const snake = snake4 ;
49+ console . log ( `🎣 fetching user contribution from ${ source . platform } ` ) ;
50+ const cells = await getUserContribution ( source ) ;
51+ const grid = cellsToGrid ( cells ) ;
52+ const snake = snake4 ;
5353
54- console . log ( "📡 computing best route" ) ;
55- const chain = getBestRoute ( grid , snake ) ! ;
56- chain . push ( ...getPathToPose ( chain . slice ( - 1 ) [ 0 ] , snake ) ! ) ;
54+ console . log ( "📡 computing best route" ) ;
55+ const chain = getBestRoute ( grid , snake ) ! ;
56+ chain . push ( ...getPathToPose ( chain . slice ( - 1 ) [ 0 ] , snake ) ! ) ;
5757
58- return Promise . all (
59- outputs . map ( async ( out , i ) => {
60- if ( ! out ) return ;
61- const { format, drawOptions, animationOptions } = out ;
62- switch ( format ) {
63- case "svg" : {
64- console . log ( `🖌 creating svg (outputs[${ i } ])` ) ;
65- const { createSvg } = await import ( "@snk/svg-creator" ) ;
66- return createSvg ( grid , cells , chain , drawOptions , animationOptions ) ;
67- }
68- case "gif" : {
69- console . log ( `📹 creating gif (outputs[${ i } ])` ) ;
70- const { createGif } = await import ( "@snk/gif-creator" ) ;
71- return createGif ( grid , cells , chain , drawOptions , animationOptions ) ;
72- }
73- }
74- } ) ,
75- ) ;
58+ return Promise . all (
59+ outputs . map ( async ( out , i ) => {
60+ if ( ! out ) return ;
61+ const { format, drawOptions, animationOptions } = out ;
62+ switch ( format ) {
63+ case "svg" : {
64+ console . log ( `🖌 creating svg (outputs[${ i } ])` ) ;
65+ const { createSvg } = await import ( "@snk/svg-creator" ) ;
66+ return createSvg ( grid , cells , chain , drawOptions , animationOptions ) ;
67+ }
68+ case "gif" : {
69+ console . log ( `📹 creating gif (outputs[${ i } ])` ) ;
70+ const { createGif } = await import ( "@snk/gif-creator" ) ;
71+ return createGif ( grid , cells , chain , drawOptions , animationOptions ) ;
72+ }
73+ }
74+ } ) ,
75+ ) ;
7676} ;
0 commit comments