@storybook/preset-server-webpack 7.0.0-alpha.3 → 7.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-HKSD7XQF.mjs +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/{types/loader.d.ts → loader.d.ts} +2 -1
- package/dist/loader.js +18 -0
- package/dist/loader.mjs +18 -0
- package/package.json +40 -11
- package/preset.js +1 -1
- package/LICENSE +0 -21
- package/dist/cjs/index.js +0 -26
- package/dist/cjs/lib/compiler/index.js +0 -19
- package/dist/cjs/lib/compiler/stringifier.js +0 -102
- package/dist/cjs/lib/compiler/types.js +0 -1
- package/dist/cjs/loader.js +0 -20
- package/dist/esm/index.js +0 -14
- package/dist/esm/lib/compiler/index.js +0 -12
- package/dist/esm/lib/compiler/stringifier.js +0 -83
- package/dist/esm/lib/compiler/types.js +0 -0
- package/dist/esm/loader.js +0 -10
- package/dist/types/index.d.ts +0 -2
- package/dist/types/lib/compiler/index.d.ts +0 -2
- package/dist/types/lib/compiler/stringifier.d.ts +0 -7
- package/dist/types/lib/compiler/types.d.ts +0 -24
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=(a=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(a,{get:(b,c)=>(typeof require!="undefined"?require:b)[c]}):a)(function(a){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+a+'" is not supported')});export{d as a};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var i=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var o in r)s(e,o,{get:r[o],enumerable:!0})},p=(e,r,o,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of y(r))!v.call(e,t)&&t!==o&&s(e,t,{get:()=>r[t],enumerable:!(l=m(r,t))||l.enumerable});return e};var u=(e,r,o)=>(o=e!=null?a(i(e)):{},p(r||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),d=e=>p(s({},"__esModule",{value:!0}),e);var j={};b(j,{webpack:()=>k});module.exports=d(j);var k=e=>{var o;let r=[...((o=e.module)==null?void 0:o.rules)||[],{type:"javascript/auto",test:/\.stories\.json$/,use:require.resolve("@storybook/preset-server-webpack/dist/loader")},{type:"javascript/auto",test:/\.stories\.ya?ml/,use:[require.resolve("@storybook/preset-server-webpack/dist/loader"),require.resolve("yaml-loader")]}];return e.module=e.module||{},e.module.rules=r,e};0&&(module.exports={webpack});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o}from"./chunk-HKSD7XQF.mjs";var s=e=>{let r=[...e.module?.rules||[],{type:"javascript/auto",test:/\.stories\.json$/,use:o.resolve("@storybook/preset-server-webpack/dist/loader")},{type:"javascript/auto",test:/\.stories\.ya?ml/,use:[o.resolve("@storybook/preset-server-webpack/dist/loader"),o.resolve("yaml-loader")]}];return e.module=e.module||{},e.module.rules=r,e};export{s as webpack};
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var l=(t,r)=>{for(var n in r)c(t,n,{get:r[n],enumerable:!0})},$=(t,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of a(r))!m.call(t,o)&&o!==n&&c(t,o,{get:()=>r[o],enumerable:!(i=u(r,o))||i.enumerable});return t};var d=t=>$(c({},"__esModule",{value:!0}),t);var h={};l(h,{default:()=>A});module.exports=d(h);var S=require("ts-dedent"),{identifier:k}=require("safe-identifier");function f(t,r=0,n=!1){if(typeof t=="string")return JSON.stringify(t);let i=" ".repeat(r);if(Array.isArray(t)){let e=t.map(s=>f(s,r+1)).join(`,
|
|
2
|
+
${i} `);return n?e:`[
|
|
3
|
+
${i} ${e}
|
|
4
|
+
${i}]`}if(typeof t=="object"){let o="";return Object.keys(t).length>0&&(o=Object.keys(t).map(s=>{let g=f(t[s],r+1);return`
|
|
5
|
+
${i} ${s}: ${g}`}).join(",")),n?o:o.length===0?"{}":`{${o}
|
|
6
|
+
${i}}`}return t}function b(t){return Object.keys(t).length===0?"":Object.entries(t).map(([r,n])=>`import { ${n.sort().join(", ")} } from '${r}';
|
|
7
|
+
`).join("")}function x(t){return t&&t.length>0?`
|
|
8
|
+
decorators: [
|
|
9
|
+
${t.join(`,
|
|
10
|
+
`)}
|
|
11
|
+
],`:""}function j(t){let{title:r,imports:n,decorators:i,stories:o,...e}=t,s=x(i),g=f(e,0,!0);return S.dedent`
|
|
12
|
+
export default {
|
|
13
|
+
title: ${JSON.stringify(r)},${s}${g}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
`}function C(t){let{name:r,...n}=t,i=k(r),o={name:r,...n};return[`export const ${i} = ${f(o)};`,""].join(`
|
|
17
|
+
`)}function p(t){return[b(t.imports),j(t),...t.stories.map(n=>C(n))].join(`
|
|
18
|
+
`)}function O(t){return{imports:{},decorators:[],...t}}function y(t){return p(O(t))}var A=t=>{try{return y(JSON.parse(t))}catch{}return t};0&&(module.exports={});
|
package/dist/loader.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{a as y}from"./chunk-HKSD7XQF.mjs";import{dedent as u}from"ts-dedent";var{identifier:a}=y("safe-identifier");function f(t,r=0,n=!1){if(typeof t=="string")return JSON.stringify(t);let o=" ".repeat(r);if(Array.isArray(t)){let e=t.map(s=>f(s,r+1)).join(`,
|
|
2
|
+
${o} `);return n?e:`[
|
|
3
|
+
${o} ${e}
|
|
4
|
+
${o}]`}if(typeof t=="object"){let i="";return Object.keys(t).length>0&&(i=Object.keys(t).map(s=>{let g=f(t[s],r+1);return`
|
|
5
|
+
${o} ${s}: ${g}`}).join(",")),n?i:i.length===0?"{}":`{${i}
|
|
6
|
+
${o}}`}return t}function m(t){return Object.keys(t).length===0?"":Object.entries(t).map(([r,n])=>`import { ${n.sort().join(", ")} } from '${r}';
|
|
7
|
+
`).join("")}function l(t){return t&&t.length>0?`
|
|
8
|
+
decorators: [
|
|
9
|
+
${t.join(`,
|
|
10
|
+
`)}
|
|
11
|
+
],`:""}function $(t){let{title:r,imports:n,decorators:o,stories:i,...e}=t,s=l(o),g=f(e,0,!0);return u`
|
|
12
|
+
export default {
|
|
13
|
+
title: ${JSON.stringify(r)},${s}${g}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
`}function d(t){let{name:r,...n}=t,o=a(r),i={name:r,...n};return[`export const ${o} = ${f(i)};`,""].join(`
|
|
17
|
+
`)}function S(t){return[m(t.imports),$(t),...t.stories.map(n=>d(n))].join(`
|
|
18
|
+
`)}function k(t){return{imports:{},decorators:[],...t}}function p(t){return S(k(t))}var A=t=>{try{return p(JSON.parse(t))}catch{}return t};export{A as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/preset-server-webpack",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.30",
|
|
4
4
|
"description": "Storybook for Server: View HTML snippets from a server in isolation with Hot Reloading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -19,9 +19,31 @@
|
|
|
19
19
|
"url": "https://opencollective.com/storybook"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"require": "./dist/index.js",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./preset": {
|
|
29
|
+
"require": "./dist/index.js",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./dist/loader": {
|
|
34
|
+
"require": "./dist/loader.js",
|
|
35
|
+
"import": "./dist/loader.mjs",
|
|
36
|
+
"types": "./dist/loader.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": {
|
|
39
|
+
"require": "./package.json",
|
|
40
|
+
"import": "./package.json",
|
|
41
|
+
"types": "./package.json"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"main": "dist/index.js",
|
|
45
|
+
"module": "dist/index.mjs",
|
|
46
|
+
"types": "dist/index.d.ts",
|
|
25
47
|
"files": [
|
|
26
48
|
"dist/**/*",
|
|
27
49
|
"README.md",
|
|
@@ -29,18 +51,17 @@
|
|
|
29
51
|
"*.d.ts"
|
|
30
52
|
],
|
|
31
53
|
"scripts": {
|
|
32
|
-
"
|
|
54
|
+
"check": "tsc --noEmit",
|
|
55
|
+
"prepare": "../../../scripts/prepare/bundle.ts"
|
|
33
56
|
},
|
|
34
57
|
"dependencies": {
|
|
35
|
-
"@storybook/core-server": "7.0.0-alpha.
|
|
36
|
-
"@storybook/core-webpack": "7.0.0-alpha.
|
|
37
|
-
"@storybook/server": "7.0.0-alpha.
|
|
58
|
+
"@storybook/core-server": "7.0.0-alpha.30",
|
|
59
|
+
"@storybook/core-webpack": "7.0.0-alpha.30",
|
|
60
|
+
"@storybook/server": "7.0.0-alpha.30",
|
|
38
61
|
"@types/node": "^14.14.20 || ^16.0.0",
|
|
39
|
-
"core-js": "^3.8.2",
|
|
40
62
|
"global": "^4.4.0",
|
|
41
63
|
"react": "16.14.0",
|
|
42
64
|
"react-dom": "16.14.0",
|
|
43
|
-
"regenerator-runtime": "^0.13.7",
|
|
44
65
|
"safe-identifier": "^0.4.1",
|
|
45
66
|
"ts-dedent": "^2.0.0",
|
|
46
67
|
"yaml-loader": "^0.8.0"
|
|
@@ -48,6 +69,7 @@
|
|
|
48
69
|
"devDependencies": {
|
|
49
70
|
"fs-extra": "^9.0.1",
|
|
50
71
|
"jest-specific-snapshot": "^4.0.0",
|
|
72
|
+
"typescript": "~4.6.3",
|
|
51
73
|
"yaml": "^1.10.0"
|
|
52
74
|
},
|
|
53
75
|
"engines": {
|
|
@@ -56,5 +78,12 @@
|
|
|
56
78
|
"publishConfig": {
|
|
57
79
|
"access": "public"
|
|
58
80
|
},
|
|
59
|
-
"
|
|
81
|
+
"bundler": {
|
|
82
|
+
"entries": [
|
|
83
|
+
"./src/index.ts",
|
|
84
|
+
"./src/loader.ts"
|
|
85
|
+
],
|
|
86
|
+
"platform": "node"
|
|
87
|
+
},
|
|
88
|
+
"gitHead": "aabf7b595cb13d8a86dca27ad3d6039205bd55d6"
|
|
60
89
|
}
|
package/preset.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/
|
|
1
|
+
module.exports = require('./dist/index');
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/dist/cjs/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.webpack = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const webpack = config => {
|
|
13
|
-
config.module.rules.push({
|
|
14
|
-
type: 'javascript/auto',
|
|
15
|
-
test: /\.stories\.json$/,
|
|
16
|
-
use: _path.default.resolve(__dirname, './loader.js')
|
|
17
|
-
});
|
|
18
|
-
config.module.rules.push({
|
|
19
|
-
type: 'javascript/auto',
|
|
20
|
-
test: /\.stories\.ya?ml/,
|
|
21
|
-
use: [_path.default.resolve(__dirname, './loader.js'), 'yaml-loader']
|
|
22
|
-
});
|
|
23
|
-
return config;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.webpack = webpack;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.compileCsfModule = compileCsfModule;
|
|
7
|
-
|
|
8
|
-
var _stringifier = require("./stringifier");
|
|
9
|
-
|
|
10
|
-
function createSection(args) {
|
|
11
|
-
return Object.assign({
|
|
12
|
-
imports: {},
|
|
13
|
-
decorators: []
|
|
14
|
-
}, args);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function compileCsfModule(args) {
|
|
18
|
-
return (0, _stringifier.stringifySection)(createSection(args));
|
|
19
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.stringifyDecorators = stringifyDecorators;
|
|
7
|
-
exports.stringifyDefault = stringifyDefault;
|
|
8
|
-
exports.stringifyImports = stringifyImports;
|
|
9
|
-
exports.stringifyObject = stringifyObject;
|
|
10
|
-
exports.stringifySection = stringifySection;
|
|
11
|
-
exports.stringifyStory = stringifyStory;
|
|
12
|
-
|
|
13
|
-
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
|
14
|
-
|
|
15
|
-
const _excluded = ["title", "imports", "decorators", "stories"],
|
|
16
|
-
_excluded2 = ["name"];
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
identifier
|
|
24
|
-
} = require('safe-identifier');
|
|
25
|
-
|
|
26
|
-
function stringifyObject(object, level = 0, excludeOuterParams = false) {
|
|
27
|
-
if (typeof object === 'string') {
|
|
28
|
-
return JSON.stringify(object);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const indent = ' '.repeat(level);
|
|
32
|
-
|
|
33
|
-
if (Array.isArray(object)) {
|
|
34
|
-
const arrayStrings = object.map(item => stringifyObject(item, level + 1));
|
|
35
|
-
const arrayString = arrayStrings.join(`,\n${indent} `);
|
|
36
|
-
if (excludeOuterParams) return arrayString;
|
|
37
|
-
return `[\n${indent} ${arrayString}\n${indent}]`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (typeof object === 'object') {
|
|
41
|
-
let objectString = '';
|
|
42
|
-
|
|
43
|
-
if (Object.keys(object).length > 0) {
|
|
44
|
-
const objectStrings = Object.keys(object).map(key => {
|
|
45
|
-
const value = stringifyObject(object[key], level + 1);
|
|
46
|
-
return `\n${indent} ${key}: ${value}`;
|
|
47
|
-
});
|
|
48
|
-
objectString = objectStrings.join(',');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (excludeOuterParams) return objectString;
|
|
52
|
-
if (objectString.length === 0) return '{}';
|
|
53
|
-
return `{${objectString}\n${indent}}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return object;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function stringifyImports(imports) {
|
|
60
|
-
if (Object.keys(imports).length === 0) return '';
|
|
61
|
-
return Object.entries(imports).map(([module, names]) => `import { ${names.sort().join(', ')} } from '${module}';\n`).join('');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function stringifyDecorators(decorators) {
|
|
65
|
-
return decorators && decorators.length > 0 ? `\n decorators: [\n ${decorators.join(',\n ')}\n ],` : '';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function stringifyDefault(section) {
|
|
69
|
-
const {
|
|
70
|
-
title,
|
|
71
|
-
decorators
|
|
72
|
-
} = section,
|
|
73
|
-
options = _objectWithoutPropertiesLoose(section, _excluded);
|
|
74
|
-
|
|
75
|
-
const decoratorsString = stringifyDecorators(decorators);
|
|
76
|
-
const optionsString = stringifyObject(options, 0, true);
|
|
77
|
-
return (0, _tsDedent.default)`
|
|
78
|
-
export default {
|
|
79
|
-
title: ${JSON.stringify(title)},${decoratorsString}${optionsString}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function stringifyStory(story) {
|
|
86
|
-
const {
|
|
87
|
-
name
|
|
88
|
-
} = story,
|
|
89
|
-
options = _objectWithoutPropertiesLoose(story, _excluded2);
|
|
90
|
-
|
|
91
|
-
const storyId = identifier(name);
|
|
92
|
-
const exportedStory = Object.assign({
|
|
93
|
-
name
|
|
94
|
-
}, options);
|
|
95
|
-
const storyStrings = [`export const ${storyId} = ${stringifyObject(exportedStory)};`, ''];
|
|
96
|
-
return storyStrings.join('\n');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function stringifySection(section) {
|
|
100
|
-
const sectionString = [stringifyImports(section.imports), stringifyDefault(section), ...section.stories.map(story => stringifyStory(story))].join('\n');
|
|
101
|
-
return sectionString;
|
|
102
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/cjs/loader.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _compiler = require("./lib/compiler");
|
|
9
|
-
|
|
10
|
-
var _default = content => {
|
|
11
|
-
try {
|
|
12
|
-
const after = (0, _compiler.compileCsfModule)(JSON.parse(content));
|
|
13
|
-
return after;
|
|
14
|
-
} catch (e) {//
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return content;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.default = _default;
|
package/dist/esm/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
export const webpack = config => {
|
|
3
|
-
config.module.rules.push({
|
|
4
|
-
type: 'javascript/auto',
|
|
5
|
-
test: /\.stories\.json$/,
|
|
6
|
-
use: path.resolve(__dirname, './loader.js')
|
|
7
|
-
});
|
|
8
|
-
config.module.rules.push({
|
|
9
|
-
type: 'javascript/auto',
|
|
10
|
-
test: /\.stories\.ya?ml/,
|
|
11
|
-
use: [path.resolve(__dirname, './loader.js'), 'yaml-loader']
|
|
12
|
-
});
|
|
13
|
-
return config;
|
|
14
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { stringifySection } from './stringifier';
|
|
2
|
-
|
|
3
|
-
function createSection(args) {
|
|
4
|
-
return Object.assign({
|
|
5
|
-
imports: {},
|
|
6
|
-
decorators: []
|
|
7
|
-
}, args);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function compileCsfModule(args) {
|
|
11
|
-
return stringifySection(createSection(args));
|
|
12
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const _excluded = ["title", "imports", "decorators", "stories"],
|
|
2
|
-
_excluded2 = ["name"];
|
|
3
|
-
|
|
4
|
-
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; }
|
|
5
|
-
|
|
6
|
-
import dedent from 'ts-dedent';
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
identifier
|
|
10
|
-
} = require('safe-identifier');
|
|
11
|
-
|
|
12
|
-
export function stringifyObject(object, level = 0, excludeOuterParams = false) {
|
|
13
|
-
if (typeof object === 'string') {
|
|
14
|
-
return JSON.stringify(object);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const indent = ' '.repeat(level);
|
|
18
|
-
|
|
19
|
-
if (Array.isArray(object)) {
|
|
20
|
-
const arrayStrings = object.map(item => stringifyObject(item, level + 1));
|
|
21
|
-
const arrayString = arrayStrings.join(`,\n${indent} `);
|
|
22
|
-
if (excludeOuterParams) return arrayString;
|
|
23
|
-
return `[\n${indent} ${arrayString}\n${indent}]`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (typeof object === 'object') {
|
|
27
|
-
let objectString = '';
|
|
28
|
-
|
|
29
|
-
if (Object.keys(object).length > 0) {
|
|
30
|
-
const objectStrings = Object.keys(object).map(key => {
|
|
31
|
-
const value = stringifyObject(object[key], level + 1);
|
|
32
|
-
return `\n${indent} ${key}: ${value}`;
|
|
33
|
-
});
|
|
34
|
-
objectString = objectStrings.join(',');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (excludeOuterParams) return objectString;
|
|
38
|
-
if (objectString.length === 0) return '{}';
|
|
39
|
-
return `{${objectString}\n${indent}}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return object;
|
|
43
|
-
}
|
|
44
|
-
export function stringifyImports(imports) {
|
|
45
|
-
if (Object.keys(imports).length === 0) return '';
|
|
46
|
-
return Object.entries(imports).map(([module, names]) => `import { ${names.sort().join(', ')} } from '${module}';\n`).join('');
|
|
47
|
-
}
|
|
48
|
-
export function stringifyDecorators(decorators) {
|
|
49
|
-
return decorators && decorators.length > 0 ? `\n decorators: [\n ${decorators.join(',\n ')}\n ],` : '';
|
|
50
|
-
}
|
|
51
|
-
export function stringifyDefault(section) {
|
|
52
|
-
const {
|
|
53
|
-
title,
|
|
54
|
-
decorators
|
|
55
|
-
} = section,
|
|
56
|
-
options = _objectWithoutPropertiesLoose(section, _excluded);
|
|
57
|
-
|
|
58
|
-
const decoratorsString = stringifyDecorators(decorators);
|
|
59
|
-
const optionsString = stringifyObject(options, 0, true);
|
|
60
|
-
return dedent`
|
|
61
|
-
export default {
|
|
62
|
-
title: ${JSON.stringify(title)},${decoratorsString}${optionsString}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
export function stringifyStory(story) {
|
|
68
|
-
const {
|
|
69
|
-
name
|
|
70
|
-
} = story,
|
|
71
|
-
options = _objectWithoutPropertiesLoose(story, _excluded2);
|
|
72
|
-
|
|
73
|
-
const storyId = identifier(name);
|
|
74
|
-
const exportedStory = Object.assign({
|
|
75
|
-
name
|
|
76
|
-
}, options);
|
|
77
|
-
const storyStrings = [`export const ${storyId} = ${stringifyObject(exportedStory)};`, ''];
|
|
78
|
-
return storyStrings.join('\n');
|
|
79
|
-
}
|
|
80
|
-
export function stringifySection(section) {
|
|
81
|
-
const sectionString = [stringifyImports(section.imports), stringifyDefault(section), ...section.stories.map(story => stringifyStory(story))].join('\n');
|
|
82
|
-
return sectionString;
|
|
83
|
-
}
|
|
File without changes
|
package/dist/esm/loader.js
DELETED
package/dist/types/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { StorybookStory, StorybookSection } from './types';
|
|
2
|
-
export declare function stringifyObject(object: any, level?: number, excludeOuterParams?: boolean): string;
|
|
3
|
-
export declare function stringifyImports(imports: Record<string, string[]>): string;
|
|
4
|
-
export declare function stringifyDecorators(decorators: string[]): string;
|
|
5
|
-
export declare function stringifyDefault(section: StorybookSection): string;
|
|
6
|
-
export declare function stringifyStory(story: StorybookStory): string;
|
|
7
|
-
export declare function stringifySection(section: StorybookSection): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface CompileStorybookStoryArgs {
|
|
2
|
-
name: string;
|
|
3
|
-
[x: string]: any;
|
|
4
|
-
}
|
|
5
|
-
export interface CompileStorybookSectionArgs {
|
|
6
|
-
title: string;
|
|
7
|
-
stories: CompileStorybookStoryArgs[];
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
}
|
|
10
|
-
export interface CompileCsfModuleArgs extends CompileStorybookSectionArgs {
|
|
11
|
-
addons?: string[];
|
|
12
|
-
}
|
|
13
|
-
export interface StorybookStory {
|
|
14
|
-
name: string;
|
|
15
|
-
decorators?: string[];
|
|
16
|
-
[x: string]: any;
|
|
17
|
-
}
|
|
18
|
-
export interface StorybookSection {
|
|
19
|
-
imports: Record<string, string[]>;
|
|
20
|
-
decorators?: string[];
|
|
21
|
-
title: string;
|
|
22
|
-
stories: StorybookStory[];
|
|
23
|
-
[x: string]: any;
|
|
24
|
-
}
|