-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathsourceAdapterFactory.ts
52 lines (48 loc) · 2.32 KB
/
sourceAdapterFactory.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
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Messages, SfError } from '@salesforce/core';
import { SourceAdapter } from '../types';
import { ForceIgnore } from '../forceIgnore';
import { RegistryAccess } from '../../registry/registryAccess';
import { MetadataType } from '../../registry/types';
import { TreeContainer } from '../treeContainers';
import { BundleSourceAdapter } from './bundleSourceAdapter';
import { DecomposedSourceAdapter } from './decomposedSourceAdapter';
import { MatchingContentSourceAdapter } from './matchingContentSourceAdapter';
import { MixedContentSourceAdapter } from './mixedContentSourceAdapter';
import { DefaultSourceAdapter } from './defaultSourceAdapter';
import { DigitalExperienceSourceAdapter } from './digitalExperienceSourceAdapter';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
export class SourceAdapterFactory {
private readonly registry: RegistryAccess;
private readonly tree: TreeContainer;
public constructor(registry: RegistryAccess, tree: TreeContainer) {
this.registry = registry;
this.tree = tree;
}
public getAdapter(type: MetadataType, forceIgnore = new ForceIgnore()): SourceAdapter {
const adapterId = type.strategies?.adapter;
switch (adapterId) {
case 'bundle':
return new BundleSourceAdapter(type, this.registry, forceIgnore, this.tree);
case 'decomposed':
return new DecomposedSourceAdapter(type, this.registry, forceIgnore, this.tree);
case 'matchingContentFile':
return new MatchingContentSourceAdapter(type, this.registry, forceIgnore, this.tree);
case 'mixedContent':
return new MixedContentSourceAdapter(type, this.registry, forceIgnore, this.tree);
case 'digitalExperience':
return new DigitalExperienceSourceAdapter(type, this.registry, forceIgnore, this.tree);
case 'default':
case undefined:
return new DefaultSourceAdapter(type, this.registry, forceIgnore, this.tree);
default:
throw new SfError(messages.getMessage('error_missing_adapter', [adapterId, type.name]), 'RegistryError');
}
}
}