Skip to content

Commit ea5ec23

Browse files
committed
fix(app): default serving port flag
close #29
1 parent a6a6d48 commit ea5ec23

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Options:
9191
-o, --open Open the generated documentation
9292
-t, --silent In silent mode, log messages aren't logged in the console
9393
-s, --serve Serve generated documentation (default http://localhost:8080/)
94+
-r, --port [port] Change default serving port
9495
-g, --hideGenerator Do not print the Compodoc link at the bottom of the page
9596
```
9697

src/app/application.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export namespace Application {
3434
defaultAdditionalEntryName = 'Additional documentation',
3535
defaultAdditionalEntryPath = 'additional-documentation',
3636
defaultFolder = './documentation/',
37+
defaultPort = 8080,
3738
defaultTheme = 'gitbook';
3839

3940
program
@@ -49,6 +50,7 @@ export namespace Application {
4950
//.option('-j, --includesName [name]', 'Name of item menu of externals markdown file')
5051
.option('-t, --silent', 'In silent mode, log messages aren\'t logged in the console', false)
5152
.option('-s, --serve', 'Serve generated documentation (default http://localhost:8080/)', false)
53+
.option('-r, --port [port]', 'Change default serving port')
5254
.option('-g, --hideGenerator', 'Do not print the Compodoc link at the bottom of the page', false)
5355
.parse(process.argv);
5456

@@ -74,6 +76,10 @@ export namespace Application {
7476
$configuration.mainData.theme = defaultTheme;
7577
}
7678

79+
if (program.port) {
80+
defaultPort = program.port;
81+
}
82+
7783
$configuration.mainData.documentationMainName = program.name; //default commander value
7884

7985
$configuration.mainData.base = program.base;
@@ -442,7 +448,7 @@ export namespace Application {
442448
let finalTime = (new Date() - startTime) / 1000;
443449
logger.info('Documentation generated in ' + defaultFolder + ' in ' + finalTime + ' seconds');
444450
if (program.serve) {
445-
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:8080`);
451+
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:${defaultPort}`);
446452
runWebServer(defaultFolder);
447453
}
448454
}
@@ -464,7 +470,8 @@ export namespace Application {
464470
root: folder,
465471
open: false,
466472
quiet: true,
467-
logLevel: 0
473+
logLevel: 0,
474+
port: defaultPort
468475
});
469476
}
470477

@@ -478,7 +485,7 @@ export namespace Application {
478485
logger.fatal(`${program.output} folder doesn't exist`);
479486
process.exit(1);
480487
} else {
481-
logger.info(`Serving documentation from ${program.output} at http://127.0.0.1:8080`);
488+
logger.info(`Serving documentation from ${program.output} at http://127.0.0.1:${defaultPort}`);
482489
runWebServer(program.output);
483490
}
484491
} else if (program.serve && !program.tsconfig && !program.output) {
@@ -487,7 +494,7 @@ export namespace Application {
487494
logger.fatal('Provide output generated folder with -d flag');
488495
process.exit(1);
489496
} else {
490-
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:8080`);
497+
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:${defaultPort}`);
491498
runWebServer(defaultFolder);
492499
}
493500
} else {

test/src/cli-options.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ describe('CLI Options', () => {
7171
expect(runHelp.stdout.toString()).to.contain('Serve generated documentation');
7272
});
7373

74+
it(`-sp`, () => {
75+
expect(runHelp.stdout.toString()).to.contain('-r, --port [port]');
76+
expect(runHelp.stdout.toString()).to.contain('Change default serving port');
77+
});
78+
7479
it(`-g`, () => {
7580
expect(runHelp.stdout.toString()).to.contain('-g, --hideGenerator');
7681
expect(runHelp.stdout.toString()).to.contain('Do not print the Compodoc link at the bottom of the page');

0 commit comments

Comments
 (0)