Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broccoli coffee upgrade #124

Merged
merged 12 commits into from
Feb 6, 2017
49 changes: 1 addition & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,6 @@ earlier versions, but I wouldn't know.

### How to use

#### CoffeeScript and ember-cli
There is one thing to note when using CoffeeScript with ember-cli: the syntax for _ES6-modules_.
In ember-cli-apps written in JavaScript, this is a common pattern:

```js
// app/components/my-component.js
import Ember from 'ember';

export default Ember.Component.extend({
tagName: 'div'
});
```

Writing `import` or `export` in a CoffeeScript-file causes an error, so we'll need
to escape these lines with backticks so they run as JavaScript.

We also need to store the export in a variable to export at the end, we can't export
directly as done above. Please note that the name of this variable does not affect
the name of the component itself - that is based entirely on the file name and placement.

Here's the above file in CoffeeScript:

```coffee
# app/components/my-component.coffee
`import Ember from 'ember'`

MyComponent = Ember.Component.extend
tagName: 'div'

`export default MyComponent`
```

Luckily, all the blueprints included with ember-cli-coffeescript do this for you! Which
leads to…

#### Blueprints
Run `ember help generate` to get a list of available blueprints. Use them by running `ember g <blueprint> <args>`. For instance, to generate the above component:

Expand Down Expand Up @@ -89,19 +54,7 @@ ENV.coffeeOptions = {
}
```

You can set `lint` to `true` to enable linting with the default configurations, but you will probably
want to add a `coffeelint.json` file to the root of your project either way, for instance to turn
off the error for backticks.

Example `coffeelint.json`:

```json
{
"no_backticks": {
"level": "ignore"
}
}
```
You can set `lint` to `true` to enable linting with the default configurations

You can find all the [available options on the website for `coffeelint`](http://www.coffeelint.org/#options).

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`import Ember from 'ember'`
`import { module, test } from 'qunit'`
`import startApp from '<%= testFolderRoot %>/tests/helpers/start-app'`
import Ember from 'ember'
import { module, test } from 'qunit'
import startApp from '<%= testFolderRoot %>/tests/helpers/start-app'

module 'Acceptance: <%= classifiedModuleName %>',
beforeEach: ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'adapter:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/adapter/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`<%= importStatement %>`
<%= importStatement %>

<%= classifiedModuleName %>Adapter = <%= baseClass %>.extend()

`export default <%= classifiedModuleName %>Adapter`
export default <%= classifiedModuleName %>Adapter
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default } from '<%= modulePath %>'`
export { default } from '<%= modulePath %>'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default } from '<%= modulePath %>'`
export { default } from '<%= modulePath %>'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { test, moduleForComponent } from 'ember-qunit'`<%= testImports %>
import { test, moduleForComponent } from 'ember-qunit'<%= testImports %>

moduleForComponent '<%= componentPathName %>', '<%= friendlyTestDescription %>', {
<%= testOptions %>
Expand Down
2 changes: 1 addition & 1 deletion blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
var locals = blueprint.locals.apply(blueprint, arguments);

var dasherizedModuleName = stringUtils.dasherize(options.entity.name);
var testImports = EOL + "`import hbs from 'htmlbars-inline-precompile'`";
var testImports = EOL + "import hbs from 'htmlbars-inline-precompile'";
var testOptions = "integration: true";

var testContent = "assert.expect 2" + EOL + EOL +
Expand Down
4 changes: 2 additions & 2 deletions blueprints/component/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'
<%= importTemplate %>
<%= classifiedModuleName %>Component = Ember.Component.extend(<%=contents%>)

`export default <%= classifiedModuleName %>Component`
export default <%= classifiedModuleName %>Component
7 changes: 1 addition & 6 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ module.exports = {
newContents = locals.contents + '\n';
}

var newImport = '';
if (locals.importTemplate) {
newImport = "`" + locals.importTemplate.replace(/;/, '`');
}

locals.contents = newContents;
locals.importTemplate = newImport;
locals.importTemplate = locals.importTemplate.replace(/;/, '');

return locals;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'controller:<%= dasherizedModuleName %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/controller/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= classifiedModuleName %>Controller = Ember.Controller.extend()

`export default <%= classifiedModuleName %>Controller`
export default <%= classifiedModuleName %>Controller
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default, <%= camelizedModuleName %> } from '<%= modulePath %>'`
export { default, <%= camelizedModuleName %> } from '<%= modulePath %>'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>'`
`import { module, test } from 'qunit'`
import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>'
import { module, test } from 'qunit'

module '<%= friendlyTestName %>'

Expand Down
6 changes: 3 additions & 3 deletions blueprints/helper/files/__root__/helpers/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
`import Ember from 'ember'`
import Ember from 'ember'

# This function receives the params `params, hash`
<%= camelizedModuleName %> = (params) ->
return params

<%= classifiedModuleName %>Helper = Ember.Helper.helper <%= camelizedModuleName %>

`export { <%= camelizedModuleName %> }`
export { <%= camelizedModuleName %> }

`export default <%= classifiedModuleName %>Helper`
export default <%= classifiedModuleName %>Helper
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default, initialize } from '<%= modulePath %>'`
export { default, initialize } from '<%= modulePath %>'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`import Ember from 'ember'`
`import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'`
`import { module, test } from 'qunit'`
import Ember from 'ember'
import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'
import { module, test } from 'qunit'

application = null
registry = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ initialize = () ->
name: '<%= dasherizedModuleName %>'
initialize: initialize

`export {initialize}`
`export default <%= classifiedModuleName %>Initializer`
export {initialize}
export default <%= classifiedModuleName %>Initializer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`import Ember from 'ember'`
`import <%= classifiedModuleName %>Mixin from '../../../mixins/<%= dasherizedModuleName %>'`
`import { module, test } from 'qunit'`
import Ember from 'ember'
import <%= classifiedModuleName %>Mixin from '../../../mixins/<%= dasherizedModuleName %>'
import { module, test } from 'qunit'

module '<%= friendlyTestName %>'

Expand Down
4 changes: 2 additions & 2 deletions blueprints/mixin/files/__root__/mixins/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= classifiedModuleName %>Mixin = Ember.Mixin.create()

`export default <%= classifiedModuleName %>Mixin`
export default <%= classifiedModuleName %>Mixin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleForModel, test } from 'ember-qunit'`
import { moduleForModel, test } from 'ember-qunit'

moduleForModel '<%= dasherizedModuleName %>', '<%= friendlyDescription %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/model/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
`import DS from 'ember-data'`
import DS from 'ember-data'

<%= classifiedModuleName %> = DS.Model.extend {
<%= attrs %>
}

`export default <%= classifiedModuleName %>`
export default <%= classifiedModuleName %>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default } from '<%= routeModulePath %>'`
export { default } from '<%= routeModulePath %>'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
`export { default } from '<%= templateModulePath %>'`
export { default } from '<%= templateModulePath %>'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'route:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/route/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= classifiedModuleName %>Route = Ember.Route.extend()

`export default <%= classifiedModuleName %>Route`
export default <%= classifiedModuleName %>Route
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleForModel, test } from 'ember-qunit'`
import { moduleForModel, test } from 'ember-qunit'

moduleForModel '<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>',
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/serializer/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import DS from 'ember-data'`
import DS from 'ember-data'

<%= classifiedModuleName %>Serializer = DS.RESTSerializer.extend()

`export default <%= classifiedModuleName %>Serializer`
export default <%= classifiedModuleName %>Serializer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'service:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/service/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= classifiedModuleName %>Service = Ember.Service.extend()

`export default <%= classifiedModuleName %>Service`
export default <%= classifiedModuleName %>Service
4 changes: 2 additions & 2 deletions blueprints/test-helper/files/tests/helpers/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= camelizedModuleName %> = (app) ->

`export default Ember.Test.registerAsyncHelper('<%= camelizedModuleName %>', <%= camelizedModuleName %>)`
export default Ember.Test.registerAsyncHelper('<%= camelizedModuleName %>', <%= camelizedModuleName %>)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'transform:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
# Specify the other units that are required for this test.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/transform/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import DS from 'ember-data'`
import DS from 'ember-data'

<%= classifiedModuleName %>Transform = DS.Transform.extend
deserialize: (serialized) ->
Expand All @@ -7,4 +7,4 @@
serialize: (deserialized) ->
deserialized

`export default <%= classifiedModuleName %>Transform`
export default <%= classifiedModuleName %>Transform
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import <%= camelizedModuleName %> from '../../../utils/<%= dasherizedModuleName %>'`
`import { module, test } from 'qunit'`
import <%= camelizedModuleName %> from '../../../utils/<%= dasherizedModuleName %>'
import { module, test } from 'qunit'

module '<%= friendlyTestName %>'

Expand Down
2 changes: 1 addition & 1 deletion blueprints/util/files/__root__/utils/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= camelizedModuleName %> = () ->
true

`export default <%= camelizedModuleName %>`
export default <%= camelizedModuleName %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`import { moduleFor, test } from 'ember-qunit'`
import { moduleFor, test } from 'ember-qunit'

moduleFor 'view:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>'

Expand Down
4 changes: 2 additions & 2 deletions blueprints/view/files/__root__/__path__/__name__.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`import Ember from 'ember'`
import Ember from 'ember'

<%= classifiedModuleName %>View = Ember.View.extend()

`export default <%= classifiedModuleName %>View`
export default <%= classifiedModuleName %>View
13 changes: 9 additions & 4 deletions node-tests/blueprints/acceptance-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var emberNew = blueprintHelpers.emberNew;
var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;

var expect = require('ember-cli-blueprint-test-helpers/chai').expect;
var expectCoffee = require('../helpers/expect-coffee');

describe('Acceptance: ember generate and destroy acceptance-test', function() {
setupTestHooks(this);
Expand All @@ -15,15 +16,19 @@ describe('Acceptance: ember generate and destroy acceptance-test', function() {

return emberNew()
.then(() => emberGenerateDestroy(args, (file) => {
expect(file('tests/acceptance/foo-test.coffee'))
.to.contain("`import Ember from 'ember'`")
.to.contain("`import { module, test } from 'qunit'`")
.to.contain("`import startApp from 'my-app/tests/helpers/start-app'`")
var acceptanceFile = file('tests/acceptance/foo-test.coffee');

expect(acceptanceFile)
.to.contain("import Ember from 'ember'")
.to.contain("import { module, test } from 'qunit'")
.to.contain("import startApp from 'my-app/tests/helpers/start-app'")
.to.contain("module 'Acceptance: Foo',")
.to.contain("test 'visiting /foo', (assert) ->")
.to.contain("visit '/foo'")
.to.contain("andThen ->")
.to.contain("assert.equal currentURL(), '/foo'");

expectCoffee(acceptanceFile);
}));
});
});
Loading