-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Presets / Addon-docs: Cleanup framework-specific presets (#8782)
Presets / Addon-docs: Cleanup framework-specific presets
- Loading branch information
Showing
29 changed files
with
123 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/preset'); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
import fs from 'fs'; | ||
import * as common from './preset'; | ||
import deprecate from 'util-deprecate'; | ||
import dedent from 'ts-dedent'; | ||
import * as common from '../../preset'; | ||
|
||
const makePreset = (framework: string) => { | ||
const docsConfig = [`${__dirname}/config.js`]; | ||
const frameworkConfig = `${__dirname}/../../../dist/frameworks/${framework}/config.js`; | ||
if (fs.existsSync(frameworkConfig)) { | ||
docsConfig.push(frameworkConfig); | ||
} | ||
function config(entry: any[] = []) { | ||
return [...docsConfig, ...entry]; | ||
} | ||
deprecate( | ||
() => {}, | ||
dedent` | ||
Framework-specific presets are no longer-needed as of Storybook 5.3 and will be removed in 6.0. | ||
const configureJSX = framework !== 'react'; | ||
const webpack = (webpackConfig: any, options: any) => | ||
common.webpack(webpackConfig, { configureJSX, ...options }); | ||
|
||
return { | ||
...common, | ||
webpack, | ||
config, | ||
}; | ||
Please use '@storybook/addon-docs/preset' instead of '@storybook/addon-docs/${framework}/preset'. | ||
` | ||
)(); | ||
return common; | ||
}; | ||
|
||
export default makePreset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function webpack(webpackConfig: any = {}, options: any = {}) { | ||
webpackConfig.module.rules.push({ | ||
test: /\.vue$/, | ||
loader: 'storybook-addon-vue-info/loader', | ||
enforce: 'post', | ||
}); | ||
return webpackConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as commonPreset from './frameworks/common/preset'; | ||
|
||
// Map a framework to a preset file that gets executed | ||
type Preset = any; | ||
type FrameworkPresetMapper = (framework: string) => string | void; | ||
|
||
const PRESET_METHODS = [ | ||
'babel', | ||
'babelDefault', | ||
'managerBabel', | ||
'webpack', | ||
'webpackFinal', | ||
'managerWebpack', | ||
'addons', | ||
'entries', | ||
'config', | ||
]; | ||
|
||
function getFrameworkPreset(frameworkPresetFile: string): Preset { | ||
// eslint-disable-next-line import/no-dynamic-require, global-require | ||
return require(frameworkPresetFile); | ||
} | ||
|
||
// Create a composite preset that applies the base preset & | ||
// appends any framework-specific extensions as needed | ||
function withFrameworkExtensions(basePreset: Preset, mapper: FrameworkPresetMapper): Preset { | ||
const extended: Preset = {}; | ||
PRESET_METHODS.forEach(method => { | ||
extended[method] = (existing: any, options: any) => { | ||
let updated = existing; | ||
|
||
const baseMethod = basePreset[method]; | ||
if (baseMethod) { | ||
updated = baseMethod(updated, options); | ||
} | ||
|
||
const frameworkPresetFile = mapper(options.framework); | ||
if (frameworkPresetFile) { | ||
const frameworkPreset = getFrameworkPreset(frameworkPresetFile); | ||
const frameworkMethod = frameworkPreset[method]; | ||
if (frameworkMethod) updated = frameworkMethod(updated, options); | ||
} | ||
|
||
return updated; | ||
}; | ||
}); | ||
return extended; | ||
} | ||
|
||
module.exports = withFrameworkExtensions(commonPreset, framework => { | ||
try { | ||
return require.resolve(`./frameworks/${framework}/preset`); | ||
} catch (err) { | ||
// there is no custom config for the user's framework, do nothing | ||
return null; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
declare module '@mdx-js/react'; | ||
declare module '@storybook/addon-docs/mdx-compiler-plugin'; | ||
declare module '@storybook/addon-docs/blocks'; | ||
declare module 'global'; | ||
declare module 'react-is'; | ||
declare module '@egoist/vue-to-react'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1 @@ | ||
const commonExports = require('../dist/frameworks/common/makePreset').default('vue'); | ||
|
||
const webpack = (webpackConfig, options) => { | ||
const config = commonExports.webpack(webpackConfig, options); | ||
config.module.rules.push({ | ||
test: /\.vue$/, | ||
loader: 'storybook-addon-vue-info/loader', | ||
enforce: 'post', | ||
}); | ||
return config; | ||
}; | ||
|
||
module.exports = { | ||
...commonExports, | ||
webpack, | ||
}; | ||
module.exports = require('../dist/frameworks/common/makePreset').default('vue'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = ['@storybook/addon-docs/angular/preset']; | ||
module.exports = ['@storybook/addon-docs/preset']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = ['@storybook/addon-docs/html/preset']; | ||
module.exports = ['@storybook/addon-docs/preset']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = ['@storybook/addon-docs/vue/preset']; | ||
module.exports = ['@storybook/addon-docs/preset']; |
14a449b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: