-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathless-compiler-stdout.ts
49 lines (40 loc) · 1.3 KB
/
less-compiler-stdout.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
import { dirname } from "https://deno.land/[email protected]/path/mod.ts"
import less from "./less/less-node/index.js"
// --------------------------------------------------------------------------------
interface RenderError {
column: number
extract: string[]
filename: string
index: number
line: number
message: string
type: string
}
interface RenderOutput {
css: string
map: string
imports: string[]
}
(async () => {
let css: string
try {
css = await Deno.readTextFile(Deno.args[0])
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
await Deno.stdout.write(new TextEncoder().encode('Deno error: The file was not found'))
Deno.exit(1)
} else {
await Deno.stdout.write(new TextEncoder().encode('Deno error: ' + error))
Deno.exit(1)
}
}
const options = { paths: [dirname(Deno.args[0])] }
less.render(css, options, async (error: RenderError, output: RenderOutput | undefined) => {
if (error || !output) {
await Deno.stdout.write(new TextEncoder().encode((`${error.message} in ${error.filename} on line ${error.line}`)))
Deno.exit(1)
}
await Deno.stdout.write(new TextEncoder().encode(output.css))
Deno.exit()
})
})()