Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer: Print name of installed file #492

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions installer/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ export async function install(
const installerDir = getInstallerDir();
createDirIfNotExists(installerDir);

const FILE_PATH = path.join(installerDir, moduleName);
const filePath = path.join(installerDir, moduleName);

let fileInfo;
try {
fileInfo = await stat(FILE_PATH);
fileInfo = await stat(filePath);
} catch (e) {
// pass
}
Expand Down Expand Up @@ -209,17 +209,19 @@ export async function install(

// TODO: add windows Version
const template = `#/bin/sh\n${commands.join(" ")}`;
await writeFile(FILE_PATH, encoder.encode(template));
await writeFile(filePath, encoder.encode(template));

const makeExecutable = run({ args: ["chmod", "+x", FILE_PATH] });
const makeExecutable = run({ args: ["chmod", "+x", filePath] });
const { code } = await makeExecutable.status();
makeExecutable.close();

if (code !== 0) {
throw new Error("Failed to make file executable");
}

console.log(`✅ Successfully installed ${moduleName}.`);
console.log(`✅ Successfully installed ${moduleName}`);
console.log(filePath);

// TODO: add Windows version
if (!checkIfExistsInPath(installerDir)) {
console.log("\nℹ️ Add ~/.deno/bin to PATH");
Expand All @@ -231,17 +233,17 @@ export async function install(

export async function uninstall(moduleName: string): Promise<void> {
const installerDir = getInstallerDir();
const FILE_PATH = path.join(installerDir, moduleName);
const filePath = path.join(installerDir, moduleName);

try {
await stat(FILE_PATH);
await stat(filePath);
} catch (e) {
if (e instanceof Deno.DenoError && e.kind === Deno.ErrorKind.NotFound) {
throw new Error(`ℹ️ ${moduleName} not found`);
}
}

await remove(FILE_PATH);
await remove(filePath);
console.log(`ℹ️ Uninstalled ${moduleName}`);
}

Expand Down