Skip to content

Commit 235cc7d

Browse files
committedJul 11, 2017
Add option to change filename of output (--filename)
1 parent 6ca45f0 commit 235cc7d

File tree

13 files changed

+146
-5
lines changed

13 files changed

+146
-5
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.10.34",
3+
"version": "0.10.36",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",

‎source/application/builder/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './fork';
44
export * from './from-module-factory';
55
export * from './from-module';
66
export * from './from-source';
7+
export * from './options';
78
export * from './prerenderer';

‎source/bin/options/parse.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ let inlineVectorGraphics: boolean = false;
104104
// Enable 'blacklist by default' route rendering behaviour (each route you wish to render must be marked with `server: true')
105105
let blacklist: boolean = false;
106106

107+
// The name of files to generate for each route (index.html, eg foo/index.html)
108+
let filename: string = Files.index;
109+
107110
const renderOptions = (options): OutputOptions => {
108111
let outputString = options['output'];
109112

@@ -113,7 +116,7 @@ const renderOptions = (options): OutputOptions => {
113116

114117
const output = pathFromString(outputString);
115118

116-
return {output, inlineStylesheets, inlineVectorGraphics};
119+
return {filename, output, inlineStylesheets, inlineVectorGraphics};
117120
};
118121

119122
const createOutput = (options): OutputProducer =>
@@ -134,6 +137,7 @@ const parseCommandLine = () => {
134137
.option('-p, --project <path>', 'Path to tsconfig.json file or project root (if tsconfig.json lives in the root)', cwd())
135138
.option('-w, --webpack <config>', 'Optional path to webpack configuration file')
136139
.option('-t, --template <path>', 'HTML template document', 'dist/index.html')
140+
.option('-f, --filename <path>', 'Change the name of the HTML files that are produced', filename)
137141
.option('-m, --module <path>', 'Path to root application module TypeScript file')
138142
.option('-s, --symbol <identifier>', 'Class name of application root module')
139143
.option('-o, --output <path>', 'Output path to write rendered HTML documents to', 'dist')
@@ -160,6 +164,8 @@ const parseCommandLine = () => {
160164
options.on('pessimistic',
161165
value => pessimistic = value == null ? true : value);
162166

167+
options.on('filename', value => filename = value);
168+
163169
return options.parse(process.argv);
164170
};
165171

‎source/bin/render.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Module = require('module');
1010

1111
import {
1212
Files,
13+
PrerenderOptions,
1314
applicationBuilderFromSource,
1415
applicationPrerenderer,
1516
log,
@@ -41,7 +42,9 @@ const applicationRenderer = applicationPrerenderer(application);
4142

4243
const execute = async () => {
4344
try {
44-
await applicationRenderer.prerenderTo(options.output, {pessimistic: options.pessimistic});
45+
const prerender: PrerenderOptions = {pessimistic: options.pessimistic};
46+
47+
await applicationRenderer.prerenderTo(options.output, prerender);
4548
}
4649
finally {
4750
// If we are debugging, then we are likely to produce a stack trace that includes compiled

‎source/output/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class HtmlOutput implements OutputProducer {
3535
}
3636

3737
async write<V>(snapshot: Snapshot<V>): Promise<void> {
38-
const file = fileFromString(join(this.routedPathFromSnapshot(snapshot).toString(), Files.index));
38+
const file = fileFromString(join(this.routedPathFromSnapshot(snapshot).toString(), this.options.filename || Files.index));
3939

4040
transformInplace(file.parent(), snapshot, this.options);
4141

‎source/output/options.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {PathReference} from '../filesystem/contracts';
22

33
export interface OutputOptions {
4+
// Output filename to generate for each route (index.html by default)
5+
filename: string;
6+
47
output: PathReference;
58

69
// Inline CSS stylesheets into the output

‎source/platform/http/backend.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {ConnectionBackend, Connection, Request, XHRBackend} from '@angular/http';
2+
3+
import {HttpConnection} from './connection';
4+
5+
export class HttpBackendImpl implements ConnectionBackend {
6+
constructor(private backend: XHRBackend) {}
7+
8+
createConnection(request: Request): Connection {
9+
return new HttpConnection(request, this.backend);
10+
}
11+
}

‎source/platform/http/connection.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Connection, ReadyState, Request, XHRBackend} from '@angular/http';
2+
import {Observable} from 'rxjs/Observable';
3+
4+
import {adjustUri} from './uri';
5+
6+
import {scheduleTask} from './../zone/task';
7+
8+
export class HttpConnection implements Connection {
9+
response: Observable<Response>;
10+
11+
private connection: Connection;
12+
13+
constructor(public request: Request, backend: XHRBackend) {
14+
Object.assign(request, {url: adjustUri(request.url)});
15+
16+
this.response = scheduleTask(() => {
17+
this.connection = backend.createConnection(this.request);
18+
19+
return this.connection.response as Observable<any>;
20+
});
21+
}
22+
23+
get readyState(): ReadyState {
24+
return this.connection ? this.connection.readyState : ReadyState.Unsent;
25+
}
26+
}

‎source/platform/http/http.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Injectable} from '@angular/core';
2+
3+
import {ConnectionBackend, Http, RequestOptionsArgs, RequestOptions, Request, Response} from '@angular/http';
4+
5+
import {Observable} from 'rxjs/Observable';
6+
7+
@Injectable()
8+
export class HttpImpl extends Http {
9+
constructor(private backend: ConnectionBackend, defaultOptions: RequestOptions) {
10+
super(backend, defaultOptions);
11+
}
12+
13+
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
14+
console.error('CREATE REQUEST CON');
15+
return this.backend.createConnection(url).response;
16+
}
17+
}

‎source/platform/http/uri.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {PlatformLocation} from '@angular/common';
2+
3+
import {LocationImpl} from '../location/location';
4+
5+
import {PlatformException} from '../../exception';
6+
7+
import {injectableFromZone} from '../zone';
8+
9+
import url = require('url');
10+
11+
export const adjustUri = (uri: string): string => {
12+
const parsed = url.parse(uri);
13+
14+
if (parsed.host == null) { // relative path?
15+
const location = injectableFromZone(Zone.current, PlatformLocation) as LocationImpl;
16+
if (location) {
17+
return url.resolve(location.href, parsed.href);
18+
}
19+
else {
20+
try {
21+
return url.resolve(Zone.current.name, parsed.href);
22+
}
23+
catch (exception) {
24+
throw new PlatformException(`Cannot determine origin URI of zone: ${Zone.current.name}`, exception);
25+
}
26+
}
27+
}
28+
return uri;
29+
};

‎source/platform/http/xsrf.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Injectable} from '@angular/core';
2+
3+
import {Request, XSRFStrategy} from '@angular/http';
4+
5+
@Injectable()
6+
export class NoopXsrfStrategy implements XSRFStrategy {
7+
configureRequest(req: Request) {}
8+
}

‎source/platform/zone/task.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Observable, Subscription} from 'rxjs';
2+
3+
import 'zone.js';
4+
5+
import {RuntimeException} from '../../exception';
6+
7+
export const scheduleTask = <T>(execute: () => Observable<T>, description?: string): Observable<T> => {
8+
let subscription: Subscription;
9+
10+
return new Observable<T>(observer => {
11+
let result: T | Error;
12+
13+
const scheduleTask = (task: Task) => {
14+
subscription = execute().subscribe(
15+
value => {
16+
result = value;
17+
task.invoke();
18+
},
19+
error => {
20+
result = new RuntimeException(`Task failure: ${description}`, error);
21+
},
22+
() => task.invoke());
23+
};
24+
25+
const complete = () => {
26+
if (result instanceof Error) {
27+
observer.error(result as Error);
28+
}
29+
else {
30+
observer.next(result);
31+
observer.complete();
32+
}
33+
};
34+
35+
Zone.current.scheduleMacroTask('wrapped task', complete, null, scheduleTask, subscription.unsubscribe.bind(subscription));
36+
});
37+
};

‎source/static/files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export namespace Files {
22
// Angular CLI configuration file names
33
export const cli = ['angular-cli.json', '.angular-cli.json'];
44

5-
// Filename used when writing route structures to disk (eg foo/index.html)
5+
// Default filename used when writing route structures to disk (eg foo/index.html)
66
export const index = 'index.html';
77

88
// The possible names of node_modules folders (TODO(bond): Really inviolate or configurable?)

0 commit comments

Comments
 (0)
Failed to load comments.