Skip to content

chore: Angular 13 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

# dependencies
/node_modules
/packages/*/node_modules
package-lock.json
.npmrc

# IDEs and editors
/.idea
Expand Down Expand Up @@ -41,3 +43,5 @@ packages/angular/dist
# System Files
.DS_Store
Thumbs.db

.angular
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
# @nativescript/angular 12
# @nativescript/angular 12+

For usage with NativeScript for Angular 12+ projects.

Clean and setup workspace:

```
yarn clean.all
npm run clean.all
```

## Build packages:

```
npm run build
```

## Run demo:

```
npm run demo.ios
// or...
npm run demo.android
```

Build angular package:
## Clean/Reset demo dependencies

```
nx run angular:build
npm run demo.clean
```

Run angular demo:
## Unit tests for iOS and Android:

```
nx run nativescript-demo-ng:ios
npm run test.android
npm run test.ios
```
51 changes: 12 additions & 39 deletions apps/nativescript-demo-ng/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// const filePatterns = ['tests/test-main.ts','tests/**/*.ts', '**/*.spec.ts'];
const filePatterns = ['tests/test-main.ts', 'tests/**/*.ts'];
module.exports = function (config) {
const options = {
// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -9,8 +7,8 @@ module.exports = function (config) {
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'sinon'],

// list of files / patterns to load in the browser
files: filePatterns,
// list of files / patterns to load in the browser. Leave empty for webpack projects
// files: [],

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

// configure optional coverage, enable via --env.codeCoverage
coverageReporter: {
dir: require('path').join(__dirname, './coverage'),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }],
},

// web server port
port: 9876,

Expand Down Expand Up @@ -62,41 +67,9 @@ module.exports = function (config) {
singleRun: false,
};

setWebpackPreprocessor(config, options);
setWebpack(config, options);
if (config._NS && config._NS.env && config._NS.env.codeCoverage) {
options.reporters = (options.reporters || []).concat(['coverage']);
}

config.set(options);
};
module.exports.filePatterns = filePatterns;
// You can also use RegEx if you'd like:
// module.exports.filesRegex = /\.\/tests\/.*\.ts$/;

function setWebpackPreprocessor(config, options) {
if (config && config.bundle) {
if (!options.preprocessors) {
options.preprocessors = {};
}

options.files.forEach((file) => {
if (!options.preprocessors[file]) {
options.preprocessors[file] = [];
}
options.preprocessors[file].push('webpack');
});
}
}

function setWebpack(config, options) {
if (config && config.bundle) {
const env = {};
env[config.platform] = true;
env.sourceMap = config.debugBrk;
env.appPath = config.appPath;
env.karmaWebpack = true;
options.webpack = require('./webpack.config')(env);
delete options.webpack.entry;
delete options.webpack.output.libraryTarget;
const invalidPluginsForUnitTesting = ['GenerateBundleStarterPlugin', 'GenerateNativeScriptEntryPointsPlugin'];
options.webpack.plugins = options.webpack.plugins.filter((p) => !invalidPluginsForUnitTesting.includes(p.constructor.name));
}
}
3 changes: 3 additions & 0 deletions apps/nativescript-demo-ng/nativescript.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export default {
discardUncaughtJsExceptions: true,
},
appPath: 'src',
cli: {
packageManager: 'npm',
},
} as NativeScriptConfig;
9 changes: 5 additions & 4 deletions apps/nativescript-demo-ng/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
},
"dependencies": {
"@nativescript/angular": "file:../../packages/angular",
"@nativescript/core": "~8.1.0"
"@nativescript/core": "file:../../node_modules/@nativescript/core",
"@nativescript-community/ui-material-bottom-navigation": "^6.2.5"
},
"devDependencies": {
"@nativescript/android": "8.0.0",
"@nativescript/ios": "8.1.0",
"@nativescript/unit-test-runner": "^2.0.5"
"@nativescript/android": "~8.1.1",
"@nativescript/ios": "~8.1.0",
"@nativescript/unit-test-runner": "^3.0.1"
}
}
82 changes: 82 additions & 0 deletions apps/nativescript-demo-ng/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"root": "apps/nativescript-demo-ng/",
"sourceRoot": "apps/nativescript-demo-ng/src",
"projectType": "application",
"prefix": "nativescript",
"generators": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
"targets": {
"build": {
"executor": "@nativescript/nx:build",
"options": {
"noHmr": true,
"production": true,
"uglify": true,
"release": true,
"forDevice": true
},
"configurations": {
"prod": {
"fileReplacements": [
{
"replace": "./src/environments/environment.ts",
"with": "./src/environments/environment.prod.ts"
}
]
}
}
},
"ios": {
"executor": "@nativescript/nx:build",
"options": {
"platform": "ios"
},
"configurations": {
"build": {
"copyTo": "./dist/build.ipa"
},
"prod": {
"combineWithConfig": "build:prod"
}
}
},
"android": {
"executor": "@nativescript/nx:build",
"options": {
"platform": "android"
},
"configurations": {
"build": {
"copyTo": "./dist/build.apk"
},
"prod": {
"combineWithConfig": "build:prod"
}
}
},
"clean": {
"executor": "@nativescript/nx:build",
"options": {
"clean": true
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/nativescript-demo-ng/**/*.ts", "apps/nativescript-demo-ng/src/**/*.html"]
}
},
"test": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": ["ns test {args.platform}"],
"cwd": "apps/nativescript-demo-ng",
"parallel": false
}
}
},
"tags": []
}
34 changes: 30 additions & 4 deletions apps/nativescript-demo-ng/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
import { NgModule } from '@angular/core';
import { NativeScriptRouterModule } from '@nativescript/angular';
import { NativeScriptRouterModule, NSEmptyOutletComponent } from '@nativescript/angular';
import { Routes } from '@angular/router';

import { ItemsComponent } from './item/items.component';
import { ItemDetailComponent } from './item/item-detail.component';
// import { HomeComponent } from './home/home.component';
// import { BootGuardService } from './boot-guard.service';

const routes: Routes = [
{ path: '', redirectTo: '/items', pathMatch: 'full' },
{ path: '', redirectTo: '/rootlazy', pathMatch: 'full' },
{ path: 'items', component: ItemsComponent },
{ path: 'item/:id', component: ItemDetailComponent }
{ path: 'item/:id', component: ItemDetailComponent },
{ path: 'item2', loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module) },
{ path: 'rootlazy', loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module) },

/**
* Test tab named outlets
*/
// { path: '', redirectTo: '/home', pathMatch: 'full' },
// {
// path: 'home',
// component: HomeComponent,
// canActivate: [BootGuardService],
// children: [
// {
// path: 'start',
// component: NSEmptyOutletComponent,
// loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module),
// outlet: 'startTab',
// },
// ],
// },
// {
// path: 'item2',
// loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module),
// },
];

@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
exports: [NativeScriptRouterModule],
})
export class AppRoutingModule {}
46 changes: 23 additions & 23 deletions apps/nativescript-demo-ng/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { TestBed } from '@angular/core/testing';
import { NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
// import { TestBed } from '@angular/core/testing';
// import { NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
// import { AppRoutingModule } from './app-routing.module';
// import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [NativeScriptModule, NativeScriptCommonModule, AppRoutingModule],
providers: [],
});
return TestBed.compileComponents();
});
it('creates', function () {
const fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance).toBeTruthy();
});
// describe('AppComponent', () => {
// beforeEach(() => {
// TestBed.configureTestingModule({
// declarations: [AppComponent],
// imports: [NativeScriptModule, NativeScriptCommonModule, AppRoutingModule],
// providers: [],
// });
// return TestBed.compileComponents();
// });
// it('creates', function () {
// const fixture = TestBed.createComponent(AppComponent);
// expect(fixture.componentInstance).toBeTruthy();
// });

it('shows message', function () {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
expect(fixture.componentInstance.message).toEqual('Hello Angular!');
});
});
// it('shows message', function () {
// const fixture = TestBed.createComponent(AppComponent);
// fixture.detectChanges();
// expect(fixture.componentInstance.message).toEqual('Hello Angular!');
// });
// });
22 changes: 20 additions & 2 deletions apps/nativescript-demo-ng/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,28 @@ import { ItemsComponent } from './item/items.component';
import { ItemDetailComponent } from './item/item-detail.component';
import { ModalComponent } from './modal/modal.component';

/**
* To test tab named outlets, can uncomment imports and declarations
*/
// import { HomeComponent } from './home/home.component';
// import { NativeScriptMaterialBottomNavigationModule } from '@nativescript-community/ui-material-bottom-navigation/angular';

@NgModule({
bootstrap: [AppComponent],
imports: [NativeScriptModule, NativeScriptHttpClientModule, AppRoutingModule, NativeDialogModule],
declarations: [AppComponent, ItemsComponent, ItemDetailComponent, ModalComponent],
imports: [
NativeScriptModule,
NativeScriptHttpClientModule,
AppRoutingModule,
NativeDialogModule,
// NativeScriptMaterialBottomNavigationModule
],
declarations: [
AppComponent,
ItemsComponent,
ItemDetailComponent,
ModalComponent,
// HomeComponent
],
providers: [],
schemas: [NO_ERRORS_SCHEMA],
})
Expand Down
17 changes: 17 additions & 0 deletions apps/nativescript-demo-ng/src/app/boot-guard.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route, Router } from '@angular/router';

@Injectable({
providedIn: 'root',
})
export class BootGuardService implements CanActivate, CanLoad {
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
return new Promise((resolve) => {
resolve(true);
});
}

public canLoad(route: Route): Promise<boolean> {
return this.canActivate(null, null);
}
}
Loading