Skip to content

Commit 353bec8

Browse files
committed
feat: remove match vue version
1 parent c037b32 commit 353bec8

File tree

14 files changed

+11455
-272
lines changed

14 files changed

+11455
-272
lines changed

README.md

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You can also write configuration file named `.coderflyrc.js`, mainly to simplify
4848
// .coderflyrc.js
4949
const path = require('path');
5050
module.exports = {
51-
'src': path.resolve(process.cwd(), 'test'),
51+
'src': path.resolve(__dirname, 'test'),
5252
// ...
5353
}
5454
```
@@ -63,126 +63,27 @@ see the [API](#api) or [Example](#example).
6363

6464
### coderfly
6565

66-
The API for the complete process is included, use this for a one-step process if you don't need control the process yourself.
66+
The API for the complete process is included, use this for a one-step process.
6767

6868
**Params**
6969

7070
- srcPath: string. It's source code folder path
71-
### diff
72-
73-
Get the changes of the function by the changes of the file.
74-
75-
If you changed `test/a.js`, you can get the following result by diff.
76-
77-
```js
78-
{
79-
file: 'test/a.js',
80-
changed: ['getSum'],
81-
added: [],
82-
deleted: ['getData'],
83-
total: ['getSum', 'getData']
84-
}
85-
```
86-
87-
### getAllFiles
88-
89-
Get all files from source code, filter by default for non-`.vue``.js``.ts` files.
90-
91-
**Params**
92-
93-
- folderPath: string. It's source code folder path.
94-
95-
### getFuncTree
96-
97-
Analyze the project and build a 「file tree」.
98-
99-
**Params**
100-
101-
- files: string[]. All the files from folder path
102-
- options: Options
103-
104-
```ts
105-
interface Options {
106-
alias?: {
107-
[aliasName: string]: string // alias name and path
108-
};
109-
}
110-
```
111-
112-
### getImpacts**
113-
114-
Get the impact of changes.
115-
116-
**Params**
117-
118-
- treeData: FileInfoTree. It's file tree.
119-
- funcInfo: ImpactReason. It's the entry function that we get by diff.
120-
121-
```ts
122-
interface ImpactReason {
123-
filePath: string;
124-
name: string;
125-
}
126-
```
127-
128-
### matchVueVersion
129-
130-
Since the use of `vue-template-compiler` must be consistent with the `vue` version, otherwise an error will be reported, you must keep them both consistent before using `coderfly`. You can either manually install the corresponding version of `vue-template-compiler` in your project yourself, or you can use the API to do this in your code. Note that this operation needs to be called before using the other APIs.
13171

13272
## Example
13373

13474
**Easy to use**
13575

13676
```js
137-
// if necessary
138-
const { matchVueVersion } = require('coderfly/dist/match_version');
139-
140-
matchVueVersion();
141-
14277
const { coderfly } = require('coderfly');
14378

14479
coderfly('./src');
14580
```
146-
147-
148-
**If you want you control the process yourself**
149-
```js
150-
// if necessary
151-
const { matchVueVersion } = require('coderfly/dist/match_version');
152-
153-
matchVueVersion();
154-
155-
const { diff, getAllFiles, getFuncTree, getImpacts } = require('coderfly');
156-
157-
// diff
158-
const functionDiffInfo = diff();
159-
160-
// get all files
161-
const files = getAllFiles(path.resolve(process.cwd(), targetDir));
162-
163-
// build file tree
164-
const tree = getFuncTree(files, {
165-
alias: {
166-
src: path.resolve(process.cwd(), './demo/vue')
167-
}
168-
});
169-
170-
// get impacts
171-
// here is just a example, in the real word the second argument needs constructed using the result of diff()
172-
let impacts = getImpacts(tree, {
173-
filePath: 'src/utils/a.js',
174-
name: 'getSum'
175-
});
176-
177-
console.log(impacts);
178-
```
179-
18081
## Support
18182

18283
- [x] JavaScript
18384
- [x] Vue2
18485
- [x] TypeScript
185-
- [ ] Vue3
86+
- [x] Vue3
18687

18788
## how it works
18889

copy_files.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
const dest = path.resolve(__dirname, 'dist/coderfly_vue_compiler');
5+
const compilerFolder = path.resolve(__dirname, 'src/coderfly_vue_compiler');
6+
7+
function copyCompiler () {
8+
if (!fs.existsSync(dest)) {
9+
fs.mkdirSync(dest);
10+
}
11+
12+
const files = fs.readdirSync(compilerFolder);
13+
14+
for (const file of files) {
15+
if (path.extname(file) !== '.js') continue;
16+
const ctx = fs.readFileSync(path.join(compilerFolder, file), 'utf8');
17+
fs.writeFileSync(path.join(dest, file), ctx);
18+
}
19+
}
20+
21+
copyCompiler();

docs/README_CN.md

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -67,112 +67,22 @@ API集大成者,如果不需要自己字定义过程,用这个一步到位
6767

6868
**Params**
6969

70-
- srcPath: string. It's source code folder path
71-
72-
**Params**
73-
7470
- srcPath: string,源码文件夹路径
75-
### diff
76-
77-
根据本地文件变动,输出函数修改情况。
78-
79-
假如修改了 `test/a.js`,通过 diff 可以获得下面的结果
80-
81-
```js
82-
{
83-
file: 'test/a.js',
84-
changed: ['getSum'],
85-
added: [],
86-
deleted: ['getData'],
87-
total: ['getSum', 'getData']
88-
}
89-
```
90-
91-
### getAllFiles
92-
93-
获取项目所有文件,默认过滤非 `.vue``.js``.ts` 文件
94-
95-
**Params**
96-
97-
- folderPath: string,源码文件夹路径
98-
99-
### getFuncTree
100-
101-
分析项目文件,构建「文件树」
102-
103-
**Params**
104-
105-
- files: string[], 所有源码文件
106-
- options: Options, 配置
107-
108-
```ts
109-
interface Options {
110-
alias?: {
111-
[aliasName: string]: string // alias name and path
112-
};
113-
}
114-
```
115-
116-
### getImpacts
117-
118-
分析改动影响
119-
120-
**Params**
121-
122-
- treeData: FileInfoTree, 文件树数据
123-
- funcInfo: ImpactReason, 被搜索的入口函数
124-
125-
```ts
126-
interface ImpactReason {
127-
filePath: string;
128-
name: string;
129-
}
130-
```
131-
132-
### matchVueVersion
133-
134-
由于 `vue-template-compiler` 的使用必须保持和 `vue` 版本一致,否则会报错,因此在使用 `coderfly` 前必须将二者保持一致。你可以自己手动在项目中安装对应的 `vue-template-compiler` 版本,也可以使用该 API 在代码中完成此操作。注意此操作需要在使用其他 API 之前调用
135-
13671

13772
## 示例
13873

13974
```js
140-
// 如果有必要
141-
const { matchVueVersion } = require('coderfly/dist/match_version');
142-
143-
matchVueVersion();
144-
145-
const { diff, getAllFiles, getFuncTree, getImpacts } = require('coderfly');
146-
147-
// diff
148-
const functionDiffInfo = diff();
149-
150-
// 获取所有文件信息
151-
const files = getAllFiles(path.resolve(process.cwd(), targetDir));
152-
153-
// 构建文件树
154-
const tree = getFuncTree(files, {
155-
alias: {
156-
src: path.resolve(process.cwd(), './demo/vue')
157-
}
158-
});
159-
160-
// 输出改动影响
161-
// 这里使用一个示例来说明,真实情况下需要使用 diff() 的返回结果来构造 getImpacts 的第二个参数
162-
let impacts = getImpacts(tree, {
163-
filePath: 'src/utils/a.js',
164-
name: 'getSum'
165-
});
75+
const { coderfly } = require('coderfly');
16676

167-
console.log(impacts);
77+
coderfly('./src');
16878
```
16979

17080
## 支持
17181

17282
- [x] JavaScript
17383
- [x] Vue2
17484
- [x] TypeScript
175-
- [ ] Vue3
85+
- [x] Vue3
17686

17787
## 如何工作的
17888

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"url": "https://github.com/CocaColf/coderfly"
1818
},
1919
"scripts": {
20-
"build": "rm -rf dist/ && tsc && find ./dist -type f|xargs dos2unix",
20+
"build": "rm -rf dist/ && tsc && node ./copy_files.js && find ./dist -type f|xargs dos2unix",
2121
"lint": "eslint . --ext .ts",
2222
"lint:fix": "eslint . --ext .ts --fix"
2323
},
@@ -35,15 +35,14 @@
3535
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
3636
"@babel/preset-env": "^7.16.11",
3737
"@babel/preset-typescript": "^7.16.7",
38-
"@types/lodash-es": "^4.17.6",
3938
"commander": "^9.1.0",
39+
"de-indent": "^1.0.2",
4040
"enhanced-resolve": "^5.9.2",
4141
"execa": "5.1.1",
42-
"lodash-es": "^4.17.21",
42+
"he": "^1.2.0",
4343
"n-readlines": "^1.0.1",
4444
"nanoid": "^3.3.4",
4545
"ora": "5.4.1",
46-
"recast": "^0.20.5",
47-
"vue-template-compiler": "^2.6.14"
46+
"recast": "^0.20.5"
4847
}
4948
}

0 commit comments

Comments
 (0)