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

Spike on rearranging the build and server methods. #878

Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 23 additions & 7 deletions bin/styleguidist.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ function commandBuild() {
if (err) {
console.error(err);
process.exit(1);
} else if (config.printBuildInstructions) {
config.printBuildInstructions(config);
} else {
console.log('Style guide published to:\n' + chalk.underline(config.styleguideDir));
printBuildInstructions(config);
}
});

Expand All @@ -120,7 +122,11 @@ function commandServer() {
console.error(err);
} else {
const isHttps = compiler.options.devServer && compiler.options.devServer.https;
printInstructions(isHttps, config.serverHost, config.serverPort);
if (config.printServerInstructions) {
config.printServerInstructions(config, { isHttps });
} else {
printServerInstructions(config, { isHttps });
}
}
});

Expand Down Expand Up @@ -175,19 +181,29 @@ function commandHelp() {
}

/**
* @param {boolean} isHttps
* @param {string} host
* @param {number} port
* @param {object} config
* @param {options} options
*/
function printInstructions(isHttps, host, port) {
const urls = webpackDevServerUtils.prepareUrls(isHttps ? 'https' : 'http', host, port);
function printServerInstructions(config, options) {
const urls = webpackDevServerUtils.prepareUrls(
options.isHttps ? 'https' : 'http',
config.serverHost,
config.serverPort
);
console.log(`You can now view your style guide in the browser:`);
console.log();
console.log(` ${chalk.bold('Local:')} ${urls.localUrlForTerminal}`);
console.log(` ${chalk.bold('On your network:')} ${urls.lanUrlForTerminal}`);
console.log();
}

/**
* @param {object} config
*/
function printBuildInstructions(config) {
console.log('Style guide published to:\n' + chalk.underline(config.styleguideDir));
}

/**
* @param {string} message
* @param {string} linkTitle
Expand Down
30 changes: 30 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje
* [`ignore`](#ignore)
* [`logger`](#logger)
* [`pagePerSection`](#pagepersection)
* [`printBuildInstructions`](#printbuildinstructions)
* [`printServerInstructions`](#printserverinstructions)
* [`previewDelay`](#previewdelay)
* [`propsParser`](#propsparser)
* [`require`](#require)
Expand Down Expand Up @@ -279,6 +281,34 @@ module.exports = {
}
```

#### `printBuildInstructions`

Type: `Function`, optional

Function that allows you to override the printing of build messages to console.log.

```javascript
module.exports = {
printBuildInstructions(config) {
console.log('Style guide published to ${config.styleguideDir}. Something else interesting.');
},
}
```

#### `printServerInstructions`

Type: `Function`, optional

Function that allows you to override the printing of local dev server messages to console.log.

```javascript
module.exports = {
serverHost: 'your-domain',
printServerInstructions(config) {
console.log(`'Local style guide: http://${config.serverHost}`);
},
```

#### `previewDelay`

Type: `Number`, default: 500
Expand Down
9 changes: 9 additions & 0 deletions examples/customised/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ module.exports = {
const name = path.basename(componentPath, '.js');
return `import { ${name} } from 'my-awesome-library';`;
},

// Example of overriding the CLI message in local development.
// Uncomment/edit the following `serverHost` entry to see in output
// serverHost: 'your-domain',
printServerInstructions(config) {
// eslint-disable-next-line no-console
console.log(`View your styleguide at: http://${config.serverHost}`);
},

// Override Styleguidist components
styleguideComponents: {
LogoRenderer: path.join(__dirname, 'styleguide/components/Logo'),
Expand Down
6 changes: 6 additions & 0 deletions scripts/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ module.exports = {
type: 'number',
default: 500,
},
printBuildInstructions: {
type: 'function',
},
printServerInstructions: {
type: 'function',
},
propsParser: {
type: 'function',
},
Expand Down