Rakefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. task default: %w(develop)
  2. STORY_DIR=File.join(ENV['USERPROFILE'], 'Documents\\Twine\\Stories')
  3. STORY_TITLE = 'Volleyball'
  4. STORY_FORMAT = 'SugarCube'
  5. STORY_FORMAT_PATH = "story_formats/sugarcube-2.28.2-for-twine-2.1-local/sugarcube-2"
  6. STORY_FORMAT_VERSION = '2.28.2'
  7. FILES = {
  8. '01_intro' => '01 Intro',
  9. '02_transform' => '02 Transform',
  10. '03_custom_girl' => '03 Custom Girl',
  11. '04_money_game' => '04 Money Games',
  12. '05_beaches' => '05 Beaches',
  13. }
  14. def files
  15. FILES.map do |short_name, long_name|
  16. OpenStruct.new({
  17. short_name: short_name,
  18. long_name: long_name,
  19. source_file: "story/#{short_name}.tw2",
  20. dest_file: File.join(STORY_DIR, "#{STORY_TITLE} - #{long_name}.html"),
  21. wrapper_file: "#{short_name}_wrapper.tw2",
  22. })
  23. end
  24. end
  25. task develop: %w(bundle_install) do
  26. sh "bundle exec twee2 build '--format=#{STORY_FORMAT_PATH}' main.tw2 develop.html"
  27. end
  28. task watch: %w(bundle_install) do
  29. sh 'start watch.html' # FIXME non-windows
  30. sh "bundle exec twee2 watch main.tw2 watch.html"
  31. end
  32. task release: %w(bundle_install) do
  33. sh "bundle exec twee2 build main.tw2 release.html"
  34. end
  35. desc 'export sub files to Twine 2'
  36. task export: %w(bundle_install) do
  37. files.each do |file|
  38. IO.write file.wrapper_file, <<~EOF
  39. ::StoryTitle
  40. Volleyball - #{file.long_name}
  41. ::Twee2Settings [twee2]
  42. @story_start_name = 'Start #{file.long_name}'
  43. Twee2::build_config.story_format = '#{STORY_FORMAT}'
  44. Twee2::build_config.story_format_version = '#{STORY_FORMAT_VERSION}'
  45. ::StoryIncludes
  46. images.tw2
  47. stylesheet.tw2
  48. storyjs.tw2
  49. #{file.source_file}
  50. EOF
  51. sh(
  52. 'bundle', 'exec', 'twee2', 'export',
  53. "--format=#{STORY_FORMAT}", "--format-version=#{STORY_FORMAT_VERSION}",
  54. file.wrapper_file, file.dest_file,
  55. )
  56. end
  57. sh(
  58. 'bundle', 'exec', 'twee2', 'export',
  59. "--format=#{STORY_FORMAT}", "--format-version=#{STORY_FORMAT_VERSION}",
  60. 'main.tw2', STORY_DIR,
  61. )
  62. end
  63. desc 'import sub files from Twine 2'
  64. task import: %w(bundle_install) do
  65. files.each do |file|
  66. sh(
  67. 'bundle', 'exec', 'twee2', 'decompile',
  68. file.dest_file, file.source_file,
  69. '--exclude=StoryJS,StoryCSS,StoryTitle',
  70. '--exclude-from=../stylesheet.tw2,../storyjs.tw2,../stylesheet.tw2,../images.tw2',
  71. )
  72. end
  73. end
  74. task :bundle_install do
  75. sh 'bundle install'
  76. end
  77. task :clean do
  78. # TODO
  79. end
  80. task :lint do
  81. files.each do |file|
  82. twee_source = IO.read(file.source_file)
  83. twee_source.lines.each_with_index do |line, lineno|
  84. lineno += 1
  85. line
  86. .scan(%r{\[\[([^\]]*)\]\]})
  87. .map { |x| x[0] }
  88. .each do |link|
  89. case link.scan('->').length
  90. when 0
  91. #puts("link contains no ->, probably not a problem")
  92. text = link
  93. when 1
  94. # no problem
  95. text, dest = link.split('->')
  96. else
  97. warn("link contains multiple -> definitely a problem")
  98. next
  99. end
  100. if text.start_with?('\'')
  101. if !text.end_with?('\'')
  102. warn "#{file.source_file}:#{lineno} link text (#{text.inspect}) does not end with single quote despite starting with one"
  103. next
  104. end
  105. text = text[1..-2]
  106. text
  107. .to_enum(:scan, '\'')
  108. .map {Regexp.last_match.offset(0)[0]}
  109. .each do |offset|
  110. if text[offset - 1] != '\\'
  111. warn "#{file.source_file}:#{lineno} link text (#{text.inspect}) contains unquoted single quote in body"
  112. end
  113. end
  114. elsif text.start_with?('"')
  115. if !text.end_with?('"')
  116. warn "#{file.source_file}:#{lineno} link text (#{text.inspect}) does not end with double quote despite starting with one"
  117. next
  118. end
  119. text = text[1..-2]
  120. text
  121. .to_enum(:scan, '"')
  122. .map {Regexp.last_match.offset(0)[0]}
  123. .each do |offset|
  124. if text[offset - 1] != '\\'
  125. warn "#{file.source_file}:#{lineno} link text (#{text.inspect}) contains unquoted double quote in body"
  126. end
  127. end
  128. elsif text =~ /\A[\[\]'"\\]*\z/
  129. warn "#{file.source_file}:#{lineno} link text (#{text.inspect}) contains special characters but is not quoted with single or double quotes"
  130. end
  131. end
  132. end
  133. end
  134. end