minetest_x_bows/scripts/lls-check.js

94 lines
2.6 KiB
JavaScript
Raw Normal View History

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 12:36:07 -05:00
import jaguar from 'jaguar'
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 12:36:07 -05:00
const cwd = process.cwd()
const logPath = path.join(cwd, 'logs')
2022-11-03 09:24:57 -05:00
2022-11-03 12:36:07 -05:00
// Extract lua language server
const from = path.join(cwd, 'bin/lua-language-server-3.5.6-linux-x64.tar.gz');
const to = path.join(cwd, 'bin', 'lua-language-server-3.5.6-linux-x64');
const extract = jaguar.extract(from, to)
2022-11-03 12:48:19 -05:00
// extract.on('file', (name) => {
// console.log(name)
// })
2022-11-03 12:36:07 -05:00
2022-11-03 12:48:19 -05:00
extract.on('start', () => {
console.log('Extracting...')
2022-11-03 12:36:07 -05:00
})
2022-11-03 12:48:19 -05:00
// extract.on('progress', (percent) => {
// console.log(percent + '%')
// })
2022-11-03 12:36:07 -05:00
extract.on('error', (error) => {
console.error(error)
process.exit(1)
})
extract.on('end', () => {
2022-11-03 12:48:19 -05:00
console.log('Extracting: Done')
2022-11-03 12:36:07 -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
}
2022-11-03 12:36:07 -05:00
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 10:37:33 -05:00
}
2022-11-03 12:36:07 -05:00
exec(`${command} --logpath "${logPath}" --check "${cwd}"`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`)
2022-11-03 12:48:19 -05:00
process.exit(1)
2022-11-03 12:36:07 -05:00
}
if (stderr) {
console.log(`stderr: ${stderr}`)
2022-11-03 12:48:19 -05:00
process.exit(1)
2022-11-03 12:36:07 -05:00
}
2022-11-03 12:06:43 -05:00
2022-11-03 12:48:19 -05:00
console.log(`\n${stdout}`)
2022-11-03 10:37:33 -05:00
2022-11-03 12:36:07 -05:00
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:36:07 -05:00
Object.keys(diagnosticsJson).forEach((key) => {
console.log(key)
diagnosticsJson[key].forEach((errObj) => {
console.log(`line: ${errObj.range.start.line} - ${errObj.message}`)
})
2022-11-03 12:06:43 -05:00
})
2022-11-03 10:37:33 -05:00
2022-11-03 12:36:07 -05:00
console.error('Fix the errors/warnings above.')
process.exit(1)
}
// Delete directory recursively
const llsFolder = path.join(cwd, 'bin', 'lua-language-server-3.5.6-linux-x64')
2022-11-03 12:48:19 -05:00
2022-11-03 12:36:07 -05:00
try {
fs.rmSync(llsFolder, { recursive: true, force: true })
console.log(`Removed folder: ${llsFolder}`)
} catch (err) {
console.error(`Error while deleting ${llsFolder}.`)
console.error(err)
process.exit(1)
}
})
2022-11-03 10:37:33 -05:00
})