schematics-utilities
- Version 2.0.3
- Published
- 151 kB
- 7 dependencies
- MIT license
Install
npm i schematics-utilities
yarn add schematics-utilities
pnpm add schematics-utilities
Overview
🛠️ Useful exported utilities for working with Schematics
Index
Variables
Functions
- addBootstrapToModule()
- addDeclarationToModule()
- addEntryComponentToModule()
- addExportToModule()
- addImportToModule()
- addModuleImportToModule()
- addModuleImportToRootModule()
- addPackageJsonDependency()
- addPackageToPackageJson()
- addProjectToWorkspace()
- addProviderToModule()
- addRouteDeclarationToModule()
- addSymbolToNgModuleMetadata()
- appendHtmlElementToHead()
- appendPropertyInAstObject()
- appendValueInAstArray()
- applyLintFix()
- buildComponent()
- buildDefaultPath()
- buildRelativePath()
- findBootstrapModuleCall()
- findBootstrapModulePath()
- findModule()
- findModuleFromOptions()
- findNode()
- findNodes()
- findPropertyInAstObject()
- getAppFromConfig()
- getAppModulePath()
- getConfig()
- getContentOfKeyLiteral()
- getDecoratorMetadata()
- getFirstNgModuleName()
- getHtmlHeadTagElement()
- getMetadataField()
- getNpmPackageJson()
- getPackageJsonDependency()
- getProject()
- getProjectFromWorkspace()
- getProjectTargets()
- getRouterModuleDeclaration()
- getSourceFile()
- getSourceNodes()
- getWorkspace()
- getWorkspacePath()
- hasNgModuleImport()
- insertAfterLastOccurrence()
- insertImport()
- insertPropertyInAstObjectInOrder()
- isImported()
- isWorkspaceProject()
- isWorkspaceSchema()
- parseName()
- relativePathToWorkspaceRoot()
- removePackageJsonDependency()
- removePropertyInAstObject()
- targetBuildNotFoundError()
- updateWorkspace()
- validateHtmlSelector()
- validateName()
- validateProjectName()
Classes
Interfaces
Enums
Type Aliases
Variables
variable configPath
const configPath: string;
variable htmlSelectorRe
const htmlSelectorRe: RegExp;
variable latestVersions
const latestVersions: { Angular: string; RxJs: string; ZoneJs: string; TypeScript: string; TsLib: string; DevkitBuildAngular: string; DevkitBuildNgPackagr: string; DevkitBuildWebpack: string; AngularPWA: string; tsickle: string; ngPackagr: string;};
variable MODULE_EXT
const MODULE_EXT: string;
variable ROUTING_MODULE_EXT
const ROUTING_MODULE_EXT: string;
Functions
function addBootstrapToModule
addBootstrapToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert an export into NgModule. It also imports it.
function addDeclarationToModule
addDeclarationToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert a declaration (component, pipe, directive) into NgModule declarations. It also imports the component.
function addEntryComponentToModule
addEntryComponentToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert an entryComponent into NgModule. It also imports it.
function addExportToModule
addExportToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert an export into NgModule. It also imports it.
function addImportToModule
addImportToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert an NgModule into NgModule imports. It also imports the module.
function addModuleImportToModule
addModuleImportToModule: ( host: Tree, modulePath: string, moduleName: string, src: string) => void;
Import and add module to specific module path.
Parameter host
the tree we are updating
Parameter modulePath
src location of the module to import
Parameter moduleName
name of module to import
Parameter src
src location to import
function addModuleImportToRootModule
addModuleImportToRootModule: ( host: Tree, moduleName: string, src: string, project: WorkspaceProject) => void;
Import and add module to root app module.
function addPackageJsonDependency
addPackageJsonDependency: (tree: Tree, dependency: NodeDependency) => void;
function addPackageToPackageJson
addPackageToPackageJson: (host: Tree, pkg: string, version: string) => Tree;
Adds a package to the package.json in the given host tree.
function addProjectToWorkspace
addProjectToWorkspace: < TProjectType extends ProjectType = ProjectType.Application>( workspace: WorkspaceSchema, name: string, project: WorkspaceProject<TProjectType>) => Rule;
function addProviderToModule
addProviderToModule: ( source: ts.SourceFile, modulePath: string, classifiedName: string, importPath: string) => Change[];
Custom function to insert a provider into NgModule. It also imports it.
function addRouteDeclarationToModule
addRouteDeclarationToModule: ( source: ts.SourceFile, fileToAdd: string, routeLiteral: string) => Change;
Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
function addSymbolToNgModuleMetadata
addSymbolToNgModuleMetadata: ( source: ts.SourceFile, ngModulePath: string, metadataField: string, symbolName: string, importPath?: string | null) => Change[];
function appendHtmlElementToHead
appendHtmlElementToHead: ( host: Tree, htmlFilePath: string, elementHtml: string) => void;
Appends the given element HTML fragment to the
<head>
element of the specified HTML file.
function appendPropertyInAstObject
appendPropertyInAstObject: ( recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number) => void;
function appendValueInAstArray
appendValueInAstArray: ( recorder: UpdateRecorder, node: JsonAstArray, value: JsonValue, indent?: number) => void;
function applyLintFix
applyLintFix: (path?: string) => Rule;
function buildComponent
buildComponent: ( options: ComponentOptions, additionalFiles?: { [key: string]: string }) => Rule;
Rule that copies and interpolates the files that belong to this schematic context. Additionally a list of file paths can be passed to this rule in order to expose them inside the EJS template context.
This allows inlining the external template or stylesheet files in EJS without having to manually duplicate the file content.
function buildDefaultPath
buildDefaultPath: (project: WorkspaceProject) => string;
Build a default project path for generating.
Parameter project
The project to build the path for.
function buildRelativePath
buildRelativePath: (from: string, to: string) => string;
Build a relative path from one file path to another file path.
function findBootstrapModuleCall
findBootstrapModuleCall: ( host: Tree, mainPath: string) => ts.CallExpression | null;
function findBootstrapModulePath
findBootstrapModulePath: (host: Tree, mainPath: string) => string;
function findModule
findModule: ( host: Tree, generateDir: string, moduleExt?: string, routingModuleExt?: string) => Path;
Function to find the "closest" module to a generated file's path.
function findModuleFromOptions
findModuleFromOptions: (host: Tree, options: ModuleOptions) => Path | undefined;
Find the module referred by a set of options passed to the schematics.
function findNode
findNode: (node: ts.Node, kind: ts.SyntaxKind, text: string) => ts.Node | null;
function findNodes
findNodes: ( node: ts.Node, kind: ts.SyntaxKind, max?: number, recursive?: boolean) => ts.Node[];
Find all nodes from the AST in the subtree of node of SyntaxKind kind.
Parameter node
Parameter kind
Parameter max
The maximum number of items to return.
Parameter recursive
Continue looking for nodes of kind recursive until end the last child even when node of kind has been found. all nodes of kind, or [] if none is found
function findPropertyInAstObject
findPropertyInAstObject: ( node: JsonAstObject, propertyName: string) => JsonAstNode | null;
function getAppFromConfig
getAppFromConfig: ( config: CliConfig, appIndexOrName: string) => AppConfig | null;
function getAppModulePath
getAppModulePath: (host: Tree, mainPath: string) => string;
function getConfig
getConfig: (host: Tree) => CliConfig;
function getContentOfKeyLiteral
getContentOfKeyLiteral: (_source: ts.SourceFile, node: ts.Node) => string | null;
function getDecoratorMetadata
getDecoratorMetadata: ( source: ts.SourceFile, identifier: string, module: string) => ts.Node[];
function getFirstNgModuleName
getFirstNgModuleName: (source: ts.SourceFile) => string | undefined;
Given a source file with class(es), find the name of the first class.
Parameter source
source file containing one or more
Returns
the name of the first @NgModule, or
undefined
if none is found
function getHtmlHeadTagElement
getHtmlHeadTagElement: (htmlContent: string) => DefaultTreeElement | null;
Parses the given HTML file and returns the head element if available.
function getMetadataField
getMetadataField: ( node: ts.ObjectLiteralExpression, metadataField: string) => ts.ObjectLiteralElement[];
function getNpmPackageJson
getNpmPackageJson: ( packageName: string, logger: logging.LoggerApi, options?: { registryUrl?: string; usingYarn?: boolean; verbose?: boolean }) => Observable<Partial<NpmRepositoryPackageJson>>;
Get the NPM repository's package.json for a package. This is p
Parameter packageName
The package name to fetch.
Parameter registryUrl
The NPM Registry URL to use.
Parameter logger
A logger instance to log debug information.
Returns
An observable that will put the pacakge.json content.
function getPackageJsonDependency
getPackageJsonDependency: (tree: Tree, name: string) => NodeDependency | null;
function getProject
getProject: <TProjectType extends ProjectType = ProjectType.Application>( workspaceOrHost: WorkspaceSchema | Tree, projectName: string) => WorkspaceProject<TProjectType>;
function getProjectFromWorkspace
getProjectFromWorkspace: ( workspace: WorkspaceSchema, projectName?: string) => any;
Finds the specified project configuration in the workspace. Throws an error if the project couldn't be found.
function getProjectTargets
getProjectTargets: { (project: WorkspaceProject): WorkspaceTargets; ( workspaceOrHost: any, projectName: string ): WorkspaceTargets<ProjectType.Application>;};
function getRouterModuleDeclaration
getRouterModuleDeclaration: (source: ts.SourceFile) => ts.Expression | undefined;
Returns the RouterModule declaration from NgModule metadata, if any.
function getSourceFile
getSourceFile: (host: Tree, path: string) => typescript.SourceFile;
Reads file given path and returns TypeScript source file.
function getSourceNodes
getSourceNodes: (sourceFile: ts.SourceFile) => ts.Node[];
Get all the nodes from a source.
Parameter sourceFile
The source file object.
Returns
{Observable<ts.Node>} An observable of all the nodes in the source.
function getWorkspace
getWorkspace: (host: Tree) => WorkspaceSchema;
function getWorkspacePath
getWorkspacePath: (host: Tree) => string;
function hasNgModuleImport
hasNgModuleImport: ( tree: Tree, modulePath: string, className: string) => boolean;
Whether the Angular module in the given path imports the specified module class name.
function insertAfterLastOccurrence
insertAfterLastOccurrence: ( nodes: ts.Node[], toInsert: string, file: string, fallbackPos: number, syntaxKind?: ts.SyntaxKind) => Change;
Insert
toInsert
after the last occurence ofts.SyntaxKind[nodes[i].kind]
or after the last of occurence ofsyntaxKind
if the last occurence is a sub child of ts.SyntaxKind[nodes[i].kind] and save the changes in file.Parameter nodes
insert after the last occurence of nodes
Parameter toInsert
string to insert
Parameter file
file to insert changes into
Parameter fallbackPos
position to insert if toInsert happens to be the first occurence
Parameter syntaxKind
the ts.SyntaxKind of the subchildren to insert after Change instance Error if toInsert is first occurence but fall back is not set
function insertImport
insertImport: ( source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean) => Change;
Add Import
import { symbolName } from fileName
if the import doesn't exit already. Assumes fileToEdit can be resolved and accessed.Parameter fileToEdit
(file we want to add import to)
Parameter symbolName
(item to import)
Parameter fileName
(path to the file)
Parameter isDefault
(if true, import follows style for importing default exports) Change
function insertPropertyInAstObjectInOrder
insertPropertyInAstObjectInOrder: ( recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number) => void;
function isImported
isImported: ( source: ts.SourceFile, classifiedName: string, importPath: string) => boolean;
Determine if an import already exists.
function isWorkspaceProject
isWorkspaceProject: (project: any) => project is WorkspaceProject;
function isWorkspaceSchema
isWorkspaceSchema: (workspace: any) => workspace is WorkspaceSchema;
function parseName
parseName: (path: string, name: string) => Location;
function relativePathToWorkspaceRoot
relativePathToWorkspaceRoot: (projectRoot: string | undefined) => string;
function removePackageJsonDependency
removePackageJsonDependency: (tree: Tree, name: string) => void;
function removePropertyInAstObject
removePropertyInAstObject: ( recorder: UpdateRecorder, node: JsonAstObject, propertyName: string) => void;
function targetBuildNotFoundError
targetBuildNotFoundError: () => SchematicsException;
function updateWorkspace
updateWorkspace: (workspace: WorkspaceSchema) => Rule;
function validateHtmlSelector
validateHtmlSelector: (selector: string) => void;
function validateName
validateName: (name: string) => void;
function validateProjectName
validateProjectName: (projectName: string) => void;
Classes
class InsertChange
class InsertChange extends OriginalInsertChange {}
Will add text to the source code.
class NoopChange
class NoopChange extends OriginalNoopChange {}
An operation that does nothing.
class RemoveChange
class RemoveChange extends OriginalRemoveChange {}
Will remove text from the source code.
class ReplaceChange
class ReplaceChange extends OriginalReplaceChange {}
Will replace text from the source code.
Interfaces
interface AppConfig
interface AppConfig extends OriginalAppConfig {}
interface AppShellBuilderOptions
interface AppShellBuilderOptions {}
property browserTarget
browserTarget: string;
property route
route: string;
property serverTarget
serverTarget: string;
interface BrowserBuilderBaseOptions
interface BrowserBuilderBaseOptions {}
property assets
assets?: (object | string)[];
property fileReplacements
fileReplacements?: FileReplacements[];
property index
index?: string;
property main
main: string;
property outputPath
outputPath?: string;
property polyfills
polyfills: string;
property scripts
scripts?: (object | string)[];
property sourceMap
sourceMap?: boolean;
property styles
styles?: (object | string)[];
property tsConfig
tsConfig: string;
interface BrowserBuilderOptions
interface BrowserBuilderOptions extends BrowserBuilderBaseOptions {}
property aot
aot?: boolean;
property budgets
budgets?: { type: string; maximumWarning?: string; maximumError?: string;}[];
property buildOptimizer
buildOptimizer?: boolean;
property es5BrowserSupport
es5BrowserSupport?: boolean;
property extractCss
extractCss?: boolean;
property extractLicenses
extractLicenses?: boolean;
property namedChunks
namedChunks?: boolean;
property ngswConfigPath
ngswConfigPath?: string;
property optimization
optimization?: boolean;
property outputHashing
outputHashing?: 'all';
property resourcesOutputPath
resourcesOutputPath?: string;
property serviceWorker
serviceWorker?: boolean;
property vendorChunk
vendorChunk?: boolean;
property webWorkerTsConfig
webWorkerTsConfig?: string;
interface BuilderTarget
interface BuilderTarget<TBuilder extends Builders, TOptions> {}
property builder
builder: TBuilder;
property configurations
configurations?: { production: Partial<TOptions>; [key: string]: Partial<TOptions>;};
property options
options: TOptions;
interface Change
interface Change extends OriginalChange {}
interface CliConfig
interface CliConfig extends OriginalCliConfig {}
interface E2EOptions
interface E2EOptions {}
property devServerTarget
devServerTarget: string;
property protractorConfig
protractorConfig: string;
interface ExtractI18nOptions
interface ExtractI18nOptions {}
property browserTarget
browserTarget: string;
interface FileReplacements
interface FileReplacements {}
interface Host
interface Host extends OriginalHost {}
interface LibraryBuilderOptions
interface LibraryBuilderOptions {}
interface LintBuilderOptions
interface LintBuilderOptions {}
interface Location
interface Location extends OriginalLocation {}
interface ModuleOptions
interface ModuleOptions extends OriginalModuleOptions {}
interface NodeDependency
interface NodeDependency extends OriginalNodeDependency {}
interface NpmRepositoryPackageJson
interface NpmRepositoryPackageJson extends OriginalNpmRepositoryPackageJson {}
interface Schema
interface Schema {}
Copyright Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at https://angular.io/license
property changeDetection
changeDetection?: 'Default' | 'OnPush';
Specifies the change detection strategy.
property entryComponent
entryComponent?: boolean;
Specifies if the component is an entry component of declaring module.
property export
export?: boolean;
Specifies if declaring module exports the component.
property flat
flat?: boolean;
Flag to indicate if a dir is created.
property inlineStyle
inlineStyle?: boolean;
Specifies if the style will be in the ts file.
property inlineTemplate
inlineTemplate?: boolean;
Specifies if the template will be in the ts file.
property lintFix
lintFix?: boolean;
Specifies whether to apply lint fixes after generating the component.
property module
module?: string;
Allows specification of the declaring module.
property name
name: string;
The name of the component.
property path
path?: string;
The path to create the component.
property prefix
prefix?: string;
The prefix to apply to generated selectors.
property project
project?: string;
The name of the project.
property selector
selector?: string;
The selector to use for the component.
property skipImport
skipImport?: boolean;
Flag to skip the module import.
property spec
spec?: boolean;
Specifies if a spec file is generated.
property styleext
styleext?: string;
The file extension to be used for style files.
property viewEncapsulation
viewEncapsulation?: 'Emulated' | 'Native' | 'None';
Specifies the view encapsulation strategy.
interface ServeBuilderOptions
interface ServeBuilderOptions {}
property browserTarget
browserTarget: string;
interface ServerBuilderOptions
interface ServerBuilderOptions {}
property fileReplacements
fileReplacements?: FileReplacements[];
property main
main: string;
property optimization
optimization?: { scripts?: boolean; styles?: boolean;};
property outputPath
outputPath: string;
property sourceMap
sourceMap?: boolean;
property tsConfig
tsConfig: string;
interface TestBuilderOptions
interface TestBuilderOptions extends Partial<BrowserBuilderBaseOptions> {}
property karmaConfig
karmaConfig: string;
interface WorkspaceProject
interface WorkspaceProject< TProjectType extends ProjectType = ProjectType.Application> extends experimental.workspace.WorkspaceProject {}
property architect
architect?: WorkspaceTargets<TProjectType>;
Tool options.
property projectType
projectType: ProjectType;
Project type.
property targets
targets?: WorkspaceTargets<TProjectType>;
Tool options.
interface WorkspaceSchema
interface WorkspaceSchema extends experimental.workspace.WorkspaceSchema {}
property projects
projects: { [key: string]: WorkspaceProject< ProjectType.Application | ProjectType.Library >;};
interface WorkspaceTargets
interface WorkspaceTargets< TProjectType extends ProjectType = ProjectType.Application> {}
property 'app-shell'
'app-shell'?: AppShellBuilderTarget;
property 'extract-i18n'
'extract-i18n'?: ExtractI18nBuilderTarget;
property build
build?: TProjectType extends ProjectType.Library ? LibraryBuilderTarget : BrowserBuilderTarget;
property e2e
e2e?: E2EBuilderTarget;
property lint
lint?: LintBuilderTarget;
property serve
serve?: ServeBuilderTarget;
property server
server?: ServerBuilderTarget;
property test
test?: TestBuilderTarget;
index signature
[key: string]: any;
Enums
enum Builders
enum Builders { AppShell = '@angular-devkit/build-angular:app-shell', Server = '@angular-devkit/build-angular:server', Browser = '@angular-devkit/build-angular:browser', Karma = '@angular-devkit/build-angular:karma', TsLint = '@angular-devkit/build-angular:tslint', NgPackagr = '@angular-devkit/build-ng-packagr:build', DevServer = '@angular-devkit/build-angular:dev-server', ExtractI18n = '@angular-devkit/build-angular:extract-i18n', Protractor = '@angular-devkit/build-angular:protractor',}
member AppShell
AppShell = '@angular-devkit/build-angular:app-shell'
member Browser
Browser = '@angular-devkit/build-angular:browser'
member DevServer
DevServer = '@angular-devkit/build-angular:dev-server'
member ExtractI18n
ExtractI18n = '@angular-devkit/build-angular:extract-i18n'
member Karma
Karma = '@angular-devkit/build-angular:karma'
member NgPackagr
NgPackagr = '@angular-devkit/build-ng-packagr:build'
member Protractor
Protractor = '@angular-devkit/build-angular:protractor'
member Server
Server = '@angular-devkit/build-angular:server'
member TsLint
TsLint = '@angular-devkit/build-angular:tslint'
enum NodeDependencyType
enum NodeDependencyType { Default = 'dependencies', Dev = 'devDependencies', Peer = 'peerDependencies', Optional = 'optionalDependencies',}
enum ProjectType
enum ProjectType { Application = 'application', Library = 'library',}
member Application
Application = 'application'
member Library
Library = 'library'
Type Aliases
type AppShellBuilderTarget
type AppShellBuilderTarget = BuilderTarget< Builders.AppShell, AppShellBuilderOptions>;
type BrowserBuilderTarget
type BrowserBuilderTarget = BuilderTarget<Builders.Browser, BrowserBuilderOptions>;
type E2EBuilderTarget
type E2EBuilderTarget = BuilderTarget<Builders.Protractor, E2EOptions>;
type ExtractI18nBuilderTarget
type ExtractI18nBuilderTarget = BuilderTarget< Builders.ExtractI18n, ExtractI18nOptions>;
type LibraryBuilderTarget
type LibraryBuilderTarget = BuilderTarget<Builders.NgPackagr, LibraryBuilderOptions>;
type LintBuilderTarget
type LintBuilderTarget = BuilderTarget<Builders.TsLint, LintBuilderOptions>;
type ServeBuilderTarget
type ServeBuilderTarget = BuilderTarget<Builders.DevServer, ServeBuilderOptions>;
type ServerBuilderTarget
type ServerBuilderTarget = BuilderTarget<Builders.Server, ServerBuilderOptions>;
type TestBuilderTarget
type TestBuilderTarget = BuilderTarget<Builders.Karma, TestBuilderOptions>;
Package Files (25)
- dist/angular/ast-utils.d.ts
- dist/angular/change.d.ts
- dist/angular/component-schema.d.ts
- dist/angular/config.d.ts
- dist/angular/dependencies.d.ts
- dist/angular/find-module.d.ts
- dist/angular/json-utils.d.ts
- dist/angular/latest-versions.d.ts
- dist/angular/lint-fix.d.ts
- dist/angular/ng-ast-utils.d.ts
- dist/angular/parse-name.d.ts
- dist/angular/paths.d.ts
- dist/angular/project-targets.d.ts
- dist/angular/project.d.ts
- dist/angular/validation.d.ts
- dist/angular/workspace-models.d.ts
- dist/index.d.ts
- dist/material/ast.d.ts
- dist/material/ast/ng-module-imports.d.ts
- dist/material/build-component.d.ts
- dist/material/get-project.d.ts
- dist/material/html-head-element.d.ts
- dist/material/package-config.d.ts
- dist/package_update/npm-package-json.d.ts
- dist/package_update/npm.d.ts
Dependencies (7)
Dev Dependencies (8)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/schematics-utilities
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/schematics-utilities)
- HTML<a href="https://www.jsdocs.io/package/schematics-utilities"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4687 ms. - Missing or incorrect documentation? Open an issue for this package.