@storybook/preset-server-webpack 7.0.0-alpha.0 → 7.0.0-alpha.11

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.
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var e=(a,b)=>d(a,"name",{value:b,configurable:!0}),f=(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{e as a,f as b};
@@ -0,0 +1,6 @@
1
+ import { StorybookConfig } from '@storybook/core-webpack';
2
+ export { BuilderResult, StorybookConfig, TypescriptOptions } from '@storybook/core-webpack';
3
+
4
+ declare const webpack: StorybookConfig['webpack'];
5
+
6
+ export { webpack };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var m=Object.create;var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var i=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var a=(e,r)=>u(e,"name",{value:r,configurable:!0});var q=(e,r)=>{for(var s in r)u(e,s,{get:r[s],enumerable:!0})},p=(e,r,s,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of d(r))!j.call(e,t)&&t!==s&&u(e,t,{get:()=>r[t],enumerable:!(l=v(r,t))||l.enumerable});return e};var o=(e,r,s)=>(s=e!=null?m(i(e)):{},p(r||!e||!e.__esModule?u(s,"default",{value:e,enumerable:!0}):s,e)),x=e=>p(u({},"__esModule",{value:!0}),e);var b={};q(b,{webpack:()=>y});module.exports=x(b);var y=a(e=>{var s;let r=[...((s=e.module)==null?void 0:s.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},"webpack");0&&(module.exports={webpack});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";import{a as s,b as r}from"./chunk-ROAVVZ5J.mjs";var l=s(e=>{let t=[...e.module?.rules||[],{type:"javascript/auto",test:/\.stories\.json$/,use:r.resolve("@storybook/preset-server-webpack/dist/loader")},{type:"javascript/auto",test:/\.stories\.ya?ml/,use:[r.resolve("@storybook/preset-server-webpack/dist/loader"),r.resolve("yaml-loader")]}];return e.module=e.module||{},e.module.rules=t,e},"webpack");export{l as webpack};
@@ -1,2 +1,3 @@
1
1
  declare const _default: (content: string) => string;
2
- export default _default;
2
+
3
+ export { _default as default };
package/dist/loader.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var e=(t,r)=>c(t,"name",{value:r,configurable:!0});var d=(t,r)=>{for(var n in r)c(t,n,{get:r[n],enumerable:!0})},l=(t,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of m(r))!$.call(t,i)&&i!==n&&c(t,i,{get:()=>r[i],enumerable:!(o=S(r,i))||o.enumerable});return t};var x=t=>l(c({},"__esModule",{value:!0}),t);var C={};d(C,{default:()=>A});module.exports=x(C);var g=require("ts-dedent"),{identifier:j}=require("safe-identifier");function u(t,r=0,n=!1){if(typeof t=="string")return JSON.stringify(t);let o=" ".repeat(r);if(Array.isArray(t)){let s=t.map(f=>u(f,r+1)).join(`,
2
+ ${o} `);return n?s:`[
3
+ ${o} ${s}
4
+ ${o}]`}if(typeof t=="object"){let i="";return Object.keys(t).length>0&&(i=Object.keys(t).map(f=>{let p=u(t[f],r+1);return`
5
+ ${o} ${f}: ${p}`}).join(",")),n?i:i.length===0?"{}":`{${i}
6
+ ${o}}`}return t}e(u,"stringifyObject");function O(t){return Object.keys(t).length===0?"":Object.entries(t).map(([r,n])=>`import { ${n.sort().join(", ")} } from '${r}';
7
+ `).join("")}e(O,"stringifyImports");function h(t){return t&&t.length>0?`
8
+ decorators: [
9
+ ${t.join(`,
10
+ `)}
11
+ ],`:""}e(h,"stringifyDecorators");function J(t){let{title:r,imports:n,decorators:o,stories:i,...s}=t,f=h(o),p=u(s,0,!0);return g.dedent`
12
+ export default {
13
+ title: ${JSON.stringify(r)},${f}${p}
14
+ };
15
+
16
+ `}e(J,"stringifyDefault");function N(t){let{name:r,...n}=t,o=j(r),i={name:r,...n};return[`export const ${o} = ${u(i)};`,""].join(`
17
+ `)}e(N,"stringifyStory");function a(t){return[O(t.imports),J(t),...t.stories.map(n=>N(n))].join(`
18
+ `)}e(a,"stringifySection");function k(t){return{imports:{},decorators:[],...t}}e(k,"createSection");function y(t){return a(k(t))}e(y,"compileCsfModule");var A=e(t=>{try{return y(JSON.parse(t))}catch{}return t},"default");0&&(module.exports={});
@@ -0,0 +1,18 @@
1
+ "use strict";import{a as n,b as y}from"./chunk-ROAVVZ5J.mjs";import{dedent as S}from"ts-dedent";var{identifier:m}=y("safe-identifier");function c(t,r=0,i=!1){if(typeof t=="string")return JSON.stringify(t);let o=" ".repeat(r);if(Array.isArray(t)){let s=t.map(f=>c(f,r+1)).join(`,
2
+ ${o} `);return i?s:`[
3
+ ${o} ${s}
4
+ ${o}]`}if(typeof t=="object"){let e="";return Object.keys(t).length>0&&(e=Object.keys(t).map(f=>{let u=c(t[f],r+1);return`
5
+ ${o} ${f}: ${u}`}).join(",")),i?e:e.length===0?"{}":`{${e}
6
+ ${o}}`}return t}n(c,"stringifyObject");function $(t){return Object.keys(t).length===0?"":Object.entries(t).map(([r,i])=>`import { ${i.sort().join(", ")} } from '${r}';
7
+ `).join("")}n($,"stringifyImports");function d(t){return t&&t.length>0?`
8
+ decorators: [
9
+ ${t.join(`,
10
+ `)}
11
+ ],`:""}n(d,"stringifyDecorators");function l(t){let{title:r,imports:i,decorators:o,stories:e,...s}=t,f=d(o),u=c(s,0,!0);return S`
12
+ export default {
13
+ title: ${JSON.stringify(r)},${f}${u}
14
+ };
15
+
16
+ `}n(l,"stringifyDefault");function x(t){let{name:r,...i}=t,o=m(r),e={name:r,...i};return[`export const ${o} = ${c(e)};`,""].join(`
17
+ `)}n(x,"stringifyStory");function g(t){return[$(t.imports),l(t),...t.stories.map(i=>x(i))].join(`
18
+ `)}n(g,"stringifySection");function j(t){return{imports:{},decorators:[],...t}}n(j,"createSection");function a(t){return g(j(t))}n(a,"compileCsfModule");var A=n(t=>{try{return a(JSON.parse(t))}catch{}return t},"default");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.0",
3
+ "version": "7.0.0-alpha.11",
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
- "main": "dist/cjs/index.js",
23
- "module": "dist/esm/index.js",
24
- "types": "dist/types/index.d.ts",
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,25 +51,27 @@
29
51
  "*.d.ts"
30
52
  ],
31
53
  "scripts": {
32
- "prepare": "node ../../scripts/prepare.js"
54
+ "check": "tsc --noEmit",
55
+ "prepare": "esrun ../../scripts/prepare/bundle.ts"
33
56
  },
34
57
  "dependencies": {
35
- "@storybook/core-server": "7.0.0-alpha.0",
36
- "@storybook/core-webpack": "7.0.0-alpha.0",
37
- "@storybook/server": "7.0.0-alpha.0",
58
+ "@storybook/core-server": "7.0.0-alpha.11",
59
+ "@storybook/core-webpack": "7.0.0-alpha.11",
60
+ "@storybook/server": "7.0.0-alpha.11",
38
61
  "@types/node": "^14.14.20 || ^16.0.0",
39
62
  "core-js": "^3.8.2",
40
63
  "global": "^4.4.0",
41
64
  "react": "16.14.0",
42
65
  "react-dom": "16.14.0",
43
- "regenerator-runtime": "^0.13.7",
44
66
  "safe-identifier": "^0.4.1",
45
67
  "ts-dedent": "^2.0.0",
46
68
  "yaml-loader": "^0.8.0"
47
69
  },
48
70
  "devDependencies": {
71
+ "@digitak/esrun": "^3.2.2",
49
72
  "fs-extra": "^9.0.1",
50
73
  "jest-specific-snapshot": "^4.0.0",
74
+ "typescript": "~4.6.3",
51
75
  "yaml": "^1.10.0"
52
76
  },
53
77
  "engines": {
@@ -56,5 +80,12 @@
56
80
  "publishConfig": {
57
81
  "access": "public"
58
82
  },
59
- "gitHead": "c82d897ea765da8cf4fbbcc2af1f28c808a93e23"
83
+ "bundler": {
84
+ "entries": [
85
+ "./src/index.ts",
86
+ "./src/loader.ts"
87
+ ],
88
+ "platform": "node"
89
+ },
90
+ "gitHead": "688d338903e84a7e83cb104472e868e734399f65"
60
91
  }
package/preset.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/cjs/index');
1
+ module.exports = require('./dist/index');
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
- var webpack = function 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,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compileCsfModule = compileCsfModule;
7
-
8
- require("core-js/modules/es.object.assign.js");
9
-
10
- var _stringifier = require("./stringifier");
11
-
12
- function createSection(args) {
13
- return Object.assign({
14
- imports: {},
15
- decorators: []
16
- }, args);
17
- }
18
-
19
- function compileCsfModule(args) {
20
- return (0, _stringifier.stringifySection)(createSection(args));
21
- }
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.symbol.js");
4
-
5
- require("core-js/modules/es.symbol.description.js");
6
-
7
- require("core-js/modules/es.object.to-string.js");
8
-
9
- require("core-js/modules/es.symbol.iterator.js");
10
-
11
- require("core-js/modules/es.array.iterator.js");
12
-
13
- require("core-js/modules/es.string.iterator.js");
14
-
15
- require("core-js/modules/web.dom-collections.iterator.js");
16
-
17
- require("core-js/modules/es.array.slice.js");
18
-
19
- require("core-js/modules/es.array.from.js");
20
-
21
- require("core-js/modules/es.regexp.exec.js");
22
-
23
- require("core-js/modules/es.object.freeze.js");
24
-
25
- Object.defineProperty(exports, "__esModule", {
26
- value: true
27
- });
28
- exports.stringifyDecorators = stringifyDecorators;
29
- exports.stringifyDefault = stringifyDefault;
30
- exports.stringifyImports = stringifyImports;
31
- exports.stringifyObject = stringifyObject;
32
- exports.stringifySection = stringifySection;
33
- exports.stringifyStory = stringifyStory;
34
-
35
- require("core-js/modules/es.string.repeat.js");
36
-
37
- require("core-js/modules/es.array.map.js");
38
-
39
- require("core-js/modules/es.array.join.js");
40
-
41
- require("core-js/modules/es.array.concat.js");
42
-
43
- require("core-js/modules/es.object.keys.js");
44
-
45
- require("core-js/modules/es.object.entries.js");
46
-
47
- require("core-js/modules/es.array.sort.js");
48
-
49
- require("core-js/modules/es.function.name.js");
50
-
51
- require("core-js/modules/es.object.assign.js");
52
-
53
- var _tsDedent = _interopRequireDefault(require("ts-dedent"));
54
-
55
- var _templateObject;
56
-
57
- var _excluded = ["title", "imports", "decorators", "stories"],
58
- _excluded2 = ["name"];
59
-
60
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
61
-
62
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
63
-
64
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
65
-
66
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
67
-
68
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
69
-
70
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
71
-
72
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
73
-
74
- 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; }
75
-
76
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
77
-
78
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
79
-
80
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
81
-
82
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
83
-
84
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
85
-
86
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
87
-
88
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
89
-
90
- var _require = require('safe-identifier'),
91
- identifier = _require.identifier;
92
-
93
- function stringifyObject(object) {
94
- var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
95
- var excludeOuterParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
96
-
97
- if (typeof object === 'string') {
98
- return JSON.stringify(object);
99
- }
100
-
101
- var indent = ' '.repeat(level);
102
-
103
- if (Array.isArray(object)) {
104
- var arrayStrings = object.map(function (item) {
105
- return stringifyObject(item, level + 1);
106
- });
107
- var arrayString = arrayStrings.join(",\n".concat(indent, " "));
108
- if (excludeOuterParams) return arrayString;
109
- return "[\n".concat(indent, " ").concat(arrayString, "\n").concat(indent, "]");
110
- }
111
-
112
- if (_typeof(object) === 'object') {
113
- var objectString = '';
114
-
115
- if (Object.keys(object).length > 0) {
116
- var objectStrings = Object.keys(object).map(function (key) {
117
- var value = stringifyObject(object[key], level + 1);
118
- return "\n".concat(indent, " ").concat(key, ": ").concat(value);
119
- });
120
- objectString = objectStrings.join(',');
121
- }
122
-
123
- if (excludeOuterParams) return objectString;
124
- if (objectString.length === 0) return '{}';
125
- return "{".concat(objectString, "\n").concat(indent, "}");
126
- }
127
-
128
- return object;
129
- }
130
-
131
- function stringifyImports(imports) {
132
- if (Object.keys(imports).length === 0) return '';
133
- return Object.entries(imports).map(function (_ref) {
134
- var _ref2 = _slicedToArray(_ref, 2),
135
- module = _ref2[0],
136
- names = _ref2[1];
137
-
138
- return "import { ".concat(names.sort().join(', '), " } from '").concat(module, "';\n");
139
- }).join('');
140
- }
141
-
142
- function stringifyDecorators(decorators) {
143
- return decorators && decorators.length > 0 ? "\n decorators: [\n ".concat(decorators.join(',\n '), "\n ],") : '';
144
- }
145
-
146
- function stringifyDefault(section) {
147
- var title = section.title,
148
- imports = section.imports,
149
- decorators = section.decorators,
150
- stories = section.stories,
151
- options = _objectWithoutProperties(section, _excluded);
152
-
153
- var decoratorsString = stringifyDecorators(decorators);
154
- var optionsString = stringifyObject(options, 0, true);
155
- return (0, _tsDedent.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n export default {\n title: ", ",", "", "\n };\n \n "])), JSON.stringify(title), decoratorsString, optionsString);
156
- }
157
-
158
- function stringifyStory(story) {
159
- var name = story.name,
160
- options = _objectWithoutProperties(story, _excluded2);
161
-
162
- var storyId = identifier(name);
163
- var exportedStory = Object.assign({
164
- name: name
165
- }, options);
166
- var storyStrings = ["export const ".concat(storyId, " = ").concat(stringifyObject(exportedStory), ";"), ''];
167
- return storyStrings.join('\n');
168
- }
169
-
170
- function stringifySection(section) {
171
- var sectionString = [stringifyImports(section.imports), stringifyDefault(section)].concat(_toConsumableArray(section.stories.map(function (story) {
172
- return stringifyStory(story);
173
- }))).join('\n');
174
- return sectionString;
175
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -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 = function _default(content) {
11
- try {
12
- var 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
@@ -1,10 +0,0 @@
1
- import { compileCsfModule } from './lib/compiler';
2
- export default (content => {
3
- try {
4
- const after = compileCsfModule(JSON.parse(content));
5
- return after;
6
- } catch (e) {//
7
- }
8
-
9
- return content;
10
- });
@@ -1,2 +0,0 @@
1
- import type { StorybookConfig } from '@storybook/core-webpack';
2
- export declare const webpack: StorybookConfig['webpack'];
@@ -1,2 +0,0 @@
1
- import { CompileCsfModuleArgs } from './types';
2
- export declare function compileCsfModule(args: CompileCsfModuleArgs): string;
@@ -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
- }