@storybook/core-server 6.4.0-alpha.7 → 6.4.0-beta.1

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.
Files changed (40) hide show
  1. package/dist/cjs/build-dev.js +8 -2
  2. package/dist/cjs/build-static.js +11 -5
  3. package/dist/cjs/cli/dev.js +1 -1
  4. package/dist/cjs/cli/utils.js +5 -1
  5. package/dist/cjs/dev-server.js +5 -2
  6. package/dist/cjs/presets/common-preset.js +8 -1
  7. package/dist/cjs/utils/StoryIndexGenerator.js +163 -0
  8. package/dist/cjs/utils/output-startup-information.js +2 -1
  9. package/dist/cjs/utils/output-stats.js +17 -4
  10. package/dist/cjs/utils/stories-json.js +17 -81
  11. package/dist/esm/build-dev.js +8 -2
  12. package/dist/esm/build-static.js +12 -6
  13. package/dist/esm/cli/dev.js +1 -1
  14. package/dist/esm/cli/utils.js +5 -1
  15. package/dist/esm/dev-server.js +5 -2
  16. package/dist/esm/presets/common-preset.js +9 -2
  17. package/dist/esm/utils/StoryIndexGenerator.js +140 -0
  18. package/dist/esm/utils/output-startup-information.js +2 -1
  19. package/dist/esm/utils/output-stats.js +16 -3
  20. package/dist/esm/utils/stories-json.js +18 -74
  21. package/dist/modern/build-dev.js +8 -2
  22. package/dist/modern/build-static.js +12 -6
  23. package/dist/modern/cli/dev.js +1 -1
  24. package/dist/modern/cli/utils.js +5 -1
  25. package/dist/modern/dev-server.js +5 -2
  26. package/dist/modern/presets/common-preset.js +9 -2
  27. package/dist/modern/utils/StoryIndexGenerator.js +140 -0
  28. package/dist/modern/utils/output-startup-information.js +2 -1
  29. package/dist/modern/utils/output-stats.js +16 -3
  30. package/dist/modern/utils/stories-json.js +18 -74
  31. package/dist/ts3.4/presets/common-preset.d.ts +1 -1
  32. package/dist/ts3.4/utils/StoryIndexGenerator.d.ts +17 -0
  33. package/dist/ts3.4/utils/output-startup-information.d.ts +1 -0
  34. package/dist/ts3.4/utils/stories-json.d.ts +2 -2
  35. package/dist/ts3.9/presets/common-preset.d.ts +1 -1
  36. package/dist/ts3.9/utils/StoryIndexGenerator.d.ts +17 -0
  37. package/dist/ts3.9/utils/output-startup-information.d.ts +1 -0
  38. package/dist/ts3.9/utils/stories-json.d.ts +2 -2
  39. package/package.json +16 -14
  40. package/typings.d.ts +3 -2
@@ -62,7 +62,9 @@ async function buildDevStandalone(options) {
62
62
  var packageJson = options.packageJson,
63
63
  versionUpdates = options.versionUpdates,
64
64
  releaseNotes = options.releaseNotes;
65
- var version = packageJson.version; // updateInfo and releaseNotesData are cached, so this is typically pretty fast
65
+ var version = packageJson.version,
66
+ _packageJson$name = packageJson.name,
67
+ name = _packageJson$name === void 0 ? '' : _packageJson$name; // updateInfo and releaseNotesData are cached, so this is typically pretty fast
66
68
 
67
69
  var _await$Promise$all = await Promise.all([(0, _serverAddress.getServerPort)(options.port), versionUpdates ? (0, _updateCheck.updateCheck)(version) : Promise.resolve({
68
70
  success: false,
@@ -135,11 +137,15 @@ async function buildDevStandalone(options) {
135
137
  if (previewWarnings.length > 0) _nodeLogger.logger.warn(`preview: ${previewWarnings}`);
136
138
  process.exit(managerWarnings.length > 0 || previewWarnings.length > 0 && !options.ignorePreview ? 1 : 0);
137
139
  return;
138
- }
140
+ } // Get package name and capitalize it e.g. @storybook/react -> React
141
+
139
142
 
143
+ var packageName = name.split('@storybook/').length > 0 ? name.split('@storybook/')[1] : name;
144
+ var frameworkName = packageName.charAt(0).toUpperCase() + packageName.slice(1);
140
145
  (0, _outputStartupInformation.outputStartupInformation)({
141
146
  updateInfo: versionCheck,
142
147
  version: version,
148
+ name: frameworkName,
143
149
  address: address,
144
150
  networkAddress: networkAddress,
145
151
  managerTotalTime: managerTotalTime,
@@ -99,11 +99,12 @@ async function buildStaticStandalone(options) {
99
99
  }, options));
100
100
  var features = await presets.apply('features');
101
101
 
102
- if (features !== null && features !== void 0 && features.buildStoriesJson) {
103
- var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories'), options.configDir);
104
- await (0, _storiesJson.extractStoriesJson)(_path.default.join(options.outputDir, 'stories.json'), stories.map(function (s) {
105
- return s.glob;
106
- }), options.configDir);
102
+ if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
103
+ var stories = (0, _coreCommon.normalizeStories)(await presets.apply('stories'), {
104
+ configDir: options.configDir,
105
+ workingDir: process.cwd()
106
+ });
107
+ await (0, _storiesJson.extractStoriesJson)(_path.default.join(options.outputDir, 'stories.json'), stories, options.configDir);
107
108
  }
108
109
 
109
110
  var fullOptions = _objectSpread(_objectSpread({}, options), {}, {
@@ -111,6 +112,11 @@ async function buildStaticStandalone(options) {
111
112
  features: features
112
113
  });
113
114
 
115
+ if (options.debugWebpack) {
116
+ (0, _coreCommon.logConfig)('Preview webpack config', await previewBuilder.getConfig(fullOptions));
117
+ (0, _coreCommon.logConfig)('Manager webpack config', await managerBuilder.getConfig(fullOptions));
118
+ }
119
+
114
120
  var core = await presets.apply('core');
115
121
 
116
122
  var _ref = (core === null || core === void 0 ? void 0 : core.builder) === 'webpack5' ? await Promise.resolve().then(function () {
@@ -28,7 +28,7 @@ async function getDevCli(packageJson) {
28
28
 
29
29
  _commander.default.version(packageJson.version).option('-p, --port <number>', 'Port to run Storybook', function (str) {
30
30
  return parseInt(str, 10);
31
- }).option('-h, --host <string>', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from').option('--https', 'Serve Storybook over HTTPS. Note: You must provide your own certificate information.').option('--ssl-ca <ca>', 'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)', _utils.parseList).option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)').option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)').option('--smoke-test', 'Exit after successful start').option('--ci', "CI mode (skip interactive prompts, don't open browser)").option('--loglevel <level>', 'Control level of logging during build').option('--quiet', 'Suppress verbose build output').option('--no-version-updates', 'Suppress update check', true).option('--no-release-notes', 'Suppress automatic redirects to the release notes after upgrading', true).option('--no-manager-cache', 'Do not cache the manager UI').option('--no-dll', 'Do not use dll references (no-op)').option('--docs-dll', 'Use Docs dll reference (legacy)').option('--ui-dll', 'Use UI dll reference (legacy)').option('--debug-webpack', 'Display final webpack configurations for debugging purposes').option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk').option('--preview-url <string>', 'Disables the default storybook preview and lets your use your own').option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url').option('--docs', 'Build a documentation-only site using addon-docs').option('--modern', 'Use modern browser modules').parse(process.argv);
31
+ }).option('-h, --host <string>', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from').option('--https', 'Serve Storybook over HTTPS. Note: You must provide your own certificate information.').option('--ssl-ca <ca>', 'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)', _utils.parseList).option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)').option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)').option('--smoke-test', 'Exit after successful start').option('--ci', "CI mode (skip interactive prompts, don't open browser)").option('--no-open', 'Do not open Storybook automatically in the browser').option('--loglevel <level>', 'Control level of logging during build').option('--quiet', 'Suppress verbose build output').option('--no-version-updates', 'Suppress update check', true).option('--no-release-notes', 'Suppress automatic redirects to the release notes after upgrading', true).option('--no-manager-cache', 'Do not cache the manager UI').option('--no-dll', 'Do not use dll references (no-op)').option('--docs-dll', 'Use Docs dll reference (legacy)').option('--ui-dll', 'Use UI dll reference (legacy)').option('--debug-webpack', 'Display final webpack configurations for debugging purposes').option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk').option('--preview-url <string>', 'Disables the default storybook preview and lets your use your own').option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url').option('--docs', 'Build a documentation-only site using addon-docs').option('--modern', 'Use modern browser modules').parse(process.argv);
32
32
 
33
33
  _nodeLogger.logger.setLevel(_commander.default.loglevel); // Workaround the `-h` shorthand conflict.
34
34
  // Output the help if `-h` is called without any value.
@@ -14,7 +14,11 @@ var _tsDedent = _interopRequireDefault(require("ts-dedent"));
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  function parseList(str) {
17
- return str.split(',');
17
+ return str.split(',').map(function (item) {
18
+ return item.trim();
19
+ }).filter(function (item) {
20
+ return item.length > 0;
21
+ });
18
22
  }
19
23
 
20
24
  function getEnvConfig(program, configEnv) {
@@ -75,7 +75,7 @@ async function storybookDevServer(options) {
75
75
  await (0, _serverStatics.useStatics)(router, options);
76
76
  var features = await options.presets.apply('features');
77
77
 
78
- if (features !== null && features !== void 0 && features.buildStoriesJson) {
78
+ if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
79
79
  await (0, _storiesJson.useStoriesJson)(router, options);
80
80
  }
81
81
 
@@ -131,7 +131,10 @@ async function storybookDevServer(options) {
131
131
  managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough
132
132
 
133
133
 
134
- if (!options.ci && !options.smokeTest) (0, _openInBrowser.openInBrowser)(host ? networkAddress : address);
134
+ if (!options.ci && !options.smokeTest && options.open) {
135
+ (0, _openInBrowser.openInBrowser)(host ? networkAddress : address);
136
+ }
137
+
135
138
  return {
136
139
  previewResult: previewResult,
137
140
  managerResult: managerResult,
@@ -16,10 +16,17 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
16
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
17
 
18
18
  var babel = async function (_, options) {
19
+ var _options$features;
20
+
19
21
  var configDir = options.configDir,
20
22
  presets = options.presets;
23
+
24
+ if ((_options$features = options.features) !== null && _options$features !== void 0 && _options$features.babelModeV7) {
25
+ return presets.apply('babelDefault', {}, options);
26
+ }
27
+
21
28
  return (0, _coreCommon.loadCustomBabelConfig)(configDir, function () {
22
- return presets.apply('babelDefault', (0, _coreCommon.babelConfig)(), options);
29
+ return presets.apply('babelDefault', (0, _coreCommon.getStorybookBabelConfig)(), options);
23
30
  });
24
31
  };
25
32
 
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StoryIndexGenerator = void 0;
7
+
8
+ require("core-js/modules/es.promise.js");
9
+
10
+ require("core-js/modules/es.array.flat-map.js");
11
+
12
+ require("core-js/modules/es.array.unscopables.flat-map.js");
13
+
14
+ var _path = _interopRequireDefault(require("path"));
15
+
16
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
17
+
18
+ var _globby = _interopRequireDefault(require("globby"));
19
+
20
+ var _store = require("@storybook/store");
21
+
22
+ var _nodeLogger = require("@storybook/node-logger");
23
+
24
+ var _csfTools = require("@storybook/csf-tools");
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ function sortExtractedStories(stories, storySortParameter, fileNameOrder) {
29
+ var sortableStories = Object.values(stories);
30
+ (0, _store.sortStoriesV7)(sortableStories, storySortParameter, fileNameOrder);
31
+ return sortableStories.reduce(function (acc, item) {
32
+ acc[item.id] = item;
33
+ return acc;
34
+ }, {});
35
+ }
36
+
37
+ class StoryIndexGenerator {
38
+ // An internal cache mapping specifiers to a set of path=><set of stories>
39
+ // Later, we'll combine each of these subsets together to form the full index
40
+ constructor(specifiers, configDir) {
41
+ this.specifiers = specifiers;
42
+ this.configDir = configDir;
43
+ this.storyIndexEntries = void 0;
44
+ this.storyIndexEntries = new Map();
45
+ }
46
+
47
+ async initialize() {
48
+ var _this = this;
49
+
50
+ // Find all matching paths for each specifier
51
+ await Promise.all(this.specifiers.map(async function (specifier) {
52
+ var pathToSubIndex = {};
53
+ var files = await (0, _globby.default)(_path.default.join(_this.configDir, specifier.glob));
54
+ files.forEach(function (fileName) {
55
+ pathToSubIndex[fileName] = false;
56
+ });
57
+
58
+ _this.storyIndexEntries.set(specifier, pathToSubIndex);
59
+ })); // Extract stories for each file
60
+
61
+ await this.ensureExtracted();
62
+ }
63
+
64
+ async ensureExtracted() {
65
+ var _this2 = this;
66
+
67
+ await Promise.all(this.specifiers.map(async function (specifier) {
68
+ var entry = _this2.storyIndexEntries.get(specifier);
69
+
70
+ await Promise.all(Object.keys(entry).map(async function (fileName) {
71
+ if (!entry[fileName]) await _this2.extractStories(specifier, fileName);
72
+ }));
73
+ }));
74
+ }
75
+
76
+ async extractStories(specifier, absolutePath) {
77
+ var ext = _path.default.extname(absolutePath);
78
+
79
+ var relativePath = _path.default.relative(this.configDir, absolutePath);
80
+
81
+ if (!['.js', '.jsx', '.ts', '.tsx', '.mdx'].includes(ext)) {
82
+ _nodeLogger.logger.info(`Skipping ${ext} file ${relativePath}`);
83
+
84
+ return;
85
+ }
86
+
87
+ try {
88
+ var entry = this.storyIndexEntries.get(specifier);
89
+ var fileStories = {};
90
+ var importPath = relativePath[0] === '.' ? relativePath : `./${relativePath}`;
91
+ var defaultTitle = (0, _store.autoTitleFromSpecifier)(importPath, specifier);
92
+ var csf = (await (0, _csfTools.readCsfOrMdx)(absolutePath, {
93
+ defaultTitle: defaultTitle
94
+ })).parse();
95
+ csf.stories.forEach(function ({
96
+ id: id,
97
+ name: name
98
+ }) {
99
+ fileStories[id] = {
100
+ id: id,
101
+ title: csf.meta.title,
102
+ name: name,
103
+ importPath: importPath
104
+ };
105
+ });
106
+ entry[absolutePath] = fileStories;
107
+ } catch (err) {
108
+ _nodeLogger.logger.warn(`🚨 Extraction error on ${relativePath}: ${err}`);
109
+
110
+ _nodeLogger.logger.warn(`🚨 ${err.stack}`);
111
+
112
+ throw err;
113
+ }
114
+ }
115
+
116
+ async getIndex() {
117
+ var _this3 = this;
118
+
119
+ // Extract any entries that are currently missing
120
+ await this.ensureExtracted();
121
+ var stories = {}; // Check each entry and compose into stories, extracting if needed
122
+
123
+ this.specifiers.map(async function (specifier) {
124
+ Object.values(_this3.storyIndexEntries.get(specifier)).map(function (subStories) {
125
+ return Object.assign(stories, subStories);
126
+ });
127
+ });
128
+ var storySortParameter = await this.getStorySortParameter();
129
+ var sorted = sortExtractedStories(stories, storySortParameter, this.storyFileNames());
130
+ return {
131
+ v: 3,
132
+ stories: sorted
133
+ };
134
+ }
135
+
136
+ async getStorySortParameter() {
137
+ var _this4 = this;
138
+
139
+ var previewFile = ['js', 'jsx', 'ts', 'tsx'].map(function (ext) {
140
+ return _path.default.join(_this4.configDir, `preview.${ext}`);
141
+ }).find(function (fname) {
142
+ return _fsExtra.default.existsSync(fname);
143
+ });
144
+ var storySortParameter;
145
+
146
+ if (previewFile) {
147
+ var previewCode = (await _fsExtra.default.readFile(previewFile, 'utf-8')).toString();
148
+ storySortParameter = await (0, _csfTools.getStorySortParameter)(previewCode);
149
+ }
150
+
151
+ return storySortParameter;
152
+ } // Get the story file names in "imported order"
153
+
154
+
155
+ storyFileNames() {
156
+ return Array.from(this.storyIndexEntries.values()).flatMap(function (r) {
157
+ return Object.keys(r);
158
+ });
159
+ }
160
+
161
+ }
162
+
163
+ exports.StoryIndexGenerator = StoryIndexGenerator;
@@ -24,6 +24,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
24
  function outputStartupInformation(options) {
25
25
  var updateInfo = options.updateInfo,
26
26
  version = options.version,
27
+ name = options.name,
27
28
  address = options.address,
28
29
  networkAddress = options.networkAddress,
29
30
  managerTotalTime = options.managerTotalTime,
@@ -57,7 +58,7 @@ function outputStartupInformation(options) {
57
58
  var timeStatement = [managerTotalTime && `${_chalk.default.underline((0, _prettyHrtime.default)(managerTotalTime))} for manager`, previewTotalTime && `${_chalk.default.underline((0, _prettyHrtime.default)(previewTotalTime))} for preview`].filter(Boolean).join(' and '); // eslint-disable-next-line no-console
58
59
 
59
60
  console.log((0, _boxen.default)((0, _tsDedent.default)`
60
- ${_nodeLogger.colors.green(`Storybook ${_chalk.default.bold(version)} started`)}
61
+ ${_nodeLogger.colors.green(`Storybook ${_chalk.default.bold(version)} for ${_chalk.default.bold(name)} started`)}
61
62
  ${_chalk.default.gray(timeStatement)}
62
63
 
63
64
  ${serveMessage.toString()}${updateMessage ? `\n\n${updateMessage}` : ''}
@@ -8,16 +8,22 @@ exports.writeStats = void 0;
8
8
 
9
9
  require("core-js/modules/es.promise.js");
10
10
 
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
-
13
- var _path = _interopRequireDefault(require("path"));
11
+ var _jsonExt = require("@discoveryjs/json-ext");
14
12
 
15
13
  var _nodeLogger = require("@storybook/node-logger");
16
14
 
15
+ var _chalk = _interopRequireDefault(require("chalk"));
16
+
17
17
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
18
18
 
19
+ var _path = _interopRequireDefault(require("path"));
20
+
19
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
22
 
23
+ 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; }
24
+
25
+ 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; }
26
+
21
27
  async function outputStats(directory, previewStats, managerStats) {
22
28
  if (previewStats) {
23
29
  var filePath = await writeStats(directory, 'preview', previewStats);
@@ -35,7 +41,14 @@ async function outputStats(directory, previewStats, managerStats) {
35
41
  var writeStats = async function (directory, name, stats) {
36
42
  var filePath = _path.default.join(directory, `${name}-stats.json`);
37
43
 
38
- await _fsExtra.default.outputFile(filePath, JSON.stringify(stats.toJson(), null, 2), 'utf8');
44
+ var _stats$toJson = stats.toJson(),
45
+ chunks = _stats$toJson.chunks,
46
+ data = _objectWithoutProperties(_stats$toJson, ["chunks"]); // omit chunks, which is about half of the total data
47
+
48
+
49
+ await new Promise(function (resolve, reject) {
50
+ (0, _jsonExt.stringifyStream)(data, null, 2).on('error', reject).pipe(_fsExtra.default.createWriteStream(filePath)).on('error', reject).on('finish', resolve);
51
+ });
39
52
  return filePath;
40
53
  };
41
54
 
@@ -8,100 +8,36 @@ exports.useStoriesJson = useStoriesJson;
8
8
 
9
9
  require("core-js/modules/es.promise.js");
10
10
 
11
- var _path = _interopRequireDefault(require("path"));
12
-
13
11
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
14
12
 
15
- var _globby = _interopRequireDefault(require("globby"));
16
-
17
- var _nodeLogger = require("@storybook/node-logger");
18
-
19
13
  var _coreCommon = require("@storybook/core-common");
20
14
 
21
- var _csfTools = require("@storybook/csf-tools");
15
+ var _StoryIndexGenerator = require("./StoryIndexGenerator");
22
16
 
23
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
18
 
25
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
26
-
27
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
28
-
29
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
-
31
- async function extractStoriesJson(ouputFile, storiesGlobs, configDir) {
32
- if (!storiesGlobs) {
33
- throw new Error('No stories glob');
34
- }
35
-
36
- var storyFiles = [];
37
- await Promise.all(storiesGlobs.map(async function (storiesGlob) {
38
- var files = await (0, _globby.default)(_path.default.join(configDir, storiesGlob));
39
- storyFiles.push(...files);
40
- }));
41
-
42
- _nodeLogger.logger.info(`⚙️ Processing ${storyFiles.length} story files from ${storiesGlobs}`);
43
-
44
- var stories = {};
45
- await Promise.all(storyFiles.map(async function (absolutePath) {
46
- var ext = _path.default.extname(absolutePath);
47
-
48
- var relativePath = _path.default.relative(configDir, absolutePath);
49
-
50
- if (!['.js', '.jsx', '.ts', '.tsx'].includes(ext)) {
51
- _nodeLogger.logger.info(`Skipping ${ext} file ${relativePath}`);
52
-
53
- return;
54
- }
55
-
56
- try {
57
- var csf = (await (0, _csfTools.readCsf)(absolutePath)).parse();
58
- csf.stories.forEach(function (story) {
59
- stories[story.id] = _objectSpread(_objectSpread({}, story), {}, {
60
- kind: csf.meta.title,
61
- parameters: _objectSpread(_objectSpread({}, story.parameters), {}, {
62
- fileName: relativePath
63
- })
64
- });
65
- });
66
- } catch (err) {
67
- _nodeLogger.logger.error(`🚨 Extraction error on ${relativePath}`);
68
-
69
- throw err;
70
- }
71
- }));
72
- await _fsExtra.default.writeJson(ouputFile, {
73
- v: 3,
74
- stories: stories
75
- });
19
+ async function extractStoriesJson(outputFile, normalizedStories, configDir) {
20
+ var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalizedStories, configDir);
21
+ await generator.initialize();
22
+ var index = await generator.getIndex();
23
+ await _fsExtra.default.writeJson(outputFile, index);
76
24
  }
77
25
 
78
- var timeout = 30000; // 30s
79
-
80
- var step = 100; // .1s
81
-
82
26
  async function useStoriesJson(router, options) {
83
- var storiesJson = (0, _coreCommon.resolvePathInStorybookCache)('stories.json');
84
- await _fsExtra.default.remove(storiesJson);
85
- var stories = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), options.configDir);
86
- var globs = stories.map(function (s) {
87
- return s.glob;
27
+ var normalized = (0, _coreCommon.normalizeStories)(await options.presets.apply('stories'), {
28
+ configDir: options.configDir,
29
+ workingDir: process.cwd()
88
30
  });
89
- extractStoriesJson(storiesJson, globs, options.configDir);
90
31
  router.use('/stories.json', async function (_req, res) {
91
- for (var i = 0; i < timeout / step; i += 1) {
92
- if (_fsExtra.default.existsSync(storiesJson)) {
93
- // eslint-disable-next-line no-await-in-loop
94
- var json = await _fsExtra.default.readFile(storiesJson, 'utf-8');
95
- res.header('Content-Type', 'application/json');
96
- return res.send(json);
97
- } // eslint-disable-next-line no-await-in-loop
98
-
32
+ var generator = new _StoryIndexGenerator.StoryIndexGenerator(normalized, options.configDir);
33
+ await generator.initialize();
99
34
 
100
- await new Promise(function (r) {
101
- return setTimeout(r, step);
102
- });
35
+ try {
36
+ var index = await generator.getIndex();
37
+ res.header('Content-Type', 'application/json');
38
+ return res.send(JSON.stringify(index));
39
+ } catch (err) {
40
+ return res.status(500).send(err.message);
103
41
  }
104
-
105
- return res.status(408).send('stories.json timeout');
106
42
  });
107
43
  }
@@ -36,7 +36,9 @@ export async function buildDevStandalone(options) {
36
36
  var packageJson = options.packageJson,
37
37
  versionUpdates = options.versionUpdates,
38
38
  releaseNotes = options.releaseNotes;
39
- var version = packageJson.version; // updateInfo and releaseNotesData are cached, so this is typically pretty fast
39
+ var version = packageJson.version,
40
+ _packageJson$name = packageJson.name,
41
+ name = _packageJson$name === void 0 ? '' : _packageJson$name; // updateInfo and releaseNotesData are cached, so this is typically pretty fast
40
42
 
41
43
  var _await$Promise$all = await Promise.all([getServerPort(options.port), versionUpdates ? updateCheck(version) : Promise.resolve({
42
44
  success: false,
@@ -109,11 +111,15 @@ export async function buildDevStandalone(options) {
109
111
  if (previewWarnings.length > 0) logger.warn(`preview: ${previewWarnings}`);
110
112
  process.exit(managerWarnings.length > 0 || previewWarnings.length > 0 && !options.ignorePreview ? 1 : 0);
111
113
  return;
112
- }
114
+ } // Get package name and capitalize it e.g. @storybook/react -> React
115
+
113
116
 
117
+ var packageName = name.split('@storybook/').length > 0 ? name.split('@storybook/')[1] : name;
118
+ var frameworkName = packageName.charAt(0).toUpperCase() + packageName.slice(1);
114
119
  outputStartupInformation({
115
120
  updateInfo: versionCheck,
116
121
  version: version,
122
+ name: frameworkName,
117
123
  address: address,
118
124
  networkAddress: networkAddress,
119
125
  managerTotalTime: managerTotalTime,
@@ -27,7 +27,7 @@ import cpy from 'cpy';
27
27
  import fs from 'fs-extra';
28
28
  import path from 'path';
29
29
  import { logger } from '@storybook/node-logger';
30
- import { loadAllPresets, cache, normalizeStories } from '@storybook/core-common';
30
+ import { loadAllPresets, cache, normalizeStories, logConfig } from '@storybook/core-common';
31
31
  import { getProdCli } from './cli';
32
32
  import { outputStats } from './utils/output-stats';
33
33
  import { copyAllStaticFiles } from './utils/copy-all-static-files';
@@ -71,11 +71,12 @@ export async function buildStaticStandalone(options) {
71
71
  }, options));
72
72
  var features = await presets.apply('features');
73
73
 
74
- if (features !== null && features !== void 0 && features.buildStoriesJson) {
75
- var stories = normalizeStories(await presets.apply('stories'), options.configDir);
76
- await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories.map(function (s) {
77
- return s.glob;
78
- }), options.configDir);
74
+ if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
75
+ var stories = normalizeStories(await presets.apply('stories'), {
76
+ configDir: options.configDir,
77
+ workingDir: process.cwd()
78
+ });
79
+ await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories, options.configDir);
79
80
  }
80
81
 
81
82
  var fullOptions = _objectSpread(_objectSpread({}, options), {}, {
@@ -83,6 +84,11 @@ export async function buildStaticStandalone(options) {
83
84
  features: features
84
85
  });
85
86
 
87
+ if (options.debugWebpack) {
88
+ logConfig('Preview webpack config', await previewBuilder.getConfig(fullOptions));
89
+ logConfig('Manager webpack config', await managerBuilder.getConfig(fullOptions));
90
+ }
91
+
86
92
  var core = await presets.apply('core');
87
93
 
88
94
  var _ref = (core === null || core === void 0 ? void 0 : core.builder) === 'webpack5' ? await import('@storybook/manager-webpack5/prebuilt-manager') : await import('@storybook/manager-webpack4/prebuilt-manager'),
@@ -13,7 +13,7 @@ export async function getDevCli(packageJson) {
13
13
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
14
14
  program.version(packageJson.version).option('-p, --port <number>', 'Port to run Storybook', function (str) {
15
15
  return parseInt(str, 10);
16
- }).option('-h, --host <string>', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList).option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from').option('--https', 'Serve Storybook over HTTPS. Note: You must provide your own certificate information.').option('--ssl-ca <ca>', 'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)', parseList).option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)').option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)').option('--smoke-test', 'Exit after successful start').option('--ci', "CI mode (skip interactive prompts, don't open browser)").option('--loglevel <level>', 'Control level of logging during build').option('--quiet', 'Suppress verbose build output').option('--no-version-updates', 'Suppress update check', true).option('--no-release-notes', 'Suppress automatic redirects to the release notes after upgrading', true).option('--no-manager-cache', 'Do not cache the manager UI').option('--no-dll', 'Do not use dll references (no-op)').option('--docs-dll', 'Use Docs dll reference (legacy)').option('--ui-dll', 'Use UI dll reference (legacy)').option('--debug-webpack', 'Display final webpack configurations for debugging purposes').option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk').option('--preview-url <string>', 'Disables the default storybook preview and lets your use your own').option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url').option('--docs', 'Build a documentation-only site using addon-docs').option('--modern', 'Use modern browser modules').parse(process.argv);
16
+ }).option('-h, --host <string>', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList).option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from').option('--https', 'Serve Storybook over HTTPS. Note: You must provide your own certificate information.').option('--ssl-ca <ca>', 'Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)', parseList).option('--ssl-cert <cert>', 'Provide an SSL certificate. (Required with --https)').option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)').option('--smoke-test', 'Exit after successful start').option('--ci', "CI mode (skip interactive prompts, don't open browser)").option('--no-open', 'Do not open Storybook automatically in the browser').option('--loglevel <level>', 'Control level of logging during build').option('--quiet', 'Suppress verbose build output').option('--no-version-updates', 'Suppress update check', true).option('--no-release-notes', 'Suppress automatic redirects to the release notes after upgrading', true).option('--no-manager-cache', 'Do not cache the manager UI').option('--no-dll', 'Do not use dll references (no-op)').option('--docs-dll', 'Use Docs dll reference (legacy)').option('--ui-dll', 'Use UI dll reference (legacy)').option('--debug-webpack', 'Display final webpack configurations for debugging purposes').option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk').option('--preview-url <string>', 'Disables the default storybook preview and lets your use your own').option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url').option('--docs', 'Build a documentation-only site using addon-docs').option('--modern', 'Use modern browser modules').parse(process.argv);
17
17
  logger.setLevel(program.loglevel); // Workaround the `-h` shorthand conflict.
18
18
  // Output the help if `-h` is called without any value.
19
19
  // See storybookjs/storybook#5360
@@ -1,7 +1,11 @@
1
1
  import deprecate from 'util-deprecate';
2
2
  import dedent from 'ts-dedent';
3
3
  export function parseList(str) {
4
- return str.split(',');
4
+ return str.split(',').map(function (item) {
5
+ return item.trim();
6
+ }).filter(function (item) {
7
+ return item.length > 0;
8
+ });
5
9
  }
6
10
  export function getEnvConfig(program, configEnv) {
7
11
  Object.keys(configEnv).forEach(function (fieldName) {
@@ -46,7 +46,7 @@ export async function storybookDevServer(options) {
46
46
  await useStatics(router, options);
47
47
  var features = await options.presets.apply('features');
48
48
 
49
- if (features !== null && features !== void 0 && features.buildStoriesJson) {
49
+ if (features !== null && features !== void 0 && features.buildStoriesJson || features !== null && features !== void 0 && features.storyStoreV7) {
50
50
  await useStoriesJson(router, options);
51
51
  }
52
52
 
@@ -102,7 +102,10 @@ export async function storybookDevServer(options) {
102
102
  managerResult = _await$Promise$all2[1]; // TODO #13083 Remove this when compiling the preview is fast enough
103
103
 
104
104
 
105
- if (!options.ci && !options.smokeTest) openInBrowser(host ? networkAddress : address);
105
+ if (!options.ci && !options.smokeTest && options.open) {
106
+ openInBrowser(host ? networkAddress : address);
107
+ }
108
+
106
109
  return {
107
110
  previewResult: previewResult,
108
111
  managerResult: managerResult,
@@ -5,12 +5,19 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import "core-js/modules/es.promise.js";
8
- import { getPreviewBodyTemplate, getPreviewHeadTemplate, getManagerMainTemplate, getPreviewMainTemplate, loadCustomBabelConfig, babelConfig, loadEnvs } from '@storybook/core-common';
8
+ import { getPreviewBodyTemplate, getPreviewHeadTemplate, getManagerMainTemplate, getPreviewMainTemplate, loadCustomBabelConfig, getStorybookBabelConfig, loadEnvs } from '@storybook/core-common';
9
9
  export var babel = async function (_, options) {
10
+ var _options$features;
11
+
10
12
  var configDir = options.configDir,
11
13
  presets = options.presets;
14
+
15
+ if ((_options$features = options.features) !== null && _options$features !== void 0 && _options$features.babelModeV7) {
16
+ return presets.apply('babelDefault', {}, options);
17
+ }
18
+
12
19
  return loadCustomBabelConfig(configDir, function () {
13
- return presets.apply('babelDefault', babelConfig(), options);
20
+ return presets.apply('babelDefault', getStorybookBabelConfig(), options);
14
21
  });
15
22
  };
16
23
  export var logLevel = function (previous, options) {