Skip to content

Commit

Permalink
refactor: use native Deno.build.os (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard authored Jun 18, 2023
1 parent 3138f6b commit 87810fb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions githooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os from "https://deno.land/x/[email protected]/mod.ts";

export type Githooks = {
githooks: Record<string, string[]>;
};
Expand All @@ -12,9 +10,11 @@ export type GithooksOptions = {
export async function readJson(filePath: string): Promise<unknown> {
try {
const jsonString = await Deno.readTextFile(filePath);

return JSON.parse(jsonString);
} catch (err) {
err.message = `${filePath}: ${err.message}`;

throw err;
}
}
Expand All @@ -40,14 +40,15 @@ export async function setupGithooks(opts: GithooksOptions = defaultOptions) {
for (const hook of hooks) {
const task = config.githooks[hook];
const hookPath = `./.git/hooks/${hook}`;
const hookScript = `#!/bin/sh
exec deno task ${task}
`;
const hookScript = `#!/bin/sh\nexec deno task ${task}`;

await Deno.writeTextFile(hookPath, hookScript);
if (os.platform() !== "windows") {

if (Deno.build.os !== "windows") {
await Deno.chmod(hookPath, 0o755);
}
}

opts.verbose &&
console.log("Githooks setup successfully:", hooks.join(", "));
}
Expand Down

0 comments on commit 87810fb

Please sign in to comment.