@@ -10,6 +10,7 @@ import invariant from 'tiny-invariant';
10
10
11
11
import { version } from '../../../package.json' ;
12
12
import { build } from '../build' ;
13
+ import { buildIndex as index } from '../buildIndex' ;
13
14
import { dev } from '../dev' ;
14
15
15
16
addToGlobalContext ( 'cliVersion' , versions . storybook ) ;
@@ -133,6 +134,34 @@ command('build')
133
134
} ) . catch ( ( ) => process . exit ( 1 ) ) ;
134
135
} ) ;
135
136
137
+ command ( 'index' )
138
+ . option ( '-o, --output-file <file-name>' , 'JSON file to output index' )
139
+ . option ( '-c, --config-dir <dir-name>' , 'Directory where to load Storybook configurations from' )
140
+ . option ( '--quiet' , 'Suppress verbose build output' )
141
+ . option ( '--loglevel <level>' , 'Control level of logging during build' )
142
+ . action ( async ( options ) => {
143
+ const { env } = process ;
144
+ env . NODE_ENV = env . NODE_ENV || 'production' ;
145
+
146
+ const pkg = await findPackage ( __dirname ) ;
147
+ invariant ( pkg , 'Failed to find the closest package.json file.' ) ;
148
+
149
+ logger . setLevel ( options . loglevel ) ;
150
+ consoleLogger . log ( picocolors . bold ( `${ pkg . name } v${ pkg . version } \n` ) ) ;
151
+
152
+ // The key is the field created in `options` variable for
153
+ // each command line argument. Value is the env variable.
154
+ getEnvConfig ( options , {
155
+ configDir : 'SBCONFIG_CONFIG_DIR' ,
156
+ outputFile : 'SBCONFIG_OUTPUT_FILE' ,
157
+ } ) ;
158
+
159
+ await index ( {
160
+ ...options ,
161
+ packageJson : pkg ,
162
+ } ) . catch ( ( ) => process . exit ( 1 ) ) ;
163
+ } ) ;
164
+
136
165
program . on ( 'command:*' , ( [ invalidCmd ] ) => {
137
166
consoleLogger . error (
138
167
' Invalid command: %s.\n See --help for a list of available commands.' ,
0 commit comments