MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / run

Function run

cli/src/cli.ts:47–111  ·  view source on GitHub ↗
({ args })

Source from the content-addressed store, hash-verified

45 },
46 },
47 async run({ args }) {
48 const port = Number.parseInt(args.port as string, 10) || DEFAULT_PORT
49 const frontendUrl =
50 process.env.NPMX_CLI_DEV === 'true' ? DEV_FRONTEND_URL : DEFAULT_FRONTEND_URL
51
52 initLogger()
53
54 // Warning message and accept prompt
55 logWarning(
56 `This allows ${styleText('underline', 'npmx.dev')} to access your npm cli and any authenticated contexts.`,
57 )
58 const accept = await p.confirm({
59 message: 'Do you accept?',
60 initialValue: true,
61 })
62
63 if (!accept || p.isCancel(accept)) {
64 logError('Connector setup cancelled.')
65 process.exit(0)
66 }
67
68 // Check npm authentication before starting
69 logInfo('Checking npm authentication...')
70 let npmUser = await getNpmUser()
71
72 if (!npmUser) {
73 logWarning('Not logged in to npm. Starting npm login...')
74 // oxlint-disable-next-line no-console -- deliberate spacing
75 console.log()
76
77 const loginSuccess = await runNpmLogin()
78
79 // oxlint-disable-next-line no-console -- deliberate spacing
80 console.log()
81
82 if (!loginSuccess) {
83 logWarning('npm login failed or was cancelled.')
84 process.exit(1)
85 }
86
87 // Check again after login
88 npmUser = await getNpmUser()
89 if (!npmUser) {
90 logWarning('Still not authenticated after login attempt.')
91 process.exit(1)
92 }
93 }
94
95 logInfo(`Authenticated as: ${npmUser}`)
96
97 const token = generateToken()
98 showToken(token, port, frontendUrl)
99
100 const app = createConnectorApp(token)
101
102 const server = serve({
103 port,
104 hostname: '127.0.0.1',

Callers 4

setupFunction · 0.50
closeThenFunction · 0.50
runThenAnnounceFunction · 0.50
closeThenFunction · 0.50

Calls 9

initLoggerFunction · 0.90
logWarningFunction · 0.90
logErrorFunction · 0.90
logInfoFunction · 0.90
getNpmUserFunction · 0.90
generateTokenFunction · 0.90
showTokenFunction · 0.90
createConnectorAppFunction · 0.90
runNpmLoginFunction · 0.85

Tested by 1

setupFunction · 0.40