1 | #!/usr/bin/env node
|
2 |
|
3 | const chalk = require('chalk');
|
4 | const program = require('commander');
|
5 | const express = require('express');
|
6 | const config = require('./config/express');
|
7 | const app = new express();
|
8 | const { exec } = require('child_process');
|
9 |
|
10 | program
|
11 | .version('0.0.1')
|
12 | .arguments('<path>')
|
13 | .option('-p, --port <port>', 'the port where to serve the files')
|
14 | .option('-U, --user <user>', 'username for http auth')
|
15 | .option('-P, --password <password>', 'password for http auth')
|
16 | .action(function(path) {
|
17 | let options = {
|
18 | port: program.port || 8080,
|
19 | path: path,
|
20 | user: program.user,
|
21 | password: program.password
|
22 | }
|
23 |
|
24 | config(app, options);
|
25 |
|
26 |
|
27 | app.listen(options.port, (error) => {
|
28 | if (!error) {
|
29 | let url = `http://localhost:${options.port}`
|
30 | console.log(chalk.green(`Running ${options.path} on port: ${options.port}`));
|
31 | console.log(chalk.bold.cyan(`Opening ${url}`));
|
32 | exec(`open ${url}`);
|
33 | }
|
34 | });
|
35 |
|
36 | })
|
37 | .parse(process.argv); |
\ | No newline at end of file |