@acoustic-content-sdk/schematics-utils

Helper library to implement schematics.

Usage no npm install needed!

<script type="module">
  import acousticContentSdkSchematicsUtils from 'https://cdn.skypack.dev/@acoustic-content-sdk/schematics-utils';
</script>

README

npm

API Documentation

Home > @acoustic-content-sdk/schematics-utils

schematics-utils package

Helper library to implement schematics.

Classes

Class Description
InsertChange Will add text to the source code.
NoopChange An operation that does nothing.
RemoveChange Will remove text from the source code.
ReplaceChange Will replace text from the source code.

Enumerations

Enumeration Description
Builders
DEP_TYPE
NodeDependencyType
ProjectType

Functions

Function Description
addBootstrapToModule(source, modulePath, classifiedName, importPath) Custom function to insert an export into NgModule. It also imports it.
addDeclarationToModule(source, modulePath, classifiedName, importPath) Custom function to insert a declaration (component, pipe, directive) into NgModule declarations. It also imports the component.
addEntryComponentToModule(source, modulePath, classifiedName, importPath) Custom function to insert an entryComponent into NgModule. It also imports it.
addExportToModule(source, modulePath, classifiedName, importPath) Custom function to insert an export into NgModule. It also imports it.
addImportsToModule(aFile, aModules, aHost) Changes the identified module by adding a couple of imports
addImportToModule(source, modulePath, classifiedName, importPath) Custom function to insert an NgModule into NgModule imports. It also imports the module.
addPackageJsonDependency(tree, dependency)
addProjectToWorkspace(workspace, name, project)
addProviderToModule(source, modulePath, classifiedName, importPath) Custom function to insert a provider into NgModule. It also imports it.
addRouteDeclarationToModule(source, fileToAdd, routeLiteral) Adds a new route declaration to a router module (i.e. has a RouterModule declaration)
addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath)
addToWchToolsDependencies(aDeps, aPkg)
assertHasTrailingSlash(aValue)
assertIsEmail(aValue, aName)
assertIsUrl(aValue, aName)
assertIsValidUserName(aValue, aName)
assertNotNull(aValue, aName)
assertParameter(aValue, aParameterName)
buildDefaultPath(project) Build a default project path for generating.
buildRelativePath(from, to) Build a relative path from one file path to another file path.
byIdentifier(aName)
byName(aText)
byText(aText)
byType(aType)
byTypeAndName(aType, aName)
canonicalizeJSON(aData)
changeSourceFile(aFile, aOp, aHost)
copyDir(aSrc, aDst, aHost, aLogger) Copies from source to target and overrides the target. But does not delete extra files
createLoggerService(context) Constructs the logger service on top of the context
createTransientTree(aRoot) Creates a transient copy of a tree
ensureTrailingSlash(aUrl)
findBootstrapModuleCall(host, mainPath)
findBootstrapModulePath(host, mainPath)
findDataDir(host, options)
findModule(host, generateDir, moduleExt, routingModuleExt) Function to find the "closest" module to a generated file's path.
findModuleFromOptions(host, options) Find the module referred by a set of options passed to the schematics.
findNode(node, kind, text)
findNodes(node, kind, max, recursive) Find all nodes from the AST in the subtree of node of SyntaxKind kind.
findPackageJson(aDir)
findProject(workspaceOrHost, options) Locates the workspace project, either from the configured project name, else falls back to the default project
findProjectName(workspaceOrHost, options) Locates the workspace project, either from the configured project name, else falls back to the default project
findSdkVersion(host)
findWchToolsOptions(host, options)
getAppFromConfig(config, appIndexOrName)
getAppModulePath(host, mainPath)
getConfig(host)
getContentOfKeyLiteral(_source, node)
getDecoratorMetadata(source, identifier, module)
getEnvironmentExportName(source) This function returns the name of the environment export whether this export is aliased or not. If the environment file is not imported, then it will return null.
getFirstNgModuleName(source) Given a source file with class(es), find the name of the first class.
getFolderForType(aType)
getMetadataField(node, metadataField)
getPackageJsonDependency(tree, name)
getPackageManager(aHost) Decodes the supported workspace from the host
getProject(workspaceOrHost, projectName)
getProjectTargets(project)
getProjectTargets(workspaceOrHost, projectName)
getRouterModuleDeclaration(source) Returns the RouterModule declaration from NgModule metadata, if any.
getSourceFile(host, path)
getSourceFileFromFileEntry(aEntry)
getSourceNodes(sourceFile) Get all the nodes from a source.
getWorkspace(host)
getWorkspacePath(host)
hasTrailingSlash(aUrl)
insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) 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 SyntaxKind[nodes[i].kind] and save the changes in file.
insertChanges(aChanges, aRecorder)
insertImport(source, fileToEdit, symbolName, fileName, isDefault) Add Import import { symbolName } from fileName if the import doesn't exit already. Assumes fileToEdit can be resolved and accessed.
insertLines(aSource, aInsert)
isImported(source, classifiedName, importPath) Determine if an import already exists.
isValidEmail(aValue)
isValidUrl(aValue)
isValidUserName(aValue)
isWorkspaceProject(project)
isWorkspaceSchema(workspace)
locatePackageJson(aDir) Locates the name of the package.json starting with the current directory
parseLines(aSource)
parseName(path, name)
readBufferOnTree(aHost, aRoot) Constructs the ReadBuffer callback on top of a host
readDirectoryOnTree(aHost, aRoot) Creates a function callback that reads files from a host
readRelativeDirectoryOnTree(aHost, aRoot) Creates a function callback that reads files from a host
readTextFileOnTree(aHost, aRoot) Constructs the ReadTextFile callback on top of a host
readWorkspace(aRoot) Reads a workspace definition based on a root path
removePackageJsonDependency(tree, name)
rxDownload(aUri, aDstFile)
rxFormPost(aUri, aData)
rxGet(aUri)
rxGetJson(aUri)
rxLocateDir(aSrcDir, aPredicate) Locates the directory across the parent chain for which the predicate matches
rxTransformHtmlFile(aName, aOp, aTree) Reads an HMTL from the tree and then transforms it using the given function. If the result is null or undefined, the file will be deleted, else replaced or created.
rxTransformHtmlFragment(aName, aOp, aTree) Reads an HMTL from the tree and then transforms it using the given function. If the result is null or undefined, the file will be deleted, else replaced or created.
rxTransformJsonFile(aName, aOp, aTree) Reads a JSON file from the tree and then transforms it using the given function. If the result is null or undefined, the file will be deleted, else replaced or created.
rxTransformLinesFile(aName, aOp, aTree) Reads a line based file from the tree and then transforms it using the given function. If the result is null or undefined, the file will be deleted, else replaced or created.
rxTransformTextFile(aName, aOp, aTree) Reads a text file from the tree and then transforms it using the given function. If the result is null or undefined, the file will be deleted, else replaced or created.
rxUnzipFromUrl(aTree, aSrcUrl, aDstDir, aSkip)
safeWrite(aPath, aFile, aHost) Overwrites file content, but only if it differs
serializeJson(aData)
serializeLines(aSource)
syncDir(aSrc, aDst, aHost, aLogger)
targetBuildNotFoundError()
updateField(aName, aGenerator, aObj)
updateMinVersion(aName, aMinVersion, aPkg, aType) Updates the package JSON to use at least the given version
updateWorkspace(workspace)
validateApiUrl(aUrl, bValidateWithCredentials) Tests if the API URL is valid and if we have sufficient credentials to access the API
validateCredentials(aApiUrl, aCredentials)
validateHtmlSelector(selector)
validateName(name)
validateProjectName(projectName)
writeFilesOnTree(aHost, aRoot) Returns an operator that writes all file descriptors to disk

Interfaces

Interface Description
AppConfig
AppShellBuilderOptions
BrowserBuilderBaseOptions
BrowserBuilderOptions
BuilderTarget
Change
CliConfig
E2EOptions
ExtractI18nOptions
FileReplacements
Host 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
LibraryBuilderOptions
LintBuilderOptions
Location
ModuleOptions
NodeDependency
ServeBuilderOptions
ServerBuilderOptions
TestBuilderOptions
WorkspaceProject
WorkspaceSchema
WorkspaceTargets
ZipEntry

Variables

Variable Description
ajaxRequest
configPath
createXHR
htmlSelectorRe
MODULE_EXT
NOOP_LOGGER
ROUTING_MODULE_EXT
rxDeleteFile
rxReadTextFile
rxReadZip Export the function to extract a zip file
rxTmpFile
rxUnlink
TENANT_BASED_URL_REGEXP
VERSION Version and build number of the package
WCHTOOLS_DEPENDENCIES
writeBufferOnTree Constructs a WriteTextFile on top of a host
writeTextFileOnTree Constructs a WriteTextFile on top of a host

Type Aliases

Type Alias Description
AppShellBuilderTarget
BrowserBuilderTarget
E2EBuilderTarget
ExtractI18nBuilderTarget
LibraryBuilderTarget
LintBuilderTarget
OutputHashing
ServeBuilderTarget
ServerBuilderTarget
TestBuilderTarget
TransformCallback
TransformWithoutPath
TransformWithPath

Home > @acoustic-content-sdk/schematics-utils > InsertChange

InsertChange class

Will add text to the source code.

Signature:

export declare class InsertChange implements Change 

Constructors

Constructor Modifiers Description
(constructor)(path, pos, toAdd) Constructs a new instance of the InsertChange class

Properties

Property Modifiers Type Description
description string
order number
path string
pos number
toAdd string

Methods

Method Modifiers Description
apply(host) This method does not insert spaces if there is none in the original string.

Home > @acoustic-content-sdk/schematics-utils > NoopChange

NoopChange class

An operation that does nothing.

Signature:

export declare class NoopChange implements Change 

Properties

Property Modifiers Type Description
description string
order number
path any

Methods

Method Modifiers Description
apply()

Home > @acoustic-content-sdk/schematics-utils > RemoveChange

RemoveChange class

Will remove text from the source code.

Signature:

export declare class RemoveChange implements Change 

Constructors

Constructor Modifiers Description
(constructor)(path, pos, toRemove) Constructs a new instance of the RemoveChange class

Properties

Property Modifiers Type Description
description string
order number
path string

Methods

Method Modifiers Description
apply(host)

Home > @acoustic-content-sdk/schematics-utils > ReplaceChange

ReplaceChange class

Will replace text from the source code.

Signature:

export declare class ReplaceChange implements Change 

Constructors

Constructor Modifiers Description
(constructor)(path, pos, oldText, newText) Constructs a new instance of the ReplaceChange class

Properties

Property Modifiers Type Description
description string
order number
path string

Methods

Method Modifiers Description
apply(host)

Home > @acoustic-content-sdk/schematics-utils > Builders

Builders enum

Signature:

export declare enum Builders 

Enumeration Members

Member Value Description
AppShell "@angular-devkit/build-angular:app-shell"
Browser "@angular-devkit/build-angular:browser"
DevServer "@angular-devkit/build-angular:dev-server"
ExtractI18n "@angular-devkit/build-angular:extract-i18n"
Karma "@angular-devkit/build-angular:karma"
NgPackagr "@angular-devkit/build-ng-packagr:build"
Protractor "@angular-devkit/build-angular:protractor"
Server "@angular-devkit/build-angular:server"
TsLint "@angular-devkit/build-angular:tslint"

Home > @acoustic-content-sdk/schematics-utils > DEP_TYPE

DEP_TYPE enum

Signature:

export declare enum DEP_TYPE 

Enumeration Members

Member Value Description
DEVELOPMENT 2
PEER 0
RUNTIME 1

Home > @acoustic-content-sdk/schematics-utils > NodeDependencyType

NodeDependencyType enum

Signature:

export declare enum NodeDependencyType 

Enumeration Members

Member Value Description
Default "dependencies"
Dev "devDependencies"
Optional "optionalDependencies"
Peer "peerDependencies"

Home > @acoustic-content-sdk/schematics-utils > ProjectType

ProjectType enum

Signature:

export declare enum ProjectType 

Enumeration Members

Member Value Description
Application "application"
Library "library"

Home > @acoustic-content-sdk/schematics-utils > addBootstrapToModule

addBootstrapToModule() function

Custom function to insert an export into NgModule. It also imports it.

Signature:

export declare function addBootstrapToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addDeclarationToModule

addDeclarationToModule() function

Custom function to insert a declaration (component, pipe, directive) into NgModule declarations. It also imports the component.

Signature:

export declare function addDeclarationToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addEntryComponentToModule

addEntryComponentToModule() function

Warning: This API is now obsolete.

  • Since version 9.0.0 with Ivy, entryComponents is no longer necessary.

Custom function to insert an entryComponent into NgModule. It also imports it.

Signature:

export declare function addEntryComponentToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addExportToModule

addExportToModule() function

Custom function to insert an export into NgModule. It also imports it.

Signature:

export declare function addExportToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addImportsToModule

addImportsToModule() function

Changes the identified module by adding a couple of imports

Signature:

export declare function addImportsToModule(aFile: string, aModules: {
    [identifier: string]: string;
}, aHost: Tree): void;

Parameters

Parameter Type Description
aFile string the filename
aModules {
[identifier: string]: string;
}
the modules to be added
aHost Tree the tree

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > addImportToModule

addImportToModule() function

Custom function to insert an NgModule into NgModule imports. It also imports the module.

Signature:

export declare function addImportToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addPackageJsonDependency

addPackageJsonDependency() function

Signature:

export declare function addPackageJsonDependency(tree: Tree, dependency: NodeDependency): void;

Parameters

Parameter Type Description
tree Tree
dependency NodeDependency

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > addProjectToWorkspace

addProjectToWorkspace() function

Signature:

export declare function addProjectToWorkspace<TProjectType extends ProjectType = ProjectType.Application>(workspace: WorkspaceSchema, name: string, project: WorkspaceProject<TProjectType>): Rule;

Parameters

Parameter Type Description
workspace WorkspaceSchema
name string
project WorkspaceProject<TProjectType>

Returns:

Rule

Home > @acoustic-content-sdk/schematics-utils > addProviderToModule

addProviderToModule() function

Custom function to insert a provider into NgModule. It also imports it.

Signature:

export declare function addProviderToModule(source: SourceFile, modulePath: string, classifiedName: string, importPath: string): Change[];

Parameters

Parameter Type Description
source SourceFile
modulePath string
classifiedName string
importPath string

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addRouteDeclarationToModule

addRouteDeclarationToModule() function

Adds a new route declaration to a router module (i.e. has a RouterModule declaration)

Signature:

export declare function addRouteDeclarationToModule(source: SourceFile, fileToAdd: string, routeLiteral: string): Change;

Parameters

Parameter Type Description
source SourceFile
fileToAdd string
routeLiteral string

Returns:

Change

Home > @acoustic-content-sdk/schematics-utils > addSymbolToNgModuleMetadata

addSymbolToNgModuleMetadata() function

Signature:

export declare function addSymbolToNgModuleMetadata(source: SourceFile, ngModulePath: string, metadataField: string, symbolName: string, importPath?: string | null): Change[];

Parameters

Parameter Type Description
source SourceFile
ngModulePath string
metadataField string
symbolName string
importPath string | null

Returns:

Change[]

Home > @acoustic-content-sdk/schematics-utils > addToWchToolsDependencies

addToWchToolsDependencies() function

Signature:

export declare function addToWchToolsDependencies(aDeps: string[], aPkg: any): void;

Parameters

Parameter Type Description
aDeps string[]
aPkg any

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > assertHasTrailingSlash

assertHasTrailingSlash() function

Signature:

export declare function assertHasTrailingSlash(aValue: any): string;

Parameters

Parameter Type Description
aValue any

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > assertIsEmail

assertIsEmail() function

Signature:

export declare function assertIsEmail(aValue: any, aName?: string): string;

Parameters

Parameter Type Description
aValue any
aName string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > assertIsUrl

assertIsUrl() function

Signature:

export declare function assertIsUrl(aValue: any, aName?: string): string;

Parameters

Parameter Type Description
aValue any
aName string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > assertIsValidUserName

assertIsValidUserName() function

Signature:

export declare function assertIsValidUserName(aValue: any, aName?: string): string;

Parameters

Parameter Type Description
aValue any
aName string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > assertNotNull

assertNotNull() function

Signature:

export declare function assertNotNull(aValue: any, aName?: string): void;

Parameters

Parameter Type Description
aValue any
aName string

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > assertParameter

assertParameter() function

Signature:

export declare function assertParameter(aValue: any, aParameterName: string): void;

Parameters

Parameter Type Description
aValue any
aParameterName string

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > buildDefaultPath

buildDefaultPath() function

Build a default project path for generating.

Signature:

export declare function buildDefaultPath(project: WorkspaceProject): string;

Parameters

Parameter Type Description
project WorkspaceProject The project to build the path for.

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > buildRelativePath

buildRelativePath() function

Build a relative path from one file path to another file path.

Signature:

export declare function buildRelativePath(from: string, to: string): string;

Parameters

Parameter Type Description
from string
to string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > byIdentifier

byIdentifier() function

Signature:

export declare function byIdentifier(aName: string): Predicate<Node>;

Parameters

Parameter Type Description
aName string

Returns:

Predicate<Node>

Home > @acoustic-content-sdk/schematics-utils > byName

byName() function

Signature:

export declare function byName(aText: string): Predicate<NamedDeclaration>;

Parameters

Parameter Type Description
aText string

Returns:

Predicate<NamedDeclaration>

Home > @acoustic-content-sdk/schematics-utils > byText

byText() function

Signature:

export declare function byText(aText: string): Predicate<Node>;

Parameters

Parameter Type Description
aText string

Returns:

Predicate<Node>

Home > @acoustic-content-sdk/schematics-utils > byType

byType() function

Signature:

export declare function byType(aType: SyntaxKind): Predicate<Node>;

Parameters

Parameter Type Description
aType SyntaxKind

Returns:

Predicate<Node>

Home > @acoustic-content-sdk/schematics-utils > byTypeAndName

byTypeAndName() function

Signature:

export declare function byTypeAndName(aType: SyntaxKind, aName: string): Predicate<Node>;

Parameters

Parameter Type Description
aType SyntaxKind
aName string

Returns:

Predicate<Node>

Home > @acoustic-content-sdk/schematics-utils > canonicalizeJSON

canonicalizeJSON() function

Signature:

declare function _canonicalize(aData: any): any;

Parameters

Parameter Type Description
aData any

Returns:

any

Home > @acoustic-content-sdk/schematics-utils > changeSourceFile

changeSourceFile() function

Signature:

export declare function changeSourceFile(aFile: string, aOp: (aFile: string, aContent: SourceFile) => Change[], aHost: Tree): void;

Parameters

Parameter Type Description
aFile string
aOp (aFile: string, aContent: SourceFile) => Change[]
aHost Tree

Returns:

void

Home > @acoustic-content-sdk/schematics-utils > copyDir

copyDir() function

Copies from source to target and overrides the target. But does not delete extra files

Signature:

export declare function copyDir(aSrc: string, aDst: string, aHost: Tree, aLogger?: Logger): Tree;

Parameters

Parameter Type Description
aSrc string source directory
aDst string target directory
aHost Tree tree
aLogger Logger

Returns:

Tree

the tree

Home > @acoustic-content-sdk/schematics-utils > createLoggerService

createLoggerService() function

Constructs the logger service on top of the context

Signature:

export declare function createLoggerService(context: SchematicContext): LoggerService;

Parameters

Parameter Type Description
context SchematicContext context

Returns:

LoggerService

the logger service

Home > @acoustic-content-sdk/schematics-utils > createTransientTree

createTransientTree() function

Creates a transient copy of a tree

Signature:

export declare function createTransientTree(aRoot: string): Tree;

Parameters

Parameter Type Description
aRoot string root folder for the tree

Returns:

Tree

the tree

Home > @acoustic-content-sdk/schematics-utils > ensureTrailingSlash

ensureTrailingSlash() function

Signature:

declare function _ensureTrailingSlash(aUrl: string): string;

Parameters

Parameter Type Description
aUrl string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > findBootstrapModuleCall

findBootstrapModuleCall() function

Signature:

export declare function findBootstrapModuleCall(host: Tree, mainPath: string): CallExpression | null;

Parameters

Parameter Type Description
host Tree
mainPath string

Returns:

CallExpression | null

Home > @acoustic-content-sdk/schematics-utils > findBootstrapModulePath

findBootstrapModulePath() function

Signature:

export declare function findBootstrapModulePath(host: Tree, mainPath: string): string;

Parameters

Parameter Type Description
host Tree
mainPath string

Returns:

string

Home > @acoustic-content-sdk/schematics-utils > findDataDir

findDataDir() function

Signature:

export declare function findDataDir(host: Tree, options?: {
    data?: string;
}): Path;

Parameters

Parameter Type Description
host Tree
options {
data?: string;
}

Returns:

Path

Home > @acoustic-content-sdk/schematics-utils > findModule

findModule() function

Function to find the "closest" module to a generated file's path.

Signature:

export declare function findModule(host: Tree, generateDir: string, moduleExt?: string, routingModuleExt?: string): Path;

Parameters

Parameter Type Description
host Tree
generateDir string
moduleExt string
routingModuleExt string

Returns:

Path

Home > @acoustic-content-sdk/schematics-utils > findModuleFromOptions

findModuleFromOptions() function

Find the module referred by a set of options passed to the schematics.

Signature:

export declare function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined;

Parameters

Parameter Type Description
host Tree
options ModuleOptions

Returns:

Path | undefined

Home > @acoustic-content-sdk/schematics-utils > findNode

findNode() function

Signature:

export declare function findNode(node: Node, kind: SyntaxKind, text: string): Node | null;

Parameters

Parameter Type Description
node Node
kind SyntaxKind
text string

Returns:

Node | null

Home > @acoustic-content-sdk/schematics-utils > findNodes

findNodes() function

Find all nodes from the AST in the subtree of node of SyntaxKind kind.

Signature:

export declare function findNodes(node: Node, kind: SyntaxKind, max?: number, recursive?: boolean): Node[];

Parameters

Parameter Type Description
node Node
kind SyntaxKind
max number The maximum number of items to return.
recursive boolean Continue looking for nodes of kind recursive until end the last child even when node of kind has been found.

Returns:

Node[]

all nodes of kind, or [] if none is foun