1 |
|
2 | import { Readable } from 'node:stream';
|
3 | import { Queue } from './queue';
|
4 | import { Projector } from './projector';
|
5 |
|
6 |
|
7 |
|
8 | export interface IBundleResourceOptions {
|
9 | |
10 |
|
11 |
|
12 | atime?: null | Date;
|
13 | |
14 |
|
15 |
|
16 | atimeCopy?: null | boolean;
|
17 | |
18 |
|
19 |
|
20 | mtime?: null | Date;
|
21 | |
22 |
|
23 |
|
24 | mtimeCopy?: null | boolean;
|
25 | |
26 |
|
27 |
|
28 | executable?: null | boolean;
|
29 | |
30 |
|
31 |
|
32 | executableCopy?: null | boolean;
|
33 | |
34 |
|
35 |
|
36 | merge?: null | boolean;
|
37 | |
38 |
|
39 |
|
40 | noRecurse?: null | boolean;
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 | export declare abstract class Bundle {
|
46 | |
47 |
|
48 |
|
49 | excludes: RegExp[];
|
50 | |
51 |
|
52 |
|
53 | readonly path: string;
|
54 | |
55 |
|
56 |
|
57 | readonly flat: boolean;
|
58 | |
59 |
|
60 |
|
61 | abstract readonly projector: Projector;
|
62 | |
63 |
|
64 |
|
65 | protected _isOpen: boolean;
|
66 | |
67 |
|
68 |
|
69 | protected _closeQueue: Queue;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | constructor(path: string, flat?: boolean);
|
77 | /**
|
78 | * Check if output open.
|
79 | *
|
80 | * @returns Returns true if open, else false.
|
81 | */
|
82 | get isOpen(): boolean;
|
83 | /**
|
84 | * Check if name is excluded file.
|
85 | *
|
86 | * @param name File name.
|
87 | * @returns Returns true if excluded, else false.
|
88 | */
|
89 | isExcludedFile(name: string): boolean;
|
90 | /**
|
91 | * Open output.
|
92 | */
|
93 | open(): Promise<void>;
|
94 | /**
|
95 | * Close output.
|
96 | */
|
97 | close(): Promise<void>;
|
98 | /**
|
99 | * Write out the bundle.
|
100 | * Has a callback to write out the resources.
|
101 | *
|
102 | * @param func Async function.
|
103 | * @returns Return value of the async function.
|
104 | */
|
105 | write<T>(func?: ((self: this) => Promise<T>) | null): Promise<T | null>;
|
106 | /**
|
107 | * Get path for resource.
|
108 | *
|
109 | * @param destination Resource destination.
|
110 | * @returns Destination path.
|
111 | */
|
112 | resourcePath(destination: string): string;
|
113 | /**
|
114 | * Check if path for resource exists.
|
115 | *
|
116 | * @param destination Resource destination.
|
117 | * @returns True if destination exists, else false.
|
118 | */
|
119 | resourceExists(destination: string): Promise<boolean>;
|
120 | /**
|
121 | * Copy resource, detecting source type automatically.
|
122 | *
|
123 | * @param destination Resource destination.
|
124 | * @param source Source directory.
|
125 | * @param options Resource options.
|
126 | */
|
127 | copyResource(destination: string, source: string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
128 | /**
|
129 | * Copy directory as resource, recursive copy.
|
130 | *
|
131 | * @param destination Resource destination.
|
132 | * @param source Source directory.
|
133 | * @param options Resource options.
|
134 | */
|
135 | copyResourceDirectory(destination: string, source: string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
136 | /**
|
137 | * Copy file as resource.
|
138 | *
|
139 | * @param destination Resource destination.
|
140 | * @param source Source file.
|
141 | * @param options Resource options.
|
142 | */
|
143 | copyResourceFile(destination: string, source: string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
144 | /**
|
145 | * Copy symlink as resource.
|
146 | *
|
147 | * @param destination Resource destination.
|
148 | * @param source Source symlink.
|
149 | * @param options Resource options.
|
150 | */
|
151 | copyResourceSymlink(destination: string, source: string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
152 | /**
|
153 | * Create a resource directory.
|
154 | *
|
155 | * @param destination Resource destination.
|
156 | * @param options Resource options.
|
157 | */
|
158 | createResourceDirectory(destination: string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
159 | /**
|
160 | * Create a resource file.
|
161 | *
|
162 | * @param destination Resource destination.
|
163 | * @param data Resource data.
|
164 | * @param options Resource options.
|
165 | */
|
166 | createResourceFile(destination: string, data: Readonly<Uint8Array> | string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
167 | /**
|
168 | * Create a resource symlink.
|
169 | *
|
170 | * @param destination Resource destination.
|
171 | * @param target Symlink target.
|
172 | * @param options Resource options.
|
173 | */
|
174 | createResourceSymlink(destination: string, target: Readonly<Uint8Array> | string, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
175 | /**
|
176 | * Stream readable source to resource file.
|
177 | *
|
178 | * @param destination Resource destination.
|
179 | * @param data Resource stream.
|
180 | * @param options Resource options.
|
181 | */
|
182 | streamResourceFile(destination: string, data: Readable, options?: Readonly<IBundleResourceOptions> | null): Promise<void>;
|
183 | /**
|
184 | * Check that output path is valid, else throws.
|
185 | */
|
186 | protected _checkOutput(): Promise<void>;
|
187 | /**
|
188 | * Expand resource options copy properties with stat object from source.
|
189 | *
|
190 | * @param options Options object.
|
191 | * @param stat Stat function.
|
192 | * @returns Options copy with any values populated.
|
193 | */
|
194 | protected _expandResourceOptionsCopy(options: Readonly<IBundleResourceOptions>, stat: () => Promise<{
|
195 | atime: Date;
|
196 | mtime: Date;
|
197 | mode: number;
|
198 | }>): Promise<IBundleResourceOptions>;
|
199 | /**
|
200 | * Set resource attributes from options object.
|
201 | *
|
202 | * @param path File path.
|
203 | * @param options Options object.
|
204 | */
|
205 | protected _setResourceAttributes(path: string, options: Readonly<IBundleResourceOptions>): Promise<void>;
|
206 | /**
|
207 | * Get file mode executable.
|
208 | *
|
209 | * @param mode Current mode.
|
210 | * @returns Is executable.
|
211 | */
|
212 | protected _getResourceModeExecutable(mode: number): boolean;
|
213 | /**
|
214 | * Set file mode executable.
|
215 | *
|
216 | * @param mode Current mode.
|
217 | * @param executable Is executable.
|
218 | * @returns File mode.
|
219 | */
|
220 | protected _setResourceModeExecutable(mode: number, executable: boolean): number;
|
221 | /**
|
222 | * Open output.
|
223 | */
|
224 | protected _open(): Promise<void>;
|
225 | /**
|
226 | * Close output.
|
227 | */
|
228 | protected _close(): Promise<void>;
|
229 | /**
|
230 | * Assert bundle is open.
|
231 | */
|
232 | protected _assertIsOpen(): void;
|
233 | /**
|
234 | * Assert resource does not exist, returning destination path.
|
235 | *
|
236 | * @param destination Resource destination.
|
237 | * @param ignoreDirectory Ignore directories.
|
238 | * @returns Destination path.
|
239 | */
|
240 | protected _assertNotResourceExists(destination: string, ignoreDirectory?: boolean): Promise<string>;
|
241 | /**
|
242 | * Get the projector path.
|
243 | *
|
244 | * @returns This path or the nested path.
|
245 | */
|
246 | protected _getProjectorPath(): string;
|
247 | /**
|
248 | * Get nested projector path.
|
249 | *
|
250 | * @returns Output path.
|
251 | */
|
252 | protected abstract _getProjectorPathNested(): string;
|
253 | /**
|
254 | * Create projector instance for the bundle.
|
255 | *
|
256 | * @returns Projector instance.
|
257 | */
|
258 | protected abstract _createProjector(): Projector;
|
259 | }
|