-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·52 lines (44 loc) · 1.28 KB
/
cli.js
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
#!/usr/bin/env node
import { createServer } from 'vite';
import path from 'path';
import { fileURLToPath } from 'url';
import react from '@vitejs/plugin-react';
import dynamicImport from 'vite-plugin-dynamic-import';
import tailwindcss from '@tailwindcss/vite'
import { Command } from 'commander';
import fileTreePlugin from './plugins/file-tree.js';
const program = new Command();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
program
.name('react-pdf')
.description('CLI for react-pdf to preview pdf files')
.option('--dir <path>', 'path to templates directory', 'src/templates')
.option('--port <port>', 'port to run on', '3000')
.parse();
const options = program.opts();
async function startServer() {
try {
const server = await createServer({
root: path.join(__dirname, 'src'),
server: {
port: options.port,
},
resolve: {
alias: { "@": path.join(process.cwd(), options.dir) },
},
plugins: [
react(),
tailwindcss(),
fileTreePlugin(options.dir),
dynamicImport(),
],
});
await server.listen();
server.printUrls();
} catch (error) {
console.error("Error starting Vite server:", error);
process.exit(1);
}
}
startServer();