@epic-web/workshop-app 5.24.2 → 5.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/epicshop.js +55 -9
  2. package/package.json +4 -3
package/bin/epicshop.js CHANGED
@@ -6,8 +6,10 @@ import fs from 'fs'
6
6
  import http from 'http'
7
7
  import path from 'path'
8
8
  import { fileURLToPath } from 'url'
9
+ import chalk from 'chalk'
9
10
  import closeWithGrace from 'close-with-grace'
10
11
  import getPort from 'get-port'
12
+ import open from 'open'
11
13
 
12
14
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
13
15
  const isPublished = !fs.existsSync(path.join(__dirname, '..', 'app'))
@@ -60,9 +62,13 @@ async function start() {
60
62
  let server = null
61
63
  let child = null
62
64
  let restarting = false
65
+ let childPort = null
63
66
  let childPortPromiseResolve = null
64
- const childPort = new Promise((resolve) => {
67
+ const childPortPromise = new Promise((resolve) => {
65
68
  childPortPromiseResolve = resolve
69
+ }).then((port) => {
70
+ childPort = port
71
+ return port
66
72
  })
67
73
 
68
74
  function parsePortFromLine(line) {
@@ -74,7 +80,7 @@ async function start() {
74
80
  }
75
81
 
76
82
  async function waitForChildReady() {
77
- const port = await childPort
83
+ const port = await childPortPromise
78
84
  const url = `http://localhost:${port}/`
79
85
  const maxAttempts = 40 // 20s max (500ms interval)
80
86
  for (let i = 0; i < maxAttempts; i++) {
@@ -187,15 +193,13 @@ async function start() {
187
193
  if (child.stdout) {
188
194
  child.stdout.on('data', (data) => {
189
195
  process.stdout.write(data)
190
-
191
- if (childPortPromiseResolve) {
196
+ if (!childPort) {
192
197
  const str = data.toString('utf8')
193
198
  const lines = str.split(/\r?\n/)
194
199
  for (const line of lines) {
195
200
  const port = parsePortFromLine(line)
196
- if (port && childPortPromiseResolve) {
197
- childPortPromiseResolve(port)
198
- childPortPromiseResolve = null
201
+ if (port) {
202
+ childPortPromiseResolve?.(port)
199
203
  }
200
204
  }
201
205
  }
@@ -213,8 +217,8 @@ async function start() {
213
217
 
214
218
  spawnChild()
215
219
 
216
- // Listen for 'u' key to update and restart
217
- if (process.stdin.isTTY) {
220
+ if (process.stdin.isTTY && !isDeployed) {
221
+ printSupportedKeys()
218
222
  process.stdin.setRawMode(true)
219
223
  process.stdin.resume()
220
224
  process.stdin.setEncoding('utf8')
@@ -224,6 +228,38 @@ async function start() {
224
228
  '\nšŸ”„ Update requested from terminal. Running update and restarting app process...',
225
229
  )
226
230
  await doUpdateAndRestart()
231
+ } else if (key === 'o') {
232
+ if (childPort) {
233
+ console.log(
234
+ chalk.blue(
235
+ `\n🌐 Opening browser to http://localhost:${childPort} ...`,
236
+ ),
237
+ )
238
+ await open(`http://localhost:${childPort}`)
239
+ } else {
240
+ console.log(chalk.red('Local server URL not available yet.'))
241
+ }
242
+ } else if (key === 'q') {
243
+ console.log(chalk.yellow('\nšŸ‘‹ Exiting...'))
244
+ await cleanupBeforeExit()
245
+ process.exit(0)
246
+ } else if (key === 'r') {
247
+ console.log(chalk.magenta('\nšŸ”„ Restarting app process...'))
248
+ restarting = true
249
+ await killChild(child)
250
+ restarting = false
251
+ spawnChild()
252
+ } else if (key === 'k') {
253
+ const messages = [
254
+ chalk.bgCyan.black('🐨 Kody says: You are koalafied for greatness!'),
255
+ chalk.bgGreen.black('🐨 Kody says: Keep going, you are pawsome!'),
256
+ chalk.bgMagenta.white('🐨 Kody says: Eucalyptus up and code on!'),
257
+ chalk.bgYellow.black('🐨 Kody says: You can do it, fur real!'),
258
+ chalk.bgBlue.white('🐨 Kody says: Stay curious, stay cuddly!'),
259
+ chalk.bgRed.white("🐨 Kody says: Don't leaf your dreams behind!"),
260
+ ]
261
+ const msg = messages[Math.floor(Math.random() * messages.length)]
262
+ console.log('\n' + msg + '\n')
227
263
  } else if (key === '\u0003') {
228
264
  // Ctrl+C
229
265
  await cleanupBeforeExit()
@@ -251,3 +287,13 @@ async function killChild(child) {
251
287
  child.kill()
252
288
  })
253
289
  }
290
+
291
+ function printSupportedKeys() {
292
+ console.log(chalk.bold.cyan('\nSupported keys:'))
293
+ console.log(` ${chalk.green('u')} - update repo`)
294
+ console.log(` ${chalk.blue('o')} - open browser`)
295
+ console.log(` ${chalk.yellow('q')} - exit`)
296
+ console.log(` ${chalk.magenta('r')} - restart`)
297
+ console.log(` ${chalk.cyan('k')} - Kody the Koala encouragement 🐨`)
298
+ console.log(` ${chalk.gray('Ctrl+C')} - exit`)
299
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epic-web/workshop-app",
3
- "version": "5.24.2",
3
+ "version": "5.25.0",
4
4
  "sideEffects": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -44,8 +44,8 @@
44
44
  "@epic-web/invariant": "^1.0.0",
45
45
  "@epic-web/remember": "^1.1.0",
46
46
  "@epic-web/restore-scroll": "^1.1.1",
47
- "@epic-web/workshop-presence": "5.24.2",
48
- "@epic-web/workshop-utils": "5.24.2",
47
+ "@epic-web/workshop-presence": "5.25.0",
48
+ "@epic-web/workshop-utils": "5.25.0",
49
49
  "@mdx-js/mdx": "^3.0.1",
50
50
  "@mux/mux-player-react": "^3.0.0",
51
51
  "@nasa-gcn/remix-seo": "^2.0.1",
@@ -92,6 +92,7 @@
92
92
  "mime-types": "^2.1.35",
93
93
  "morgan": "^1.10.0",
94
94
  "msw": "^2.4.9",
95
+ "open": "^8.4.2",
95
96
  "openid-client": "^6.1.7",
96
97
  "p-queue": "^8.0.1",
97
98
  "partysocket": "^1.0.2",