Beginning angular2-aspnet NPM package

This commit is contained in:
SteveSandersonMS
2015-12-10 14:10:21 +00:00
parent 2261c9964e
commit 30281636d6
7 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
/node_modules/
/dist/
/bundles/

View File

@@ -0,0 +1,3 @@
/src/
/tsconfig.json
/build.js

View File

@@ -0,0 +1,32 @@
// -------------
// No need to invoke this directly. To run a build, execute:
// npm run prepublish
// -------------
var Builder = require('systemjs-builder');
var builder = new Builder('./');
builder.config({
defaultJSExtensions: true,
paths: {
'angular2-aspnet': 'dist/Exports',
'angular2-aspnet/*': 'dist/*'
},
meta: {
'angular2/*': { build: false }
}
});
var entryPoint = 'dist/Exports';
var tasks = [
builder.bundle(entryPoint, './bundles/angular2-aspnet.js'),
builder.bundle(entryPoint, './bundles/angular2-aspnet.min.js', { minify: true })
];
Promise.all(tasks)
.then(function() {
console.log('Build complete');
})
.catch(function(err) {
console.error('Build error');
console.error(err);
});

View File

@@ -0,0 +1,24 @@
{
"name": "angular2-aspnet",
"version": "0.0.1",
"description": "Helpers for Angular 2 apps built on ASP.NET",
"main": "./dist/Exports",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "tsc && node build.js"
},
"repository": {
"type": "git",
"url": "https://github.com/aspnet/NodeServices/tree/master/Microsoft.AspNet.AngularServices"
},
"typings": "dist/Exports",
"author": "Microsoft",
"license": "Apache-2.0",
"peerDependencies": {
"angular2": "^2.0.0-alpha.44"
},
"devDependencies": {
"systemjs-builder": "^0.14.11",
"typescript": "^1.7.3"
}
}

View File

@@ -0,0 +1 @@
export * from './Validation';

View File

@@ -0,0 +1,31 @@
import { ControlGroup } from 'angular2/angular2';
import { Response } from 'angular2/http';
export class Validation {
public static showValidationErrors(response: ValidationErrorResult | Response, controlGroup: ControlGroup): void {
if (response instanceof Response) {
var httpResponse = <Response>response;
response = <ValidationErrorResult>(httpResponse.json());
}
// It's not yet clear whether this is a legitimate and supported use of the ng.ControlGroup API.
// Need feedback from the Angular 2 team on whether there's a better way.
var errors = <ValidationErrorResult>response;
Object.keys(errors || {}).forEach(key => {
errors[key].forEach(errorMessage => {
// This in particular is rough
if (!controlGroup.controls[key].errors) {
(<any>controlGroup.controls[key])._errors = {};
}
controlGroup.controls[key].errors[errorMessage] = true;
});
});
}
}
export interface ValidationErrorResult {
[propertyName: string]: string[];
}

View File

@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": false,
"declaration": true,
"noLib": false,
"outDir": "./dist"
},
"exclude": [
"node_modules"
]
}