Skip to content

Commit

Permalink
feat: move the geocoding control to a separate library (Wykks#300)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmytro Gokun <[email protected]>
  • Loading branch information
2 people authored and Nosfit committed Jun 22, 2021
1 parent eeebe55 commit 2f0eb3e
Show file tree
Hide file tree
Showing 22 changed files with 1,886 additions and 1,730 deletions.
38 changes: 38 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,44 @@
}
}
}
},
"ngx-mapbox-gl-geocoder-control": {
"projectType": "library",
"root": "projects/ngx-mapbox-gl-geocoder-control",
"sourceRoot": "projects/ngx-mapbox-gl-geocoder-control/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "projects/ngx-mapbox-gl-geocoder-control/tsconfig.lib.json",
"project": "projects/ngx-mapbox-gl-geocoder-control/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/ngx-mapbox-gl-geocoder-control/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ngx-mapbox-gl-geocoder-control/src/test.ts",
"tsConfig": "projects/ngx-mapbox-gl-geocoder-control/tsconfig.spec.json",
"karmaConfig": "projects/ngx-mapbox-gl-geocoder-control/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/ngx-mapbox-gl-geocoder-control/tsconfig.lib.json",
"projects/ngx-mapbox-gl-geocoder-control/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "ngx-mapbox-gl",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"@angular/platform-browser": "^11.2.5",
"@angular/platform-browser-dynamic": "^11.2.5",
"@angular/router": "^11.2.5",
"@mapbox/mapbox-gl-geocoder": "^4.0.0",
"@mapbox/mapbox-gl-geocoder": "^4.7.1",
"@ngrx/effects": "^11.0.1",
"@ngrx/router-store": "^11.0.1",
"@ngrx/store": "^11.0.1",
"@ngrx/store-devtools": "^11.0.1",
"@stackblitz/sdk": "^1.3.0",
"lodash-es": "^4.17.11",
"mapbox-gl": "2.0.1",
"mapbox-gl": "^2.3.1",
"ngx-markdown": "^11.1.3",
"rxjs": "^6.6.6",
"scroll-into-view-if-needed": "^2.2.20",
Expand All @@ -68,8 +68,8 @@
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "^2.0.6",
"@types/lodash-es": "^4.17.3",
"@types/mapbox-gl": "2.1.1",
"@types/mapbox__mapbox-gl-geocoder": "4.7.0",
"@types/mapbox-gl": "^2.3.0",
"angular-cli-ghpages": "^0.6.0",
"codelyzer": "^6.0.0",
"commitizen": "^4.0.3",
Expand Down
25 changes: 25 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# NgxMapboxGlGeocoderControl

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.2.4.

## Code scaffolding

Run `ng generate component component-name --project ngx-mapbox-gl-geocoder-control` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-mapbox-gl-geocoder-control`.

> Note: Don't forget to add `--project ngx-mapbox-gl-geocoder-control` or else it will be added to the default project in your `angular.json` file.
## Build

Run `ng build ngx-mapbox-gl-geocoder-control` to build the project. The build artifacts will be stored in the `dist/` directory.

## Publishing

After building your library with `ng build ngx-mapbox-gl-geocoder-control`, go to the dist folder `cd dist/ngx-mapbox-gl-geocoder-control` and run `npm publish`.

## Running unit tests

Run `ng test ngx-mapbox-gl-geocoder-control` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
44 changes: 44 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(
__dirname,
'../../coverage/ngx-mapbox-gl-geocoder-control'
),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }],
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};
8 changes: 8 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ngx-mapbox-gl-geocoder-control",
"deleteDestPath": false,
"lib": {
"entryFile": "src/public-api.ts"
}
}
8 changes: 8 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/ng-package.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ngx-mapbox-gl-geocoder-control",
"lib": {
"entryFile": "src/public-api.ts"
},
"whitelistedNonPeerDependencies": ["."]
}
14 changes: 14 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ngx-mapbox-gl-geocoder-control",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^11.2.4",
"@angular/core": "^11.2.4",
"mapbox-gl": "^2.3.1",
"ngx-mapbox-gl": "^6.0.0"
},
"dependencies": {
"@mapbox/mapbox-gl-geocoder": "^4.7.1",
"tslib": "^2.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EventEmitter,
Host,
Inject,
InjectionToken,
Input,
NgZone,
OnChanges,
Expand All @@ -18,15 +17,27 @@ import MapboxGeocoder, {
LngLatLiteral,
GeocoderOptions,
} from '@mapbox/mapbox-gl-geocoder';
import { MapService } from '../map/map.service';
import { GeocoderEvent } from '../map/map.types';
import { deprecationWarning } from '../utils';
import { ControlComponent } from './control.component';
import {
MapService,
deprecationWarning,
ControlComponent,
MAPBOX_GEOCODER_API_KEY,
} from 'ngx-mapbox-gl';
import { Map, Marker } from 'mapbox-gl';

export const MAPBOX_GEOCODER_API_KEY = new InjectionToken('MapboxApiKey');
export { Result, Results } from '@mapbox/mapbox-gl-geocoder';

export interface GeocoderEvent {
clear: EventEmitter<void>;
loading: EventEmitter<{ query: string }>;
results: EventEmitter<Results>;
result: EventEmitter<{ result: Result }>;
error: EventEmitter<any>;
geocoderResults: EventEmitter<Results>;
geocoderResult: EventEmitter<{ result: Result }>;
geocoderError: EventEmitter<any>;
}

@Directive({
selector: '[mglGeocoder]',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { NgxMapboxGLModule } from 'ngx-mapbox-gl';
import { GeocoderControlDirective } from './geocoder-control.directive';

@NgModule({
declarations: [GeocoderControlDirective],
imports: [NgxMapboxGLModule],
exports: [GeocoderControlDirective],
})
export class NgxMapboxGlGeocoderControlModule {}
6 changes: 6 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Public API Surface of ngx-mapbox-gl-geocoder-control
*/

export * from './lib/ngx-mapbox-gl-geocoder-control.module';
export * from './lib/geocoder-control.directive';
30 changes: 30 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';

declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
27 changes: 27 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"declarationMap": true,
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": ["node"],
"lib": ["dom", "es2015"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true,
"flatModuleId": "AUTOGENERATED",
"flatModuleOutFile": "AUTOGENERATED"
},
"exclude": ["src/test.ts", "**/*.spec.ts"]
}
10 changes: 10 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}
10 changes: 10 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine"]
},
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
7 changes: 7 additions & 0 deletions projects/ngx-mapbox-gl-geocoder-control/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [true, "attribute", "lib", "camelCase"],
"component-selector": [true, "element", "lib", "kebab-case"]
}
}
5 changes: 1 addition & 4 deletions projects/ngx-mapbox-gl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"peerDependencies": {
"@angular/common": ">= 9.0.0 < 12.0.0",
"@angular/core": ">= 9.0.0 < 12.0.0",
"mapbox-gl": "^2.0.1",
"mapbox-gl": "^2.3.1",
"rxjs": "^6.6.3"
},
"dependencies": {
"@mapbox/mapbox-gl-geocoder": "^4.0.0"
}
}
12 changes: 0 additions & 12 deletions projects/ngx-mapbox-gl/src/lib/map/map.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
MapTouchEvent,
MapWheelEvent,
} from 'mapbox-gl';
import { Results, Result } from '../control/geocoder-control.directive';

export interface MapEvent {
mapResize: EventEmitter<MapboxEvent & EventData>;
Expand Down Expand Up @@ -154,17 +153,6 @@ export interface LayerEvents {
touchCancel: EventEmitter<MapLayerTouchEvent & EventData>;
}

export interface GeocoderEvent {
clear: EventEmitter<void>;
loading: EventEmitter<{ query: string }>;
results: EventEmitter<Results>;
result: EventEmitter<{ result: Result }>;
error: EventEmitter<any>;
geocoderResults: EventEmitter<Results>;
geocoderResult: EventEmitter<{ result: Result }>;
geocoderError: EventEmitter<any>;
}

/**
* in typescript 4.1 DOM interface Position and Coordinates renamed to GeolocationPosition GeolocationCoordinates
* to avoid deprecation angular version < 11.0.0 we declared own Coordinates, Position interface
Expand Down
Loading

0 comments on commit 2f0eb3e

Please sign in to comment.