diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4fe241a..19eb9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/node_modules/ -/build/ -/src/typings/ - +/node_modules/ +/build/ +/src/typings/ + npm-debug.log \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2f65f55..b94c167 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,61 +1,61 @@ -{ - "version": "0.1.0", - "command": "npm", - "isShellCommand": true, - "showOutput": "silent", - "args": [ - "run" - ], - "tasks": [ - { - "taskName": "build", - "isBuildCommand": true, - "problemMatcher": "$tsc" - }, - { - "taskName": "test", - "isTestCommand": true, - "showOutput": "always", - "problemMatcher": { - "owner": "mocha", - "fileLocation": [ - "absolute" - ], - "pattern": [ - { - "regexp": "^\\s*\\d+\\)\\s+(.+):$", - "message": 1 - }, - { - "regexp": "^\\s+.*$" - }, - { - "regexp": "^\\s+.*$" - }, - { - "regexp": "^\\s+.*$" - }, - { - "regexp": "^\\s+.*$" - }, - { - "regexp": "^\\s+.*$" - }, - { - "regexp": "\\s+at\\s(.*)\\s\\((.*?:.*?):(\\d+):(\\d+)\\)", - "file": 2, - "line": 3, - "column": 4 - } - ] - } - }, - { - "taskName": "clean", - "args": [ - "run" - ], - "showOutput": "silent" - } - ] +{ + "version": "0.1.0", + "command": "npm", + "isShellCommand": true, + "showOutput": "silent", + "args": [ + "run" + ], + "tasks": [ + { + "taskName": "build", + "isBuildCommand": true, + "problemMatcher": "$tsc" + }, + { + "taskName": "test", + "isTestCommand": true, + "showOutput": "always", + "problemMatcher": { + "owner": "mocha", + "fileLocation": [ + "absolute" + ], + "pattern": [ + { + "regexp": "^\\s*\\d+\\)\\s+(.+):$", + "message": 1 + }, + { + "regexp": "^\\s+.*$" + }, + { + "regexp": "^\\s+.*$" + }, + { + "regexp": "^\\s+.*$" + }, + { + "regexp": "^\\s+.*$" + }, + { + "regexp": "^\\s+.*$" + }, + { + "regexp": "\\s+at\\s(.*)\\s\\((.*?:.*?):(\\d+):(\\d+)\\)", + "file": 2, + "line": 3, + "column": 4 + } + ] + } + }, + { + "taskName": "clean", + "args": [ + "run" + ], + "showOutput": "silent" + } + ] } \ No newline at end of file diff --git a/README.md b/README.md index 4f49353..ab82183 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,112 @@ -vscode-typescript-boilerplate -========================= - -This project provides a skeleton structure and IDE settings files to help with TypeScript development in [Visual Studio Code][vscode] (as of build 0.9.1). The project builds all TypeScript (`.ts`) files into a `build` directory in the root. - -## Project Structure -The project currently provides the following features: -* TypeScript compilation with Code's build command, or via `npm run build`, providing source maps -* Mocha test structure, which can be run with Code or `npm test`, also with source maps -* Error detection and navigation within Code for both build and test problems (see [Code Tasks](https://code.visualstudio.com/Docs/editor/tasks)) -* Debug settings (_currently a bug is preventing this from being reliable_) -* Type definitions provided by [`typings`][typings] -* Custom type definitions ready for your own declarations - -### Project Structure -``` -.vscode/ - launch.json # Defines launch tasks for debugging etc. - tasks.json # Defines tasks available e.g. build & test - -build/ # The output directory of JavaScript files - # when built from TypeScript - -src/ # The root of all TypeScript source code - app/ - app.ts # The main entry point for the project. - mymodule.ts # A sample module - - test/ - app.test.ts # A sample test - app.test.ts # A sample module test with sinon spies - - typings/ # Typings downloaded using the typings command - - 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 -``` - -## Getting Started -This repository is ready for you to clone and start building your code around it. Simply follow the guide below. - -### Prerequisites -1. Clone, fork, or [download](//github.com/Codesleuth/vscode-typescript-boilerplate/releases) the project. -2. You need Node.js. [Go install it][nodejsdownload] -3. Ensure the required dependencies have been installed: - ```bash - $ npm install - ``` - -4. You will need [`typings`][typings] to allow the TypeScript to compile without errors. It's recommended to install this globally: - ```bash - $ npm install typings -g - ``` - -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) - $ typings install - - # otherwise - $ ../node_modules/.bin/typings install - ``` - -### Building -1. Open VSCode, hit CTRL/Cmd+Shift+P, type `open folder` and select the root of this repository -2. Build with one of the following shortcuts: - * Press CTRL/Cmd+Shift+B to build, which is declared in the `.vscode/tasks.json` file with the `isBuildCommand` marker - * Press CTRL/Cmd+Shift+P and select the `Tasks: Run Build Task` option - * Press CTRL/Cmd+Shift+P, 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/ - app/ - app.js - app.js.map - mymodule.js - mymodule.js.map - test/ - app.test.js - app.test.js.map - mymodule.test.js - mymodule.test.js.map -``` - -### Error Navigation -After building or testing, errors are captured (defined in the `.vscode/tasks.json` file) and can be viewed with CTRL/Command+Shift+M. - -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 are sample tests located in the `test` folder. You can run them by hitting CTRL/Command+Shift+T (or use the `Tasks` menu and run `Tasks: Run Test Task`) - -### Running and Debugging -To run the project in debug mode, simply hit F5! Place breakpoints in your TypeScript code and view them in the debugger (CTRL+Shift+D or Cmd+Shift+D). - -## Contribute -Yes, that would be great! Open a pull request and we'll go from there! - -## License -MIT - -[vscode]: https://code.visualstudio.com/ -[nodejsdownload]: https://nodejs.org/download/ -[sourcemapquestion]: http://stackoverflow.com/questions/21719562/javascript-map-files-javascript-source-maps -[typings]: https://www.npmjs.com/package/typings +vscode-typescript-boilerplate +========================= + +This project provides a skeleton structure and IDE settings files to help with TypeScript development in [Visual Studio Code][vscode] (as of build 0.9.1). The project builds all TypeScript (`.ts`) files into a `build` directory in the root. + +## Project Structure +The project currently provides the following features: +* TypeScript compilation with Code's build command, or via `npm run build`, providing source maps +* Mocha test structure, which can be run with Code or `npm test`, also with source maps +* Error detection and navigation within Code for both build and test problems (see [Code Tasks](https://code.visualstudio.com/Docs/editor/tasks)) +* Debug settings (_currently a bug is preventing this from being reliable_) +* Type definitions provided by [`typings`][typings] +* Custom type definitions ready for your own declarations + +### Project Structure +``` +.vscode/ + launch.json # Defines launch tasks for debugging etc. + tasks.json # Defines tasks available e.g. build & test + +build/ # The output directory of JavaScript files + # when built from TypeScript + +src/ # The root of all TypeScript source code + app/ + app.ts # The main entry point for the project. + mymodule.ts # A sample module + + test/ + app.test.ts # A sample test + mymodule.test.ts # A sample module test with sinon spies + + typings/ # Typings downloaded using the typings command + + 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 +``` + +## Getting Started +This repository is ready for you to clone and start building your code around it. Simply follow the guide below. + +### Prerequisites +1. Clone, fork, or [download](//github.com/Codesleuth/vscode-typescript-boilerplate/releases) the project. +2. You need Node.js. [Go install it][nodejsdownload] +3. Ensure the required dependencies have been installed: + ```bash + $ npm install + ``` + +4. You will need [`typings`][typings] to allow the TypeScript to compile without errors. It's recommended to install this globally: + ```bash + $ npm install typings -g + ``` + +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) + $ typings install + + # otherwise + $ ../node_modules/.bin/typings install + ``` + +### Building +1. Open VSCode, hit CTRL/Cmd+Shift+P, type `open folder` and select the root of this repository +2. Build with one of the following shortcuts: + * Press CTRL/Cmd+Shift+B to build, which is declared in the `.vscode/tasks.json` file with the `isBuildCommand` marker + * Press CTRL/Cmd+Shift+P and select the `Tasks: Run Build Task` option + * Press CTRL/Cmd+Shift+P, 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/ + app/ + app.js + app.js.map + mymodule.js + mymodule.js.map + test/ + app.test.js + app.test.js.map + mymodule.test.js + mymodule.test.js.map +``` + +### Error Navigation +After building or testing, errors are captured (defined in the `.vscode/tasks.json` file) and can be viewed with CTRL/Command+Shift+M. + +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 are sample tests located in the `test` folder. You can run them by hitting CTRL/Command+Shift+T (or use the `Tasks` menu and run `Tasks: Run Test Task`) + +### Running and Debugging +To run the project in debug mode, simply hit F5! Place breakpoints in your TypeScript code and view them in the debugger (CTRL+Shift+D or Cmd+Shift+D). + +## Contribute +Yes, that would be great! Open a pull request and we'll go from there! + +## License +MIT + +[vscode]: https://code.visualstudio.com/ +[nodejsdownload]: https://nodejs.org/download/ +[sourcemapquestion]: http://stackoverflow.com/questions/21719562/javascript-map-files-javascript-source-maps +[typings]: https://www.npmjs.com/package/typings diff --git a/package.json b/package.json index 75f2a8c..bfb4818 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vscode-typescript-boilerplate", - "version": "1.2.0", + "version": "1.2.1", "description": "A project skeleton for TypeScript development in Visual Studio Code.", "main": "build/app/app.js", "scripts": { diff --git a/src/app/app.ts b/src/app/app.ts index 3e6a804..6566254 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,6 +1,6 @@ -import 'source-map-support/register' -import {SayGoodbye} from './mymodule' - -console.log('Hey there, VSCode user!') - +import 'source-map-support/register' +import {SayGoodbye} from './mymodule' + +console.log('Hey there, VSCode user!') + SayGoodbye(console.log) \ No newline at end of file diff --git a/src/app/mymodule.ts b/src/app/mymodule.ts index 340b083..e94cf65 100644 --- a/src/app/mymodule.ts +++ b/src/app/mymodule.ts @@ -1,3 +1,3 @@ -export function SayGoodbye(log: (s: string) => void) { - log("Goodbye :(") +export function SayGoodbye(log: (s: string) => void) { + log("Goodbye :(") } \ No newline at end of file diff --git a/src/custom.d.ts b/src/custom.d.ts index e916740..14fb58f 100644 --- a/src/custom.d.ts +++ b/src/custom.d.ts @@ -1,8 +1,8 @@ -declare module "some_module" { - function some_module(string: any): void; - - module some_module { - } - - export = some_module; +declare module "some_module" { + function some_module(string: any): void; + + module some_module { + } + + export = some_module; } \ No newline at end of file diff --git a/src/test/app.test.ts b/src/test/app.test.ts index 72e1f6d..3a9a923 100644 --- a/src/test/app.test.ts +++ b/src/test/app.test.ts @@ -1,17 +1,17 @@ -import * as assert from 'assert' - -describe('Some suite', () => { - - describe('Some functionality', () => { - - it('should really just pass', () => { - assert.ok(true) - }) - - it('should really just fail', () => { - assert.ok(false, 'Check file and line number - source map support!') - }) - - }) - +import * as assert from 'assert' + +describe('Some suite', () => { + + describe('Some functionality', () => { + + it('should really just pass', () => { + assert.ok(true) + }) + + it('should really just fail', () => { + assert.ok(false, 'Check file and line number - source map support!') + }) + + }) + }) \ No newline at end of file diff --git a/src/test/mymodule.test.ts b/src/test/mymodule.test.ts index 3dbdd10..d0663bd 100644 --- a/src/test/mymodule.test.ts +++ b/src/test/mymodule.test.ts @@ -1,17 +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 :(') - }) - - }) - +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 :(') + }) + + }) + }) \ No newline at end of file diff --git a/src/tsconfig.json b/src/tsconfig.json index f66f233..93e5baf 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,13 +1,13 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "sourceMap": true, - "outDir": "../build/", - "removeComments": true - }, - "exclude": [ - "typings/browser.d.ts", - "typings/browser" - ] +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "outDir": "../build/", + "removeComments": true + }, + "exclude": [ + "typings/browser.d.ts", + "typings/browser" + ] } \ No newline at end of file