09. Lint and Build Setup
In this chapter, we will go over how to set up npm lint and build scripts to lint our code and output our build to files.
Linting
To ensure code quality, we can set up a lint script.
We already have ESLint and Prettier integrated into our project, so we can simply call ESLint CLI; for TypeScript project, we additionally call TypeScript compiler to type check.
Putting them together and add a lint
script to our package.json
:
{
"scripts": {
"lint": "tsc -p . --noEmit && eslint --ext .ts src/"
// ...
}
// ...
}
{
"scripts": {
"lint": "eslint --ext .mjs src/"
// ...
}
// ...
}
You can lint your project code by executing lint
script using terminal or IDE npm script integration:
npm run lint
Building
buildOutput
already contains built files as well as hash, all we need to do is to simply write them to disk so they can be served.
We create src/build.ts
which outputs the files:
import { writeFileSync } from 'fs'
import { buildOutput } from '.'
writeFileSync('EngineConfiguration', buildOutput.engine.configuration.buffer)
writeFileSync('EngineData', buildOutput.engine.data.buffer)
writeFileSync('LevelData', buildOutput.level.data.buffer)
import { writeFileSync } from 'fs'
import { buildOutput } from './index.mjs'
writeFileSync('EngineConfiguration', buildOutput.engine.configuration.buffer)
writeFileSync('EngineData', buildOutput.engine.data.buffer)
writeFileSync('LevelData', buildOutput.level.data.buffer)
Normally the level data is not needed as we are developing an engine, however in this guide we are going to output it so we can test it in a real production server as well.
Lastly, we add it as a build
script to our package.json
:
{
"scripts": {
"build": "ts-node ./src/build"
// ...
}
// ...
}
{
"scripts": {
"build": "node ./src/build.mjs"
// ...
}
// ...
}
You can build your project by executing build
script using terminal or IDE npm script integration:
npm run build