1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.configure = configure;
|
7 |
|
8 | var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
9 |
|
10 | var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
11 |
|
12 | const _excluded = ["addons", "extensions", "commonJs"];
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
17 |
|
18 | function configureMain(_ref) {
|
19 | let {
|
20 | addons,
|
21 | extensions = ['js', 'jsx', 'ts', 'tsx'],
|
22 | commonJs = false
|
23 | } = _ref,
|
24 | custom = _objectWithoutPropertiesLoose(_ref, _excluded);
|
25 |
|
26 | const prefix = _fsExtra.default.existsSync('./src') ? '../src' : '../stories';
|
27 | const config = Object.assign({
|
28 | stories: [`${prefix}/**/*.stories.mdx`, `${prefix}/**/*.stories.@(${extensions.join('|')})`],
|
29 | addons
|
30 | }, custom);
|
31 |
|
32 | const stringified = `module.exports = ${JSON.stringify(config, null, 2).replace(/\\"/g, '"').replace(/['"]%%/g, '').replace(/%%['"]/, '').replace(/\\n/g, '\r\n')}`;
|
33 |
|
34 | _fsExtra.default.ensureDirSync('./.storybook');
|
35 |
|
36 | _fsExtra.default.writeFileSync(`./.storybook/main.${commonJs ? 'cjs' : 'js'}`, stringified, {
|
37 | encoding: 'utf8'
|
38 | });
|
39 | }
|
40 |
|
41 | const frameworkToPreviewParts = {
|
42 | angular: {
|
43 | prefix: (0, _tsDedent.default)`
|
44 | import { setCompodocJson } from "@storybook/addon-docs/angular";
|
45 | import docJson from "../documentation.json";
|
46 | setCompodocJson(docJson);
|
47 |
|
48 | `.trimStart(),
|
49 | extraParameters: 'docs: { inlineStories: true },'
|
50 | }
|
51 | };
|
52 |
|
53 | function configurePreview(framework, commonJs) {
|
54 | const {
|
55 | prefix = '',
|
56 | extraParameters = ''
|
57 | } = frameworkToPreviewParts[framework] || {};
|
58 | const previewPath = `./.storybook/preview.${commonJs ? 'cjs' : 'js'}`;
|
59 |
|
60 | if (_fsExtra.default.existsSync(previewPath)) {
|
61 | return;
|
62 | }
|
63 |
|
64 | const preview = (0, _tsDedent.default)`
|
65 | ${prefix}
|
66 | export const parameters = {
|
67 | actions: { argTypesRegex: "^on[A-Z].*" },
|
68 | controls: {
|
69 | matchers: {
|
70 | color: /(background|color)$/i,
|
71 | date: /Date$/,
|
72 | },
|
73 | },
|
74 | ${extraParameters}
|
75 | }`.replace(' \n', '').trim();
|
76 |
|
77 | _fsExtra.default.writeFileSync(previewPath, preview, {
|
78 | encoding: 'utf8'
|
79 | });
|
80 | }
|
81 |
|
82 | function configure(framework, mainOptions) {
|
83 | _fsExtra.default.ensureDirSync('./.storybook');
|
84 |
|
85 | configureMain(mainOptions);
|
86 | configurePreview(framework, mainOptions.commonJs);
|
87 | } |
\ | No newline at end of file |