Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# Generated folders from build process
/build

# Compiled js for tests
/tmp

# Local package dependencies
/node_modules

# Coverage report
coverage*

# Logs
npm-debug.log
npm-debug.log
92 changes: 44 additions & 48 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@ banner = """

"""

umdHead = '''
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['backbone', 'underscore'], factory);
} else if (typeof module === 'object' && module && module.exports) {
module.exports = factory(require('backbone'), require('underscore'));
} else if (typeof require === 'function') {
factory(window.Backbone, window._ || window.Backbone.utils);
} else {
throw new Error('Chaplin requires Common.js or AMD modules');
}
}(this, function(Backbone, _) {
function require(name) {
return {backbone: Backbone, underscore: _}[name];
}

require =
'''

umdTail = '''
return require(1);
}))
'''

module.exports = (grunt) ->

# Configuration
Expand All @@ -56,51 +32,63 @@ module.exports = (grunt) ->
options:
configFile: 'coffeelint.json'

clean: ['./tmp']

coffee:
test:
expand: true,
cwd: './test/',
src: ['*.coffee'],
dest: './tmp/test/',
ext: '.js'

mochaTest:
native:
options:
reporter: 'spec'
require: [
'coffee-script/register'
'coffee-coverage/register-istanbul'
->
global._$coffeeIstanbul = {}
Copy link
Contributor Author

@Florian-R Florian-R Nov 23, 2016

Choose a reason for hiding this comment

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

This is ugly, but needed. istanbul add something like

if (typeof _$coffeeIstanbul === 'undefined') _$coffeeIstanbul = {};

in every modules. This breaks badly with babel-register which wrap the code in a function with a use strict pragma.

Edit: In all fairness, this comes indeed from coffee-coverage. I've proposed a fix here benbria/coffee-coverage#82 (comment)

'babel-register'
'jsdom-assign'
-> require.cache[require.resolve 'jquery'] = {}
'backbone.nativeview'
]
src: 'test/*.coffee'
src: 'tmp/test/*.js'
jquery:
options:
reporter: 'spec'
require: [
'coffee-script/register'
->
global._$coffeeIstanbul = {}
'babel-register'
'jsdom-assign'
]
src: 'test/*.coffee'
src: 'tmp/test/*.js'

makeReport:
src: 'coverage/coverage-coffee.json',
options:
type: 'html'
dir: 'coverage'

browserify:
rollup:
options:
plugins: [
require('rollup-plugin-coffee-script')()
require('rollup-plugin-node-resolve')(extensions: ['.coffee'])
]
external: ['underscore', 'backbone']
globals:
backbone: 'Backbone'
underscore: '_'
format: 'umd'
moduleName: 'Chaplin'
banner: banner

dist:
files:
'build/chaplin.js': ['./src/chaplin.coffee']
options: {
banner
external: ['backbone', 'underscore']
transform: ['coffeeify']
browserifyOptions:
debug: true
extensions: ['.coffee']
postBundleCB: (err, src, next) ->
if err
next err
else
src = umdHead + src + umdTail
next null, new Buffer src
}
'build/chaplin.js': 'src/chaplin.coffee'

# Minify
# ======
Expand Down Expand Up @@ -298,17 +286,25 @@ module.exports = (grunt) ->

# Tests
# =====

grunt.registerTask 'instrument', ->
{CoverageInstrumentor} = require('coffee-coverage')
coverageInstrumentor = new CoverageInstrumentor({
instrumentor: 'istanbul'
})
coverageInstrumentor.instrument('./src', './tmp/src', bare: true)

grunt.registerTask 'lint', 'coffeelint'
grunt.registerTask 'test', 'mochaTest:native'
grunt.registerTask 'test:jquery', 'mochaTest:jquery'
grunt.registerTask 'test', ['clean', 'instrument', 'coffee:test', 'mochaTest:native']
grunt.registerTask 'test:jquery', ['clean', 'instrument', 'coffee:test', 'mochaTest:jquery']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part need some rework.


# Coverage
# ========
grunt.registerTask 'coverage', ['mochaTest:native', 'makeReport']

# Building
# ========
grunt.registerTask 'build', ['browserify', 'uglify', 'compress']
grunt.registerTask 'build', ['rollup', 'uglify', 'compress']

# Default
# =======
Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@
"description": "An Application Architecture Using Backbone.js",
"repository": "git://github.com/chaplinjs/chaplin.git",
"dependencies": {
"babel-register": "6.18.0",
"backbone": "~1.3.3",
"underscore": "~1.8.3"
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "6.18.0",
"backbone.nativeview": "~0.3.3",
"chai": "3.5.x",
"coffee-coverage": "1.0.1",
"coffee-script": "1.10.x",
"coffeeify": "~2.0.1",
"coffee-script": "1.11.x",
"grunt": "~0.4.5",
"grunt-browserify": "~4.0.1",
"grunt-cli": "~0.1.13",
"grunt-coffeelint": "~0.0.15",
"grunt-contrib-clean": "1.0.0",
"grunt-contrib-coffee": "florian-r/grunt-contrib-coffee",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is WIP pending a new release of grunt-contrib-coffee. The current version use an old version of coffee-script.

"grunt-contrib-compress": "0.14.x",
"grunt-contrib-uglify": "~0.11.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-istanbul": "0.7.0",
"grunt-mocha-test": "~0.12.7",
"grunt-rollup": "1.0.1",
"grunt-transbrute": "0.2.x",
"jquery": "2.2.x",
"jsdom": "~8.0.2",
"jsdom-assign": "shvaikalesh/jsdom-assign",
"mocha": "~2.4.5",
"prompt": "~0.2.14",
"rollup-plugin-coffee-script": "1.1.0",
"rollup-plugin-node-resolve": "2.0.0",
"sinon": "~1.17.3",
"sinon-chai": "2.8.x"
},
Expand All @@ -37,5 +42,10 @@
"coverage": "grunt coverage",
"build": "grunt build"
},
"license": "SEE LICENSE IN MIT-LICENSE.txt"
"license": "SEE LICENSE IN MIT-LICENSE.txt",
"babel": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined this to avoid a .babelrc

}
58 changes: 38 additions & 20 deletions src/chaplin.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
'use strict'
import Application from './chaplin/application'
import Composer from './chaplin/composer'
import Controller from './chaplin/controllers/controller'
import Dispatcher from './chaplin/dispatcher'
import Composition from './chaplin/lib/composition'
import EventBroker from './chaplin/lib/event_broker'
import History from './chaplin/lib/history'
import Route from './chaplin/lib/route'
import Router from './chaplin/lib/router'
import support from './chaplin/lib/support'
import SyncMachine from './chaplin/lib/sync_machine'
import utils from './chaplin/lib/utils'
import mediator from './chaplin/mediator'
import Collection from './chaplin/models/collection'
import Model from './chaplin/models/model'
import CollectionView from './chaplin/views/collection_view'
import Layout from './chaplin/views/layout'
import View from './chaplin/views/view'

# Main entry point into Chaplin module.
# Load all components and expose them.
module.exports =
Application: require './chaplin/application'
Composer: require './chaplin/composer'
Controller: require './chaplin/controllers/controller'
Dispatcher: require './chaplin/dispatcher'
Composition: require './chaplin/lib/composition'
EventBroker: require './chaplin/lib/event_broker'
History: require './chaplin/lib/history'
Route: require './chaplin/lib/route'
Router: require './chaplin/lib/router'
support: require './chaplin/lib/support'
SyncMachine: require './chaplin/lib/sync_machine'
utils: require './chaplin/lib/utils'
mediator: require './chaplin/mediator'
Collection: require './chaplin/models/collection'
Model: require './chaplin/models/model'
CollectionView: require './chaplin/views/collection_view'
Layout: require './chaplin/views/layout'
View: require './chaplin/views/view'
export default {
Application
Composer
Controller
Dispatcher
Composition
EventBroker
History
Route
Router
support
SyncMachine
utils
mediator
Collection
Model
CollectionView
Layout
View
}
Copy link
Contributor Author

@Florian-R Florian-R Nov 16, 2016

Choose a reason for hiding this comment

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

I'm not super fluent with ES6 modules, almost always used CommonJS. Cannot find a way have the import inlined in the export as were the require. Let me know if this could be done in a nicer way.

Copy link
Contributor

Choose a reason for hiding this comment

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

ES6 modules can do export { foo } from 'bar.coffee', but that won't help here. Furthermore, we should be careful not break CommonJS users because of default thing.

20 changes: 9 additions & 11 deletions src/chaplin/application.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'use strict'

# Third-party libraries.
_ = require 'underscore'
Backbone = require 'backbone'
import _ from 'underscore'
import Backbone from 'backbone'

# CoffeeScript classes which are instantiated with `new`
Composer = require './composer'
Dispatcher = require './dispatcher'
Router = require './lib/router'
Layout = require './views/layout'
import Composer from './composer'
import Dispatcher from './dispatcher'
import Router from './lib/router'
import Layout from './views/layout'

# A mix-in that should be mixed to class.
EventBroker = require './lib/event_broker'
import EventBroker from './lib/event_broker'

# Independent global event bus that is used by itself, so lowercased.
mediator = require './mediator'
import mediator from './mediator'

# The bootstrapper is the entry point for Chaplin apps.
module.exports = class Application
export default class Application
# Borrow the `extend` method from a dear friend.
@extend = Backbone.Model.extend

Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/composer.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'

Composition = require './lib/composition'
EventBroker = require './lib/event_broker'
mediator = require './mediator'
import Composition from './lib/composition'
import EventBroker from './lib/event_broker'
import mediator from './mediator'

# Composer
# --------
Expand All @@ -18,7 +16,7 @@ mediator = require './mediator'
# is routed to where a view that was composed is not re-composed, the
# composed view is disposed.

module.exports = class Composer
export default class Composer
# Borrow the static extend method from Backbone
@extend = Backbone.Model.extend

Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/controllers/controller.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
import mediator from '../mediator'
import EventBroker from '../lib/event_broker'
import utils from '../lib/utils'

mediator = require '../mediator'
EventBroker = require '../lib/event_broker'
utils = require '../lib/utils'

module.exports = class Controller
export default class Controller
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
14 changes: 6 additions & 8 deletions src/chaplin/dispatcher.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
import EventBroker from './lib/event_broker'
import utils from './lib/utils'
import mediator from './mediator'

EventBroker = require './lib/event_broker'
utils = require './lib/utils'
mediator = require './mediator'

module.exports = class Dispatcher
export default class Dispatcher
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
9 changes: 4 additions & 5 deletions src/chaplin/lib/composition.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'
import _ from 'underscore'
import Backbone from 'backbone'

_ = require 'underscore'
Backbone = require 'backbone'
EventBroker = require './event_broker'
import EventBroker from './event_broker'

# Composition
# -----------
Expand All @@ -11,7 +10,7 @@ EventBroker = require './event_broker'
# controller that is used internally to inflate simple
# calls to !composer:compose and may be extended and used to have complete
# control over the composition process.
module.exports = class Composition
export default class Composition
# Borrow the static extend method from Backbone.
@extend = Backbone.Model.extend

Expand Down
Loading