@@ -16,90 +16,98 @@ import {
1616 onSetScope ,
1717 onTest ,
1818 onUse ,
19+ cleanInvalidNpmConfig ,
1920} from './actions.js' ;
2021
21- const program = new Command ( ) ;
22-
23- const { name, version, description } = packageJson ;
24- program . name ( name ) . description ( description ) . version ( version ) ;
25-
26- program . command ( 'ls' ) . description ( 'List all the registries' ) . action ( onList ) ;
27-
28- program
29- . command ( 'current' )
30- . option ( '-u, --show-url' , 'Show the registry URL instead of the name' )
31- . description ( 'Show current registry name or URL' )
32- . action ( onCurrent ) ;
33-
34- program
35- . command ( 'use [name]' )
36- . description ( 'Change current registry' )
37- . action ( onUse ) ;
38-
39- program
40- . command ( 'add <name> <url> [home]' )
41- . description ( 'Add custom registry' )
42- . action ( onAdd ) ;
43-
44- program
45- . command ( 'login <name> [base64]' )
46- . option ( '-a, --always-auth' , 'Set is always auth' )
47- . option ( '-u, --username <username>' , 'Your user name for this registry' )
48- . option ( '-p, --password <password>' , 'Your password for this registry' )
49- . option ( '-e, --email <email>' , 'Your email for this registry' )
50- . description (
51- 'Set authorize information for a custom registry with a base64 encoded string or username and password' ,
52- )
53- . action ( onLogin ) ;
54-
55- program
56- . command ( 'set-hosted-repo <name> <repo>' )
57- . description (
58- 'Set hosted npm repository for a custom registry to publish package' ,
59- )
60- . action ( onSetRepository ) ;
61-
62- program
63- . command ( 'set-scope <scopeName> <url>' )
64- . description ( 'Associating a scope with a registry' )
65- . action ( onSetScope ) ;
66-
67- program
68- . command ( 'del-scope <scopeName>' )
69- . description ( 'Remove a scope' )
70- . action ( onDeleteScope ) ;
71-
72- program
73- . command ( 'set <name>' )
74- . requiredOption ( '-a,--attr <attr>' , 'Set a custom registry attribute' )
75- . requiredOption ( '-v,--value <value>' , 'Set a custom registry value' )
76- . description ( 'Set a custom registry attribute' )
77- . action ( onSetAttribute ) ;
78-
79- program
80- . command ( 'rename <name> <newName>' )
81- . description ( 'Change custom registry name' )
82- . action ( onRename ) ;
83-
84- program
85- . command ( 'del [name]' )
86- . description ( 'Delete custom registry' )
87- . action ( onDelete ) ;
88-
89- program
90- . command ( 'home <name> [browser]' )
91- . description ( 'Open the homepage of registry with optional browser' )
92- . action ( onHome ) ;
93-
94- program
95- . command ( 'test [registry]' )
96- . description ( 'Show response time for specific or all registries' )
97- . action ( ( ) => {
98- onTest ( ) ;
99- } ) ; // ignore return value to pass typescript check
100-
101- program . parse ( process . argv ) ;
102-
103- if ( process . argv . length === 2 ) {
104- program . outputHelp ( ) ;
22+ async function main ( ) {
23+ const program = new Command ( ) ;
24+
25+ // make sure the invalid npm config is cleaned up
26+ await cleanInvalidNpmConfig ( ) ;
27+
28+ const { name, version, description } = packageJson ;
29+ program . name ( name ) . description ( description ) . version ( version ) ;
30+
31+ program . command ( 'ls' ) . description ( 'List all the registries' ) . action ( onList ) ;
32+
33+ program
34+ . command ( 'current' )
35+ . option ( '-u, --show-url' , 'Show the registry URL instead of the name' )
36+ . description ( 'Show current registry name or URL' )
37+ . action ( onCurrent ) ;
38+
39+ program
40+ . command ( 'use [name]' )
41+ . description ( 'Change current registry' )
42+ . action ( onUse ) ;
43+
44+ program
45+ . command ( 'add <name> <url> [home]' )
46+ . description ( 'Add custom registry' )
47+ . action ( onAdd ) ;
48+
49+ program
50+ . command ( 'login <name> [base64]' )
51+ . option ( '-a, --always-auth' , 'Set is always auth' )
52+ . option ( '-u, --username <username>' , 'Your user name for this registry' )
53+ . option ( '-p, --password <password>' , 'Your password for this registry' )
54+ . option ( '-e, --email <email>' , 'Your email for this registry' )
55+ . description (
56+ 'Set authorize information for a custom registry with a base64 encoded string or username and password' ,
57+ )
58+ . action ( onLogin ) ;
59+
60+ program
61+ . command ( 'set-hosted-repo <name> <repo>' )
62+ . description (
63+ 'Set hosted npm repository for a custom registry to publish package' ,
64+ )
65+ . action ( onSetRepository ) ;
66+
67+ program
68+ . command ( 'set-scope <scopeName> <url>' )
69+ . description ( 'Associating a scope with a registry' )
70+ . action ( onSetScope ) ;
71+
72+ program
73+ . command ( 'del-scope <scopeName>' )
74+ . description ( 'Remove a scope' )
75+ . action ( onDeleteScope ) ;
76+
77+ program
78+ . command ( 'set <name>' )
79+ . requiredOption ( '-a,--attr <attr>' , 'Set a custom registry attribute' )
80+ . requiredOption ( '-v,--value <value>' , 'Set a custom registry value' )
81+ . description ( 'Set a custom registry attribute' )
82+ . action ( onSetAttribute ) ;
83+
84+ program
85+ . command ( 'rename <name> <newName>' )
86+ . description ( 'Change custom registry name' )
87+ . action ( onRename ) ;
88+
89+ program
90+ . command ( 'del [name]' )
91+ . description ( 'Delete custom registry' )
92+ . action ( onDelete ) ;
93+
94+ program
95+ . command ( 'home <name> [browser]' )
96+ . description ( 'Open the homepage of registry with optional browser' )
97+ . action ( onHome ) ;
98+
99+ program
100+ . command ( 'test [registry]' )
101+ . description ( 'Show response time for specific or all registries' )
102+ . action ( ( ) => {
103+ onTest ( ) ;
104+ } ) ; // ignore return value to pass typescript check
105+
106+ await program . parseAsync ( process . argv ) ;
107+
108+ if ( process . argv . length === 2 ) {
109+ program . outputHelp ( ) ;
110+ }
105111}
112+
113+ main ( ) ;
0 commit comments