Skip to content

Commit

Permalink
refactor(compiler-cli): fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Aug 8, 2017
1 parent a02f33c commit 8d3b6d7
Show file tree
Hide file tree
Showing 31 changed files with 407 additions and 188 deletions.
30 changes: 30 additions & 0 deletions integration/i18n/closure.conf
@@ -0,0 +1,30 @@
--compilation_level=ADVANCED_OPTIMIZATIONS
--language_out=ES5
--js_output_file=dist/bundle.js
--output_manifest=dist/manifest.MF
--variable_renaming_report=dist/variable_renaming_report
--property_renaming_report=dist/property_renaming_report
--create_source_map=%outname%.map

--warning_level=QUIET
--dependency_mode=STRICT
--rewrite_polyfills=false

node_modules/zone.js/dist/zone_externs.js

--js node_modules/rxjs/**.js
--process_common_js_modules
--module_resolution=node

node_modules/@angular/core/@angular/core.js
--js_module_root=node_modules/@angular/core
node_modules/@angular/core/src/testability/testability.externs.js

node_modules/@angular/common/@angular/common.js
--js_module_root=node_modules/@angular/common

node_modules/@angular/platform-browser/@angular/platform-browser.js
--js_module_root=node_modules/@angular/platform-browser

--js built/**.js
--entry_point=built/src/main
10 changes: 10 additions & 0 deletions integration/i18n/e2e/app.e2e-spec.ts
@@ -0,0 +1,10 @@
import { browser, element, by } from 'protractor';

describe('i18n E2E Tests', function () {
it('remove i18n attributes', function () {
browser.get('');
const div = element(by.css('div'));
expect(div.getAttribute('title')).not.toBe(null);
expect(div.getAttribute('i18n')).toBe(null);
});
});
15 changes: 15 additions & 0 deletions integration/i18n/e2e/browser.config.json
@@ -0,0 +1,15 @@
{
"open": false,
"logLevel": "silent",
"port": 8080,
"server": {
"baseDir": "src",
"routes": {
"/dist": "dist",
"/node_modules": "node_modules"
},
"middleware": {
"0": null
}
}
}
16 changes: 16 additions & 0 deletions integration/i18n/e2e/protractor.config.js
@@ -0,0 +1,16 @@
exports.config = {
specs: [
'../built/e2e/*.e2e-spec.js'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox'],
binary: process.env.CHROME_BIN,
}
},
directConnect: true,
baseUrl: 'http://localhost:8080/',
framework: 'jasmine',
useAllAngular2AppRoots: true
};
8 changes: 8 additions & 0 deletions integration/i18n/e2e/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "../built/e2e",
"types": ["jasmine"],
// TODO(alexeagle): was required for Protractor 4.0.11
"skipLibCheck": true
}
}
32 changes: 32 additions & 0 deletions integration/i18n/package.json
@@ -0,0 +1,32 @@
{
"name": "angular-integration",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
"@angular/tsc-wrapped": "file:../../dist/packages-dist/tsc-wrapped",
"google-closure-compiler": "20170409.0.0",
"rxjs": "5.3.1",
"typescript": "~2.3.1",
"zone.js": "0.8.6"
},
"devDependencies": {
"@types/jasmine": "2.5.41",
"concurrently": "3.4.0",
"lite-server": "2.2.2",
"protractor": "file:../../node_modules/protractor"
},
"scripts": {
"closure": "java -jar node_modules/google-closure-compiler/compiler.jar --flagfile closure.conf",
"test": "ngc && yarn run closure && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first",
"serve": "lite-server -c e2e/browser.config.json",
"preprotractor": "tsc -p e2e",
"protractor": "protractor e2e/protractor.config.js"
}
}
11 changes: 11 additions & 0 deletions integration/i18n/src/app.ts
@@ -0,0 +1,11 @@
import {HelloWorldComponent} from './hello-world.component';

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';

@NgModule({
declarations: [HelloWorldComponent],
bootstrap: [HelloWorldComponent],
imports: [BrowserModule],
})
export class AppModule {}
9 changes: 9 additions & 0 deletions integration/i18n/src/hello-world.component.ts
@@ -0,0 +1,9 @@
import {Component} from '@angular/core';

@Component({
selector: 'hello-world-app',
template: `<div i18n="desc|meaning" title="i18n attribute should be removed">Hello {{ name }}!</div>`,
})
export class HelloWorldComponent {
name: string = 'world';
}
18 changes: 18 additions & 0 deletions integration/i18n/src/index.html
@@ -0,0 +1,18 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Hello World</title>
<base href="/">
</head>

<body>
<hello-world-app>Loading...</hello-world-app>

<script src="node_modules/zone.js/dist/zone.min.js"></script>
<script src="dist/bundle.js"></script>

</body>

</html>
4 changes: 4 additions & 0 deletions integration/i18n/src/main.ts
@@ -0,0 +1,4 @@
import {platformBrowser} from '@angular/platform-browser';
import {AppModuleNgFactory} from './app.ngfactory';

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
30 changes: 30 additions & 0 deletions integration/i18n/tsconfig.json
@@ -0,0 +1,30 @@
{
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true
},

"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
// TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432
"strictNullChecks": false,
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"experimentalDecorators": true,
"outDir": "built",
"rootDir": ".",
"declaration": true,
"types": []
},

"exclude": [
"vendor",
"node_modules",
"built",
"dist",
"e2e"
]
}
12 changes: 0 additions & 12 deletions packages/compiler-cli/integrationtest/alt/src/bootstrap.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/compiler-cli/integrationtest/test/all_spec.ts
Expand Up @@ -18,3 +18,11 @@ import './projection_spec';
import './query_spec';
import './source_map_spec';
import './jit_summaries_spec';

import * as ts from 'typescript';

const [major, minor] = ts.version.split('.');

if (+major < 2 || (+major === 2 && +minor < 3)) {
throw new Error('Must use TypeScript > 2.3 to have transformer support');
}
11 changes: 2 additions & 9 deletions packages/compiler-cli/integrationtest/test/basic_spec.ts
Expand Up @@ -12,7 +12,6 @@ import * as path from 'path';
import {MultipleComponentsMyComp} from '../src/a/multiple_components';
import {BasicComp} from '../src/basic';
import {createComponent} from './util';
import {createComponentAlt} from './util_alt';

describe('template codegen output', () => {
const outDir = 'src';
Expand All @@ -37,9 +36,9 @@ describe('template codegen output', () => {
expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic');
});

it('should write .ngfactory.ts for .d.ts inputs', () => {
it('should write .ngfactory.js for .d.ts inputs', () => {
const factoryOutput =
path.join('node_modules', '@angular2-material', 'button', 'button.ngfactory.ts');
path.join('node_modules', '@angular2-material', 'button', 'button.ngfactory.js');
expect(fs.existsSync(factoryOutput)).toBeTruthy();
});

Expand Down Expand Up @@ -95,11 +94,5 @@ describe('template codegen output', () => {
expect(containerElement.attributes['title']).toBe('käännä teksti');
expect(containerElement.attributes['i18n-title']).toBeUndefined();
});

it('should have removed i18n markup event without translations', () => {
const containerElement = createComponentAlt(BasicComp).debugElement.children[0];
expect(containerElement.attributes['title']).toBe('translate me');
expect(containerElement.attributes['i18n-title']).toBeUndefined();
});
});
});
Expand Up @@ -10,7 +10,8 @@ import './init';
import {BindingErrorComp} from '../src/errors';
import {createComponent} from './util';

describe('source maps', () => {
// source maps does not currently work with the transformer pipeline
xdescribe('source maps', () => {
it('should report source location for binding errors', () => {
const comp = createComponent(BindingErrorComp);
let error: any;
Expand Down
33 changes: 0 additions & 33 deletions packages/compiler-cli/integrationtest/test/util_alt.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/compiler-cli/integrationtest/tsconfig-build-alt.json

This file was deleted.

4 changes: 3 additions & 1 deletion packages/compiler-cli/integrationtest/tsconfig-build.json
Expand Up @@ -5,7 +5,9 @@
"genDir": ".",
"debug": true,
"enableSummariesForJit": true,
"alwaysCompileGeneratedCode": true
"alwaysCompileGeneratedCode": true,
"locale": "fi",
"i18nFormat": "xlf"
},

"compilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"typings": "index.d.ts",
"bin": {
"ngc": "./src/main2.js",
"ngc": "./src/main.js",
"ng-xi18n": "./src/extract_i18n.js"
},
"dependencies": {
Expand Down
23 changes: 21 additions & 2 deletions packages/compiler-cli/src/main.ts
Expand Up @@ -12,8 +12,14 @@ import 'reflect-metadata';

import * as ts from 'typescript';
import * as tsc from '@angular/tsc-wrapped';
import * as fs from 'fs';
import * as path from 'path';
import * as ngc from './ngc';

import {isSyntaxError} from '@angular/compiler';

import {readConfiguration} from './perform-compile';

import {CodeGenerator} from './codegen';

function codegen(
Expand Down Expand Up @@ -45,6 +51,19 @@ export function main(

// CLI entry point
if (require.main === module) {
const args = require('minimist')(process.argv.slice(2));
main(args).then((exitCode: number) => process.exit(exitCode));
const args = process.argv.slice(2);
const parsedArgs = require('minimist')(args);
const project = parsedArgs.p || parsedArgs.project || '.';

const projectDir = fs.lstatSync(project).isFile() ? path.dirname(project) : project;

// file names in tsconfig are resolved relative to this absolute path
const basePath = path.resolve(process.cwd(), projectDir);
const {ngOptions} = readConfiguration(project, basePath);

if (ngOptions.disableTransformerPipeline) {
main(parsedArgs).then((exitCode: number) => process.exit(exitCode));
} else {
process.exit(ngc.main(args, s => console.error(s)));
}
}

0 comments on commit 8d3b6d7

Please sign in to comment.