Skip to content

Commit 7793928

Browse files
whitemerrywhitemerry
andauthored
Add view_component_storybook:remove_stories_json (#153)
Co-authored-by: whitemerry <piotr@b67.engineering>
1 parent 87c9a1a commit 7793928

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

docs/guide/getting-started.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,20 @@ class ExampleComponentStories < ViewComponent::Storybook::Stories
111111
end
112112
```
113113

114-
### Generating Storybook Stories JSON
114+
### Storybook Stories JSON
115115

116116
Generate the Storybook JSON stories by running the rake task:
117117

118118
```sh
119119
rake view_component_storybook:write_stories_json
120120
```
121121

122+
Remove existing Storybook JSON stories by running the rake task:
123+
124+
```sh
125+
rake view_component_storybook:remove_stories_json
126+
```
127+
122128
### Start the Rails app and Storybook
123129

124130
In separate shells start the Rails app and Storybook

lib/view_component/storybook/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Engine < Rails::Engine
4545
end
4646

4747
rake_tasks do
48-
load File.join(__dir__, "tasks/write_stories_json.rake")
48+
load File.join(__dir__, "tasks/view_component_storybook.rake")
4949
end
5050
end
5151
end

lib/view_component/storybook/tasks/write_stories_json.rake renamed to lib/view_component/storybook/tasks/view_component_storybook.rake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ namespace :view_component_storybook do
1616

1717
puts "Done"
1818
end
19+
20+
desc "Remove all existing CSF JSON Stories"
21+
task remove_stories_json: :environment do
22+
puts "Removing old Stories JSON"
23+
exceptions = []
24+
Dir["#{ViewComponent::Storybook.stories_path}/**/*.stories.json"].sort.each do |file|
25+
puts file
26+
File.unlink(file)
27+
rescue StandardError => e
28+
exceptions << e
29+
end
30+
31+
raise StandardError, exceptions.map(&:message).join(", ") if exceptions.present?
32+
33+
puts "Done"
34+
end
1935
end

0 commit comments

Comments
 (0)