diff --git a/bin/styleguidist.js b/bin/styleguidist.js index 955bad54d..e90fb0700 100755 --- a/bin/styleguidist.js +++ b/bin/styleguidist.js @@ -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); } }); @@ -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 }); + } } }); @@ -175,12 +181,15 @@ 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}`); @@ -188,6 +197,13 @@ function printInstructions(isHttps, host, port) { 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 diff --git a/docs/Configuration.md b/docs/Configuration.md index 180bdcb79..e5f0ac720 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -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) @@ -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 diff --git a/examples/customised/styleguide.config.js b/examples/customised/styleguide.config.js index f7e9a5f9a..d12b0acf9 100644 --- a/examples/customised/styleguide.config.js +++ b/examples/customised/styleguide.config.js @@ -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'), diff --git a/scripts/schemas/config.js b/scripts/schemas/config.js index 303badf5f..fc1e52cf7 100644 --- a/scripts/schemas/config.js +++ b/scripts/schemas/config.js @@ -132,6 +132,12 @@ module.exports = { type: 'number', default: 500, }, + printBuildInstructions: { + type: 'function', + }, + printServerInstructions: { + type: 'function', + }, propsParser: { type: 'function', },