Skip to content

Commit 01a1f0c

Browse files
committed
Add version flag.
1 parent 259fdfb commit 01a1f0c

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎frontend/purestack.studio/guides/getting-started/purestack-cli.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ Every build command requires `--content <dir>`. The path is resolved from the wo
102102

103103
Use `yarn purestack --help` or `yarn purestack help` to print the CLI's own usage summary. Options can be written as `--content ./content` or `--content=./content`.
104104

105+
Use `yarn purestack --version` or `yarn purestack -v` to print the installed PureStack version.
106+
105107
### `build`: generate static files
106108

107109
```sh

‎packages/purestack/src/cli.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
#!/usr/bin/env node
2-
import { runCli } from '@purestack/ts-ssg'
2+
import { readFileSync } from 'node:fs'
33

4-
runCli(process.argv.slice(2)).catch((error) => {
4+
async function main() {
5+
const args = process.argv.slice(2)
6+
if (args[0] === '--version' || args[0] === '-v') {
7+
const { version } = JSON.parse(
8+
readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
9+
)
10+
console.log(version)
11+
return
12+
}
13+
14+
const { runCli } = await import('@purestack/ts-ssg')
15+
await runCli(args)
16+
}
17+
18+
main().catch((error) => {
519
console.error(error)
620
process.exitCode = 1
721
})

‎packages/ts-ssg/src/cli-runner.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,16 @@ class CliUsageError extends Error {
206206
}
207207

208208
const USAGE = `Usage:
209+
purestack --version
209210
purestack build --content <dir> [--clean]
210211
purestack serve --content <dir> [--host <host>] [--port <port>] [--clean] [--no-watch] [--no-reload] [--full-render]
211212
purestack publish --content <dir>
212213
213214
Commands:
214215
build Build a content directory into its configured outDir.
215216
serve Start the dev server; --full-render builds all pages once at startup.
216-
publish Clean and build a publish artifact using the configured publishDir.`
217+
publish Clean and build a publish artifact using the configured publishDir.
218+
219+
Options:
220+
--help, -h Print this usage summary.
221+
--version, -v Print the installed PureStack version.`

0 commit comments

Comments
 (0)