Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagobustamante committed Jun 10, 2016
0 parents commit d4fd0c5
Show file tree
Hide file tree
Showing 40 changed files with 6,237 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.jshintrc
.sublime-project
.tern-project
/node_modules

12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
src
typings
gulpfile.js
tsconfig.json
typings.json
.DS_Store
.jshintrc
.sublime-project
.tern-project
release/spec
package.sublime-workspace

22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2016 Thiago da Rosa de Bustamante

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# REST Services for Typescript
This is a lightweight annotation-based expressjs extension for typescript.

It can be used to define your APIs using ES7 decorators.

**Table of Contents**

- [REST Services for Typescript](#)
- [Installation](#installation)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)

## Installation

This library only works with typescript. Ensure it is installed:

```bash
npm install typescript -g
```

To install typescript-rest:

```bash
npm install typescript-rest --save
```

## Configuration

Typescript-rest requires the following TypeScript compilation options in your tsconfig.json file:

```typescript
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```

## Basic Usage

```typescript
import * as express from "express";
import {Server, Path, GET, PathParam} from "../typescript-rest";

@Path("/hello")
class PersonService {
@Path(":name")
@GET
sayHello( @PathParam('name') name: string): string {
return "Hello " + name;
}
}

let app: express.Application = express();
Server.buildServices(app);

app.listen(3000, function() {
console.log('Rest Server listening on port 3000!');
});

```

That's it. You can just call now:

```
GET http://localhost:3000/hello/joe
```

113 changes: 113 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// require("harmonize")();

var gulp = require('gulp');
var ts = require('gulp-typescript');
var merge = require('merge2');
var sourcemaps = require('gulp-sourcemaps');
var runSequence = require('run-sequence');
var del = require('del');
var rename = require('gulp-rename');
var jasmineNode = require('gulp-jasmine-node');
var typedoc = require("gulp-typedoc");
var babel = require('gulp-babel');

var tsProject = ts.createProject('tsconfig.json', {
sortOutput: true,
declaration: true,
rootDir: "./src",
noExternalResolve: false
}, ts.reporter.fullReporter(true));

gulp.task('compile', function() {
var tsResult = tsProject.src()
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(ts(tsProject, {referencedFrom:['typescript-rest.ts']}));

return merge([
tsResult.dts.pipe(gulp.dest('release')),

tsResult.js
// .pipe(babel({
// optional: ["runtime"]
// }));
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-runtime']
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('release'))
]);
});

gulp.task('clean', function() {
return del(['release/**/*']);
});

gulp.task('docs-clean', function() {
return del(['doc/']);
});

gulp.task('test-compile', function(done) {
return tsResult = gulp.src('src/**/test-*.ts')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(ts(tsProject))
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-runtime']
}))
.pipe(rename({ extname: '.spec.js' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('release'));
});


gulp.task('test-run', function() {
return gulp.src('release/**/*.spec.js')
.pipe(jasmineNode({
timeout: 10000,
includeStackTrace: false,
color: true
}));
});

gulp.task('test', function(done) {
runSequence('test-compile', 'test-run', function() {
console.log('Release tested.');
done();
});
});

gulp.task("docs", ['docs-clean'], function() {
return gulp
.src(["./src/typescript-rest.ts"])
.pipe(typedoc({
module: "commonjs",
target: "es6",
out: "./doc/",
name: "Typescript-rest",
includeDeclarations: true,
experimentalDecorators: true,
emitDecoratorMetadata: true,
excludeExternals: true,

// TypeDoc options (see typedoc docs)
version: true,
verbose: false,
// json: "output/to/file.json"

// theme: "/path/to/my/theme",
ignoreCompilerErrors: true
}))
;
});

gulp.task('release', function(done) {
runSequence('clean', 'compile', 'test', 'docs', function() {
console.log('Release deployed.');
done();
});
});

gulp.task('watch', ['compile'], function() {
gulp.watch('src/**/*.ts', ['compile']);
});
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "typescript-rest",
"version": "0.0.1",
"description": "A Library to create RESTFul APIs with Typescript",
"author": "Thiago da Rosa de Bustamante <[email protected]>",
"dependencies": {
"body-parser": "^1.15.1",
"cookie-parser": "^1.4.3",
"express": "^4.13.4",
"reflect-metadata": "^0.1.3"
},
"devDependencies": {
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-runtime": "^6.9.2",
"del": "^2.2.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-jasmine-node": "^1.0.6",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-typedoc": "^2.0.0",
"gulp-typescript": "^2.13.0",
"merge2": "^1.0.2",
"phantomjs-prebuilt": "^2.1.7",
"request": "^2.72.0",
"run-sequence": "^1.1.5",
"typedoc": "^0.3.12",
"webpack-stream": "^3.2.0"
},
"keywords": [
"API",
"REST",
"RESTFul",
"service",
"microservice",
"typescript",
"node server"
],
"repository": {
"type": "git",
"url": "https://github.com/thiagobustamante/typescript-rest.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/thiagobustamante/typescript-rest/issues"
},
"directories": {
"lib": "release",
"doc": "doc"
},
"main": "release/typescript-rest.js",
"typings": "release/typescript-rest.d.ts"
}
Loading

0 comments on commit d4fd0c5

Please sign in to comment.