Commit Graph

11 Commits

Author SHA1 Message Date
Jon Jensen dff3dec7e2 js bundle extensions for plugins, bugfixes and DRYification
allows plugins to have a bundle get auto-loaded with a corresponding
canvas bundle. uses require.js' include mechanism in build.js (when
optimized) and a rails helper tweak (when not optimized).

this happens automatically based on the path, e.g. the foo plugin's
"bundles/extensions/bar" will get automagically included whenever the
regular "bar" bundle is required.

removes the need for a plugin-level build.js, and auto-generates bundle
module definitions in canvas' build.js (via erb). this handles all
regular bundles both from canvas and plugins.

also fixes plugins so that bundle dependencies get optimized. plugin
paths are created automatically, so this means  we can remove things like
this from plugin bundles and specs:

 require.config
   paths:
     myplugin: "/plugins/myplugin/javascripts"

test plan:
1. use canvas in development mode, it should work
2. use canvas in optimized JS mode, it should work
   i.  confirm that all scripts are optimized
3. use canvas in development mode with plugins w/ JS, it should work
4. use canvas in optimized JS mode with plugins w/ JS, it should work
   i.  confirm that all scripts are optimized
5. add a bundle extension in a plugin (e.g. create
   bundles/extensions/conversations in plugin foo)
   i.  confirm that the extension code runs in development mode
   ii. confirm that the extension code runs in optimized JS mode

Change-Id: If8507afdbabab4ae8966f7db79d9b0e2284034db
Reviewed-on: https://gerrit.instructure.com/11238
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-06-25 10:28:49 -06:00
Cody Cutrer b6bbfb611d fix for using coffee when compiling js
coffee works a directory at a time, and the regex wasn't working for
plugins for just a directory

test plan:
 * npm install -g coffee-script@1.1.2
 * have a plugin with coffeescript
 * rake canvas:compile_assets (in a clean repo)
 * it should not fail

Change-Id: I5ca8030b9cdc572875169a0342dc09601fd2569b
Reviewed-on: https://gerrit.instructure.com/10095
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
2012-04-17 11:24:08 -06:00
Ryan Shaw 25725a198e parallelize build tasks
a faster rake js:generate, js:build, canvas:compile_assets, and guard

will use 'coffee' binary if installed

even if it doesn't use 'coffee' binary it will be
a lot faster

`time rake js:generate`
before               => real	0m29.960s
with 'coffee' binary => real	0m4.342s
without              => real	0m8.202s

test plan:
 * run bundle exec guard; ensure coffeescripts are compiled to the
   correct directories
 * run rake js:generate; ditto

Change-Id: I8fc4d4a415e5c77d1efa910c0922588d3095446b
Reviewed-on: https://gerrit.instructure.com/9989
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-04-16 16:38:23 -06:00
Jacob Fugal aba524e43f fix js:test for OSX, plugins, and dynamic manifest
no more maintaining spec/javascripts/supports/specs.js to tell the
runner which specs to run. instead, the runner is built from an erb that
determines the list of specs to run from the filesystem. this new way is
also plugin friendly by maintaining a plugin symlink to include plugin
specs in the spec/coffeescripts tree.

second, give the runner page to the phantomjs execution as a file:///
path rather than just a local path. the latter worked on the build
machine, but failed with the phantomjs installed viw macbrew.

third, clean up/out some slightly broken specs.

 * ENVSpec fails when the specs are reordered by the dynamic globbing,
   but is no longer necessary anyways (since ENV is global now)
 * the 'specs/helpers/' path in TemplateSpec doesn't work with the new
   setup, but just 'helpers/' does and is what it should have been using
   before anyways.
 * asyncTest is not reliable. once the specs started running in a
   slightly different order (thanks to the initial point), they started
   failing with asyncTest race conditions. use fakeTimers and
   fakeServers instead when appropriate.
 * found and fixed a minor bug in BackoffPoller while converting/fixing
   its asyncTests

test-plan:
  - run rake js:test; should run completely as before
  - add a plugin with a spec in spec_canvas/coffeescripts then run rake
    js:test again; the plugin's spec should be executed.

Change-Id: I9ce5a038829a9e747df26d878ce86dbb7da8c384
Reviewed-on: https://gerrit.instructure.com/9411
Reviewed-by: Jon Jensen <jon@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
2012-03-29 10:44:21 -06:00
Jacob Fugal 678ebe39cd fix rake canvas:compile_assets for plugins
while guard was watching and handling most of this, it wasn't happening
on deploy.

Change-Id: Ia4682b5487381ac741db5d2a7b1e8199495510d0
Reviewed-on: https://gerrit.instructure.com/9293
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Florence <ryanf@instructure.com>
2012-03-08 09:19:33 -07:00
Brian Palmer 92ce864aaf don't exec in js:build rake task
this is so evil

test plan:
  * run rake canvas:compile_assets, and verify that the api
    documentation gets built after js:build runs

Change-Id: If931f39735855b13e09ee773f296f24b555b3dc1
Reviewed-on: https://gerrit.instructure.com/9096
Reviewed-by: Ryan Florence <ryanf@instructure.com>
Tested-by: Brian Palmer <brianp@instructure.com>
2012-02-29 16:13:50 -07:00
Ryan Florence a1e31c8c9a AMD Conversion
"Trivial" JavaScript / CoffeeScript changes
--------------------------------------------------

For the most part, all javascript was simply
wrapped in `require` or `define`. The dependencies
were found with a script that matched regexes in
the files, it errs on the side of listing too many
dependencies, so its worth double checking each
file's dependencies (over time, anyway).

i18n API changes
--------------------------------------------------

No longer have to do I18n.scoped calls, just
list i18n as a dependency with the scope and it's
imported already scoped

  require ['i18n!some_scope'], (I18n) ->
    I18n.t 'im_scoped', 'I'm scoped!'

JS bundling now done with r.js, not Jammit
--------------------------------------------------

We don't use jammit to bundle JS anymore. Simply
list dependencies for your JS modules in the file
and RequireJS handles the rest.

To optimize the JavaScript, first make sure you
have node.js 0.4.12+ installed and then run:

  $ rake js:build

The app defaults to the optimized build in
production. You can use non-optimized in
production by putting ?debug_assets=true in the
url just like before.

You can also test the optimized JavaScript in
development with ?optimized_js=true.

Significant changes
--------------------------------------------------

These files have "real" changes to them (unlike
the JavaScript that is simply wrapped in require
and define).  Worth taking a really close look at:

- app/helpers/application_helper.rb
- app/views/layouts/application.html.erb
- config/assets.yml
- config/build.js
- lib/handlebars/handlebars.rb
- lib/i18n_extraction/js_extractor.rb
- lib/tasks/canvas.rake
- lib/tasks/i18n.rake
- lib/tasks/js.rake

Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7
Reviewed-on: https://gerrit.instructure.com/6986
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Florence <ryanf@instructure.com>
2012-02-06 16:41:40 -07:00
Ryan Shaw 686d13884d make task to just gen coffee script and handlebars
instead of telling people that they need to run
rake canvas:compile_assets (which is slow and error
prone) every time they fetch new code, we can just
have them run:

  rake js:generate

Change-Id: I560df603185b6b957fab7ab5ab2e5a211564d5d4
Reviewed-on: https://gerrit.instructure.com/7544
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-20 10:06:16 -07:00
Bryan Madsen 9224f6b0b1 make rake js:test task fail when a qunit test fails
Change-Id: Iafab3a98975e3911c8a39f80efd6ba7c401aa617
Reviewed-on: https://gerrit.instructure.com/7359
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Shaw <ryan@instructure.com>
2011-12-08 12:45:23 -07:00
Ryan Shaw 153be9f441 recompile qUint coffee scripts before running tests
Change-Id: I5b1fcd9f3b41331097100a7909986a9cb14241cf
Reviewed-on: https://gerrit.instructure.com/7280
Reviewed-by: Bryan Madsen <bryan@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
2011-12-05 14:43:38 -07:00
Ryan Florence 718f9f34ea qunit + AMD javascript specs
new stuff
---------

- added curl.js AMD module loader
- converted existing js specs to use QUnit
- removed jasmine stuff
- added rake task to run js specs

dependencies!
-------------

you'll need to install http://www.phantomjs.org/
if you want to run the specs.

next step is to incorporate curl.js into our app
environment.


Change-Id: I0ba97bc9abe1494f87fdfc0eca51d987a759bc85
Reviewed-on: https://gerrit.instructure.com/6477
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
2011-10-27 12:58:47 -06:00