Skip to content

Commit

Permalink
fix(init): call unzip command directly
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Dec 21, 2024
1 parent acbfab1 commit 56ba413
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
5 changes: 5 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export {
SpinnerTypes,
TerminalSpinner,
} from "https://cdn.jsdelivr.net/gh/will-weiss/spinners@master/mod.ts";
export { decompress } from "https://cdn.jsdelivr.net/gh/bootoffav/deno-zip@main/mod.ts";
import dir from "https://deno.land/x/dir@1.5.2/mod.ts";
export { dir };
import Logger from "https://deno.land/x/logger@v1.1.3/logger.ts";
Expand Down
43 changes: 22 additions & 21 deletions src/cmd/init.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
brightGreen,
cyan,
pkgx,
generateName,
green,
magenta,
brightGreen,
TerminalSpinner,
pkgx,
SpinnerTypes,
green,
decompress,
generateName,
TerminalSpinner,
} from "../../deps.ts";
import { POCKETENV_CACHE_DIR } from "../consts.ts";
import { existsSync } from "node:fs";
Expand All @@ -16,7 +15,7 @@ import { getDefaultGithubBranch } from "../lib.ts";

async function init(
{ template, standalone }: { template?: string; standalone?: boolean },
name?: string
name?: string,
) {
if (!name) {
console.log(`${cyan("?")} Workspace name: `);
Expand All @@ -32,7 +31,7 @@ async function init(
console.log(`${cyan("?")} Choose a template: `);
template = await pkgx.run(
`gum choose pkgx nix devbox homebrew devenv flox`,
"piped"
"piped",
);
await Deno.stdout.write(new TextEncoder().encode(magenta(template)));
template = template.trim();
Expand All @@ -58,8 +57,9 @@ async function downloadFromGithub(template: string, standalone?: boolean) {
if (existsSync(".pocketenv")) {
console.log(
`🚨 ${brightGreen(
".pocketenv"
)} directory already exists. Please remove it and try again.`
".pocketenv",
)
} directory already exists. Please remove it and try again.`,
);
Deno.exit(1);
}
Expand All @@ -74,17 +74,17 @@ async function downloadFromGithub(template: string, standalone?: boolean) {

const filePath = `${POCKETENV_CACHE_DIR}/${template.replaceAll(
"/",
"-"
)}.zip`;
"-",
)
}.zip`;

const branch = await getDefaultGithubBranch(
template.split("/").length === 2 ? template : `pocketenv-io/${template}`
template.split("/").length === 2 ? template : `pocketenv-io/${template}`,
);

const url =
template.split("/").length === 2
? `https://codeload.github.com/${template}/zip/refs/heads/${branch}`
: `https://codeload.github.com/pocketenv-io/${template}/zip/refs/heads/${branch}`;
const url = template.split("/").length === 2
? `https://codeload.github.com/${template}/zip/refs/heads/${branch}`
: `https://codeload.github.com/pocketenv-io/${template}/zip/refs/heads/${branch}`;

if (!existsSync(filePath)) {
const response = await fetch(url);
Expand All @@ -100,21 +100,22 @@ async function downloadFromGithub(template: string, standalone?: boolean) {

if (!existsSync(`${cacheDir}/${template.split("/").pop()}-${branch}`)) {
await pkgx.installPackage("unzip");
await decompress(filePath, cacheDir);
await pkgx.run(`unzip ${filePath} -d ${cacheDir}`, "inherit");
await pkgx.run(
`terraform init`,
"inherit",
`${cacheDir}/${template.split("/").pop()}-${branch}`
`${cacheDir}/${template.split("/").pop()}-${branch}`,
);
} else {
console.log(
`💾 Using cached template: ${brightGreen(template)} ${brightGreen("...")}`
`💾 Using cached template: ${brightGreen(template)} ${brightGreen("...")
}`,
);
}

await copyDir(
`${cacheDir}/${template.split("/").pop()}-${branch}`,
standalone ? "." : ".pocketenv"
standalone ? "." : ".pocketenv",
);
}

Expand Down

0 comments on commit 56ba413

Please sign in to comment.