@toptal/davinci-storybook 0.0.2-alpha-fx-use-node-env-variable-cypress.33 → 0.1.0
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/README.md +14 -1
- package/package.json +13 -2
- package/src/addons.js +1 -0
- package/src/index.js +3 -1
- package/src/main.js +15 -0
- package/src/stories.js +65 -0
- package/src/webpack.conf.js +7 -0
package/README.md
CHANGED
|
@@ -5,5 +5,18 @@ Davinci's support for storybook. Themes, webpack configurations and related tool
|
|
|
5
5
|
|
|
6
6
|
## Usage
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Simple run
|
|
9
|
+
```shell
|
|
10
|
+
yarn storybook
|
|
11
|
+
```
|
|
9
12
|
|
|
13
|
+
To run storybook only for a particular `stories` file
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
yarn storybook -s hosts/host-1/src/stories/Button.stories.tsx
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
To run storybook from a particular directory:
|
|
20
|
+
```shell
|
|
21
|
+
yarn storybook -s hosts/host-1/src/stories/
|
|
22
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-storybook",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Davinci Storybook support project, containing configurations, themes, webpack plugins and related tools",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,5 +30,16 @@
|
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/toptal/davinci/issues"
|
|
32
32
|
},
|
|
33
|
-
"
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@babel/core": "^7.18.5",
|
|
35
|
+
"@toptal/davinci-storybook-addons": "^0.2.0",
|
|
36
|
+
"@storybook/builder-webpack5": "^6.5.9",
|
|
37
|
+
"@storybook/manager-webpack5": "^6.5.9",
|
|
38
|
+
"@storybook/react": "^6.5.9",
|
|
39
|
+
"@storybook/testing-library": "^0.0.13",
|
|
40
|
+
"babel-loader": "^8.2.5"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"yargs": "^17.5.1"
|
|
44
|
+
}
|
|
34
45
|
}
|
package/src/addons.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = ['@toptal/davinci-storybook-addons']
|
package/src/index.js
CHANGED
package/src/main.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const webpackFinal = require('./webpack.conf')
|
|
2
|
+
const addons = require('./addons')
|
|
3
|
+
const stories = require('./stories')
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
stories,
|
|
7
|
+
addons,
|
|
8
|
+
core: {
|
|
9
|
+
builder: 'webpack5',
|
|
10
|
+
options: {
|
|
11
|
+
fsCache: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
webpackFinal,
|
|
15
|
+
}
|
package/src/stories.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const yargs = require('yargs/yargs')
|
|
4
|
+
|
|
5
|
+
const STORY_EXTENSIONS = ['mdx', 'tsx', 'md', 'jsx']
|
|
6
|
+
const STORY_EXTENSIONS_PATTERN = `(${STORY_EXTENSIONS.join('|')})`
|
|
7
|
+
|
|
8
|
+
let currentWorkspace = process.cwd()
|
|
9
|
+
let isRootWorkspace = __dirname === `${currentWorkspace}/.storybook`
|
|
10
|
+
|
|
11
|
+
const args = yargs(process.argv.slice(2))
|
|
12
|
+
.command('src', 'Source path to stories')
|
|
13
|
+
.alias('s', 'src').argv
|
|
14
|
+
const source = args.src
|
|
15
|
+
|
|
16
|
+
const tryingSingleStory = STORY_EXTENSIONS.some(ext =>
|
|
17
|
+
source.endsWith(`.${ext}`)
|
|
18
|
+
)
|
|
19
|
+
const isSingleStory = STORY_EXTENSIONS.some(ext =>
|
|
20
|
+
source.endsWith(`stories.${ext}`)
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const singleStoryPath = isSingleStory
|
|
24
|
+
? path.resolve(currentWorkspace, source)
|
|
25
|
+
: undefined
|
|
26
|
+
|
|
27
|
+
if (tryingSingleStory) {
|
|
28
|
+
if (!isSingleStory) {
|
|
29
|
+
console.error(
|
|
30
|
+
'It seems you\'re trying to run a single story, but not a story file is provided, please specify "*.stories.tsx" or ".stories.mdx" file'
|
|
31
|
+
)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log(`Running single story file: "${source}"`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// try locating provided directory path,
|
|
39
|
+
// fallback to default behavior silently if cannot locate the directory
|
|
40
|
+
if (!tryingSingleStory && !source.startsWith('.')) {
|
|
41
|
+
const directoryPath = path.resolve(currentWorkspace, source)
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
fs.existsSync(directoryPath) &&
|
|
45
|
+
fs.statSync(directoryPath).isDirectory()
|
|
46
|
+
) {
|
|
47
|
+
console.log(`Running stories from directory: "${source}"`)
|
|
48
|
+
isRootWorkspace = false
|
|
49
|
+
currentWorkspace = directoryPath
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const stories = singleStoryPath
|
|
54
|
+
? [singleStoryPath]
|
|
55
|
+
: isRootWorkspace
|
|
56
|
+
? [
|
|
57
|
+
`../hosts/storybook/*.stories.@${STORY_EXTENSIONS_PATTERN}`,
|
|
58
|
+
`../apps/**/*.stories.@${STORY_EXTENSIONS_PATTERN}`,
|
|
59
|
+
`../libs/**/*.stories.@${STORY_EXTENSIONS_PATTERN}`,
|
|
60
|
+
`../namespaces/*/apps/**/*.stories.@${STORY_EXTENSIONS_PATTERN}`,
|
|
61
|
+
`../namespaces/*/libs/**/*.stories.@${STORY_EXTENSIONS_PATTERN}`,
|
|
62
|
+
]
|
|
63
|
+
: [`${currentWorkspace}/**/*.stories.@${STORY_EXTENSIONS_PATTERN}`]
|
|
64
|
+
|
|
65
|
+
module.exports = stories
|