Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scully): Add option for open the browser after run the server. #292

Merged
merged 3 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions scully/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ 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')
.describe('o', 'Use this flag for open the browser with the serve').argv;