-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use native
Deno.build.os
(#5)
- Loading branch information
1 parent
3138f6b
commit 87810fb
Showing
1 changed file
with
7 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]>; | ||
}; | ||
|
@@ -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; | ||
} | ||
} | ||
|
@@ -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(", ")); | ||
} | ||
|