Typescript will now be compiled without CLI
This commit is contained in:
@@ -1,15 +1,50 @@
|
|||||||
//PLEASE COMPILE USING "npm run build" BEFORE STARTING THE BOT!
|
//@ts-check
|
||||||
//OR USE "npm start" TO INSTANTLY COMPILE & START THE BOT!
|
|
||||||
|
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
if (process.argv.includes("-%-compile")){
|
const ts = require("typescript")
|
||||||
console.log("Removing prebuilds...")
|
const nodepath = require('path')
|
||||||
|
|
||||||
|
//REMOVE EXISTING BUILDS
|
||||||
|
console.log("OT: Removing Prebuilds...")
|
||||||
fs.rmSync("./dist",{recursive:true,force:true})
|
fs.rmSync("./dist",{recursive:true,force:true})
|
||||||
console.log("Compiling the bot...")
|
|
||||||
//exit on compilation
|
//COMPILE TYPESCRIPT
|
||||||
process.exit(0)
|
console.log("OT: Compiling Typescript...")
|
||||||
|
const configPath = nodepath.resolve('./tsconfig.json')
|
||||||
|
const configFile = ts.readConfigFile(configPath,ts.sys.readFile)
|
||||||
|
|
||||||
|
//check for tsconfig errors
|
||||||
|
if (configFile.error){
|
||||||
|
const message = ts.formatDiagnosticsWithColorAndContext([configFile.error],ts.createCompilerHost({}))
|
||||||
|
console.error(message)
|
||||||
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//start the bot
|
//parse tsconfig file
|
||||||
console.log("Finished compilation!")
|
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config,ts.sys,nodepath.dirname(configPath))
|
||||||
import("./dist/src/index.js")
|
|
||||||
|
//create program/compiler
|
||||||
|
const program = ts.createProgram({
|
||||||
|
rootNames:parsedConfig.fileNames,
|
||||||
|
options:parsedConfig.options
|
||||||
|
})
|
||||||
|
|
||||||
|
//emit all compiled files
|
||||||
|
const emitResult = program.emit()
|
||||||
|
|
||||||
|
//print emit errors/warnings (type errors)
|
||||||
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
||||||
|
const formattedDiagnostics = ts.formatDiagnosticsWithColorAndContext(allDiagnostics, ts.createCompilerHost(parsedConfig.options))
|
||||||
|
console.log(formattedDiagnostics)
|
||||||
|
|
||||||
|
//run with code
|
||||||
|
if (emitResult.emitSkipped){
|
||||||
|
console.log("OT: Compilation Failed!")
|
||||||
|
process.exit(1)
|
||||||
|
}else{
|
||||||
|
console.log("OT: Compilation Succeeded!")
|
||||||
|
if (process.argv.includes("-%-compile")) process.exit(0) //exit when only compile is required!
|
||||||
|
|
||||||
|
//START THE BOT
|
||||||
|
console.log("OT: Starting Bot!")
|
||||||
|
require("./dist/src/index.js")
|
||||||
|
}
|
||||||
+3
-2
@@ -12,8 +12,9 @@
|
|||||||
],
|
],
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js -%-compile && npx tsc -p ./tsconfig.json && node index.js",
|
"build": "node index.js -%-compile",
|
||||||
"test": "npm run start -- --dev-config --dev-database"
|
"start": "node index.js",
|
||||||
|
"test": "node index.js --dev-config --dev-database"
|
||||||
},
|
},
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
|
|||||||
Reference in New Issue
Block a user