| 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', |