workspace.d.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.dev/license
  7. */
  8. import { json, workspaces } from '@angular-devkit/core';
  9. import { Rule, Tree } from '@angular-devkit/schematics';
  10. export type WorkspaceDefinition = workspaces.WorkspaceDefinition;
  11. export type ProjectDefinition = workspaces.ProjectDefinition;
  12. export type TargetDefinition = workspaces.TargetDefinition;
  13. /**
  14. * A {@link workspaces.WorkspaceHost} backed by a Schematics {@link Tree} instance.
  15. */
  16. export declare class TreeWorkspaceHost implements workspaces.WorkspaceHost {
  17. private readonly tree;
  18. constructor(tree: Tree);
  19. readFile(path: string): Promise<string>;
  20. writeFile(path: string, data: string): Promise<void>;
  21. isDirectory(path: string): Promise<boolean>;
  22. isFile(path: string): Promise<boolean>;
  23. }
  24. /**
  25. * Updates the workspace file (`angular.json`) found within the root of the schematic's tree.
  26. * The workspace object model can be directly modified within the provided updater function
  27. * with changes being written to the workspace file after the updater function returns.
  28. * The spacing and overall layout of the file (including comments) will be maintained where
  29. * possible when updating the file.
  30. *
  31. * @param updater An update function that can be used to modify the object model for the
  32. * workspace. A {@link WorkspaceDefinition} is provided as the first argument to the function.
  33. */
  34. export declare function updateWorkspace(updater: (workspace: WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>): Rule;
  35. /**
  36. * Reads a workspace file (`angular.json`) from the provided {@link Tree} instance.
  37. *
  38. * @param tree A schematics {@link Tree} instance used to access the workspace file.
  39. * @param path The path where a workspace file should be found. If a file is specified, the file
  40. * path will be used. If a directory is specified, the file `angular.json` will be used from
  41. * within the specified directory. Defaults to `/angular.json`.
  42. * @returns A {@link WorkspaceDefinition} representing the workspace found at the specified path.
  43. */
  44. export declare function getWorkspace(tree: Tree, path?: string): Promise<WorkspaceDefinition>;
  45. /**
  46. * Writes a workspace file (`angular.json`) to the provided {@link Tree} instance.
  47. * The spacing and overall layout of an exisitng file (including comments) will be maintained where
  48. * possible when writing the file.
  49. *
  50. * @param tree A schematics {@link Tree} instance used to access the workspace file.
  51. * @param workspace The {@link WorkspaceDefinition} to write.
  52. * @param path The path where a workspace file should be written. If a file is specified, the file
  53. * path will be used. If not provided, the definition's underlying file path stored during reading
  54. * will be used.
  55. */
  56. export declare function writeWorkspace(tree: Tree, workspace: WorkspaceDefinition, path?: string): Promise<void>;
  57. /**
  58. * Build a default project path for generating.
  59. * @param project The project which will have its default path generated.
  60. */
  61. export declare function buildDefaultPath(project: workspaces.ProjectDefinition): string;
  62. export declare function createDefaultPath(tree: Tree, projectName: string): Promise<string>;
  63. export declare function allWorkspaceTargets(workspace: workspaces.WorkspaceDefinition): Iterable<[string, workspaces.TargetDefinition, string, workspaces.ProjectDefinition]>;
  64. export declare function allTargetOptions(target: workspaces.TargetDefinition, skipBaseOptions?: boolean): Iterable<[string | undefined, Record<string, json.JsonValue | undefined>]>;