agmd 0.3.15 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +215 -0
- package/README.EN.md +164 -175
- package/README.md +374 -71
- package/agmd.js +55 -0
- package/bin/agmd-linux-arm64 +0 -0
- package/bin/agmd-linux-x64 +0 -0
- package/bin/agmd-windows-x64.exe +0 -0
- package/install.js +59 -0
- package/package.json +46 -79
- package/es6/package.json +0 -79
- package/es6/script/cli/handle.js +0 -20
- package/es6/script/cli/handle.js.map +0 -1
- package/es6/script/cli/index.js +0 -23
- package/es6/script/cli/index.js.map +0 -1
- package/es6/script/help/index.js +0 -24
- package/es6/script/help/index.js.map +0 -1
- package/es6/src/bin.js +0 -7
- package/es6/src/bin.js.map +0 -1
- package/es6/src/commands/agmd.js +0 -24
- package/es6/src/commands/agmd.js.map +0 -1
- package/es6/src/commands/change-path.js +0 -119
- package/es6/src/commands/change-path.js.map +0 -1
- package/es6/src/commands/command-actions.js +0 -101
- package/es6/src/commands/command-actions.js.map +0 -1
- package/es6/src/commands/command-handler.js +0 -117
- package/es6/src/commands/command-handler.js.map +0 -1
- package/es6/src/commands/get-file.js +0 -162
- package/es6/src/commands/get-file.js.map +0 -1
- package/es6/src/commands/get-router.js +0 -107
- package/es6/src/commands/get-router.js.map +0 -1
- package/es6/src/commands/mark-file.js +0 -138
- package/es6/src/commands/mark-file.js.map +0 -1
- package/es6/src/commands/mark-write-file.js +0 -53
- package/es6/src/commands/mark-write-file.js.map +0 -1
- package/es6/src/commands/rename-path.js +0 -187
- package/es6/src/commands/rename-path.js.map +0 -1
- package/es6/src/commands/wirte-md.js +0 -82
- package/es6/src/commands/wirte-md.js.map +0 -1
- package/es6/src/index.js +0 -4
- package/es6/src/index.js.map +0 -1
- package/es6/src/shared/constant.js +0 -5
- package/es6/src/shared/constant.js.map +0 -1
- package/es6/src/types.js +0 -2
- package/es6/src/types.js.map +0 -1
- package/es6/src/utils/router-utils.js +0 -37
- package/es6/src/utils/router-utils.js.map +0 -1
- package/lib/package.json +0 -79
- package/lib/script/cli/handle.js +0 -25
- package/lib/script/cli/handle.js.map +0 -1
- package/lib/script/cli/index.js +0 -28
- package/lib/script/cli/index.js.map +0 -1
- package/lib/script/help/index.js +0 -26
- package/lib/script/help/index.js.map +0 -1
- package/lib/src/bin.js +0 -9
- package/lib/src/bin.js.map +0 -1
- package/lib/src/commands/agmd.js +0 -29
- package/lib/src/commands/agmd.js.map +0 -1
- package/lib/src/commands/change-path.js +0 -132
- package/lib/src/commands/change-path.js.map +0 -1
- package/lib/src/commands/command-actions.js +0 -117
- package/lib/src/commands/command-actions.js.map +0 -1
- package/lib/src/commands/command-handler.js +0 -125
- package/lib/src/commands/command-handler.js.map +0 -1
- package/lib/src/commands/get-file.js +0 -173
- package/lib/src/commands/get-file.js.map +0 -1
- package/lib/src/commands/get-router.js +0 -140
- package/lib/src/commands/get-router.js.map +0 -1
- package/lib/src/commands/mark-file.js +0 -151
- package/lib/src/commands/mark-file.js.map +0 -1
- package/lib/src/commands/mark-write-file.js +0 -61
- package/lib/src/commands/mark-write-file.js.map +0 -1
- package/lib/src/commands/rename-path.js +0 -202
- package/lib/src/commands/rename-path.js.map +0 -1
- package/lib/src/commands/wirte-md.js +0 -92
- package/lib/src/commands/wirte-md.js.map +0 -1
- package/lib/src/index.js +0 -8
- package/lib/src/index.js.map +0 -1
- package/lib/src/shared/constant.js +0 -8
- package/lib/src/shared/constant.js.map +0 -1
- package/lib/src/types.js +0 -3
- package/lib/src/types.js.map +0 -1
- package/lib/src/utils/router-utils.js +0 -43
- package/lib/src/utils/router-utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,71 +1,374 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
[]( https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667)
|
|
6
|
-
[]( https://github.com/kakajun/auto-generate-md/actions/workflows/test.yml)
|
|
7
|
-
[]( https://app.circleci.com/pipelines/github/kakajun/auto-generate-md)
|
|
8
|
-
|
|
9
|
-
简体中文 | [English](https://github.com/kakajun/auto-generate-md/blob/master/README.EN.md)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
# agmd(auto generate md)
|
|
2
|
+
|
|
3
|
+
> 这是一个前端代码管理的辅助工具,在任何需要生成文档的,文件夹下的控制台中输入`agmd`, 就能自动生成目录 md 说明(部分功能需要在src目录下), 同时能够统计分析当前工程的各类型文件总量和代码总量,还提供一些实用的工具,具体看下面功能特征
|
|
4
|
+
|
|
5
|
+
[]( https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667)
|
|
6
|
+
[]( https://github.com/kakajun/auto-generate-md/actions/workflows/test.yml)
|
|
7
|
+
[]( https://app.circleci.com/pipelines/github/kakajun/auto-generate-md)
|
|
8
|
+
|
|
9
|
+
简体中文 | [English](https://github.com/kakajun/auto-generate-md/blob/master/README.EN.md)
|
|
10
|
+
|
|
11
|
+
## 🚀 功能特性
|
|
12
|
+
|
|
13
|
+
😍 一键统计工程的文件数和代码总量
|
|
14
|
+
|
|
15
|
+
📦 一键补充缺省后缀名 .js .vue 这样子能方便vscode编辑器点击直接跳转查看代码
|
|
16
|
+
|
|
17
|
+
🚘 一键更改文件或者文件名,驼峰命名为kable-case
|
|
18
|
+
|
|
19
|
+
⛵ 把工程所有引用更改绝对路径为相对路径(方便点击下钻查看文件)
|
|
20
|
+
🔧 支持将相对路径统一转换为基于 '@' 别名的绝对路径
|
|
21
|
+
|
|
22
|
+
♨️ 把工程按路由标记分类(对拆分工程很重要)
|
|
23
|
+
|
|
24
|
+
☝️ 把工程按分类对拆分工程(自动拆分的错误可控, 手动拆分会有各种问题)
|
|
25
|
+
|
|
26
|
+
✈️ 全程界面命令选择操作, 不用记命令
|
|
27
|
+
|
|
28
|
+
😍 得到一个包含整个工程结构树的json
|
|
29
|
+
|
|
30
|
+
💡 一键拿到文件和文件夹名字, 并生成JSON输出
|
|
31
|
+
|
|
32
|
+
🔥 **v2 版本使用 Rust 重写,性能提升 10 倍以上,零 Node.js 依赖**
|
|
33
|
+
|
|
34
|
+
## 设计初衷
|
|
35
|
+
|
|
36
|
+
1. 统计工程量, 看看咱们工程究竟有多少个文件, 多少代码量
|
|
37
|
+
2. 如果仅仅只是为了重命文件和文件夹, 那么其实这个库没有存在的必要, 因为我们可以自己随手写个node代码, 就全部重命名了, 问题的关键是, 我们内部工程有很多依赖, 像这样子 `import { replaceName } from '../src/commands/rename-path'` , 我们需要一个工具, 能够帮我们自动生成目录, 快速定位到文件,也进行重命名来减少重复劳动, 提升效率.
|
|
38
|
+
3. 如果想把工程1分2做成按路由拆分的微服务, 那么需要知道哪些文件被工程1用到了, 哪些文件被工程2用到了, 那么就需要一个工具, 来进行标记,甚至清除没有被标记的文件.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### 操作界面
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
### 案例
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
### 使用方法
|
|
49
|
+
|
|
50
|
+
**v2 版本基于 Rust 构建,通过 npm 分发预编译二进制,无需本地 Rust 环境。**
|
|
51
|
+
|
|
52
|
+
1. 全局安装
|
|
53
|
+
> npm i agmd -g
|
|
54
|
+
|
|
55
|
+
安装完成后,在需要记录 md 的文件夹下面输入`agmd`,会自动生成相对路径下的文件夹和文件的名字,如果文件里面还有在头部写注释的话,那么会一并带过来自动生成 md 文件。生成的文件名为`readme-md.md`, 路径为刚刚输入命名的路径同级别下,对于工程比较大的开发来说,这个脚本或许会帮你省下些许时间。
|
|
56
|
+
|
|
57
|
+
2. 作为依赖安装
|
|
58
|
+
> npm i agmd -D
|
|
59
|
+
|
|
60
|
+
在package.json的scripts 中配置 agmd: npx agmd --ignore lib,node_modules,dist --include .js,.ts,.vue [--dry-run] [--silent] 可以在每次启动或打包时,带上命令行来自动更新文档
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
example,是我为演示准备的一些文件,并没有其他用
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
3. 命令说明
|
|
67
|
+
- 帮助
|
|
68
|
+
- 生成结构树文档
|
|
69
|
+
- 修改为相对路径
|
|
70
|
+
- 修改为绝对路径
|
|
71
|
+
- 补全文件后缀
|
|
72
|
+
- 统一命名文件夹为 Kebab-Case
|
|
73
|
+
- 统一命名文件为 Kebab-Case
|
|
74
|
+
- 记录节点 JSON
|
|
75
|
+
- 给需要分类的都打上标记
|
|
76
|
+
- 删除标记
|
|
77
|
+
- 分类
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
4. 代码结构说明
|
|
81
|
+
```
|
|
82
|
+
├── src/
|
|
83
|
+
│ ├── main.rs # CLI 入口:解析参数 + 交互菜单
|
|
84
|
+
│ ├── lib.rs # 库入口:公开 API
|
|
85
|
+
│ ├── cli.rs # clap 命令行参数定义
|
|
86
|
+
│ ├── types.rs # 核心数据结构
|
|
87
|
+
│ ├── commands.rs # 高层动作分发(对应菜单每一项)
|
|
88
|
+
│ ├── get_file.rs # 递归扫描、提取注释/大小/import
|
|
89
|
+
│ ├── write_md.rs # 生成 Markdown、统计输出
|
|
90
|
+
│ ├── change_path.rs # 批量重写 import 路径
|
|
91
|
+
│ ├── rename_path.rs # 批量重命名文件/文件夹
|
|
92
|
+
│ ├── get_router.rs # 解析路由配置
|
|
93
|
+
│ ├── mark_file.rs # 按路由给文件打标记
|
|
94
|
+
│ ├── mark_write_file.rs # 按标记分类复制文件
|
|
95
|
+
│ └── bin/ # 开发调试脚本
|
|
96
|
+
├── tests/ # 集成测试与单元测试
|
|
97
|
+
├── bin/ # 预编译二进制(多平台分发)
|
|
98
|
+
├── Cargo.toml # Rust 包配置
|
|
99
|
+
├── package.json # npm 包配置
|
|
100
|
+
├── agmd.js # Node 入口:检测平台并 spawn 二进制
|
|
101
|
+
├── install.js # postinstall:复制对应平台二进制
|
|
102
|
+
└── classify.js # 路由分类配置示例
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
5. 高级用法
|
|
106
|
+
给文件打标记分类, 需要在src的同级目录下, 设置一个文件叫classify.js, 从里面读取需要配置的信息, 注意路径一定是带@符号的路径,@代表项目根目录(如 `@/components/Button.vue`), 没有配置, 那么程序会自动退出
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
#### Rust 库 API
|
|
110
|
+
|
|
111
|
+
本项目同时提供 Rust 库,暴露两个异步 API:
|
|
112
|
+
|
|
113
|
+
```rust
|
|
114
|
+
use agmd::{get_file_nodes_api, get_md_api, types::Options};
|
|
115
|
+
use std::path::Path;
|
|
116
|
+
|
|
117
|
+
let option = Options {
|
|
118
|
+
ignore: Some(vec!["node_modules".to_string()]),
|
|
119
|
+
include: Some(vec![".rs".to_string()]),
|
|
120
|
+
..Default::default()
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// 获取文件节点树
|
|
124
|
+
let nodes = get_file_nodes_api(Path::new("./src"), Some(&option)).await?;
|
|
125
|
+
|
|
126
|
+
// 获取 Markdown 输出
|
|
127
|
+
let (md, nodes) = get_md_api(Some(&option), Path::new(".")).await?;
|
|
128
|
+
```
|
|
129
|
+
#### 命令行参数说明
|
|
130
|
+
1. 使用agmd -h 来查看帮助
|
|
131
|
+
2. 可以带上 --ignore 忽略输出文件或文件夹, 默认为: img,styles,node_modules,LICENSE,.git,.github,dist,.husky,.vscode,readme-file.js,readme-md.js
|
|
132
|
+
3. 可以带上 --include 要求只输出带此后缀文件, 默认只输出 .js,.vue,.ts, 可自己加jsx,json 等
|
|
133
|
+
|
|
134
|
+
### 创作背景
|
|
135
|
+
|
|
136
|
+
1. 大家有没有被要求写一个目录文件的 md 说明呢?
|
|
137
|
+
2. 或者工程目录和文件被移动位置重构了,这时还需要重新修改 md 文件里面的目录说明
|
|
138
|
+
3. 接手老工程,看了 md 说明,能对文件夹里面的文件功能做到一目了然,而不是点开对应文件去看
|
|
139
|
+
4. 分析源码工程需要做点笔记
|
|
140
|
+
5. 拆分老代码工程, 手工量大还容易出错, 程序控制又快又好
|
|
141
|
+
6. 为什么绝对路径要改相对路径? 大家用vscode重命名文件时, 有没发现, 引用文件是绝对路径时, 文件没变化.....而且点击下钻查看文件详情还点不下去????但是相对路径不会有这个问题
|
|
142
|
+
7. 文件有后缀能一目了然文件是js文件还是vue文件
|
|
143
|
+
8. 一切需要手工重复操作的, 都可以用插件脚本搞定, 留时间学新知识更好
|
|
144
|
+
9. 补全缀是刚需, 很多伙伴就不喜欢写文件后缀, 所以import引入的是组件还是js 得去查看, 很不方便
|
|
145
|
+
|
|
146
|
+
### 功能
|
|
147
|
+
|
|
148
|
+
1. 自动生成匹配目录的文件夹名和文件(已经按名称进行排序)
|
|
149
|
+
2. 自动进行层级目录判断进行缩进
|
|
150
|
+
3. 如果文件顶部有注释, 那么会自动进行判断
|
|
151
|
+
4. 支持在任意文件目录下递归查找下级文件(不要在很大目录下执行啊!!!递归直到该级目录下没有文件为止)
|
|
152
|
+
5. 支持命令行参数配置, 可以自定义忽略文件和过滤后缀名文件
|
|
153
|
+
6. 命令行解析
|
|
154
|
+
|
|
155
|
+
控制台命令: agmd --include <string> --ignore <string> [--dry-run] [--silent]
|
|
156
|
+
|
|
157
|
+
可选项:
|
|
158
|
+
--include string / -in string.......... 包含解析的后缀 (以空格分隔)
|
|
159
|
+
--ignore string / -i string........... 忽略文件名或目录 (以空格分隔)
|
|
160
|
+
--dry-run / -d.................. 预演模式, 不对文件系统进行写入
|
|
161
|
+
--silent / -s.................. 静默模式, 最小化日志输出
|
|
162
|
+
|
|
163
|
+
例子:
|
|
164
|
+
--ignore / -i img,styles,node_modules,LICENSE,.git,.github,dist,.husky,.vscode,readme-file.js,readme-md.js
|
|
165
|
+
--include / -in .js,.vue,.ts
|
|
166
|
+
|
|
167
|
+
注意:
|
|
168
|
+
配置中的字符串之间不应有空格
|
|
169
|
+
|
|
170
|
+
命令行例子:
|
|
171
|
+
$ agmd --ignore lib node_modules dist --include .js .ts .vue --dry-run --silent
|
|
172
|
+
|
|
173
|
+
### 相关文章
|
|
174
|
+
|
|
175
|
+
[掘金-自动生成目录 md 文件](https://juejin.cn/post/7030030599268073508)
|
|
176
|
+
|
|
177
|
+
### 写在最后
|
|
178
|
+
|
|
179
|
+
本工程有36个测试, 大家如果想扩展什么功能, 测试代码跑起来, 很方便, 也欢迎大家克隆本工程然后提交进行PR!
|
|
180
|
+
|
|
181
|
+
### 更新记录
|
|
182
|
+
0.1.3
|
|
183
|
+
1. 采用esbuild 进行打包
|
|
184
|
+
2. 并且用eslint, preter规范写法, 规范
|
|
185
|
+
3. 用ts进行改写
|
|
186
|
+
4. 支持gitee一键同步
|
|
187
|
+
|
|
188
|
+
0.2.0
|
|
189
|
+
支持命令行解析参数,可以动态传参
|
|
190
|
+
|
|
191
|
+
0.2.6
|
|
192
|
+
修复全局安装报错
|
|
193
|
+
|
|
194
|
+
0.2.9
|
|
195
|
+
新增文件统计功能
|
|
196
|
+
|
|
197
|
+
0.3.0
|
|
198
|
+
✈️ 全程界面命令选择操作
|
|
199
|
+
|
|
200
|
+
⛵ 把工程所有引用更改绝对路径为相对路径(方便点击下钻查看文件)
|
|
201
|
+
|
|
202
|
+
♨️ 把工程所有引用文件都加上后缀(方便点击下钻查看文件)
|
|
203
|
+
|
|
204
|
+
👏 把工程按路由标记分类(对拆分工程很重要)
|
|
205
|
+
|
|
206
|
+
☝️ 把工程按分类对拆分工程(自动拆分的错误可控, 手动拆分会有各种问题)
|
|
207
|
+
|
|
208
|
+
0.3.3
|
|
209
|
+
优化提示日志打印
|
|
210
|
+
对路由进行自动分析
|
|
211
|
+
增加单元测试到26个,覆盖率达到84%,一些没必要的方法就没测试
|
|
212
|
+
|
|
213
|
+
0.3.7
|
|
214
|
+
升级所有依赖到最新
|
|
215
|
+
|
|
216
|
+
0.3.8
|
|
217
|
+
操作界面改成中文的, 我还是做不到大爱全世界, 先给自己和中国伙伴用好就行了, 同时增加功能只补全后缀, 但不更改路径
|
|
218
|
+
|
|
219
|
+
0.3.14
|
|
220
|
+
重构代码, 修改打包有esbuild转为tsc编译, 同时修改里面本身为异步操作的fs.readFileSync改为await readFile ,同时新增部分测试用例使得覆盖率达到85%
|
|
221
|
+
|
|
222
|
+
0.4.1
|
|
223
|
+
重构代码, 新增功能:
|
|
224
|
+
1. 新增命令行参数 --dry-run / -d 预演模式, 不对文件系统进行写入
|
|
225
|
+
2. 新增命令行参数 --silent / -s 静默模式, 最小化日志输出
|
|
226
|
+
3. 新增命令行参数 --absolute-alias / -a 把工程所有引用文件都加上绝对路径别名(方便点击下钻查看文件)
|
|
227
|
+
|
|
228
|
+
0.5.0 / v2
|
|
229
|
+
🔥 **使用 Rust 完全重写**
|
|
230
|
+
1. 性能提升 10 倍以上,大型工程秒级扫描
|
|
231
|
+
2. 零 Node.js 运行时依赖,单二进制文件分发
|
|
232
|
+
3. 支持多平台:Linux x64/ARM64、macOS x64/ARM64、Windows x64
|
|
233
|
+
4. npm 包内含所有平台预编译二进制,安装时自动选择当前平台
|
|
234
|
+
5. 安装包体积大幅缩小
|
|
235
|
+
|
|
236
|
+
### 开发者打包发布说明
|
|
237
|
+
|
|
238
|
+
v2 版本使用 Rust 编写,npm 包通过内嵌多平台预编译二进制分发。
|
|
239
|
+
|
|
240
|
+
#### 本地开发环境搭建(Windows)
|
|
241
|
+
|
|
242
|
+
如果你需要在 Windows 本地编译和测试,按以下步骤安装 Rust 环境:
|
|
243
|
+
|
|
244
|
+
1. **创建目录**(建议非 C 盘)
|
|
245
|
+
```powershell
|
|
246
|
+
New-Item -ItemType Directory -Force -Path E:\rust\cargo, E:\rust\rustup, E:\mingw
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
2. **下载并安装 Rust**
|
|
250
|
+
```powershell
|
|
251
|
+
$env:CARGO_HOME='E:\rust\cargo'
|
|
252
|
+
$env:RUSTUP_HOME='E:\rust\rustup'
|
|
253
|
+
Invoke-WebRequest -Uri https://win.rustup.rs/x86_64 -OutFile E:\rustup-init.exe
|
|
254
|
+
E:\rustup-init.exe -y --default-toolchain stable
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
3. **下载 MinGW-w64(GNU 工具链)**
|
|
258
|
+
```powershell
|
|
259
|
+
Invoke-WebRequest -Uri https://github.com/brechtsanders/winlibs_mingw/releases/download/13.2.0posix-17.0.6-11.0.1-ucrt-r5/winlibs-x86_64-posix-seh-gcc-13.2.0-llvm-17.0.6-mingw-w64ucrt-11.0.1-r5.zip -OutFile E:\mingw.zip
|
|
260
|
+
Expand-Archive -Path E:\mingw.zip -DestinationPath E:\mingw -Force
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
4. **添加环境变量**
|
|
264
|
+
|
|
265
|
+
在系统环境变量中添加:
|
|
266
|
+
- `CARGO_HOME` = `E:\rust\cargo`
|
|
267
|
+
- `RUSTUP_HOME` = `E:\rust\rustup`
|
|
268
|
+
- `Path` 追加 `E:\rust\cargo\bin;E:\mingw\mingw64\bin`
|
|
269
|
+
|
|
270
|
+
5. **安装 GNU 目标并切换默认工具链**
|
|
271
|
+
```powershell
|
|
272
|
+
rustup target add x86_64-pc-windows-gnu
|
|
273
|
+
rustup toolchain install stable-x86_64-pc-windows-gnu
|
|
274
|
+
rustup default stable-x86_64-pc-windows-gnu
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
6. **验证安装**
|
|
278
|
+
```powershell
|
|
279
|
+
rustc --version
|
|
280
|
+
cargo --version
|
|
281
|
+
gcc --version
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
#### 运行测试
|
|
285
|
+
|
|
286
|
+
```powershell
|
|
287
|
+
# 进入项目目录
|
|
288
|
+
cd e:\git\auto-generate-md
|
|
289
|
+
|
|
290
|
+
# 运行所有测试
|
|
291
|
+
cargo test
|
|
292
|
+
|
|
293
|
+
# 运行单个测试(带输出)
|
|
294
|
+
cargo test test_write_to_file_sync_replacement_logic -- --nocapture
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### 打包 Windows 版本
|
|
298
|
+
|
|
299
|
+
```powershell
|
|
300
|
+
# 编译 release 版本
|
|
301
|
+
cargo build --release --target x86_64-pc-windows-gnu
|
|
302
|
+
|
|
303
|
+
# 复制到 bin 目录
|
|
304
|
+
Copy-Item target\x86_64-pc-windows-gnu\release\agmd.exe bin\agmd-windows-x64.exe -Force
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### 打包步骤(全平台)
|
|
308
|
+
|
|
309
|
+
1. **编译各平台二进制**
|
|
310
|
+
|
|
311
|
+
在对应平台执行(或交叉编译):
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# Linux x64
|
|
315
|
+
cargo build --release --target x86_64-unknown-linux-gnu
|
|
316
|
+
cp target/x86_64-unknown-linux-gnu/release/agmd bin/agmd-linux-x64
|
|
317
|
+
|
|
318
|
+
# Linux ARM64
|
|
319
|
+
cargo build --release --target aarch64-unknown-linux-gnu
|
|
320
|
+
cp target/aarch64-unknown-linux-gnu/release/agmd bin/agmd-linux-arm64
|
|
321
|
+
|
|
322
|
+
# macOS x64
|
|
323
|
+
cargo build --release --target x86_64-apple-darwin
|
|
324
|
+
cp target/x86_64-apple-darwin/release/agmd bin/agmd-macos-x64
|
|
325
|
+
|
|
326
|
+
# macOS ARM64
|
|
327
|
+
cargo build --release --target aarch64-apple-darwin
|
|
328
|
+
cp target/aarch64-apple-darwin/release/agmd bin/agmd-macos-arm64
|
|
329
|
+
|
|
330
|
+
# Windows x64(MSVC 工具链,需安装 Visual Studio)
|
|
331
|
+
cargo build --release --target x86_64-pc-windows-msvc
|
|
332
|
+
cp target/x86_64-pc-windows-msvc/release/agmd.exe bin/agmd-windows-x64.exe
|
|
333
|
+
|
|
334
|
+
# Windows x64(GNU 工具链,无需 Visual Studio)
|
|
335
|
+
cargo build --release --target x86_64-pc-windows-gnu
|
|
336
|
+
cp target/x86_64-pc-windows-gnu/release/agmd.exe bin/agmd-windows-x64.exe
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
2. **确保二进制可执行**
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
chmod +x bin/agmd-linux-* bin/agmd-macos-*
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
3. **更新版本号**
|
|
346
|
+
|
|
347
|
+
同步修改以下文件的版本号:
|
|
348
|
+
- `Cargo.toml`
|
|
349
|
+
- `package.json`
|
|
350
|
+
|
|
351
|
+
4. **发布到 npm**
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
npm publish
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
需要提前登录 npm:`npm login`
|
|
358
|
+
|
|
359
|
+
#### npm 包结构
|
|
360
|
+
|
|
361
|
+
```
|
|
362
|
+
├── package.json # npm 包配置
|
|
363
|
+
├── agmd.js # 入口脚本,检测平台并 spawn 二进制
|
|
364
|
+
├── install.js # postinstall,复制对应平台二进制为 agmd
|
|
365
|
+
├── bin/ # 预编译二进制目录
|
|
366
|
+
│ ├── agmd-linux-x64
|
|
367
|
+
│ ├── agmd-linux-arm64
|
|
368
|
+
│ ├── agmd-macos-x64
|
|
369
|
+
│ ├── agmd-macos-arm64
|
|
370
|
+
│ └── agmd-windows-x64.exe
|
|
371
|
+
└── ...
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
用户安装时,`postinstall` 脚本会自动检测当前平台,从 `bin/` 复制对应二进制并命名为 `agmd`,无需联网下载。
|
package/agmd.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
function getBinaryPath() {
|
|
8
|
+
const binDir = path.join(__dirname, 'bin');
|
|
9
|
+
const platform = os.platform();
|
|
10
|
+
const targetName = platform === 'win32' ? 'agmd.exe' : 'agmd';
|
|
11
|
+
const targetPath = path.join(binDir, targetName);
|
|
12
|
+
|
|
13
|
+
if (fs.existsSync(targetPath)) {
|
|
14
|
+
return targetPath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const arch = os.arch();
|
|
18
|
+
const platformMap = { win32: 'windows', darwin: 'macos', linux: 'linux' };
|
|
19
|
+
const archMap = { x64: 'x64', arm64: 'arm64' };
|
|
20
|
+
const p = platformMap[platform];
|
|
21
|
+
const a = archMap[arch];
|
|
22
|
+
|
|
23
|
+
if (!p || !a) {
|
|
24
|
+
console.error(`Unsupported platform: ${platform} ${arch}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ext = platform === 'win32' ? '.exe' : '';
|
|
29
|
+
const binaryName = `agmd-${p}-${a}${ext}`;
|
|
30
|
+
const fallbackPath = path.join(binDir, binaryName);
|
|
31
|
+
|
|
32
|
+
if (fs.existsSync(fallbackPath)) {
|
|
33
|
+
return fallbackPath;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.error(`Binary not found. Please reinstall agmd.`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const binaryPath = getBinaryPath();
|
|
41
|
+
const args = process.argv.slice(2);
|
|
42
|
+
|
|
43
|
+
const child = spawn(binaryPath, args, {
|
|
44
|
+
stdio: 'inherit',
|
|
45
|
+
shell: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.on('error', (err) => {
|
|
49
|
+
console.error('Failed to start agmd:', err.message);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
child.on('exit', (code) => {
|
|
54
|
+
process.exit(code ?? 0);
|
|
55
|
+
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/install.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
function getBinaryName() {
|
|
6
|
+
const platform = os.platform();
|
|
7
|
+
const arch = os.arch();
|
|
8
|
+
|
|
9
|
+
const platformMap = {
|
|
10
|
+
win32: 'windows',
|
|
11
|
+
darwin: 'macos',
|
|
12
|
+
linux: 'linux',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const archMap = {
|
|
16
|
+
x64: 'x64',
|
|
17
|
+
arm64: 'arm64',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const p = platformMap[platform];
|
|
21
|
+
const a = archMap[arch];
|
|
22
|
+
|
|
23
|
+
if (!p || !a) {
|
|
24
|
+
console.error(`Unsupported platform: ${platform} ${arch}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ext = platform === 'win32' ? '.exe' : '';
|
|
29
|
+
return `agmd-${p}-${a}${ext}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function main() {
|
|
33
|
+
const binaryName = getBinaryName();
|
|
34
|
+
const binDir = path.join(__dirname, 'bin');
|
|
35
|
+
const sourcePath = path.join(binDir, binaryName);
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(sourcePath)) {
|
|
38
|
+
console.error(`Binary not found for your platform: ${binaryName}`);
|
|
39
|
+
console.error('Supported platforms: Linux x64/ARM64, macOS x64/ARM64, Windows x64');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const targetName = os.platform() === 'win32' ? 'agmd.exe' : 'agmd';
|
|
44
|
+
const targetPath = path.join(binDir, targetName);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
if (fs.existsSync(targetPath)) {
|
|
48
|
+
fs.unlinkSync(targetPath);
|
|
49
|
+
}
|
|
50
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
51
|
+
fs.chmodSync(targetPath, 0o755);
|
|
52
|
+
console.log(`agmd installed: ${binaryName}`);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error('Failed to setup binary:', err.message);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
main();
|