UNPKG

5.62 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. 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.io/license
7 */
8import { Rule, SchematicContext, Source, Tree } from '@angular-devkit/schematics';
9import * as ts from 'typescript';
10import { FileData } from '@nrwl/devkit';
11import { Path } from '@angular-devkit/core';
12import type { NxJsonConfiguration } from '@nrwl/devkit';
13export declare function sortObjectByKeys(obj: unknown): {};
14export { findNodes } from '../utilities/typescript/find-nodes';
15export { getSourceNodes } from '../utilities/typescript/get-source-nodes';
16export interface Change {
17 apply(host: any): Promise<void>;
18 readonly type: string;
19 readonly path: string | null;
20 readonly order: number;
21 readonly description: string;
22}
23export declare class NoopChange implements Change {
24 type: string;
25 description: string;
26 order: number;
27 path: any;
28 apply(): Promise<void>;
29}
30export declare class InsertChange implements Change {
31 path: string;
32 pos: number;
33 toAdd: string;
34 type: string;
35 order: number;
36 description: string;
37 constructor(path: string, pos: number, toAdd: string);
38 apply(host: any): any;
39}
40export declare class RemoveChange implements Change {
41 path: string;
42 pos: number;
43 toRemove: string;
44 type: string;
45 order: number;
46 description: string;
47 constructor(path: string, pos: number, toRemove: string);
48 apply(host: any): Promise<void>;
49}
50export declare class ReplaceChange implements Change {
51 path: string;
52 pos: number;
53 oldText: string;
54 newText: string;
55 type: string;
56 order: number;
57 description: string;
58 constructor(path: string, pos: number, oldText: string, newText: string);
59 apply(host: any): Promise<void>;
60}
61export declare function addParameterToConstructor(source: ts.SourceFile, modulePath: string, opts: {
62 className: string;
63 param: string;
64}): Change[];
65export declare function addMethod(source: ts.SourceFile, modulePath: string, opts: {
66 className: string;
67 methodHeader: string;
68 body: string;
69}): Change[];
70export declare function findClass(source: ts.SourceFile, className: string, silent?: boolean): ts.ClassDeclaration;
71export declare function offset(text: string, numberOfTabs: number, wrap: boolean): string;
72export declare function addIncludeToTsConfig(tsConfigPath: string, source: ts.SourceFile, include: string): Change[];
73export declare function getImport(source: ts.SourceFile, predicate: (a: any) => boolean): {
74 moduleSpec: string;
75 bindings: string[];
76}[];
77export declare function addGlobal(source: ts.SourceFile, modulePath: string, statement: string): Change[];
78export declare function insert(host: Tree, modulePath: string, changes: Change[]): void;
79/**
80 * This method is specifically for reading JSON files in a Tree
81 * @param host The host tree
82 * @param path The path to the JSON file
83 * @returns The JSON data in the file.
84 */
85export declare function readJsonInTree<T extends object = any>(host: Tree, path: string): T;
86/**
87 * @deprecated This method is deprecated
88 */
89export declare function getFileDataInHost(host: Tree, path: Path): FileData;
90export declare function allFilesInDirInHost(host: Tree, path: Path, options?: {
91 recursive: boolean;
92}): Path[];
93/**
94 * This method is specifically for updating JSON in a Tree
95 * @param path Path of JSON file in the Tree
96 * @param callback Manipulation of the JSON data
97 * @returns A rule which updates a JSON file file in a Tree
98 */
99export declare function updateJsonInTree<T extends object = any, O extends object = T>(path: string, callback: (json: T, context: SchematicContext) => O): Rule;
100export declare function updateWorkspaceInTree<T extends object = any, O extends object = T>(callback: (json: T, context: SchematicContext, host: Tree) => O): Rule;
101export declare function readNxJsonInTree(host: Tree): NxJsonConfiguration<string[] | "*">;
102export declare function libsDir(host: Tree): string;
103export declare function appsDir(host: Tree): string;
104export declare function updateNxJsonInTree(callback: (json: NxJsonConfiguration, context: SchematicContext) => NxJsonConfiguration): Rule;
105export declare function readWorkspace(host: Tree): any;
106/**
107 * Updates the package.json given the passed deps and/or devDeps. Only updates
108 * if the packages are not yet present
109 *
110 * @param deps the package.json dependencies to add
111 * @param devDeps the package.json devDependencies to add
112 * @param addInstall default `true`; set to false to avoid installs
113 */
114export declare function addDepsToPackageJson(deps: any, devDeps: any, addInstall?: boolean): Rule;
115export declare function updatePackageJsonDependencies(deps: any, devDeps: any, addInstall?: boolean): Rule;
116export declare function getProjectConfig(host: Tree, name: string): any;
117export declare function createOrUpdate(host: Tree, path: string, content: string): void;
118export declare function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): Change;
119export declare function replaceNodeValue(host: Tree, modulePath: string, node: ts.Node, content: string): void;
120export declare function renameSyncInTree(tree: Tree, from: string, to: string, cb: (err: string) => void): void;
121export declare function renameDirSyncInTree(tree: Tree, from: string, to: string, cb: (err: string) => void): void;
122/**
123 * Applies a template merge but skips for already existing entries
124 */
125export declare function applyWithSkipExisting(source: Source, rules: Rule[]): Rule;