22
33const DEFAULT_JS_EXTENSIONS = 'js,ts' ;
44
5- function getTransformPath ( binRoot , transformName ) {
6- const path = require ( 'path' ) ;
7-
8- return path . join ( binRoot , '..' , 'transforms' , transformName , 'index.js' ) ;
9- }
10-
11- async function runJsTransform ( binRoot , transformName , args , extensions = DEFAULT_JS_EXTENSIONS ) {
5+ async function runJsTransform ( root , transformName , args , extensions = DEFAULT_JS_EXTENSIONS ) {
126 const globby = require ( 'globby' ) ;
137 const execa = require ( 'execa' ) ;
148 const chalk = require ( 'chalk' ) ;
159 const path = require ( 'path' ) ;
1610 const { parseTransformArgs } = require ( './options-support' ) ;
11+ const { getTransformPath } = require ( './transform-support' ) ;
1712
1813 let { paths, options } = parseTransformArgs ( args ) ;
1914
2015 try {
2116 let foundPaths = await globby ( paths , {
2217 expandDirectories : { extensions : extensions . split ( ',' ) } ,
2318 } ) ;
24- let transformPath = getTransformPath ( binRoot , transformName ) ;
19+ let transformPath = getTransformPath ( root , transformName ) ;
2520
2621 let jscodeshiftPkg = require ( 'jscodeshift/package' ) ;
2722 let jscodeshiftPath = path . dirname ( require . resolve ( 'jscodeshift/package' ) ) ;
@@ -43,15 +38,16 @@ async function runJsTransform(binRoot, transformName, args, extensions = DEFAULT
4338 }
4439}
4540
46- async function runTemplateTransform ( binRoot , transformName , args ) {
41+ async function runTemplateTransform ( root , transformName , args ) {
4742 const execa = require ( 'execa' ) ;
4843 const chalk = require ( 'chalk' ) ;
4944 const { parseTransformArgs } = require ( './options-support' ) ;
45+ const { getTransformPath } = require ( './transform-support' ) ;
5046
5147 let { paths, options } = parseTransformArgs ( args ) ;
5248
5349 try {
54- let transformPath = getTransformPath ( binRoot , transformName ) ;
50+ let transformPath = getTransformPath ( root , transformName ) ;
5551 let binOptions = [ '-t' , transformPath , ...paths ] ;
5652
5753 return execa ( 'ember-template-recast' , binOptions , {
@@ -70,16 +66,18 @@ async function runTemplateTransform(binRoot, transformName, args) {
7066}
7167
7268async function runTransform ( binRoot , transformName , args , extensions ) {
73- const { getTransformType } = require ( './transform-support' ) ;
69+ const { getTransformType, getTransformPath } = require ( './transform-support' ) ;
70+ const path = require ( 'path' ) ;
7471
75- let transformPath = getTransformPath ( binRoot , transformName ) ;
72+ let root = path . join ( binRoot , '..' ) ;
73+ let transformPath = getTransformPath ( root , transformName ) ;
7674 let type = getTransformType ( transformPath ) ;
7775
7876 switch ( type ) {
7977 case 'js' :
80- return runJsTransform ( binRoot , transformName , args , extensions ) ;
78+ return runJsTransform ( root , transformName , args , extensions ) ;
8179 case 'hbs' :
82- return runTemplateTransform ( binRoot , transformName , args ) ;
80+ return runTemplateTransform ( root , transformName , args ) ;
8381 default :
8482 throw new Error ( `Unknown type passed to runTransform: "${ type } "` ) ;
8583 }
0 commit comments