Created
May 20, 2016 23:52
-
-
Save abuiles/f15539c683e2121a3027b220073569b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * npm install inflected | |
| * find . -type f | xargs perl -pi -e 's/all\(\)\.length/all\(\)\.models\.length/g' | |
| * find . -type f | xargs perl -pi -e 's/all\(\)\.forEach/all\(\)\.models\.forEach/g' | |
| toArray | |
| * $ jscodeshift -t mirage-migrator.js tests/acceptance | |
| */ | |
| var Inflected = require('inflected'); | |
| function directCallToSchema(path) { | |
| return (path.value.type === 'CallExpression' && | |
| path.value.callee.object && | |
| path.value.callee.object.type === 'MemberExpression' && | |
| path.value.callee.object.object.name === 'schema') | |
| }; | |
| function serverSchema(path) { | |
| return (path.value.type === 'CallExpression' && | |
| path.value.callee.object && | |
| path.value.callee.object.type === 'MemberExpression' && | |
| path.value.callee.object.object.object && | |
| path.value.callee.object.object.object.name === 'server' | |
| ); | |
| } | |
| module.exports = function(fileInfo, api) { | |
| var j = api.jscodeshift; | |
| var root = j(fileInfo.source); | |
| root | |
| .find(j.CallExpression) | |
| .forEach(path => { | |
| if (directCallToSchema(path)) { | |
| // | |
| // Pluralize schema model classes | |
| // | |
| path.value.callee.object.property.name = Inflected.pluralize(path.value.callee.object.property.name); | |
| if (callsLength(path)) { | |
| console.log('length'); | |
| } | |
| } | |
| if (serverSchema(path)) { | |
| // | |
| // Pluralize schema model classes | |
| // | |
| path.value.callee.object.property.name = Inflected.pluralize(path.value.callee.object.property.name); | |
| } | |
| }); | |
| return root.toSource(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment