UNPKG

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