11import path from 'path' ;
22import semver from 'semver' ;
33import chalk from 'chalk' ;
4- import { PluginManager } from 'live-plugin-manager' ;
4+ import findUp from 'find-up' ;
5+ import inquirer from 'inquirer' ;
56
7+ import { fetchConfigAtPath } from '@codeshift/fetcher' ;
8+ import { PluginManager } from 'live-plugin-manager' ;
69// @ts -ignore Run transform(s) on path https://github.com/facebook/jscodeshift/issues/398
710import * as jscodeshift from 'jscodeshift/src/Runner' ;
811
912import { Flags } from './types' ;
1013import { InvalidUserInputError } from './errors' ;
1114import { fetchPackageConfig } from './fetch-package' ;
15+ import { getTransformPrompt } from './prompt' ;
1216
1317export default async function main ( paths : string [ ] , flags : Flags ) {
1418 const packageManager = new PluginManager ( {
@@ -18,9 +22,32 @@ export default async function main(paths: string[], flags: Flags) {
1822 let transforms : string [ ] = [ ] ;
1923
2024 if ( ! flags . transform && ! flags . packages ) {
21- throw new InvalidUserInputError (
22- 'No transform provided, please specify a transform with either the --transform or --packages flags' ,
25+ console . log (
26+ chalk . green (
27+ 'No transforms specified, attempting to find local codeshift.config file' ,
28+ ) ,
2329 ) ;
30+
31+ const configFilePath = await findUp ( [
32+ 'codeshift.config.js' ,
33+ 'codeshift.config.ts' ,
34+ 'codeshift.config.tsx' ,
35+ ] ) ;
36+
37+ if ( ! configFilePath ) {
38+ throw new InvalidUserInputError (
39+ 'No transform provided, please specify a transform with either the --transform or --packages flags' ,
40+ ) ;
41+ }
42+
43+ console . log (
44+ chalk . green ( 'Found local codeshift.config file at:' ) ,
45+ configFilePath ,
46+ ) ;
47+
48+ const config = await fetchConfigAtPath ( configFilePath ) ;
49+ const answers = await inquirer . prompt ( [ getTransformPrompt ( config ) ] ) ;
50+ transforms . push ( answers . transform ) ;
2451 }
2552
2653 if ( paths . length === 0 ) {
0 commit comments