forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-file.ts
44 lines (35 loc) · 948 Bytes
/
validate-file.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
import * as readline from 'readline'
import * as fs from 'fs'
export type SassVariable = {
readonly fileName: string
readonly lineNumber: number
readonly text: string
}
export function listUnencodedSassVariables(
path: string
): Promise<ReadonlyArray<SassVariable>> {
return new Promise<ReadonlyArray<SassVariable>>((resolve, reject) => {
const unencodedVariables = new Array<SassVariable>()
const lineReader = readline.createInterface({
input: fs.createReadStream(path),
})
let lineNumber = 0
lineReader.on('line', (line: string) => {
lineNumber++
const index = line.indexOf('$', 0)
if (index > -1) {
unencodedVariables.push({
fileName: path,
lineNumber,
text: line,
})
}
})
lineReader.on('close', () => {
resolve(unencodedVariables)
})
lineReader.on('error', (err: Error) => {
reject(err)
})
})
}