-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathinterface.ts
117 lines (91 loc) · 3.36 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @license
* Copyright Google LLC 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
*/
import { Path, PathFragment } from '@angular-devkit/core';
import { Action } from './action';
export enum MergeStrategy {
AllowOverwriteConflict = 1 << 1,
AllowCreationConflict = 1 << 2,
AllowDeleteConflict = 1 << 3,
// Uses the default strategy.
Default = 0,
// Error out if 2 files have the same path. It is useful to have a different value than
// Default in this case as the tooling Default might differ.
Error = 1 << 0,
// Only content conflicts are overwritten.
ContentOnly = AllowOverwriteConflict,
// Overwrite everything with the latest change.
Overwrite = AllowOverwriteConflict + AllowCreationConflict + AllowDeleteConflict,
}
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
export const FileVisitorCancelToken: symbol = Symbol();
export type FileVisitor = FilePredicate<void>;
export interface FileEntry {
readonly path: Path;
readonly content: Buffer;
}
export interface DirEntry {
readonly parent: DirEntry | null;
readonly path: Path;
readonly subdirs: PathFragment[];
readonly subfiles: PathFragment[];
dir(name: PathFragment): DirEntry;
file(name: PathFragment): FileEntry | null;
visit(visitor: FileVisitor): void;
}
export interface FilePredicate<T> {
(path: Path, entry?: Readonly<FileEntry> | null): T;
}
declare const window: { Symbol: { schematicTree: symbol }; window: {} };
declare const self: { Symbol: { schematicTree: symbol }; self: {} };
declare const global: { Symbol: { schematicTree: symbol }; global: {} };
export const TreeSymbol: symbol = (function () {
const globalSymbol =
(typeof window == 'object' && window.window === window && window.Symbol) ||
(typeof self == 'object' && self.self === self && self.Symbol) ||
(typeof global == 'object' && global.global === global && global.Symbol);
if (!globalSymbol) {
return Symbol('schematic-tree');
}
if (!globalSymbol.schematicTree) {
globalSymbol.schematicTree = Symbol('schematic-tree');
}
return globalSymbol.schematicTree;
})();
export interface Tree {
branch(): Tree;
merge(other: Tree, strategy?: MergeStrategy): void;
readonly root: DirEntry;
// Readonly.
read(path: string): Buffer | null;
exists(path: string): boolean;
get(path: string): FileEntry | null;
getDir(path: string): DirEntry;
visit(visitor: FileVisitor): void;
// Change content of host files.
overwrite(path: string, content: Buffer | string): void;
beginUpdate(path: string): UpdateRecorder;
commitUpdate(record: UpdateRecorder): void;
// Structural methods.
create(path: string, content: Buffer | string): void;
delete(path: string): void;
rename(from: string, to: string): void;
apply(action: Action, strategy?: MergeStrategy): void;
readonly actions: Action[];
}
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Tree {
export function isTree(maybeTree: object): maybeTree is Tree {
return TreeSymbol in maybeTree;
}
}
export interface UpdateRecorder {
// These just record changes.
insertLeft(index: number, content: Buffer | string): UpdateRecorder;
insertRight(index: number, content: Buffer | string): UpdateRecorder;
remove(index: number, length: number): UpdateRecorder;
}