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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📕 Storybook for everyone (take 2) #43529

Merged
merged 75 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
28971f3
chore: 🤖 add Infra sample Storybook story
streamich Aug 19, 2019
666871c
chore: 🤖 add @kbn/storybook package
streamich Aug 19, 2019
d783b52
chore: 🤖 add sample SIEM stories
streamich Aug 19, 2019
a1ed9f4
chore: 🤖 add Canvas new Storybook config
streamich Aug 19, 2019
2a83b27
fix: 🐛 fix TypeScript errors
streamich Aug 19, 2019
f49b9a6
chore: 🤖 add @kbn/babel-preset to package.json
streamich Aug 19, 2019
4585e82
chore: 🤖 move dependencies to devDependencies
streamich Aug 20, 2019
1a357ec
chore: 🤖 catch up with master
streamich Aug 30, 2019
5484761
chore: 🤖 make Storybook dependencies non-dev
streamich Aug 30, 2019
e800762
chore: 🤖 catch-up with master
streamich Dec 5, 2019
b4b587f
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Dec 5, 2019
a4f797f
chore: 🤖 upgrade Storybook dependencies
streamich Dec 5, 2019
6482901
chore: 🤖 add packages to webpack
streamich Dec 5, 2019
e932374
fix: 🐛 fix TypeScript type check
streamich Dec 5, 2019
2d03884
chore: 🤖 catch-up with master
streamich Dec 6, 2019
f2a89f5
chore: 🤖 disable ESLint warnings
streamich Dec 6, 2019
cae01fa
chore: 🤖 remove Storybook info plugin
streamich Dec 6, 2019
28e3c2b
chore: 🤖 upate yarn.lock
streamich Dec 6, 2019
cc31878
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Dec 9, 2019
90da44b
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Dec 9, 2019
89a8086
chore: 🤖 add Storbook to Embeddables
streamich Dec 9, 2019
a29a447
Merge branch 'master' into storybook-2
streamich Dec 10, 2019
35e143d
feat: 🎸 add --clean flag to Storybook CLI
streamich Dec 10, 2019
f72dd98
Merge branch 'master' of github.com:elastic/kibana into pr/43529
Dec 11, 2019
97d8ff9
coalesce yarn.lock versions
Dec 11, 2019
49b07cd
update kbn/pm dist
Dec 11, 2019
ec78413
This reverts commit 97d8ff9f53c627589838b2558044de58753b4347 and 49b0…
Dec 11, 2019
ba94dde
chore: 🤖 use fs instead of mkdirp
streamich Dec 10, 2019
1d70621
chore: 🤖 use debug for message logging
streamich Dec 13, 2019
a2245f5
chore: 🤖 catch up with master
streamich Dec 13, 2019
25bb279
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Dec 23, 2019
8ce3f9d
chore: 🤖 update yarn.lock
streamich Dec 23, 2019
8d41985
feat: 🎸 add link to kbn-storybook package
streamich Dec 23, 2019
710c9f9
docs: ✏️ add Storybook readme
streamich Dec 23, 2019
c6981f0
chore: 🤖 remove packages that failed DLL build
streamich Dec 23, 2019
401572c
style: 💄 add ESLint comma
streamich Dec 23, 2019
80f9be0
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Dec 23, 2019
fd96192
chore: 🤖 apply changes from #52209
streamich Dec 23, 2019
463b579
fix: 🐛 make Canvas Storybook build again
streamich Dec 23, 2019
3f4f7f4
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Jan 3, 2020
b9fab20
chore: 🤖 move Canvas stories to global Storybook
streamich Jan 3, 2020
732020e
chore: 🤖 move more Canvas components to global Storybook
streamich Jan 3, 2020
f68166c
chore: 🤖 move more Canvas stories to global Storybook
streamich Jan 3, 2020
16412b2
chore: 🤖 move <ItemGrid> and <KeyboardShortcutsDoc> to NP SB
streamich Jan 3, 2020
2dfc316
chore: 🤖 move shape picker Canvas stories to global Storybook
streamich Jan 3, 2020
ad3bc8b
chore: 🤖 move Canvas sidebar stories to global Storybook
streamich Jan 3, 2020
e4878a7
fix: 🐛 split imports to not import path.resolve in Storybook
streamich Jan 3, 2020
1955060
chore: 🤖 move tag and PDF panel Canvas stories to global SB
streamich Jan 3, 2020
99cbe6d
chore: 🤖 move Canvas share website flyout stories to global SB
streamich Jan 3, 2020
d6a4747
fix: 🐛 clean up <ShareWebsiteFlyout> imports
streamich Jan 3, 2020
6f363a4
chore: 🤖 add back Canvas withInfo decorator
streamich Jan 3, 2020
714e95c
chore: 🤖 look for Canvas stories everywhere in /canvas folder
streamich Jan 3, 2020
8d1e2db
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Jan 6, 2020
0f0a91d
test: 💍 mock correct files in Storyshots
streamich Jan 6, 2020
f5ff62f
test: 💍 update Canvas Storyshot snapshots
streamich Jan 6, 2020
b64a662
chore: 🤖 move more Canvas components to global Storybook
streamich Jan 6, 2020
d8fc07a
chore: 🤖 move more Canvas components to global Storybook
streamich Jan 6, 2020
ed9aec7
test: 💍 update Canvas Storyshots
streamich Jan 6, 2020
5eb4c38
Merge branch 'master' into storybook-2
elasticmachine Jan 6, 2020
87323f9
chore: 🤖 rebuild @kbn/pm
streamich Jan 6, 2020
a2ea8bb
chore: 🤖 catch up with master
streamich Jan 9, 2020
b609cbb
chore: 🤖 refresh @kbn/pm dist/index.js artifact
streamich Jan 9, 2020
8fb92a1
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Jan 9, 2020
0f78d5f
chore: 🤖 catch up with master
streamich Jan 13, 2020
e41d520
chore: 🤖 update yarn.lock
streamich Jan 13, 2020
5386be1
chore: 🤖 update @kbn/pm artifact
streamich Jan 13, 2020
1b2d995
Merge remote-tracking branch 'upstream/master' into storybook-2
streamich Jan 14, 2020
eef1fc0
feat: 🎸 address review comments
streamich Jan 14, 2020
4cc67d7
fix: 🐛 remove circular import
streamich Jan 15, 2020
c773ec2
chore: 🤖 catch up with master
streamich Jan 15, 2020
9083e70
chore: 🤖 update yarn.lock
streamich Jan 15, 2020
3b42a13
test: 💍 disable a test suite
streamich Jan 15, 2020
28dd3fb
test: 💍 update Canvas storyshots
streamich Jan 15, 2020
2d8d08d
chore: 🤖 remvoe build step from @kbn/storybook
streamich Jan 15, 2020
d4e7847
chore: 🤖 enable disabled functional test suite
streamich Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"kbn:bootstrap": "yarn build:types && node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
"backport-skip-ci": "backport --prDescription \"[skip-ci]\"",
"storybook": "node scripts/storybook",
"cover:report": "nyc report --temp-dir target/kibana-coverage/functional --report-dir target/coverage/report --reporter=lcov && open ./target/coverage/report/lcov-report/index.html"
},
"repository": {
Expand Down Expand Up @@ -460,10 +461,13 @@
"postcss-url": "^8.0.0",
"prettier": "^1.19.1",
"proxyquire": "1.8.0",
"react-popper-tooltip": "^2.10.1",
"react-textarea-autosize": "^7.1.2",
"regenerate": "^1.4.0",
"sass-lint": "^1.12.1",
"selenium-webdriver": "^4.0.0-alpha.5",
"simple-git": "1.116.0",
"simplebar-react": "^2.1.0",
"sinon": "^7.4.2",
"strip-ansi": "^3.0.1",
"supertest": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { withProcRunner } from './proc_runner';
export { withProcRunner, ProcRunner } from './proc_runner';
export {
ToolingLog,
ToolingLogTextWriter,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-dev-utils/src/proc_runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { withProcRunner } from './with_proc_runner';
export { ProcRunner } from './proc_runner';
13 changes: 9 additions & 4 deletions packages/kbn-dev-utils/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import exitHook from 'exit-hook';
import { pickLevelFromFlags, ToolingLog } from '../tooling_log';
import { createFlagError, isFailError } from './fail';
import { Flags, getFlags, getHelp } from './flags';
import { ProcRunner, withProcRunner } from '../proc_runner';

type CleanupTask = () => void;
type RunFn = (args: {
log: ToolingLog;
flags: Flags;
procRunner: ProcRunner;
addCleanupTask: (task: CleanupTask) => void;
}) => Promise<void> | void;

Expand Down Expand Up @@ -102,10 +104,13 @@ export async function run(fn: RunFn, options: Options = {}) {
}

try {
await fn({
log,
flags,
addCleanupTask: (task: CleanupTask) => cleanupTasks.push(task),
await withProcRunner(log, async procRunner => {
await fn({
log,
flags,
procRunner,
addCleanupTask: (task: CleanupTask) => cleanupTasks.push(task),
});
});
} finally {
doCleanup();
Expand Down
15 changes: 11 additions & 4 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4489,6 +4489,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = __webpack_require__(36);
var proc_runner_1 = __webpack_require__(37);
exports.withProcRunner = proc_runner_1.withProcRunner;
exports.ProcRunner = proc_runner_1.ProcRunner;
var tooling_log_1 = __webpack_require__(415);
exports.ToolingLog = tooling_log_1.ToolingLog;
exports.ToolingLogTextWriter = tooling_log_1.ToolingLogTextWriter;
Expand Down Expand Up @@ -4761,6 +4762,8 @@ function __importDefault(mod) {
Object.defineProperty(exports, "__esModule", { value: true });
var with_proc_runner_1 = __webpack_require__(38);
exports.withProcRunner = with_proc_runner_1.withProcRunner;
var proc_runner_1 = __webpack_require__(39);
exports.ProcRunner = proc_runner_1.ProcRunner;


/***/ }),
Expand Down Expand Up @@ -37069,6 +37072,7 @@ const exit_hook_1 = tslib_1.__importDefault(__webpack_require__(348));
const tooling_log_1 = __webpack_require__(415);
const fail_1 = __webpack_require__(425);
const flags_1 = __webpack_require__(426);
const proc_runner_1 = __webpack_require__(37);
async function run(fn, options = {}) {
var _a;
const flags = flags_1.getFlags(process.argv.slice(2), options);
Expand Down Expand Up @@ -37118,10 +37122,13 @@ async function run(fn, options = {}) {
throw fail_1.createFlagError(`Unknown flag(s) "${flags.unexpected.join('", "')}"`);
}
try {
await fn({
log,
flags,
addCleanupTask: (task) => cleanupTasks.push(task),
await proc_runner_1.withProcRunner(log, async (procRunner) => {
await fn({
log,
flags,
procRunner,
addCleanupTask: (task) => cleanupTasks.push(task),
});
});
}
finally {
Expand Down
33 changes: 33 additions & 0 deletions packages/kbn-storybook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Kibana Storybook

This package provides ability to add [Storybook](https://storybook.js.org/) to any Kibana plugin.

- [Setup Instructions](#setup-instructions)


## Setup Instructions

1. Add `storybook.js` launcher file to your plugin. For example, create a file at
`src/plugins/<plugin>/scripts/storybook.js`, with the following contents:

```js
import { join } from 'path';

// eslint-disable-next-line
require('@kbn/storybook').runStorybookCli({
name: '<plugin>',
storyGlobs: [join(__dirname, '..', 'public', 'components', '**', '*.examples.tsx')],
});
```
2. Add your plugin alias to `src/dev/storybook/aliases.ts` config.
3. Create sample Storybook stories. For example, in your plugin create create a file at
`src/plugins/<plugin>/public/components/hello_world/__examples__/hello_world.examples.tsx` with
the following contents:

```jsx
import * as React from 'react';
import { storiesOf } from '@storybook/react';

storiesOf('Hello world', module).add('default', () => <div>Hello world!</div>);
```
4. Launch Storybook with `yarn storybook <plugin>`.
86 changes: 86 additions & 0 deletions packages/kbn-storybook/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const fs = require('fs');
const { join } = require('path');
const Rx = require('rxjs');
const { first } = require('rxjs/operators');
const storybook = require('@storybook/react/standalone');
const { run } = require('@kbn/dev-utils');
const { generateStorybookEntry } = require('./lib/storybook_entry');
const { REPO_ROOT, CURRENT_CONFIG } = require('./lib/constants');
const { buildDll } = require('./lib/dll');

exports.runStorybookCli = config => {
const { name, storyGlobs } = config;
run(
async ({ flags, log, procRunner }) => {
log.debug('Global config:\n', require('./lib/constants'));

const currentConfig = JSON.stringify(config, null, 2);
const currentConfigDir = join(CURRENT_CONFIG, '..');
await fs.promises.mkdir(currentConfigDir, { recursive: true });
log.debug('Writing currentConfig:\n', CURRENT_CONFIG + '\n', currentConfig);
await fs.promises.writeFile(CURRENT_CONFIG, `exports.currentConfig = ${currentConfig};`);

await buildDll({
streamich marked this conversation as resolved.
Show resolved Hide resolved
rebuildDll: flags.rebuildDll,
log,
procRunner,
});

// Build sass and continue when initial build complete
await procRunner.run('watch sass', {
cmd: process.execPath,
args: ['scripts/build_sass', '--watch'],
cwd: REPO_ROOT,
wait: /scss bundles created/,
});

const subj = new Rx.ReplaySubject(1);
generateStorybookEntry({ log, storyGlobs }).subscribe(subj);

await subj.pipe(first()).toPromise();

await Promise.all([
// route errors
subj.toPromise(),

new Promise(() => {
// storybook never completes, so neither will this promise
const configDir = join(__dirname, 'storybook_config');
log.debug('Config dir:', configDir);
storybook({
mode: 'dev',
port: 9001,
configDir,
});
}),
]);
},
{
flags: {
boolean: ['rebuildDll'],
},
description: `
Run the storybook examples for ${name}
`,
}
);
};
27 changes: 27 additions & 0 deletions packages/kbn-storybook/lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const { resolve, dirname } = require('path');

exports.REPO_ROOT = dirname(require.resolve('../../../package.json'));
exports.ASSET_DIR = resolve(exports.REPO_ROOT, 'built_assets/storybook');
exports.CURRENT_CONFIG = resolve(exports.ASSET_DIR, 'current.config.js');
exports.STORY_ENTRY_PATH = resolve(exports.ASSET_DIR, 'stories.entry.js');
exports.DLL_DIST_DIR = resolve(exports.ASSET_DIR, 'dll');
exports.DLL_NAME = 'storybook_dll';
41 changes: 41 additions & 0 deletions packages/kbn-storybook/lib/dll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const { resolve } = require('path');
const { existsSync } = require('fs');

const { REPO_ROOT, DLL_DIST_DIR } = require('./constants');

exports.buildDll = async ({ rebuildDll, log, procRunner }) => {
if (rebuildDll) {
log.info('rebuilding dll');
} else if (!existsSync(resolve(DLL_DIST_DIR, 'dll.js'))) {
log.info('dll missing, rebuilding');
} else {
log.info('dll exists');
return;
}

await procRunner.run('build dll ', {
cmd: require.resolve('webpack/bin/webpack'),
args: ['--config', require.resolve('./webpack.dll.config.js')],
cwd: REPO_ROOT,
wait: true,
});
};
89 changes: 89 additions & 0 deletions packages/kbn-storybook/lib/storybook_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const { resolve, relative, dirname } = require('path');
const Fs = require('fs');
const Rx = require('rxjs');
const { mergeMap, map, debounceTime } = require('rxjs/operators');
const normalize = require('normalize-path');
const { promisify } = require('util');

const watch = require('glob-watcher');
const mkdirp = require('mkdirp'); // eslint-disable-line
const glob = require('fast-glob');

const mkdirpAsync = promisify(mkdirp);
const writeFileAsync = promisify(Fs.writeFile);

const { REPO_ROOT, STORY_ENTRY_PATH } = require('./constants');
const STORE_ENTRY_DIR = dirname(STORY_ENTRY_PATH);

exports.generateStorybookEntry = ({ log, storyGlobs }) => {
const globs = ['built_assets/css/**/*.light.css', ...storyGlobs];
log.info('Storybook globs:\n', globs);
const norm = p => normalize(relative(STORE_ENTRY_DIR, p));

return Rx.defer(() =>
glob(globs, {
absolute: true,
cwd: REPO_ROOT,
onlyFiles: true,
})
).pipe(
map(paths => {
log.info('Discovered Storybook entry points:\n', paths);
return new Set(paths.map(norm));
}),
mergeMap(
paths =>
new Rx.Observable(observer => {
observer.next(paths);

const chokidar = watch(globs, { cwd: REPO_ROOT })
.on('add', path => {
observer.next(paths.add(norm(resolve(REPO_ROOT, path))));
})
.on('unlink', path => {
observer.next(paths.delete(norm(resolve(REPO_ROOT, path))));
});

return () => {
chokidar.close();
};
})
),
debounceTime(200),
mergeMap(async (paths, i) => {
await mkdirpAsync(STORE_ENTRY_DIR);

let content = '';
for (const path of paths) {
content += `require('${path}');\n`;
}

await writeFileAsync(STORY_ENTRY_PATH, content);

if (i === 0) {
log.info('%d paths written to entry file', paths.size);
} else {
log.info('entry file updated');
}
})
);
};
Loading