\begin{quote}
Shared utilities for Angular Dev\+Kit. \end{quote}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1104}{}\doxysection{Exception}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1104}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1105}{}\doxysection{Json}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1105}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1106}{}\doxysubsection{Schema}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1106}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1107}{}\doxysubsubsection{Schema\+Validator\+Result}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1107}

\begin{DoxyCode}{0}
\DoxyCodeLine{export interface SchemaValidatorResult \{}
\DoxyCodeLine{  success: boolean;}
\DoxyCodeLine{  errors?: string[];}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1108}{}\doxysubsubsection{Schema\+Validator}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1108}

\begin{DoxyCode}{0}
\DoxyCodeLine{export interface SchemaValidator \{}
\DoxyCodeLine{  (data: any): Observable<SchemaValidatorResult>;}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1109}{}\doxysubsubsection{Schema\+Formatter}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1109}

\begin{DoxyCode}{0}
\DoxyCodeLine{export interface SchemaFormatter \{}
\DoxyCodeLine{  readonly async: boolean;}
\DoxyCodeLine{  validate(data: any): boolean | Observable<boolean>;}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1110}{}\doxysubsubsection{Schema\+Registry}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1110}

\begin{DoxyCode}{0}
\DoxyCodeLine{export interface SchemaRegistry \{}
\DoxyCodeLine{  compile(schema: Object): Observable<SchemaValidator>;}
\DoxyCodeLine{  addFormat(name: string, formatter: SchemaFormatter): void;}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1111}{}\doxysubsubsection{Core\+Schema\+Registry}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1111}
{\ttfamily Schema\+Registry} implementation using \href{https://github.com/epoberezkin/ajv}{\texttt{ https\+://github.\+com/epoberezkin/ajv}}. Constructor accepts object containing {\ttfamily Schema\+Formatter} that will be added automatically.


\begin{DoxyCode}{0}
\DoxyCodeLine{export class CoreSchemaRegistry implements SchemaRegistry \{}
\DoxyCodeLine{  constructor(formats: \{ [name: string]: SchemaFormatter\} = \{\}) \{\}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1112}{}\doxysection{Logger}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1112}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1113}{}\doxysection{Utils}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1113}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1114}{}\doxysection{Virtual FS}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1114}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1115}{}\doxysection{Workspaces}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1115}
The {\ttfamily workspaces} namespace provides an API for interacting with the workspace file formats. It provides an abstraction of the underlying storage format of the workspace and provides support for both reading and writing. Currently, the only supported format is the JSON-\/based format used by the Angular CLI. For this format, the API provides internal change tracking of values which enables fine-\/grained updates to the underlying storage of the workspace. This allows for the retention of existing formatting and comments.

A workspace is defined via the following object model. Definition collection objects are specialized Javascript {\ttfamily Map} objects with an additional {\ttfamily add} method to simplify addition and provide more localized error checking of the newly added values.


\begin{DoxyCode}{0}
\DoxyCodeLine{export interface WorkspaceDefinition \{}
\DoxyCodeLine{    readonly extensions: Record<string, JsonValue | undefined>;}
\DoxyCodeLine{    readonly projects: ProjectDefinitionCollection;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{export interface ProjectDefinition \{}
\DoxyCodeLine{    readonly extensions: Record<string, JsonValue | undefined>;}
\DoxyCodeLine{    readonly targets: TargetDefinitionCollection;}
\DoxyCodeLine{    root: string;}
\DoxyCodeLine{    prefix?: string;}
\DoxyCodeLine{    sourceRoot?: string;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{export interface TargetDefinition \{}
\DoxyCodeLine{    options?: Record<string, JsonValue | undefined>;}
\DoxyCodeLine{    configurations?: Record<string, Record<string, JsonValue | undefined> | undefined>;}
\DoxyCodeLine{    builder: string;}
\DoxyCodeLine{\} }

\end{DoxyCode}


The API is asynchronous and has two main functions to facilitate reading, creation, and modifying a workspace\+: {\ttfamily read\+Workspace} and {\ttfamily write\+Workspace}.


\begin{DoxyCode}{0}
\DoxyCodeLine{export enum WorkspaceFormat \{}
\DoxyCodeLine{  JSON,}
\DoxyCodeLine{\} }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{export function readWorkspace(}
\DoxyCodeLine{  path: string,}
\DoxyCodeLine{  host: WorkspaceHost,}
\DoxyCodeLine{  format?: WorkspaceFormat,}
\DoxyCodeLine{): Promise<\{ workspace: WorkspaceDefinition; \}>; }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{export function writeWorkspace(}
\DoxyCodeLine{  workspace: WorkspaceDefinition,}
\DoxyCodeLine{  host: WorkspaceHost,}
\DoxyCodeLine{  path?: string,}
\DoxyCodeLine{  format?: WorkspaceFormat,}
\DoxyCodeLine{): Promise<void>; }

\end{DoxyCode}


A {\ttfamily Workspace\+Host} abstracts the underlying data access methods from the functions. It provides methods to read, write, and analyze paths. A utility function is provided to create an instance of a {\ttfamily Workspace\+Host} from the Angular Dev\+Kit\textquotesingle{}s virtual filesystem host abstraction.


\begin{DoxyCode}{0}
\DoxyCodeLine{export interface WorkspaceHost \{}
\DoxyCodeLine{    readFile(path: string): Promise<string>;}
\DoxyCodeLine{    writeFile(path: string, data: string): Promise<void>;}
\DoxyCodeLine{    isDirectory(path: string): Promise<boolean>;}
\DoxyCodeLine{    isFile(path: string): Promise<boolean>;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{export function createWorkspaceHost(host: virtualFs.Host): WorkspaceHost; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1116}{}\doxysubsection{Usage Example}\label{md_sfcode_node_modules__angular_devkit_core_README_autotoc_md1116}
To demonstrate the usage of the API, the following code will show how to add a option property to a build target for an application.


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ NodeJsSyncHost \} from '@angular-\/devkit/core/node';}
\DoxyCodeLine{import \{ workspaces \} from '@angular-\/devkit/core';}
\DoxyCodeLine{}
\DoxyCodeLine{async function demonstrate() \{}
\DoxyCodeLine{    const host = workspaces.createWorkspaceHost(new NodeJsSyncHost());}
\DoxyCodeLine{    const \{ workspace \} = await workspaces.readWorkspace('path/to/workspace/directory/', host);}
\DoxyCodeLine{}
\DoxyCodeLine{    const project = workspace.projects.get('my-\/app');}
\DoxyCodeLine{    if (!project) \{}
\DoxyCodeLine{      throw new Error('my-\/app does not exist');}
\DoxyCodeLine{    \}}
\DoxyCodeLine{}
\DoxyCodeLine{    const buildTarget = project.targets.get('build');}
\DoxyCodeLine{    if (!buildTarget) \{}
\DoxyCodeLine{      throw new Error('build target does not exist');}
\DoxyCodeLine{    \}}
\DoxyCodeLine{}
\DoxyCodeLine{    buildTarget.options.optimization = true;}
\DoxyCodeLine{}
\DoxyCodeLine{    await workspaces.writeWorkspace(workspace, host);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{demonstrate(); }

\end{DoxyCode}
 