Skip to content

Commit d911e66

Browse files
committed
Add aot
1 parent b10562a commit d911e66

14 files changed

Lines changed: 163 additions & 34 deletions

angular.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
"index": "src/index.html",
2222
"main": "src/main.ts",
2323
"polyfills": "src/polyfills.ts",
24-
"tsConfig": "tsconfig.app.json",
24+
"tsConfig": "tsconfig.aot.json",
2525
"aot": false,
26-
"assets": ["src/favicon.ico", "src/assets"],
27-
"styles": ["src/styles.scss"],
2826
"scripts": []
2927
},
3028
"configurations": {
@@ -83,8 +81,6 @@
8381
"polyfills": "src/polyfills.ts",
8482
"tsConfig": "tsconfig.spec.json",
8583
"karmaConfig": "karma.conf.js",
86-
"assets": ["src/favicon.ico", "src/assets"],
87-
"styles": ["src/styles.scss"],
8884
"scripts": []
8985
}
9086
},

main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require('zone.js/dist/zone-node');
2+
require('reflect-metadata');
3+
4+
window = {};
5+
6+
require('./runtime-es5');
7+
require('./polyfills-es5');
8+
require('./vendor-es5');
9+
require('./main-es5');

package-lock.json

Lines changed: 9 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
6-
"start": "npm run build-app && qode ./dist/src/main.js",
6+
"start": "npm run build-dev && qode ./dist/src/main.js",
7+
"start:prod": "qode ./dist/angular-nodegui/main.js",
78
"build": "ng build",
8-
"build-app": "ngc -p tsconfig.app.json",
9+
"build:prod": "ng build --aot",
10+
"build-dev": "ngc -p tsconfig.app.json",
11+
"build-ngtsc": "ngc -p tsconfig.ngtsc.json",
912
"test": "ng test",
1013
"lint": "ng lint",
1114
"e2e": "ng e2e"

src/app/app.component.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<window title="Angular app in window!">
2+
<view>
3+
<image
4+
[src]="'C:/temp/angular.png'"
5+
[aspectRatioMode]="aspectRatioMode"
6+
></image>
7+
<text [style.font-size.px]="45">Hello, {{ name }}</text>
8+
<checkbox [checked]="true"></checkbox>
9+
<checkbox [checked]="true" [enabled]="false"></checkbox>
10+
<button [style.background-color]="'green'" (clicked)="setName()">
11+
Green button
12+
</button>
13+
<linedit
14+
[text]="name"
15+
[placeholderText]="'Insert your name'"
16+
(textChanged)="textChanged($event)"
17+
></linedit>
18+
<progressbar [value]="40" [minimum]="0" [maximum]="100"></progressbar>
19+
<spinbox
20+
[prefix]="'aa'"
21+
[suffix]="'bb'"
22+
[singleStep]="10"
23+
[range]="{ minimum: 0, maximum: 50 }"
24+
[value]="20"
25+
>
26+
</spinbox>
27+
</view>
28+
</window>

src/app/app.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import { AspectRatioMode } from '@nodegui/nodegui';
2828
[singleStep]="10"
2929
[range]="{ minimum: 0, maximum: 50 }"
3030
[value]="20"
31-
></spinbox>
31+
>
32+
</spinbox>
3233
</view>
3334
</window>
3435
`
36+
// templateUrl: './app.component.html'
3537
})
3638
export class AppComponent {
3739
public name = 'World!';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import { ResourceLoader } from '@angular/compiler';
4+
5+
export class FileSystemResourceLoader extends ResourceLoader {
6+
resolve(url: string, baseUrl: string): string {
7+
// Angular assembles absolute URL's and prefixes them with //
8+
if (url.indexOf('/') !== 0) {
9+
// Resolve relative URL's based on the app root.
10+
return path.join(baseUrl, url);
11+
} else {
12+
return url;
13+
}
14+
}
15+
16+
get(url: string): Promise<string> {
17+
const appDir = path.join(__dirname);
18+
const templatePath = this.resolve(url, appDir);
19+
20+
return new Promise((resolve, reject) => {
21+
fs.readFile(templatePath, 'utf8', (err, data) => {
22+
if (err) {
23+
reject(err);
24+
} else {
25+
resolve(data);
26+
}
27+
});
28+
});
29+
}
30+
}

src/lib/platform-dynamic.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
COMPILER_OPTIONS,
3+
createPlatformFactory,
4+
Sanitizer
5+
} from '@angular/core';
6+
import { ɵplatformCoreDynamic as platformCoreDynamic } from '@angular/platform-browser-dynamic';
7+
import { DOCUMENT } from '@angular/common';
8+
import { ElementSchemaRegistry, ResourceLoader } from '@angular/compiler';
9+
10+
import { NodeguiElementSchemaRegistry } from './schema-registry';
11+
import { NodeguiSanitizer } from './sanitizer';
12+
// import { FileSystemResourceLoader } from './file-system-resource-loader';
13+
14+
export const platformNodeguiDynamic = createPlatformFactory(
15+
platformCoreDynamic,
16+
'NodeguiDynamic',
17+
[
18+
{ provide: DOCUMENT, useValue: {} },
19+
{ provide: Sanitizer, useClass: NodeguiSanitizer, deps: [] },
20+
{
21+
provide: COMPILER_OPTIONS,
22+
useValue: {
23+
providers: [
24+
{
25+
provide: ElementSchemaRegistry,
26+
useClass: NodeguiElementSchemaRegistry,
27+
deps: []
28+
}
29+
// {
30+
// provide: ResourceLoader,
31+
// useClass: FileSystemResourceLoader,
32+
// deps: []
33+
// }
34+
]
35+
},
36+
multi: true
37+
}
38+
]
39+
);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
22
COMPILER_OPTIONS,
3+
platformCore,
34
createPlatformFactory,
45
Sanitizer
56
} from '@angular/core';
6-
import { ɵplatformCoreDynamic as platformCoreDynamic } from '@angular/platform-browser-dynamic';
77
import { DOCUMENT } from '@angular/common';
88
import { ElementSchemaRegistry } from '@angular/compiler';
99

1010
import { NodeguiElementSchemaRegistry } from './schema-registry';
1111
import { NodeguiSanitizer } from './sanitizer';
1212

13-
export const platformNodeguiDynamic = createPlatformFactory(
14-
platformCoreDynamic,
15-
'NodeguiDynamic',
13+
export const platformNodeguiStatic = createPlatformFactory(
14+
platformCore,
15+
'NodeguiStatic',
1616
[
1717
{ provide: DOCUMENT, useValue: {} },
1818
{ provide: Sanitizer, useClass: NodeguiSanitizer, deps: [] },

src/main-aot.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import './lib/reflect';
2+
import 'zone.js/dist/zone-node';
3+
4+
import { enableProdMode } from '@angular/core';
5+
6+
import { AppModule } from './app/app.module';
7+
import { environment } from './environments/environment';
8+
import { platformNodeguiStatic } from './lib/platform-static';
9+
10+
if (environment.production) {
11+
enableProdMode();
12+
}
13+
14+
platformNodeguiStatic()
15+
.bootstrapModuleFactory(AppModule as any)
16+
.catch(err => console.error(err));

0 commit comments

Comments
 (0)