-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 4 commits
30f2a86
1bc7d1d
dc80be8
9916f14
0eda93b
e708db0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,8 +94,10 @@ function commandBuild() { | |
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} else if (typeof config.printBuildInstructions === 'function') { | ||
config.printBuildInstructions(config); | ||
} else { | ||
console.log('Style guide published to:\n' + chalk.underline(config.styleguideDir)); | ||
printBuildInstructions(config); | ||
} | ||
}); | ||
|
||
|
@@ -120,7 +122,12 @@ function commandServer() { | |
console.error(err); | ||
} else { | ||
const isHttps = compiler.options.devServer && compiler.options.devServer.https; | ||
printInstructions(isHttps, config.serverHost, config.serverPort); | ||
const configuration = Object.assign({ isHttps }, config); | ||
if (typeof config.printServerInstructions === 'function') { | ||
config.printServerInstructions(configuration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Fixed in 0eda93b |
||
} else { | ||
printServerInstructions(configuration); | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -175,19 +182,28 @@ function commandHelp() { | |
} | ||
|
||
/** | ||
* @param {boolean} isHttps | ||
* @param {string} host | ||
* @param {number} port | ||
* @param {object} config | ||
*/ | ||
function printInstructions(isHttps, host, port) { | ||
const urls = webpackDevServerUtils.prepareUrls(isHttps ? 'https' : 'http', host, port); | ||
function printServerInstructions(config) { | ||
const urls = webpackDevServerUtils.prepareUrls( | ||
config.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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje | |
* [`handlers`](#handlers) | ||
* [`ignore`](#ignore) | ||
* [`logger`](#logger) | ||
* [`printBuildInstructions`](#printBuildInstructions) | ||
* [`printServerInstructions`](#printServerInstructions) | ||
* [`previewDelay`](#previewdelay) | ||
* [`propsParser`](#propsparser) | ||
* [`require`](#require) | ||
|
@@ -259,6 +261,18 @@ module.exports = { | |
} | ||
``` | ||
|
||
#### `printBuildInstructions` | ||
|
||
Type: `Function`, optional | ||
|
||
Function that allows you to override the printing of build messages to console.log. Takes the `config` object with `isHttps` merged in. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’d show an example instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great point. I removed and added example for both methods in 0eda93b |
||
|
||
#### `printServerInstructions` | ||
|
||
Type: `Function`, optional | ||
|
||
Function that allows you to override the printing of build messages to console.log. Takes the `config` object with `isHttps` merged in. | ||
|
||
#### `previewDelay` | ||
|
||
Type: `Number`, default: 500 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ const CLIENT_CONFIG_OPTIONS = [ | |
'showCode', | ||
'showUsage', | ||
'showSidebar', | ||
'printBuildInstructions', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this, we use this array to pass config options to React. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed and ran locally and nothing bad happened. Thanks for heads up |
||
'printServerInstructions', | ||
'previewDelay', | ||
'theme', | ||
'styles', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be sure that if a config option has a value, then it's a function (it'd fail before otherwise), so
if (config.printBuildInstructions)
would be enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 0eda93b