mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Beginning angular2-aspnet NPM package
This commit is contained in:
3
Microsoft.AspNet.AngularServices/npm/.gitignore
vendored
Normal file
3
Microsoft.AspNet.AngularServices/npm/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
/bundles/
|
||||
3
Microsoft.AspNet.AngularServices/npm/.npmignore
Normal file
3
Microsoft.AspNet.AngularServices/npm/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
/src/
|
||||
/tsconfig.json
|
||||
/build.js
|
||||
32
Microsoft.AspNet.AngularServices/npm/build.js
Normal file
32
Microsoft.AspNet.AngularServices/npm/build.js
Normal 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);
|
||||
});
|
||||
24
Microsoft.AspNet.AngularServices/npm/package.json
Normal file
24
Microsoft.AspNet.AngularServices/npm/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
1
Microsoft.AspNet.AngularServices/npm/src/Exports.ts
Normal file
1
Microsoft.AspNet.AngularServices/npm/src/Exports.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './Validation';
|
||||
31
Microsoft.AspNet.AngularServices/npm/src/Validation.ts
Normal file
31
Microsoft.AspNet.AngularServices/npm/src/Validation.ts
Normal 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[];
|
||||
}
|
||||
13
Microsoft.AspNet.AngularServices/npm/tsconfig.json
Normal file
13
Microsoft.AspNet.AngularServices/npm/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"noLib": false,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user