GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — devframe/scripts/play.ts at main · devframes/devframe

Expand file tree

/

play.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
105 lines (90 loc) · 2.89 KB
/

play.ts

Copy path

File metadata and controls

105 lines (90 loc) · 2.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { Choice } from 'prompts'
import { spawnSync } from 'node:child_process'
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import prompts from 'prompts'
/**
* Workspace globs, mirrored from `pnpm-workspace.yaml`'s `packages:` list
* (same mirroring rationale as `scripts/verify-typecheck-coverage.ts`): a
* new example, plugin, or other playground shows up here for free, with no
* change to this script.
*/
const WORKSPACE_PATTERNS = [
'examples/*',
'packages/*',
'plugins/*',
'storybook',
]
/**
* Script names that make a workspace package runnable as a "play"; the
* first one present in a package's `scripts` wins.
*/
const RUN_SCRIPTS = ['dev', 'storybook', 'start']
const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), '..')
interface Play {
dir: string
pkgName: string
script: string
}
function expandPattern(pattern: string): string[] {
if (!pattern.endsWith('/*'))
return [pattern]
const base = pattern.slice(0, -2)
const baseDir = join(rootDir, base)
if (!existsSync(baseDir))
return []
return readdirSync(baseDir, { withFileTypes: true })
.filter(entry => entry.isDirectory())
.map(entry => `${base}/${entry.name}`)
.sort((a, b) => a.localeCompare(b))
}
function findPlay(dir: string): Play | undefined {
const pkgPath = join(rootDir, dir, 'package.json')
if (!existsSync(pkgPath))
return undefined
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
const script = RUN_SCRIPTS.find(name => pkg.scripts?.[name])
if (!script)
return undefined
return { dir, pkgName: pkg.name, script }
}
function suggest(input: string, choices: Choice[]): Promise<Choice[]> {
const needle = input.toLowerCase()
return Promise.resolve(choices.filter(choice => choice.title.toLowerCase().includes(needle)))
}
async function main(): Promise<void> {
const plays = WORKSPACE_PATTERNS
.flatMap(expandPattern)
.map(findPlay)
.filter((play): play is Play => play !== undefined)
if (plays.length === 0) {
console.error(`No playgrounds found: none of ${WORKSPACE_PATTERNS.join(', ')} has a package.json with a ${RUN_SCRIPTS.join('/')} script.`)
process.exitCode = 1
return
}
const { play } = await prompts({
type: 'autocomplete',
name: 'play',
message: 'Select a playground to run',
choices: plays.map(p => ({
title: p.dir,
description: `${p.pkgName} · pnpm run ${p.script}`,
value: p,
})),
suggest,
}) as { play?: Play }
if (!play) {
console.log('No playground selected.')
return
}
console.log(`\n▶ pnpm run ${play.script} (${play.dir})\n`)
const result = spawnSync('pnpm', ['run', play.script], {
cwd: join(rootDir, play.dir),
stdio: 'inherit',
shell: false,
})
process.exitCode = result.status ?? 1
}
main()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.