projview 0.2.3 → 0.2.4
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.
- package/bin/projview.js +10 -3
- package/package.json +1 -1
package/bin/projview.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
5
6
|
import { startServer } from '../src/server.js';
|
|
6
7
|
|
|
7
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
9
|
const DEMO_DIR = path.join(__dirname, '..', 'docs'); // bundled sample docs
|
|
10
|
+
const VERSION = JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version;
|
|
9
11
|
|
|
10
12
|
function parseArgs(argv) {
|
|
11
13
|
const opts = {
|
|
@@ -20,7 +22,9 @@ function parseArgs(argv) {
|
|
|
20
22
|
if (arg === '--port' || arg === '-p') opts.port = Number(argv[++i]) || opts.port;
|
|
21
23
|
else if (arg === '--no-open') opts.open = false;
|
|
22
24
|
else if (arg === '--demo') opts.demo = true;
|
|
25
|
+
else if (arg === '--version' || arg === '-v') opts.version = true;
|
|
23
26
|
else if (arg === '--help' || arg === '-h') opts.help = true;
|
|
27
|
+
else if (arg.startsWith('-')) opts.unknown = arg; // unrecognised flag -> error, don't treat as a path
|
|
24
28
|
else rest.push(arg);
|
|
25
29
|
}
|
|
26
30
|
if (rest[0]) opts.root = path.resolve(process.cwd(), rest[0]);
|
|
@@ -49,15 +53,18 @@ options:
|
|
|
49
53
|
-p, --port <n> preferred port (default: 4321, climbs if taken)
|
|
50
54
|
--demo preview projview's bundled sample docs
|
|
51
55
|
--no-open do not auto-open the browser
|
|
56
|
+
-v, --version print the version and exit
|
|
52
57
|
-h, --help show this help
|
|
53
58
|
|
|
54
59
|
nothing is written to disk - ctrl-c and it's gone.`;
|
|
55
60
|
|
|
56
61
|
async function main() {
|
|
57
62
|
const opts = parseArgs(process.argv.slice(2));
|
|
58
|
-
if (opts.help) {
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
if (opts.help) { console.log(HELP); return; }
|
|
64
|
+
if (opts.version) { console.log(VERSION); return; }
|
|
65
|
+
if (opts.unknown) {
|
|
66
|
+
console.error(`projview: unknown option "${opts.unknown}"\nrun "projview --help" for usage.`);
|
|
67
|
+
process.exit(1);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
const { port, close } = await startServer(opts.root, { port: opts.port, host: opts.host });
|