openmatrix 0.1.89 → 0.1.91
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.
|
@@ -39,6 +39,7 @@ const child_process_1 = require("child_process");
|
|
|
39
39
|
const util_1 = require("util");
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
const fs = __importStar(require("fs/promises"));
|
|
42
|
+
const gitignore_js_1 = require("../utils/gitignore.js");
|
|
42
43
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
43
44
|
/**
|
|
44
45
|
* GitCommitManager - Git 自动提交管理器
|
|
@@ -242,19 +243,7 @@ class GitCommitManager {
|
|
|
242
243
|
this.gitRoot = this.repoPath; // 刚初始化的仓库,根目录就是 repoPath
|
|
243
244
|
}
|
|
244
245
|
// 确保 .gitignore 中包含 .openmatrix(写入到 git 根目录)
|
|
245
|
-
|
|
246
|
-
const gitignorePath = path.join(gitRoot, '.gitignore');
|
|
247
|
-
let gitignoreContent = '';
|
|
248
|
-
try {
|
|
249
|
-
gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');
|
|
250
|
-
}
|
|
251
|
-
catch {
|
|
252
|
-
// 文件不存在
|
|
253
|
-
}
|
|
254
|
-
if (!gitignoreContent.includes('.openmatrix')) {
|
|
255
|
-
const addition = (gitignoreContent && !gitignoreContent.endsWith('\n') ? '\n' : '') + '.openmatrix/\n';
|
|
256
|
-
await fs.writeFile(gitignorePath, gitignoreContent + addition, 'utf-8');
|
|
257
|
-
}
|
|
246
|
+
await (0, gitignore_js_1.ensureOpenmatrixGitignore)(this.repoPath);
|
|
258
247
|
// 获取未提交的文件
|
|
259
248
|
const files = await this.getUncommittedFiles();
|
|
260
249
|
if (files.length === 0) {
|
|
@@ -283,7 +272,7 @@ class GitCommitManager {
|
|
|
283
272
|
};
|
|
284
273
|
}
|
|
285
274
|
// 使用临时文件传递 commit message(避免 Windows 下多行消息转义问题)
|
|
286
|
-
const tmpFile = path.join(
|
|
275
|
+
const tmpFile = path.join(await this.getGitRoot(), '.git', 'COMMIT_MSG_TMP');
|
|
287
276
|
await fs.writeFile(tmpFile, commitMessage, 'utf-8');
|
|
288
277
|
try {
|
|
289
278
|
const { stdout } = await execAsync(`git commit -F "${tmpFile}"`, { cwd: this.repoPath });
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 确保 .gitignore 包含当前项目需要的所有忽略条目
|
|
3
|
+
*
|
|
4
|
+
* 自动检测项目类型(Node.js/Python/Java/Go/Rust/.NET/Vue/React),
|
|
5
|
+
* 补充对应的 node_modules、dist、.venv、target 等忽略规则。
|
|
6
|
+
*
|
|
3
7
|
* @param basePath 项目目录(可以是 git 仓库的子目录)
|
|
4
|
-
* @param ignorePattern 要忽略的模式 (默认 .openmatrix/)
|
|
5
|
-
*/
|
|
6
|
-
export declare function ensureGitignore(basePath: string, ignorePattern?: string): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* 确保 .openmatrix 目录被 git 忽略
|
|
9
8
|
*/
|
|
10
9
|
export declare function ensureOpenmatrixGitignore(basePath: string): Promise<void>;
|
package/dist/utils/gitignore.js
CHANGED
|
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ensureGitignore = ensureGitignore;
|
|
37
36
|
exports.ensureOpenmatrixGitignore = ensureOpenmatrixGitignore;
|
|
38
37
|
// src/utils/gitignore.ts
|
|
39
38
|
const fs = __importStar(require("fs/promises"));
|
|
@@ -53,43 +52,247 @@ async function getGitRoot(basePath) {
|
|
|
53
52
|
return basePath;
|
|
54
53
|
}
|
|
55
54
|
}
|
|
55
|
+
// ============ 项目类型检测 ============
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @param basePath 项目目录(可以是 git 仓库的子目录)
|
|
59
|
-
* @param ignorePattern 要忽略的模式 (默认 .openmatrix/)
|
|
57
|
+
* 项目类型对应的 gitignore 条目
|
|
60
58
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const GITIGNORE_TEMPLATES = {
|
|
60
|
+
nodejs: [
|
|
61
|
+
'node_modules/',
|
|
62
|
+
'dist/',
|
|
63
|
+
'build/',
|
|
64
|
+
'.npm/',
|
|
65
|
+
'*.log',
|
|
66
|
+
'npm-debug.log*',
|
|
67
|
+
'yarn-debug.log*',
|
|
68
|
+
'yarn-error.log*',
|
|
69
|
+
],
|
|
70
|
+
typescript: [
|
|
71
|
+
'*.tsbuildinfo',
|
|
72
|
+
],
|
|
73
|
+
python: [
|
|
74
|
+
'__pycache__/',
|
|
75
|
+
'*.py[cod]',
|
|
76
|
+
'.venv/',
|
|
77
|
+
'venv/',
|
|
78
|
+
'.pytest_cache/',
|
|
79
|
+
'.mypy_cache/',
|
|
80
|
+
'*.egg-info/',
|
|
81
|
+
],
|
|
82
|
+
java: [
|
|
83
|
+
'target/',
|
|
84
|
+
'.gradle/',
|
|
85
|
+
'*.class',
|
|
86
|
+
'*.jar',
|
|
87
|
+
],
|
|
88
|
+
go: [
|
|
89
|
+
'vendor/',
|
|
90
|
+
'bin/',
|
|
91
|
+
'*.exe',
|
|
92
|
+
'*.dll',
|
|
93
|
+
'*.so',
|
|
94
|
+
'*.dylib',
|
|
95
|
+
],
|
|
96
|
+
rust: [
|
|
97
|
+
'target/',
|
|
98
|
+
'Cargo.lock',
|
|
99
|
+
],
|
|
100
|
+
dotnet: [
|
|
101
|
+
'bin/',
|
|
102
|
+
'obj/',
|
|
103
|
+
'*.nupkg',
|
|
104
|
+
],
|
|
105
|
+
vue: [
|
|
106
|
+
'.nuxt/',
|
|
107
|
+
'.output/',
|
|
108
|
+
'.vite/',
|
|
109
|
+
],
|
|
110
|
+
react: [
|
|
111
|
+
'.next/',
|
|
112
|
+
],
|
|
113
|
+
common: [
|
|
114
|
+
'.env',
|
|
115
|
+
'.env.local',
|
|
116
|
+
'.env.*.local',
|
|
117
|
+
'.DS_Store',
|
|
118
|
+
'Thumbs.db',
|
|
119
|
+
'*.swp',
|
|
120
|
+
'*~',
|
|
121
|
+
'.idea/',
|
|
122
|
+
'.vscode/',
|
|
123
|
+
'*.iml',
|
|
124
|
+
],
|
|
125
|
+
openmatrix: [
|
|
126
|
+
'.openmatrix/',
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* 根据项目文件检测项目类型
|
|
131
|
+
*/
|
|
132
|
+
async function detectProjectTypes(projectRoot) {
|
|
133
|
+
const types = [];
|
|
134
|
+
// 检查 package.json → nodejs + 可能的框架
|
|
65
135
|
try {
|
|
66
|
-
const content = await fs.readFile(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const trimmed = line.trim();
|
|
72
|
-
return trimmed === patternBase ||
|
|
73
|
-
trimmed === `${patternBase}/` ||
|
|
74
|
-
trimmed === `/${patternBase}` ||
|
|
75
|
-
trimmed === `/${patternBase}/`;
|
|
76
|
-
});
|
|
77
|
-
if (!hasPattern) {
|
|
78
|
-
// 添加模式到 .gitignore
|
|
79
|
-
const newContent = content.endsWith('\n')
|
|
80
|
-
? `${content}${ignorePattern}\n`
|
|
81
|
-
: `${content}\n\n# Auto-added by OpenMatrix\n${ignorePattern}\n`;
|
|
82
|
-
await fs.writeFile(gitignorePath, newContent);
|
|
136
|
+
const content = await fs.readFile(path.join(projectRoot, 'package.json'), 'utf-8');
|
|
137
|
+
const pkg = JSON.parse(content);
|
|
138
|
+
types.push('nodejs');
|
|
139
|
+
if (pkg.devDependencies?.typescript || pkg.dependencies?.typescript) {
|
|
140
|
+
types.push('typescript');
|
|
83
141
|
}
|
|
142
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
143
|
+
if (allDeps['nuxt'] || allDeps['@nuxt/content'])
|
|
144
|
+
types.push('vue');
|
|
145
|
+
if (allDeps['next'] || allDeps['@next/react'])
|
|
146
|
+
types.push('react');
|
|
84
147
|
}
|
|
85
|
-
catch {
|
|
86
|
-
|
|
87
|
-
|
|
148
|
+
catch { /* not node */ }
|
|
149
|
+
// 检查 Python
|
|
150
|
+
try {
|
|
151
|
+
await fs.access(path.join(projectRoot, 'pyproject.toml'));
|
|
152
|
+
types.push('python');
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
try {
|
|
156
|
+
await fs.access(path.join(projectRoot, 'requirements.txt'));
|
|
157
|
+
if (!types.includes('python'))
|
|
158
|
+
types.push('python');
|
|
88
159
|
}
|
|
160
|
+
catch { }
|
|
161
|
+
// 检查 Java
|
|
162
|
+
try {
|
|
163
|
+
await fs.access(path.join(projectRoot, 'pom.xml'));
|
|
164
|
+
types.push('java');
|
|
165
|
+
}
|
|
166
|
+
catch { }
|
|
167
|
+
try {
|
|
168
|
+
await fs.access(path.join(projectRoot, 'build.gradle'));
|
|
169
|
+
if (!types.includes('java'))
|
|
170
|
+
types.push('java');
|
|
171
|
+
}
|
|
172
|
+
catch { }
|
|
173
|
+
// 检查 Go
|
|
174
|
+
try {
|
|
175
|
+
await fs.access(path.join(projectRoot, 'go.mod'));
|
|
176
|
+
types.push('go');
|
|
177
|
+
}
|
|
178
|
+
catch { }
|
|
179
|
+
// 检查 Rust
|
|
180
|
+
try {
|
|
181
|
+
await fs.access(path.join(projectRoot, 'Cargo.toml'));
|
|
182
|
+
types.push('rust');
|
|
183
|
+
}
|
|
184
|
+
catch { }
|
|
185
|
+
// 检查 .NET
|
|
186
|
+
try {
|
|
187
|
+
const files = await fs.readdir(projectRoot);
|
|
188
|
+
if (files.some(f => f.endsWith('.sln') || f.endsWith('.csproj')))
|
|
189
|
+
types.push('dotnet');
|
|
190
|
+
}
|
|
191
|
+
catch { }
|
|
192
|
+
types.push('common');
|
|
193
|
+
types.push('openmatrix');
|
|
194
|
+
return types;
|
|
89
195
|
}
|
|
196
|
+
// ============ Gitignore 操作 ============
|
|
90
197
|
/**
|
|
91
|
-
*
|
|
198
|
+
* 检查 gitignore 内容中是否已包含指定模式
|
|
199
|
+
*/
|
|
200
|
+
function hasGitignoreEntry(content, pattern) {
|
|
201
|
+
const patternBase = pattern.replace(/\/$/, '');
|
|
202
|
+
return content.split('\n').some(line => {
|
|
203
|
+
const trimmed = line.trim();
|
|
204
|
+
return trimmed === patternBase ||
|
|
205
|
+
trimmed === `${patternBase}/` ||
|
|
206
|
+
trimmed === `/${patternBase}` ||
|
|
207
|
+
trimmed === `/${patternBase}/`;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 根据项目类型收集所有需要的 gitignore 条目
|
|
212
|
+
*/
|
|
213
|
+
function collectRequiredEntries(projectTypes) {
|
|
214
|
+
const seen = new Set();
|
|
215
|
+
const entries = [];
|
|
216
|
+
for (const type of projectTypes) {
|
|
217
|
+
const template = GITIGNORE_TEMPLATES[type];
|
|
218
|
+
if (template) {
|
|
219
|
+
for (const entry of template) {
|
|
220
|
+
if (!seen.has(entry)) {
|
|
221
|
+
seen.add(entry);
|
|
222
|
+
entries.push(entry);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return entries;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* 确保 .gitignore 包含当前项目需要的所有忽略条目
|
|
231
|
+
*
|
|
232
|
+
* 自动检测项目类型(Node.js/Python/Java/Go/Rust/.NET/Vue/React),
|
|
233
|
+
* 补充对应的 node_modules、dist、.venv、target 等忽略规则。
|
|
234
|
+
*
|
|
235
|
+
* @param basePath 项目目录(可以是 git 仓库的子目录)
|
|
92
236
|
*/
|
|
93
237
|
async function ensureOpenmatrixGitignore(basePath) {
|
|
94
|
-
await
|
|
238
|
+
const gitRoot = await getGitRoot(basePath);
|
|
239
|
+
const gitignorePath = path.join(gitRoot, '.gitignore');
|
|
240
|
+
// 读取现有内容
|
|
241
|
+
let content = '';
|
|
242
|
+
try {
|
|
243
|
+
content = await fs.readFile(gitignorePath, 'utf-8');
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// 文件不存在
|
|
247
|
+
}
|
|
248
|
+
// 检测项目类型并收集需要的条目
|
|
249
|
+
const projectTypes = await detectProjectTypes(gitRoot);
|
|
250
|
+
const requiredEntries = collectRequiredEntries(projectTypes);
|
|
251
|
+
// 筛选缺失的条目
|
|
252
|
+
const missingEntries = requiredEntries.filter(e => !hasGitignoreEntry(content, e));
|
|
253
|
+
if (missingEntries.length === 0)
|
|
254
|
+
return;
|
|
255
|
+
// 按类型分组追加
|
|
256
|
+
const timestamp = new Date().toISOString().split('T')[0];
|
|
257
|
+
const groups = {
|
|
258
|
+
'Dependencies': [],
|
|
259
|
+
'Build Output': [],
|
|
260
|
+
'Environment': [],
|
|
261
|
+
'IDE / Editor': [],
|
|
262
|
+
'OS Files': [],
|
|
263
|
+
'OpenMatrix': [],
|
|
264
|
+
'Other': [],
|
|
265
|
+
};
|
|
266
|
+
for (const entry of missingEntries) {
|
|
267
|
+
if (entry.includes('node_modules') || entry.includes('vendor') || entry.includes('.venv') || entry.includes('packages')) {
|
|
268
|
+
groups['Dependencies'].push(entry);
|
|
269
|
+
}
|
|
270
|
+
else if (entry.includes('dist') || entry.includes('build') || entry.includes('target') || entry.includes('bin') || entry.includes('obj') || entry.includes('.output') || entry.includes('.next') || entry.includes('.nuxt')) {
|
|
271
|
+
groups['Build Output'].push(entry);
|
|
272
|
+
}
|
|
273
|
+
else if (entry.includes('.env')) {
|
|
274
|
+
groups['Environment'].push(entry);
|
|
275
|
+
}
|
|
276
|
+
else if (entry.includes('.idea') || entry.includes('.vscode') || entry.includes('.vite') || entry.includes('.iml')) {
|
|
277
|
+
groups['IDE / Editor'].push(entry);
|
|
278
|
+
}
|
|
279
|
+
else if (entry.includes('.openmatrix')) {
|
|
280
|
+
groups['OpenMatrix'].push(entry);
|
|
281
|
+
}
|
|
282
|
+
else if (entry.includes('.DS_Store') || entry.includes('Thumbs.db')) {
|
|
283
|
+
groups['OS Files'].push(entry);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
groups['Other'].push(entry);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
let addition = (content && !content.endsWith('\n') ? '\n' : '') +
|
|
290
|
+
`\n# Auto-generated by OpenMatrix (${timestamp})\n`;
|
|
291
|
+
for (const [group, items] of Object.entries(groups)) {
|
|
292
|
+
if (items.length > 0) {
|
|
293
|
+
addition += `\n# ${group}\n`;
|
|
294
|
+
addition += items.join('\n') + '\n';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
await fs.writeFile(gitignorePath, content + addition, 'utf-8');
|
|
95
298
|
}
|