2022-11-03 10:37:33 -05:00
|
|
|
import * as path from 'node:path'
|
|
|
|
import * as fs from 'node:fs'
|
|
|
|
import {exec} from 'node:child_process'
|
|
|
|
import yargs from 'yargs/yargs'
|
|
|
|
import {hideBin} from 'yargs/helpers'
|
2022-11-03 09:24:57 -05:00
|
|
|
|
2022-11-03 10:37:33 -05:00
|
|
|
const argv = yargs(hideBin(process.argv)).argv
|
2022-11-03 09:24:57 -05:00
|
|
|
|
2022-11-03 10:37:33 -05:00
|
|
|
const logPath = path.join(process.cwd(), 'logs')
|
|
|
|
const checkPath = process.cwd()
|
|
|
|
let command = './bin/lua-language-server-3.5.6-linux-x64/bin/lua-language-server'
|
|
|
|
|
|
|
|
if (argv.local) {
|
|
|
|
command = 'lua-language-server'
|
|
|
|
}
|
|
|
|
|
2022-11-03 12:06:43 -05:00
|
|
|
// Delete directory recursively
|
|
|
|
try {
|
|
|
|
fs.rmSync(logPath, { recursive: true, force: true })
|
|
|
|
console.log(`Removed folder: ${logPath}`)
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`Error while deleting ${logPath}.`)
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
|
2022-11-03 10:37:33 -05:00
|
|
|
exec(`${command} --logpath "${logPath}" --check "${checkPath}"`, (error, stdout, stderr) => {
|
|
|
|
if (error) {
|
|
|
|
console.log(`error: ${error.message}`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stderr) {
|
|
|
|
console.log(`stderr: ${stderr}`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-03 12:06:43 -05:00
|
|
|
console.log(`stdout: ${stdout}`)
|
|
|
|
|
|
|
|
if (fs.existsSync('./logs/check.json')) {
|
|
|
|
const rawdata = fs.readFileSync('./logs/check.json')
|
|
|
|
const diagnosticsJson = JSON.parse(rawdata)
|
2022-11-03 10:37:33 -05:00
|
|
|
|
2022-11-03 12:06:43 -05:00
|
|
|
Object.keys(diagnosticsJson).forEach((key) => {
|
|
|
|
console.log(key)
|
2022-11-03 10:37:33 -05:00
|
|
|
|
2022-11-03 12:06:43 -05:00
|
|
|
diagnosticsJson[key].forEach((errObj) => {
|
|
|
|
console.log(`line: ${errObj.range.start.line} - ${errObj.message}`)
|
|
|
|
})
|
2022-11-03 10:37:33 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
console.error('Fix the errors/warnings above.')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|