mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 16:11:33 +08:00
Add CLI template
This commit is contained in:
parent
067caf8498
commit
f00a369d9e
@ -18,6 +18,7 @@ import vueGenerator from '../generators/VUE';
|
||||
import polymerGenerator from '../generators/POLYMER';
|
||||
import webpackReactGenerator from '../generators/WEBPACK_REACT';
|
||||
import mithrilGenerator from '../generators/MITHRIL';
|
||||
import markoGenerator from '../generators/MARKO';
|
||||
|
||||
const logger = console;
|
||||
|
||||
@ -163,6 +164,11 @@ const runGenerator = () => {
|
||||
.then(commandLog('Adding storybook support to your "Mithril" app'))
|
||||
.then(end);
|
||||
|
||||
case types.MARKO:
|
||||
return markoGenerator()
|
||||
.then(commandLog('Adding storybook support to your "Marko" app'))
|
||||
.then(end);
|
||||
|
||||
default:
|
||||
paddedLog(`We couldn't detect your project type. (code: ${projectType})`);
|
||||
paddedLog(
|
||||
|
45
lib/cli/generators/MARKO/index.js
Normal file
45
lib/cli/generators/MARKO/index.js
Normal file
@ -0,0 +1,45 @@
|
||||
import path from 'path';
|
||||
import mergeDirs from 'merge-dirs';
|
||||
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
|
||||
|
||||
export default async () => {
|
||||
const [
|
||||
storybookVersion,
|
||||
actionsVersion,
|
||||
linksVersion,
|
||||
addonsVersion,
|
||||
babelCoreVersion,
|
||||
babelRuntimeVersion,
|
||||
] = await getVersions(
|
||||
'@storybook/marko',
|
||||
'@storybook/addon-actions',
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addons',
|
||||
'babel-core',
|
||||
'babel-runtime'
|
||||
);
|
||||
|
||||
mergeDirs(path.resolve(__dirname, 'template/'), '.', 'overwrite');
|
||||
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
packageJson.dependencies = packageJson.dependencies || {};
|
||||
packageJson.devDependencies = packageJson.devDependencies || {};
|
||||
packageJson.devDependencies['@storybook/addon-actions'] = actionsVersion;
|
||||
packageJson.devDependencies['@storybook/addon-links'] = linksVersion;
|
||||
packageJson.devDependencies['@storybook/addons'] = addonsVersion;
|
||||
packageJson.devDependencies['@storybook/marko'] = storybookVersion;
|
||||
|
||||
if (!packageJson.dependencies['babel-core'] && !packageJson.devDependencies['babel-core']) {
|
||||
packageJson.devDependencies['babel-core'] = babelCoreVersion;
|
||||
}
|
||||
if (!packageJson.dependencies['babel-runtime'] && !packageJson.devDependencies['babel-runtime']) {
|
||||
packageJson.devDependencies['babel-runtime'] = babelRuntimeVersion;
|
||||
}
|
||||
|
||||
packageJson.scripts = packageJson.scripts || {};
|
||||
packageJson.scripts.storybook = 'start-storybook -p 6006';
|
||||
packageJson.scripts['build-storybook'] = 'build-storybook';
|
||||
|
||||
writePackageJson(packageJson);
|
||||
};
|
2
lib/cli/generators/MARKO/template/.storybook/addons.js
Normal file
2
lib/cli/generators/MARKO/template/.storybook/addons.js
Normal file
@ -0,0 +1,2 @@
|
||||
import '@storybook/addon-actions/register';
|
||||
import '@storybook/addon-links/register';
|
9
lib/cli/generators/MARKO/template/.storybook/config.js
Normal file
9
lib/cli/generators/MARKO/template/.storybook/config.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { configure } from '@storybook/mithril';
|
||||
|
||||
// automatically import all files ending in *.stories.js
|
||||
const req = require.context('../stories', true, /.stories.js$/);
|
||||
function loadStories() {
|
||||
req.keys().forEach(filename => req(filename));
|
||||
}
|
||||
|
||||
configure(loadStories, module);
|
File diff suppressed because one or more lines are too long
BIN
lib/cli/generators/MARKO/template/components/welcome/logo.png
Normal file
BIN
lib/cli/generators/MARKO/template/components/welcome/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
@ -0,0 +1,5 @@
|
||||
import { storiesOf } from '@storybook/marko';
|
||||
|
||||
import Welcome from '../components/welcome/index.marko';
|
||||
|
||||
storiesOf('Welcome', module).add('welcome', () => Welcome.renderSync({}));
|
@ -84,6 +84,13 @@ function detectFramework(dependencies) {
|
||||
return types.MITHRIL;
|
||||
}
|
||||
|
||||
if (
|
||||
(dependencies.dependencies && dependencies.dependencies.marko) ||
|
||||
(dependencies.devDependencies && dependencies.devDependencies.marko)
|
||||
) {
|
||||
return types.MARKO;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -14,4 +14,5 @@ export default {
|
||||
UPDATE_PACKAGE_ORGANIZATIONS: 'UPDATE_PACKAGE_ORGANIZATIONS',
|
||||
POLYMER: 'POLYMER',
|
||||
MITHRIL: 'MITHRIL',
|
||||
MARKO: 'MARKO',
|
||||
};
|
||||
|
@ -56,6 +56,7 @@
|
||||
"@storybook/channel-postmessage": "4.0.0-alpha.4",
|
||||
"@storybook/channel-websocket": "4.0.0-alpha.4",
|
||||
"@storybook/channels": "4.0.0-alpha.4",
|
||||
"@storybook/marko": "4.0.0-alpha.4",
|
||||
"@storybook/mithril": "4.0.0-alpha.4",
|
||||
"@storybook/polymer": "4.0.0-alpha.4",
|
||||
"@storybook/react": "4.0.0-alpha.4",
|
||||
|
9
lib/cli/test/fixtures/marko/package.json
vendored
Normal file
9
lib/cli/test/fixtures/marko/package.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "marko-fixture",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"marko": "^4.9.7"
|
||||
}
|
||||
}
|
2
lib/cli/test/snapshots/marko/.storybook/addons.js
Normal file
2
lib/cli/test/snapshots/marko/.storybook/addons.js
Normal file
@ -0,0 +1,2 @@
|
||||
import '@storybook/addon-actions/register';
|
||||
import '@storybook/addon-links/register';
|
9
lib/cli/test/snapshots/marko/.storybook/config.js
Normal file
9
lib/cli/test/snapshots/marko/.storybook/config.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { configure } from '@storybook/mithril';
|
||||
|
||||
// automatically import all files ending in *.stories.js
|
||||
const req = require.context('../stories', true, /.stories.js$/);
|
||||
function loadStories() {
|
||||
req.keys().forEach(filename => req(filename));
|
||||
}
|
||||
|
||||
configure(loadStories, module);
|
41
lib/cli/test/snapshots/marko/components/welcome/index.marko
Normal file
41
lib/cli/test/snapshots/marko/components/welcome/index.marko
Normal file
File diff suppressed because one or more lines are too long
BIN
lib/cli/test/snapshots/marko/components/welcome/logo.png
Normal file
BIN
lib/cli/test/snapshots/marko/components/welcome/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
21
lib/cli/test/snapshots/marko/package.json
Normal file
21
lib/cli/test/snapshots/marko/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "marko-fixture",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"marko": "^4.9.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@storybook/addon-actions": "^4.0.0-alpha.4",
|
||||
"@storybook/addon-links": "^4.0.0-alpha.4",
|
||||
"@storybook/addons": "^4.0.0-alpha.4",
|
||||
"@storybook/marko": "4.0.0-alpha.4",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-runtime": "^6.26.0"
|
||||
},
|
||||
"scripts": {
|
||||
"storybook": "start-storybook -p 6006",
|
||||
"build-storybook": "build-storybook"
|
||||
}
|
||||
}
|
5
lib/cli/test/snapshots/marko/stories/index.stories.js
Normal file
5
lib/cli/test/snapshots/marko/stories/index.stories.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { storiesOf } from '@storybook/marko';
|
||||
|
||||
import Welcome from '../components/welcome/index.marko';
|
||||
|
||||
storiesOf('Welcome', module).add('welcome', () => Welcome.renderSync({}));
|
Loading…
x
Reference in New Issue
Block a user