11import {
2- decompress ,
3- prompt ,
4- Input ,
2+ _ ,
53 brightGreen ,
64 Confirm ,
7- TerminalSpinner ,
8- SpinnerTypes ,
5+ decompress ,
96 green ,
10- _ ,
7+ Input ,
8+ prompt ,
9+ SpinnerTypes ,
10+ TerminalSpinner ,
1111 toml ,
1212} from "../../deps.ts" ;
1313import { directoryExists } from "../utils.ts" ;
@@ -30,7 +30,7 @@ async function init(
3030 standalone,
3131 wasm,
3232 } : { template ?: string ; standalone ?: boolean ; wasm ?: boolean } = { } ,
33- name ?: string
33+ name ?: string ,
3434) {
3535 const infos = await promptPackageDetails ( standalone , name ) ;
3636 let version = extractVersion ( template || "base_pipeline" ) ;
@@ -40,8 +40,9 @@ async function init(
4040 const data = await result . json ( ) ;
4141
4242 if ( data . version ) {
43- version =
44- version === "latest" ? data . version || data . default_branch : version ;
43+ version = version === "latest"
44+ ? data . version || data . default_branch
45+ : version ;
4546 if (
4647 await downloadTemplateFromRegistry ( template , version , standalone , wasm )
4748 ) {
@@ -57,8 +58,9 @@ async function init(
5758 }
5859
5960 if ( data . github_url ) {
60- version =
61- version === "latest" ? data . version || data . default_branch : version ;
61+ version = version === "latest"
62+ ? data . version || data . default_branch
63+ : version ;
6264 await downloadTemplateFromGithub ( data , template , version , standalone , wasm ) ;
6365 await overrideFluentciToml ( infos , standalone ? "." : ".fluentci" ) ;
6466 if ( wasm ) {
@@ -71,9 +73,11 @@ async function init(
7173 }
7274
7375 console . log (
74- `Pipeline template ${ green ( '"' ) } ${ green ( template ) } ${ green (
75- '"'
76- ) } not found in Fluent CI registry`
76+ `Pipeline template ${ green ( '"' ) } ${ green ( template ) } ${
77+ green (
78+ '"' ,
79+ )
80+ } not found in Fluent CI registry`,
7781 ) ;
7882 Deno . exit ( 1 ) ;
7983}
@@ -119,9 +123,9 @@ async function download(url: string, template: string) {
119123
120124 terminalSpinner . succeed ( "Downloaded template" ) ;
121125
122- Deno . writeFile ( tempFilePath , new Uint8Array ( value ) ) ;
126+ await Deno . writeFile ( tempFilePath , new Uint8Array ( value ) ) ;
123127
124- await decompress ( tempFilePath , "." ) ;
128+ const io = await decompress ( tempFilePath , "." , { overwrite : true } ) ;
125129
126130 // Cleanup the temp file
127131 await Deno . remove ( tempFilePath ) ;
@@ -158,18 +162,21 @@ async function downloadTemplateFromGithub(
158162 template : string ,
159163 version : string ,
160164 standalone ?: boolean ,
161- wasm ?: boolean
165+ wasm ?: boolean ,
162166) {
163- const archiveUrl =
164- data . version && data . version . startsWith ( "v" )
165- ? `${ data . github_url . replace (
166- "https://github.com" ,
167- "https://codeload.github.com"
168- ) } /zip/refs/tags/${ version } `
169- : `${ data . github_url . replace (
170- "https://github.com" ,
171- "https://api.github.com/repos"
172- ) } /zipball/${ version } `;
167+ const archiveUrl = data . version && data . version . startsWith ( "v" )
168+ ? `${
169+ data . github_url . replace (
170+ "https://github.com" ,
171+ "https://codeload.github.com" ,
172+ )
173+ } /zip/refs/tags/${ version } `
174+ : `${
175+ data . github_url . replace (
176+ "https://github.com" ,
177+ "https://api.github.com/repos" ,
178+ )
179+ } /zipball/${ version } `;
173180
174181 await download ( archiveUrl , template ) ;
175182
@@ -209,10 +216,10 @@ async function downloadTemplateFromRegistry(
209216 template : string ,
210217 version : string ,
211218 standalone ?: boolean ,
212- wasm ?: boolean
219+ wasm ?: boolean ,
213220) {
214221 const status = await fetch (
215- `https://pkg.fluentci.io/${ template } @${ version } `
222+ `https://pkg.fluentci.io/${ template } @${ version } ` ,
216223 ) . then ( ( res ) => res . status ) ;
217224 if ( status === 200 ) {
218225 await download ( `https://pkg.fluentci.io/${ template } @${ version } ` , template ) ;
@@ -257,14 +264,18 @@ async function promptPackageDetails(standalone?: boolean, name?: string) {
257264 console . log ( `👋 Welcome to ${ brightGreen ( "Fluent CI" ) } !\n` ) ;
258265 console . log ( `This utility will walk you through creating a new pipeline.` ) ;
259266 console . log (
260- `It only covers the most common items, and tries to guess sensible defaults.\n`
267+ `It only covers the most common items, and tries to guess sensible defaults.\n` ,
261268 ) ;
262269 console . log (
263- `Use ${ brightGreen (
264- "`fluentci run <pkg>`"
265- ) } to run a published pipeline, or ${ brightGreen (
266- "`fluentci publish`"
267- ) } to publish one.\n`
270+ `Use ${
271+ brightGreen (
272+ "`fluentci run <pkg>`" ,
273+ )
274+ } to run a published pipeline, or ${
275+ brightGreen (
276+ "`fluentci publish`" ,
277+ )
278+ } to publish one.\n`,
268279 ) ;
269280 console . log ( `See ${ brightGreen ( "`fluentci help`" ) } for more information.\n` ) ;
270281 console . log ( `Press ${ brightGreen ( "CTRL+C" ) } at any time to quit.\n` ) ;
@@ -305,9 +316,9 @@ async function promptPackageDetails(standalone?: boolean, name?: string) {
305316 ] ) ;
306317
307318 console . log (
308- `\n✨ About to create a new${
309- standalone ? " reusable " : " "
310- } pipeline in ${ brightGreen ( Deno . cwd ( ) ) } \n`
319+ `\n✨ About to create a new${ standalone ? " reusable " : " " } pipeline in ${
320+ brightGreen ( Deno . cwd ( ) )
321+ } \n`,
311322 ) ;
312323
313324 console . log ( "📦 Package details:\n" ) ;
@@ -341,14 +352,14 @@ async function overrideDaggerJson(infos: Record<string, unknown>, path = ".") {
341352 const dagger = await Deno . readFile ( `${ path } /dagger.json` ) ;
342353 // deno-lint-ignore no-explicit-any
343354 const daggerJson : Record < string , any > = JSON . parse (
344- new TextDecoder ( ) . decode ( dagger )
355+ new TextDecoder ( ) . decode ( dagger ) ,
345356 ) ;
346357 for ( const key of Object . keys ( infos ) ) {
347358 daggerJson [ key ] = _ . get ( infos , key ) ;
348359 }
349360 await Deno . writeFile (
350361 `${ path } /dagger.json` ,
351- new TextEncoder ( ) . encode ( JSON . stringify ( daggerJson , null , 2 ) )
362+ new TextEncoder ( ) . encode ( JSON . stringify ( daggerJson , null , 2 ) ) ,
352363 ) ;
353364
354365 if ( _ . isEqual ( path , ".fluentci" ) ) {
@@ -372,13 +383,13 @@ async function overrideCargoToml(infos: Record<string, unknown>, path = ".") {
372383
373384 await Deno . writeFile (
374385 `${ path } /Cargo.toml` ,
375- new TextEncoder ( ) . encode ( toml . stringify ( config ) )
386+ new TextEncoder ( ) . encode ( toml . stringify ( config ) ) ,
376387 ) ;
377388}
378389
379390async function overrideFluentciToml (
380391 infos : Record < string , unknown > ,
381- path = "."
392+ path = "." ,
382393) {
383394 let config = { } ;
384395 try {
@@ -399,7 +410,7 @@ async function overrideFluentciToml(
399410
400411 await Deno . writeFile (
401412 `${ path } /fluentci.toml` ,
402- new TextEncoder ( ) . encode ( toml . stringify ( config ) )
413+ new TextEncoder ( ) . encode ( toml . stringify ( config ) ) ,
403414 ) ;
404415}
405416
0 commit comments