1- var fs = require ( 'fs' ) ;
21var path = require ( 'path' ) ;
3- var findup = require ( 'findup ' ) ;
2+ var fs = require ( 'fs ' ) ;
43var minimist = require ( 'minimist' ) ;
54var prettyjson = require ( 'prettyjson' ) ;
6- var _ = require ( 'lodash' ) ;
75var utils = require ( './server' ) ;
6+ var _ = require ( 'lodash' ) ;
7+
8+ var sourceJSUtils ;
9+ var globalConfig ;
10+ var pathToSourceJSUser = '' ;
11+
12+ if ( global . pathToApp ) {
13+ sourceJSUtils = require ( path . join ( global . pathToApp , 'core/lib/utils' ) ) ;
14+ globalConfig = global . opts . plugins && global . opts . plugins . reactStyleguidist ? global . opts . plugins . reactStyleguidist : { } ;
15+
16+ pathToSourceJSUser = global . userPath ;
17+ }
18+
19+ var config = {
20+ enabled : true ,
21+ bundlePath : 'build/bundle.js' ,
22+
23+ // Public object is exposed to Front-end via options API.
24+ public : { } ,
25+
26+ // Original styleguidist options
27+ rootDir : path . join ( pathToSourceJSUser , 'specs' ) ,
28+ components : './**/*.js' ,
29+ styleguideDir : path . join ( pathToSourceJSUser , 'build/styleguide' ) ,
830
9- var CONFIG_FILENAME = 'styleguide.config.js' ;
10- var DEFAULT_CONFIG = {
11- rootDir : null ,
12- components : null ,
13- title : 'Style guide' ,
14- styleguideDir : 'styleguide' ,
15- template : path . join ( __dirname , '../templates/index.html' ) ,
16- serverHost : 'localhost' ,
17- serverPort : 3000 ,
1831 highlightTheme : 'base16-light' ,
1932 verbose : false ,
2033 getExampleFilename : function ( componentpath ) {
21- return path . join ( path . dirname ( componentpath ) , 'Readme .md' ) ;
34+ return path . join ( path . dirname ( componentpath ) , 'readme .md' ) ;
2235 } ,
2336 updateWebpackConfig : null
37+
38+ // Not used in SourceJS integration
39+ // title: 'Style guide',
40+ // template: path.join(__dirname, '../templates/index.html'),
41+ // serverHost: 'localhost',
42+ // serverPort: 3000,
2443} ;
2544
45+ if ( sourceJSUtils ) {
46+ sourceJSUtils . extendOptions ( config , globalConfig ) ;
47+ }
48+
2649function readConfig ( ) {
2750 var argv = minimist ( process . argv . slice ( 2 ) ) ;
2851 var configFilepath = findConfig ( argv ) ;
52+ var customConfig = { } ;
53+ var options = config ;
2954
30- var options = require ( configFilepath ) ;
31-
32- validateConfig ( options ) ;
55+ if ( configFilepath ) {
56+ customConfig = require ( configFilepath ) ;
57+ }
3358
34- var configDir = path . dirname ( configFilepath ) ;
35- var rootDir = path . resolve ( configDir , options . rootDir ) ;
59+ options = _ . merge ( { } , options , customConfig ) ;
3660
37- if ( rootDir === configDir ) {
38- throw Error ( 'Styleguidist: "rootDir" should not point to a folder with the Styleguidist config and node_modules folder' ) ;
39- }
40- if ( ! utils . isDirectoryExists ( rootDir ) ) {
41- throw Error ( 'Styleguidist: "rootDir" directory not found: ' + rootDir ) ;
61+ if ( customConfig ) {
62+ options . rootDir = path . resolve ( path . dirname ( configFilepath ) , options . rootDir ) ;
4263 }
4364
44- options = _ . merge ( { } , DEFAULT_CONFIG , options ) ;
45- options = _ . merge ( { } , options , {
46- verbose : ! ! argv . verbose ,
47- rootDir : rootDir ,
48- styleguideDir : path . resolve ( configDir , options . styleguideDir )
49- } ) ;
65+ validateConfig ( options ) ;
5066
5167 if ( options . verbose ) {
5268 console . log ( ) ;
53- console . log ( 'Using config file:' , configFilepath ) ;
5469 console . log ( prettyjson . render ( options ) ) ;
5570 console . log ( ) ;
5671 }
5772
73+ if ( options . rootDir === global . userPath ) {
74+ throw Error ( 'Styleguidist: "rootDir" should not point to folder with node_modules' ) ;
75+ }
76+ if ( ! utils . isDirectoryExists ( options . rootDir ) ) {
77+ throw Error ( 'Styleguidist: "rootDir" directory not found: ' + options . rootDir ) ;
78+ }
79+
5880 return options ;
5981}
6082
@@ -69,19 +91,6 @@ function findConfig(argv) {
6991
7092 return configFilepath ;
7193 }
72- else {
73- // Search config file in all parent directories
74-
75- var configDir ;
76- try {
77- configDir = findup . sync ( __dirname , CONFIG_FILENAME ) ;
78- }
79- catch ( e ) {
80- throw Error ( 'Styleguidist config not found: ' + CONFIG_FILENAME + '.' ) ;
81- }
82-
83- return path . join ( configDir , CONFIG_FILENAME ) ;
84- }
8594}
8695
8796function validateConfig ( options ) {
0 commit comments