UNPKG

2.48 kBPlain TextView Raw
1import * as program from 'commander';
2import * as fs from 'fs-extra';
3import { CommandLineOptions } from '../index.d.ts';
4
5const packageJSON: {
6 version: string;
7} = JSON.parse(fs.readFileSync('./package.json').toString());
8
9program
10 .version(packageJSON.version)
11 .option('-p, --port [port]', 'Specify the server\'s port')
12 // .option('-nw, --no-watch-files', 'Do not watch files in current directory and do not reload browser on changes')
13 // .option('--ts-warning', 'Report TypeScript errors in the browser console as warnings')
14 // .option('--ts-error', 'Report TypeScript errors in the browser console as errors')
15 .option('--build-static', 'Create a static build of the current working directory. The output will be in a directory called dist in the current working directory')
16 .option('--target [target]', 'The ECMAScript version to compile to; if omitted, defaults to ES2015. Any targets supported by the TypeScript compiler are supported here (ES3, ES5, ES6/ES2015, ES2016, ES2017, ESNext)')
17 .option('--disable-spa', 'Disable the SPA redirect to index.html')
18 .option('--exclude [exclude]', 'A comma-separated list of paths, relative to the current directory, to exclude from the static build') //TODO I know this is wrong, I need to figure out how to do variadic arguments
19 .option('--include [include]', 'A comma-separated list of paths, relative to the current directory, to include in the static build') //TODO I know this is wrong, I need to figure out how to do variadic arguments
20 .option('--headers [headers]', 'A path to a file, relative to the current directory, for custom HTTP headers')
21 .parse(process.argv);
22
23// TODO understand how null and undefined are going to work here
24const buildStatic: boolean = program.buildStatic || false;
25// const watchFiles: boolean = program.watchFiles || true;
26const watchFiles: boolean = true;
27const httpPort: number = parseInt(program.port || 5000);
28const wsPort: number = httpPort + 1;
29const jsTarget: string = program.target || 'ES2015';
30const exclude: string | undefined = program.exclude;
31const include: string | undefined = program.include;
32const disableSpa: boolean = program.disableSpa || false;
33const customHTTPHeadersFilePath: string | undefined = program.headers;
34
35export const commandLineOptions: Readonly<CommandLineOptions> = {
36 buildStatic,
37 watchFiles,
38 httpPort,
39 wsPort,
40 jsTarget,
41 exclude,
42 include,
43 disableSpa,
44 customHTTPHeadersFilePath
45};
\No newline at end of file