Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user support for updating JS #83

Merged
merged 12 commits into from
Jun 5, 2018
Merged

Conversation

rohitner
Copy link
Contributor

@rohitner rohitner commented Mar 8, 2018

I have used the OptionParser as mentioned in #47

@Shekharrajak
Copy link
Member

Shekharrajak commented Mar 9, 2018

Please write few examples/description/proper commit msg to understand how it will work along with PR. It will be better if we create different commands for updating the different library js files. i.e. (1 command for updating the highcharts related files another command for updating the googlecharts related files). Means I want it to be modular and extendable. The main command (which will update all the js files) will use these commands.

Refer this One command must do only one thing.

bin/daru-view Outdated
opts.on('-u', '--update', 'Update js libraries') do
path = `gem which daru/view`.split('/')
path = path - [path[-1]]
path = path.join('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path = `gem which daru/view`.split('/')[0...-1].join('/')

@rohitner
Copy link
Contributor Author

rohitner commented Mar 9, 2018

Usage

  • To get help do :
    daru-view or daru-view --help

  • To update JS files for google charts do:
    daru-view update -g or daru-view update --googlecharts

  • To update JS files for highcharts do:
    daru-view update -H or daru-view --highcharts

@rohitner
Copy link
Contributor Author

rohitner commented Mar 9, 2018

Should I add the following to prevent rubocop fail because replacing __FILE__ with __dir__ in the files mentioned in offenses leads to failing rspec.

Style/ExpandPathArguments:
  Enabled: false

Copy link
Member

@Shekharrajak Shekharrajak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write test case for it. I hope there must be a way to test it.

@rohitner
Copy link
Contributor Author

rohitner commented Mar 11, 2018

I have managed to prevent failing build without altering the tests. Please check.

@v0dro
Copy link
Member

v0dro commented Mar 21, 2018

@Shekharrajak can you review this change and see if its good enough for merging?

@Shekharrajak
Copy link
Member

I will review it by tonight. I was waiting for testcases .

bin/daru-view Outdated
opts.banner = "Usage: daru-view [options]"
# Update google charts javascript dependent files, from latest Builds on google developers website
opts.on('-g', '--update-googlecharts', 'Update googlecharts.js libraries') do
sh "curl -# http://www.google.com/jsapi -L --compressed -o #{path}/view/adapters/js/googlecharts_js/google_visualr.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must create folder and file if it is not present, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will make that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if file is also not present or deleted to update it ? touch can be useful here, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this too. curl downloads the missing/deleted files. I have checked it by manually removing some js files. So it won't be a problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even I tried deleting the files. But it was throwing error. I hope you can write testcases for it. Please write in comment the TODO part as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the travis script to run the executable and added the TODO.

bin/daru-view Outdated

# Update highcharts.js from latest Builds on Highcharts codebase: http://code.highcharts.com/
opts.on('-H', '--update-highcharts', 'Update highcharts.js libraries') do
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/modules/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must have modularity , to update just modules or just adapters or just particular file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a doubt, why will someone using daru-view care about updating adapters and modules separately or a specific file? I think it is a different issue of having updates in a granular manner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if someone wants to use new features added in highcharts3d then user may just want to update the file highcharts-3d.js . Let me know if it is little tricky task. We will add it as TODO task .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to add it as a TODO task in #47 as it will require a bit of restructuring. This PR will make it easy to atleast update the JS files for now. ☺️

@Shekharrajak
Copy link
Member

The idea of the PR looks good, please have a look on comments .

@rohitner rohitner force-pushed the cmd-update-js branch 5 times, most recently from 65c3481 to e45721b Compare March 30, 2018 21:03
.travis.yml Outdated
@@ -11,6 +11,8 @@ rvm:
script:
- bundle exec rspec
- bundle exec rubocop
- ./bin/daru-view -g
- ./bin/daru-view -H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have added tests in RSpec instead of Travis, please check.

@@ -0,0 +1,22 @@
describe Daru::View, "Update JS files" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the tab indent to 2 spaces. 😄

expect(flag).to eq(true)
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line here.

bin/daru-view Outdated
@@ -3,10 +3,12 @@
require 'optparse'
require 'rake'

path = `gem which daru/view`.split('/')[0...-1].join('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your commit message is saying something else !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know why did you change this.

Copy link
Contributor Author

@rohitner rohitner May 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed to be an overkill for getting the path, So I just made it simpler by using the relative path. Pardon for the commit message. 😅

Copy link
Member

@Shekharrajak Shekharrajak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested the command in isolated container and docker it is working fine.

I was waiting for the spec which will test the files (i.e. whether js file are created/updated or not). Also some modular way of doing the task.

Merging it for now. Thanks @rohitner !

@Shekharrajak
Copy link
Member

@rohitner , Can you please document it ?

bin/daru-view Outdated
opts.banner = "Usage: daru-view [options]"
# TODO add arguments to update only modules/adapters/a particular file

# Update google charts javascript dependent files, from latest Builds on google developers website
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please maintain line length everywhere in the PR.

@@ -0,0 +1,22 @@
describe Daru::View, "Update JS files" do
context "googlecharts" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context ?

end
end

context "googlecharts" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context ?

bin/daru-view Outdated
opts.on('-g', '--update-googlecharts', 'Update googlecharts.js libraries') do
sh "mkdir -p #{path}/view/adapters/js/googlecharts_js/"

sh "curl -# http://www.google.com/jsapi -L --compressed -o #{path}/view/adapters/js/googlecharts_js/google_visualr.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length can be reduced,right ?

bin/daru-view Outdated
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/modules/"
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/adapters/"

sh "curl -# http://code.highcharts.com/highcharts.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/highcharts.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we make them in a loop ?

@rohitner
Copy link
Contributor Author

To keep everything DRY, I have replaced the code block with rake tasks.

@Shekharrajak
Copy link
Member

@rohitner , I will test it once more in isolated (docker) container. Let me know if you have tested all the commands properly in your system.

@rohitner
Copy link
Contributor Author

Actually there's a problem, we always need a rakefile in current directory for this to work. I will revert back to previous commit if there aren't any ways to tackle this.

@rohitner
Copy link
Contributor Author

@Shekharrajak , sorry for delay, please review

@rohitner
Copy link
Contributor Author

rohitner commented Jun 1, 2018

ping! @Shekharrajak

Copy link
Member

@Shekharrajak Shekharrajak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work by using the already present rake task.

TBH, thor is better if we want to test it properly, WDYT?

bin/daru-view Outdated
# Update google charts javascript dependent files, from latest Builds
# on the google developers website
opts.on('-g', '--update-googlecharts', 'Update googlecharts.js libraries') do
update(:googlecharts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a folder googlecharts_js, if it is not present. Better place will be in rake task.

bin/daru-view Outdated
update(:highcharts)
end

opts.on('-h', '--help', 'Displays Help') do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it will handle if invalid option is given?

@Shekharrajak
Copy link
Member

@rohitner , I just wanted to know your opinion. Let me know if you have checked it properly. This PR must be merged soon. Remaining thing we will do .

@rohitner
Copy link
Contributor Author

rohitner commented Jun 4, 2018

Hey @Shekharrajak , I actually saw the need of thor gem as I had to define a seperate update method in previous commit. I have checked it and everything works fine. This gem will be perfect for future work of providing granular updates.

@Shekharrajak
Copy link
Member

Thanks @rohitner ! I had tested few commands in isolated container it worked fine. I still have few concerns :

  1. If invalid command is typed then it must display the help command only. When help command is typed then all the commands must be displayed.
  2. I think along with this daru-view help update, we must also have daru-view help update -g, daru-view help update -h. If -g is lowercase then for highcharts as well it should be lowercase -h. For help we may have -H.
  3. Tescases need to be improved (we need to check the updated/present js file or some other kind of specs which can validate it is not breaking).

I am putting these into TODO list.

Let me know @rohitner , if you have any suggestions/opinions. I will merge it after that.

@rohitner
Copy link
Contributor Author

rohitner commented Jun 5, 2018

IMO, we should stick to the conventional -h for help command (change googlecharts to -G maybe). Regarding tests, we can run the update spec followed by remaining tests to check if the updated/present js files work properly. Good to go! ☺️

@Shekharrajak
Copy link
Member

change googlecharts to -G

will be better I guess.

Merging it for now.

@Shekharrajak Shekharrajak merged commit 67c6df6 into SciRuby:master Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants