Skip to content

Commit

Permalink
fix(app): default serving port flag
Browse files Browse the repository at this point in the history
close #29
  • Loading branch information
vogloblinsky committed Dec 8, 2016
1 parent a6a6d48 commit ea5ec23
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Options:
-o, --open Open the generated documentation
-t, --silent In silent mode, log messages aren't logged in the console
-s, --serve Serve generated documentation (default http://localhost:8080/)
-r, --port [port] Change default serving port
-g, --hideGenerator Do not print the Compodoc link at the bottom of the page
```

Expand Down
15 changes: 11 additions & 4 deletions src/app/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export namespace Application {
defaultAdditionalEntryName = 'Additional documentation',
defaultAdditionalEntryPath = 'additional-documentation',
defaultFolder = './documentation/',
defaultPort = 8080,
defaultTheme = 'gitbook';

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

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

if (program.port) {
defaultPort = program.port;
}

$configuration.mainData.documentationMainName = program.name; //default commander value

$configuration.mainData.base = program.base;
Expand Down Expand Up @@ -442,7 +448,7 @@ export namespace Application {
let finalTime = (new Date() - startTime) / 1000;
logger.info('Documentation generated in ' + defaultFolder + ' in ' + finalTime + ' seconds');
if (program.serve) {
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:8080`);
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:${defaultPort}`);
runWebServer(defaultFolder);
}
}
Expand All @@ -464,7 +470,8 @@ export namespace Application {
root: folder,
open: false,
quiet: true,
logLevel: 0
logLevel: 0,
port: defaultPort
});
}

Expand All @@ -478,7 +485,7 @@ export namespace Application {
logger.fatal(`${program.output} folder doesn't exist`);
process.exit(1);
} else {
logger.info(`Serving documentation from ${program.output} at http://127.0.0.1:8080`);
logger.info(`Serving documentation from ${program.output} at http://127.0.0.1:${defaultPort}`);
runWebServer(program.output);
}
} else if (program.serve && !program.tsconfig && !program.output) {
Expand All @@ -487,7 +494,7 @@ export namespace Application {
logger.fatal('Provide output generated folder with -d flag');
process.exit(1);
} else {
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:8080`);
logger.info(`Serving documentation from ${defaultFolder} at http://127.0.0.1:${defaultPort}`);
runWebServer(defaultFolder);
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/src/cli-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ describe('CLI Options', () => {
expect(runHelp.stdout.toString()).to.contain('Serve generated documentation');
});

it(`-sp`, () => {
expect(runHelp.stdout.toString()).to.contain('-r, --port [port]');
expect(runHelp.stdout.toString()).to.contain('Change default serving port');
});

it(`-g`, () => {
expect(runHelp.stdout.toString()).to.contain('-g, --hideGenerator');
expect(runHelp.stdout.toString()).to.contain('Do not print the Compodoc link at the bottom of the page');
Expand Down

0 comments on commit ea5ec23

Please sign in to comment.