mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Remove angular2-aspnet NPM package source as none of its functionality is still in use (and hasn't been since beta versions of Angular 2)
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
/node_modules/
|
|
||||||
/dist/
|
|
||||||
/bundles/
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
/src/
|
|
||||||
/tsconfig.json
|
|
||||||
/build.js
|
|
||||||
/typings/
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// -------------
|
|
||||||
// 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 },
|
|
||||||
'rxjs/*': { 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);
|
|
||||||
});
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "angular2-aspnet",
|
|
||||||
"version": "0.0.6",
|
|
||||||
"description": "Helpers for Angular 2 apps built on ASP.NET",
|
|
||||||
"main": "./dist/Exports",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
|
||||||
"prepublish": "rimraf *.d.ts dist/*.d.ts && tsc && node build.js"
|
|
||||||
},
|
|
||||||
"typings": "dist/Exports",
|
|
||||||
"author": "Microsoft",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/aspnet/JavaScriptServices/issues"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/aspnet/JavaScriptServices.git"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"angular2": "2.0.0-beta.13",
|
|
||||||
"reflect-metadata": "0.1.2",
|
|
||||||
"rxjs": "5.0.0-beta.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"es6-shim": "^0.35.0",
|
|
||||||
"rimraf": "^2.5.4",
|
|
||||||
"systemjs-builder": "^0.14.11",
|
|
||||||
"typescript": "^2.0.0",
|
|
||||||
"zone.js": "^0.6.10"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
If you just want to use this package, then you *don't have to build it*. Instead, just grab the prebuilt package from NPM:
|
|
||||||
|
|
||||||
npm install angular2-aspnet
|
|
||||||
|
|
||||||
The rest of this file is notes for anyone contributing to this package itself.
|
|
||||||
|
|
||||||
## How to build
|
|
||||||
|
|
||||||
Run the following:
|
|
||||||
|
|
||||||
npm install
|
|
||||||
npm run prepublish
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
|
|
||||||
* Node, NPM
|
|
||||||
* `tsc` installed globally (via `npm install -g typescript`)
|
|
||||||
|
|
||||||
## Project structure
|
|
||||||
|
|
||||||
This package is intended to be consumable both on the server in Node.js, and on the client. Also, it's written in TypeScript,
|
|
||||||
which neither of those environments knows natively, but the TypeScript type definitions need to get delivered with the package
|
|
||||||
so that developers get a good IDE experience when consuming it.
|
|
||||||
|
|
||||||
The build process is therefore:
|
|
||||||
|
|
||||||
1. Compile the TypeScript to produce the development-time (.d.ts) and server-side (.js) artifacts
|
|
||||||
|
|
||||||
`tsc` reads `tsconfig.json` and is instructed to compile all the `.ts` files in `src/`. It produces a corresponding
|
|
||||||
structure of `.js` and `.d.ts` files in `dist/`.
|
|
||||||
|
|
||||||
When a developer consumes the resulting package (via `npm install angular2-aspnet`),
|
|
||||||
|
|
||||||
- No additional copy of `angular2` will be installed, because this package's dependency on it is declared as a
|
|
||||||
`peerDependency`. This means it will work with whatever (compatible) version of `angular2` is already installed.
|
|
||||||
- At runtime inside Node.js, the `main` configuration in `package.json` means the developer can use a standard
|
|
||||||
`import` statement to consume this package (i.e., `import * from 'angular2-aspnet';` in either JS or TS files).
|
|
||||||
- At development time inside an IDE such as Visual Studio Code, the `typings` configuration in `package.json` means
|
|
||||||
the IDE will use the corresponding `.d.ts` file as type metadata for the variable imported that way.
|
|
||||||
|
|
||||||
2. Use the SystemJS builder to produce the client-side artifacts
|
|
||||||
|
|
||||||
`build.js` uses the SystemJS Builder API to combine files in `dist/` into `.js` files ready for use in client-side
|
|
||||||
SystemJS environments, and puts them in `bundles/`. The bundle files contain `System.register` calls so that any
|
|
||||||
other part of your client-side code that tries to import `angular2-aspnet` via SystemJS will get that module at runtime.
|
|
||||||
|
|
||||||
To make it work in an application:
|
|
||||||
- Set up some build step that copies your chosen bundle file from `bundles/` to some location where it will
|
|
||||||
be served to the client
|
|
||||||
- Below your `<script>` tag that loads SystemJS itself, and above the `<script>` tag that makes the first call to
|
|
||||||
`System.import`, have a `<script>` tag that loads the desired `angular2-aspnet.js` bundle file
|
|
||||||
|
|
||||||
For an example, see https://github.com/aspnet/NodeServices/tree/master/samples/angular/MusicStore
|
|
||||||
|
|
||||||
Of course, you can also bundle the `angular2-aspnet.js` file into a larger SystemJS bundle if you want to combine
|
|
||||||
it with the rest of the code in your application.
|
|
||||||
|
|
||||||
Currently, this build system does *not* attempt to send sourcemaps of the original TypeScript to the client. This
|
|
||||||
could be added if a strong need emerges.
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
import { provide, Injectable, Provider } from 'angular2/core';
|
|
||||||
import { Connection, ConnectionBackend, Http, XHRBackend, RequestOptions, Request, RequestMethod, Response, ResponseOptions, ReadyState } from 'angular2/http';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class CachePrimedConnectionBackend extends ConnectionBackend {
|
|
||||||
private _preCachedResponses: PreCachedResponses;
|
|
||||||
|
|
||||||
constructor(private _underlyingBackend: ConnectionBackend, private _baseResponseOptions: ResponseOptions) {
|
|
||||||
super();
|
|
||||||
this._preCachedResponses = (<any>window).__preCachedResponses || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
public createConnection(request: Request): Connection {
|
|
||||||
let cacheKey = request.url;
|
|
||||||
if (request.method === RequestMethod.Get && this._preCachedResponses.hasOwnProperty(cacheKey)) {
|
|
||||||
return new CacheHitConnection(request, this._preCachedResponses[cacheKey], this._baseResponseOptions);
|
|
||||||
} else {
|
|
||||||
return this._underlyingBackend.createConnection(request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CacheHitConnection implements Connection {
|
|
||||||
readyState: ReadyState;
|
|
||||||
request: Request;
|
|
||||||
response: any;
|
|
||||||
|
|
||||||
constructor (req: Request, cachedResponse: PreCachedResponse, baseResponseOptions: ResponseOptions) {
|
|
||||||
this.request = req;
|
|
||||||
this.readyState = ReadyState.Done;
|
|
||||||
|
|
||||||
// Workaround for difficulty consuming CommonJS default exports in TypeScript. Note that it has to be a dynamic
|
|
||||||
// 'require', and not an 'import' statement, because the module isn't available on the server.
|
|
||||||
let obsCtor: any = require('rxjs/Observable').Observable;
|
|
||||||
this.response = new obsCtor(responseObserver => {
|
|
||||||
let response = new Response(new ResponseOptions({ body: cachedResponse.body, status: cachedResponse.statusCode }));
|
|
||||||
responseObserver.next(response);
|
|
||||||
responseObserver.complete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare var require: any; // Part of the workaround mentioned below. Can remove this after updating Angular.
|
|
||||||
|
|
||||||
interface PreCachedResponses {
|
|
||||||
[url: string]: PreCachedResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PreCachedResponse {
|
|
||||||
statusCode: number;
|
|
||||||
body: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CACHE_PRIMED_HTTP_PROVIDERS = [
|
|
||||||
provide(Http, {
|
|
||||||
useFactory: (xhrBackend, requestOptions, responseOptions) => new Http(new CachePrimedConnectionBackend(xhrBackend, responseOptions), requestOptions),
|
|
||||||
deps: [XHRBackend, RequestOptions, ResponseOptions]
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './CachePrimedHttp';
|
|
||||||
export * from './Validation';
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { ControlGroup } from 'angular2/common';
|
|
||||||
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 => {
|
|
||||||
// If there's a specific control for this key, then use it. Otherwise associate the error
|
|
||||||
// with the whole control group.
|
|
||||||
var control = controlGroup.controls[key] || controlGroup;
|
|
||||||
|
|
||||||
// This is rough. Need to find out if there's a better way, or if this is even supported.
|
|
||||||
if (!control.errors) {
|
|
||||||
(<any>control)._errors = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
control.errors[errorMessage] = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ValidationErrorResult {
|
|
||||||
[propertyName: string]: string[];
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es5",
|
|
||||||
"sourceMap": false,
|
|
||||||
"declaration": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"noLib": false,
|
|
||||||
"outDir": "./dist",
|
|
||||||
"lib": ["es2015", "dom"]
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"node_modules"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user