-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add retrievetargetdir to source:retrieve #624
Changes from all commits
0091091
ededda5
2676119
c5ec4f6
77b7eb1
434b082
df8d554
b25ac34
a121b01
8bc1596
461b9e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2022, 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 { ensureArray } from '@salesforce/kit'; | ||
|
||
/** | ||
* Function to throttle a list of promises. | ||
* | ||
* @param sourceQueue - The list of items to process. | ||
* @param producer - The function to produce a promise from an item. | ||
* @param concurrency - The number of promises to run at a time. | ||
* @param queueResults - Whether to queue the results of the promises. | ||
*/ | ||
export async function promisesQueue<T>( | ||
sourceQueue: T[], | ||
producer: (T) => Promise<T | T[]>, | ||
concurrency: number, | ||
queueResults = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd omit this since it isn't used. It's not clear what it might do and at-a-glance invites an infinite loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mshanemc it is used in mv function. Yes it can and yes I have :). Not being able to queue results defeats the ability to accomplish the dir traversal without recursion. |
||
): Promise<T[]> { | ||
const results: T[] = []; | ||
let queue = [...sourceQueue]; | ||
while (queue.length > 0) { | ||
const next = queue.slice(0, concurrency); | ||
queue = queue.slice(concurrency); | ||
// eslint-disable-next-line no-await-in-loop | ||
const nextResults = (await Promise.all(ensureArray(next.map(producer)))) | ||
.flat(1) | ||
.filter((val) => val !== undefined) as T[]; | ||
if (queueResults) { | ||
queue.push(...nextResults); | ||
} | ||
results.push(...nextResults); | ||
} | ||
return results; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 { SourceTestkit } from '@salesforce/source-testkit'; | ||
import { JsonMap } from '@salesforce/ts-types'; | ||
import { TEST_REPOS_MAP } from '../testMatrix'; | ||
|
||
// DO NOT TOUCH. generateNuts.ts will insert these values | ||
const REPO = TEST_REPOS_MAP.get('%REPO_URL%'); | ||
|
||
context('Retrieve metadata NUTs [name: %REPO_NAME%]', () => { | ||
let testkit: SourceTestkit; | ||
|
||
before(async () => { | ||
testkit = await SourceTestkit.create({ | ||
repository: REPO.gitUrl, | ||
nut: __filename, | ||
}); | ||
await testkit.trackGlobs(testkit.packageGlobs); | ||
await testkit.deploy({ args: `--sourcepath ${testkit.packageNames.join(',')}` }); | ||
}); | ||
|
||
after(async () => { | ||
try { | ||
await testkit?.clean(); | ||
} catch (e) { | ||
// if the it fails to clean, don't throw so NUTs will pass | ||
// eslint-disable-next-line no-console | ||
console.log('Clean Failed: ', e); | ||
} | ||
}); | ||
|
||
describe('--retrievetargetdir flag', () => { | ||
for (const testCase of REPO.retrieve.retrievetargetdir) { | ||
it(`should retrieve ${testCase.toRetrieve}`, async () => { | ||
await testkit.modifyLocalGlobs(testCase.toVerify); | ||
await testkit.retrieve({ args: `--retrievetargetdir targetdir --metadata ${testCase.toRetrieve}` }); | ||
await testkit.expect.filesToBeRetrieved(testCase.toVerify, testCase.toIgnore); | ||
}); | ||
} | ||
|
||
it('should throw an error if the metadata is not valid', async () => { | ||
const retrieve = (await testkit.retrieve({ args: '--retrievetargetdir targetdir --metadata DOES_NOT_EXIST', exitCode: 1 })) as JsonMap; | ||
testkit.expect.errorToHaveName(retrieve, 'SfError'); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall comment...there's some tools that do this kind of thing if we find a lot more use cases for it.
https://github.com/supercharge/promise-pool is fairly small, zero-dep. The error handling and abort looks nice.