Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Merge branch '2-0-stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalw committed Feb 6, 2017
2 parents f5e1dee + d462294 commit 8c52044
Show file tree
Hide file tree
Showing 86 changed files with 1,275 additions and 746 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.0.0
### Added
- memo-is for using memoization in specs

### Changed

- Updated Marionette to 3.1
- Updated Backbone to 1.3.3
- Updated Mocha to 3.1.2
- Updated jQuery to 3.0.0
- Node.js >= 6 is now required
- Switched from Browserify to webpack module bundler

### Removed

- Maji plugin management (`cordova/plugins.txt`) in favor of Cordova plugin management
- Maji application bus in favor of Backbone.Radio
- Maji Cordova platform management, see upgrade guide for details
37 changes: 14 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,15 @@ Before you can use Maji, make sure you have the following:

### General

* Ruby, for the Cucumber specs
* NodeJS, for the build system (`bin/setup` will install this if you've got Homebrew)
* Homebrew (`bin/setup` will use this to hook you up with all of the dependencies, except Ruby)

### Mac OS X

* [Homebrew](http://brew.sh) a Mac OS X package manager

### Linux

* [Nodejs](http://nodejs.org) allows JavaScript to be run Server-side
* [Apache Ant](http://ant.apache.org) is used for building Java Applications
* [PhantomJS](http://phantomjs.org/download.html) is a headless WebKit Browser, scriptable with a JavaScript API
* Ruby + Bundler, for the integration specs
* Node.js >= 6 + NPM, for the build system

## Getting started

To create a new app execute the following commands in your shell:

```
$ npm install kabisa/maji
$ npm install maji
$ ./node_modules/.bin/maji new org.example.my-app /desired/path/to/your/project/
$ cd /desired/path/to/your/project/
$ bin/setup
Expand All @@ -51,9 +40,11 @@ Your new Maji app will now be generated at the supplied path.

Commands:

run [options] <platform> build and run a native app for the specified platform
build [options] <platform> build a native app for the specified platform
new <package_name> <path> create a new Maji app
new <package_name> <path> Create a new Maji app
run [options] <platform> Build and run a native app for the specified platform
build [options] [platform] Build a native app for the specified platform
test [options] Run your project tests
start [options] Run the maji dev server and compile changes on the fly

Options:

Expand All @@ -64,15 +55,15 @@ Your new Maji app will now be generated at the supplied path.

### Starting in the browser

To start your app, `cd` into its directory, execute `make watch` and navigate to http://localhost:9090/ with your browser.
To start your app, `cd` into its directory, execute `bin/maji start` and navigate to http://localhost:9090/ with your browser.

### Running tests

To run test, you have several options:
* To run JavaScript tests run `bin/karma start`. This will start a Karma server with Phantomjs and will continuously watch your Javascript files and run tests on changes.
* To run JavaScript tests once, run `bin/karma start --single-run`.
* To run features specs once, run `bundle exec rspec`.
* To run all tests once, run `bin/ci`.
* To run JavaScript tests run `bin/maji test --watch`. This will start a Karma server with Phantomjs headless browser and will continuously watch your Javascript files and run tests on changes.
* To run JavaScript tests once, run `bin/maji test --unit`.
* To run features specs once, run `bin/maji test --integration`.
* To run all tests once, run `bin/maji test`.

### Creating builds

Expand All @@ -96,7 +87,7 @@ A Maji Mobile App comes with several frameworks built-in and configured to work
* [MarionetteJS](http://marionettejs.com) Marionette simplifies Backbone Views
* [FastClick](http://ftlabs.github.io/fastclick/) disable the delay between click and the action on iOS
* [jQuery](http://jquery.com) JavaScript library for working with the DOM
* [Browserify](http://browserify.org) is a JavaScript module system that supports CommonJS syntax
* [Webpack](https://webpack.js.org/) is a JavaScript module bundler
* [BugSnagJS](https://github.com/bugsnag/bugsnag-js) JavaScript client for [BugSnag](http://bugsnag.com/) exception tracker
* [Karma](http://karma-runner.github.io/) is a JavaScript test runner
* [MochaJS](http://mochajs.org) a JavaScript testing framework that supports a BDD style of writing tests
Expand Down
2 changes: 2 additions & 0 deletions bin/test-project-template
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
set -e

TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t maji-tests)
npm link
lib/cli.js new nl.kabisa.test-app $TMP_DIR

pushd $TMP_DIR
bin/setup
npm link maji
bin/ci
popd
30 changes: 30 additions & 0 deletions cordova/hooks/before_platform_add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function ensureDependencyInstalled(Q, mod) {
try {
require(`${mod}/package.json`);
return Q();
} catch(e) {
console.log(`Installing ${mod}`);
const deferred = Q.defer();

exec(`npm install ${mod}`, function(exitCode, stdout, stderr) {
if(exitCode == 0)
deferred.resolve();
else
deferred.reject();
});

return deferred.promise;
}
}

module.exports = function(context) {
if(context.opts.cordova.platforms.includes('ios')) {
context.requireCordovaModule('shelljs/global');

var Q = context.requireCordovaModule('q');
return Q.all([
ensureDependencyInstalled(Q, 'ios-sim'),
ensureDependencyInstalled(Q, 'ios-deploy')
]);
}
}
10 changes: 1 addition & 9 deletions dockerfiles/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ RUN apt-get update \
locales \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install NodeJS 5
RUN curl -sL https://deb.nodesource.com/setup_5.x | bash - \
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
&& apt-get install --yes nodejs

# Install PhantomJS 2.1.1
RUN cd /tmp && curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -o phantomjs-2.1.1-linux-x86_64.tar.bz2 \
&& tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 \
&& mv /tmp/phantomjs-*/bin/phantomjs /usr/bin/ \
&& rm -r /tmp/phantomjs*

ENV CONTAINER_INIT /usr/local/bin/init-container
RUN echo '#!/usr/bin/env bash' > $CONTAINER_INIT ; chmod +x $CONTAINER_INIT

Expand All @@ -37,5 +30,4 @@ RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV PHANTOMJS_BIN /usr/bin/phantomjs
ENV BUNDLE_PATH /cache/bundle
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Fast Node based build system
* Compilation of Coffeescript and Sass
* Javascript bundling and minification including source maps
* CommonJS module system using Browserify
* CommonJS module system using Webpack
* CSS autoprefixer (no more vendor prefixes!)
* Iconfont builder. Drop an SVG in your project and it's instantly available in your iconfont. [Read more](./icons.md).
* Livereload integration. Make changes and your browser will automatically reload, works on mobile too.
Expand Down
202 changes: 202 additions & 0 deletions docs/upgrade_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Upgrade guide Maji 1.1.0 -> 2.0.0

Maji 2.0 contains several (breaking) changes. Follow the steps outlined in this document to upgrade your app to Maji 2.0.

## MarionetteJS

In Maji 2.0.0 the Marionette dependency has been updated to 3.1.0.

This means that your app has to update from Marionette 2.4.4 to 3.1.0.
The `Maji.bus` (using `backbone.wreqr`) is also removed in favor of using `backbone.radio`.

Marionette has an [upgrade guide available online][marionette-upgrade], which you can use to find more help upgrading after using this guide.

The best way to start is to checkout the updated example app and compare it to your app.

1. Update `app/application.coffee`:
1. At the top of the file, replace
```coffee
attachFastClick = require('fastclick')
```

with

```coffee
FastClick = require('fastclick)
```
1. In the method `setTimeout`, replace both instances of
```coffee
app.mainRegion.$el
```
with
```coffee
$(app.getRegion().el)
```
2. Update `app/app.coffee`:
Add in the top of the file:
```coffee
Radio = require('backbone.radio')
```
Change the following:
```coffee
app.addInitializer ->
require('./modules/home/home_app').start()
```
to:
```coffee
app.on 'before:start', ->
require('./modules/home/home_app')
```
Change the kickoff of the backbone history:
```coffee
app.on 'initialize:after', (options) ->
Backbone.history.start()
```
to:
```coffee
app.on 'before:start', (options) ->
# Bind the start event in after the inclusion of
# the modules, so that the routers are initialized
# before the kick-off of the backbone history
app.on 'start', (options) ->
Backbone.history.start()
```
Update the implementation of the bus functions to:
```coffee
Radio.channel('app').reply(
'view:current': -> app.getView()
'uri:current': -> Backbone.history.fragment
'navigate': (location, options = {}) ->
app.getRegion().navigate(location, options, Backbone.history)
'go-back': (where, opts = {}) ->
where = undefined if where == '#'
app.getRegion().goBack(where, opts)
)
```

3. The best approachs is to disable all modules, and enable/update them one by one, starting with the main module 'app' file:

Change:

```coffee
MyModuleApp = app.module('my_module')
MyModuleApp.startWithParent = false

class MyModuleApp.Router extends Marionette.AppRouter
appRoutes:
'my_route/:resource_id' : 'openMyRoute'

API =
openMyRoute: (resourceId) ->
app.mainRegion.show new EditorPage(
model: model
)

MyModuleApp.addInitializer ->
new EditorApp.Router
controller: API

module.exports = EditorApp
```

To:

```coffee
# Notice creation of module is gone;
# New name for router

class MyModuleRouter extends Marionette.AppRouter
routes: # previously appRoutes
'my_route/:resource_id' : 'openMyRoute'

openMyRoute: (resourceId) -> # Method in class now
app.showView new EditorPage( # Use showView
model: model
)

app.on 'start', ->
new MyModuleRouter # No passing of controller

# No Module exports
```

4. Update all your views:

* everything extending from `Marionette.ItemView` must now extend from `Marionette.View`
* `onShow` is gone. Use `onAttach` instead
* Update use of *Regions*. `@myRegion.show new MySubView` is now `@showChildView('myRegion', new MySubView)`
* `getChildView: ->` is now `childView: ->`


## Cordova plugin management

Maji 2.x uses Cordova plugin management

This means that the Cordova plugins you wish to use should now be defined in `cordova/config.xml`, instead of `cordova/plugins.txt`.

Refer to the Cordova documentation for details: https://cordova.apache.org/docs/en/latest/platform_plugin_versioning_ref/

## Cordova platform management

In Maji 2.0, Maji no longer automatically adds Cordova platforms when you invoke `maji run` or `maji build`. Instead it is expected that you define the platform versions in your `cordova/config.xml` like so:

```xml
<!-- cordova/config.xml -->
<engine name="android" spec="~6.0.0" />
<engine name="ios" spec="~4.3.1" />
```

All projects created with Maji 2.0 are configured like this out of the box.

## Maji bus

Update all uses of the `Maji.bus` to Backbone.Radio ([see documentation of radio here][backbone-radio])

## Switch from Browserify to webpack (optional)

With Maji 2.x new projects use webpack for module bundling. While not required it's recommended that you migrate your projects to webpack, see [this Pull Request](https://github.com/kabisa/maji/pull/128) for reasoning and benefits. This PR can be used as a basis to migrate your project to webpack.

With these steps your app should become functional again, depending on how much custom stuff your app uses (like overwriting private implementations of Marionette).

## Maji CLI

Maji 2.x adds several new subcommands to the Maji CLI, streamlining the development workflow to have a single way to interact with your project:

* `maji start` - starts the development server
* `maji build` - build static assets
* `maji test` - runs your projects tests once
* `maji test --unit` - runs your unit test once
* `maji test --integration` - runs your integration test once
* `maji test --watch` - runs your tests whenever files are changed

All these commands delegate to NPM run scripts. When upgrading from Maji 1.x to Maji 2.x you can add the following snippet to your `package.json` to add support for these commands:

```json
"scripts": {
"test": "bin/ci",
"test:unit": "APP_ENV=test karma start --single-run",
"test:integration": "APP_ENV=test PRE_BUILT=true bundle exec rspec",
"test:watch": "APP_ENV=test karma start --watch",
"start": "make watch",
"build": "make dist"
}
```

Should you choose the use a different test runner for example then the only thing that needs to change are the NPM scripts defined in your `package.json` and everything will continue to work.

[marionette-upgrade]: http://marionettejs.com/docs/v3.1.0/upgrade.html
[backbone-radio]: https://github.com/marionettejs/backbone.radio
Loading

0 comments on commit 8c52044

Please sign in to comment.