FIX review comments, CHANGE to only support a single preview.*

This commit is contained in:
Norbert de Langen 2019-11-11 11:11:38 +01:00
parent cd3bc6797f
commit eaab26e6e4
2 changed files with 39 additions and 15 deletions

View File

@ -84,32 +84,57 @@ const loadStories = (loadable: string, framework: string, clientApi: ClientApi)
});
};
const getPreviewFile = (configDir: string): string | false => {
const preview = path.join(configDir, 'preview.js');
const previewTS = path.join(configDir, 'preview.ts');
const config = path.join(configDir, 'config.js');
const configTS = path.join(configDir, 'config.ts');
if (isFile(previewTS)) {
return configTS;
}
if (isFile(preview)) {
return config;
}
if (isFile(configTS)) {
return configTS;
}
if (isFile(config)) {
return config;
}
return false;
};
const getMainFile = (configDir: string): string | false => {
const main = path.join(configDir, 'main.js');
if (isFile(main)) {
return main;
}
return false;
};
function getConfigPathParts(input: string): Output {
const configDir = path.resolve(input);
if (fs.lstatSync(configDir).isDirectory()) {
const output: Output = { files: [], stories: [] };
const main = path.join(configDir, 'main.js');
const preview = path.join(configDir, 'preview.js');
const config = path.join(configDir, 'config.js');
const configTS = path.join(configDir, 'config.ts');
if (isFile(preview)) {
const preview = getPreviewFile(configDir);
const main = getMainFile(configDir);
if (preview) {
output.files.push(preview);
}
if (isFile(main)) {
if (main) {
const { stories = [] } = require.requireActual(main);
const result = stories.reduce((acc: string[], i: string) => [...acc, ...glob.sync(i)], []);
output.stories = result;
}
if (isFile(config)) {
output.files.push(config);
}
if (isFile(configTS)) {
output.files.push(configTS);
}
return output;
}
@ -119,7 +144,7 @@ function getConfigPathParts(input: string): Output {
function configure(
options: {
storybook: any;
storybook: ClientApi;
} & StoryshotsOptions
): void {
const { configPath = '.storybook', config, storybook, framework } = options;

View File

@ -16,10 +16,9 @@ function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'vue';
mockVueToIncludeCompiler();
const { configPath, config } = options;
const storybook = require.requireActual('@storybook/vue');
configure({ configPath, ...config, storybook });
configure({ ...options, storybook });
return {
framework: 'vue' as const,