Skip to content

Commit bbc4d4d

Browse files
committed
cli: --dev/--prod presets, --help, subcommand valtown (renamed)
Three coordinated changes. 1. --dev / --prod presets on generate/serve/watch: --dev local-friendly (no minify, no base-path). --prod GH Pages-shaped (--minify + --base-path=/socket-packageurl-js). No preset → auto-pick via `'CI' in process.env`: CI set (GitHub Actions etc.) → prod. CI unset (local) → dev. Explicit --minify / --base-path= still work and override piecewise. This removes duplicate flag strings from package.json scripts and CI workflows; the CLI + env are the single source of truth. 2. Rename deploy-val → valtown: - Subcommand: `pnpm walkthrough valtown` - Function: deployVal → deployValtown - Workflow: .github/workflows/deploy-val.yml → valtown.yml - npm script: walkthrough:val → walkthrough:valtown Matches the bare-word subcommand convention (generate, serve, watch, token, doctor) rather than the hyphenated verb. 3. --help / -h: `pnpm walkthrough --help` (and -h, and bare walkthrough) prints usage to stdout with exit 0. Unknown subcommands still go to stderr with exit 1 and a pointer to --help, rather than dumping the whole usage block. package.json scripts collapse — the old `walkthrough:build:prod` went away; `walkthrough:build` relies on the CLI to pick the right mode based on the `CI` env var. pages.yml + valtown.yml updated to match the new names; pages now just runs `pnpm walkthrough:build` (CI env auto-selects --prod).
1 parent bfce1e3 commit bbc4d4d

4 files changed

Lines changed: 95 additions & 37 deletions

File tree

.github/workflows/pages.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ name: 📘 Walkthrough (GH Pages)
1111
#
1212
# Build model:
1313
# 1. Shared setup-and-install → checkout w/ submodules, pnpm install.
14-
# 2. `pnpm walkthrough --minify --base-path=/socket-packageurl-js generate walkthrough.json`
15-
# The --base-path flag rewrites root-relative asset URLs and Val-Town
16-
# part links (/<slug>/part/<n>) into prefixed flat HTML paths so the
17-
# output works at socketdev.github.io/socket-packageurl-js/. --minify
18-
# runs esbuild on JS + lightningcss on CSS (~49% on-disk reduction).
14+
# 2. `pnpm walkthrough:build` — the `CI` env var (set by all GitHub
15+
# Actions runners) makes this auto-select the `prod` preset, which
16+
# applies --minify + --base-path=/socket-packageurl-js. Locally the
17+
# same script defaults to `dev`. No flag drift between CI and the
18+
# npm script.
1919
# 3. Upload `walkthrough/` as the Pages artifact.
2020
# 4. Deploy via actions/deploy-pages.
2121

@@ -68,12 +68,8 @@ jobs:
6868
- name: Init meander submodule
6969
run: git submodule update --init --depth=1 upstream/meander
7070

71-
- name: Generate walkthrough (minified, base-path=/socket-packageurl-js)
72-
run: >
73-
pnpm walkthrough
74-
--minify
75-
--base-path=/socket-packageurl-js
76-
generate walkthrough.json
71+
- name: Generate walkthrough (auto-prod via CI env)
72+
run: pnpm walkthrough:build
7773

7874
- name: Upload Pages artifact
7975
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ on:
3535
- 'val/**'
3636
- 'scripts/walkthrough.mts'
3737
- 'scripts/audit-deps.mts'
38-
- '.github/workflows/deploy-val.yml'
38+
- '.github/workflows/valtown.yml'
3939
- 'package.json'
4040
- 'pnpm-lock.yaml'
4141
workflow_dispatch:
@@ -46,7 +46,7 @@ permissions:
4646
# Queue deploys serially. Never cancel a running deploy — a partial
4747
# upload can leave Val Town with a mix of old + new file versions.
4848
concurrency:
49-
group: deploy-val
49+
group: valtown
5050
cancel-in-progress: false
5151

5252
jobs:
@@ -68,7 +68,7 @@ jobs:
6868
run: |
6969
if [ -z "$VALTOWN_TOKEN" ]; then
7070
echo "::error::VALTOWN_TOKEN secret is not configured."
71-
echo "::error::See .github/workflows/deploy-val.yml header for setup steps."
71+
echo "::error::See .github/workflows/valtown.yml header for setup steps."
7272
exit 1
7373
fi
7474
echo "VALTOWN_TOKEN present (length: ${#VALTOWN_TOKEN})"
@@ -79,8 +79,8 @@ jobs:
7979
checkout-fetch-depth: '1'
8080

8181
- name: Deploy val
82-
# `pnpm walkthrough deploy-val` runs the Socket.dev malware
82+
# `pnpm walkthrough valtown` runs the Socket.dev malware
8383
# audit on the val's transitive closure first — a finding
8484
# fails fast before any upload. Deploy receipt (file + sha256)
8585
# prints to GITHUB_STEP_SUMMARY at the end.
86-
run: pnpm walkthrough deploy-val
86+
run: pnpm walkthrough valtown

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@
6363
"update:data:npm": "node scripts/update-data-npm.mts",
6464
"walkthrough": "node scripts/walkthrough.mts",
6565
"walkthrough:build": "node scripts/walkthrough.mts generate walkthrough.json",
66-
"walkthrough:build:prod": "node scripts/walkthrough.mts --minify --base-path=/socket-packageurl-js generate walkthrough.json",
6766
"walkthrough:serve": "node scripts/walkthrough.mts serve",
6867
"walkthrough:watch": "node scripts/walkthrough.mts watch walkthrough.json",
69-
"walkthrough:val": "node scripts/walkthrough.mts deploy-val"
68+
"walkthrough:valtown": "node scripts/walkthrough.mts valtown"
7069
},
7170
"devDependencies": {
7271
"@anthropic-ai/claude-code": "2.1.92",

scripts/walkthrough.mts

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,24 +1008,91 @@ const failWith =
10081008
process.exit(1)
10091009
}
10101010

1011+
// Preset shorthand — sets minify + base-path in one flag.
1012+
// --prod ≈ --minify --base-path=/socket-packageurl-js (GH Pages layout)
1013+
// --dev ≈ plain, no minify, no base-path (local-friendly)
1014+
// Explicit --minify / --base-path= still work and override the preset.
1015+
// No preset given? Auto-pick based on `CI` in process.env:
1016+
// CI set (GitHub Actions, GitLab, etc.) → prod
1017+
// CI unset (local machine) → dev
1018+
const PROD_BASE_PATH = '/socket-packageurl-js'
1019+
10111020
function main(): void {
10121021
const args = process.argv.slice(2)
10131022
const refresh = args.includes('--refresh')
1014-
const minify = args.includes('--minify')
1015-
// Parse --base-path=<p>. When set, every root-relative asset URL
1016-
// and Val-Town-shaped part link is rewritten so the output works
1017-
// under a subdirectory host (e.g. GitHub Pages /<repo>/). Leading
1018-
// slash enforced, trailing slash stripped so path joins are clean.
1023+
1024+
// Explicit flags.
1025+
const wantDev = args.includes('--dev')
1026+
const wantProd = args.includes('--prod')
1027+
const explicitMinify = args.includes('--minify')
10191028
const basePathArg = args.find(a => a.startsWith('--base-path='))
1020-
const basePath = basePathArg
1029+
const explicitBasePath = basePathArg
10211030
? normalizeBasePath(basePathArg.slice('--base-path='.length))
1022-
: ''
1031+
: undefined
1032+
1033+
// Resolve preset. Explicit --dev / --prod wins; otherwise CI env var
1034+
// picks prod. `'CI' in process.env` covers any CI that exports it
1035+
// (GitHub Actions, GitLab CI, CircleCI, most).
1036+
const preset: 'dev' | 'prod' = wantProd
1037+
? 'prod'
1038+
: wantDev
1039+
? 'dev'
1040+
: 'CI' in process.env
1041+
? 'prod'
1042+
: 'dev'
1043+
1044+
// Final knobs — explicit flag beats preset default.
1045+
const minify = explicitMinify || preset === 'prod'
1046+
const basePath =
1047+
explicitBasePath !== undefined
1048+
? explicitBasePath
1049+
: preset === 'prod'
1050+
? PROD_BASE_PATH
1051+
: ''
1052+
10231053
const rest = args.filter(
1024-
a => a !== '--refresh' && a !== '--minify' && !a.startsWith('--base-path='),
1054+
a =>
1055+
a !== '--refresh' &&
1056+
a !== '--minify' &&
1057+
a !== '--dev' &&
1058+
a !== '--prod' &&
1059+
!a.startsWith('--base-path='),
10251060
)
10261061
const command = rest[0]
10271062

1063+
const HELP_TEXT = [
1064+
'pnpm walkthrough — walkthrough generator for the Socket pilot',
1065+
'',
1066+
'Subcommands:',
1067+
' generate <walkthrough.json> Build the walkthrough HTML/CSS/JS.',
1068+
' serve [--port=8080] Start the local dev server.',
1069+
' watch <walkthrough.json> Build + serve + rebuild on source change.',
1070+
' valtown [--name=<valname>] Deploy val/ to Val Town.',
1071+
' token <set|clear|status> Manage the Val Town API token.',
1072+
' doctor Check external-tool prerequisites.',
1073+
'',
1074+
'Presets (apply to build/serve/watch):',
1075+
' --dev Local-friendly: no minify, no base-path.',
1076+
` --prod GH Pages-shaped: --minify + --base-path=${PROD_BASE_PATH}.`,
1077+
' Default: `prod` when the `CI` env var is set, else `dev`.',
1078+
'',
1079+
'Explicit knobs (override presets piecewise):',
1080+
' --minify Minify emitted JS/CSS.',
1081+
' --base-path=/prefix Subdir URL prefix for assets + part links.',
1082+
' --refresh Force-rebuild the meander submodule.',
1083+
'',
1084+
'Show this help: pnpm walkthrough --help (or -h)',
1085+
].join('\n')
1086+
10281087
switch (command) {
1088+
case undefined:
1089+
case '--help':
1090+
case '-h':
1091+
// POSIX convention: --help is a successful request. Stdout, exit 0 —
1092+
// so `pnpm walkthrough --help > help.txt` works and shell checks
1093+
// can detect availability by capturing stdout.
1094+
console.log(HELP_TEXT)
1095+
return
10291096
case 'generate':
10301097
generate(refresh, minify, basePath, rest.slice(1)).catch(
10311098
failWith('generate'),
@@ -1037,8 +1104,8 @@ function main(): void {
10371104
case 'watch':
10381105
watch(refresh, minify, basePath, rest.slice(1)).catch(failWith('watch'))
10391106
break
1040-
case 'deploy-val':
1041-
deployVal(rest.slice(1)).catch(failWith('deploy-val'))
1107+
case 'valtown':
1108+
deployValtown(rest.slice(1)).catch(failWith('valtown'))
10421109
break
10431110
case 'token':
10441111
tokenCli(rest.slice(1)).catch(failWith('token'))
@@ -1047,14 +1114,10 @@ function main(): void {
10471114
doctor().catch(failWith('doctor'))
10481115
break
10491116
default:
1117+
// Unknown command — stderr + non-zero exit, with a pointer to
1118+
// --help rather than dumping the full usage block here.
10501119
console.error(
1051-
'Usage:\n' +
1052-
' pnpm walkthrough [--refresh] [--minify] [--base-path=/prefix] generate <walkthrough.json>\n' +
1053-
' pnpm walkthrough [--base-path=/prefix] serve [--port=8080]\n' +
1054-
' pnpm walkthrough [--minify] [--base-path=/prefix] watch <walkthrough.json>\n' +
1055-
' pnpm walkthrough deploy-val [--name=<valname>]\n' +
1056-
' pnpm walkthrough token <set|clear|status>\n' +
1057-
' pnpm walkthrough doctor',
1120+
`Unknown command: ${command}\n\nRun \`pnpm walkthrough --help\` for usage.`,
10581121
)
10591122
process.exit(1)
10601123
}
@@ -1119,14 +1182,14 @@ function printDeployReceipt(
11191182
appendFileSync(summaryPath, summary + '\n')
11201183
} catch (err) {
11211184
console.warn(
1122-
'[deploy-val] could not write GITHUB_STEP_SUMMARY:',
1185+
'[valtown] could not write GITHUB_STEP_SUMMARY:',
11231186
(err as Error).message,
11241187
)
11251188
}
11261189
}
11271190
}
11281191

1129-
async function deployVal(args: readonly string[]): Promise<void> {
1192+
async function deployValtown(args: readonly string[]): Promise<void> {
11301193
const envFile = path.join(repoRoot, '.env.local')
11311194
if (existsSync(envFile)) {
11321195
loadDotEnv(envFile)

0 commit comments

Comments
 (0)