/
cli-utils.ts
53 lines (46 loc) 路 1.62 KB
/
cli-utils.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
53
import { SyntheticEvent } from 'react';
export const copyToClipBoardUtility =
(str: string): ((e: SyntheticEvent<HTMLElement>) => void) =>
(event: SyntheticEvent<HTMLElement>): void => {
event.preventDefault();
const node = document.createElement('div');
node.innerText = str;
if (document.body) {
document.body.appendChild(node);
const range = document.createRange();
const selection = window.getSelection() as Selection;
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
document.body.removeChild(node);
}
};
export function getCLISetConfigRegistry(
command: string,
scope: string | undefined,
registryUrl: string
): string {
// if there is a scope defined there needs to be a ":" separator between the scope and the registry
return `${command} ${scope ? `${scope}:` : ''}registry ${registryUrl}`;
}
export function getCLISetRegistry(command: string, registryUrl: string): string {
return `${command} --registry ${registryUrl}`;
}
export function getCLIChangePassword(command: string, registryUrl: string): string {
return `${command} profile set password --registry ${registryUrl}`;
}
export function getCLISBerryYamlRegistry(scope: string | undefined, registryUrl: string): string {
return !scope
? `// .yarnrc.yml
npmRegistryServer: "${registryUrl}"
unsafeHttpWhitelist:
- ${new URL(registryUrl).host}`
: `
// .yarnrc.yml
npmRegistryServer: "${registryUrl}"
npmScopes:
${scope.replace('@', '')}:
npmRegistryServer: ${registryUrl}
npmPublishRegistry: ${registryUrl}`;
}