Skip to content

Commit 613dcc7

Browse files
authored
feat(scully): Add option for open the browser after run the server. (#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
1 parent 06b3545 commit 613dcc7

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

docs/scully-cmd-line.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Scully CLI has the following options available:
1111
- [project](#project)
1212
- [baseFilter](#basefilter)
1313
- [removeStaticDist](#removestaticdist)
14+
- [open](#openNavigator)
1415

1516
## serve
1617

@@ -67,3 +68,11 @@ npx scully --removeStaticDist
6768
```
6869

6970
Alias `--RSD`. Remove the static folder generated by Scully in previous renders.
71+
72+
## open
73+
74+
```bash
75+
npx scully serve/watch --open
76+
```
77+
78+
Alias `--o`. Open the default browser and show the scully dist.

scully/package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scully/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"marked": "^0.7.0",
2323
"puppeteer": "^2.0.0",
2424
"yamljs": "^0.3.0",
25-
"yargs": "^14.2.0"
25+
"yargs": "^14.2.0",
26+
"open": "^7.0.2"
2627
},
2728
"author": "@herodevs",
2829
"license": "MIT",

scully/scully.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {logError, logWarn, yellow} from './utils/log';
1515
import {startScully} from './utils/startup';
1616
import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable';
1717
import {bootServe, isBuildThere, watchMode} from './watchMode';
18-
import {watch, removeStaticDist} from './utils/cli-options';
18+
import {watch, removeStaticDist, openNavigator} from './utils/cli-options';
19+
const open = require('open');
1920

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

4142
if (process.argv.includes('serve')) {
4243
await bootServe(scullyConfig);
44+
if (openNavigator) {
45+
await open(`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
46+
}
4347
} else {
4448
const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder);
4549
/** copy in current build artifacts */
@@ -63,6 +67,9 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server.
6367
process.exit(15);
6468
}
6569
}
70+
if (openNavigator) {
71+
await open(`http://${scullyConfig.hostName}:${scullyConfig.staticport}/`);
72+
}
6673
if (watch) {
6774
watchMode(
6875
join(scullyConfig.homeFolder, scullyConfig.distFolder) ||

scully/utils/cli-options.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ export const {argv: options} = yargs.option('port', {
1717
type: 'number',
1818
description: 'The port to run on',
1919
});
20+
21+
export const {openNavigator} = yargs
22+
.boolean('o')
23+
.default('o', false)
24+
.alias('o', 'openNavigator')
25+
.alias('open', 'openNavigator')
26+
.describe('o', 'Use this flag for open the browser with the serve').argv;

0 commit comments

Comments
 (0)