Skip to content

Commit

Permalink
Update all packages and project structure
Browse files Browse the repository at this point in the history
Switch to use `typings` over `tsd`
Restructure to separate app and tests
Add new module test
Update custom typings as a single ambient file with example
  • Loading branch information
Codesleuth committed Mar 25, 2016
1 parent 61d05ad commit fc814c5
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules/
/build/
/typings/
/src/typings/

npm-debug.log
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "build/app.js",
"program": "${workspaceRoot}/build/app.js",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
"cwd": "${workspaceRoot}",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
Expand All @@ -25,7 +25,7 @@
// Use JavaScript source maps (if they exist).
"sourceMaps": true,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": "build"
"outDir": "${workspaceRoot}/build"
},
{
"name": "Attach",
Expand Down
7 changes: 2 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"args": ["run"],

"tasks": [
{
"taskName": "build",
"args": ["run"],
"isBuildCommand": true,
"problemMatcher": {
"base": "$tsc",
"fileLocation": ["relative", "${workspaceRoot}/src"]
}
"problemMatcher": "$tsc"
},
{
"taskName": "test",
Expand Down
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ The project currently provides the following features:
.vscode/
launch.json # Defines launch tasks for debugging etc.
tasks.json # Defines tasks available e.g. build & test
custom_typings/ # Place your custom typings within this directory
tsd.d.ts # Custom typings should be added to this file, e.g.:
# /// <reference path="mymodule.d.ts" />
build/ # The output directory of JavaScript files
# when built from TypeScript
src/ # The root of all TypeScript source code
lib/
app/
app.ts # The main entry point for the project.
mymodule.ts # A sample module
test/
app.test.ts # A sample test
_ref.d.ts # The root type definition file.
# Reference this in all your TypeScript files.
app.test.ts # A sample module test with sinon spies
typings/ # Typings downloaded using the typings command
app.ts # The main entry point for the project.
custom.d.ts # An example of custom ambient typings
tsconfig.json # TypeScript compilation settings
typings.json # TypeScript package definition file for typings
package.json
README.md
tsd.json # TypeScript package definition file for tsd
```

## Getting Started
Expand All @@ -51,37 +52,41 @@ This repository is ready for you to clone and start building your code around it
$ npm install
```

4. You will need [`tsd`][tsd] to allow the TypeScript to compile without errors. It's recommended to install this globally:
4. You will need [`typings`][typings] to allow the TypeScript to compile without errors. It's recommended to install this globally:
```bash
$ npm install tsd -g
$ npm install typings -g
```
5. Run `tsd install` to fetch the required module type definitions defined in `tsd.json`:
5. Change to the `src` directory and run `typings install` to fetch the required module type definitions defined in `typings.json`:
```bash
$ cd src
# if installed globally (recommended)
$ tsd install
$ typings install
# otherwise
$ ./node_modules/.bin/tsd install
$ ../node_modules/.bin/typings install
```
### Building
1. Open VSCode and select the root of the repository as the project folder
1. Open VSCode, hit <kbd>CTRL</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>, type `open folder` and select the root of this repository
2. Build with one of the following shortcuts:
* Hitting <kbd>CTRL</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build, which is declared in the `.settings/tasks.json` file with the `isBuildCommand` marker
* Press <kbd>CTRL</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build, which is declared in the `.settings/tasks.json` file with the `isBuildCommand` marker
* Press <kbd>CTRL</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> and select the `Tasks: Run Build Task` option
* Press <kbd>CTRL</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>, delete the `>` and type `task build`
3. If there were no errors, you should see a new directory, `build`, in the root with the following content:
```
build/
lib/
mymodule.js
app/
app.js
app.js.map
mymodule.js
mymodule.js.map
test/
app.test.js
app.test.js.map
app.js
app.js.map
mymodule.test.js
mymodule.test.js.map
```
### Error Navigation
Expand All @@ -90,7 +95,7 @@ After building or testing, errors are captured (defined in the `.settings/tasks.
Your `.ts` files have been compiled to `.js` files within the `build` directory, and each should have a `.js.map` _sourcemap_ file alongside it to allow stack traces to correctly report the line in the original file. See [this StackOverflow article][sourcemapquestion] for an overview of what a sourcemap is.
### Testing
There's a sample test located in the `test` folder. You can run them by hitting <kbd>CTRL</kbd>/<kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>T</kbd> (or use the `Tasks` menu and run `Tasks: Run Test Task`)
There are sample tests located in the `test` folder. You can run them by hitting <kbd>CTRL</kbd>/<kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>T</kbd> (or use the `Tasks` menu and run `Tasks: Run Test Task`)
### Running and Debugging
To run the project in debug mode, simply hit <kbd>F5</kbd>! Place breakpoints in your TypeScript code and view them in the debugger (<kbd>CTRL</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> or <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd>).
Expand All @@ -104,4 +109,4 @@ MIT
[vscode]: https://code.visualstudio.com/
[nodejsdownload]: https://nodejs.org/download/
[sourcemapquestion]: http://stackoverflow.com/questions/21719562/javascript-map-files-javascript-source-maps
[tsd]: https://www.npmjs.com/package/tsd
[typings]: https://www.npmjs.com/package/typings
Empty file removed custom_typings/tsd.d.ts
Empty file.
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "vscode-typescript-example",
"name": "vscode-typescript-boilerplate",
"version": "0.1.0",
"description": "A project skeleton for TypeScript development in Visual Studio Code.",
"main": "build/app.js",
"main": "build/app/app.js",
"scripts": {
"build": "cd src && tsc",
"test": "mocha build/test --require source-map-support/register",
"build": "tsc -p src/ || true",
"test": "mocha build/test --require source-map-support/register || true",
"clean": "rimraf build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codesleuth/vscode-typescript-example.git"
"url": "git+https://github.com/codesleuth/vscode-typescript-boilerplate.git"
},
"keywords": [
"vscode",
"typescript",
"example",
"boilerplate",
"project",
"skeleton",
"debug",
Expand All @@ -26,17 +27,18 @@
"author": "David Wood <david.p.wood@gmail.com> (http://www.codesleuth.co.uk/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/codesleuth/vscode-typescript-example/issues"
"url": "https://github.com/codesleuth/vscode-typescript-boilerplate/issues"
},
"homepage": "https://github.com/codesleuth/vscode-typescript-example#readme",
"homepage": "https://github.com/codesleuth/vscode-typescript-boilerplate#readme",
"private": true,
"devDependencies": {
"mocha": "^2.2.5",
"rimraf": "^2.4.3",
"tsd": "^0.6.3",
"typescript": "^1.5.3"
"mocha": "^2.4.5",
"rimraf": "^2.5.2",
"sinon": "^1.17.3",
"typescript": "^1.8.9",
"typings": "^0.7.9"
},
"dependencies": {
"source-map-support": "^0.3.2"
"source-map-support": "^0.4.0"
}
}
2 changes: 0 additions & 2 deletions src/_ref.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app.ts → src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'source-map-support/register'
import mymodule = require('./lib/mymodule')
import {SayGoodbye} from './mymodule'

console.log('Hey there, VSCode user!')

mymodule.SayGoodbye();
SayGoodbye(console.log)
3 changes: 3 additions & 0 deletions src/app/mymodule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function SayGoodbye(log: (s: string) => void) {
log("Goodbye :(")
}
8 changes: 8 additions & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module "some_module" {
function some_module(string: any): void;

module some_module {
}

export = some_module;
}
5 changes: 0 additions & 5 deletions src/lib/mymodule.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/test/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// <reference path="../_ref.d.ts" />

import assert = require('assert')
import * as assert from 'assert'

describe('Some suite', () => {

Expand Down
17 changes: 17 additions & 0 deletions src/test/mymodule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as sinon from 'sinon'
import {SayGoodbye} from '../app/mymodule'

describe('My Module', () => {

describe('#SayGoodbye', () => {

it('should say goodbye', () => {
let logSpy = sinon.spy()
SayGoodbye(logSpy)

sinon.assert.calledWith(logSpy, 'Goodbye :(')
})

})

})
8 changes: 6 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"compilerOptions": {
"target": "ES5",
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"outDir": "../build/",
"removeComments": true
}
},
"exclude": [
"typings/browser.d.ts",
"typings/browser"
]
}
11 changes: 11 additions & 0 deletions src/typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "vscode-typescript-boilerplate",
"version": false,
"dependencies": {
"sinon": "registry:npm/sinon#1.16.0+20160309002336"
},
"ambientDependencies": {
"mocha": "registry:dt/mocha#2.2.5+20160317120654",
"node": "registry:dt/node#4.0.0+20160319033040"
}
}
15 changes: 0 additions & 15 deletions tsd.json

This file was deleted.

0 comments on commit fc814c5

Please sign in to comment.