diff --git a/blueprints/adapter/index.js b/blueprints/adapter/index.js index 1f8ea57a426..b3ecab8c23f 100644 --- a/blueprints/adapter/index.js +++ b/blueprints/adapter/index.js @@ -10,6 +10,6 @@ module.exports = { ], locals: function(options) { - return extendFromApplicationEntity('adapter', 'JSONAPIAdapter', 'ember-data/adapters/json-api', options); + return extendFromApplicationEntity('adapter', 'DS.JSONAPIAdapter', options); } }; diff --git a/blueprints/model/HELP.md b/blueprints/model/HELP.md index bfd70568519..caba05ddbac 100644 --- a/blueprints/model/HELP.md +++ b/blueprints/model/HELP.md @@ -14,16 +14,13 @@ For instance: \`ember generate model taco filling:belongs-to:protein topp would result in the following model: ```js -import Model from 'ember-data/model'; +import DS from 'ember-data'; -import attr from 'ember-data/attr'; -import { belongsTo, hasMany } from 'ember-data/relationships'; - -export default Model.extend({ - filling: belongsTo('protein'), - toppings: hasMany('topping'), - name: attr('string'), - price: attr('number'), - misc: attr() +export default DS.Model.extend({ + filling: DS.belongsTo('protein'), + toppings: DS.hasMany('topping'), + name: DS.attr('string'), + price: DS.attr('number'), + misc: DS.attr() }); ``` diff --git a/blueprints/model/files/__root__/__path__/__name__.js b/blueprints/model/files/__root__/__path__/__name__.js index d92b5042812..3661e07bc60 100644 --- a/blueprints/model/files/__root__/__path__/__name__.js +++ b/blueprints/model/files/__root__/__path__/__name__.js @@ -1,5 +1,5 @@ -<%= importStatements %> +import DS from 'ember-data'; -export default Model.extend({ +export default DS.Model.extend({ <%= attrs.length ? ' ' + attrs : '' %> }); diff --git a/blueprints/model/index.js b/blueprints/model/index.js index 4d813b39b59..6f19377212c 100644 --- a/blueprints/model/index.js +++ b/blueprints/model/index.js @@ -16,10 +16,6 @@ module.exports = { var attrs = []; var needs = []; var entityOptions = options.entity.options; - var importStatements = ['import Model from \'ember-data/model\';']; - var shouldImportAttr = false; - var shouldImportBelongsTo = false; - var shouldImportHasMany = false; for (var name in entityOptions) { var type = entityOptions[name] || ''; @@ -39,15 +35,12 @@ module.exports = { var camelizedNamePlural = inflection.pluralize(camelizedName); attr = dsAttr(dasherizedForeignModelSingular, dasherizedType); attrs.push(camelizedNamePlural + ': ' + attr); - shouldImportHasMany = true; } else if (/belongs-to/.test(dasherizedType)) { attr = dsAttr(dasherizedForeignModel, dasherizedType); attrs.push(camelizedName + ': ' + attr); - shouldImportBelongsTo = true; } else { attr = dsAttr(dasherizedName, dasherizedType); attrs.push(camelizedName + ': ' + attr); - shouldImportAttr = true; } if (/has-many|belongs-to/.test(dasherizedType)) { @@ -59,30 +52,10 @@ module.exports = { return needs.indexOf(need) === i; }); - if (shouldImportAttr) { - importStatements.push('import attr from \'ember-data/attr\';'); - } else { - importStatements.push('// import attr from \'ember-data/attr\';'); - } - - if (shouldImportBelongsTo && shouldImportHasMany) { - importStatements.push('import { belongsTo, hasMany } from \'ember-data/relationships\';'); - } else if (shouldImportBelongsTo) { - importStatements.push('import { belongsTo } from \'ember-data/relationships\';'); - importStatements.push('// import { hasMany } from \'ember-data/relationships\';'); - } else if (shouldImportHasMany) { - importStatements.push('// import { belongsTo } from \'ember-data/relationships\';'); - importStatements.push('import { hasMany } from \'ember-data/relationships\';'); - } else { - importStatements.push('// import { belongsTo, hasMany } from \'ember-data/relationships\';'); - } - - importStatements = importStatements.join(EOL); attrs = attrs.join(',' + EOL + ' '); needs = ' needs: [' + needsDeduplicated.join(', ') + ']'; return { - importStatements: importStatements, attrs: attrs, needs: needs }; @@ -92,14 +65,14 @@ module.exports = { function dsAttr(name, type) { switch (type) { case 'belongs-to': - return 'belongsTo(\'' + name + '\')'; + return 'DS.belongsTo(\'' + name + '\')'; case 'has-many': - return 'hasMany(\'' + name + '\')'; + return 'DS.hasMany(\'' + name + '\')'; case '': //"If you don't specify the type of the attribute, it will be whatever was provided by the server" //http://emberjs.com/guides/models/defining-models/ - return 'attr()'; + return 'DS.attr()'; default: - return 'attr(\'' + type + '\')'; + return 'DS.attr(\'' + type + '\')'; } } diff --git a/blueprints/serializer/index.js b/blueprints/serializer/index.js index 1e43a8a2fa0..b5b278ae70a 100644 --- a/blueprints/serializer/index.js +++ b/blueprints/serializer/index.js @@ -10,6 +10,6 @@ module.exports = { ], locals: function(options) { - return extendFromApplicationEntity('serializer', 'JSONAPISerializer', 'ember-data/serializers/json-api', options); + return extendFromApplicationEntity('serializer', 'DS.JSONAPISerializer', options); } }; diff --git a/blueprints/transform/files/__root__/__path__/__name__.js b/blueprints/transform/files/__root__/__path__/__name__.js index 1d048927535..722408742d7 100644 --- a/blueprints/transform/files/__root__/__path__/__name__.js +++ b/blueprints/transform/files/__root__/__path__/__name__.js @@ -1,6 +1,6 @@ -import Transform from 'ember-data/transform'; +import DS from 'ember-data'; -export default Transform.extend({ +export default DS.Transform.extend({ deserialize(serialized) { return serialized; }, diff --git a/lib/utilities/extend-from-application-entity.js b/lib/utilities/extend-from-application-entity.js index cb340293364..437a38818b4 100644 --- a/lib/utilities/extend-from-application-entity.js +++ b/lib/utilities/extend-from-application-entity.js @@ -4,7 +4,7 @@ var pathUtil = require('ember-cli-path-utils'); var existsSync = require('exists-sync'); var path = require('path'); -module.exports = function(type, baseClass, packagePath, options) { +module.exports = function(type, baseClass, options) { var entityName = options.entity.name; var isAddon = options.inRepoAddon || options.project.isEmberCLIAddon(); var relativePath = pathUtil.getRelativePath(options.entity.name); @@ -18,14 +18,12 @@ module.exports = function(type, baseClass, packagePath, options) { var hasApplicationEntity = existsSync(applicationEntityPath); if (!isAddon && !options.baseClass && entityName !== 'application' && hasApplicationEntity) { options.baseClass = 'application'; - packagePath = './application'; } if (options.baseClass === entityName) { throw new SilentError(stringUtil.classify(type) + 's cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.'); } - - var importStatement = 'import ' + baseClass + ' from \'' + packagePath + '\';'; + var importStatement = 'import DS from \'ember-data\';'; if (options.baseClass) { baseClass = stringUtil.classify(options.baseClass.replace('\/', '-')); diff --git a/node-tests/blueprints/adapter-test.js b/node-tests/blueprints/adapter-test.js index 26475faca6a..699abfa1454 100644 --- a/node-tests/blueprints/adapter-test.js +++ b/node-tests/blueprints/adapter-test.js @@ -19,8 +19,8 @@ describe('Acceptance: generate and destroy adapter blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/adapters/foo.js')) - .to.contain('import JSONAPIAdapter from \'ember-data/adapters/json-api\';') - .to.contain('export default JSONAPIAdapter.extend({'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.JSONAPIAdapter.extend({'); expect(_file('tests/unit/adapters/foo-test.js')) .to.contain('moduleFor(\'adapter:foo\''); @@ -70,8 +70,8 @@ describe('Acceptance: generate and destroy adapter blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/adapters/application.js')) - .to.contain('import JSONAPIAdapter from \'ember-data/adapters/json-api\';') - .to.contain('export default JSONAPIAdapter.extend({'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.JSONAPIAdapter.extend({'); expect(_file('tests/unit/adapters/application-test.js')) .to.contain('moduleFor(\'adapter:application\''); diff --git a/node-tests/blueprints/model-test.js b/node-tests/blueprints/model-test.js index d3565b41ea3..70e046f9517 100644 --- a/node-tests/blueprints/model-test.js +++ b/node-tests/blueprints/model-test.js @@ -16,12 +16,8 @@ describe('Acceptance: generate and destroy model blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/models/foo.js')) - .to.contain('import Model from \'ember-data/model\';') - .to.contain('export default Model.extend(') - .to.contain('// import attr from \'ember-data/attr\';') - .to.contain('// import { belongsTo, hasMany } from \'ember-data/relationships\';') - .to.not.contain('import { belongsTo } from \'ember-data/relationships\';') - .to.not.contain('import { hasMany } from \'ember-data/relationships\';'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.Model.extend(') expect(_file('tests/unit/models/foo-test.js')) .to.contain('moduleForModel(\'foo\''); @@ -45,20 +41,16 @@ describe('Acceptance: generate and destroy model blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/models/foo.js')) - .to.contain('import Model from \'ember-data/model\';') - .to.contain('import attr from \'ember-data/attr\';') - .to.contain('export default Model.extend(') - .to.contain('misc: attr()') - .to.contain('skills: attr(\'array\')') - .to.contain('isActive: attr(\'boolean\')') - .to.contain('birthday: attr(\'date\')') - .to.contain('someObject: attr(\'object\')') - .to.contain('age: attr(\'number\')') - .to.contain('name: attr(\'string\')') - .to.contain('customAttr: attr(\'custom-transform\')') - .to.contain('// import { belongsTo, hasMany } from \'ember-data/relationships\';') - .to.not.contain('import { belongsTo } from \'ember-data/relationships\';') - .to.not.contain('import { hasMany } from \'ember-data/relationships\';'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.Model.extend(') + .to.contain('misc: DS.attr()') + .to.contain('skills: DS.attr(\'array\')') + .to.contain('isActive: DS.attr(\'boolean\')') + .to.contain('birthday: DS.attr(\'date\')') + .to.contain('someObject: DS.attr(\'object\')') + .to.contain('age: DS.attr(\'number\')') + .to.contain('name: DS.attr(\'string\')') + .to.contain('customAttr: DS.attr(\'custom-transform\')') expect(_file('tests/unit/models/foo-test.js')) .to.contain('moduleForModel(\'foo\''); @@ -71,14 +63,10 @@ describe('Acceptance: generate and destroy model blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/models/comment.js')) - .to.contain('import Model from \'ember-data/model\';') - .to.contain('import { belongsTo } from \'ember-data/relationships\';') - .to.contain('export default Model.extend(') - .to.contain('post: belongsTo(\'post\')') - .to.contain('author: belongsTo(\'user\')') - .to.contain('// import attr from \'ember-data/attr\';') - .to.contain('// import { hasMany } from \'ember-data/relationships\';') - .to.not.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.Model.extend(') + .to.contain('post: DS.belongsTo(\'post\')') + .to.contain('author: DS.belongsTo(\'user\')') expect(_file('tests/unit/models/comment-test.js')) .to.contain('moduleForModel(\'comment\'') @@ -92,14 +80,10 @@ describe('Acceptance: generate and destroy model blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/models/post.js')) - .to.contain('import Model from \'ember-data/model\';') - .to.contain('import { hasMany } from \'ember-data/relationships\';') - .to.contain('export default Model.extend(') - .to.contain('comments: hasMany(\'comment\')') - .to.contain('otherComments: hasMany(\'comment\')') - .to.contain('// import attr from \'ember-data/attr\';') - .to.contain('// import { belongsTo } from \'ember-data/relationships\';') - .to.not.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.Model.extend(') + .to.contain('comments: DS.hasMany(\'comment\')') + .to.contain('otherComments: DS.hasMany(\'comment\')') expect(_file('tests/unit/models/post-test.js')) .to.contain('moduleForModel(\'post\'') @@ -107,19 +91,6 @@ describe('Acceptance: generate and destroy model blueprints', function() { })); }); - it('model with belongsTo and hasMany has both imports', function() { - var args = ['model', 'post', 'comments:has-many', 'user:belongs-to']; - - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { - expect(_file('app/models/post.js')) - .to.contain('import { belongsTo, hasMany } from \'ember-data/relationships\';') - .to.contain('// import attr from \'ember-data/attr\';') - .to.not.contain('import { belongsTo } from \'ember-data/relationships\';') - .to.not.contain('import { hasMany } from \'ember-data/relationships\';'); - })); - }); - it('model-test', function() { var args = ['model-test', 'foo']; diff --git a/node-tests/blueprints/serializer-test.js b/node-tests/blueprints/serializer-test.js index 8adc60f1745..b7eb757e527 100644 --- a/node-tests/blueprints/serializer-test.js +++ b/node-tests/blueprints/serializer-test.js @@ -19,8 +19,8 @@ describe('Acceptance: generate and destroy serializer blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/serializers/foo.js')) - .to.contain('import JSONAPISerializer from \'ember-data/serializers/json-api\';') - .to.contain('export default JSONAPISerializer.extend('); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.JSONAPISerializer.extend('); expect(_file('tests/unit/serializers/foo-test.js')) .to.contain('moduleForModel(\'foo\''); @@ -70,8 +70,8 @@ describe('Acceptance: generate and destroy serializer blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/serializers/application.js')) - .to.contain('import JSONAPISerializer from \'ember-data/serializers/json-api\';') - .to.contain('export default JSONAPISerializer.extend({'); + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.JSONAPISerializer.extend({'); expect(_file('tests/unit/serializers/application-test.js')) .to.contain('moduleForModel(\'application\''); diff --git a/node-tests/blueprints/transform-test.js b/node-tests/blueprints/transform-test.js index f52814c712e..cebe88093b6 100644 --- a/node-tests/blueprints/transform-test.js +++ b/node-tests/blueprints/transform-test.js @@ -16,8 +16,8 @@ describe('Acceptance: generate and destroy transform blueprints', function() { return emberNew() .then(() => emberGenerateDestroy(args, _file => { expect(_file('app/transforms/foo.js')) - .to.contain('import Transform from \'ember-data/transform\';') - .to.contain('export default Transform.extend(') + .to.contain('import DS from \'ember-data\';') + .to.contain('export default DS.Transform.extend(') .to.contain('deserialize(serialized) {') .to.contain('serialize(deserialized) {');