generated from qiwi/blank-ts-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add new action compare (#31)
- Loading branch information
1 parent
cf2e9ab
commit 667d6b2
Showing
12 changed files
with
3,349 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { NpmRegClientWrapper } from '@qiwi/npm-batch-client' | ||
import { join } from 'path' | ||
|
||
import { TCompareConfigData, TCompareRegistryOpts, TDownloadListItem } from '../interfaces' | ||
import { writeJson } from '../utils' | ||
|
||
const clientFactory = (opts: TCompareRegistryOpts) => new NpmRegClientWrapper( | ||
opts.url, | ||
{ | ||
...opts.auth, | ||
email: '', | ||
} | ||
) | ||
|
||
export const performCompare = async (config: TCompareConfigData): Promise<void> => { | ||
const { | ||
secondaryRegistry, | ||
primaryRegistry, | ||
packages, | ||
cwd, | ||
} = config | ||
|
||
const primaryRegClient = clientFactory(primaryRegistry) | ||
const secondaryRegClient = clientFactory(secondaryRegistry) | ||
|
||
const downloadListMissing: TDownloadListItem[] = [] | ||
const downloadListExtra: TDownloadListItem[] = [] | ||
|
||
for (const item of packages) { | ||
const name = item.group && item.group !== 'null' ? `@${item.group}/${item.name}` : item.name | ||
try { | ||
const [ | ||
primaryPackument, | ||
secondaryPackument, | ||
] = await Promise.all([ | ||
primaryRegClient.getPackument(name), | ||
secondaryRegClient.getPackument(name) | ||
]) | ||
|
||
const primaryVersions = Object.keys(primaryPackument.versions) | ||
const secondaryVersions = Object.keys(secondaryPackument.versions) | ||
|
||
secondaryVersions | ||
.filter(item => !primaryVersions.includes(item)) | ||
.forEach(version => downloadListMissing.push({ version, name: item.name, group: item.group })) | ||
|
||
primaryVersions | ||
.filter(item => !secondaryVersions.includes(item)) | ||
.forEach(version => downloadListExtra.push({ version, name: item.name, group: item.group })) | ||
} catch (e) { | ||
console.error(`Could not get data packuments for ${name}:`, e) | ||
} | ||
} | ||
|
||
const missingResultsPath = join(cwd, 'missing.json') | ||
const extraResultsPath = join(cwd, 'extra.json') | ||
|
||
writeJson(downloadListMissing, missingResultsPath) | ||
writeJson(downloadListExtra, extraResultsPath) | ||
|
||
console.log(`Done.`) | ||
console.log(`${downloadListMissing.length} packages are missing, ${downloadListExtra.length} packages are extra in primary registry`) | ||
console.log(`Metadata is written to ${missingResultsPath} and ${extraResultsPath}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.