Skip to content

Commit a548d88

Browse files
author
Orta
authored
Merge branch 'master' into master
2 parents 3dbae08 + dfa9150 commit a548d88

File tree

17 files changed

+4731
-4680
lines changed

17 files changed

+4731
-4680
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ Thumbs.db
3737
# Ignore built ts files
3838
dist/**/*
3939

40+
# ignore yarn.lock
41+
yarn.lock

.travis.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
2-
{
3-
"language": "node_js",
4-
"node_js": "8",
5-
"services": [
6-
"mongodb"
7-
],
8-
"script": [
9-
"npm run build",
10-
"npm run test"
11-
]
12-
}
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 8
5+
- 9
6+
- 10
7+
services:
8+
- mongodb
9+
cache:
10+
directories:
11+
- node_modules
12+
script:
13+
- npm run build
14+
- npm run test

.vscode/extensions.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"recommendations": [
3-
"eg2.tslint",
3+
"ms-vscode.vscode-typescript-tslint-plugin",
44
"ms-azuretools.vscode-cosmosdb",
5-
"streetsidesoftware.code-spell-checker"
65
]
76
}

.vscode/settings.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"tslint.ignoreDefinitionFiles": false,
1111
"tslint.autoFixOnSave": true,
1212
"tslint.exclude": "**/node_modules/**/*",
13-
"cSpell.words": [
14-
"csrf",
15-
"definitelytyped",
16-
"promisified"
17-
]
13+
"appService.zipIgnorePattern": [
14+
".vscode{,/**}"
15+
],
16+
"appService.deploySubpath": ""
1817
}

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
![image](https://user-images.githubusercontent.com/820883/36764267-abbdb7f8-1be0-11e8-9678-2a9ea448d7f8.png)
88

99
The main purpose of this repository is to show a good end-to-end project setup and workflow for writing Node code in TypeScript.
10-
I will try to keep this as up-to-date as possible, but community contributions and recommendations for improvements are encouraged and will be most welcome.
10+
We will try to keep this as up-to-date as possible, but community contributions and recommendations for improvements are encouraged and will be most welcome.
1111

1212

1313
# Pre-reqs
@@ -45,15 +45,15 @@ npm start
4545
Or, if you're using VS Code, you can use `cmd + shift + b` to run the default build task (which is mapped to `npm run build`), and then you can use the command palette (`cmd + shift + p`) and select `Tasks: Run Task` > `npm: start` to run `npm start` for you.
4646

4747
> **Note on editors!** - TypeScript has great support in [every editor](http://www.typescriptlang.org/index.html#download-links), but this project has been pre-configured for use with [VS Code](https://code.visualstudio.com/).
48-
Throughout the README I'll try to call out specific places where VS Code really shines or where this project has been setup to take advantage of specific features.
48+
Throughout the README We will try to call out specific places where VS Code really shines or where this project has been setup to take advantage of specific features.
4949

5050
Finally, navigate to `http://localhost:3000` and you should see the template being served and rendered locally!
5151

5252
# Deploying the app
5353
There are many ways to deploy an Node app, and in general, nothing about the deployment process changes because you're using TypeScript.
5454
In this section, I'll walk you through how to deploy this app to Azure App Service using the extensions available in VS Code because I think it is the easiest and fastest way to get started, as well as the most friendly workflow from a developer's perspective.
5555

56-
## Pre-reqs
56+
## Prerequisites
5757
- [**Azure account**](https://azure.microsoft.com/en-us/free/) - If you don't have one, you can sign up for free.
5858
The Azure free tier gives you plenty of resources to play around with including up to 10 App Service instances, which is what we will be using.
5959
- [**VS Code**](https://code.visualstudio.com/) - We'll be using the interface provided by VS Code to quickly deploy our app.
@@ -64,7 +64,7 @@ The easiest way to achieve this is by using a managed cloud database.
6464
There are many different providers, but the easiest one to get started with is [MongoLab](#mlab).
6565

6666
### <a name="mlab"></a> Create a managed MongoDB with MongoLab
67-
1. Navigate to [MongoLab's Website](https://mlab.com/), sign up for a free account, and then log in.
67+
1. Navigate to [mLab's Website](https://mlab.com/), sign up for a free account, and then log in.
6868
2. In the **MongoDB Deployments** section, click the **Create New** button.
6969
3. Select any provider (I recommend **Microsoft Azure** as it provides an easier path to upgrading to globally distributed instances later).
7070
4. Select **Sandbox** to keep it free unless you know what you're doing, and hit **Continue**.
@@ -104,7 +104,7 @@ You can confirm that everything worked by seeing your Azure subscription listed
104104
Additionally you should see the email associated with your account listed in the status bar at the bottom of VS Code.
105105

106106
### Build the app
107-
Building the app locally is required for before a zip deploy because the App Service won't execute build tasks.
107+
Building the app locally is required before a zip deploy because the App Service won't execute build tasks.
108108
Build the app however you normally would:
109109
- `ctrl + shift + b` - kicks off default build in VS Code
110110
- execute `npm run build` from a terminal window
@@ -143,7 +143,7 @@ Deployment can fail for various reasons, if you get stuck with a page that says
143143

144144
# TypeScript + Node
145145
In the next few sections I will call out everything that changes when adding TypeScript to an Express project.
146-
Note that all of this has already been setup for this project, but feel free to use this as a reference for converting other Node.js project to TypeScript.
146+
Note that all of this has already been setup for this project, but feel free to use this as a reference for converting other Node.js projects to TypeScript.
147147

148148
## Getting TypeScript
149149
TypeScript itself is simple to add to any project with `npm`.
@@ -176,7 +176,7 @@ The full folder structure of this app is explained below:
176176
| **src/public** | Static assets that will be used client side |
177177
| **src/types** | Holds .d.ts files not found on DefinitelyTyped. Covered more in this [section](#type-definition-dts-files) |
178178
| **src**/server.ts | Entry point to your express app |
179-
| **test** | Contains your tests. Seperate from source because there is a different build process. |
179+
| **test** | Contains your tests. Separate from source because there is a different build process. |
180180
| **views** | Views define how your app renders on the client. In this case we're using pug |
181181
| .env.example | API keys, tokens, passwords, database URI. Clone this, but don't check it in to public repos. |
182182
| .travis.yml | Used to configure Travis CI build |
@@ -188,7 +188,7 @@ The full folder structure of this app is explained below:
188188
| tslint.json | Config settings for TSLint code style checking |
189189

190190
## Building the project
191-
It is rare for JavaScript projects not to have some kind of build pipeline these days, however Node projects typically have the least amount build configuration.
191+
It is rare for JavaScript projects not to have some kind of build pipeline these days. However, Node projects typically have the least amount of build configuration.
192192
Because of this I've tried to keep the build as simple as possible.
193193
If you're concerned about compile time, the main watch task takes ~2s to refresh.
194194

@@ -229,7 +229,7 @@ Let's dissect this project's `tsconfig.json`, starting with the `compilerOptions
229229

230230

231231

232-
The rest of the file define the TypeScript project context.
232+
The rest of the file defines the TypeScript project context.
233233
The project context is basically a set of options that determine which files are compiled when the compiler is invoked with a specific `tsconfig.json`.
234234
In this case, we use the following to define our project context:
235235
```json
@@ -363,7 +363,7 @@ Source maps allow you to drop break points in your TypeScript source code and ha
363363
> **Note!** - Source maps aren't specific to TypeScript.
364364
Anytime JavaScript is transformed (transpiled, compiled, optimized, minified, etc) you need source maps so that the code that is executed at runtime can be _mapped_ back to the source that generated it.
365365

366-
The best part of source maps is when configured correctly, you don't even know they exist! So let's take a look at how we do that in this project.
366+
The best part of source maps is, when configured correctly, you don't even know they exist! So let's take a look at how we do that in this project.
367367

368368
#### Configuring source maps
369369
First you need to make sure your `tsconfig.json` has source map generation enabled:
@@ -523,7 +523,7 @@ In that file you'll find two sections:
523523
| node-sass | Allows to compile .scss files to .css |
524524
| nodemon | Utility that automatically restarts node process when it crashes |
525525
| supertest | HTTP assertion library. |
526-
| ts-jest | A preprocessor with sourcemap support to help use TypeScript wit Jest.|
526+
| ts-jest | A preprocessor with sourcemap support to help use TypeScript with Jest.|
527527
| ts-node | Enables directly running TS files. Used to run `copy-static-assets.ts` |
528528
| tslint | Linter (similar to ESLint) for TypeScript files |
529529
| typescript | JavaScript compiler/type checker that boosts JavaScript productivity |
@@ -532,3 +532,7 @@ To install or update these dependencies you can use `npm install` or `npm update
532532

533533
# Hackathon Starter Project
534534
A majority of this quick start's content was inspired or adapted from Sahat's excellent [Hackathon Starter project](https://github.com/sahat/hackathon-starter).
535+
536+
## License
537+
Copyright (c) Microsoft Corporation. All rights reserved.
538+
Licensed under the [MIT](LICENSE.txt) License.

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module.exports = {
22
globals: {
33
'ts-jest': {
4-
tsConfigFile: 'tsconfig.json'
4+
tsConfig: 'tsconfig.json'
55
}
66
},
77
moduleFileExtensions: [
88
'ts',
99
'js'
1010
],
1111
transform: {
12-
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js'
12+
'^.+\\.(ts|tsx)$': 'ts-jest'
1313
},
1414
testMatch: [
1515
'**/test/**/*.test.(ts|js)'
1616
],
1717
testEnvironment: 'node'
18-
};
18+
};

0 commit comments

Comments
 (0)