-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
41 lines (34 loc) · 1012 Bytes
/
main.js
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
const fs = require('fs')
const lex = require('./lexer')
/**
* @type { string }
*/
let file = ''
const version = 'v0.1.2-beta'
if (process.argv.length > 2) {
if (process.argv[2].startsWith('-')) {
let token = process.argv[2]
if (token[1] == 'v' || token.toLowerCase() == '--version') console.log(version)
if (token == '--node-version') console.log(process.version)
}
else file = process.argv[2]
} else {
file = 'main.wg'
}
const run = async () => {
let path = await new Promise((resolve) => {
fs.realpath(file, (error, path) => {
resolve(error ? undefined : path)
})
})
if (!path) {
console.log('File not found. Make sure the file exists')
} else {
if (fs.statSync(path).isDirectory()) {
path += '\\main.wg'
}
if (fs.existsSync(path)) await lex(fs.readFileSync(path, 'utf-8'), path)
else console.log('File not found. Make sure the file exists')
}
}
if (file) run()