Last Updated: February 25, 2016
·
2.203K
· francpaul

Spine.js Mobile & Trigger.io Forge

Spine.js is my CoffeeScript mobile framework of choice - it's documented pretty well how to get it working with phonegap/cordova, but developing with pg is a painful process.
Trigger.io's Forge is a developer friendly cross platform native js api.

Here's what I did to get a basic app working.

Fire up forge-tools
source go.sh

Create the forge app
(forge-environment)➜ ~FORGE_ROOT : cd ..
(forge-environment)➜ mobile mkdir quotes
(forge-environment)➜ mobile cd quotes
(forge-environment)➜ quotes forge create

Install latest spine dependencies
(forge-environment)➜ quotes npm install -g spine spine.app hem

Create the spine.js app
(forge-environment)➜ quotes spine mobile ./spineapp
(forge-environment)➜ quotes cd spineapp
(forge-environment)➜ spineapp npm install .

Check that spine app is working
(forge-environment)➜ spineapp hem server

If it does:
Edit spineapp/public/index.html
remove the start.js script.
change '/application.js' -> 'application.js'
change '/application.css' -> 'application.css'

Do some basic spine app development in spineapp untill you have something that's obviously doing something - so you can check that it works on forge.

Add some forge api calls, most basic is logging. For example, my index.coffee file has this constructor in:

class App extends Stage.Global
  constructor: ->
    super
    forge.enableDebug()
    #activate controller
    @quotes = new Quotes
    @quotes.active()
    forge.logging.log('forge log example')

Once you have something you can test, the general process is as follows:
hem build spineapp
Copy the content of spineapp/public to the src directory of the forge project.
run forge build
run forge run ios
test on simulator
make changes
repeat

That's not as painless as I'd like so I've created a Thor script to do it for me. You'll need a recent release of the Thor gem (i'm on Thor 0.15.4):

create spineapp/spineforge.thor : https://gist.github.com/3071647

class Spineforge < Thor
  include Thor::Actions
  # thor spineforge:fuse ios

  desc "fuse ios/android","builds and runs app"
  def fuse(platform)
    #cd spineapp
    @spineapp_dir = File.dirname(__FILE__)
    @forge_dir = @spineapp_dir + '/../'
    inside @spineapp_dir do
      run('cd')
      run('hem build')
    end
    #copy spineapp/public/* to src/
    Thor::Sandbox::Spineforge.source_root(@spineapp_dir)
    directory 'public', @forge_dir + 'src'

    inside @forge_dir do
      #forge build
      run 'forge build'
      #forge run platform
      run "forge run #{platform}"
    end
  end

end

this lives in spineapp/ so i can easily switch between using hem server and thor spineforge:fuse ios

(forge-environment)➜ spineapp thor spineforge:fuse ios

I can now build my spine.js app, run spineforge and see the iphone simulator start the new version of my project. I'm not fond of the compile cycle, but it beats having to fire up eclipse or xcode and struggling with the pain of pg/cordova.

Trigger.io Forge is a promising tool - i hope to be in a position to support their development of more features sometime soon.