Skip to content

Commit f80842e

Browse files
authored
feat: Angular 13 (#42)
1 parent b3b715b commit f80842e

File tree

76 files changed

+1017
-11502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1017
-11502
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
# dependencies
99
/node_modules
10+
/packages/*/node_modules
1011
package-lock.json
12+
.npmrc
1113

1214
# IDEs and editors
1315
/.idea
@@ -41,3 +43,5 @@ packages/angular/dist
4143
# System Files
4244
.DS_Store
4345
Thumbs.db
46+
47+
.angular

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
# @nativescript/angular 12
1+
# @nativescript/angular 12+
2+
3+
For usage with NativeScript for Angular 12+ projects.
24

35
Clean and setup workspace:
46

57
```
6-
yarn clean.all
8+
npm run clean.all
9+
```
10+
11+
## Build packages:
12+
13+
```
14+
npm run build
15+
```
16+
17+
## Run demo:
18+
19+
```
20+
npm run demo.ios
21+
// or...
22+
npm run demo.android
723
```
824

9-
Build angular package:
25+
## Clean/Reset demo dependencies
1026

1127
```
12-
nx run angular:build
28+
npm run demo.clean
1329
```
1430

15-
Run angular demo:
31+
## Unit tests for iOS and Android:
1632

1733
```
18-
nx run nativescript-demo-ng:ios
34+
npm run test.android
35+
npm run test.ios
1936
```
Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// const filePatterns = ['tests/test-main.ts','tests/**/*.ts', '**/*.spec.ts'];
2-
const filePatterns = ['tests/test-main.ts', 'tests/**/*.ts'];
31
module.exports = function (config) {
42
const options = {
53
// base path that will be used to resolve all patterns (eg. files, exclude)
@@ -9,8 +7,8 @@ module.exports = function (config) {
97
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
108
frameworks: ['jasmine', 'sinon'],
119

12-
// list of files / patterns to load in the browser
13-
files: filePatterns,
10+
// list of files / patterns to load in the browser. Leave empty for webpack projects
11+
// files: [],
1412

1513
// list of files to exclude
1614
exclude: [],
@@ -24,6 +22,13 @@ module.exports = function (config) {
2422
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
2523
reporters: ['mocha'],
2624

25+
// configure optional coverage, enable via --env.codeCoverage
26+
coverageReporter: {
27+
dir: require('path').join(__dirname, './coverage'),
28+
subdir: '.',
29+
reporters: [{ type: 'html' }, { type: 'text-summary' }],
30+
},
31+
2732
// web server port
2833
port: 9876,
2934

@@ -62,41 +67,9 @@ module.exports = function (config) {
6267
singleRun: false,
6368
};
6469

65-
setWebpackPreprocessor(config, options);
66-
setWebpack(config, options);
70+
if (config._NS && config._NS.env && config._NS.env.codeCoverage) {
71+
options.reporters = (options.reporters || []).concat(['coverage']);
72+
}
6773

6874
config.set(options);
6975
};
70-
module.exports.filePatterns = filePatterns;
71-
// You can also use RegEx if you'd like:
72-
// module.exports.filesRegex = /\.\/tests\/.*\.ts$/;
73-
74-
function setWebpackPreprocessor(config, options) {
75-
if (config && config.bundle) {
76-
if (!options.preprocessors) {
77-
options.preprocessors = {};
78-
}
79-
80-
options.files.forEach((file) => {
81-
if (!options.preprocessors[file]) {
82-
options.preprocessors[file] = [];
83-
}
84-
options.preprocessors[file].push('webpack');
85-
});
86-
}
87-
}
88-
89-
function setWebpack(config, options) {
90-
if (config && config.bundle) {
91-
const env = {};
92-
env[config.platform] = true;
93-
env.sourceMap = config.debugBrk;
94-
env.appPath = config.appPath;
95-
env.karmaWebpack = true;
96-
options.webpack = require('./webpack.config')(env);
97-
delete options.webpack.entry;
98-
delete options.webpack.output.libraryTarget;
99-
const invalidPluginsForUnitTesting = ['GenerateBundleStarterPlugin', 'GenerateNativeScriptEntryPointsPlugin'];
100-
options.webpack.plugins = options.webpack.plugins.filter((p) => !invalidPluginsForUnitTesting.includes(p.constructor.name));
101-
}
102-
}

apps/nativescript-demo-ng/nativescript.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ export default {
1414
discardUncaughtJsExceptions: true,
1515
},
1616
appPath: 'src',
17+
cli: {
18+
packageManager: 'npm',
19+
},
1720
} as NativeScriptConfig;

apps/nativescript-demo-ng/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
},
88
"dependencies": {
99
"@nativescript/angular": "file:../../packages/angular",
10-
"@nativescript/core": "~8.1.0"
10+
"@nativescript/core": "file:../../node_modules/@nativescript/core",
11+
"@nativescript-community/ui-material-bottom-navigation": "^6.2.5"
1112
},
1213
"devDependencies": {
13-
"@nativescript/android": "8.0.0",
14-
"@nativescript/ios": "8.1.0",
15-
"@nativescript/unit-test-runner": "^2.0.5"
14+
"@nativescript/android": "~8.1.1",
15+
"@nativescript/ios": "~8.1.0",
16+
"@nativescript/unit-test-runner": "^3.0.1"
1617
}
1718
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"root": "apps/nativescript-demo-ng/",
3+
"sourceRoot": "apps/nativescript-demo-ng/src",
4+
"projectType": "application",
5+
"prefix": "nativescript",
6+
"generators": {
7+
"@schematics/angular:component": {
8+
"styleext": "scss"
9+
}
10+
},
11+
"targets": {
12+
"build": {
13+
"executor": "@nativescript/nx:build",
14+
"options": {
15+
"noHmr": true,
16+
"production": true,
17+
"uglify": true,
18+
"release": true,
19+
"forDevice": true
20+
},
21+
"configurations": {
22+
"prod": {
23+
"fileReplacements": [
24+
{
25+
"replace": "./src/environments/environment.ts",
26+
"with": "./src/environments/environment.prod.ts"
27+
}
28+
]
29+
}
30+
}
31+
},
32+
"ios": {
33+
"executor": "@nativescript/nx:build",
34+
"options": {
35+
"platform": "ios"
36+
},
37+
"configurations": {
38+
"build": {
39+
"copyTo": "./dist/build.ipa"
40+
},
41+
"prod": {
42+
"combineWithConfig": "build:prod"
43+
}
44+
}
45+
},
46+
"android": {
47+
"executor": "@nativescript/nx:build",
48+
"options": {
49+
"platform": "android"
50+
},
51+
"configurations": {
52+
"build": {
53+
"copyTo": "./dist/build.apk"
54+
},
55+
"prod": {
56+
"combineWithConfig": "build:prod"
57+
}
58+
}
59+
},
60+
"clean": {
61+
"executor": "@nativescript/nx:build",
62+
"options": {
63+
"clean": true
64+
}
65+
},
66+
"lint": {
67+
"executor": "@nrwl/linter:eslint",
68+
"options": {
69+
"lintFilePatterns": ["apps/nativescript-demo-ng/**/*.ts", "apps/nativescript-demo-ng/src/**/*.html"]
70+
}
71+
},
72+
"test": {
73+
"executor": "@nrwl/workspace:run-commands",
74+
"options": {
75+
"commands": ["ns test {args.platform}"],
76+
"cwd": "apps/nativescript-demo-ng",
77+
"parallel": false
78+
}
79+
}
80+
},
81+
"tags": []
82+
}
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
import { NgModule } from '@angular/core';
2-
import { NativeScriptRouterModule } from '@nativescript/angular';
2+
import { NativeScriptRouterModule, NSEmptyOutletComponent } from '@nativescript/angular';
33
import { Routes } from '@angular/router';
44

55
import { ItemsComponent } from './item/items.component';
66
import { ItemDetailComponent } from './item/item-detail.component';
7+
// import { HomeComponent } from './home/home.component';
8+
// import { BootGuardService } from './boot-guard.service';
79

810
const routes: Routes = [
9-
{ path: '', redirectTo: '/items', pathMatch: 'full' },
11+
{ path: '', redirectTo: '/rootlazy', pathMatch: 'full' },
1012
{ path: 'items', component: ItemsComponent },
11-
{ path: 'item/:id', component: ItemDetailComponent }
13+
{ path: 'item/:id', component: ItemDetailComponent },
14+
{ path: 'item2', loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module) },
15+
{ path: 'rootlazy', loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module) },
16+
17+
/**
18+
* Test tab named outlets
19+
*/
20+
// { path: '', redirectTo: '/home', pathMatch: 'full' },
21+
// {
22+
// path: 'home',
23+
// component: HomeComponent,
24+
// canActivate: [BootGuardService],
25+
// children: [
26+
// {
27+
// path: 'start',
28+
// component: NSEmptyOutletComponent,
29+
// loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module),
30+
// outlet: 'startTab',
31+
// },
32+
// ],
33+
// },
34+
// {
35+
// path: 'item2',
36+
// loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module),
37+
// },
1238
];
1339

1440
@NgModule({
1541
imports: [NativeScriptRouterModule.forRoot(routes)],
16-
exports: [NativeScriptRouterModule]
42+
exports: [NativeScriptRouterModule],
1743
})
1844
export class AppRoutingModule {}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { TestBed } from '@angular/core/testing';
2-
import { NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
3-
import { AppRoutingModule } from './app-routing.module';
4-
import { AppComponent } from './app.component';
1+
// import { TestBed } from '@angular/core/testing';
2+
// import { NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
3+
// import { AppRoutingModule } from './app-routing.module';
4+
// import { AppComponent } from './app.component';
55

6-
describe('AppComponent', () => {
7-
beforeEach(() => {
8-
TestBed.configureTestingModule({
9-
declarations: [AppComponent],
10-
imports: [NativeScriptModule, NativeScriptCommonModule, AppRoutingModule],
11-
providers: [],
12-
});
13-
return TestBed.compileComponents();
14-
});
15-
it('creates', function () {
16-
const fixture = TestBed.createComponent(AppComponent);
17-
expect(fixture.componentInstance).toBeTruthy();
18-
});
6+
// describe('AppComponent', () => {
7+
// beforeEach(() => {
8+
// TestBed.configureTestingModule({
9+
// declarations: [AppComponent],
10+
// imports: [NativeScriptModule, NativeScriptCommonModule, AppRoutingModule],
11+
// providers: [],
12+
// });
13+
// return TestBed.compileComponents();
14+
// });
15+
// it('creates', function () {
16+
// const fixture = TestBed.createComponent(AppComponent);
17+
// expect(fixture.componentInstance).toBeTruthy();
18+
// });
1919

20-
it('shows message', function () {
21-
const fixture = TestBed.createComponent(AppComponent);
22-
fixture.detectChanges();
23-
expect(fixture.componentInstance.message).toEqual('Hello Angular!');
24-
});
25-
});
20+
// it('shows message', function () {
21+
// const fixture = TestBed.createComponent(AppComponent);
22+
// fixture.detectChanges();
23+
// expect(fixture.componentInstance.message).toEqual('Hello Angular!');
24+
// });
25+
// });

apps/nativescript-demo-ng/src/app/app.module.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,28 @@ import { ItemsComponent } from './item/items.component';
77
import { ItemDetailComponent } from './item/item-detail.component';
88
import { ModalComponent } from './modal/modal.component';
99

10+
/**
11+
* To test tab named outlets, can uncomment imports and declarations
12+
*/
13+
// import { HomeComponent } from './home/home.component';
14+
// import { NativeScriptMaterialBottomNavigationModule } from '@nativescript-community/ui-material-bottom-navigation/angular';
15+
1016
@NgModule({
1117
bootstrap: [AppComponent],
12-
imports: [NativeScriptModule, NativeScriptHttpClientModule, AppRoutingModule, NativeDialogModule],
13-
declarations: [AppComponent, ItemsComponent, ItemDetailComponent, ModalComponent],
18+
imports: [
19+
NativeScriptModule,
20+
NativeScriptHttpClientModule,
21+
AppRoutingModule,
22+
NativeDialogModule,
23+
// NativeScriptMaterialBottomNavigationModule
24+
],
25+
declarations: [
26+
AppComponent,
27+
ItemsComponent,
28+
ItemDetailComponent,
29+
ModalComponent,
30+
// HomeComponent
31+
],
1432
providers: [],
1533
schemas: [NO_ERRORS_SCHEMA],
1634
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Injectable } from '@angular/core';
2+
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route, Router } from '@angular/router';
3+
4+
@Injectable({
5+
providedIn: 'root',
6+
})
7+
export class BootGuardService implements CanActivate, CanLoad {
8+
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
9+
return new Promise((resolve) => {
10+
resolve(true);
11+
});
12+
}
13+
14+
public canLoad(route: Route): Promise<boolean> {
15+
return this.canActivate(null, null);
16+
}
17+
}

0 commit comments

Comments
 (0)