@storybook/cli 7.0.0-alpha.31 → 7.0.0-alpha.33

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 (254) hide show
  1. package/.eslintrc.js +35 -0
  2. package/bin/index.js +1 -1
  3. package/dist/generate.d.ts +1 -0
  4. package/dist/generate.js +265 -0
  5. package/dist/generate.mjs +265 -0
  6. package/package.json +17 -11
  7. package/{dist/cjs/generators/ANGULAR → templates/angular}/template-csf/.storybook/tsconfig.json +0 -0
  8. package/{dist/cjs/generators/ANGULAR → templates/angular}/template-csf/.storybook/typings.d.ts +0 -0
  9. package/{dist/cjs/generators/AURELIA → templates/aurelia}/template-csf/.storybook/tsconfig.json +0 -0
  10. package/{dist/cjs/generators/AURELIA → templates/aurelia}/template-csf/.storybook/typings.d.ts +0 -0
  11. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/addons.js +1 -1
  12. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/index.js +13 -6
  13. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/rn-addons.js +1 -1
  14. package/templates/react-native/template-csf/storybook/stories/Button/Button.stories.js +20 -0
  15. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/Button/index.js +8 -10
  16. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/CenterView/index.js +8 -9
  17. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/CenterView/style.js +3 -3
  18. package/{dist/esm/generators/REACT_NATIVE → templates/react-native}/template-csf/storybook/stories/Welcome/Welcome.stories.js +2 -3
  19. package/templates/react-native/template-csf/storybook/stories/Welcome/index.js +57 -0
  20. package/templates/react-native/template-csf/storybook/stories/index.js +2 -0
  21. package/templates/server/template-csf/.storybook/preview.js +5 -0
  22. package/dist/cjs/NpmOptions.js +0 -1
  23. package/dist/cjs/add.js +0 -149
  24. package/dist/cjs/automigrate/fixes/angular12.js +0 -74
  25. package/dist/cjs/automigrate/fixes/builder-vite.js +0 -118
  26. package/dist/cjs/automigrate/fixes/cra5.js +0 -82
  27. package/dist/cjs/automigrate/fixes/eslint-plugin.js +0 -126
  28. package/dist/cjs/automigrate/fixes/index.js +0 -45
  29. package/dist/cjs/automigrate/fixes/mainjsFramework.js +0 -94
  30. package/dist/cjs/automigrate/fixes/new-frameworks.js +0 -258
  31. package/dist/cjs/automigrate/fixes/npm7.js +0 -57
  32. package/dist/cjs/automigrate/fixes/sb-scripts.js +0 -140
  33. package/dist/cjs/automigrate/fixes/vue3.js +0 -77
  34. package/dist/cjs/automigrate/fixes/webpack5.js +0 -151
  35. package/dist/cjs/automigrate/helpers/getEslintInfo.js +0 -28
  36. package/dist/cjs/automigrate/index.js +0 -98
  37. package/dist/cjs/automigrate/types.js +0 -5
  38. package/dist/cjs/babel-config.js +0 -65
  39. package/dist/cjs/build.js +0 -36
  40. package/dist/cjs/detect-nextjs.js +0 -33
  41. package/dist/cjs/detect-webpack.js +0 -39
  42. package/dist/cjs/detect.js +0 -179
  43. package/dist/cjs/dev.js +0 -66
  44. package/dist/cjs/dirs.js +0 -12
  45. package/dist/cjs/extract.js +0 -93
  46. package/dist/cjs/generate.js +0 -215
  47. package/dist/cjs/generators/ANGULAR/angular-helpers.js +0 -106
  48. package/dist/cjs/generators/ANGULAR/index.js +0 -95
  49. package/dist/cjs/generators/AURELIA/index.js +0 -41
  50. package/dist/cjs/generators/EMBER/index.js +0 -20
  51. package/dist/cjs/generators/HTML/index.js +0 -15
  52. package/dist/cjs/generators/MARIONETTE/index.js +0 -15
  53. package/dist/cjs/generators/MARKO/index.js +0 -15
  54. package/dist/cjs/generators/MITHRIL/index.js +0 -15
  55. package/dist/cjs/generators/PREACT/index.js +0 -15
  56. package/dist/cjs/generators/RAX/index.js +0 -28
  57. package/dist/cjs/generators/REACT/index.js +0 -15
  58. package/dist/cjs/generators/REACT_NATIVE/index.js +0 -55
  59. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/addons.js +0 -7
  60. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/index.js +0 -31
  61. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/rn-addons.js +0 -5
  62. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Button/Button.stories.js +0 -23
  63. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Button/index.js +0 -32
  64. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/CenterView/index.js +0 -31
  65. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/CenterView/style.js +0 -15
  66. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/Welcome.stories.js +0 -15
  67. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/index.js +0 -68
  68. package/dist/cjs/generators/REACT_NATIVE/template-csf/storybook/stories/index.js +0 -5
  69. package/dist/cjs/generators/REACT_SCRIPTS/index.js +0 -68
  70. package/dist/cjs/generators/RIOT/index.js +0 -17
  71. package/dist/cjs/generators/SERVER/index.js +0 -20
  72. package/dist/cjs/generators/SERVER/template-csf/.storybook/preview.js +0 -12
  73. package/dist/cjs/generators/SFC_VUE/index.js +0 -15
  74. package/dist/cjs/generators/SVELTE/index.js +0 -59
  75. package/dist/cjs/generators/VUE/index.js +0 -17
  76. package/dist/cjs/generators/VUE3/index.js +0 -17
  77. package/dist/cjs/generators/WEB-COMPONENTS/index.js +0 -17
  78. package/dist/cjs/generators/WEBPACK_REACT/index.js +0 -15
  79. package/dist/cjs/generators/baseGenerator.js +0 -208
  80. package/dist/cjs/generators/configure.js +0 -83
  81. package/dist/cjs/generators/types.js +0 -5
  82. package/dist/cjs/helpers.js +0 -258
  83. package/dist/cjs/initiate.js +0 -295
  84. package/dist/cjs/js-package-manager/JsPackageManager.js +0 -358
  85. package/dist/cjs/js-package-manager/JsPackageManagerFactory.js +0 -71
  86. package/dist/cjs/js-package-manager/NPMProxy.js +0 -112
  87. package/dist/cjs/js-package-manager/PackageJson.js +0 -5
  88. package/dist/cjs/js-package-manager/Yarn1Proxy.js +0 -72
  89. package/dist/cjs/js-package-manager/Yarn2Proxy.js +0 -68
  90. package/dist/cjs/js-package-manager/index.js +0 -44
  91. package/dist/cjs/link.js +0 -99
  92. package/dist/cjs/migrate.js +0 -33
  93. package/dist/cjs/project_types.js +0 -263
  94. package/dist/cjs/repro-generators/configs.js +0 -201
  95. package/dist/cjs/repro-generators/scripts.js +0 -338
  96. package/dist/cjs/repro-next.js +0 -182
  97. package/dist/cjs/repro-templates.js +0 -103
  98. package/dist/cjs/repro.js +0 -194
  99. package/dist/cjs/typings.d.ts +0 -3
  100. package/dist/cjs/upgrade.js +0 -170
  101. package/dist/cjs/utils.js +0 -22
  102. package/dist/cjs/versions.js +0 -89
  103. package/dist/cjs/warn.js +0 -32
  104. package/dist/cjs/window.d.js +0 -5
  105. package/dist/esm/NpmOptions.js +0 -0
  106. package/dist/esm/add.js +0 -121
  107. package/dist/esm/automigrate/fixes/angular12.js +0 -58
  108. package/dist/esm/automigrate/fixes/builder-vite.js +0 -103
  109. package/dist/esm/automigrate/fixes/cra5.js +0 -66
  110. package/dist/esm/automigrate/fixes/eslint-plugin.js +0 -111
  111. package/dist/esm/automigrate/fixes/index.js +0 -12
  112. package/dist/esm/automigrate/fixes/mainjsFramework.js +0 -76
  113. package/dist/esm/automigrate/fixes/new-frameworks.js +0 -234
  114. package/dist/esm/automigrate/fixes/npm7.js +0 -45
  115. package/dist/esm/automigrate/fixes/sb-scripts.js +0 -119
  116. package/dist/esm/automigrate/fixes/vue3.js +0 -60
  117. package/dist/esm/automigrate/fixes/webpack5.js +0 -131
  118. package/dist/esm/automigrate/helpers/getEslintInfo.js +0 -14
  119. package/dist/esm/automigrate/index.js +0 -80
  120. package/dist/esm/automigrate/types.js +0 -1
  121. package/dist/esm/babel-config.js +0 -42
  122. package/dist/esm/build.js +0 -22
  123. package/dist/esm/detect-nextjs.js +0 -24
  124. package/dist/esm/detect-webpack.js +0 -30
  125. package/dist/esm/detect.js +0 -152
  126. package/dist/esm/dev.js +0 -47
  127. package/dist/esm/dirs.js +0 -4
  128. package/dist/esm/extract.js +0 -77
  129. package/dist/esm/generate.js +0 -162
  130. package/dist/esm/generators/ANGULAR/angular-helpers.js +0 -82
  131. package/dist/esm/generators/ANGULAR/index.js +0 -76
  132. package/dist/esm/generators/ANGULAR/template-csf/.storybook/tsconfig.json +0 -10
  133. package/dist/esm/generators/ANGULAR/template-csf/.storybook/typings.d.ts +0 -4
  134. package/dist/esm/generators/AURELIA/index.js +0 -32
  135. package/dist/esm/generators/AURELIA/template-csf/.storybook/tsconfig.json +0 -9
  136. package/dist/esm/generators/AURELIA/template-csf/.storybook/typings.d.ts +0 -4
  137. package/dist/esm/generators/EMBER/index.js +0 -12
  138. package/dist/esm/generators/HTML/index.js +0 -7
  139. package/dist/esm/generators/MARIONETTE/index.js +0 -7
  140. package/dist/esm/generators/MARKO/index.js +0 -7
  141. package/dist/esm/generators/MITHRIL/index.js +0 -7
  142. package/dist/esm/generators/PREACT/index.js +0 -7
  143. package/dist/esm/generators/RAX/index.js +0 -20
  144. package/dist/esm/generators/REACT/index.js +0 -7
  145. package/dist/esm/generators/REACT_NATIVE/index.js +0 -42
  146. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/Button/Button.stories.js +0 -12
  147. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/Welcome/index.js +0 -54
  148. package/dist/esm/generators/REACT_NATIVE/template-csf/storybook/stories/index.js +0 -2
  149. package/dist/esm/generators/REACT_SCRIPTS/index.js +0 -49
  150. package/dist/esm/generators/RIOT/index.js +0 -9
  151. package/dist/esm/generators/SERVER/index.js +0 -11
  152. package/dist/esm/generators/SERVER/template-csf/.storybook/preview.js +0 -5
  153. package/dist/esm/generators/SFC_VUE/index.js +0 -7
  154. package/dist/esm/generators/SVELTE/index.js +0 -44
  155. package/dist/esm/generators/VUE/index.js +0 -9
  156. package/dist/esm/generators/VUE3/index.js +0 -9
  157. package/dist/esm/generators/WEB-COMPONENTS/index.js +0 -9
  158. package/dist/esm/generators/WEBPACK_REACT/index.js +0 -7
  159. package/dist/esm/generators/baseGenerator.js +0 -191
  160. package/dist/esm/generators/configure.js +0 -69
  161. package/dist/esm/generators/types.js +0 -1
  162. package/dist/esm/helpers.js +0 -207
  163. package/dist/esm/initiate.js +0 -254
  164. package/dist/esm/js-package-manager/JsPackageManager.js +0 -334
  165. package/dist/esm/js-package-manager/JsPackageManagerFactory.js +0 -57
  166. package/dist/esm/js-package-manager/NPMProxy.js +0 -99
  167. package/dist/esm/js-package-manager/PackageJson.js +0 -1
  168. package/dist/esm/js-package-manager/Yarn1Proxy.js +0 -62
  169. package/dist/esm/js-package-manager/Yarn2Proxy.js +0 -58
  170. package/dist/esm/js-package-manager/index.js +0 -3
  171. package/dist/esm/link.js +0 -69
  172. package/dist/esm/migrate.js +0 -25
  173. package/dist/esm/project_types.js +0 -248
  174. package/dist/esm/repro-generators/configs.js +0 -174
  175. package/dist/esm/repro-generators/scripts.js +0 -307
  176. package/dist/esm/repro-next.js +0 -163
  177. package/dist/esm/repro-templates.js +0 -94
  178. package/dist/esm/repro.js +0 -170
  179. package/dist/esm/typings.d.ts +0 -3
  180. package/dist/esm/upgrade.js +0 -132
  181. package/dist/esm/utils.js +0 -13
  182. package/dist/esm/versions.js +0 -82
  183. package/dist/esm/warn.js +0 -16
  184. package/dist/esm/window.d.js +0 -1
  185. package/dist/types/NpmOptions.d.ts +0 -4
  186. package/dist/types/add.d.ts +0 -10
  187. package/dist/types/automigrate/fixes/angular12.d.ts +0 -15
  188. package/dist/types/automigrate/fixes/builder-vite.d.ts +0 -19
  189. package/dist/types/automigrate/fixes/cra5.d.ts +0 -15
  190. package/dist/types/automigrate/fixes/eslint-plugin.d.ts +0 -15
  191. package/dist/types/automigrate/fixes/index.d.ts +0 -3
  192. package/dist/types/automigrate/fixes/mainjsFramework.d.ts +0 -8
  193. package/dist/types/automigrate/fixes/new-frameworks.d.ts +0 -31
  194. package/dist/types/automigrate/fixes/npm7.d.ts +0 -9
  195. package/dist/types/automigrate/fixes/sb-scripts.d.ts +0 -23
  196. package/dist/types/automigrate/fixes/vue3.d.ts +0 -15
  197. package/dist/types/automigrate/fixes/webpack5.d.ts +0 -26
  198. package/dist/types/automigrate/helpers/getEslintInfo.d.ts +0 -2
  199. package/dist/types/automigrate/index.d.ts +0 -7
  200. package/dist/types/automigrate/types.d.ts +0 -15
  201. package/dist/types/babel-config.d.ts +0 -4
  202. package/dist/types/build.d.ts +0 -1
  203. package/dist/types/detect-nextjs.d.ts +0 -2
  204. package/dist/types/detect-webpack.d.ts +0 -2
  205. package/dist/types/detect.d.ts +0 -16
  206. package/dist/types/dev.d.ts +0 -1
  207. package/dist/types/dirs.d.ts +0 -1
  208. package/dist/types/extract.d.ts +0 -1
  209. package/dist/types/generate.d.ts +0 -1
  210. package/dist/types/generators/ANGULAR/angular-helpers.d.ts +0 -6
  211. package/dist/types/generators/ANGULAR/index.d.ts +0 -3
  212. package/dist/types/generators/AURELIA/index.d.ts +0 -3
  213. package/dist/types/generators/EMBER/index.d.ts +0 -3
  214. package/dist/types/generators/HTML/index.d.ts +0 -3
  215. package/dist/types/generators/MARIONETTE/index.d.ts +0 -3
  216. package/dist/types/generators/MARKO/index.d.ts +0 -3
  217. package/dist/types/generators/MITHRIL/index.d.ts +0 -3
  218. package/dist/types/generators/PREACT/index.d.ts +0 -3
  219. package/dist/types/generators/RAX/index.d.ts +0 -3
  220. package/dist/types/generators/REACT/index.d.ts +0 -3
  221. package/dist/types/generators/REACT_NATIVE/index.d.ts +0 -4
  222. package/dist/types/generators/REACT_SCRIPTS/index.d.ts +0 -3
  223. package/dist/types/generators/RIOT/index.d.ts +0 -3
  224. package/dist/types/generators/SERVER/index.d.ts +0 -3
  225. package/dist/types/generators/SFC_VUE/index.d.ts +0 -3
  226. package/dist/types/generators/SVELTE/index.d.ts +0 -3
  227. package/dist/types/generators/VUE/index.d.ts +0 -3
  228. package/dist/types/generators/VUE3/index.d.ts +0 -3
  229. package/dist/types/generators/WEB-COMPONENTS/index.d.ts +0 -3
  230. package/dist/types/generators/WEBPACK_REACT/index.d.ts +0 -3
  231. package/dist/types/generators/baseGenerator.d.ts +0 -5
  232. package/dist/types/generators/configure.d.ts +0 -19
  233. package/dist/types/generators/types.d.ts +0 -38
  234. package/dist/types/helpers.d.ts +0 -26
  235. package/dist/types/initiate.d.ts +0 -3
  236. package/dist/types/js-package-manager/JsPackageManager.d.ts +0 -118
  237. package/dist/types/js-package-manager/JsPackageManagerFactory.d.ts +0 -4
  238. package/dist/types/js-package-manager/NPMProxy.d.ts +0 -23
  239. package/dist/types/js-package-manager/PackageJson.d.ts +0 -4
  240. package/dist/types/js-package-manager/Yarn1Proxy.d.ts +0 -17
  241. package/dist/types/js-package-manager/Yarn2Proxy.d.ts +0 -17
  242. package/dist/types/js-package-manager/index.d.ts +0 -3
  243. package/dist/types/link.d.ts +0 -7
  244. package/dist/types/migrate.d.ts +0 -1
  245. package/dist/types/project_types.d.ts +0 -64
  246. package/dist/types/repro-generators/configs.d.ts +0 -44
  247. package/dist/types/repro-generators/scripts.d.ts +0 -44
  248. package/dist/types/repro-next.d.ts +0 -8
  249. package/dist/types/repro-templates.d.ts +0 -73
  250. package/dist/types/repro.d.ts +0 -14
  251. package/dist/types/upgrade.d.ts +0 -19
  252. package/dist/types/utils.d.ts +0 -2
  253. package/dist/types/versions.d.ts +0 -82
  254. package/dist/types/warn.d.ts +0 -5
@@ -1,152 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- import findUp from 'find-up';
4
- import { ProjectType, supportedTemplates, SUPPORTED_RENDERERS, SupportedLanguage, unsupportedTemplate, CoreBuilder } from './project_types';
5
- import { getBowerJson, paddedLog } from './helpers';
6
- import { detectNextJS } from './detect-nextjs';
7
- const viteConfigFiles = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];
8
-
9
- const hasDependency = (packageJson, name, matcher) => {
10
- const version = packageJson.dependencies?.[name] || packageJson.devDependencies?.[name];
11
-
12
- if (version && typeof matcher === 'function') {
13
- return matcher(version);
14
- }
15
-
16
- return !!version;
17
- };
18
-
19
- const hasPeerDependency = (packageJson, name, matcher) => {
20
- const version = packageJson.peerDependencies?.[name];
21
-
22
- if (version && typeof matcher === 'function') {
23
- return matcher(version);
24
- }
25
-
26
- return !!version;
27
- };
28
-
29
- const getFrameworkPreset = (packageJson, framework) => {
30
- const matcher = {
31
- dependencies: [false],
32
- peerDependencies: [false],
33
- files: [false]
34
- };
35
- const {
36
- preset,
37
- files,
38
- dependencies,
39
- peerDependencies,
40
- matcherFunction
41
- } = framework;
42
- let dependencySearches = [];
43
-
44
- if (Array.isArray(dependencies)) {
45
- dependencySearches = dependencies.map(name => [name, undefined]);
46
- } else if (typeof dependencies === 'object') {
47
- dependencySearches = Object.entries(dependencies);
48
- } // Must check the length so the `[false]` isn't overwritten if `{ dependencies: [] }`
49
-
50
-
51
- if (dependencySearches.length > 0) {
52
- matcher.dependencies = dependencySearches.map(([name, matchFn]) => hasDependency(packageJson, name, matchFn));
53
- }
54
-
55
- let peerDependencySearches = [];
56
-
57
- if (Array.isArray(peerDependencies)) {
58
- peerDependencySearches = peerDependencies.map(name => [name, undefined]);
59
- } else if (typeof peerDependencies === 'object') {
60
- peerDependencySearches = Object.entries(peerDependencies);
61
- } // Must check the length so the `[false]` isn't overwritten if `{ peerDependencies: [] }`
62
-
63
-
64
- if (peerDependencySearches.length > 0) {
65
- matcher.peerDependencies = peerDependencySearches.map(([name, matchFn]) => hasPeerDependency(packageJson, name, matchFn));
66
- }
67
-
68
- if (Array.isArray(files) && files.length > 0) {
69
- matcher.files = files.map(name => fs.existsSync(path.join(process.cwd(), name)));
70
- }
71
-
72
- return matcherFunction(matcher) ? preset : null;
73
- };
74
-
75
- export function detectFrameworkPreset(packageJson = {}) {
76
- const result = [...supportedTemplates, unsupportedTemplate].find(framework => {
77
- return getFrameworkPreset(packageJson, framework) !== null;
78
- });
79
- return result ? result.preset : ProjectType.UNDETECTED;
80
- }
81
- /**
82
- * Attempts to detect which builder to use, by searching for a vite config file. If one is found, the vite builder
83
- * will be used, otherwise, webpack5 is the default.
84
- *
85
- * @returns CoreBuilder
86
- */
87
-
88
- export function detectBuilder(packageManager) {
89
- const viteConfig = findUp.sync(viteConfigFiles);
90
-
91
- if (viteConfig) {
92
- paddedLog('Detected vite project, setting builder to @storybook/builder-vite');
93
- return CoreBuilder.Vite;
94
- }
95
-
96
- const nextJSVersion = detectNextJS(packageManager);
97
-
98
- if (nextJSVersion) {
99
- if (nextJSVersion >= 11) {
100
- return CoreBuilder.Webpack5;
101
- }
102
- } // Fallback to webpack5
103
-
104
-
105
- return CoreBuilder.Webpack5;
106
- }
107
- export function isStorybookInstalled(dependencies, force) {
108
- if (!dependencies) {
109
- return false;
110
- }
111
-
112
- if (!force && dependencies.devDependencies) {
113
- if (SUPPORTED_RENDERERS.reduce((storybookPresent, framework) => storybookPresent || !!dependencies.devDependencies[`@storybook/${framework}`], false)) {
114
- return ProjectType.ALREADY_HAS_STORYBOOK;
115
- }
116
- }
117
-
118
- return false;
119
- }
120
- export function detectLanguage(packageJson) {
121
- let language = SupportedLanguage.JAVASCRIPT;
122
- const bowerJson = getBowerJson();
123
-
124
- if (!packageJson && !bowerJson) {
125
- return language;
126
- }
127
-
128
- if (hasDependency(packageJson || bowerJson, 'typescript')) {
129
- language = SupportedLanguage.TYPESCRIPT;
130
- }
131
-
132
- return language;
133
- }
134
- export function detect(packageJson, options = {}) {
135
- const bowerJson = getBowerJson();
136
-
137
- if (!packageJson && !bowerJson) {
138
- return ProjectType.UNDETECTED;
139
- }
140
-
141
- const storyBookInstalled = isStorybookInstalled(packageJson, options.force);
142
-
143
- if (storyBookInstalled) {
144
- return storyBookInstalled;
145
- }
146
-
147
- if (options.html) {
148
- return ProjectType.HTML;
149
- }
150
-
151
- return detectFrameworkPreset(packageJson || bowerJson);
152
- }
package/dist/esm/dev.js DELETED
@@ -1,47 +0,0 @@
1
- import { dedent } from 'ts-dedent';
2
- import { sync as readUpSync } from 'read-pkg-up';
3
- import { logger, instance as npmLog } from '@storybook/node-logger';
4
- import { buildDevStandalone } from '@storybook/core-server';
5
- import { cache } from '@storybook/core-common';
6
- export const dev = async cliOptions => {
7
- process.env.NODE_ENV = process.env.NODE_ENV || 'development';
8
-
9
- try {
10
- await buildDevStandalone(Object.assign({}, cliOptions, {
11
- configDir: cliOptions.configDir || './.storybook',
12
- configType: 'DEVELOPMENT',
13
- ignorePreview: !!cliOptions.previewUrl && !cliOptions.forceBuildPreview,
14
- docsMode: !!cliOptions.docs,
15
- cache,
16
- packageJson: readUpSync({
17
- cwd: __dirname
18
- }).packageJson
19
- }));
20
- } catch (error) {
21
- // this is a weird bugfix, somehow 'node-pre-gyp' is polluting the npmLog header
22
- npmLog.heading = '';
23
-
24
- if (error instanceof Error) {
25
- if (error.error) {
26
- logger.error(error.error);
27
- } else if (error.stats && error.stats.compilation.errors) {
28
- error.stats.compilation.errors.forEach(e => logger.plain(e));
29
- } else {
30
- logger.error(error);
31
- }
32
- } else if (error.compilation?.errors) {
33
- error.compilation.errors.forEach(e => logger.plain(e));
34
- }
35
-
36
- logger.line();
37
- logger.warn(error.close ? dedent`
38
- FATAL broken build!, will close the process,
39
- Fix the error below and restart storybook.
40
- ` : dedent`
41
- Broken build, fix the error above.
42
- You may need to refresh the browser.
43
- `);
44
- logger.line();
45
- process.exit(1);
46
- }
47
- };
package/dist/esm/dirs.js DELETED
@@ -1,4 +0,0 @@
1
- import { dirname } from 'path';
2
- export function getBaseDir() {
3
- return dirname(require.resolve('@storybook/cli/package.json'));
4
- }
@@ -1,77 +0,0 @@
1
- import "core-js/modules/web.immediate.js";
2
- import path from 'path';
3
- import { writeFile, stat } from 'fs-extra';
4
- import puppeteerCore from 'puppeteer-core';
5
- import express from 'express';
6
- import getPort from 'get-port';
7
- import { logger } from '@storybook/node-logger';
8
-
9
- const read = async url => {
10
- const browser = await usePuppeteerBrowser();
11
- const page = await browser.newPage();
12
- await page.goto(url); // we don't know whether we are running against a new or old storybook
13
- // FIXME: add tests for both
14
-
15
- await page.waitForFunction(`
16
- (window.__STORYBOOK_PREVIEW__ && window.__STORYBOOK_PREVIEW__.extract && window.__STORYBOOK_PREVIEW__.extract()) ||
17
- (window.__STORYBOOK_STORY_STORE__ && window.__STORYBOOK_STORY_STORE__.extract && window.__STORYBOOK_STORY_STORE__.extract())
18
- `);
19
- const data = JSON.parse(await page.evaluate(async () => {
20
- return JSON.stringify(window.__STORYBOOK_STORY_STORE__.getStoriesJsonData(), null, 2);
21
- }));
22
- setImmediate(() => {
23
- browser.close();
24
- });
25
- return data;
26
- };
27
-
28
- const useLocation = async input => {
29
- // check for input's existence
30
- await stat(path.resolve(input));
31
-
32
- if (input.match(/^http/)) {
33
- return [input, async () => {}];
34
- }
35
-
36
- const app = express();
37
- app.use(express.static(input));
38
- const port = await getPort();
39
- return new Promise(resolve => {
40
- const server = app.listen(port, () => {
41
- const result = `http://localhost:${port}/iframe.html`;
42
- logger.info(`connecting to: ${result}`);
43
- resolve([result, server.close.bind(server)]);
44
- });
45
- });
46
- };
47
-
48
- const usePuppeteerBrowser = async () => {
49
- const args = ['--no-sandbox ', '--disable-setuid-sandbox'];
50
-
51
- try {
52
- return await puppeteerCore.launch({
53
- args,
54
- executablePath: process.env.SB_CHROMIUM_PATH
55
- });
56
- } catch (e) {
57
- // it's not installed
58
- logger.info('installing puppeteer...');
59
- return new Promise((resolve, reject) => {
60
- // eslint-disable-next-line global-require
61
- require('child_process').exec(`node ${require.resolve(path.join('puppeteer-core', 'install.js'))}`, error => error ? reject(error) : resolve(puppeteerCore.launch({
62
- args
63
- })));
64
- });
65
- }
66
- };
67
-
68
- export async function extract(input, targetPath) {
69
- if (input && targetPath) {
70
- const [location, exit] = await useLocation(input);
71
- const data = await read(location);
72
- await writeFile(targetPath, JSON.stringify(data, null, 2));
73
- await exit();
74
- } else {
75
- throw new Error('Extract: please specify a path where your built-storybook is (can be a public url) and a target directory');
76
- }
77
- }
@@ -1,162 +0,0 @@
1
- import program from 'commander';
2
- import path from 'path';
3
- import chalk from 'chalk';
4
- import envinfo from 'envinfo';
5
- import leven from 'leven';
6
- import { sync as readUpSync } from 'read-pkg-up';
7
- import { logger } from '@storybook/node-logger';
8
- import { initiate } from './initiate';
9
- import { add } from './add';
10
- import { migrate } from './migrate';
11
- import { extract } from './extract';
12
- import { upgrade } from './upgrade';
13
- import { repro } from './repro';
14
- import { reproNext } from './repro-next';
15
- import { link } from './link';
16
- import { automigrate } from './automigrate';
17
- import { generateStorybookBabelConfigInCWD } from './babel-config';
18
- import { dev } from './dev';
19
- import { build } from './build';
20
- import { parseList, getEnvConfig } from './utils';
21
- const pkg = readUpSync({
22
- cwd: __dirname
23
- }).packageJson;
24
- const consoleLogger = console;
25
- program.option('--disable-telemetry', 'disable sending telemetry data', // default value is false, but if the user sets STORYBOOK_DISABLE_TELEMETRY, it can be true
26
- process.env.STORYBOOK_DISABLE_TELEMETRY && process.env.STORYBOOK_DISABLE_TELEMETRY !== 'false');
27
- program.option('--enable-crash-reports', 'enable sending crash reports to telemetry data');
28
- program.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 => initiate(options, pkg).catch(err => {
29
- logger.error(err);
30
- process.exit(1);
31
- }));
32
- program.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) => add(addonName, options));
33
- program.command('babelrc').description('generate the default storybook babel config into your current working directory').action(() => generateStorybookBabelConfigInCWD());
34
- program.command('upgrade').description('Upgrade your Storybook packages to the latest').option('-N --use-npm', 'Use NPM to build the Storybook server').option('-y --yes', 'Skip prompting the user').option('-n --dry-run', 'Only check for upgrades, do not install').option('-p --prerelease', 'Upgrade to the pre-release packages').option('-s --skip-check', 'Skip postinstall version and automigration checks').action(options => upgrade(options));
35
- program.command('info').description('Prints debugging information about the local environment').action(() => {
36
- consoleLogger.log(chalk.bold('\nEnvironment Info:'));
37
- envinfo.run({
38
- System: ['OS', 'CPU'],
39
- Binaries: ['Node', 'Yarn', 'npm'],
40
- Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
41
- npmPackages: '@storybook/*',
42
- npmGlobalPackages: '@storybook/*'
43
- }).then(consoleLogger.log);
44
- });
45
- program.command('migrate [migration]').description('Run a Storybook codemod migration on your source files').option('-l --list', 'List available migrations').option('-g --glob <glob>', 'Glob for files upon which to apply the migration', '**/*.js').option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser').option('-n --dry-run', 'Dry run: verify the migration exists and show the files to which it will be applied').option('-r --rename <from-to>', 'Rename suffix of matching files after codemod has been applied, e.g. ".js:.ts"').action((migration, {
46
- configDir,
47
- glob,
48
- dryRun,
49
- list,
50
- rename,
51
- parser
52
- }) => {
53
- migrate(migration, {
54
- configDir,
55
- glob,
56
- dryRun,
57
- list,
58
- rename,
59
- parser,
60
- logger: consoleLogger
61
- }).catch(err => {
62
- logger.error(err);
63
- process.exit(1);
64
- });
65
- });
66
- program.command('extract [location] [output]').description('extract stories.json from a built version').action((location = 'storybook-static', output = path.join(location, 'stories.json')) => extract(location, output).catch(e => {
67
- logger.error(e);
68
- process.exit(1);
69
- }));
70
- program.command('repro [outputDirectory]').description('Create a reproduction from a set of possible templates').option('-f --renderer <renderer>', 'Filter on given renderer').option('-t --template <template>', 'Use the given template').option('-l --list', 'List available templates').option('-g --generator <generator>', 'Use custom generator command').option('--registry <registry>', 'which registry to use for storybook packages').option('--pnp', "Use Yarn Plug'n'Play mode instead of node_modules one").option('--local', "use storybook's local packages instead of yarn's registry").option('--e2e', 'Used in e2e context').action((outputDirectory, {
71
- renderer,
72
- template,
73
- list,
74
- e2e,
75
- generator,
76
- pnp,
77
- local
78
- }) => repro({
79
- outputDirectory,
80
- renderer,
81
- template,
82
- list,
83
- e2e,
84
- local,
85
- generator,
86
- pnp
87
- }).catch(e => {
88
- logger.error(e);
89
- process.exit(1);
90
- }));
91
- program.command('repro-next [filterValue]').description('Create a reproduction from a set of possible templates').option('-o --output <outDir>', 'Define an output directory').option('-b --branch <branch>', 'Define the branch to degit from', 'next').option('--no-init', 'Whether to download a template without an initialized Storybook', false).action((filterValue, options) => reproNext(Object.assign({
92
- filterValue
93
- }, options)).catch(e => {
94
- logger.error(e);
95
- process.exit(1);
96
- }));
97
- program.command('link <repo-url-or-directory>').description('Pull down a repro from a URL (or a local directory), link it, and run storybook').option('--local', 'Link a local directory already in your file system').option('--no-start', 'Start the storybook', true).action((target, {
98
- local,
99
- start
100
- }) => link({
101
- target,
102
- local,
103
- start
104
- }).catch(e => {
105
- logger.error(e);
106
- process.exit(1);
107
- }));
108
- program.command('automigrate [fixId]').description('Check storybook for known problems or migrations and apply fixes').option('-y --yes', 'Skip prompting the user').option('-n --dry-run', 'Only check for fixes, do not actually run them').action((fixId, options) => automigrate(Object.assign({
109
- fixId
110
- }, options)).catch(e => {
111
- logger.error(e);
112
- process.exit(1);
113
- }));
114
- program.command('dev').option('-p, --port <number>', 'Port to run Storybook', str => parseInt(str, 10)).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('--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').action(options => {
115
- logger.setLevel(program.loglevel);
116
- consoleLogger.log(chalk.bold(`${pkg.name} v${pkg.version}`) + chalk.reset('\n')); // The key is the field created in `program` variable for
117
- // each command line argument. Value is the env variable.
118
-
119
- getEnvConfig(program, {
120
- port: 'SBCONFIG_PORT',
121
- host: 'SBCONFIG_HOSTNAME',
122
- staticDir: 'SBCONFIG_STATIC_DIR',
123
- configDir: 'SBCONFIG_CONFIG_DIR',
124
- ci: 'CI'
125
- });
126
-
127
- if (typeof program.port === 'string' && program.port.length > 0) {
128
- program.port = parseInt(program.port, 10);
129
- }
130
-
131
- dev(Object.assign({}, options, {
132
- packageJson: pkg
133
- }));
134
- });
135
- program.command('build').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList).option('-o, --output-dir <dir-name>', 'Directory where to store built files').option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from').option('--quiet', 'Suppress verbose build output').option('--loglevel <level>', 'Control level of logging during build').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('--no-manager-cache', 'Do not cache the manager UI').action(options => {
136
- process.env.NODE_ENV = process.env.NODE_ENV || 'production';
137
- logger.setLevel(program.loglevel);
138
- consoleLogger.log(chalk.bold(`${pkg.name} v${pkg.version}\n`)); // The key is the field created in `program` variable for
139
- // each command line argument. Value is the env variable.
140
-
141
- getEnvConfig(program, {
142
- staticDir: 'SBCONFIG_STATIC_DIR',
143
- outputDir: 'SBCONFIG_OUTPUT_DIR',
144
- configDir: 'SBCONFIG_CONFIG_DIR'
145
- });
146
- build(Object.assign({}, options, {
147
- packageJson: pkg
148
- }));
149
- });
150
- program.on('command:*', ([invalidCmd]) => {
151
- consoleLogger.error(' Invalid command: %s.\n See --help for a list of available commands.', invalidCmd); // eslint-disable-next-line
152
-
153
- const availableCommands = program.commands.map(cmd => cmd._name);
154
- const suggestion = availableCommands.find(cmd => leven(cmd, invalidCmd) < 3);
155
-
156
- if (suggestion) {
157
- consoleLogger.info(`\n Did you mean ${suggestion}?`);
158
- }
159
-
160
- process.exit(1);
161
- });
162
- program.usage('<command> [options]').version(pkg.version).parse(process.argv);
@@ -1,82 +0,0 @@
1
- import * as path from 'path';
2
- import * as fs from 'fs';
3
- import { pathExists } from 'fs-extra';
4
- import { readFileAsJson, writeFileAsJson } from '../../helpers';
5
- export function getAngularAppTsConfigPath() {
6
- const angularJson = readFileAsJson('angular.json', true);
7
- const defaultProject = getDefaultProjectName(angularJson);
8
- const tsConfigPath = angularJson.projects[defaultProject].architect.build.options.tsConfig;
9
-
10
- if (!tsConfigPath || !fs.existsSync(path.resolve(tsConfigPath))) {
11
- return false;
12
- }
13
-
14
- return tsConfigPath;
15
- }
16
- export function getAngularAppTsConfigJson() {
17
- const tsConfigPath = getAngularAppTsConfigPath();
18
-
19
- if (!tsConfigPath) {
20
- return false;
21
- }
22
-
23
- return readFileAsJson(tsConfigPath, true);
24
- }
25
-
26
- function setStorybookTsconfigExtendsPath(tsconfigJson) {
27
- const angularProjectTsConfigPath = getAngularAppTsConfigPath();
28
- const newTsconfigJson = Object.assign({}, tsconfigJson);
29
- newTsconfigJson.extends = `../${angularProjectTsConfigPath}`;
30
- return newTsconfigJson;
31
- }
32
-
33
- export function editStorybookTsConfig(tsconfigPath) {
34
- let tsConfigJson;
35
-
36
- try {
37
- tsConfigJson = readFileAsJson(tsconfigPath);
38
- } catch (e) {
39
- if (e.name === 'SyntaxError' && e.message.indexOf('Unexpected token /') > -1) {
40
- throw new Error(`Comments are disallowed in ${tsconfigPath}`);
41
- }
42
-
43
- throw e;
44
- }
45
-
46
- tsConfigJson = setStorybookTsconfigExtendsPath(tsConfigJson);
47
- writeFileAsJson(tsconfigPath, tsConfigJson);
48
- }
49
- export function getDefaultProjectName(angularJson) {
50
- const {
51
- defaultProject,
52
- projects
53
- } = angularJson;
54
-
55
- if (projects?.storybook) {
56
- return 'storybook';
57
- }
58
-
59
- if (defaultProject) {
60
- return defaultProject;
61
- }
62
-
63
- const firstProjectName = projects ? Object.keys(projects)[0] : undefined;
64
-
65
- if (firstProjectName) {
66
- return firstProjectName;
67
- }
68
-
69
- return undefined;
70
- }
71
- export function checkForProjects() {
72
- const {
73
- projects
74
- } = readFileAsJson('angular.json', true);
75
-
76
- if (!projects || Object.keys(projects).length === 0) {
77
- throw new Error('Could not find a project in your Angular workspace. \nAdd a project and re-run the installation');
78
- }
79
- }
80
- export async function getBaseTsConfigName() {
81
- return (await pathExists('./tsconfig.base.json')) ? 'tsconfig.base.json' : 'tsconfig.json';
82
- }
@@ -1,76 +0,0 @@
1
- import path from 'path';
2
- import semver from '@storybook/semver';
3
- import { checkForProjects, editStorybookTsConfig, getAngularAppTsConfigJson, getAngularAppTsConfigPath, getBaseTsConfigName } from './angular-helpers';
4
- import { writeFileAsJson, copyTemplate } from '../../helpers';
5
- import { baseGenerator } from '../baseGenerator';
6
- import { CoreBuilder } from '../../project_types';
7
-
8
- function editAngularAppTsConfig() {
9
- const tsConfigJson = getAngularAppTsConfigJson();
10
- const glob = '**/*.stories.*';
11
-
12
- if (!tsConfigJson) {
13
- return;
14
- }
15
-
16
- const {
17
- exclude = []
18
- } = tsConfigJson;
19
-
20
- if (exclude.includes(glob)) {
21
- return;
22
- }
23
-
24
- tsConfigJson.exclude = [...exclude, glob];
25
- writeFileAsJson(getAngularAppTsConfigPath(), tsConfigJson);
26
- }
27
-
28
- const generator = async (packageManager, npmOptions, options) => {
29
- checkForProjects();
30
- const angularVersion = semver.coerce(packageManager.retrievePackageJson().dependencies['@angular/core'])?.version;
31
- const isWebpack5 = semver.gte(angularVersion, '12.0.0');
32
- const updatedOptions = isWebpack5 ? Object.assign({}, options, {
33
- builder: CoreBuilder.Webpack5
34
- }) : options;
35
- await baseGenerator(packageManager, npmOptions, updatedOptions, 'angular', {
36
- extraPackages: ['@compodoc/compodoc'],
37
- addScripts: false
38
- });
39
- copyTemplate(__dirname);
40
- editAngularAppTsConfig(); // TODO: we need to add the following:
41
-
42
- /*
43
- "storybook": {
44
- "builder": "@storybook/angular:start-storybook",
45
- "options": {
46
- "browserTarget": "angular-cli:build",
47
- "port": 4400
48
- }
49
- },
50
- "build-storybook": {
51
- "builder": "@storybook/angular:build-storybook",
52
- "options": {
53
- "browserTarget": "angular-cli:build"
54
- }
55
- }
56
- */
57
- // to the user's angular.json file. see: https://github.com/storybookjs/storybook/blob/next/examples/angular-cli/angular.json#L78
58
- // then we want to add these scripts to package.json
59
- // packageManager.addScripts({
60
- // storybook: 'ng storybook',
61
- // 'build-storybook': 'ng build-storybook',
62
- // });
63
-
64
- editStorybookTsConfig(path.resolve('./.storybook/tsconfig.json')); // edit scripts to generate docs
65
-
66
- const tsConfigFile = await getBaseTsConfigName();
67
- packageManager.addScripts({
68
- 'docs:json': `compodoc -p ./${tsConfigFile} -e json -d .`
69
- });
70
- packageManager.addStorybookCommandInScripts({
71
- port: 6006,
72
- preCommand: 'docs:json'
73
- });
74
- };
75
-
76
- export default generator;
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "%SET_DURING_SB_INIT%",
3
- "compilerOptions": {
4
- "types": ["node"],
5
- "allowSyntheticDefaultImports": true
6
- },
7
- "exclude": ["../src/test.ts", "../src/**/*.spec.ts", "../projects/**/*.spec.ts"],
8
- "include": ["../src/**/*", "../projects/**/*"],
9
- "files": ["./typings.d.ts"]
10
- }
@@ -1,4 +0,0 @@
1
- declare module '*.md' {
2
- const content: string;
3
- export default content;
4
- }
@@ -1,32 +0,0 @@
1
- import { writeFileAsJson, readFileAsJson, copyTemplate } from '../../helpers';
2
- import { baseGenerator } from '../baseGenerator';
3
-
4
- function addStorybookExcludeGlobToTsConfig() {
5
- const tsConfigJson = readFileAsJson('tsconfig.json', true);
6
- const glob = '**/*.stories.ts';
7
-
8
- if (!tsConfigJson) {
9
- return;
10
- }
11
-
12
- const {
13
- exclude = []
14
- } = tsConfigJson;
15
-
16
- if (exclude.includes(glob)) {
17
- return;
18
- }
19
-
20
- tsConfigJson.exclude = [...exclude, glob];
21
- writeFileAsJson('tsconfig.json', tsConfigJson);
22
- }
23
-
24
- const generator = async (packageManager, npmOptions, options) => {
25
- addStorybookExcludeGlobToTsConfig();
26
- await baseGenerator(packageManager, npmOptions, options, 'aurelia', {
27
- extraPackages: ['aurelia']
28
- });
29
- copyTemplate(__dirname);
30
- };
31
-
32
- export default generator;
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "%SET_DURING_SB_INIT%",
3
- "compilerOptions": {
4
- "types": ["node"]
5
- },
6
- "exclude": ["../src/test.ts", "../src/**/*.spec.ts", "../projects/**/*.spec.ts"],
7
- "include": ["../src/**/*", "../projects/**/*"],
8
- "files": ["./typings.d.ts"]
9
- }
@@ -1,4 +0,0 @@
1
- declare module '*.md' {
2
- const content: string;
3
- export default content;
4
- }