This is a project template with various adjusted configurations. You can start scripting Node on the base with confidence. It targets to the last NodeJS version still under maintenance, meaning v12 and ES2019.
You can download the project without git index content:
curl -L https://github.com/towertop/ts-node-ready/tarball/master | tar xf -
After install dependencies, it is ready to open editor and start programing from src/main.ts
.
If you're going to commit or publish the project, you need to modify package.json
fields like name
, version
, author
and etc.
You can use the simple workflow with:
npm run <command>
Commands include:
start | run production version, depends on build |
build | build production version, output to dist/ |
clean | remove dist/ |
dev | run developement version main.ts directly |
watch | automatically restart main.ts |
lint | check all source code for bad practices |
lintFix | manage to correct the bad practices |
checkTyping | use tsc check the typing of scripts |
test | execute test cases |
testWatch | automatically re-execute test cases |
release | release current version as a git tag |
buildDocker | deliver the app as a docker image |
After all, this is a template, you can modify anything on demand.
- Make your editor support TS type check and code lint.
- Use new ES2019 syntax as more as you can.
- Update
@types/node
if targeting to a fresher NodeJS than v12.
- Defines a consistent indent style in
.editorconfig
. - Declares target node version range by
engines
field inpackage.json
. - Uses officially recommended TSConfig base from tsconfig/bases project, which specified type check for ES2019.
- Installs @types/node@12 to specify type check for Node API of that version.
- Tunes TSConfig to transpile ESModules to CommonJS for Node. Current Node has't been ready for native ESModules without flag and
.mjs
file extension. - Includes TSLint and its autofix function. In
tslint.json
turn on thetslint:recommended
presets and additional rules from tslint-eslint-rules. I added some personal adjustments after a blank line at therules
section in that file. - Adds basic Unit Test methods with Mocha and Chai. I prefer BDD style interfaces and assertions with
expect()
function. - Has double TS configuration
tsconfig.app.json
andtsconfig.spec.json
like Angular projects. The TS lang server reference all@types/*
module's declarations when you coding in supporting editors. But the compiler need to select some of them for strict type checking. - Has a simple development workflow by
scripts
section inpackage.json
. Use nodemon to have a live restart or retest when you coding. - Utilizes husky and lint-staged to enforce code style before every commits.
- Has a simple relase method within the workflow based on npm-version command. It would lint and test source code, build production version, and release them as a git tag. I feel it is handy for private projects within a team internally. What you should do before use
release
command is to bump the version inpackage.json
, else would get stuck by tag name collision. - Use rollup.js to bundle and emit
main.js
while keeping readable javascript code and sourcemap for debugging. - Use Dockerfile to build and deliver the app as an image.
- Collect common Node program patterns as references.
- Utilize code generators like Yeoman, Schematics and etc.
- Introduce zeit/pkg.
- Introduce node-config.
- Replace tslint with typescript-eslint.
- Upgrade all deps with builtin compatibility checks
- Introduce schematic-release?
- Bring in npm-check-updates tool to confidentially bump dependencies.