Skip to content

Commit

Permalink
fix(package): improved the build process of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed Dec 22, 2019
1 parent 47debd1 commit 5c26591
Show file tree
Hide file tree
Showing 31 changed files with 1,130 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
{
"name": "@angular-material-extensions/google-maps-autocomplete",
"version": "0.0.1",
"description": "Autocomplete input component for google-maps built with angular material design",
"version": "2.0.0",
"homepage": "https://github.com/angular-material-extensions/google-maps-autocomplete",
"author": {
"name": "Anthony Nahas",
"url": "https://github.com/angular-material-extensions"
},
"repository": {
"type": "git",
"url": "git://github.com/angular-material-extensions/google-maps-autocomplete.git"
},
"license": "MIT",
"schematics": "./schematics/collection.json",
"keywords": [
"angular",
"material design",
"google maps",
"autocomplete",
"places",
"locations"
],
"bugs": {
"url": "https://github.com/angular-material-extensions/google-maps-autocomplete/issues"
},
"scripts": {
"build": "../../../node_modules/.bin/ng build @angular-material-extensions/google-maps-autocomplete",
"build:schematics": "../../../node_modules/.bin/tsc -p tsconfig.schematics.json",
"clean": "rm -rf ../../../dist",
"lint": "../../../node_modules/.bin/ng lint @angular-material-extensions/google-maps-autocomplete",
"resync:schematics": "rsync -a schematics/collection.json ../../../dist/angular-material-extensions/google-maps-autocomplete/schematics/",
"resync:readme": "rsync -a ../../../README.md ../../../dist/angular-material-extensions/google-maps-autocomplete/",
"postbuild": "npm run build:schematics && npm run resync:readme && npm run resync:schematics",
"prepublish": "npm run build",
"release:patch": "../../../node_modules/.bin/release-it --patch --ci",
"release:minor": "../../../node_modules/.bin/release-it --minor --ci",
"release:major": "../../../node_modules/.bin/release-it --major --ci",
"ng:test": "../../../node_modules/.bin/ng test @angular-material-extensions/google-maps-autocomplete",
"test": "../../../node_modules/.bin/jest --coverage",
"test:watch": "../../../node_modules/.bin/jest --coverage --watch"
},
"peerDependencies": {
"@angular/common": "^8.2.14",
"@angular/core": "^8.2.14",
Expand All @@ -10,5 +49,51 @@
"@agm/core": "^1.1.0",
"@types/googlemaps": "^3.38.0",
"zone.js": "~0.9.1"
},
"engines": {
"node": ">=10.0.0"
},
"release-it": {
"github": {
"release": true
},
"npm": {
"publish": true,
"publishPath": "../../../dist/angular-material-extensions/google-maps-autocomplete"
},
"publishConfig": {
"access": "public"
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "angular",
"infile": "../../../CHANGELOG.md"
}
},
"hooks": {
"before:init": [
"npm run clean"
],
"after:bump": "echo \"building lib v${version}... \" && npm run build",
"before:git:release": "echo \"Updating CHANGELOG.md for v${version} \" && git commit -m \"Updating CHANGELOG.md for v${version} \" ../../../CHANGELOG.md",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}.",
"before:npm": "echo building the library..."
}
},
"jest": {
"preset": "jest-preset-angular",
"setupFilesAfterEnv": [
"<rootDir>/../../../src/setup-jest.ts"
]
},
"globals": {
"ts-jest": {
"tsConfig": "<rootDir>/tsconfig.spec.json",
"stringifyContentPathRegex": "\\.html$",
"astTransformers": [
"jest-preset-angular/build/InlineFilesTransformer",
"jest-preset-angular/build/StripStylesTransformer"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"ng-add": {
"description": "Installs and injects the @angular-material-extensions/google-maps-autocomplete library",
"factory": "./ng-add/index"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import {
insertImport as originalInsertImport,
findNodes as originalFindNodes,
findNode as originalFindNode,
getSourceNodes as originalGetSourceNodes,
insertAfterLastOccurrence as originalInsertAfterLastOccurrence,
getContentOfKeyLiteral as originalGetContentOfKeyLiteral,
getFirstNgModuleName as originalGetFirstNgModuleName,
getDecoratorMetadata as originalGetDecoratorMetadata,
getMetadataField as originalGetMetadataField,
getRouterModuleDeclaration as originalGetRouterModuleDeclaration,
addSymbolToNgModuleMetadata as originalAddSymbolToNgModuleMetadata,
addDeclarationToModule as originalAddDeclarationToModule,
addImportToModule as originalAddImportToModule,
addProviderToModule as originalAddProviderToModule,
addExportToModule as originalAddExportToModule,
addBootstrapToModule as originalAddBootstrapToModule,
addEntryComponentToModule as originalAddEntryComponentToModule,
addRouteDeclarationToModule as originalAddRouteDeclarationToModule,
isImported as originalIsImported
} from '@schematics/angular/utility/ast-utils';
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';

import { Change } from './change';

/**
* Add Import `import { symbolName } from fileName` if the import doesn't exit
* already. Assumes fileToEdit can be resolved and accessed.
* @param fileToEdit (file we want to add import to)
* @param symbolName (item to import)
* @param fileName (path to the file)
* @param isDefault (if true, import follows style for importing default exports)
* @return Change
*/
export function insertImport(
source: ts.SourceFile,
fileToEdit: string,
symbolName: string,
fileName: string,
isDefault = false
): Change {
return originalInsertImport(source, fileToEdit, symbolName, fileName, isDefault);
}

/**
* Find all nodes from the AST in the subtree of node of SyntaxKind kind.
* @param node
* @param kind
* @param max The maximum number of items to return.
* @param recursive Continue looking for nodes of kind recursive until end
* the last child even when node of kind has been found.
* @return all nodes of kind, or [] if none is found
*/
export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity, recursive = false): ts.Node[] {
return originalFindNodes(node, kind, max, recursive);
}

/**
* Get all the nodes from a source.
* @param sourceFile The source file object.
* @returns {Observable<ts.Node>} An observable of all the nodes in the source.
*/
export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
return originalGetSourceNodes(sourceFile);
}

export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {
return originalFindNode(node, kind, text);
}

/**
* Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
* or after the last of occurence of `syntaxKind` if the last occurence is a sub child
* of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
*
* @param nodes insert after the last occurence of nodes
* @param toInsert string to insert
* @param file file to insert changes into
* @param fallbackPos position to insert if toInsert happens to be the first occurence
* @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
* @return Change instance
* @throw Error if toInsert is first occurence but fall back is not set
*/
export function insertAfterLastOccurrence(
nodes: ts.Node[],
toInsert: string,
file: string,
fallbackPos: number,
syntaxKind?: ts.SyntaxKind
): Change {
return originalInsertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind);
}

export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
return originalGetContentOfKeyLiteral(_source, node);
}

export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[] {
return originalGetDecoratorMetadata(source, identifier, module);
}

/**
* Given a source file with @NgModule class(es), find the name of the first @NgModule class.
*
* @param source source file containing one or more @NgModule
* @returns the name of the first @NgModule, or `undefined` if none is found
*/
export function getFirstNgModuleName(source: ts.SourceFile): string | undefined {
return originalGetFirstNgModuleName(source);
}

export function getMetadataField(node: ts.ObjectLiteralExpression, metadataField: string): ts.ObjectLiteralElement[] {
return originalGetMetadataField(node, metadataField);
}

export function addSymbolToNgModuleMetadata(
source: ts.SourceFile,
ngModulePath: string,
metadataField: string,
symbolName: string,
importPath: string | null = null
): Change[] {
return originalAddSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath);
}

/**
* Custom function to insert a declaration (component, pipe, directive)
* into NgModule declarations. It also imports the component.
*/
export function addDeclarationToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddDeclarationToModule(source, modulePath, classifiedName, importPath);
}

/**
* Custom function to insert an NgModule into NgModule imports. It also imports the module.
*/
export function addImportToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddImportToModule(source, modulePath, classifiedName, importPath);
}

/**
* Custom function to insert a provider into NgModule. It also imports it.
*/
export function addProviderToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddProviderToModule(source, modulePath, classifiedName, importPath);
}

/**
* Custom function to insert an export into NgModule. It also imports it.
*/
export function addExportToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddExportToModule(source, modulePath, classifiedName, importPath);
}

/**
* Custom function to insert an export into NgModule. It also imports it.
*/
export function addBootstrapToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddBootstrapToModule(source, modulePath, classifiedName, importPath);
}

/**
* Custom function to insert an entryComponent into NgModule. It also imports it.
*/
export function addEntryComponentToModule(
source: ts.SourceFile,
modulePath: string,
classifiedName: string,
importPath: string
): Change[] {
return originalAddEntryComponentToModule(source, modulePath, classifiedName, importPath);
}

/**
* Determine if an import already exists.
*/
export function isImported(source: ts.SourceFile, classifiedName: string, importPath: string): boolean {
return originalIsImported(source, classifiedName, importPath);
}

/**
* Returns the RouterModule declaration from NgModule metadata, if any.
*/
export function getRouterModuleDeclaration(source: ts.SourceFile): ts.Expression | undefined {
return originalGetRouterModuleDeclaration(source);
}

/**
* Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
*/
export function addRouteDeclarationToModule(source: ts.SourceFile, fileToAdd: string, routeLiteral: string): Change {
return originalAddRouteDeclarationToModule(source, fileToAdd, routeLiteral);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Host as OriginalHost,
Change as OriginalChange,
NoopChange as OriginalNoopChange,
InsertChange as OriginalInsertChange,
RemoveChange as OriginalRemoveChange,
ReplaceChange as OriginalReplaceChange
} from '@schematics/angular/utility/change';

export interface Host extends OriginalHost {}

export interface Change extends OriginalChange {}

/**
* An operation that does nothing.
*/
export class NoopChange extends OriginalNoopChange {}

/**
* Will add text to the source code.
*/
export class InsertChange extends OriginalInsertChange {}

/**
* Will remove text from the source code.
*/
export class RemoveChange extends OriginalRemoveChange {}

/**
* Will replace text from the source code.
*/
export class ReplaceChange extends OriginalReplaceChange {}

0 comments on commit 5c26591

Please sign in to comment.