From 725b324645a9e6e7f55830be03dd893e57378aa9 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 6 Sep 2011 16:44:44 +0300 Subject: [PATCH] Refactor :compress task in Rakefile. This task is now run *before* other tasks. So we first compress the contents of template/ dir into template-min/ and from then on use the template-min/ dir as our template. To perform sencha build, I added build-js.html file that is like template.html but contains only bare minumum of JavaScript links that we need to build into one file. The purpose of all this is to run the :compress before building gem for release version of JSDuck. For this reason we also don't concatenate data.js with app.js, as the jsduck gem wants to generate its own data.js. The default value for --template option is now "template-min/", only in development related tasks :sdk and :touch do we replace it with "template/". --- .gitignore | 1 + Rakefile | 122 ++++++++++++++++++++++------------------- jsduck.gemspec | 9 +-- lib/jsduck/options.rb | 2 +- template/build-js.html | 25 +++++++++ template/template.html | 2 +- 6 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 template/build-js.html diff --git a/.gitignore b/.gitignore index 7fb16273..a6534cea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ template/extjs template/resources/css template/resources/sass/.sass-cache +template-min/ sdk-vars.rb diff --git a/Rakefile b/Rakefile index c6912d9f..35f89f4e 100644 --- a/Rakefile +++ b/Rakefile @@ -10,16 +10,6 @@ RSpec::Core::RakeTask.new(:spec) do |spec| 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" @@ -64,6 +54,7 @@ task :sdk do # to create symbolic links to template files instead of copying them over. # Useful for development. Turn off for deployment. "--template-links", + "--template", "template", "#{SDK_DIR}/extjs/src", "#{SDK_DIR}/platform/src", "#{SDK_DIR}/platform/core/src", @@ -215,7 +206,10 @@ end desc "Run JSDuck on Sencha Touch" task :touch do - run_on_touch("--template-links") + run_on_touch([ + "--template-links", + "--template", "template" + ]) end desc "Base task for creating live Sencta Touch docs" @@ -233,19 +227,19 @@ end # 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) +def combine_css(html, dir, opts = :write) css_section_re = /.*/m css = [] css_section_re.match(html)[0].each_line do |line| if line =~ /.*/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" +desc "Compress JavaScript and CSS files of JSDuck" 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" + + # Clean up template-min/ left over from previous compress task + system("rm", "-rf", "template-min") + # Copy template/ files to template-min/ + system("cp", "-r", "template", "template-min") + # Now do everything that follows in template-min/ dir + dir = "template-min" + # Create JSB3 file for Docs app - system("sencha", "create", "jsb", "-a", index_html, "-p", "#{OUT_DIR}/app.jsb3") + system("sencha", "create", "jsb", "-a", "#{dir}/build-js.html", "-p", "#{dir}/app.jsb3") # Concatenate files listed in JSB3 file - system("sencha", "build", "-p", "#{OUT_DIR}/app.jsb3", "-d", OUT_DIR) + system("sencha", "build", "-p", "#{dir}/app.jsb3", "-d", dir) # Remove intermediate build files - system("rm", "#{OUT_DIR}/app.jsb3") - system("rm", "#{OUT_DIR}/all-classes.js") + system("rm", "#{dir}/app.jsb3") + system("rm", "#{dir}/all-classes.js") # Replace app.js with app-all.js - system("mv", "#{OUT_DIR}/app-all.js", "#{OUT_DIR}/app.js") + system("mv", "#{dir}/app-all.js", "#{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) } + system("rm", "-r", "#{dir}/app") + + # Concatenate CSS in print-template.html file + print_template = "#{dir}/print-template.html"; + html = IO.read(print_template); + # Just modify HTML to link app.css, don't write files. + html = combine_css(html, dir, :replace_html_only) + File.open(print_template, 'w') {|f| f.write(html) } + + # Concatenate CSS and JS files referenced in template.html file + template_html = "#{dir}/template.html" + html = IO.read(template_html) + html = combine_css(html, dir) + html = combine_js(html, dir) + File.open(template_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" + system "rm -rf #{dir}/resources/sass" + system "rm -rf #{dir}/resources/codemirror" + system "rm -rf #{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" + system "rm -rf #{dir}/extjs" + system "mkdir #{dir}/extjs" + system "cp #{EXT_DIR}/ext-all.js #{dir}/extjs" + system "cp #{EXT_DIR}/ext-all-debug.js #{dir}/extjs" + system "cp #{EXT_DIR}/bootstrap.js #{dir}/extjs" + system "mkdir -p #{dir}/extjs/resources/css" + system "cp #{EXT_DIR}/resources/css/ext-all.css #{dir}/extjs/resources/css" + system "mkdir -p #{dir}/extjs/resources/themes/images" + system "cp -r #{EXT_DIR}/resources/themes/images/default #{dir}/extjs/resources/themes/images" 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 "Build gem locally" +task :build_gem do + system "gem build jsduck.gemspec" end desc "Run JSDuck on ExtJS SDK to create release version of docs app" -task :export => [:base_export_sdk, :compress, :copy_sdk_examples] +task :export => [:compress, :base_export_sdk, :copy_sdk_examples] desc "Run JSDuck on ExtJS SDK to create live docs app" -task :live_sdk => [:base_live_sdk, :compress, :copy_sdk_examples] +task :live_sdk => [:compress, :base_live_sdk, :copy_sdk_examples] desc "Run JSDuck on Sencha Touch to create live docs app" -task :live_touch => [:base_live_touch, :compress] +task :live_touch => [:compress, :base_live_touch] + +desc "Create gemfile for release" +task :build => [:compress, :build_gem] task :default => :spec diff --git a/jsduck.gemspec b/jsduck.gemspec index 8ef79525..022a172a 100644 --- a/jsduck.gemspec +++ b/jsduck.gemspec @@ -12,15 +12,10 @@ Gem::Specification.new do |s| s.rubyforge_project = s.name s.files = `git ls-files`.split("\n").find_all do |file| - file !~ /spec.rb$/ && file !~ /benchmark/ && file !~ /resources\/sass/ + file !~ /spec.rb$/ && file !~ /benchmark/ && file !~ /template\// end # Add files not in git - s.files += ['template/extjs/ext-all.js'] - s.files += ['template/extjs/resources/themes/images/default/tree/arrows.gif'] - s.files += ['template/extjs/resources/themes/images/default/grid/loading.gif'] - s.files += ['template/extjs/resources/themes/images/default/form/text-bg.gif'] - s.files += ['template/extjs/resources/themes/images/default/form/checkbox.gif'] - s.files += Dir['template/resources/css/*.css'] + s.files += Dir['template-min/**/*'] s.executables = ["jsduck"] diff --git a/lib/jsduck/options.rb b/lib/jsduck/options.rb index 9f714366..b7389114 100644 --- a/lib/jsduck/options.rb +++ b/lib/jsduck/options.rb @@ -89,7 +89,7 @@ module JsDuck # Debugging @processes = nil - @template_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + "/template" + @template_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + "/template-min" @template_links = false @extjs_path = "extjs/ext-all.js" @local_storage_db = "docs" diff --git a/template/build-js.html b/template/build-js.html new file mode 100644 index 00000000..64400b59 --- /dev/null +++ b/template/build-js.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/template/template.html b/template/template.html index 2c64e9d8..a3d932e5 100644 --- a/template/template.html +++ b/template/template.html @@ -30,8 +30,8 @@ - + {head_html} -- GitLab