add angular 2

This commit is contained in:
chsakell
2016-09-26 10:49:50 +03:00
parent 05c81a3cb9
commit 53e0dd8685
10 changed files with 261 additions and 2 deletions

2
.gitignore vendored
View File

@@ -186,6 +186,8 @@ typings/
wwwroot/lib/
app/**/*.js
app/**/*.map
wwwroot/app/**/*.*
orleans.codegen.cs
# RIA/Silverlight projects

View File

@@ -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",

View File

@@ -3,8 +3,27 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="~/lib/signalr/jquery.signalR.js"></script>
<script src="~/lib/core-js/client/shim.js"></script>
<script src="~/lib/zone.js/dist/zone.js"></script>
<script src="~/lib/reflect-metadata/Reflect.js"></script>
<script src="~/lib/systemjs/dist/system.src.js"></script>
<script src="/signalr/js"></script>
<script src="~/js/systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<h1>Hello from home controller!</h1>
<my-app>Loading...</my-app>
</body>
</html>

6
app/app.component.ts Normal file
View File

@@ -0,0 +1,6 @@
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular App</h1>'
})
export class AppComponent { }

9
app/app.module.ts Normal file
View File

@@ -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 { }

6
app/main.ts Normal file
View File

@@ -0,0 +1,6 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

143
gulpfile.js Normal file
View File

@@ -0,0 +1,143 @@
/// <binding Clean='clean' />
"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"]);

17
tsconfig.json Normal file
View File

@@ -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
}
}

0
wwwroot/css/site.css Normal file
View File

View File

@@ -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);