Skip to content

Commit

Permalink
fix: add web-components to cli init (#9106)
Browse files Browse the repository at this point in the history
fix: add web-components to cli init
  • Loading branch information
ndelangen committed Dec 10, 2019
2 parents 600f7f3 + 16ac92a commit 712f7be
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/cli/generators/WEB-COMPONENTS/index.js
Expand Up @@ -8,10 +8,14 @@ import {
installDependencies,
} from '../../lib/helpers';

export default async npmOptions => {
export default async (npmOptions, { storyFormat = 'csf' }) => {
const storybookVersion = await getVersion(npmOptions, '@storybook/web-components');
fse.copySync(path.resolve(__dirname, 'template/'), '.', { overwrite: true });

if (storyFormat === 'mdx') {
// TODO: handle adding of docs mode
}

const packageJson = await retrievePackageJson();

packageJson.dependencies = packageJson.dependencies || {};
Expand Down
30 changes: 30 additions & 0 deletions lib/cli/generators/WEB-COMPONENTS/template/.storybook/preview.js
@@ -0,0 +1,30 @@
/* global window */

import {
configure,
addParameters,
// setCustomElements,
} from '@storybook/web-components';

// import customElements from '../custom-elements.json';

// setCustomElements(customElements);

addParameters({
docs: {
iframeHeight: '200px',
},
});

// configure(require.context('../stories', true, /\.stories\.(js|mdx)$/), module);

// force full reload to not reregister web components
const req = require.context('../stories', true, /\.stories\.(js|mdx)$/);
configure(req, module);
if (module.hot) {
module.hot.accept(req.id, () => {
const currentLocationHref = window.location.href;
window.history.pushState(null, null, currentLocationHref);
window.location.reload();
});
}
7 changes: 7 additions & 0 deletions lib/cli/lib/detect.js
Expand Up @@ -83,6 +83,13 @@ function detectFramework(dependencies) {
return types.POLYMER;
}

if (
(dependencies.dependencies && dependencies.dependencies['lit-element']) ||
(dependencies.devDependencies && dependencies.devDependencies['lit-element'])
) {
return types.WEB_COMPONENTS;
}

if (
(dependencies.dependencies && dependencies.dependencies.mithril) ||
(dependencies.devDependencies && dependencies.devDependencies.mithril)
Expand Down
6 changes: 6 additions & 0 deletions lib/cli/lib/initiate.js
Expand Up @@ -25,6 +25,7 @@ import webpackReactGenerator from '../generators/WEBPACK_REACT';
import mithrilGenerator from '../generators/MITHRIL';
import markoGenerator from '../generators/MARKO';
import htmlGenerator from '../generators/HTML';
import webComponentsGenerator from '../generators/WEB-COMPONENTS';
import riotGenerator from '../generators/RIOT';
import preactGenerator from '../generators/PREACT';
import svelteGenerator from '../generators/SVELTE';
Expand Down Expand Up @@ -172,6 +173,11 @@ const installStorybook = (projectType, options) => {
.then(commandLog('Adding storybook support to your "HTML" app'))
.then(end);

case types.WEB_COMPONENTS:
return webComponentsGenerator(npmOptions, generatorOptions)
.then(commandLog('Adding storybook support to your "web components" app'))
.then(end);

case types.RIOT:
return riotGenerator(npmOptions, generatorOptions)
.then(commandLog('Adding storybook support to your "riot.js" app'))
Expand Down
1 change: 1 addition & 0 deletions lib/cli/lib/project_types.js
Expand Up @@ -13,6 +13,7 @@ const projectTypes = {
ALREADY_HAS_STORYBOOK: 'ALREADY_HAS_STORYBOOK',
UPDATE_PACKAGE_ORGANIZATIONS: 'UPDATE_PACKAGE_ORGANIZATIONS',
POLYMER: 'POLYMER',
WEB_COMPONENTS: 'WEB_COMPONENTS',
MITHRIL: 'MITHRIL',
MARKO: 'MARKO',
HTML: 'HTML',
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/package.json
Expand Up @@ -83,7 +83,8 @@
"@storybook/riot": "5.3.0-beta.20",
"@storybook/svelte": "5.3.0-beta.20",
"@storybook/ui": "5.3.0-beta.20",
"@storybook/vue": "5.3.0-beta.20"
"@storybook/vue": "5.3.0-beta.20",
"@storybook/web-components": "5.3.0-beta.20"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 712f7be

Please sign in to comment.