Skip to content

Commit

Permalink
feat(scully): Add option for open the browser after run the server. (#…
Browse files Browse the repository at this point in the history
…292)

* feat(scully): add open option for serve and watchmode

* docs(scully-cmd-line): add documentation for open option in the CLI

* chore(cli-options): add open alias
  • Loading branch information
jorgeucano authored Feb 12, 2020
1 parent 06b3545 commit 613dcc7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/scully-cmd-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Scully CLI has the following options available:
- [project](#project)
- [baseFilter](#basefilter)
- [removeStaticDist](#removestaticdist)
- [open](#openNavigator)

## serve

Expand Down Expand Up @@ -67,3 +68,11 @@ npx scully --removeStaticDist
```

Alias `--RSD`. Remove the static folder generated by Scully in previous renders.

## open

```bash
npx scully serve/watch --open
```

Alias `--o`. Open the default browser and show the scully dist.
19 changes: 19 additions & 0 deletions scully/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scully/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"marked": "^0.7.0",
"puppeteer": "^2.0.0",
"yamljs": "^0.3.0",
"yargs": "^14.2.0"
"yargs": "^14.2.0",
"open": "^7.0.2"
},
"author": "@herodevs",
"license": "MIT",
Expand Down
9 changes: 8 additions & 1 deletion scully/scully.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {logError, logWarn, yellow} from './utils/log';
import {startScully} from './utils/startup';
import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable';
import {bootServe, isBuildThere, watchMode} from './watchMode';
import {watch, removeStaticDist} from './utils/cli-options';
import {watch, removeStaticDist, openNavigator} from './utils/cli-options';
const open = require('open');

/** the default of 10 is too shallow for generating pages. */
require('events').defaultMaxListeners = 100;
Expand All @@ -40,6 +41,9 @@ if (process.argv.includes('version')) {

if (process.argv.includes('serve')) {
await bootServe(scullyConfig);
if (openNavigator) {
await open(`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
}
} else {
const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder);
/** copy in current build artifacts */
Expand All @@ -63,6 +67,9 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server.
process.exit(15);
}
}
if (openNavigator) {
await open(`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
}
if (watch) {
watchMode(
join(scullyConfig.homeFolder, scullyConfig.distFolder) ||
Expand Down
7 changes: 7 additions & 0 deletions scully/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ export const {argv: options} = yargs.option('port', {
type: 'number',
description: 'The port to run on',
});

export const {openNavigator} = yargs
.boolean('o')
.default('o', false)
.alias('o', 'openNavigator')
.alias('open', 'openNavigator')
.describe('o', 'Use this flag for open the browser with the serve').argv;

0 comments on commit 613dcc7

Please sign in to comment.