├── .gitignore ├── LICENCE ├── README.md ├── bs-config.json ├── gulpfile.ts ├── package.json ├── src ├── app │ ├── about │ │ └── components │ │ │ ├── about.component.ts │ │ │ └── about.html │ ├── app.component.ts │ ├── app.html │ ├── app.module.ts │ ├── app.routing.ts │ ├── main.ts │ └── todo │ │ ├── components │ │ ├── task-list.component.ts │ │ ├── task-list.css │ │ ├── task-list.html │ │ ├── task.component.ts │ │ └── task.html │ │ ├── models │ │ └── task.ts │ │ └── services │ │ └── task-service.ts ├── index.html └── systemjs.config.js ├── tsconfig.json ├── tslint.json └── typings.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | build 3 | node_modules 4 | typings -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Rafal Borowiec 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Angular2 with TypeScript and Gulp 2 | ================================= 3 | 4 | A basic Angular2 application with Gulp as build system. 5 | 6 | #### 1. Prerequisites 7 | 8 | *nodejs* must be installed on your system and the below global node packages must be installed: 9 | 10 | - gulp 11 | 12 | > npm i -g gulp 13 | 14 | - gulp-cli 15 | 16 | > npm i -g gulp-cli 17 | 18 | - typings 19 | 20 | > npm i -g typings@1.3.3 21 | 22 | - typescript 23 | 24 | > npm i -g typescript@2.0.2 25 | 26 | - ts-node 27 | 28 | > npm i -g ts-node@1.3.0 29 | 30 | #### 2. Cloning the repository 31 | 32 | Clone the repository: 33 | 34 | > git clone https://github.com/kolorobot/angular2-typescript-gulp.git 35 | 36 | Navigate to `angular2-typescript-gulp` directory: 37 | 38 | > cd angular2-typescript-gulp 39 | 40 | #### 3. Installing dependencies 41 | 42 | Install dependencies by running the following command: 43 | 44 | > npm install 45 | 46 | `node_modules` and `typings` directories will be created during the install. 47 | 48 | #### 4. Building the project 49 | 50 | Build the project by running the following command: 51 | 52 | > npm run clean & npm run build 53 | 54 | `build` directory will be created during the build 55 | 56 | #### 5. Starting the application 57 | 58 | Start the application by running the following command: 59 | 60 | > npm start 61 | 62 | The application will be displayed in the browser. 63 | 64 | Resources 65 | --------- 66 | 67 | - [A step-by-step tutorial](http://blog.codeleak.pl/2016/03/quickstart-angular2-with-typescript-and.html) 68 | -------------------------------------------------------------------------------- /bs-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": 8000, 3 | "files": [ 4 | "build/**/*.{html,htm,css,js}" 5 | ], 6 | "server": { 7 | "baseDir": "build" 8 | } 9 | } -------------------------------------------------------------------------------- /gulpfile.ts: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const gulp = require("gulp"); 4 | const del = require("del"); 5 | const tsc = require("gulp-typescript"); 6 | const sourcemaps = require('gulp-sourcemaps'); 7 | const tsProject = tsc.createProject("tsconfig.json"); 8 | const tslint = require('gulp-tslint'); 9 | 10 | /** 11 | * Remove build directory. 12 | */ 13 | gulp.task('clean', (cb) => { 14 | return del(["build"], cb); 15 | }); 16 | 17 | /** 18 | * Lint all custom TypeScript files. 19 | */ 20 | gulp.task('tslint', () => { 21 | return gulp.src("src/**/*.ts") 22 | .pipe(tslint({ 23 | formatter: 'prose' 24 | })) 25 | .pipe(tslint.report()); 26 | }); 27 | 28 | /** 29 | * Compile TypeScript sources and create sourcemaps in build directory. 30 | */ 31 | gulp.task("compile", ["tslint"], () => { 32 | let tsResult = gulp.src("src/**/*.ts") 33 | .pipe(sourcemaps.init()) 34 | .pipe(tsProject()); 35 | return tsResult.js 36 | .pipe(sourcemaps.write(".", {sourceRoot: '/src'})) 37 | .pipe(gulp.dest("build")); 38 | }); 39 | 40 | /** 41 | * Copy all resources that are not TypeScript files into build directory. 42 | */ 43 | gulp.task("resources", () => { 44 | return gulp.src(["src/**/*", "!**/*.ts"]) 45 | .pipe(gulp.dest("build")); 46 | }); 47 | 48 | /** 49 | * Copy all required libraries into build directory. 50 | */ 51 | gulp.task("libs", () => { 52 | return gulp.src([ 53 | 'core-js/client/shim.min.js', 54 | 'systemjs/dist/system-polyfills.js', 55 | 'systemjs/dist/system.src.js', 56 | 'reflect-metadata/Reflect.js', 57 | 'rxjs/**/*.js', 58 | 'zone.js/dist/**', 59 | '@angular/**/bundles/**' 60 | ], {cwd: "node_modules/**"}) /* Glob required here. */ 61 | .pipe(gulp.dest("build/lib")); 62 | }); 63 | 64 | /** 65 | * Watch for changes in TypeScript, HTML and CSS files. 66 | */ 67 | gulp.task('watch', function () { 68 | gulp.watch(["src/**/*.ts"], ['compile']).on('change', function (e) { 69 | console.log('TypeScript file ' + e.path + ' has been changed. Compiling.'); 70 | }); 71 | gulp.watch(["src/**/*.html", "src/**/*.css"], ['resources']).on('change', function (e) { 72 | console.log('Resource file ' + e.path + ' has been changed. Updating.'); 73 | }); 74 | }); 75 | 76 | /** 77 | * Build the project. 78 | */ 79 | gulp.task("build", ['compile', 'resources', 'libs'], () => { 80 | console.log("Building the project ..."); 81 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-typescript-gulp", 3 | "version": "1.0.0", 4 | "description": "Angular2 with TypeScript and Gulp QuickStart", 5 | "scripts": { 6 | "clean": "gulp clean", 7 | "compile": "gulp compile", 8 | "build": "gulp build", 9 | "start": "concurrent --kill-others \"gulp watch\" \"lite-server\"", 10 | "postinstall": "typings install" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/kolorobot/angular2-typescript-gulp.git" 15 | }, 16 | "author": "Rafał Borowiec", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/kolorobot/angular2-typescript-gulp/issues" 20 | }, 21 | "dependencies": { 22 | "@angular/common": "~2.2.4", 23 | "@angular/compiler": "~2.2.4", 24 | "@angular/core": "~2.2.4", 25 | "@angular/forms": "~2.2.4", 26 | "@angular/http": "~2.2.4", 27 | "@angular/platform-browser": "~2.2.4", 28 | "@angular/platform-browser-dynamic": "~2.2.4", 29 | "@angular/router": "~3.2.4", 30 | "@angular/upgrade": "~2.2.4", 31 | 32 | "core-js": "^2.4.1", 33 | "reflect-metadata": "^0.1.3", 34 | "rxjs": "5.0.0-beta.12", 35 | "systemjs": "0.19.27", 36 | "zone.js": "^0.6.23" 37 | }, 38 | "devDependencies": { 39 | "concurrently": "^3.1.0", 40 | "del": "^2.2.0", 41 | "gulp": "^3.9.1", 42 | "gulp-sourcemaps": "^1.9.1", 43 | "gulp-tslint": "^7.0.1", 44 | "gulp-typescript": "^3.1.3", 45 | "lite-server": "^2.2.2", 46 | "tslint": "^4.0.2", 47 | "typescript": "^2.1.4", 48 | "typings": "^2.0.0", 49 | "ts-node": "^1.7.2" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/app/about/components/about.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from "@angular/core"; 2 | import {OnInit} from "@angular/core"; 3 | 4 | @Component({ 5 | templateUrl: './app/about/components/about.html' 6 | }) 7 | export class AboutComponent implements OnInit { 8 | 9 | ngOnInit() { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /src/app/about/components/about.html: -------------------------------------------------------------------------------- 1 |

About

2 |

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

-------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit} from "@angular/core"; 2 | 3 | @Component({ 4 | selector: "app", 5 | templateUrl: "./app/app.html" 6 | }) 7 | export class AppComponent implements OnInit { 8 | ngOnInit() { 9 | console.log("Application component initialized ..."); 10 | } 11 | } -------------------------------------------------------------------------------- /src/app/app.html: -------------------------------------------------------------------------------- 1 |
2 | 6 | 7 |
-------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {BrowserModule} from '@angular/platform-browser'; 3 | 4 | import {AppComponent} from "./app.component"; 5 | import {TaskListComponent} from "./todo/components/task-list.component"; 6 | import {AboutComponent} from "./about/components/about.component"; 7 | import {TaskComponent} from "./todo/components/task.component"; 8 | 9 | import {routing, appRoutingProviders} from './app.routing'; 10 | import {FormsModule} from "@angular/forms"; 11 | 12 | @NgModule({ 13 | imports: [ 14 | BrowserModule, 15 | FormsModule, 16 | routing 17 | ], 18 | declarations: [ 19 | AppComponent, 20 | TaskComponent, 21 | TaskListComponent, 22 | AboutComponent 23 | ], 24 | providers: [ 25 | appRoutingProviders 26 | ], 27 | bootstrap: [AppComponent] 28 | }) 29 | export class AppModule { 30 | } -------------------------------------------------------------------------------- /src/app/app.routing.ts: -------------------------------------------------------------------------------- 1 | import {Routes, RouterModule} from "@angular/router"; 2 | import {TaskListComponent} from "./todo/components/task-list.component"; 3 | import {AboutComponent} from "./about/components/about.component"; 4 | import {ModuleWithProviders} from "@angular/core"; 5 | 6 | const appRoutes: Routes = [ 7 | {path: '', redirectTo: 'tasks', pathMatch: 'full'}, 8 | {path: 'tasks', component: TaskListComponent, data: {title: 'TaskList'}}, 9 | {path: 'about', component: AboutComponent, data: {title: 'About'}} 10 | ]; 11 | 12 | export const appRoutingProviders: any[] = []; 13 | export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true }); 14 | -------------------------------------------------------------------------------- /src/app/main.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; 4 | import {AppModule} from './app.module'; 5 | 6 | const platform = platformBrowserDynamic(); 7 | 8 | platform.bootstrapModule(AppModule); -------------------------------------------------------------------------------- /src/app/todo/components/task-list.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from "@angular/core"; 2 | import {Task} from "../models/task"; 3 | import {OnInit} from "@angular/core"; 4 | import {TaskService} from "../services/task-service"; 5 | import {TaskComponent} from "./task.component"; 6 | 7 | @Component({ 8 | selector: 'task-list', 9 | templateUrl: './app/todo/components/task-list.html', 10 | styleUrls: ['./app/todo/components/task-list.css'], 11 | providers: [TaskService] 12 | }) 13 | export class TaskListComponent implements OnInit { 14 | 15 | todoCount:number; 16 | selectedTask:Task; 17 | tasks:Array; 18 | 19 | constructor(private _taskService:TaskService) { 20 | this.tasks = _taskService.getTasks(); 21 | this.calculateTodoCount(); 22 | } 23 | 24 | ngOnInit() { 25 | console.log("Todo component initialized with " + this.tasks.length + " tasks."); 26 | } 27 | 28 | calculateTodoCount() { 29 | this.todoCount = this.tasks.filter(t => !t.done).length; 30 | } 31 | 32 | select(task:Task) { 33 | this.selectedTask = task; 34 | } 35 | } -------------------------------------------------------------------------------- /src/app/todo/components/task-list.css: -------------------------------------------------------------------------------- 1 | li.selected { 2 | background-color: #8a8a8a; 3 | } -------------------------------------------------------------------------------- /src/app/todo/components/task-list.html: -------------------------------------------------------------------------------- 1 |

Todo tasks ({{todoCount}})

2 | 13 | 14 | -------------------------------------------------------------------------------- /src/app/todo/components/task.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from "@angular/core"; 2 | import {Input} from "@angular/core"; 3 | 4 | import {Task} from "../models/task"; 5 | import {Output} from "@angular/core"; 6 | import {EventEmitter} from "@angular/core"; 7 | 8 | @Component({ 9 | selector: 'task', 10 | templateUrl: './app/todo/components/task.html' 11 | }) 12 | export class TaskComponent { 13 | @Input() task:Task; 14 | @Output() statusChanged:any = new EventEmitter(); 15 | 16 | toggleDone() { 17 | this.task.toggleDone(); 18 | this.statusChanged.emit(null); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/app/todo/components/task.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | -------------------------------------------------------------------------------- /src/app/todo/models/task.ts: -------------------------------------------------------------------------------- 1 | export class Task { 2 | 3 | constructor(public name:string, public done:boolean) { 4 | } 5 | 6 | toggleDone() { 7 | this.done = !this.done; 8 | } 9 | } -------------------------------------------------------------------------------- /src/app/todo/services/task-service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from "@angular/core"; 2 | import {Task} from "../models/task"; 3 | 4 | @Injectable() 5 | export class TaskService { 6 | 7 | private tasks:Array = [ 8 | new Task("Task 1", false), 9 | new Task("Task 2", false), 10 | new Task("Task 3", false), 11 | new Task("Task 4", false), 12 | new Task("Task 5", false) 13 | ]; 14 | 15 | getTasks():Array { 16 | return this.tasks; 17 | } 18 | 19 | addTask(name:string) { 20 | this.tasks.push(new Task(name, false)); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Angular 2 TypeScript Gulp QuickStart 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | Loading... 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/systemjs.config.js: -------------------------------------------------------------------------------- 1 | (function (global) { 2 | System.config({ 3 | paths: { 4 | // paths serve as alias 5 | 'npm:': 'lib/' 6 | }, 7 | // map tells the System loader where to look for things 8 | map: { 9 | // our app is within the app folder 10 | app: 'app', 11 | // angular bundles 12 | '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 13 | '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 14 | '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 15 | '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 16 | '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 17 | '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 18 | '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 19 | '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 20 | // other libraries 21 | 'rxjs': 'npm:rxjs' 22 | }, 23 | // packages tells the System loader how to load when no filename and/or no extension 24 | packages: { 25 | app: { 26 | main: './main.js', 27 | defaultExtension: 'js' 28 | }, 29 | rxjs: { 30 | defaultExtension: 'js' 31 | } 32 | } 33 | }); 34 | })(this); 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "build/app", 4 | "target": "es5", 5 | "module": "system", 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "removeComments": false, 11 | "noImplicitAny": false 12 | }, 13 | "exclude": [ 14 | "gulpfile.ts", 15 | "node_modules" 16 | ] 17 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "curly": true, 5 | "eofline": false, 6 | "forin": true, 7 | "indent": [ 8 | true, 9 | 4 10 | ], 11 | "label-position": true, 12 | "max-line-length": [ 13 | true, 14 | 140 15 | ], 16 | "no-arg": true, 17 | "no-bitwise": true, 18 | "no-console": [ 19 | true, 20 | "debug", 21 | "info", 22 | "time", 23 | "timeEnd", 24 | "trace" 25 | ], 26 | "no-construct": true, 27 | "no-debugger": true, 28 | "no-duplicate-variable": true, 29 | "no-empty": false, 30 | "no-eval": true, 31 | "no-string-literal": false, 32 | "no-trailing-whitespace": true, 33 | "no-use-before-declare": true, 34 | "one-line": [ 35 | true, 36 | "check-open-brace", 37 | "check-catch", 38 | "check-else", 39 | "check-whitespace" 40 | ], 41 | "radix": true, 42 | "semicolon": true, 43 | "triple-equals": [ 44 | true, 45 | "allow-null-check" 46 | ], 47 | "variable-name": false, 48 | "whitespace": [ 49 | true, 50 | "check-branch", 51 | "check-decl", 52 | "check-operator", 53 | "check-separator" 54 | ] 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "globalDependencies": { 3 | "core-js": "registry:dt/core-js#0.0.0+20160725163759", 4 | "node": "registry:dt/node#6.0.0+20160909174046", 5 | "jasmine": "registry:dt/jasmine#2.2.0+20160621224255" 6 | } 7 | } --------------------------------------------------------------------------------