Rakefile 4.1 KB

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