Skip to content

Commit dfe93e0

Browse files
authored
Merge pull request #19 from ssutar/type_option
Add type as option which will match the path
2 parents 4f860d4 + 9bd8f10 commit dfe93e0

11 files changed

Lines changed: 1339 additions & 1286 deletions

File tree

package-lock.json

Lines changed: 1283 additions & 1282 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"codemod-cli"
1111
],
1212
"dependencies": {
13-
"codemod-cli": "ssutar/codemod-cli"
13+
"codemod-cli": "ssutar/codemod-cli",
14+
"minimatch": "^3.0.4"
1415
},
1516
"devDependencies": {
1617
"jest": "^23.1.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Program comments
3+
*/
4+
const Foo = Test.extend({});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "components"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Program comments
3+
*/
4+
const Foo = Test.extend({});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Program comments
3+
*/
4+
const Foo = Test.extend({});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "services"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Program comments
3+
*/
4+
class Foo extends Test {}

transforms/ember-object/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
const { getOptions } = require("codemod-cli");
12
const { replaceEmberObjectExpressions } = require("../helpers/parse-helper");
23

34
module.exports = function transformer(file, api, options) {
45
const j = api.jscodeshift;
56
const root = j(file.source);
67

7-
replaceEmberObjectExpressions(j, root, file.path, options);
8+
replaceEmberObjectExpressions(
9+
j,
10+
root,
11+
file.path,
12+
Object.assign({}, options, getOptions())
13+
);
814

915
return root.toSource();
1016
};

transforms/helpers/parse-helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
startsWithUpperCaseLetter,
88
DECORATOR_PATHS
99
} = require("./util");
10-
const { hasValidProps } = require("./validation-helper");
10+
const { hasValidProps, isFileOfType } = require("./validation-helper");
1111
const {
1212
withComments,
1313
createClass,
@@ -350,6 +350,9 @@ function parseEmberObjectCallExpression(eoCallExpression) {
350350
* @param {Object} options
351351
*/
352352
function replaceEmberObjectExpressions(j, root, filePath, options = {}) {
353+
if (options.type && !isFileOfType(filePath, options.type)) {
354+
return;
355+
}
353356
// Parse the import statements
354357
const importedDecoratedProps = getImportedDecoratedProps(j, root);
355358
let transformed = false;

0 commit comments

Comments
 (0)