• Stars
    star
    306
  • Rank 136,456 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Ember.js codemod to make upgrades automatic.

ember-watson

A young Ember Doctor.

Build Status

Getting Started

ember-watson can be used as an Ember CLI addon, it will extend the available list of commands.

To install, run ember install ember-watson and you are good to go.

Commands

Prototype Extensions

ember watson:convert-prototype-extensions

Convert computed properties and observers to not use prototype extensions. You can specify appPath (defaults to app/) in case you want to convert code somewhere different to app/.

For more info about this please refer to the following PR Encourage decorator-style Ember.computed/Ember.observer

Resource Router Mapping

ember watson:convert-resource-router-mapping <routerPath>

Converts this.resource('user') to this.route('user', {resetNamespace: true }) in app/router.js.

Helps with the deprecation added in ember.js/11517.

Methodify (ES2015)

ember watson:methodify <path>

Converts methods in file to ES6 method syntax.

Find Overloaded CPS

ember watson:find-overloaded-cps <path>

Helps you locate all the places where your source may trigger the "Using the same function as getter and setter" deprecation.

Replace Needs with Injection

ember watson:replace-needs-with-injection <path>

Convert needs declarations the individual properties using the new Ember.inject.controller() feature. Also convert any uses of the controllers hash to use the newly defined properties.

Remove usages of Ember.K

ember watson:remove-ember-k <mode>

Replaces all usages of Ember.K with just plain functions. The <mode> argument is mandatory and can be --empty or --return-this. Invoked with --empty it will replace Ember.K with an empty function, which is more idiomatic JS. Invoked with --return-empty it will replace it by a function that returns this so allows chaining. This command runs automatically in all folders that might contain ember code, so no <path> or --dry-run options are available.

Tests: Upgrade QUnit Tests

ember watson:upgrade-qunit-tests

This command will traverse your tests directory fixing your QUnit test to use the 2.0 compatible output (see ember-cli#3197).

The following are some of the changes:

  • Add import { module, test } from 'qunit' if ember-qunit is not used. You need to use ember-cli-qunit-v0.3.8 which includes QUnit's shims. See ember-cli#3245
  • Import skip if used in tests: import { module,test, skip } from 'qunit'
  • Add assert to callback function in test.
  • Use assert inside test, e.g. ok becomes assert.ok.
  • Use beforeEach and afterEach instead of setup and teardown inside module.

Tests: Use Destroy App Helper

ember watson:use-destroy-app-helper <path>

Convert (qunit or mocha flavored) acceptance tests to utilize the destroyApp helper introduced in Ember CLI 1.13.9.

Tests: Convert andThen style async tests to async/await

ember watson:convert-tests-to-async-await <path>

Convert (qunit or mocha flavored) acceptance tests to utilize async/await

// before:
it('can visit subroutes', function(done) {
  visit('/');

  andThen(function() {
    expect(find('h2').text()).to.be.empty;
  });

  visit('/foo');

  andThen(function() {
    expect(find('h2').text()).to.be.equal('this is an acceptance test');
    done();
  });
});

// after:
it('can visit subroutes', async function() {
  await visit('/');

  expect(find('h2').text()).to.be.empty;

  await visit('/foo');

  expect(find('h2').text()).to.be.equal('this is an acceptance test');
});

Ember Data: Async Relationships Default

ember watson:convert-ember-data-async-false-relationships

In Ember Data 2.0 relationships will be asynchronous by default. Sync relationships will still be supported but you will need to manually opt into them by setting { async: false } on your relationships. This task adds an explicit async: false options to all belongsTo and hasMany that either have no options or its options does not contain an explicit async value.

For more information, read ember-data 1.13 release notes

Ember Data: Model Lookups

ember watson:convert-ember-data-model-lookups

This changes the way model lookups happen when working with Ember Data. When using hasMany or belongsTo, the first argument will become a dasherized string. Here's some examples:

// before, using a camelCase string
export default DS.Model.extend({
  postComments: DS.hasMany('postComment', {async: true})
});

// after
export default DS.Model.extend({
  postComments: DS.hasMany('post-comment', {async: true})
});

// before, using a variable or looking up on App.
export default DS.Model.extend({
  postComments: DS.hasMany(PostComment, {async: true})
});

// after
export default DS.Model.extend({
  postComments: DS.hasMany('post-comment', {async: true})
});

Ember Data: Remove isNewSerializerAPI

ember watson:remove-ember-data-is-new-serializer-api

Removes isNewSerializerAPI literals in your serializer code. You should use this after you make sure all your serializers are compatible with the new serializer API in 1.13. You can find more information on how to upgrade serializers here.

// before
export default DS.RESTSerializer.extend({
  isNewSerializerAPI: true
});

// after
export default DS.RESTSerializer.extend({});

Specifying a file or path

You can run any of the commands passing as argument the path, file or regular expression of the files that you want to transform.

ember watson:upgrade-qunit-tests tests/unit*
ember watson:upgrade-qunit-tests tests/unit/model-test.js
ember watson:upgrade-qunit-tests tests

The same is possible with ember watson:convert-prototype-extensions and ember watson:convert-ember-data-model-lookups.

Using without Ember CLI

ember-watson can be used without Ember CLI too, just do npm install -g ember-watson.

Then you can use the commands from above, just with the altered syntax.

ember watson:upgrade-qunit-tests becomes ember-watson upgrade-qunit-tests

For additional help use ember-watson -h.

License

ember-watson is MIT Licensed.

More Repositories

1

ember-101

95
star
2

rails-csrf

JavaScript
69
star
3

borrowers

Example application of the Ember.js book ember-cli-101.com
JavaScript
67
star
4

ember-attachable

JavaScript
41
star
5

borrowers-backend

Ruby
32
star
6

facturas-client

Ember.js client for facturas app, an app with Ember.js with Ruby on Rails.
JavaScript
29
star
7

facturas

ember-cli and Rails.
Ruby
27
star
8

ember-cli-101-errata

18
star
9

borrowers-api

Example application for the JSON API book https://leanpub.com/json-api-by-example
HTML
9
star
10

borrowers-2016

JavaScript
8
star
11

json-xdr

Easily convert between XDR and JSON.
TypeScript
7
star
12

heathub

Source code for heathub.co
Ruby
5
star
13

AnchorX

TypeScript
4
star
14

placefinder

The simplest ruby wrapper for placefinder's API.
Ruby
4
star
15

add_gem

Command-line tool to append new gems to your Gemfile.
Ruby
4
star
16

coassignment1

Computer Architecture Lecture's assignment
C
3
star
17

tweetex

Setup cron jobs to tweet daily about exchange rates.
Ruby
3
star
18

backtype

Ruby gem wrapper for backtype's API.
Ruby
3
star
19

turbinado-blog

Haskell
3
star
20

kintrospect

Commonplace book system for Kindle highlights
JavaScript
3
star
21

broccoli-petal

JavaScript
2
star
22

Writing-Smart-Contracts-With-Truffle

JavaScript
2
star
23

exosphere

JavaScript
2
star
24

StellarMobileWalletBoilerplate

TypeScript
2
star
25

anchorx-api

TypeScript
2
star
26

borrowers-dates

JavaScript
2
star
27

TicTacNow

Tic Tac Toe build with nowjs
C++
2
star
28

listening-crowd

Podcast player with annotations.
CSS
2
star
29

anuncios

Ruby
1
star
30

Hato

Simple To-Do Manager Using Happstack
Haskell
1
star
31

json-api-by-example-errata

Errata for the book JSON API By Example.
1
star
32

cupidhub

Ruby
1
star
33

kweb

1
star
34

dllt

Ruby
1
star
35

anchorx-api-boilerplate

TypeScript
1
star
36

operativos

Uni Project.
C
1
star
37

ember-rails-week-1

Ruby
1
star
38

kindlemd

Build a markdown file with your kindle highlights.
Ruby
1
star
39

_______ember-mobiledoc-dom-playground

JavaScript
1
star
40

atacado

Ruby
1
star