|
7 | 7 | import * as path from 'path'; |
8 | 8 | import { SfdxCommand } from '@salesforce/command'; |
9 | 9 | import { ComponentSet } from '@salesforce/source-deploy-retrieve'; |
10 | | -import { fs, PackageDir, SfdxError, SfdxProjectJson } from '@salesforce/core'; |
| 10 | +import { fs, SfdxError } from '@salesforce/core'; |
11 | 11 | import { ComponentLike } from '@salesforce/source-deploy-retrieve/lib/src/common'; |
12 | 12 |
|
13 | 13 | export type FlagOptions = { |
14 | 14 | packagenames?: string[]; |
15 | | - sourcepath?: string[]; |
16 | | - manifest?: string; |
17 | | - metadata?: string[]; |
| 15 | + sourcepath: string[]; |
| 16 | + manifest: string; |
| 17 | + metadata: string[]; |
18 | 18 | }; |
19 | 19 |
|
20 | 20 | export const MINIMUM_SRC_WAIT_MINUTES = 1; |
21 | 21 | export const DEFAULT_SRC_WAIT_MINUTES = 33; |
22 | 22 |
|
23 | 23 | export abstract class SourceCommand extends SfdxCommand { |
24 | | - public async retrievePackageDirs(): Promise<PackageDir[]> { |
25 | | - const proj = await SfdxProjectJson.create({}); |
26 | | - return proj.getPackageDirectories(); |
27 | | - } |
28 | | - |
29 | 24 | /** |
30 | 25 | * will create one ComponentSet to be deployed/retrieved |
31 | 26 | * will combine from all options passed in |
32 | 27 | * |
33 | 28 | * @param options: FlagOptions where to create ComponentSets from |
34 | 29 | */ |
35 | | - public async createComponentSet(options: FlagOptions): Promise<ComponentSet> { |
36 | | - const setAggregator: ComponentSet[] = []; |
37 | | - const pkgs = await this.retrievePackageDirs(); |
| 30 | + protected async createComponentSet(options: FlagOptions): Promise<ComponentSet> { |
| 31 | + const setAggregator: ComponentLike[] = []; |
| 32 | + |
38 | 33 | // go through options to create a list of ComponentSets |
39 | 34 | // we'll then combine all of those to deploy/retrieve |
40 | 35 | if (options.sourcepath) { |
41 | 36 | options.sourcepath.forEach((filepath) => { |
42 | 37 | if (fs.fileExistsSync(filepath)) { |
43 | 38 | this.logger.debug(`Creating ComponentSet from sourcepath ${path.resolve(filepath)}`); |
44 | | - setAggregator.push(ComponentSet.fromSource(path.resolve(filepath))); |
| 39 | + setAggregator.push(...ComponentSet.fromSource(path.resolve(filepath))); |
45 | 40 | } else { |
46 | 41 | throw SfdxError.create('@salesforce/plugin-source', 'sourceCommand', 'SourcePathInvalid', [filepath]); |
47 | 42 | } |
48 | 43 | }); |
49 | 44 | } |
50 | 45 |
|
51 | 46 | if (options.packagenames) { |
52 | | - // filter from all the packages to the ones requested |
53 | | - // will be package name, could include spaces |
54 | | - pkgs |
55 | | - .filter((pkg) => { |
56 | | - return options.packagenames.includes(pkg.path); |
57 | | - }) |
58 | | - // for the requested ones get the ComponentSet from their path |
59 | | - .forEach((pkg) => { |
60 | | - this.logger.debug(`Creating ComponentSet from source with ${path.resolve(pkg.path)}`); |
61 | | - setAggregator.push(ComponentSet.fromSource(path.resolve(pkg.path))); |
62 | | - }); |
| 47 | + // retrieve only |
| 48 | + // TODO: @W-8908888@ |
63 | 49 | } |
64 | 50 |
|
65 | 51 | if (options.manifest) { |
66 | 52 | this.logger.debug(`Creating ComponentSet from manifest ${path.resolve(options.manifest)}`); |
67 | 53 |
|
68 | 54 | setAggregator.push( |
69 | | - await ComponentSet.fromManifestFile(options.manifest, { |
| 55 | + ...(await ComponentSet.fromManifestFile(options.manifest, { |
70 | 56 | // to create a link to the actual source component we need to have it resolve through all packages |
71 | 57 | // to find the matching source metadata |
72 | 58 | // this allows us to deploy after |
73 | | - resolve: pkgs.map((pkg) => path.resolve(pkg.path)), |
74 | | - }) |
| 59 | + resolve: process.cwd(), |
| 60 | + })) |
75 | 61 | ); |
76 | 62 | } |
77 | 63 |
|
78 | 64 | if (options.metadata) { |
79 | 65 | options.metadata.forEach((entry) => { |
80 | 66 | const splitEntry = entry.split(':'); |
81 | | - const metadata: ComponentLike = { fullName: undefined, type: undefined }; |
82 | | - if (splitEntry.length === 1) { |
83 | | - // -m ApexClass |
84 | | - metadata.type = splitEntry[0]; |
85 | | - metadata.fullName = '*'; |
86 | | - } else { |
87 | | - // -m ApexClass:MyApexClass |
88 | | - metadata.type = splitEntry[0]; |
89 | | - metadata.fullName = splitEntry[1]; |
90 | | - } |
| 67 | + const metadata: ComponentLike = { |
| 68 | + type: splitEntry[0], |
| 69 | + // either -m ApexClass or -m ApexClass:MyApexClass |
| 70 | + fullName: splitEntry.length === 1 ? '*' : splitEntry[1], |
| 71 | + }; |
91 | 72 | this.logger.debug(`Creating ComponentSet from metadata member ${metadata.type}:${metadata.fullName}`); |
92 | 73 |
|
93 | 74 | const cs = new ComponentSet([metadata]); |
94 | 75 | // we need to search the entire project for the matching metadata component |
95 | 76 | // no better way than to have it search than process.cwd() |
96 | 77 | cs.resolveSourceComponents(process.cwd(), { filter: cs }); |
97 | | - setAggregator.push(cs); |
| 78 | + setAggregator.push(...cs); |
98 | 79 | }); |
99 | 80 | } |
100 | 81 |
|
101 | | - // join the ComponentSets in the aggregator into one |
102 | | - // combining ComponentLike objects from across packages to do a single deploy/retrieve call |
103 | | - const merged: ComponentLike[] = []; |
104 | | - setAggregator.forEach((set) => { |
105 | | - merged.push(...set); |
106 | | - }); |
107 | | - |
108 | | - return new ComponentSet(merged); |
| 82 | + return new ComponentSet(setAggregator); |
109 | 83 | } |
110 | 84 | } |
0 commit comments