Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:33:20+00:00 2026-06-06T18:33:20+00:00

In a build.rake file I have an array holding names of JavaScript files: JS_FROM_INDEX=`./bin/extract_files

  • 0

In a build.rake file I have an array holding names of JavaScript files:

JS_FROM_INDEX=`./bin/extract_files -e js index.html`.split

It holds these files:

js/config.js
js/vendor/dollar.js
js/vendor/ejs.min.js
js/utils.js
......
js/Viewport.js

Then there is a rule which (it is my guess as I’m completely ignorant to ruby yet) tells how to make the build/app.js file: namely take the js/config.js file first and then append all other files from the above array to it:

file DEST + '/app.js' => [DEST]+JS_FROM_INDEX.dup << 'index.html' << DEST do |t|
  sh "cat js/config.js > #{t.name}"
  sh "cat #{JS_FROM_INDEX.reject{|f| f =~ /\/config\.js/ }.join(" ")} | bin/yuicompressor --type js >> #{t.name}"
end

It works ok, but now I’ve found out, that js/utils.js should be at the very beginning, even before the js/config.js.

So my questions is:

Is there a nice way to sort the JS_FROM_INDEX array, so that js/utils.js and js/config.js are moved to its first positions? Can this be done as a oneliner (i.e. some code appended to the .split call above)?

UPDATE:

Meager has suggested (thank you!) the code:

scripts.unshift("js/config.js") if scripts.delete("js/config.js");
scripts.unshift("js/utils.js") if scripts.delete("js/utils.js");

To integrate that into the Rakefile I think I need to introduce 2 more variables:

JS_FROM_INDEX=`./bin/extract_files -e js index.html`.split
JS_SORTED_1=......use JS_FROM_INDEX somehow....
JS_SORTED_2=......use JS_FROM_SORTED_1 somehow....

file DEST + '/app.js' => [DEST]+JS_SORTED_2.dup << 'index.html' << DEST do |t|
  sh "cat #{JS_FROM_INDEX.reject{|f| f =~ /\/config\.js/ }.join(" ")} | bin/yuicompressor --type js >> #{t.name}"
end

Any ideas please on how to connect the dots above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:33:22+00:00Added an answer on June 6, 2026 at 6:33 pm

    Delete the item from the array and then (if it was found during the delete) push it onto the front of the array:

    scripts = %w(js/config.js
                js/vendor/dollar.js
                js/vendor/ejs.min.js
                js/utils.js)
    
    # Move config.js first
    scripts.unshift("js/config.js") if scripts.delete("js/config.js");
    
    # Move utils.js second to ensure it is always before config.js
    scripts.unshift("js/utils.js") if scripts.delete("js/utils.js");
    

    Here, delete returns nil if the item to delete wasn’t found, so the item is never unshifted back onto the front.

    You could easily make this more generic with by iterating over a list:

    items_to_sort_to_front.each { |item| scripts.unshift(item) if scripts.delete(item) }
    

    Just remember to sort items_to_sort_to_front backwards, as the last item in the list will be the last one moved to the front of scripts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using rake to build my project and I have a build.bat file
I'm just now learning about file tasks in Rake. I have 100s of javascript
I have the following rake file to create a static version of my sinatra
I have been looking into Rake for build script in our CI system (Projects
Does Rake have anything built in for replacing strings inside files and such or
I have a build task in rake defined with the following dependencies: desc 'Builds
I build a composite widget and would like it to have it's own accelerators
I build a project in C#. From another project I have 5 DLLs. Is
I build a css file using PHP which allows me to easily customize the
I have been playing around with Rake and Albacore, to see if I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.