Rakefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. task default: %w(develop)
  2. STORY_DIR=File.join(ENV['USERPROFILE'], 'Documents\\Twine\\Stories')
  3. FILES = {
  4. 'intro' => 'Intro',
  5. 'transform' => 'Transform',
  6. 'custom_girl' => 'Custom Girl',
  7. 'beaches' => 'Beaches',
  8. 'money_game' => 'Money Games',
  9. }
  10. task develop: %w(bundle_install) do
  11. sh "bundle exec twee2 build main.tw2 develop.html"
  12. end
  13. task watch: %w(bundle_install) do
  14. sh 'start watch.html' # FIXME non-windows
  15. sh "bundle exec twee2 watch main.tw2 watch.html"
  16. end
  17. task release: %w(bundle_install) do
  18. sh "bundle exec twee2 build main.tw2 release.html"
  19. end
  20. desc 'export sub files to Twine 2'
  21. task export: %w(bundle_install) do
  22. FILES.each do |short_name, long_name|
  23. IO.write "#{short_name}_wrapper.tw2", <<~EOF
  24. ::StoryTitle
  25. Volleyball - #{long_name}
  26. ::Twee2Settings [twee2]
  27. @story_start_name = 'Start #{long_name}'
  28. Twee2::build_config.story_format = 'SugarCube2'
  29. ::StoryIncludes
  30. images.tw2
  31. stylesheet.tw2
  32. storyjs.tw2
  33. #{short_name}.tw2
  34. EOF
  35. sh "bundle exec twee2 export #{short_name}_wrapper.tw2 '#{File.join(STORY_DIR, "Volleyball - #{long_name}.html")}'"
  36. end
  37. sh "bundle exec twee2 export main.tw2 '#{File.join(STORY_DIR, "Volleyball - Full Game.html")}'"
  38. end
  39. desc 'import sub files from Twine 2'
  40. task import: %w(bundle_install) do
  41. FILES.each do |short_name, long_name|
  42. 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"
  43. end
  44. end
  45. task :bundle_install do
  46. sh 'bundle install'
  47. end
  48. task :clean do
  49. # TODO
  50. end
  51. task :lint do
  52. FILES.each do |short_name, long_name|
  53. filename = "#{short_name}.tw2"
  54. twee_source = IO.read(filename)
  55. twee_source.lines.each_with_index do |line, lineno|
  56. lineno += 1
  57. line
  58. .scan(%r{\[\[([^\]]*)\]\]})
  59. .map { |x| x[0] }
  60. .each do |link|
  61. case link.scan('->').length
  62. when 0
  63. #puts("link contains no ->, probably not a problem")
  64. next
  65. when 1
  66. # no problem
  67. else
  68. puts("link contains multiple -> definitely a problem")
  69. next
  70. end
  71. text, dest = link.split('->')
  72. if text.start_with?('\'')
  73. if !text.end_with?('\'')
  74. puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with single quote despite starting with one")
  75. next
  76. end
  77. text = text[1..-2]
  78. text
  79. .to_enum(:scan, '\'')
  80. .map {Regexp.last_match.offset(0)[0]}
  81. .each do |offset|
  82. if text[offset - 1] != '\\'
  83. puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted single quote in body"
  84. end
  85. end
  86. elsif text.start_with?('"')
  87. if !text.end_with?('"')
  88. puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with double quote despite starting with one")
  89. next
  90. end
  91. text = text[1..-2]
  92. text
  93. .to_enum(:scan, '"')
  94. .map {Regexp.last_match.offset(0)[0]}
  95. .each do |offset|
  96. if text[offset - 1] != '\\'
  97. puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted double quote in body"
  98. end
  99. end
  100. elsif text =~ /\A[\[\]'"\\]*\Z/
  101. puts "#{filename}:#{lineno} link text (#{text.inspect}) contains special characters but is not quoted with single or double quotes"
  102. end
  103. #puts(dest)
  104. end
  105. end
  106. end
  107. end