Created by Carlos Santana / @csantanapr
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network application.
Download and Install Node http://nodejs.org/download
$node -v
v0.10.18
Super Easy Install: npm comes with node now.
$npm -v
v1.3.8
For other alternatives: @isaacs/npm
Install bower using npm
$npm install -g bower
$bower -v
1.2.6
Install grunt-cli* using npm
$npm install -g grunt-cli
$grunt
grunt-cli: The grunt command line interface. (v0.1.9)
Fatal error: Unable to find local grunt.
*This error message is OK, grunt-cli is a wrapper that looks and runs grunt locally
Install cordova using npm
$npm install -g cordova
$cordova -v
3.0.9
Upgrading is as easy as installing using npm
$npm update -g bower
$npm update -g grunt-cli
$npm update -g cordova
Download the Dojox/App Boilerplate
@csantanapr/dapp-boilerplate
$curl -L -o dapp-boilerplate.tar.gz \
https://api.github.com/repos/csantanapr/dapp-boilerplate/tarball
$curl -L -o dapp-boilerplate.zip \
https://api.github.com/repos/csantanapr/dapp-boilerplate/zipball
Let's check what we downloaded
$tree dapp-boilerplate
├── Gruntfile.js ├── .bowerrc ├── bower.json ├── package.json ├── profiles │ └── app.profile.js └── src ├── app/ └── index.html
Let's use Bower
$bower install
$cat bower.json
{
"name": "dapp-boilerplate",
"dependencies": {
"dojox": "dojo/dojox#1.9.1",
"dojo" : "dojo/dojo#1.9.1",
"dijit": "dojo/dijit#1.9.1",
"util" : "dojo/util#1.9.1",
"dojox_application": "dmachi/dojox_application#dojo191"
}
}
$cat .bowerrc
{
"directory": "components"
}
$bower install
Let's check what we downloaded
$tree -L 1 components/
components/ ├── dijit ├── dojo ├── dojox ├── dojox_application └── util
Let's use NPM (package.json)
$npm install
{"devDependencies": {
"uglify-js": "~1.3.5",
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-csslint": "~0.1.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-connect": "~0.3.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-jslint": "~1.0.0",
"grunt-htmlhint": "~0.4.0",
"connect-livereload": "~0.2.0",
"grunt-dojo": "~0.2.4",
"grunt-open": "~0.2.2",
"grunt-cordovacli": "~0.1.5",
"time-grunt": "~0.1.1",
"load-grunt-tasks": "~0.1.0"
}}
Let's check what we downloaded
$tree -L 1 node_modules/
node_modules/ ├── connect-livereload ├── grunt ├── grunt-contrib-clean ├── grunt-contrib-connect ├── grunt-contrib-copy ├── grunt-contrib-csslint ├── grunt-contrib-jshint ├── grunt-contrib-watch ├── grunt-cordovacli ├── grunt-dojo ├── grunt-htmlhint ├── grunt-jslint ├── grunt-open ├── load-grunt-tasks ├── time-grunt ├── uglify-js
Lets see GruntJS in action
$grunt server
Running "jshint:src" (jshint) task
Running "csslint:lax" (csslint) task
Running "htmlhint:html" (htmlhint) task
Running "connect:livereload" (connect) task
Running "open:server" (open) task
Running "watch" task
Waiting...
GruntJS is a JavaScript Task Runner
Loads a web server and watch for changes
$grunt server
Specify tasks, targets, leverage grunt plugins
$grunt dojo
{
"dojo": {
"dist": {
"options": {
"profile": "profiles/app.profile.js",
"appConfigFile": "src/app/config.json",
"releaseDir": "src/.tmp"
}
},
"options": {
"dojo": "components/dojo/dojo.js",
"load": "build"
}
}
}
Run more grunt tasks
$grunt lint
$grunt build
$grunt server:dist
From Web to Native App
$cordova create hybrid
$cp -r dist/www hybrid/www
$cd hybrid
$cordova platform add ios
$cordova platform add android
$cordova plugin add org.apache.cordova.core.media-capture
$cordova prepare
$cordova compile
$cordova build
$cordova emulate android
$cordova emulate ios
Automate with grunt-cordovacli plugin
$grunt cordova
$grunt cordova_build
$grunt cordova_emulate
$cat src/app/views/demo/view.html
Demo
-
JavaScript rocks !
$cat src/app/views/demo/view.js
define([
'dojo/text!app/views/demo/view.html',
'dojox/mobile/Heading',
'dojox/mobile/EdgeToEdgeList',
'dojox/mobile/ListItem'
], function () {
'use strict';
return {
init: function () {
},
beforeActivate: function (previousView, data) {
},
afterActivate: function (previousView, data) {
},
beforeDeactivate: function (nextView, data) {
},
afterDeactivate: function (nextView, data) {
}
};
});
$cat src/app/config.json
{"views": {
"demo":{
"template": "app/views/demo/view.html",
"controller" : "app/views/demo/view.js",
"dependencies": [
"dojox/mobile/Heading",
"dojox/mobile/EdgeToEdgeList",
"dojox/mobile/ListItem"
]
}
}}
$grunt build_all
$grunt cordovacli:emulate_android
dude Yeoman Generator!
Dojo Unified Development Environment
$ npm install -g yo
$ npm install -g generator-dude
$ mkdir ~/dev/my-app && cd $_
$ yo dude
$ grunt server
$ grunt demo
Slides: csantana.io