Skip to content

Commit 79c24c2

Browse files
committed
Introduce a "--storybook" CLI parameter for "heft start"
1 parent 9b7b261 commit 79c24c2

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

apps/heft/src/cli/actions/StartAction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Logging } from '../../utilities/Logging';
1010
export class StartAction extends HeftActionBase {
1111
private _buildStandardParameters!: IBuildStageStandardParameters;
1212
private _cleanFlag!: CommandLineFlagParameter;
13+
private _storybookFlag!: CommandLineFlagParameter;
1314

1415
public constructor(heftActionOptions: IHeftActionBaseOptions) {
1516
super(
@@ -31,6 +32,13 @@ export class StartAction extends HeftActionBase {
3132
parameterLongName: '--clean',
3233
description: 'If specified, clean the package before starting the development server.'
3334
});
35+
36+
// TODO: Expose an API for custom CLI parameters similar to HeftSession.registerAction()
37+
this._storybookFlag = this.defineFlagParameter({
38+
parameterLongName: '--storybook',
39+
description:
40+
'(EXPERIMENTAL) Used by the "@rushstack/heft-storybook-plugin" package to launch Storybook.'
41+
});
3442
}
3543

3644
protected async actionExecuteAsync(): Promise<void> {
@@ -52,6 +60,7 @@ export class StartAction extends HeftActionBase {
5260
watchMode: true,
5361
serveMode: true
5462
};
63+
5564
await buildStage.initializeAsync(buildStageOptions);
5665
await buildStage.executeAsync();
5766
}

apps/heft/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Optional arguments:
6767
exports[`CommandLineHelp prints the help for each action: start 1`] = `
6868
"usage: heft start [-h] [-v] [--production] [--locale LOCALE] [-l]
6969
[--typescript-max-write-parallelism PARALLEILSM]
70-
[--max-old-space-size SIZE] [--clean]
70+
[--max-old-space-size SIZE] [--clean] [--storybook]
7171
7272
7373
Optional arguments:
@@ -85,6 +85,9 @@ Optional arguments:
8585
Used to specify the max old space size.
8686
--clean If specified, clean the package before starting the
8787
development server.
88+
--storybook (EXPERIMENTAL) Used by the
89+
\\"@rushstack/heft-storybook-plugin\\" package to launch
90+
Storybook.
8891
"
8992
`;
9093

build-tests-samples/heft-storybook-react-tutorial/.vscode/launch.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "launch",
10-
"name": "Debug fake.js",
11-
"program": "${workspaceFolder}/fake.js",
12-
"args": [ "-p", "6006"],
13-
"cwd": "${workspaceFolder}",
14-
"console": "integratedTerminal",
15-
"sourceMaps": false
16-
},
177
{
188
"type": "node",
199
"request": "launch",
2010
"name": "Debug \"heft start\"",
2111
"program": "${workspaceFolder}/node_modules/@rushstack/heft/lib/start.js",
2212
"cwd": "${workspaceFolder}",
23-
"args": ["--debug", "start"],
13+
"args": ["--debug", "start", "--storybook"],
2414
"console": "integratedTerminal",
25-
"sourceMaps": true
15+
"sourceMaps": false
2616
},
2717
]
2818
}

heft-plugins/heft-storybook-plugin/src/StorybookPlugin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export class StorybookPlugin implements IHeftPlugin<IStorybookPluginOptions> {
7575
this._startupModulePath = options.startupModulePath;
7676

7777
heftSession.hooks.build.tap(PLUGIN_NAME, (build: IBuildStageContext) => {
78+
// TODO: Expose an API for custom CLI parameters similar to HeftSession.registerAction()
79+
if (process.argv.indexOf('--storybook') < 0) {
80+
this._logger.terminal.writeVerboseLine(
81+
'The command line does not include "--storybook", so bundling will proceed without Storybook'
82+
);
83+
return;
84+
}
85+
86+
this._logger.terminal.writeVerboseLine(
87+
'The command line includes "--storybook", redirecting Webpack to Storybook'
88+
);
89+
7890
build.hooks.preCompile.tap(PLUGIN_NAME, (preCompile: IPreCompileSubstage) => {
7991
preCompile.hooks.run.tap(PLUGIN_NAME, () => {
8092
this._onPreCompile(heftSession, heftConfiguration);

0 commit comments

Comments
 (0)