-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdemo.t.ts
More file actions
137 lines (123 loc) · 3.24 KB
/
demo.t.ts
File metadata and controls
137 lines (123 loc) · 3.24 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import t from '../src/t';
// Global options
t.option(
'config',
'Use specified config file',
function (complete) {
complete('vite.config.ts', 'Vite config file');
complete('vite.config.js', 'Vite config file');
},
'c'
);
t.option(
'mode',
'Set env mode',
function (complete) {
complete('development', 'Development mode');
complete('production', 'Production mode');
},
'm'
);
t.option(
'logLevel',
'info | warn | error | silent',
function (complete) {
complete('info', 'Info level');
complete('warn', 'Warn level');
complete('error', 'Error level');
complete('silent', 'Silent level');
},
'l'
);
// Root command argument
t.argument('project', function (complete) {
complete('my-app', 'My application');
complete('my-lib', 'My library');
complete('my-tool', 'My tool');
});
// Dev command
const devCmd = t.command('dev', 'Start dev server');
devCmd.option(
'host',
'Specify hostname',
function (complete) {
complete('localhost', 'Localhost');
complete('0.0.0.0', 'All interfaces');
},
'H'
);
devCmd.option(
'port',
'Specify port',
function (complete) {
complete('3000', 'Development server port');
complete('8080', 'Alternative port');
},
'p'
);
devCmd.option('verbose', 'Enable verbose logging', 'v');
// Serve command
const serveCmd = t.command('serve', 'Start the server');
serveCmd.option(
'host',
'Specify hostname',
function (complete) {
complete('localhost', 'Localhost');
complete('0.0.0.0', 'All interfaces');
},
'H'
);
serveCmd.option(
'port',
'Specify port',
function (complete) {
complete('3000', 'Development server port');
complete('8080', 'Alternative port');
},
'p'
);
// Build command
t.command('dev build', 'Build project');
// Start command
t.command('dev start', 'Start development server');
// Copy command with multiple arguments
const copyCmd = t
.command('copy', 'Copy files')
.argument('source', function (complete) {
complete('src/', 'Source directory');
complete('dist/', 'Distribution directory');
complete('public/', 'Public assets');
})
.argument('destination', function (complete) {
complete('build/', 'Build output');
complete('release/', 'Release directory');
complete('backup/', 'Backup location');
});
// Lint command with variadic arguments
const lintCmd = t.command('lint', 'Lint project').argument(
'files',
function (complete) {
complete('main.ts', 'Main file');
complete('index.ts', 'Index file');
complete('src/', 'Source directory');
complete('tests/', 'Tests directory');
},
true
); // Variadic argument for multiple files
// Handle completion command
if (process.argv[2] === 'complete') {
const shell = process.argv[3];
if (shell && ['zsh', 'bash', 'fish', 'powershell'].includes(shell)) {
t.setup('vite', 'pnpm tsx examples/demo.t.ts', shell);
} else {
// Parse completion arguments (everything after --)
const separatorIndex = process.argv.indexOf('--');
const completionArgs =
separatorIndex !== -1 ? process.argv.slice(separatorIndex + 1) : [];
t.parse(completionArgs);
}
} else {
// Regular CLI usage (just show help for demo)
console.log('Vite CLI Demo');
console.log('Use "complete" command for shell completion');
}