MCPcopy
hub / github.com/npmx-dev/npmx.dev / run

Function run

cli/src/mock-server.ts:114–165  ·  view source on GitHub ↗
({ args })

Source from the content-addressed store, hash-verified

112 },
113 },
114 async run({ args }) {
115 const port = Number.parseInt(args.port as string, 10) || DEFAULT_PORT
116 const npmUser = args.user as string
117 const empty = args.empty as boolean
118 const frontendUrl = process.env.NPMX_CLI_DEV === 'true' ? DEV_FRONTEND_URL : PROD_FRONTEND_URL
119
120 p.intro(styleText(['bgMagenta', 'white'], ' npmx mock connector '))
121
122 const token = generateToken()
123 const config: MockConnectorConfig = {
124 token,
125 npmUser,
126 avatar: null,
127 port,
128 }
129 const stateManager = new MockConnectorStateManager(createMockConnectorState(config))
130
131 if (!empty) {
132 populateDefaultData(stateManager)
133 p.log.info(`Prepopulated with sample data for ${styleText('cyan', npmUser)}`)
134 p.log.info(styleText('dim', ` Orgs: @nuxt (4 members, 3 teams), @unjs (2 members, 1 team)`))
135 p.log.info(styleText('dim', ` Packages: @nuxt/kit, @nuxt/schema, @unjs/nitro`))
136 } else {
137 p.log.info('Starting with empty state')
138 }
139
140 stateManager.connect(token)
141 const server = new MockConnectorServer(stateManager)
142
143 try {
144 await server.start()
145 } catch (error) {
146 p.log.error(error instanceof Error ? error.message : 'Failed to start mock connector server')
147 process.exit(1)
148 }
149
150 const connectUrl = `${frontendUrl}?token=${token}&port=${port}`
151
152 p.note(
153 [
154 `Open: ${styleText(['bold', 'underline', 'cyan'], connectUrl)}`,
155 '',
156 styleText('dim', `Or paste token manually: ${token}`),
157 '',
158 styleText('dim', `User: ${npmUser} | Port: ${port}`),
159 styleText('dim', 'Operations will succeed immediately (no real npm calls)'),
160 ].join('\n'),
161 'Click to connect',
162 )
163
164 p.log.info('Waiting for connection... (Press Ctrl+C to stop)')
165 },
166})
167
168runMain(main)

Callers

nothing calls this directly

Calls 5

connectMethod · 0.95
startMethod · 0.95
createMockConnectorStateFunction · 0.90
populateDefaultDataFunction · 0.85
generateTokenFunction · 0.70

Tested by

no test coverage detected