MCPcopy
hub / github.com/directus/directus / initialize

Method initialize

api/src/extensions/manager.ts:189–226  ·  view source on GitHub ↗

* Load and register all extensions * * @param {ExtensionManagerOptions} options - Extension manager configuration options * @param {boolean} options.schedule - Whether or not to allow for scheduled (CRON) hook extensions * @param {boolean} options.watch - Whether or not to watch the local ex

(options: Partial<ExtensionManagerOptions> = {})

Source from the content-addressed store, hash-verified

187 * @param {boolean} options.watch - Whether or not to watch the local extensions folder for changes
188 */
189 public async initialize(options: Partial<ExtensionManagerOptions> = {}): Promise<void> {
190 const logger = useLogger();
191
192 this.options = {
193 ...defaultOptions,
194 ...options,
195 };
196
197 const wasWatcherInitialized = this.watcher !== null;
198
199 if (this.options.watch && !wasWatcherInitialized) {
200 this.initializeWatcher();
201 } else if (!this.options.watch && wasWatcherInitialized) {
202 await this.closeWatcher();
203 }
204
205 if (!this.isLoaded) {
206 await this.load({ forceSync: true });
207
208 if (this.extensions.length > 0) {
209 logger.info(`Loaded extensions: ${this.extensions.map((ext) => ext.name).join(', ')}`);
210 }
211 }
212
213 if (this.options.watch && !wasWatcherInitialized) {
214 this.updateWatchedExtensions([...this.extensions]);
215 }
216
217 this.messenger.subscribe(this.reloadChannel, (payload: Record<string, unknown>) => {
218 // Ignore requests for reloading that were published by the current process
219 if (isPlainObject(payload) && 'origin' in payload && payload['origin'] === this.processId) return;
220 // Reload extensions with event options
221 const options: ExtensionSyncOptions = {};
222 if (typeof payload['forceSync'] === 'boolean') options.forceSync = payload['forceSync'];
223 if (typeof payload['partialSync'] === 'string') options.partialSync = payload['partialSync'];
224 this.reload(options);
225 });
226 }
227
228 /**
229 * Installs an external extension from registry

Callers

nothing calls this directly

Calls 8

initializeWatcherMethod · 0.95
closeWatcherMethod · 0.95
loadMethod · 0.95
reloadMethod · 0.95
useLoggerFunction · 0.85
joinMethod · 0.80
subscribeMethod · 0.65

Tested by

no test coverage detected