Skip to content

Commit 5c26591

Browse files
committed
fix(package): improved the build process of the library
1 parent 47debd1 commit 5c26591

31 files changed

+1130
-3
lines changed

projects/angular-material-extensions/google-maps-autocomplete/package.json

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
{
22
"name": "@angular-material-extensions/google-maps-autocomplete",
3-
"version": "0.0.1",
3+
"description": "Autocomplete input component for google-maps built with angular material design",
4+
"version": "2.0.0",
5+
"homepage": "https://github.com/angular-material-extensions/google-maps-autocomplete",
6+
"author": {
7+
"name": "Anthony Nahas",
8+
"url": "https://github.com/angular-material-extensions"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/angular-material-extensions/google-maps-autocomplete.git"
13+
},
14+
"license": "MIT",
15+
"schematics": "./schematics/collection.json",
16+
"keywords": [
17+
"angular",
18+
"material design",
19+
"google maps",
20+
"autocomplete",
21+
"places",
22+
"locations"
23+
],
24+
"bugs": {
25+
"url": "https://github.com/angular-material-extensions/google-maps-autocomplete/issues"
26+
},
27+
"scripts": {
28+
"build": "../../../node_modules/.bin/ng build @angular-material-extensions/google-maps-autocomplete",
29+
"build:schematics": "../../../node_modules/.bin/tsc -p tsconfig.schematics.json",
30+
"clean": "rm -rf ../../../dist",
31+
"lint": "../../../node_modules/.bin/ng lint @angular-material-extensions/google-maps-autocomplete",
32+
"resync:schematics": "rsync -a schematics/collection.json ../../../dist/angular-material-extensions/google-maps-autocomplete/schematics/",
33+
"resync:readme": "rsync -a ../../../README.md ../../../dist/angular-material-extensions/google-maps-autocomplete/",
34+
"postbuild": "npm run build:schematics && npm run resync:readme && npm run resync:schematics",
35+
"prepublish": "npm run build",
36+
"release:patch": "../../../node_modules/.bin/release-it --patch --ci",
37+
"release:minor": "../../../node_modules/.bin/release-it --minor --ci",
38+
"release:major": "../../../node_modules/.bin/release-it --major --ci",
39+
"ng:test": "../../../node_modules/.bin/ng test @angular-material-extensions/google-maps-autocomplete",
40+
"test": "../../../node_modules/.bin/jest --coverage",
41+
"test:watch": "../../../node_modules/.bin/jest --coverage --watch"
42+
},
443
"peerDependencies": {
544
"@angular/common": "^8.2.14",
645
"@angular/core": "^8.2.14",
@@ -10,5 +49,51 @@
1049
"@agm/core": "^1.1.0",
1150
"@types/googlemaps": "^3.38.0",
1251
"zone.js": "~0.9.1"
52+
},
53+
"engines": {
54+
"node": ">=10.0.0"
55+
},
56+
"release-it": {
57+
"github": {
58+
"release": true
59+
},
60+
"npm": {
61+
"publish": true,
62+
"publishPath": "../../../dist/angular-material-extensions/google-maps-autocomplete"
63+
},
64+
"publishConfig": {
65+
"access": "public"
66+
},
67+
"plugins": {
68+
"@release-it/conventional-changelog": {
69+
"preset": "angular",
70+
"infile": "../../../CHANGELOG.md"
71+
}
72+
},
73+
"hooks": {
74+
"before:init": [
75+
"npm run clean"
76+
],
77+
"after:bump": "echo \"building lib v${version}... \" && npm run build",
78+
"before:git:release": "echo \"Updating CHANGELOG.md for v${version} \" && git commit -m \"Updating CHANGELOG.md for v${version} \" ../../../CHANGELOG.md",
79+
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}.",
80+
"before:npm": "echo building the library..."
81+
}
82+
},
83+
"jest": {
84+
"preset": "jest-preset-angular",
85+
"setupFilesAfterEnv": [
86+
"<rootDir>/../../../src/setup-jest.ts"
87+
]
88+
},
89+
"globals": {
90+
"ts-jest": {
91+
"tsConfig": "<rootDir>/tsconfig.spec.json",
92+
"stringifyContentPathRegex": "\\.html$",
93+
"astTransformers": [
94+
"jest-preset-angular/build/InlineFilesTransformer",
95+
"jest-preset-angular/build/StripStylesTransformer"
96+
]
97+
}
1398
}
1499
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "../../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {
4+
"ng-add": {
5+
"description": "Installs and injects the @angular-material-extensions/google-maps-autocomplete library",
6+
"factory": "./ng-add/index"
7+
}
8+
}
9+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import {
2+
insertImport as originalInsertImport,
3+
findNodes as originalFindNodes,
4+
findNode as originalFindNode,
5+
getSourceNodes as originalGetSourceNodes,
6+
insertAfterLastOccurrence as originalInsertAfterLastOccurrence,
7+
getContentOfKeyLiteral as originalGetContentOfKeyLiteral,
8+
getFirstNgModuleName as originalGetFirstNgModuleName,
9+
getDecoratorMetadata as originalGetDecoratorMetadata,
10+
getMetadataField as originalGetMetadataField,
11+
getRouterModuleDeclaration as originalGetRouterModuleDeclaration,
12+
addSymbolToNgModuleMetadata as originalAddSymbolToNgModuleMetadata,
13+
addDeclarationToModule as originalAddDeclarationToModule,
14+
addImportToModule as originalAddImportToModule,
15+
addProviderToModule as originalAddProviderToModule,
16+
addExportToModule as originalAddExportToModule,
17+
addBootstrapToModule as originalAddBootstrapToModule,
18+
addEntryComponentToModule as originalAddEntryComponentToModule,
19+
addRouteDeclarationToModule as originalAddRouteDeclarationToModule,
20+
isImported as originalIsImported
21+
} from '@schematics/angular/utility/ast-utils';
22+
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
23+
24+
import { Change } from './change';
25+
26+
/**
27+
* Add Import `import { symbolName } from fileName` if the import doesn't exit
28+
* already. Assumes fileToEdit can be resolved and accessed.
29+
* @param fileToEdit (file we want to add import to)
30+
* @param symbolName (item to import)
31+
* @param fileName (path to the file)
32+
* @param isDefault (if true, import follows style for importing default exports)
33+
* @return Change
34+
*/
35+
export function insertImport(
36+
source: ts.SourceFile,
37+
fileToEdit: string,
38+
symbolName: string,
39+
fileName: string,
40+
isDefault = false
41+
): Change {
42+
return originalInsertImport(source, fileToEdit, symbolName, fileName, isDefault);
43+
}
44+
45+
/**
46+
* Find all nodes from the AST in the subtree of node of SyntaxKind kind.
47+
* @param node
48+
* @param kind
49+
* @param max The maximum number of items to return.
50+
* @param recursive Continue looking for nodes of kind recursive until end
51+
* the last child even when node of kind has been found.
52+
* @return all nodes of kind, or [] if none is found
53+
*/
54+
export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity, recursive = false): ts.Node[] {
55+
return originalFindNodes(node, kind, max, recursive);
56+
}
57+
58+
/**
59+
* Get all the nodes from a source.
60+
* @param sourceFile The source file object.
61+
* @returns {Observable<ts.Node>} An observable of all the nodes in the source.
62+
*/
63+
export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
64+
return originalGetSourceNodes(sourceFile);
65+
}
66+
67+
export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {
68+
return originalFindNode(node, kind, text);
69+
}
70+
71+
/**
72+
* Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
73+
* or after the last of occurence of `syntaxKind` if the last occurence is a sub child
74+
* of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
75+
*
76+
* @param nodes insert after the last occurence of nodes
77+
* @param toInsert string to insert
78+
* @param file file to insert changes into
79+
* @param fallbackPos position to insert if toInsert happens to be the first occurence
80+
* @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
81+
* @return Change instance
82+
* @throw Error if toInsert is first occurence but fall back is not set
83+
*/
84+
export function insertAfterLastOccurrence(
85+
nodes: ts.Node[],
86+
toInsert: string,
87+
file: string,
88+
fallbackPos: number,
89+
syntaxKind?: ts.SyntaxKind
90+
): Change {
91+
return originalInsertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind);
92+
}
93+
94+
export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
95+
return originalGetContentOfKeyLiteral(_source, node);
96+
}
97+
98+
export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[] {
99+
return originalGetDecoratorMetadata(source, identifier, module);
100+
}
101+
102+
/**
103+
* Given a source file with @NgModule class(es), find the name of the first @NgModule class.
104+
*
105+
* @param source source file containing one or more @NgModule
106+
* @returns the name of the first @NgModule, or `undefined` if none is found
107+
*/
108+
export function getFirstNgModuleName(source: ts.SourceFile): string | undefined {
109+
return originalGetFirstNgModuleName(source);
110+
}
111+
112+
export function getMetadataField(node: ts.ObjectLiteralExpression, metadataField: string): ts.ObjectLiteralElement[] {
113+
return originalGetMetadataField(node, metadataField);
114+
}
115+
116+
export function addSymbolToNgModuleMetadata(
117+
source: ts.SourceFile,
118+
ngModulePath: string,
119+
metadataField: string,
120+
symbolName: string,
121+
importPath: string | null = null
122+
): Change[] {
123+
return originalAddSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath);
124+
}
125+
126+
/**
127+
* Custom function to insert a declaration (component, pipe, directive)
128+
* into NgModule declarations. It also imports the component.
129+
*/
130+
export function addDeclarationToModule(
131+
source: ts.SourceFile,
132+
modulePath: string,
133+
classifiedName: string,
134+
importPath: string
135+
): Change[] {
136+
return originalAddDeclarationToModule(source, modulePath, classifiedName, importPath);
137+
}
138+
139+
/**
140+
* Custom function to insert an NgModule into NgModule imports. It also imports the module.
141+
*/
142+
export function addImportToModule(
143+
source: ts.SourceFile,
144+
modulePath: string,
145+
classifiedName: string,
146+
importPath: string
147+
): Change[] {
148+
return originalAddImportToModule(source, modulePath, classifiedName, importPath);
149+
}
150+
151+
/**
152+
* Custom function to insert a provider into NgModule. It also imports it.
153+
*/
154+
export function addProviderToModule(
155+
source: ts.SourceFile,
156+
modulePath: string,
157+
classifiedName: string,
158+
importPath: string
159+
): Change[] {
160+
return originalAddProviderToModule(source, modulePath, classifiedName, importPath);
161+
}
162+
163+
/**
164+
* Custom function to insert an export into NgModule. It also imports it.
165+
*/
166+
export function addExportToModule(
167+
source: ts.SourceFile,
168+
modulePath: string,
169+
classifiedName: string,
170+
importPath: string
171+
): Change[] {
172+
return originalAddExportToModule(source, modulePath, classifiedName, importPath);
173+
}
174+
175+
/**
176+
* Custom function to insert an export into NgModule. It also imports it.
177+
*/
178+
export function addBootstrapToModule(
179+
source: ts.SourceFile,
180+
modulePath: string,
181+
classifiedName: string,
182+
importPath: string
183+
): Change[] {
184+
return originalAddBootstrapToModule(source, modulePath, classifiedName, importPath);
185+
}
186+
187+
/**
188+
* Custom function to insert an entryComponent into NgModule. It also imports it.
189+
*/
190+
export function addEntryComponentToModule(
191+
source: ts.SourceFile,
192+
modulePath: string,
193+
classifiedName: string,
194+
importPath: string
195+
): Change[] {
196+
return originalAddEntryComponentToModule(source, modulePath, classifiedName, importPath);
197+
}
198+
199+
/**
200+
* Determine if an import already exists.
201+
*/
202+
export function isImported(source: ts.SourceFile, classifiedName: string, importPath: string): boolean {
203+
return originalIsImported(source, classifiedName, importPath);
204+
}
205+
206+
/**
207+
* Returns the RouterModule declaration from NgModule metadata, if any.
208+
*/
209+
export function getRouterModuleDeclaration(source: ts.SourceFile): ts.Expression | undefined {
210+
return originalGetRouterModuleDeclaration(source);
211+
}
212+
213+
/**
214+
* Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
215+
*/
216+
export function addRouteDeclarationToModule(source: ts.SourceFile, fileToAdd: string, routeLiteral: string): Change {
217+
return originalAddRouteDeclarationToModule(source, fileToAdd, routeLiteral);
218+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {
2+
Host as OriginalHost,
3+
Change as OriginalChange,
4+
NoopChange as OriginalNoopChange,
5+
InsertChange as OriginalInsertChange,
6+
RemoveChange as OriginalRemoveChange,
7+
ReplaceChange as OriginalReplaceChange
8+
} from '@schematics/angular/utility/change';
9+
10+
export interface Host extends OriginalHost {}
11+
12+
export interface Change extends OriginalChange {}
13+
14+
/**
15+
* An operation that does nothing.
16+
*/
17+
export class NoopChange extends OriginalNoopChange {}
18+
19+
/**
20+
* Will add text to the source code.
21+
*/
22+
export class InsertChange extends OriginalInsertChange {}
23+
24+
/**
25+
* Will remove text from the source code.
26+
*/
27+
export class RemoveChange extends OriginalRemoveChange {}
28+
29+
/**
30+
* Will replace text from the source code.
31+
*/
32+
export class ReplaceChange extends OriginalReplaceChange {}

0 commit comments

Comments
 (0)