UNPKG

4.46 kBMarkdownView Raw
1# typescript-node-scripts
2[![Build Status](https://travis-ci.com/liangchunn/typescript-node-scripts.svg?branch=master)](https://travis-ci.com/liangchunn/typescript-node-scripts) [![npm](https://img.shields.io/npm/v/typescript-node-scripts.svg)](https://www.npmjs.com/package/typescript-node-scripts) [![npm](https://img.shields.io/npm/dt/typescript-node-scripts.svg)](https://www.npmjs.com/package/typescript-node-scripts) [![install size](https://packagephobia.now.sh/badge?p=typescript-node-scripts)](https://packagephobia.now.sh/result?p=typescript-node-scripts) [![Greenkeeper badge](https://badges.greenkeeper.io/liangchunn/typescript-node-scripts.svg)](https://greenkeeper.io/)
3
4Create Node.js applications based on TypeScript with zero-configuration.
5<p align="center">
6 <img
7 width="600" src="https://cdn.rawgit.com/liangchunn/typescript-node-scripts/12e1600/.resources/term.svg"/>
8</p>
9
10Inspired by `create-react-app` and Dan Abramov's [The Melting Pot of JavaScript](https://increment.com/development/the-melting-pot-of-javascript/).
11- Supports testing, building, and development in watch mode
12- Supports custom TypeScript path mappings, aka `compilerOptions.path`
13
14## Quick Start Guide
15```sh
16npx typescript-node-scripts create <appName>
17cd <appName>
18yarn start
19```
20
21## Requirements
22
23- node `>=6.0.0`
24- `process.platform !== 'win32'`
25
26
27## Commands
28
29### `yarn start` or `npm run start`
30
31Starts the development server with watch mode and incremental builds. This command generates a bundle which is located at `build/bundle.js`.
32
33#### Options
34
35| Argument | Description |
36| ----------------- | -------------------------------------------------------------------------------------------------- |
37| `--no-collapse` | Expands all the collapsed errors |
38| `--no-auto-start` | Disables auto starting and stopping of the application. By default, it executes `build/bundle.js`. |
39
40### `yarn build` or `npm run build`
41
42Builds a production ready bundle. This minifies all sources into one simple, distributable `dist/bundle.prod.js` alongside `dist/bundle.prod.js.map` which is ideal for Docker builds.
43
44This command does not bundle any dependencies which is `require`-d or `import`-ed from `node_modules`!
45
46#### Options
47
48| Argument | Description |
49| ---------------------- | ------------------------------------------- |
50| `--no-collapse` | Expands all the collapsed errors |
51| `--bypass-ci-warnings` | Bypass CI warnings being treated as errors. |
52
53### `yarn test` or `npm run test`
54
55Runs the Jest test runners in watch mode by default. You can add in Jest options as usual.
56
57#### Example commands
58
59```sh
60yarn test --coverage
61
62yarn test --watchAll
63```
64
65## Tests
66Jest is the main test runner that this package supports.
67
68### Test files
69Everything that matches the globs below will be passed to Jest as a test file:
70- `src/**/__tests__/**/*.(j|t)s?(x)`
71- `src/**/?(*.)(spec|test|t).(j|t)s?(x)`
72
73### Setting up the test framework
74You can use `setupTests.ts` in your project root to set up the testing framework before each test.
75
76### Overriding Jest configuration
77You can override the Jest configuration in your `package.json` with the key `jest`.
78
79The following options can be overriden:
80- `collectCoverageFrom`
81- `coverageReporters`
82- `coverageThreshold`
83
84## Custom Module Paths
85TNS supports custom module path mappings. A default custom path mapping is provided in `tsconfig.json`
86
87```json
88{
89 "paths": {
90 "~/*": ["src/*"]
91 }
92}
93```
94
95This configuration allows you to import any module which resolves absolutely to `src`.
96
97```ts
98// src/lib/a/b/Module.ts
99
100// instead of
101import Module from '../../../Module'
102
103// you can do
104import Module from '~/Module'
105```
106
107## Source Maps
108Source maps are enabled by default and postfixed with `.map` in the `build` and `dist` folders. These files provide accurate source mappings which are helpful when debugging errors and looking at stack traces during runtime.
109
110In order to tell Node to use these source maps, you would need to install `source-map-support`.
111
112```sh
113# if you're using yarn
114yarn add source-map-support
115
116# if you're using npm
117npm i -S source-map-support
118```
119
120Then, in `src/index.ts`, add:
121```ts
122import 'source-map-support/register'
123```
124
125## TODO
126
127- [ ] e2e tests