From 53e0dd868524db93e40bc9e941c64585b0c7fb88 Mon Sep 17 00:00:00 2001 From: chsakell Date: Mon, 26 Sep 2016 10:49:50 +0300 Subject: [PATCH] add angular 2 --- .gitignore | 2 + Startup.cs | 17 +++- Views/Home/Index.cshtml | 21 ++++- app/app.component.ts | 6 ++ app/app.module.ts | 9 +++ app/main.ts | 6 ++ gulpfile.js | 143 ++++++++++++++++++++++++++++++++++ tsconfig.json | 17 ++++ wwwroot/css/site.css | 0 wwwroot/js/systemjs.config.js | 42 ++++++++++ 10 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 app/app.component.ts create mode 100644 app/app.module.ts create mode 100644 app/main.ts create mode 100644 gulpfile.js create mode 100644 tsconfig.json create mode 100644 wwwroot/css/site.css create mode 100644 wwwroot/js/systemjs.config.js diff --git a/.gitignore b/.gitignore index ed428c1..09b81b2 100644 --- a/.gitignore +++ b/.gitignore @@ -186,6 +186,8 @@ typings/ wwwroot/lib/ app/**/*.js app/**/*.map +wwwroot/app/**/*.* + orleans.codegen.cs # RIA/Silverlight projects diff --git a/Startup.cs b/Startup.cs index c1cac8e..478c186 100644 --- a/Startup.cs +++ b/Startup.cs @@ -39,7 +39,22 @@ namespace LiveGameFeed loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - app.UseMvc(routes => + app.UseCors( + builder => builder.AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials()) + .UseStaticFiles() + .UseWebSockets(); + /* + .Map("/xhrf", a => a.Run(async context => + { + var tokens = antiforgery.GetAndStoreTokens(context); + context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false }); + await context.Response.WriteAsync(tokens.RequestToken); + })); + */ + app.UseMvc(routes => { routes.MapRoute( name: "default", diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index d569ec2..055727c 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -3,8 +3,27 @@ + + + + + + + + + + + + + + + + + -

Hello from home controller!

+ Loading... \ No newline at end of file diff --git a/app/app.component.ts b/app/app.component.ts new file mode 100644 index 0000000..e049992 --- /dev/null +++ b/app/app.component.ts @@ -0,0 +1,6 @@ +import { Component } from '@angular/core'; +@Component({ + selector: 'my-app', + template: '

My First Angular App

' +}) +export class AppComponent { } diff --git a/app/app.module.ts b/app/app.module.ts new file mode 100644 index 0000000..6c3b88c --- /dev/null +++ b/app/app.module.ts @@ -0,0 +1,9 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { AppComponent } from './app.component'; +@NgModule({ + imports: [BrowserModule], + declarations: [AppComponent], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/app/main.ts b/app/main.ts new file mode 100644 index 0000000..446a949 --- /dev/null +++ b/app/main.ts @@ -0,0 +1,6 @@ +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { AppModule } from './app.module'; + +const platform = platformBrowserDynamic(); + +platform.bootstrapModule(AppModule); diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..680206c --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,143 @@ +/// +"use strict"; + +var gulp = require("gulp"), + rimraf = require("gulp-rimraf"), + concat = require("gulp-concat"), + cssmin = require("gulp-cssmin"), + uglify = require("gulp-uglify"), + copy = require("gulp-copy"), + rename = require("gulp-rename"), + watch = require("gulp-watch"), + tsc = require("gulp-tsc"); + +var paths = { + webroot: "./wwwroot/", + node_modules: "./node_modules/" +}; + +paths.js = paths.webroot + "js/**/*.js"; +paths.minJs = paths.webroot + "js/**/*.min.js"; +paths.css = paths.webroot + "css/**/*.css"; +paths.minCss = paths.webroot + "css/**/*.min.css"; +paths.concatJsDest = paths.webroot + "js/live-game-feed.min.js"; +paths.concatCssDest = paths.webroot + "css/site.min.css"; + +paths.lib = paths.webroot + "lib/"; + +paths.angular = paths.node_modules + "@angular/**/*.js" +paths.angularWebApi = paths.node_modules + "angular2-in-memory-web-api/*.js" +paths.corejs = paths.node_modules + "core-js/client/shim*.js"; +paths.zonejs = paths.node_modules + "zone.js/dist/zone*.js"; +paths.reflectjs = paths.node_modules + "reflect-metadata/Reflect*.js"; +paths.systemjs = paths.node_modules + "systemjs/dist/*.js"; +paths.rxjs = paths.node_modules + "rxjs/**/*.js"; +paths.jasminejs = paths.node_modules + "jasmine-core/lib/jasmine-core/*.*"; + +paths.app = "app/**/*.*"; +paths.appDest = paths.webroot + "app"; +gulp.task("clean:js", function (cb) { + return rimraf(paths.concatJsDest, cb); +}); + +gulp.task("clean:css", function (cb) { + rimraf(paths.concatCssDest, cb); +}); + +gulp.task("clean", ["clean:js", "clean:css"]); + +gulp.task("min:js", function () { + return gulp.src([paths.js, "!" + paths.minJs], { base: "." }) + .pipe(concat(paths.concatJsDest)) + .pipe(uglify()) + .pipe(gulp.dest(".")); +}); + +gulp.task("min:css", function () { + return gulp.src([paths.css, "!" + paths.minCss]) + .pipe(concat(paths.concatCssDest)) + .pipe(cssmin()) + .pipe(gulp.dest(".")); +}); + +gulp.task("copy:angular", function () { + + return gulp.src(paths.angular, + { base: paths.node_modules + "@angular/" }) + .pipe(gulp.dest(paths.lib + "angular/")); +}); + +gulp.task("copy:angularWebApi", function () { + return gulp.src(paths.angularWebApi, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:corejs", function () { + return gulp.src(paths.corejs, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:zonejs", function () { + return gulp.src(paths.zonejs, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:reflectjs", function () { + return gulp.src(paths.reflectjs, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:systemjs", function () { + return gulp.src(paths.systemjs, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:rxjs", function () { + return gulp.src(paths.rxjs, + { base: paths.node_modules }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("copy:app", function () { + return gulp.src(paths.app) + .pipe(gulp.dest(paths.appDest)); +}); + +gulp.task("copy:jasmine", function () { + return gulp.src(paths.jasminejs, + { base: paths.node_modules + "jasmine-core/lib" }) + .pipe(gulp.dest(paths.lib)); +}); + +gulp.task("dependencies", ["copy:angular", + "copy:angularWebApi", + "copy:corejs", + "copy:zonejs", + "copy:reflectjs", + "copy:systemjs", + "copy:rxjs", + "copy:jasmine", + "copy:app"]); + +gulp.task("watch", function () { + return watch(paths.app) + .pipe(gulp.dest(paths.appDest)) +}); + +gulp.task("min:app", function () { + return gulp.src(paths.app) + .pipe(uglify()) + .pipe(rename({ + suffix: '.min' + })) + .pipe(gulp.dest(paths.appDest)); +}); + +gulp.task("min", ["min:js", "min:css", "min:app"]); + +gulp.task("default", ["clean", "dependencies"]); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..be68417 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false, + "suppressImplicitAnyIndexErrors": true + }, + "compileOnSave": true, + "angularCompilerOptions": { + "genDir": ".", + "debug": true + } +} \ No newline at end of file diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css new file mode 100644 index 0000000..e69de29 diff --git a/wwwroot/js/systemjs.config.js b/wwwroot/js/systemjs.config.js new file mode 100644 index 0000000..411eb7d --- /dev/null +++ b/wwwroot/js/systemjs.config.js @@ -0,0 +1,42 @@ +/** + * System configuration for Angular 2 samples + * Adjust as necessary for your application needs. + */ +(function (global) { + System.config({ + paths: { + // paths serve as alias + 'npm:': 'lib/' + }, + // map tells the System loader where to look for things + map: { + // our app is within the app folder + app: 'app', + // angular bundles + '@angular/core': 'npm:angular/core/bundles/core.umd.js', + '@angular/common': 'npm:angular/common/bundles/common.umd.js', + '@angular/compiler': 'npm:angular/compiler/bundles/compiler.umd.js', + '@angular/platform-browser': 'npm:angular/platform-browser/bundles/platform-browser.umd.js', + '@angular/platform-browser-dynamic': 'npm:angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', + '@angular/http': 'npm:angular/http/bundles/http.umd.js', + '@angular/forms': 'npm:angular/forms/bundles/forms.umd.js', + // other libraries + 'rxjs': 'npm:rxjs', + 'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', + }, + // packages tells the System loader how to load when no filename and/or no extension + packages: { + app: { + main: './main.js', + defaultExtension: 'js' + }, + rxjs: { + defaultExtension: 'js' + }, + 'angular2-in-memory-web-api': { + main: './index.js', + defaultExtension: 'js' + } + } + }); +})(this); \ No newline at end of file