-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add remove-ember-data-is-new-serializer-api command
This adds a handy command for removing all the `isNewSerializerAPI` properties in serializers after you've finished upgrading.
- Loading branch information
Stanley Stuart
committed
Apr 21, 2016
1 parent
eb1aa83
commit 6afc08a
Showing
8 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var Watson = require('../../index'); | ||
|
||
module.exports = { | ||
name: 'watson:remove-ember-data-is-new-serializer-api', | ||
description: 'Removes `isNewSerializerAPI` from serialiers', | ||
works: ['insideProject', 'insideAddon'], | ||
anonymousOptions: [ | ||
'<path>' | ||
], | ||
run: function(commandOptions, rawArgs) { | ||
var path = rawArgs[0] || 'app'; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var parseAST = require('../helpers/parse-ast'); | ||
var recast = require('recast'); | ||
|
||
module.exports = function(source) { | ||
var ast = parseAST(source); | ||
|
||
recast.visit(ast, { | ||
|
||
visitCallExpression: function(path) { | ||
var callee = path.node.callee; | ||
if (callee.type === 'MemberExpression' && | ||
callee.property && | ||
callee.property.name === 'extend' && | ||
callee.object && | ||
callee.object.property && | ||
/serializer/i.test(callee.object.property.name)) { | ||
this.traverse(path); | ||
return; | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
visitProperty: function(path) { | ||
if (path.node.key.name === 'isNewSerializerAPI') { | ||
path.prune(); | ||
} | ||
return false; | ||
} | ||
}); | ||
|
||
return recast.print(ast, { tabWidth: 2, quote: 'single' }).code; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/fixtures/remove-ember-data-is-new-serializer-api/new/serializer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import DS from 'ember-data'; | ||
|
||
export default DS.RESTSerializer.extend({}); |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/remove-ember-data-is-new-serializer-api/old/serializer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import DS from 'ember-data'; | ||
|
||
export default DS.RESTSerializer.extend({ | ||
isNewSerializerAPI: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
var Watson = require('../index.js'); | ||
var fs = require('fs'); | ||
var astEquality = require('./helpers/ast-equality'); | ||
var recast = require('recast'); | ||
|
||
|
||
describe('ember data isNewSerializerAPI', function(){ | ||
var baseDir = './tests/fixtures/remove-ember-data-is-new-serializer-api'; | ||
var watson; | ||
|
||
beforeEach(function(){ | ||
watson = new Watson(); | ||
}); | ||
|
||
describe('removing isNewSerializerAPI literals', function() { | ||
|
||
it('removes the isNewSerializerAPI directive', function() { | ||
var source = fs.readFileSync(baseDir + '/old/serializer.js'); | ||
var newSource = watson._removeEmberDataIsNewSerializerAPI(source); | ||
var expectedNewSource = fs.readFileSync(baseDir + '/new/serializer.js'); | ||
|
||
astEquality(newSource, expectedNewSource); | ||
}); | ||
}); | ||
}); |