11import {
2+ brightGreen ,
23 cyan ,
3- pkgx ,
4+ generateName ,
5+ green ,
46 magenta ,
5- brightGreen ,
6- TerminalSpinner ,
7+ pkgx ,
78 SpinnerTypes ,
8- green ,
9- decompress ,
10- generateName ,
9+ TerminalSpinner ,
1110} from "../../deps.ts" ;
1211import { POCKETENV_CACHE_DIR } from "../consts.ts" ;
1312import { existsSync } from "node:fs" ;
@@ -16,7 +15,7 @@ import { getDefaultGithubBranch } from "../lib.ts";
1615
1716async function init (
1817 { template, standalone } : { template ?: string ; standalone ?: boolean } ,
19- name ?: string
18+ name ?: string ,
2019) {
2120 if ( ! name ) {
2221 console . log ( `${ cyan ( "?" ) } Workspace name: ` ) ;
@@ -32,7 +31,7 @@ async function init(
3231 console . log ( `${ cyan ( "?" ) } Choose a template: ` ) ;
3332 template = await pkgx . run (
3433 `gum choose pkgx nix devbox homebrew devenv flox` ,
35- "piped"
34+ "piped" ,
3635 ) ;
3736 await Deno . stdout . write ( new TextEncoder ( ) . encode ( magenta ( template ) ) ) ;
3837 template = template . trim ( ) ;
@@ -58,8 +57,9 @@ async function downloadFromGithub(template: string, standalone?: boolean) {
5857 if ( existsSync ( ".pocketenv" ) ) {
5958 console . log (
6059 `🚨 ${ brightGreen (
61- ".pocketenv"
62- ) } directory already exists. Please remove it and try again.`
60+ ".pocketenv" ,
61+ )
62+ } directory already exists. Please remove it and try again.`,
6363 ) ;
6464 Deno . exit ( 1 ) ;
6565 }
@@ -74,17 +74,17 @@ async function downloadFromGithub(template: string, standalone?: boolean) {
7474
7575 const filePath = `${ POCKETENV_CACHE_DIR } /${ template . replaceAll (
7676 "/" ,
77- "-"
78- ) } .zip`;
77+ "-" ,
78+ )
79+ } .zip`;
7980
8081 const branch = await getDefaultGithubBranch (
81- template . split ( "/" ) . length === 2 ? template : `pocketenv-io/${ template } `
82+ template . split ( "/" ) . length === 2 ? template : `pocketenv-io/${ template } ` ,
8283 ) ;
8384
84- const url =
85- template . split ( "/" ) . length === 2
86- ? `https://codeload.github.com/${ template } /zip/refs/heads/${ branch } `
87- : `https://codeload.github.com/pocketenv-io/${ template } /zip/refs/heads/${ branch } ` ;
85+ const url = template . split ( "/" ) . length === 2
86+ ? `https://codeload.github.com/${ template } /zip/refs/heads/${ branch } `
87+ : `https://codeload.github.com/pocketenv-io/${ template } /zip/refs/heads/${ branch } ` ;
8888
8989 if ( ! existsSync ( filePath ) ) {
9090 const response = await fetch ( url ) ;
@@ -100,21 +100,22 @@ async function downloadFromGithub(template: string, standalone?: boolean) {
100100
101101 if ( ! existsSync ( `${ cacheDir } /${ template . split ( "/" ) . pop ( ) } -${ branch } ` ) ) {
102102 await pkgx . installPackage ( "unzip" ) ;
103- await decompress ( filePath , cacheDir ) ;
103+ await pkgx . run ( `unzip ${ filePath } -d ${ cacheDir } ` , "inherit" ) ;
104104 await pkgx . run (
105105 `terraform init` ,
106106 "inherit" ,
107- `${ cacheDir } /${ template . split ( "/" ) . pop ( ) } -${ branch } `
107+ `${ cacheDir } /${ template . split ( "/" ) . pop ( ) } -${ branch } ` ,
108108 ) ;
109109 } else {
110110 console . log (
111- `💾 Using cached template: ${ brightGreen ( template ) } ${ brightGreen ( "..." ) } `
111+ `💾 Using cached template: ${ brightGreen ( template ) } ${ brightGreen ( "..." )
112+ } `,
112113 ) ;
113114 }
114115
115116 await copyDir (
116117 `${ cacheDir } /${ template . split ( "/" ) . pop ( ) } -${ branch } ` ,
117- standalone ? "." : ".pocketenv"
118+ standalone ? "." : ".pocketenv" ,
118119 ) ;
119120}
120121
0 commit comments