1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.repro = void 0;
|
7 |
|
8 | require("core-js/modules/es.object.from-entries.js");
|
9 |
|
10 | require("core-js/modules/es.promise.js");
|
11 |
|
12 | var _prompts = _interopRequireDefault(require("prompts"));
|
13 |
|
14 | var _fs = _interopRequireDefault(require("fs"));
|
15 |
|
16 | var _path = _interopRequireDefault(require("path"));
|
17 |
|
18 | var _chalk = _interopRequireDefault(require("chalk"));
|
19 |
|
20 | var _boxen = _interopRequireDefault(require("boxen"));
|
21 |
|
22 | var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
23 |
|
24 | var _scripts = require("./repro-generators/scripts");
|
25 |
|
26 | var configs = _interopRequireWildcard(require("./repro-generators/configs"));
|
27 |
|
28 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
29 |
|
30 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
31 |
|
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33 |
|
34 | const logger = console;
|
35 | const TEMPLATES = configs;
|
36 |
|
37 |
|
38 | const CURATED_TEMPLATES = Object.fromEntries(Object.entries(configs).filter(entry => entry[0] !== 'react_in_yarn_workspace'));
|
39 | const FRAMEWORKS = Object.values(CURATED_TEMPLATES).reduce((acc, cur) => {
|
40 | acc[cur.framework] = [...(acc[cur.framework] || []), cur];
|
41 | return acc;
|
42 | }, {});
|
43 |
|
44 | const repro = async ({
|
45 | outputDirectory,
|
46 | list,
|
47 | template,
|
48 | framework,
|
49 | generator,
|
50 | e2e,
|
51 | pnp
|
52 | }) => {
|
53 | logger.info((0, _boxen.default)((0, _tsDedent.default)`
|
54 | 🤗 Welcome to ${_chalk.default.yellow('sb repro')}! 🤗
|
55 |
|
56 | Create a ${_chalk.default.green('new project')} to minimally reproduce Storybook issues.
|
57 |
|
58 | 1. select an environment that most closely matches your project setup.
|
59 | 2. select a location for the reproduction, outside of your project.
|
60 |
|
61 | After the reproduction is ready, we'll guide you through the next steps.
|
62 | `.trim(), {
|
63 | borderStyle: 'round',
|
64 | padding: 1,
|
65 | borderColor: '#F1618C'
|
66 | }));
|
67 |
|
68 | if (list) {
|
69 | logger.info('🌈 Available templates');
|
70 | Object.entries(FRAMEWORKS).forEach(([fmwrk, templates]) => {
|
71 | logger.info(fmwrk);
|
72 | templates.forEach(t => logger.info(`- ${t.name}`));
|
73 |
|
74 | if (fmwrk === 'other') {
|
75 | logger.info('- blank');
|
76 | }
|
77 | });
|
78 | return;
|
79 | }
|
80 |
|
81 | let selectedTemplate = template;
|
82 | let selectedFramework = framework;
|
83 |
|
84 | if (!selectedTemplate && !generator) {
|
85 | if (!selectedFramework) {
|
86 | const {
|
87 | framework: frameworkOpt
|
88 | } = await (0, _prompts.default)({
|
89 | type: 'select',
|
90 | message: '🌈 Select the repro framework',
|
91 | name: 'framework',
|
92 | choices: Object.keys(FRAMEWORKS).map(f => ({
|
93 | title: f,
|
94 | value: f
|
95 | }))
|
96 | });
|
97 | selectedFramework = frameworkOpt;
|
98 | }
|
99 |
|
100 | if (!selectedFramework) {
|
101 | throw new Error('🚨 Repro: please select a framework!');
|
102 | }
|
103 |
|
104 | selectedTemplate = (await (0, _prompts.default)({
|
105 | type: 'select',
|
106 | message: '📝 Select the repro base template',
|
107 | name: 'template',
|
108 | choices: FRAMEWORKS[selectedFramework].map(f => ({
|
109 | title: f.name,
|
110 | value: f.name
|
111 | }))
|
112 | })).template;
|
113 | }
|
114 |
|
115 | const selectedConfig = !generator ? TEMPLATES[selectedTemplate] : {
|
116 | name: 'custom',
|
117 | version: 'custom',
|
118 | generator
|
119 | };
|
120 |
|
121 | if (!selectedConfig) {
|
122 | throw new Error('🚨 Repro: please specify a valid template type');
|
123 | }
|
124 |
|
125 | let selectedDirectory = outputDirectory;
|
126 |
|
127 | if (!selectedDirectory) {
|
128 | const {
|
129 | directory
|
130 | } = await (0, _prompts.default)({
|
131 | type: 'text',
|
132 | message: 'Enter the output directory',
|
133 | name: 'directory',
|
134 | initial: selectedConfig.name,
|
135 | validate: directoryName => _fs.default.existsSync(directoryName) ? `${directoryName} already exists. Please choose another name.` : true
|
136 | });
|
137 | selectedDirectory = directory;
|
138 | }
|
139 |
|
140 | try {
|
141 | const cwd = _path.default.isAbsolute(selectedDirectory) ? selectedDirectory : _path.default.join(process.cwd(), selectedDirectory);
|
142 | logger.info(`🏃 Running ${selectedTemplate} into ${cwd}`);
|
143 | await (0, _scripts.createAndInit)(cwd, selectedConfig, {
|
144 | e2e: !!e2e,
|
145 | pnp: !!pnp
|
146 | });
|
147 |
|
148 | if (!e2e) {
|
149 | await initGitRepo(cwd);
|
150 | }
|
151 |
|
152 | logger.info((0, _boxen.default)((0, _tsDedent.default)`
|
153 | 🎉 Your Storybook reproduction project is ready to use! 🎉
|
154 |
|
155 | ${_chalk.default.yellow(`cd ${selectedDirectory}`)}
|
156 | ${_chalk.default.yellow(`yarn storybook`)}
|
157 |
|
158 | Once you've recreated the problem you're experiencing, please:
|
159 |
|
160 | 1. Document any additional steps in ${_chalk.default.cyan('README.md')}
|
161 | 2. Publish the repository to github
|
162 | 3. Link to the repro repository in your issue
|
163 |
|
164 | Having a clean repro helps us solve your issue faster! 🙏
|
165 | `.trim(), {
|
166 | borderStyle: 'round',
|
167 | padding: 1,
|
168 | borderColor: '#F1618C'
|
169 | }));
|
170 | } catch (error) {
|
171 | logger.error('🚨 Failed to create repro');
|
172 | throw new Error(error);
|
173 | }
|
174 | };
|
175 |
|
176 | exports.repro = repro;
|
177 |
|
178 | const initGitRepo = async cwd => {
|
179 | await (0, _scripts.exec)('git init', {
|
180 | cwd
|
181 | });
|
182 | await (0, _scripts.exec)('echo "node_modules" >> .gitignore', {
|
183 | cwd
|
184 | });
|
185 | await (0, _scripts.exec)('git add --all', {
|
186 | cwd
|
187 | });
|
188 | await (0, _scripts.exec)('git commit -am "added storybook"', {
|
189 | cwd
|
190 | });
|
191 | await (0, _scripts.exec)('git tag repro-base', {
|
192 | cwd
|
193 | });
|
194 | }; |
\ | No newline at end of file |