@storybook/cli 7.0.0-alpha.1 → 7.0.0-alpha.12
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/cjs/automigrate/fixes/angular12.js +2 -2
- package/dist/cjs/automigrate/fixes/builder-vite.js +2 -2
- package/dist/cjs/automigrate/fixes/cra5.js +2 -2
- package/dist/cjs/automigrate/fixes/eslint-plugin.js +3 -3
- package/dist/cjs/automigrate/fixes/index.js +3 -1
- package/dist/cjs/automigrate/fixes/mainjsFramework.js +3 -3
- package/dist/cjs/automigrate/fixes/npm7.js +59 -0
- package/dist/cjs/automigrate/fixes/vue3.js +2 -2
- package/dist/cjs/automigrate/fixes/webpack5.js +5 -5
- package/dist/cjs/automigrate/index.js +9 -3
- package/dist/cjs/babel-config.js +5 -4
- package/dist/cjs/dev.js +3 -5
- package/dist/cjs/frameworks/angular/Button.stories.ts +6 -4
- package/dist/cjs/frameworks/angular/Header.stories.ts +2 -2
- package/dist/cjs/frameworks/angular/Page.stories.ts +3 -3
- package/dist/cjs/frameworks/html/ts/Button.stories.ts +3 -3
- package/dist/cjs/frameworks/html/ts/Button.ts +6 -2
- package/dist/cjs/frameworks/html/ts/Header.stories.ts +3 -3
- package/dist/cjs/frameworks/html/ts/Page.stories.ts +2 -2
- package/dist/cjs/frameworks/html/ts/Page.ts +4 -4
- package/dist/cjs/frameworks/react/ts/Button.stories.tsx +2 -2
- package/dist/cjs/frameworks/react/ts/Header.stories.tsx +2 -2
- package/dist/cjs/frameworks/react/ts/Page.stories.tsx +2 -2
- package/dist/cjs/frameworks/web-components/ts/Button.stories.ts +2 -2
- package/dist/cjs/frameworks/web-components/ts/Header.stories.ts +2 -2
- package/dist/cjs/frameworks/web-components/ts/Page.stories.ts +2 -2
- package/dist/cjs/generate.js +1 -1
- package/dist/cjs/generators/ANGULAR/index.js +24 -1
- package/dist/cjs/generators/REACT_SCRIPTS/index.js +4 -4
- package/dist/cjs/generators/SVELTE/index.js +8 -14
- package/dist/cjs/generators/baseGenerator.js +42 -41
- package/dist/cjs/generators/configure.js +19 -21
- package/dist/cjs/generators/types.js +5 -0
- package/dist/cjs/helpers.js +10 -12
- package/dist/cjs/initiate.js +2 -1
- package/dist/cjs/js-package-manager/JsPackageManager.js +2 -2
- package/dist/cjs/js-package-manager/NPMProxy.js +18 -2
- package/dist/cjs/repro-generators/configs.js +22 -24
- package/dist/cjs/repro-generators/scripts.js +23 -13
- package/dist/cjs/repro.js +3 -3
- package/dist/cjs/versions.js +75 -73
- package/dist/esm/automigrate/fixes/angular12.js +2 -2
- package/dist/esm/automigrate/fixes/builder-vite.js +2 -2
- package/dist/esm/automigrate/fixes/cra5.js +2 -2
- package/dist/esm/automigrate/fixes/eslint-plugin.js +3 -3
- package/dist/esm/automigrate/fixes/index.js +3 -1
- package/dist/esm/automigrate/fixes/mainjsFramework.js +3 -3
- package/dist/esm/automigrate/fixes/npm7.js +59 -0
- package/dist/esm/automigrate/fixes/vue3.js +2 -2
- package/dist/esm/automigrate/fixes/webpack5.js +5 -5
- package/dist/esm/automigrate/index.js +9 -3
- package/dist/esm/babel-config.js +5 -4
- package/dist/esm/dev.js +3 -5
- package/dist/esm/frameworks/angular/Button.stories.ts +6 -4
- package/dist/esm/frameworks/angular/Header.stories.ts +2 -2
- package/dist/esm/frameworks/angular/Page.stories.ts +3 -3
- package/dist/esm/frameworks/html/ts/Button.stories.ts +3 -3
- package/dist/esm/frameworks/html/ts/Button.ts +6 -2
- package/dist/esm/frameworks/html/ts/Header.stories.ts +3 -3
- package/dist/esm/frameworks/html/ts/Page.stories.ts +2 -2
- package/dist/esm/frameworks/html/ts/Page.ts +4 -4
- package/dist/esm/frameworks/react/ts/Button.stories.tsx +2 -2
- package/dist/esm/frameworks/react/ts/Header.stories.tsx +2 -2
- package/dist/esm/frameworks/react/ts/Page.stories.tsx +2 -2
- package/dist/esm/frameworks/web-components/ts/Button.stories.ts +2 -2
- package/dist/esm/frameworks/web-components/ts/Header.stories.ts +2 -2
- package/dist/esm/frameworks/web-components/ts/Page.stories.ts +2 -2
- package/dist/esm/generate.js +1 -1
- package/dist/esm/generators/ANGULAR/index.js +24 -1
- package/dist/esm/generators/REACT_SCRIPTS/index.js +4 -4
- package/dist/esm/generators/SVELTE/index.js +8 -14
- package/dist/esm/generators/baseGenerator.js +42 -41
- package/dist/esm/generators/configure.js +19 -21
- package/dist/esm/generators/types.js +5 -0
- package/dist/esm/helpers.js +10 -12
- package/dist/esm/initiate.js +2 -1
- package/dist/esm/js-package-manager/JsPackageManager.js +2 -2
- package/dist/esm/js-package-manager/NPMProxy.js +18 -2
- package/dist/esm/repro-generators/configs.js +22 -24
- package/dist/esm/repro-generators/scripts.js +23 -13
- package/dist/esm/repro.js +3 -3
- package/dist/esm/versions.js +75 -73
- package/dist/types/automigrate/fixes/npm7.d.ts +9 -0
- package/dist/types/generators/ANGULAR/index.d.ts +1 -1
- package/dist/types/generators/AURELIA/index.d.ts +1 -1
- package/dist/types/generators/EMBER/index.d.ts +1 -1
- package/dist/types/generators/HTML/index.d.ts +1 -1
- package/dist/types/generators/MARIONETTE/index.d.ts +1 -1
- package/dist/types/generators/MARKO/index.d.ts +1 -1
- package/dist/types/generators/MITHRIL/index.d.ts +1 -1
- package/dist/types/generators/PREACT/index.d.ts +1 -1
- package/dist/types/generators/RAX/index.d.ts +1 -1
- package/dist/types/generators/REACT/index.d.ts +1 -1
- package/dist/types/generators/REACT_SCRIPTS/index.d.ts +1 -1
- package/dist/types/generators/RIOT/index.d.ts +1 -1
- package/dist/types/generators/SERVER/index.d.ts +1 -1
- package/dist/types/generators/SFC_VUE/index.d.ts +1 -1
- package/dist/types/generators/SVELTE/index.d.ts +1 -1
- package/dist/types/generators/VUE/index.d.ts +1 -1
- package/dist/types/generators/VUE3/index.d.ts +1 -1
- package/dist/types/generators/WEB-COMPONENTS/index.d.ts +1 -1
- package/dist/types/generators/WEBPACK_REACT/index.d.ts +1 -1
- package/dist/types/generators/baseGenerator.d.ts +3 -20
- package/dist/types/generators/configure.d.ts +2 -1
- package/dist/types/generators/types.d.ts +37 -0
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/initiate.d.ts +1 -15
- package/dist/types/js-package-manager/NPMProxy.d.ts +4 -0
- package/dist/types/repro-generators/configs.d.ts +1 -4
- package/dist/types/repro-generators/scripts.d.ts +1 -1
- package/dist/types/versions.d.ts +3 -1
- package/package.json +11 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
3
|
|
|
4
4
|
import { Button } from './Button';
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
} as ComponentMeta<typeof Button>;
|
|
15
15
|
|
|
16
16
|
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
|
17
|
-
const Template:
|
|
17
|
+
const Template: ComponentStoryFn<typeof Button> = (args) => <Button {...args} />;
|
|
18
18
|
|
|
19
19
|
export const Primary = Template.bind({});
|
|
20
20
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
3
|
|
|
4
4
|
import { Header } from './Header';
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
},
|
|
13
13
|
} as ComponentMeta<typeof Header>;
|
|
14
14
|
|
|
15
|
-
const Template:
|
|
15
|
+
const Template: ComponentStoryFn<typeof Header> = (args) => <Header {...args} />;
|
|
16
16
|
|
|
17
17
|
export const LoggedIn = Template.bind({});
|
|
18
18
|
LoggedIn.args = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
3
|
import { within, userEvent } from '@storybook/testing-library';
|
|
4
4
|
import { Page } from './Page';
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
},
|
|
13
13
|
} as ComponentMeta<typeof Page>;
|
|
14
14
|
|
|
15
|
-
const Template:
|
|
15
|
+
const Template: ComponentStoryFn<typeof Page> = (args) => <Page {...args} />;
|
|
16
16
|
|
|
17
17
|
export const LoggedOut = Template.bind({});
|
|
18
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Meta, StoryFn } from '@storybook/web-components';
|
|
2
2
|
import { Button, ButtonProps } from './Button';
|
|
3
3
|
|
|
4
4
|
// More on default export: https://storybook.js.org/docs/web-components/writing-stories/introduction#default-export
|
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
} as Meta;
|
|
17
17
|
|
|
18
18
|
// More on component templates: https://storybook.js.org/docs/web-components/writing-stories/introduction#using-args
|
|
19
|
-
const Template:
|
|
19
|
+
const Template: StoryFn<ButtonProps> = (args) => Button(args);
|
|
20
20
|
|
|
21
21
|
export const Primary = Template.bind({});
|
|
22
22
|
// More on args: https://storybook.js.org/docs/web-components/writing-stories/args
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Meta, StoryFn } from '@storybook/web-components';
|
|
2
2
|
import { Header, HeaderProps } from './Header';
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
title: 'Example/Header',
|
|
6
6
|
} as Meta;
|
|
7
7
|
|
|
8
|
-
const Template:
|
|
8
|
+
const Template: StoryFn<HeaderProps> = (args) => Header(args);
|
|
9
9
|
|
|
10
10
|
export const LoggedIn = Template.bind({});
|
|
11
11
|
LoggedIn.args = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Meta, StoryFn } from '@storybook/web-components';
|
|
2
2
|
import { Page, PageProps } from './Page';
|
|
3
3
|
import * as HeaderStories from './Header.stories';
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
title: 'Example/Page',
|
|
7
7
|
} as Meta;
|
|
8
8
|
|
|
9
|
-
const Template:
|
|
9
|
+
const Template: StoryFn<PageProps> = (args) => Page(args);
|
|
10
10
|
|
|
11
11
|
export const LoggedIn = Template.bind({});
|
|
12
12
|
LoggedIn.args = {
|
package/dist/esm/generate.js
CHANGED
|
@@ -52,7 +52,7 @@ process.env.STORYBOOK_DISABLE_TELEMETRY && process.env.STORYBOOK_DISABLE_TELEMET
|
|
|
52
52
|
|
|
53
53
|
_commander.default.option('--enable-crash-reports', 'enable sending crash reports to telemetry data');
|
|
54
54
|
|
|
55
|
-
_commander.default.command('init').description('Initialize Storybook into your project.').option('-f --force', 'Force add Storybook').option('-s --skip-install', 'Skip installing deps').option('-N --use-npm', 'Use npm to install deps').option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser').option('-t --type <type>', 'Add Storybook for a specific project type').option('-y --yes', 'Answer yes to all prompts').option('-b --builder <builder>', 'Builder library').option('-l --linkable', 'Prepare installation for link (contributor helper)').action(options => (0, _initiate.initiate)(options, pkg));
|
|
55
|
+
_commander.default.command('init').description('Initialize Storybook into your project.').option('-f --force', 'Force add Storybook').option('-s --skip-install', 'Skip installing deps').option('-N --use-npm', 'Use npm to install deps').option('--use-pnp', 'Enable pnp mode').option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser').option('-t --type <type>', 'Add Storybook for a specific project type').option('-y --yes', 'Answer yes to all prompts').option('-b --builder <builder>', 'Builder library').option('-l --linkable', 'Prepare installation for link (contributor helper)').action(options => (0, _initiate.initiate)(options, pkg));
|
|
56
56
|
|
|
57
57
|
_commander.default.command('add <addon>').description('Add an addon to your Storybook').option('-N --use-npm', 'Use NPM to build the Storybook server').option('-s --skip-postinstall', 'Skip package specific postinstall config modifications').action((addonName, options) => (0, _add.add)(addonName, options));
|
|
58
58
|
|
|
@@ -57,7 +57,30 @@ const generator = async (packageManager, npmOptions, options) => {
|
|
|
57
57
|
addScripts: false
|
|
58
58
|
});
|
|
59
59
|
(0, _helpers.copyTemplate)(__dirname);
|
|
60
|
-
editAngularAppTsConfig();
|
|
60
|
+
editAngularAppTsConfig(); // TODO: we need to add the following:
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
"storybook": {
|
|
64
|
+
"builder": "@storybook/angular:start-storybook",
|
|
65
|
+
"options": {
|
|
66
|
+
"browserTarget": "angular-cli:build",
|
|
67
|
+
"port": 4400
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"build-storybook": {
|
|
71
|
+
"builder": "@storybook/angular:build-storybook",
|
|
72
|
+
"options": {
|
|
73
|
+
"browserTarget": "angular-cli:build"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
*/
|
|
77
|
+
// to the user's angular.json file. see: https://github.com/storybookjs/storybook/blob/next/examples/angular-cli/angular.json#L78
|
|
78
|
+
// then we want to add these scripts to package.json
|
|
79
|
+
// packageManager.addScripts({
|
|
80
|
+
// storybook: 'ng storybook',
|
|
81
|
+
// 'build-storybook': 'ng build-storybook',
|
|
82
|
+
// });
|
|
83
|
+
|
|
61
84
|
(0, _angularHelpers.editStorybookTsConfig)(_path.default.resolve('./.storybook/tsconfig.json')); // edit scripts to generate docs
|
|
62
85
|
|
|
63
86
|
const tsConfigFile = await (0, _angularHelpers.getBaseTsConfigName)();
|
|
@@ -30,10 +30,10 @@ const generator = async (packageManager, npmOptions, options) => {
|
|
|
30
30
|
config.resolve.plugins.forEach((p) => {
|
|
31
31
|
if (Array.isArray(p.appSrcs)) {
|
|
32
32
|
p.appSrcs.push('${monorepoRootPath}');
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
37
|
%%`
|
|
38
38
|
} : {};
|
|
39
39
|
const craVersion = (_semver$coerce = _semver.default.coerce(packageManager.retrievePackageJson().dependencies['react-scripts'])) === null || _semver$coerce === void 0 ? void 0 : _semver$coerce.version;
|
|
@@ -16,25 +16,21 @@ var _baseGenerator = require("../baseGenerator");
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
18
|
const generator = async (packageManager, npmOptions, options) => {
|
|
19
|
-
let
|
|
19
|
+
let svelteOptions;
|
|
20
20
|
let commonJs = false; // svelte.config.js ?
|
|
21
21
|
|
|
22
22
|
if (_fsExtra.default.existsSync('./svelte.config.js')) {
|
|
23
23
|
_nodeLogger.logger.info("Configuring preprocessor from 'svelte.config.js'");
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
preprocess: '%%require("../svelte.config.js").preprocess%%'
|
|
28
|
-
}
|
|
25
|
+
svelteOptions = {
|
|
26
|
+
preprocess: '%%require("../svelte.config.js").preprocess%%'
|
|
29
27
|
};
|
|
30
28
|
} else if (_fsExtra.default.existsSync('./svelte.config.cjs')) {
|
|
31
29
|
_nodeLogger.logger.info("Configuring preprocessor from 'svelte.config.cjs'");
|
|
32
30
|
|
|
33
31
|
commonJs = true;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
preprocess: '%%require("../svelte.config.cjs").preprocess%%'
|
|
37
|
-
}
|
|
32
|
+
svelteOptions = {
|
|
33
|
+
preprocess: '%%require("../svelte.config.cjs").preprocess%%'
|
|
38
34
|
};
|
|
39
35
|
} else {
|
|
40
36
|
// svelte-preprocess dependencies ?
|
|
@@ -43,10 +39,8 @@ const generator = async (packageManager, npmOptions, options) => {
|
|
|
43
39
|
if (packageJson.devDependencies && packageJson.devDependencies['svelte-preprocess']) {
|
|
44
40
|
_nodeLogger.logger.info("Configuring preprocessor with 'svelte-preprocess'");
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
preprocess: '%%require("svelte-preprocess")()%%'
|
|
49
|
-
}
|
|
42
|
+
svelteOptions = {
|
|
43
|
+
preprocess: '%%require("svelte-preprocess")()%%'
|
|
50
44
|
};
|
|
51
45
|
}
|
|
52
46
|
}
|
|
@@ -54,7 +48,7 @@ const generator = async (packageManager, npmOptions, options) => {
|
|
|
54
48
|
await (0, _baseGenerator.baseGenerator)(packageManager, npmOptions, options, 'svelte', {
|
|
55
49
|
extraPackages: ['svelte', 'svelte-loader'],
|
|
56
50
|
extensions: ['js', 'jsx', 'ts', 'tsx', 'svelte'],
|
|
57
|
-
|
|
51
|
+
framework: svelteOptions,
|
|
58
52
|
commonJs
|
|
59
53
|
});
|
|
60
54
|
};
|
|
@@ -9,7 +9,7 @@ require("core-js/modules/es.promise.js");
|
|
|
9
9
|
|
|
10
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
11
|
|
|
12
|
-
var _tsDedent =
|
|
12
|
+
var _tsDedent = require("ts-dedent");
|
|
13
13
|
|
|
14
14
|
var _project_types = require("../project_types");
|
|
15
15
|
|
|
@@ -34,6 +34,7 @@ const defaultOptions = {
|
|
|
34
34
|
addBabel: true,
|
|
35
35
|
addESLint: false,
|
|
36
36
|
extraMain: undefined,
|
|
37
|
+
framework: undefined,
|
|
37
38
|
extensions: undefined,
|
|
38
39
|
commonJs: false
|
|
39
40
|
};
|
|
@@ -54,33 +55,39 @@ const getBuilderDetails = builder => {
|
|
|
54
55
|
return builder;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
const
|
|
58
|
+
const wrapForPnp = packageName => `%%path.dirname(require.resolve(path.join('${packageName}', 'package.json')))%%`;
|
|
59
|
+
|
|
60
|
+
const getFrameworkDetails = (renderer, builder, pnp) => {
|
|
58
61
|
const frameworkPackage = `@storybook/${renderer}-${builder}`;
|
|
62
|
+
const frameworkPackagePath = pnp ? wrapForPnp(frameworkPackage) : frameworkPackage;
|
|
59
63
|
const rendererPackage = `@storybook/${renderer}`;
|
|
64
|
+
const rendererPackagePath = pnp ? wrapForPnp(rendererPackage) : rendererPackage;
|
|
65
|
+
const builderPackage = getBuilderDetails(builder);
|
|
66
|
+
const builderPackagePath = pnp ? wrapForPnp(builderPackage) : builderPackage;
|
|
60
67
|
const isKnownFramework = !!_versions.default[frameworkPackage];
|
|
61
68
|
const isKnownRenderer = !!_versions.default[rendererPackage];
|
|
62
|
-
const builderPackage = getBuilderDetails(builder);
|
|
63
69
|
|
|
64
70
|
if (renderer === 'angular') {
|
|
65
71
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
packages: [rendererPackage],
|
|
73
|
+
framework: rendererPackagePath,
|
|
68
74
|
type: 'framework'
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
if (isKnownFramework) {
|
|
73
79
|
return {
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
packages: [frameworkPackage],
|
|
81
|
+
framework: frameworkPackagePath,
|
|
76
82
|
type: 'framework'
|
|
77
83
|
};
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
if (isKnownRenderer) {
|
|
81
87
|
return {
|
|
82
|
-
|
|
83
|
-
builder:
|
|
88
|
+
packages: [rendererPackage, builderPackage],
|
|
89
|
+
builder: builderPackagePath,
|
|
90
|
+
renderer: rendererPackagePath,
|
|
84
91
|
type: 'renderer'
|
|
85
92
|
};
|
|
86
93
|
}
|
|
@@ -94,7 +101,8 @@ const hasInteractiveStories = framework => ['react', 'angular', 'preact', 'svelt
|
|
|
94
101
|
|
|
95
102
|
async function baseGenerator(packageManager, npmOptions, {
|
|
96
103
|
language,
|
|
97
|
-
builder = _project_types.CoreBuilder.Webpack5
|
|
104
|
+
builder = _project_types.CoreBuilder.Webpack5,
|
|
105
|
+
pnp
|
|
98
106
|
}, renderer, options = defaultOptions) {
|
|
99
107
|
const {
|
|
100
108
|
extraAddons: extraAddonPackages,
|
|
@@ -107,11 +115,10 @@ async function baseGenerator(packageManager, npmOptions, {
|
|
|
107
115
|
extraMain,
|
|
108
116
|
extensions
|
|
109
117
|
} = Object.assign({}, defaultOptions, options); // added to main.js
|
|
110
|
-
// make sure to update `canUsePrebuiltManager` in dev-server.js and build-manager-config/main.js when this list changes
|
|
111
118
|
|
|
112
|
-
const addons = ['@storybook/addon-links', '@storybook/addon-essentials']; // added to package.json
|
|
119
|
+
const addons = ['@storybook/addon-links', '@storybook/addon-essentials', ...stripVersions(extraAddonPackages)]; // added to package.json
|
|
113
120
|
|
|
114
|
-
const addonPackages = [
|
|
121
|
+
const addonPackages = ['@storybook/addon-links', '@storybook/addon-essentials', ...extraAddonPackages];
|
|
115
122
|
|
|
116
123
|
if (hasInteractiveStories(renderer)) {
|
|
117
124
|
addons.push('@storybook/addon-interactions');
|
|
@@ -123,54 +130,48 @@ async function baseGenerator(packageManager, npmOptions, {
|
|
|
123
130
|
const packageJson = packageManager.retrievePackageJson();
|
|
124
131
|
const installedDependencies = new Set(Object.keys(Object.assign({}, packageJson.dependencies, packageJson.devDependencies)));
|
|
125
132
|
const {
|
|
126
|
-
|
|
133
|
+
packages: frameworkPackages,
|
|
127
134
|
type,
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
renderer: rendererInclude,
|
|
137
|
+
// deepscan-disable-line UNUSED_DECL
|
|
138
|
+
framework: frameworkInclude,
|
|
139
|
+
builder: builderInclude
|
|
140
|
+
} = getFrameworkDetails(renderer, builder, pnp); // TODO: We need to start supporting this at some point
|
|
130
141
|
|
|
131
142
|
if (type === 'renderer') {
|
|
132
|
-
|
|
133
|
-
language,
|
|
134
|
-
builder,
|
|
135
|
-
renderer,
|
|
136
|
-
builderPackage,
|
|
137
|
-
frameworkPackage,
|
|
138
|
-
type
|
|
139
|
-
});
|
|
140
|
-
throw new Error((0, _tsDedent.default)`
|
|
143
|
+
throw new Error((0, _tsDedent.dedent)`
|
|
141
144
|
Sorry, for now, you can not do this, please use a framework such as @storybook/react-webpack5
|
|
142
145
|
|
|
143
146
|
https://github.com/storybookjs/storybook/issues/18360
|
|
144
147
|
`);
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
const packages = ['
|
|
150
|
+
const packages = ['storybook', ...frameworkPackages, ...addonPackages, ...extraPackages, ...yarn2ExtraPackages].filter(Boolean).filter(packageToInstall => !installedDependencies.has((0, _jsPackageManager.getPackageDetails)(packageToInstall)[0]));
|
|
148
151
|
const versionedPackages = await packageManager.getVersionedPackages(packages);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
const mainOptions = type !== 'framework' ? Object.assign({
|
|
153
|
-
core: {
|
|
154
|
-
builder: builderPackage
|
|
155
|
-
}
|
|
156
|
-
}, extraMain) : extraMain;
|
|
157
|
-
(0, _configure.configure)(renderer, Object.assign({
|
|
152
|
+
await _fsExtra.default.ensureDir('./.storybook');
|
|
153
|
+
await (0, _configure.configureMain)(Object.assign({
|
|
158
154
|
framework: {
|
|
159
|
-
name:
|
|
160
|
-
options: {}
|
|
155
|
+
name: frameworkInclude,
|
|
156
|
+
options: options.framework || {}
|
|
161
157
|
},
|
|
162
|
-
addons:
|
|
158
|
+
addons: pnp ? addons.map(wrapForPnp) : addons,
|
|
163
159
|
extensions,
|
|
164
160
|
commonJs: options.commonJs
|
|
165
|
-
},
|
|
161
|
+
}, extraMain, type !== 'framework' ? {
|
|
162
|
+
core: {
|
|
163
|
+
builder: builderInclude
|
|
164
|
+
}
|
|
165
|
+
} : {}));
|
|
166
|
+
await (0, _configure.configurePreview)(renderer, options.commonJs);
|
|
166
167
|
|
|
167
168
|
if (addComponents) {
|
|
168
169
|
(0, _helpers.copyComponents)(renderer, language);
|
|
169
170
|
} // FIXME: temporary workaround for https://github.com/storybookjs/storybook/issues/17516
|
|
170
171
|
|
|
171
172
|
|
|
172
|
-
if (
|
|
173
|
-
const previewHead = (0, _tsDedent.
|
|
173
|
+
if (frameworkPackages.includes('@storybook/builder-vite')) {
|
|
174
|
+
const previewHead = (0, _tsDedent.dedent)`
|
|
174
175
|
<script>
|
|
175
176
|
window.global = window;
|
|
176
177
|
</script>
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.configureMain = configureMain;
|
|
7
|
+
exports.configurePreview = configurePreview;
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.promise.js");
|
|
7
10
|
|
|
8
11
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
12
|
|
|
10
|
-
var _tsDedent =
|
|
13
|
+
var _tsDedent = require("ts-dedent");
|
|
11
14
|
|
|
12
15
|
const _excluded = ["addons", "extensions", "commonJs"];
|
|
13
16
|
|
|
@@ -15,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
18
|
|
|
16
19
|
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
20
|
|
|
18
|
-
function configureMain(_ref) {
|
|
21
|
+
async function configureMain(_ref) {
|
|
19
22
|
let {
|
|
20
23
|
addons,
|
|
21
24
|
extensions = ['js', 'jsx', 'ts', 'tsx'],
|
|
@@ -23,24 +26,27 @@ function configureMain(_ref) {
|
|
|
23
26
|
} = _ref,
|
|
24
27
|
custom = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
25
28
|
|
|
26
|
-
const prefix = _fsExtra.default.
|
|
29
|
+
const prefix = (await _fsExtra.default.pathExists('./src')) ? '../src' : '../stories';
|
|
27
30
|
const config = Object.assign({
|
|
28
31
|
stories: [`${prefix}/**/*.stories.mdx`, `${prefix}/**/*.stories.@(${extensions.join('|')})`],
|
|
29
32
|
addons
|
|
30
33
|
}, custom); // replace escaped values and delimiters
|
|
31
34
|
|
|
32
|
-
const stringified = `module.exports = ${JSON.stringify(config, null, 2).replace(/\\"/g, '"').replace(/['"]%%/g, '').replace(/%%['"]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const stringified = `module.exports = ${JSON.stringify(config, null, 2).replace(/\\"/g, '"').replace(/['"]%%/g, '').replace(/%%['"]/g, '').replace(/\\n/g, '\r\n')}`; // main.js isn't actually JSON, but we used JSON.stringify to convert the runtime-object into code.
|
|
36
|
+
// un-stringify the value for referencing packages by string
|
|
37
|
+
// .replaceAll(/"(path\.dirname\(require\.resolve\(path\.join\('.*\))"/g, (_, a) => a)}`;
|
|
35
38
|
|
|
36
|
-
_fsExtra.default.
|
|
39
|
+
await _fsExtra.default.writeFile(`./.storybook/main.${commonJs ? 'cjs' : 'js'}`, (0, _tsDedent.dedent)`
|
|
40
|
+
const path = require('path');
|
|
41
|
+
${stringified}
|
|
42
|
+
`, {
|
|
37
43
|
encoding: 'utf8'
|
|
38
44
|
});
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
const frameworkToPreviewParts = {
|
|
42
48
|
angular: {
|
|
43
|
-
prefix: (0, _tsDedent.
|
|
49
|
+
prefix: (0, _tsDedent.dedent)`
|
|
44
50
|
import { setCompodocJson } from "@storybook/addon-docs/angular";
|
|
45
51
|
import docJson from "../documentation.json";
|
|
46
52
|
setCompodocJson(docJson);
|
|
@@ -50,18 +56,18 @@ const frameworkToPreviewParts = {
|
|
|
50
56
|
}
|
|
51
57
|
};
|
|
52
58
|
|
|
53
|
-
function configurePreview(framework, commonJs) {
|
|
59
|
+
async function configurePreview(framework, commonJs) {
|
|
54
60
|
const {
|
|
55
61
|
prefix = '',
|
|
56
62
|
extraParameters = ''
|
|
57
63
|
} = frameworkToPreviewParts[framework] || {};
|
|
58
64
|
const previewPath = `./.storybook/preview.${commonJs ? 'cjs' : 'js'}`; // If the framework template included a preview then we have nothing to do
|
|
59
65
|
|
|
60
|
-
if (_fsExtra.default.
|
|
66
|
+
if (await _fsExtra.default.pathExists(previewPath)) {
|
|
61
67
|
return;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
const preview = (0, _tsDedent.
|
|
70
|
+
const preview = (0, _tsDedent.dedent)`
|
|
65
71
|
${prefix}
|
|
66
72
|
export const parameters = {
|
|
67
73
|
actions: { argTypesRegex: "^on[A-Z].*" },
|
|
@@ -73,15 +79,7 @@ function configurePreview(framework, commonJs) {
|
|
|
73
79
|
},
|
|
74
80
|
${extraParameters}
|
|
75
81
|
}`.replace(' \n', '').trim();
|
|
76
|
-
|
|
77
|
-
_fsExtra.default.writeFileSync(previewPath, preview, {
|
|
82
|
+
await _fsExtra.default.writeFile(previewPath, preview, {
|
|
78
83
|
encoding: 'utf8'
|
|
79
84
|
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function configure(framework, mainOptions) {
|
|
83
|
-
_fsExtra.default.ensureDirSync('./.storybook');
|
|
84
|
-
|
|
85
|
-
configureMain(mainOptions);
|
|
86
|
-
configurePreview(framework, mainOptions.commonJs);
|
|
87
85
|
}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -189,51 +189,49 @@ function copyTemplate(templateRoot) {
|
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
function copyComponents(framework, language) {
|
|
192
|
+
async function copyComponents(framework, language) {
|
|
193
193
|
const languageFolderMapping = {
|
|
194
194
|
javascript: 'js',
|
|
195
195
|
typescript: 'ts'
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
-
const componentsPath = () => {
|
|
198
|
+
const componentsPath = async () => {
|
|
199
199
|
const frameworkPath = `frameworks/${framework}`;
|
|
200
200
|
|
|
201
201
|
const languageSpecific = _path.default.resolve(__dirname, `${frameworkPath}/${languageFolderMapping[language]}`);
|
|
202
202
|
|
|
203
|
-
if (_fsExtra.default.
|
|
203
|
+
if (await _fsExtra.default.pathExists(languageSpecific)) {
|
|
204
204
|
return languageSpecific;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
const jsFallback = _path.default.resolve(__dirname, `${frameworkPath}/${languageFolderMapping.javascript}`);
|
|
208
208
|
|
|
209
|
-
if (_fsExtra.default.
|
|
209
|
+
if (await _fsExtra.default.pathExists(jsFallback)) {
|
|
210
210
|
return jsFallback;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
const frameworkRootPath = _path.default.resolve(__dirname, frameworkPath);
|
|
214
214
|
|
|
215
|
-
if (_fsExtra.default.
|
|
215
|
+
if (await _fsExtra.default.pathExists(frameworkRootPath)) {
|
|
216
216
|
return frameworkRootPath;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
throw new Error(`Unsupported framework: ${framework}`);
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
-
const targetPath = () => {
|
|
223
|
-
if (_fsExtra.default.
|
|
222
|
+
const targetPath = async () => {
|
|
223
|
+
if (await _fsExtra.default.pathExists('./src')) {
|
|
224
224
|
return './src/stories';
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
return './stories';
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
-
const destinationPath = targetPath();
|
|
231
|
-
|
|
232
|
-
_fsExtra.default.copySync(componentsPath(), destinationPath, {
|
|
230
|
+
const destinationPath = await targetPath();
|
|
231
|
+
await _fsExtra.default.copy(await componentsPath(), destinationPath, {
|
|
233
232
|
overwrite: true
|
|
234
233
|
});
|
|
235
|
-
|
|
236
|
-
_fsExtra.default.copySync(_path.default.resolve(__dirname, 'frameworks/common'), destinationPath, {
|
|
234
|
+
await _fsExtra.default.copy(_path.default.resolve(__dirname, 'frameworks/common'), destinationPath, {
|
|
237
235
|
overwrite: true
|
|
238
236
|
});
|
|
239
237
|
}
|
package/dist/esm/initiate.js
CHANGED
|
@@ -81,7 +81,8 @@ const installStorybook = (projectType, packageManager, options) => {
|
|
|
81
81
|
language,
|
|
82
82
|
builder: options.builder || (0, _detect.detectBuilder)(packageManager),
|
|
83
83
|
linkable: !!options.linkable,
|
|
84
|
-
commonJs: options.commonJs
|
|
84
|
+
commonJs: options.commonJs,
|
|
85
|
+
pnp: options.usePnp
|
|
85
86
|
};
|
|
86
87
|
|
|
87
88
|
const runGenerator = async () => {
|
|
@@ -221,8 +221,8 @@ class JsPackageManager {
|
|
|
221
221
|
var _options$port;
|
|
222
222
|
|
|
223
223
|
const sbPort = (_options$port = options === null || options === void 0 ? void 0 : options.port) !== null && _options$port !== void 0 ? _options$port : 6006;
|
|
224
|
-
const storybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx
|
|
225
|
-
const buildStorybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx
|
|
224
|
+
const storybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx storybook dev -p ${sbPort} -s ${options.staticFolder}` : `npx storybook dev -p ${sbPort}`;
|
|
225
|
+
const buildStorybookCmd = options !== null && options !== void 0 && options.staticFolder ? `npx storybook build -s ${options.staticFolder}` : `npx storybook build`;
|
|
226
226
|
const preCommand = options !== null && options !== void 0 && options.preCommand ? this.getRunCommand(options.preCommand) : undefined;
|
|
227
227
|
this.addScripts({
|
|
228
228
|
storybook: [preCommand, storybookCmd].filter(Boolean).join(' && '),
|
|
@@ -30,10 +30,26 @@ class NPMProxy extends _JsPackageManager.JsPackageManager {
|
|
|
30
30
|
return `npm run ${command}`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
getNpmVersion() {
|
|
34
|
+
return this.executeCommand('npm', ['--version']);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
hasLegacyPeerDeps() {
|
|
38
|
+
const result = this.executeCommand('npm', ['config', 'get', 'legacy-peer-deps', '--location=project']);
|
|
39
|
+
return result.trim() === 'true';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setLegacyPeerDeps() {
|
|
43
|
+
this.executeCommand('npm', ['config', 'set', 'legacy-peer-deps=true', '--location=project']);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
needsLegacyPeerDeps(version) {
|
|
47
|
+
return _semver.default.gte(version, '7.0.0') && !this.hasLegacyPeerDeps();
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
getInstallArgs() {
|
|
34
51
|
if (!this.installArgs) {
|
|
35
|
-
|
|
36
|
-
this.installArgs = _semver.default.gte(version, '7.0.0') ? ['install', '--legacy-peer-deps'] : ['install'];
|
|
52
|
+
this.installArgs = this.needsLegacyPeerDeps(this.getNpmVersion()) ? ['install', '--legacy-peer-deps'] : ['install'];
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
return this.installArgs;
|