Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add web-components to cli init #9106

Merged
merged 2 commits into from Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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