1+ import path from 'path' ;
2+ import fs from 'fs' ;
13import { diff } from './utils/function_change/index.js' ;
2- import { getAllFiles , getFuncTree } from './utils/handle_file_utils.js' ;
4+ import { confirmFolderExist , getAllFiles , getFuncTree } from './utils/handle_file_utils.js' ;
35import { getImpacts , findWhoCallMe } from './impact.js' ;
46import { getTemplateInfo } from './utils/parse_template_ast.js' ;
7+ import { CONFIG_FILENAME , REPORT_FILE } from './const.js' ;
8+ import { lookFileOrFolderUp } from './utils/handle_config.js' ;
9+ import { ImpactReason } from './type.js' ;
10+
11+ async function coderfly ( srcPath : string ) {
12+ let alias = { } ;
13+ const configFolder = lookFileOrFolderUp ( CONFIG_FILENAME , path . resolve ( process . cwd ( ) , srcPath ) ) ;
14+
15+ if ( configFolder ) {
16+ const configFile = path . resolve ( configFolder , CONFIG_FILENAME ) ;
17+
18+ try {
19+ alias = require ( configFile ) ;
20+ } catch ( error ) {
21+ // do nothing
22+ }
23+ }
24+
25+ confirmFolderExist ( ) ;
26+
27+ const functionDiffInfo = diff ( ) ;
28+
29+ const files = getAllFiles ( path . resolve ( process . cwd ( ) , srcPath ) ) ;
30+
31+ const tree = getFuncTree ( files , {
32+ alias
33+ } ) ;
34+
35+ const allFunctions : ImpactReason [ ] = [ ] ;
36+ functionDiffInfo . forEach ( item => {
37+ const file = path . resolve ( process . cwd ( ) , item . file ) ;
38+
39+ item . total . forEach ( fn => {
40+ allFunctions . push ( {
41+ filePath : file ,
42+ name : fn ,
43+ paths : [ [ fn , file ] ]
44+ } ) ;
45+ } ) ;
46+ } ) ;
47+
48+ const impactReport : any [ ] = [ ] ;
49+
50+ allFunctions . forEach ( item => {
51+ const impact = getImpacts ( tree , item ) ;
52+ impactReport . push ( impact ) ;
53+ } ) ;
54+
55+ fs . writeFileSync ( REPORT_FILE , JSON . stringify ( impactReport , null , 4 ) ) ;
56+ }
557
658export {
759 getAllFiles ,
@@ -10,4 +62,5 @@ export {
1062 getImpacts ,
1163 findWhoCallMe ,
1264 diff ,
65+ coderfly ,
1366} ;
0 commit comments