Skip to content

Commit d4357e1

Browse files
committed
Task: Add ability to skip stories/addons
1 parent 6c5c6f4 commit d4357e1

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

scripts/task.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ export const options = createOptions({
163163
description: 'Store results in junit format?',
164164
promptType: false,
165165
},
166+
skipTemplateStories: {
167+
type: 'boolean',
168+
description: 'Do not include template stories and their addons',
169+
promptType: false,
170+
},
166171
});
167172

168173
type PassedOptionValues = Omit<OptionValues<typeof options>, 'task' | 'startFrom' | 'junit'>;

scripts/tasks/sandbox-parts.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const essentialsAddons = [
4040

4141
export const create: Task['run'] = async (
4242
{ key, template, sandboxDir },
43-
{ addon: addons, fromLocalRepro, dryRun, debug }
43+
{ addon: addons, fromLocalRepro, dryRun, debug, skipTemplateStories }
4444
) => {
4545
const parentDir = resolve(sandboxDir, '..');
4646
await ensureDir(parentDir);
@@ -70,9 +70,11 @@ export const create: Task['run'] = async (
7070
}
7171

7272
const cwd = sandboxDir;
73-
for (const addon of addons) {
74-
const addonName = `@storybook/addon-${addon}`;
75-
await executeCLIStep(steps.add, { argument: addonName, cwd, dryRun, debug });
73+
if (!skipTemplateStories) {
74+
for (const addon of addons) {
75+
const addonName = `@storybook/addon-${addon}`;
76+
await executeCLIStep(steps.add, { argument: addonName, cwd, dryRun, debug });
77+
}
7678
}
7779

7880
const mainConfig = await readMainConfig({ cwd });
@@ -231,8 +233,6 @@ function setSandboxViteFinal(mainConfig: ConfigFile) {
231233
);
232234
}
233235

234-
235-
236236
// Update the stories field to ensure that no TS files
237237
// that are linked from the renderer are picked up in non-TS projects
238238
function updateStoriesField(mainConfig: ConfigFile, isJs: boolean) {
@@ -244,7 +244,6 @@ function updateStoriesField(mainConfig: ConfigFile, isJs: boolean) {
244244
? stories.map((specifier) => specifier.replace('js|jsx|ts|tsx', 'js|jsx'))
245245
: stories;
246246

247-
248247
mainConfig.setFieldValue(['stories'], [...updatedStories]);
249248
}
250249

@@ -257,7 +256,7 @@ function addStoriesEntry(mainConfig: ConfigFile, path: string) {
257256
titlePrefix: path,
258257
files: '**/*.@(mdx|stories.@(js|jsx|ts|tsx))',
259258
};
260-
259+
261260
mainConfig.setFieldValue(['stories'], [...stories, entry]);
262261
}
263262

@@ -278,7 +277,7 @@ async function linkPackageStories(
278277
: resolve(cwd, 'template-stories', packageDir);
279278
await ensureSymlink(source, target);
280279

281-
if (!linkInDir) addStoriesEntry(mainConfig, packageDir)
280+
if (!linkInDir) addStoriesEntry(mainConfig, packageDir);
282281

283282
// Add `previewAnnotation` entries of the form
284283
// './template-stories/lib/store/preview.[tj]s'
@@ -320,7 +319,6 @@ function addExtraDependencies({
320319
}
321320
}
322321

323-
324322
export const addStories: Task['run'] = async (
325323
{ sandboxDir, template },
326324
{ addon: extraAddons, dryRun, debug }
@@ -332,11 +330,7 @@ export const addStories: Task['run'] = async (
332330

333331
// Ensure that we match the right stories in the stories directory
334332
const packageJson = await import(join(cwd, 'package.json'));
335-
updateStoriesField(
336-
mainConfig,
337-
detectLanguage(packageJson) === SupportedLanguage.JAVASCRIPT
338-
);
339-
333+
updateStoriesField(mainConfig, detectLanguage(packageJson) === SupportedLanguage.JAVASCRIPT);
340334

341335
// Link in the template/components/index.js from store, the renderer and the addons
342336
const rendererPath = await workspacePath('renderer', template.expected.renderer);
@@ -345,7 +339,7 @@ export const addStories: Task['run'] = async (
345339
resolve(cwd, storiesPath, 'components')
346340
);
347341
addPreviewAnnotations(mainConfig, [`.${sep}${join(storiesPath, 'components')}`]);
348-
342+
349343
// Add stories for the renderer. NOTE: these *do* need to be processed by the framework build system
350344
await linkPackageStories(rendererPath, {
351345
mainConfig,

scripts/tasks/sandbox.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export const sandbox: Task = {
1616
await remove(details.sandboxDir);
1717
}
1818
const { create, install, addStories } = await import('./sandbox-parts');
19-
2019
await create(details, options);
2120
await install(details, options);
22-
await addStories(details, options);
21+
if (!options.skipTemplateStories) {
22+
await addStories(details, options);
23+
}
2324
},
2425
};

0 commit comments

Comments
 (0)