require 'rubygems' require 'rake' $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) require 'rspec' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.rspec_opts = ["--color"] spec.pattern = "spec/**/*_spec.rb" end desc "Build gem locally" task :build do system "gem build jsduck.gemspec" end desc "Install gem locally" task :install => :build do system "gem install --user-install jsduck" end def load_sdk_vars if File.exists?("sdk-vars.rb") require "sdk-vars.rb" else puts "Error: sdk-vars.rb not found." puts puts "Please create file sdk-vars.rb and define constants SDK_DIR and OUT_DIR in it." puts puts "For example:" puts puts " SDK_DIR='/path/to/SDK'" puts " OUT_DIR='/path/to/ouput/dir'" puts " EXT_DIR='/path/to/ext/dir'" exit 1 end end def run_on_sdk(extra_options) # Pass multiple arguments to system, so we'll take advantage of the built-in escaping system(*[ "ruby", "bin/jsduck", "--welcome", "template/welcome.html", "--guides", "#{SDK_DIR}/guides/guides.json", "--videos", "#{SDK_DIR}/guides/videos.json", "--examples", "#{SDK_DIR}/extjs/examples/examples.json", "--inline-examples", "#{SDK_DIR}/extjs/doc-resources", "--categories", "#{SDK_DIR}/extjs/doc-resources/categories.json", "--output", "#{OUT_DIR}", ].concat(extra_options)) # Finally copy over the images that documentation links to. system "cp -r #{SDK_DIR}/extjs/doc-resources #{OUT_DIR}/doc-resources" system "cp -r #{SDK_DIR}/platform/doc-resources/* #{OUT_DIR}/doc-resources" end desc "Run JSDuck on ExtJS SDK" task :sdk do load_sdk_vars run_on_sdk([ "--extjs-path", "extjs/ext-all-debug.js", "--seo", # to create symbolic links to template files instead of copying them over. # Useful for development. Turn off for deployment. "--template-links", "#{SDK_DIR}/extjs/src", "#{SDK_DIR}/platform/src", "#{SDK_DIR}/platform/core/src", ]) end def run_sdk_export(extra_options) load_sdk_vars rev = `git rev-parse HEAD`.slice(0, 7) head_html = <<-EOHTML EOHTML run_on_sdk([ "--title", "Sencha Docs - Ext JS 4.0", "--footer", "Ext JS 4.0.6 Docs - Generated with JSDuck rev #{rev}", "--head-html", head_html, "#{SDK_DIR}/extjs/src", "#{SDK_DIR}/platform/src", "#{SDK_DIR}/platform/core/src", ].concat(extra_options)) end # Use the :export task instead desc "Base task for creating export" task :base_export_sdk do load_sdk_vars run_sdk_export([ "--body-html", <<-EOHTML
EOHTML ]) end # Use the :live_docs task instead desc "Base task for creating live docs" task :base_live_sdk do load_sdk_vars run_sdk_export([ "--seo", "--body-html", <<-EOHTML EOHTML ]) end desc "Run JSDuck on the Docs app itself" task :docs do load_sdk_vars run_on_sdk([ "--template-links", "#{SDK_DIR}/extjs/src", "#{SDK_DIR}/platform/src", "#{SDK_DIR}/platform/core/src", "template/app", "template/app.js", ]) end desc "Run JSDuck on ExtJS charts" task :charts do load_sdk_vars system(*[ "ruby", "bin/jsduck", "--title", "Sencha Docs - Touch Charts", "--ignore-global", "--guides", "#{SDK_DIR}/charts/guides", "--output", "#{OUT_DIR}", "--no-warnings", "#{SDK_DIR}/charts/src", ]) system "cp -r #{SDK_DIR}/platform/doc-resources #{OUT_DIR}/doc-resources" end def run_on_touch(*extra_options) load_sdk_vars rev = `git rev-parse HEAD`.slice(0, 7) head_html = <<-EOHTML EOHTML system(*[ "ruby", "bin/jsduck", "--title", "Sencha Docs - Touch 1.0", "--seo", "--categories", "#{SDK_DIR}/touch/doc-resources/categories.json", "--videos", "#{SDK_DIR}/touch/doc-resources/videos.json", "--footer", "Sencha Touch 1.0 Documentation from Sencha. Generated with JSDuck revison #{rev}", "--head-html", head_html, "--output", "#{OUT_DIR}", "#{SDK_DIR}/touch/src/core", "#{SDK_DIR}/touch/src/data", "#{SDK_DIR}/touch/src/gestures", "#{SDK_DIR}/touch/src/layout", "#{SDK_DIR}/touch/src/plugins", "#{SDK_DIR}/touch/src/util", "#{SDK_DIR}/touch/src/widgets", "#{SDK_DIR}/touch/src/platform/src", "#{SDK_DIR}/touch/resources/themes/stylesheets/sencha-touch/default", ].concat(extra_options)) # Finally copy over the images that documentation links to. system "cp -r #{SDK_DIR}/touch/doc-resources #{OUT_DIR}/doc-resources" end desc "Run JSDuck on Sencha Touch" task :touch do run_on_touch("--template-links") end desc "Base task for creating live Sencta Touch docs" task :base_live_touch do run_on_touch end # Compress JS/CSS file in-place # Using a hackish way to access yui-compressor def yui_compress(fname) system "java -jar $(dirname $(which sencha))/../jsbuilder/ycompressor/ycompressor.jar -o #{fname} #{fname}" end # Reads in all CSS files referenced between BEGIN CSS and END CSS markers. # Deletes those input CSS files and writes out concatenated CSS to # resources/css/app.css # Finally replaces the CSS section with to that one CSS file. def combine_css(html, base_dir, opts = :write) css_section_re = /.*/m css = [] css_section_re.match(html)[0].each_line do |line| if line =~ /') end # Same thing for JavaScript, result is written to: app.js def combine_js(html, base_dir) js_section_re = /.*/m js = [] js_section_re.match(html)[0].each_line do |line| if line =~ /') end # Use :export or :live_docs tasks instead of running this separately desc "Compresses JavaScript and CSS files in output dir" task :compress do load_sdk_vars # Detect if we are using index.html or template.html index_html = File.exists?("#{OUT_DIR}/index.html") ? "#{OUT_DIR}/index.html" : "#{OUT_DIR}/template.html" # Create JSB3 file for Docs app system("sencha", "create", "jsb", "-a", index_html, "-p", "#{OUT_DIR}/app.jsb3") # Concatenate files listed in JSB3 file system("sencha", "build", "-p", "#{OUT_DIR}/app.jsb3", "-d", OUT_DIR) # Remove intermediate build files system("rm", "#{OUT_DIR}/app.jsb3") system("rm", "#{OUT_DIR}/all-classes.js") # Replace app.js with app-all.js system("mv", "#{OUT_DIR}/app-all.js", "#{OUT_DIR}/app.js") # Remove the entire app/ dir system("rm", "-r", "#{OUT_DIR}/app") # Optionally concatenate CSS in print-template.html file print_template = "#{OUT_DIR}/print-template.html"; if File.exists?(print_template) html = IO.read(print_template); # Just modify HTML to link app.css, don't write files. html = combine_css(html, OUT_DIR, :replace_html_only) File.open(print_template, 'w') {|f| f.write(html) } end # Concatenate CSS and JS files referenced in index.html file html = IO.read(index_html) html = combine_css(html, OUT_DIR) html = combine_js(html, OUT_DIR) File.open(index_html, 'w') {|f| f.write(html) } # Clean up SASS files # (But keep prettify lib, which is needed for source files) system "rm -rf #{OUT_DIR}/resources/sass" system "rm -rf #{OUT_DIR}/resources/codemirror" system "rm -rf #{OUT_DIR}/resources/.sass-cache" # Empty the extjs dir, leave only the main JS files, CSS and images system "rm -rf #{OUT_DIR}/extjs" system "mkdir -p #{OUT_DIR}/extjs/resources/css" system "mkdir -p #{OUT_DIR}/extjs/resources/themes/images" system "cp #{EXT_DIR}/ext-all.js #{OUT_DIR}/extjs" system "cp #{EXT_DIR}/ext-all-debug.js #{OUT_DIR}/extjs" system "cp #{EXT_DIR}/bootstrap.js #{OUT_DIR}/extjs" end desc "Copy over SDK examples" task :copy_sdk_examples do system "mkdir #{OUT_DIR}/extjs/builds" system "cp #{EXT_DIR}/builds/ext-core.js #{OUT_DIR}/extjs/builds/ext-core.js" system "cp #{EXT_DIR}/resources/css/ext-all.css #{OUT_DIR}/extjs/resources/css" system "cp #{EXT_DIR}/release-notes.html #{OUT_DIR}/extjs" system "cp -r #{EXT_DIR}/examples #{OUT_DIR}/extjs" system "cp -r #{EXT_DIR}/welcome #{OUT_DIR}/extjs" system "cp -r #{EXT_DIR}/resources/themes/images/default #{OUT_DIR}/extjs/resources/themes/images" end desc "Run JSDuck on ExtJS SDK to create release version of docs app" task :export => [:base_export_sdk, :compress, :copy_sdk_examples] desc "Run JSDuck on ExtJS SDK to create live docs app" task :live_sdk => [:base_live_sdk, :compress, :copy_sdk_examples] desc "Run JSDuck on Sencha Touch to create live docs app" task :live_touch => [:base_live_touch, :compress] task :default => :spec