From 30281636d663a240aeeb5eee1f362e8458c57db9 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Thu, 10 Dec 2015 14:10:21 +0000 Subject: [PATCH] Beginning angular2-aspnet NPM package --- .../npm/.gitignore | 3 ++ .../npm/.npmignore | 3 ++ Microsoft.AspNet.AngularServices/npm/build.js | 32 +++++++++++++++++++ .../npm/package.json | 24 ++++++++++++++ .../npm/src/Exports.ts | 1 + .../npm/src/Validation.ts | 31 ++++++++++++++++++ .../npm/tsconfig.json | 13 ++++++++ 7 files changed, 107 insertions(+) create mode 100644 Microsoft.AspNet.AngularServices/npm/.gitignore create mode 100644 Microsoft.AspNet.AngularServices/npm/.npmignore create mode 100644 Microsoft.AspNet.AngularServices/npm/build.js create mode 100644 Microsoft.AspNet.AngularServices/npm/package.json create mode 100644 Microsoft.AspNet.AngularServices/npm/src/Exports.ts create mode 100644 Microsoft.AspNet.AngularServices/npm/src/Validation.ts create mode 100644 Microsoft.AspNet.AngularServices/npm/tsconfig.json diff --git a/Microsoft.AspNet.AngularServices/npm/.gitignore b/Microsoft.AspNet.AngularServices/npm/.gitignore new file mode 100644 index 0000000..6cb02b1 --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ +/dist/ +/bundles/ diff --git a/Microsoft.AspNet.AngularServices/npm/.npmignore b/Microsoft.AspNet.AngularServices/npm/.npmignore new file mode 100644 index 0000000..9c3d4eb --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/.npmignore @@ -0,0 +1,3 @@ +/src/ +/tsconfig.json +/build.js diff --git a/Microsoft.AspNet.AngularServices/npm/build.js b/Microsoft.AspNet.AngularServices/npm/build.js new file mode 100644 index 0000000..2a55704 --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/build.js @@ -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); + }); diff --git a/Microsoft.AspNet.AngularServices/npm/package.json b/Microsoft.AspNet.AngularServices/npm/package.json new file mode 100644 index 0000000..8709432 --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/package.json @@ -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" + } +} diff --git a/Microsoft.AspNet.AngularServices/npm/src/Exports.ts b/Microsoft.AspNet.AngularServices/npm/src/Exports.ts new file mode 100644 index 0000000..897995d --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/src/Exports.ts @@ -0,0 +1 @@ +export * from './Validation'; diff --git a/Microsoft.AspNet.AngularServices/npm/src/Validation.ts b/Microsoft.AspNet.AngularServices/npm/src/Validation.ts new file mode 100644 index 0000000..5ed2beb --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/src/Validation.ts @@ -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 = (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 = response; + Object.keys(errors || {}).forEach(key => { + errors[key].forEach(errorMessage => { + // This in particular is rough + if (!controlGroup.controls[key].errors) { + (controlGroup.controls[key])._errors = {}; + } + + controlGroup.controls[key].errors[errorMessage] = true; + }); + }); + } + +} + +export interface ValidationErrorResult { + [propertyName: string]: string[]; +} diff --git a/Microsoft.AspNet.AngularServices/npm/tsconfig.json b/Microsoft.AspNet.AngularServices/npm/tsconfig.json new file mode 100644 index 0000000..c586e45 --- /dev/null +++ b/Microsoft.AspNet.AngularServices/npm/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "sourceMap": false, + "declaration": true, + "noLib": false, + "outDir": "./dist" + }, + "exclude": [ + "node_modules" + ] +}