-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Drakefile.ts
executable file
·80 lines (66 loc) · 1.98 KB
/
Drakefile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/env -S deno run --allow-all --unstable
import * as path from 'https://deno.land/std@0.75.0/path/mod.ts'
import { desc, task, sh, run, readFile, glob } from 'https://deno.land/x/drake@v1.4.4/mod.ts'
const {
UPDATE = 'false',
SHELL,
} = Deno.env.toObject()
const deno = Deno.execPath()
const __filename = path.fromFileUrl(import.meta.url)
const __dirname = path.dirname(__filename)
const shouldUpdate = UPDATE.toLowerCase() === 'true'
if (!SHELL || path.basename(SHELL) !== 'zsh') {
throw `Invalid $SHELL. Expecting zsh, received ${SHELL}.`
}
const compareFile = (a: string, b: string): boolean =>
Deno.statSync(a).size === Deno.statSync(b).size &&
readFile(a) === readFile(b)
desc('Sync markdown files')
task('markdown', [], async () => {
let outdated: string[] = []
type UpdateFunc = (name: string, src: string, dst: string) => void
const update: UpdateFunc = shouldUpdate
? (name, src, dst) => {
console.log(`File ${name} is out-of-date. Syncing.`)
Deno.copyFileSync(src, dst)
}
: name => outdated.push(name)
for (const name of glob('*.md')) {
const src = path.join(__dirname, name)
const dst = path.join(__dirname, 'lib', name)
if (compareFile(src, dst)) {
console.log(`File ${name} is up-to-date. Skipping.`)
} else {
update(name, src, dst)
}
}
if (outdated.length) {
for (const name of outdated) {
console.error(`File ${name} is outdated`)
}
throw 'Some files are not up-to-date'
}
})
desc('Fetch and compile dependencies')
task('cache', [], async () => {
await sh(`${deno} cache **/*.ts --unstable`)
})
desc('Run tests')
task('test', ['cache'], async () => {
const permissions = [
'--allow-read',
]
await sh(`${deno} test --unstable ${permissions.join(' ')} test/**/*.test.ts`)
})
desc('Run sane-fmt')
task('fmt', [], async () => {
await sh(shouldUpdate ? 'sane-fmt --write' : 'sane-fmt')
})
desc('Run all tasks')
task('all', [
'markdown',
'cache',
'test',
'fmt',
])
run()