Skip to content

Commit de6db1a

Browse files
committed
update options structure - use relative paths and search for *.jsx by default
1 parent 94217fe commit de6db1a

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

Readme.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ After re-running your SourceJS app, plugin will be loaded automatically.
2525
Configure path to components in SourceJS `options.js` file:
2626

2727
```javascript
28-
var path = require('path');
29-
3028
module.exports = {
3129
plugins: {
3230
reactStyleguidist: {
33-
rootDir: path.join(global.userPath, 'specs'),
34-
components: './**/*.js'
31+
rootDir: './relative/path/to/components',
32+
components: './**/*.jsx'
3533
}
3634
}
3735
};
@@ -83,10 +81,10 @@ Use SourceJS `options.js` for deep plugin configuration.
8381
- when `String`: a [glob pattern](https://github.com/isaacs/node-glob#glob-primer) that matches all your component modules. Relative to the `rootDir`.
8482
- when `Function`: function that returns an array of modules.
8583

86-
If your components look like `components/Button.js` or `components/Button/Button.js` or `components/Button/index.js`:
84+
If your components look like `components/Button.jsx` or `components/Button/Button.jsx` or `components/Button/index.jsx`:
8785

8886
```javascript
89-
components: './components/**/*.js',
87+
components: './components/**/*.jsx'
9088
```
9189

9290
If your components look like `components/Button/Button.js` + `components/Button/index.js`:

core/middleware/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ var processRequest = function (req, res, next) {
1616
// Check if request is targeting Spec
1717
if (req.specData && req.specData.renderedHtml && req.specData.info.role !== 'navigation') {
1818
var append;
19+
var pathToStyleguide = config._styleguideDir.replace(/^\./, '');
20+
var pathToBundle = config.bundlePath.replace(/^\./, '');
1921

2022
if (global.MODE === 'development') {
2123
append = '<script src="/'+ config.bundlePath +'"></script>'
2224
} else {
23-
append = '<link rel="stylesheet" href="/build/styleguide/build/styles.css"><script src="/build/styleguide/' + config.bundlePath + '"></script>'
25+
append = '<link rel="stylesheet" href="' + pathToStyleguide + '/build/styles.css"><script src="' + pathToStyleguide + pathToBundle + '"></script>'
2426
}
2527

2628
req.specData.renderedHtml += append;

src/utils/config.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ if (global.pathToApp) {
1818

1919
var config = {
2020
enabled: true,
21-
bundlePath: 'build/bundle.js',
21+
bundlePath: './build/bundle.js',
2222

2323
// Public object is exposed to Front-end via options API.
2424
public: {},
2525

2626
// Original styleguidist options
27-
rootDir: path.join(pathToSourceJSUser, 'specs'),
28-
components: './**/*.js',
29-
styleguideDir: path.join(pathToSourceJSUser, 'build/styleguide'),
27+
rootDir: './specs',
28+
components: './**/*.jsx',
29+
styleguideDir: './build/styleguide',
3030

3131
highlightTheme: 'base16-light',
3232
verbose: false,
@@ -58,9 +58,12 @@ function readConfig() {
5858

5959
options = _.merge({}, options, customConfig);
6060

61-
if (customConfig) {
62-
options.rootDir = path.resolve(path.dirname(configFilepath), options.rootDir);
63-
}
61+
// Extend config
62+
options._rootDir = config.rootDir;
63+
options.rootDir = path.join(pathToSourceJSUser, config.rootDir);
64+
65+
options._styleguideDir = config.styleguideDir;
66+
options.styleguideDir = path.join(pathToSourceJSUser, config.styleguideDir);
6467

6568
validateConfig(options);
6669

0 commit comments

Comments
 (0)