|
| 1 | +English | [中文](./docs/README_CN.md) |
| 2 | + |
| 3 | +## coderfly |
| 4 | + |
| 5 | +Find function-level association impacts of code changes. |
| 6 | + |
| 7 | +## Background |
| 8 | + |
| 9 | +When you modify the code of a large project, it may not be very clear whether it will have an impact on the functionality.Our self-test may not be enough, and we need to search a lot of related code to determine the impact of the change. Wouldn't it save a lot of time and improve the quality of self-testing if there was a tool that could identify your changes and automatically find out what you affected by the change? That's the problem this project is trying to solve. |
| 10 | + |
| 11 | +It can analyze the changes of the function by the changes of the file. |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +Then we analyze the impact of this function from the whole project. From the picture blow(a part of the result), we can see that this function is called by `jumpToAppStore` and affects the click event bound to a dom node of `header.vue`. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +You can check [how it works](#how-it-works) from here. |
| 20 | + |
| 21 | +## Install |
| 22 | + |
| 23 | +This project is still under development and has not been published to the npm yet. So you can use the built files for now. |
| 24 | + |
| 25 | +- `clone` this project |
| 26 | +- `yarn install` |
| 27 | +- `yarn build` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +**Using the API** |
| 32 | + |
| 33 | +see the [API](#api) or [Example](#example). |
| 34 | + |
| 35 | +**Using the command line** |
| 36 | + |
| 37 | +> Not yet finished |
| 38 | +
|
| 39 | +- [ ] Using command line: `cci check <folder path>` |
| 40 | + |
| 41 | +## API |
| 42 | + |
| 43 | +### diff |
| 44 | + |
| 45 | +Get the changes of the function by the changes of the file. |
| 46 | + |
| 47 | +If you changed `test/a.js`, you can get the following result by diff. |
| 48 | + |
| 49 | +```js |
| 50 | +{ |
| 51 | + file: 'test/a.js', |
| 52 | + changed: ['getSum'], |
| 53 | + added: [], |
| 54 | + deleted: ['getData'], |
| 55 | + total: ['getSum', 'getData'] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### getAllFiles |
| 60 | + |
| 61 | +Get all files from source code, filter by default for non-`.vue`、`.js`、`.ts` files. |
| 62 | + |
| 63 | +**Params** |
| 64 | + |
| 65 | +- folderPath: string. It's source code folder path. |
| 66 | + |
| 67 | +### getFuncTree |
| 68 | + |
| 69 | +Analyze the project and build a 「file tree」. |
| 70 | + |
| 71 | +**Params** |
| 72 | + |
| 73 | +- files: string[]. All the files from folder path |
| 74 | +- options: Options |
| 75 | + |
| 76 | +```ts |
| 77 | +interface Options { |
| 78 | + alias?: { |
| 79 | + [aliasName: string]: string // alias name and path |
| 80 | + }; |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### getImpacts** |
| 85 | + |
| 86 | +Get the impact of changes. |
| 87 | + |
| 88 | +**Params** |
| 89 | + |
| 90 | +- treeData: FileInfoTree. It's file tree. |
| 91 | +- funcInfo: ImpactReason. It's the entry function that we get by diff. |
| 92 | + |
| 93 | +```ts |
| 94 | +interface ImpactReason { |
| 95 | + filePath: string; |
| 96 | + name: string; |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Example |
| 101 | + |
| 102 | +```js |
| 103 | +import { diff, getAllFiles, getFuncTree, getImpacts } from "coderfly"; |
| 104 | + |
| 105 | +// diff |
| 106 | +const functionDiffInfo = diff(); |
| 107 | + |
| 108 | +// get all files |
| 109 | +const files = getAllFiles(path.resolve(process.cwd(), targetDir)); |
| 110 | + |
| 111 | +// build file tree |
| 112 | +const tree = getFuncTree(files, { |
| 113 | + alias: { |
| 114 | + src: path.resolve(process.cwd(), './demo/vue') |
| 115 | + } |
| 116 | +}); |
| 117 | + |
| 118 | +// get impacts |
| 119 | +// here is just a example, in the real word the second argument needs constructed using the result of diff() |
| 120 | +let impacts = getImpacts(tree, { |
| 121 | + filePath: 'src/utils/a.js', |
| 122 | + name: 'getSum' |
| 123 | +}); |
| 124 | + |
| 125 | +console.log(impacts); |
| 126 | +``` |
| 127 | + |
| 128 | +## Support |
| 129 | + |
| 130 | +- [x] JavaScript |
| 131 | +- [x] Vue2 |
| 132 | +- [ ] Vue3 |
| 133 | +- [ ] TypeScript |
| 134 | + |
| 135 | +## how it works |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +## License |
| 140 | + |
| 141 | +MIT License |
0 commit comments