Explorar el Código

refactor rakefile

Ruduki2 hace 6 años
padre
commit
ad2c953849
Se han modificado 1 ficheros con 27 adiciones y 9 borrados
  1. 27 9
      Rakefile

+ 27 - 9
Rakefile

@@ -1,5 +1,6 @@
 task default: %w(develop)
 STORY_DIR=File.join(ENV['USERPROFILE'], 'Documents\\Twine\\Stories')
+STORY_TITLE = 'Volleyball'
 FILES = {
   'intro' => 'Intro',
   'transform' => 'Transform',
@@ -8,6 +9,18 @@ FILES = {
   'money_game' => 'Money Games',
 }
 
+def files
+  FILES.map do |short_name, long_name|
+    OpenStruct.new({
+      short_name: short_name,
+      long_name: long_name,
+      source_file: "#{short_name}.tw2",
+      dest_file: File.join(STORY_DIR, "#{STORY_TITLE} - #{long_name}.html"),
+      wrapper_file: "#{short_name}_wrapper.tw2",
+    })
+  end
+end
+
 task develop: %w(bundle_install) do
   sh "bundle exec twee2 build main.tw2 develop.html"
 end
@@ -23,31 +36,36 @@ end
 
 desc 'export sub files to Twine 2'
 task export: %w(bundle_install) do
-  FILES.each do |short_name, long_name|
-    IO.write "#{short_name}_wrapper.tw2", <<~EOF
+  files.each do |file|
+    IO.write file.wrapper_file, <<~EOF
       ::StoryTitle
-      Volleyball - #{long_name}
+      Volleyball - #{file.long_name}
 
       ::Twee2Settings [twee2]
-      @story_start_name = 'Start #{long_name}'
+      @story_start_name = 'Start #{file.long_name}'
       Twee2::build_config.story_format = 'SugarCube2'
 
       ::StoryIncludes
       images.tw2
       stylesheet.tw2
       storyjs.tw2
-      #{short_name}.tw2
+      #{file.source_file}
     EOF
 
-    sh "bundle exec twee2 export #{short_name}_wrapper.tw2 '#{File.join(STORY_DIR, "Volleyball - #{long_name}.html")}'"
+    sh 'bundle', 'exec', 'twee2', 'export', file.wrapper_file, file.dest_file
   end
-  sh "bundle exec twee2 export main.tw2 '#{File.join(STORY_DIR, "Volleyball - Full Game.html")}'"
+  sh 'bundle', 'exec', 'twee2', 'export', 'main.tw2', STORY_DIR
 end
 
 desc 'import sub files from Twine 2'
 task import: %w(bundle_install) do
-  FILES.each do |short_name, long_name|
-    sh "bundle exec twee2 decompile '#{File.join(STORY_DIR, "Volleyball - #{long_name}.html")}' '#{short_name}.tw2' --exclude=StoryJS,StoryCSS,StoryTitle,Twee2Settings --exclude-from=storyjs.tw2,stylesheet.tw2,images.tw2"
+  files.each do |file|
+    sh(
+      'bundle', 'exec', 'twee2', 'decompile',
+      file.dest_file, file.source_file,
+      '--exclude=StoryJS,StoryCSS,StoryTitle,Twee2Settings',
+      '--exclude-from=storyjs.tw2,stylesheet.tw2,images.tw2"',
+    )
   end
 end