Add ability to get the builder
MODIFY
bin-src/lib/getStorybookInfo.test.ts
bin-src/lib/getStorybookInfo.test.ts
@@ -18,6 +18,7 @@ jest.mock('./getStorybookMetadata', () => {
packageVersion: '6.5.5',
},
],
+ builder: 'webpack5',
version: '6.5.5',
viewLayer: 'react',
})),
@@ -76,6 +77,7 @@ describe('getStorybookInfo', () => {
addons: [],
version: null,
viewLayer: null,
+ builder: null,
});
});
@@ -112,6 +114,7 @@ describe('getStorybookInfo', () => {
addons: [],
version: null,
viewLayer: null,
+ builder: null,
});
});
@@ -121,6 +124,7 @@ describe('getStorybookInfo', () => {
addons: [],
version: null,
viewLayer: null,
+ builder: null,
});
});
});
@@ -144,8 +148,7 @@ describe('getStorybookInfo', () => {
options: { storybookBuildDir: 'storybook-static' },
packageJson: { dependencies: REACT },
});
- await expect(getStorybookInfo(ctx)).resolves.toEqual(
- expect.objectContaining({
+ await expect(getStorybookInfo(ctx)).resolves.toEqual({
addons: [
{
name: 'essentials',
@@ -153,10 +156,10 @@ describe('getStorybookInfo', () => {
packageVersion: '6.5.5',
},
],
+ builder: 'webpack5',
version: '6.5.5',
viewLayer: 'react',
- })
- );
+ });
});
it('returns no metadata if cannot find project.json', async () => {
@@ -170,11 +173,13 @@ describe('getStorybookInfo', () => {
addons: [],
version: null,
viewLayer: null,
+ builder: null,
}));
await expect(getStorybookInfo(ctx)).resolves.toEqual({
addons: [],
version: null,
viewLayer: null,
+ builder: null,
});
});
});

MODIFY
bin-src/lib/getStorybookInfo.ts
bin-src/lib/getStorybookInfo.ts
@@ -135,13 +135,14 @@ export default async function getStorybookInfo(
if (ctx.options.storybookBuildDir) {
const projectJsonPath = path.resolve(ctx.options.storybookBuildDir, 'project.json');
// This test makes sure we fall through if the file does not exist.
- if (fs.existsSync(projectJsonPath)) {
- return await getStorybookMetadateFromProjectJson(ctx.options.storybookBuildDir);
+ if (fs.pathExistsSync(projectJsonPath)) {
+ return await getStorybookMetadateFromProjectJson(projectJsonPath);
}
}
const info = await Promise.all([findAddons(ctx), findConfigFlags(ctx), findViewlayer(ctx)]);
return info.reduce((acc, obj) => Object.assign(acc, obj), {});
} catch (e) {
- return { viewLayer: null, version: null, addons: [] };
+ ctx.log.debug(e);
+ return { viewLayer: null, version: null, addons: [], builder: null };
}
}

MODIFY
bin-src/lib/getStorybookMetadata.ts
bin-src/lib/getStorybookMetadata.ts
@@ -30,7 +30,7 @@ export const getStorybookMetadateFromProjectJson = async (
return {
viewLayer: sbProjectJson.framework.name ?? '',
version: sbProjectJson.storybookPackages[viewLayerPackage].version,
- builder: sbProjectJson?.builder.name ?? 'webpack4',
+ builder: sbProjectJson.builder.name ?? 'webpack4',
addons: Object.keys(sbProjectJson.addons).map((addon) => ({
name: supportedAddons[addon],
packageName: addon,

MODIFY
bin-src/ui/tasks/storybookInfo.stories.ts
bin-src/ui/tasks/storybookInfo.stories.ts
@@ -9,6 +9,7 @@ export default {
const storybook = {
version: '5.3.0',
viewLayer: 'web-components',
+ builder: 'webpack4',
addons: [],
};
const addons = [{ name: 'actions' }, { name: 'docs' }, { name: 'design-assets' }];

MODIFY
bin-src/ui/tasks/storybookInfo.ts
bin-src/ui/tasks/storybookInfo.ts
@@ -6,11 +6,17 @@ const capitalize = (string: string) =>
.map((str) => str.charAt(0).toUpperCase() + str.slice(1))
.join(' ');
-const infoMessage = ({ addons, version, viewLayer }: Context['storybook']) => {
- const info = version && viewLayer ? `Storybook ${version} for ${capitalize(viewLayer)}` : '';
+const infoMessage = ({ addons, version, viewLayer, builder }: Context['storybook']) => {
+ const info =
+ version && viewLayer
+ ? `Storybook ${version} for ${capitalize(viewLayer)} using the ${builder} builder`
+ : '';
+ const builderInfo = builder ? `${info}; using the ${builder} builder` : info;
return addons.length
- ? `${info}; supported addons found: ${addons.map((addon) => capitalize(addon.name)).join(', ')}`
- : `${info}; no supported addons found`;
+ ? `${builderInfo}; supported addons found: ${addons
+ .map((addon) => capitalize(addon.name))
+ .join(', ')}`
+ : `${builderInfo}; no supported addons found`;
};
export const initial = {

Add ability to get the builder