Skip to content

Commit 351cd87

Browse files
committed
Implement HTML output writer!
1 parent b04c096 commit 351cd87

35 files changed

+229
-71
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"reflect-metadata": "0.1.9",
6767
"rimraf": "2.5.4",
6868
"rxjs": "5.1.0",
69-
"scoped-logger": "^0.0.16",
69+
"scoped-logger": "^0.0.18",
7070
"source-map-support": "0.4.11",
7171
"typescript": "2.2.0"
7272
},
@@ -82,7 +82,7 @@
8282
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
8383
"jasmine-core": "2.5.2",
8484
"jasmine-promises": "0.4.1",
85-
"jest": "18.1.0",
85+
"jest": "19.0.2",
8686
"ts-jest": "^19.0.0",
8787
"tslint": "4.4.2",
8888
"zone.js": "0.7.6"
@@ -92,7 +92,7 @@
9292
"modulePaths": [
9393
"<rootDir>/source"
9494
],
95-
"setupTestFrameworkScriptFile": "<rootDir>/source/test-fixtures/dependencies.js",
95+
"setupTestFrameworkScriptFile": "<rootDir>/source/test/fixtures/dependencies.js",
9696
"modulePathIgnorePatterns": [
9797
"bundles(\\|/)"
9898
],

source/application/builder/tests/from-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
renderModuleFixture,
1010
moduleFromComponent,
1111
trimDocument,
12-
} from '../../../test-fixtures';
12+
} from '../../../test/fixtures';
1313

1414
describe('ApplicationFromModule', () => {
1515
it('should require a template document in order to render', done => {

source/application/builder/tests/from-source.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {ApplicationFromSource} from '../from-source';
22

3-
import {templateDocument, getApplicationProject} from '../../../test-fixtures';
3+
import {templateDocument, getApplicationProject} from '../../../test/fixtures';
44

55
describe('ApplicationFromSource', () => {
66
it('can compile a project from source and load a NgFactory module', done => {
7-
const project = getApplicationProject('test-fixtures/application-basic-inline', 'BasicInlineModule');
7+
const project = getApplicationProject('test/fixtures/application-basic-inline', 'BasicInlineModule');
88

99
const application = new ApplicationFromSource(project);
1010

source/application/compiler/pipeline.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {CompilerException} from '../../exception';
1212
import {Project} from '../../application';
1313
import {Publisher} from '../../publisher';
1414
import {makeAbsolute} from '../../filesystem';
15-
import {discoverApplicationModule} from '../ast';
15+
import {discoverApplicationModule} from '../static';
1616

1717
export type CompiledSource = {filename: string, source: string};
1818

@@ -53,15 +53,17 @@ export class CompilerPipeline {
5353
rootModule(program: Program, compilerHost: CompilerHost, options: CompilerOptions): [string, string] {
5454
const containingFile = join(this.project.basePath, 'index.ts');
5555

56-
const applicationModule =
57-
this.project.applicationModule
58-
? this.project.applicationModule
59-
: discoverApplicationModule(program);
56+
const invalid = () =>
57+
applicationModule == null ||
58+
applicationModule.source == null ||
59+
applicationModule.symbol == null;
6060

61-
if (applicationModule == null ||
62-
applicationModule.source == null ||
63-
applicationModule.symbol == null) {
64-
throw new CompilerException(`Cannot find application root @NgModule, please provide in Project structure`);
61+
var applicationModule = this.project.applicationModule;
62+
if (invalid()) {
63+
applicationModule = discoverApplicationModule(program);
64+
}
65+
if (invalid()) {
66+
throw new CompilerException(`Cannot locate root @NgModule with static analysis (please name them explicitly)`);
6567
}
6668

6769
const rootModule = sourceToNgFactory(applicationModule.source);
@@ -91,16 +93,12 @@ export class CompilerPipeline {
9193

9294
const executable = (filename: string) => extname(filename) === '.js';
9395

94-
const sourceToNgFactory = (source: string): string => {
95-
if (/\.ngfactory(\.(ts|js))?$/.test(source) === false) {
96-
return `${source.replace(/\.(js|ts)$/, String())}.ngfactory`;
97-
}
98-
return source;
99-
};
96+
const sourceToNgFactory = (source: string): string =>
97+
/\.ngfactory(\.(ts|js))?$/.test(source) === false
98+
? `${source.replace(/\.(js|ts)$/, String())}.ngfactory`
99+
: source;
100100

101-
const symbolToNgFactory = (symbol: string): string => {
102-
if (/NgFactory$/.test(symbol) === false) {
103-
return `${symbol}NgFactory`;
104-
}
105-
return symbol;
106-
};
101+
const symbolToNgFactory = (symbol: string): string =>
102+
/NgFactory$/.test(symbol) === false
103+
? `${symbol}NgFactory`
104+
: symbol;

source/application/compiler/tests/compiler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import {getApplicationProject} from '../../../test-fixtures';
1+
import {getApplicationProject} from '../../../test/fixtures';
22

33
import {Compiler} from '../compiler';
44

55
describe('in-memory Angular compiler', () => {
66
it('can build application-basic-inline in memory return executable NgModuleFactory', async () => {
7-
const compiler = new Compiler(getApplicationProject('test-fixtures/application-basic-inline', 'BasicInlineModule'));
7+
const compiler = new Compiler(getApplicationProject('test/fixtures/application-basic-inline', 'BasicInlineModule'));
88
const module = await compiler.compile();
99
expect(module).not.toBeNull();
1010
expect(typeof module).toBe('object');
1111
expect(module.constructor.name).toBe('NgModuleFactory');
1212
});
1313

1414
it('can build application-basic-external in memory return executable NgModuleFactory', async () => {
15-
const compiler = new Compiler(getApplicationProject('test-fixtures/application-basic-external', 'BasicExternalModule'));
15+
const compiler = new Compiler(getApplicationProject('test/fixtures/application-basic-external', 'BasicExternalModule'));
1616
const module = await compiler.compile();
1717
expect(module).not.toBeNull();
1818
expect(typeof module).toBe('object');
1919
expect(module.constructor.name).toBe('NgModuleFactory');
2020
});
2121

2222
it('can build application-routed in memory return executable NgModuleFactory', async () => {
23-
const compiler = new Compiler(getApplicationProject('test-fixtures/application-routed', 'BasicRoutedModule'));
23+
const compiler = new Compiler(getApplicationProject('test/fixtures/application-routed', 'BasicRoutedModule'));
2424
const module = await compiler.compile();
2525
expect(module).not.toBeNull();
2626
expect(typeof module).toBe('object');

source/application/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export * from './ast';
21
export * from './builder';
32
export * from './compiler';
3+
export * from './static';
44
export * from './fork';
55
export * from './project';
66
export * from './render';
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ const importClause = (sourceFile: SourceFile, identifier: string): ApplicationMo
100100
continue;
101101
}
102102
for (const clause of statement.parent.importClause.namedBindings.elements || []) {
103+
if (clause.name == null) {
104+
continue;
105+
}
103106
if (defactory(clause.name.text) === identifier) {
104107
return {
105108
source: relativeImportPath(sourceFile.fileName, statement.text),
106-
symbol: clause.propertyName.text
109+
symbol: identifier,
107110
};
108111
}
109112
}

source/bin/logger.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {
2+
ConsoleStream,
3+
Logger,
4+
createLogger
5+
} from 'scoped-logger';
6+
7+
export const logger: Logger = createLogger(String(), [new ConsoleStream()]);

0 commit comments

Comments
 (0)