openspec-stat 1.2.0 → 1.3.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/README.md +28 -0
- package/README.zh-CN.md +28 -0
- package/dist/cjs/cli.js +12 -127
- package/dist/cjs/commands/init.d.ts +7 -0
- package/dist/cjs/commands/init.js +58 -0
- package/dist/cjs/commands/multi.d.ts +16 -0
- package/dist/cjs/commands/multi.js +172 -0
- package/dist/cjs/commands/single.d.ts +2 -0
- package/dist/cjs/commands/single.js +148 -0
- package/dist/cjs/formatters.d.ts +4 -4
- package/dist/cjs/formatters.js +128 -36
- package/dist/cjs/git-analyzer.d.ts +1 -0
- package/dist/cjs/git-analyzer.js +6 -0
- package/dist/cjs/i18n/locales/en.json +74 -1
- package/dist/cjs/i18n/locales/zh-CN.json +74 -1
- package/dist/cjs/multi/config-validator.d.ts +3 -0
- package/dist/cjs/multi/config-validator.js +130 -0
- package/dist/cjs/multi/config-wizard.d.ts +50 -0
- package/dist/cjs/multi/config-wizard.js +331 -0
- package/dist/cjs/multi/multi-repo-analyzer.d.ts +14 -0
- package/dist/cjs/multi/multi-repo-analyzer.js +210 -0
- package/dist/cjs/types.d.ts +46 -0
- package/dist/esm/cli.js +54 -139
- package/dist/esm/commands/init.d.ts +7 -0
- package/dist/esm/commands/init.js +49 -0
- package/dist/esm/commands/multi.d.ts +16 -0
- package/dist/esm/commands/multi.js +192 -0
- package/dist/esm/commands/single.d.ts +2 -0
- package/dist/esm/commands/single.js +162 -0
- package/dist/esm/formatters.d.ts +4 -4
- package/dist/esm/formatters.js +173 -52
- package/dist/esm/git-analyzer.d.ts +1 -0
- package/dist/esm/git-analyzer.js +104 -77
- package/dist/esm/i18n/locales/en.json +74 -1
- package/dist/esm/i18n/locales/zh-CN.json +74 -1
- package/dist/esm/multi/config-validator.d.ts +3 -0
- package/dist/esm/multi/config-validator.js +109 -0
- package/dist/esm/multi/config-wizard.d.ts +50 -0
- package/dist/esm/multi/config-wizard.js +535 -0
- package/dist/esm/multi/multi-repo-analyzer.d.ts +14 -0
- package/dist/esm/multi/multi-repo-analyzer.js +446 -0
- package/dist/esm/types.d.ts +46 -0
- package/package.json +1 -1
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
+
import simpleGit from 'simple-git';
|
|
19
|
+
import { mkdtempSync, rmSync, existsSync, mkdirSync } from 'fs';
|
|
20
|
+
import { tmpdir } from 'os';
|
|
21
|
+
import { join, resolve } from 'path';
|
|
22
|
+
import chalk from 'chalk';
|
|
23
|
+
import { GitAnalyzer } from "../git-analyzer.js";
|
|
24
|
+
import { t } from "../i18n/index.js";
|
|
25
|
+
export var MultiRepoAnalyzer = /*#__PURE__*/function () {
|
|
26
|
+
function MultiRepoAnalyzer(config) {
|
|
27
|
+
_classCallCheck(this, MultiRepoAnalyzer);
|
|
28
|
+
_defineProperty(this, "config", void 0);
|
|
29
|
+
_defineProperty(this, "tempDirs", new Set());
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
_createClass(MultiRepoAnalyzer, [{
|
|
33
|
+
key: "analyzeAll",
|
|
34
|
+
value: function () {
|
|
35
|
+
var _analyzeAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(since, until) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
var repos, enabledRepos, _this$config$parallel, results, _this$config$remoteCa;
|
|
38
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
|
+
while (1) switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
repos = this.config.repositories || [];
|
|
42
|
+
enabledRepos = repos.filter(function (r) {
|
|
43
|
+
return r.enabled !== false;
|
|
44
|
+
});
|
|
45
|
+
_context.prev = 2;
|
|
46
|
+
_context.next = 5;
|
|
47
|
+
return this.processInBatches(enabledRepos, function (repo) {
|
|
48
|
+
return _this.analyzeRepository(repo, since, until);
|
|
49
|
+
}, ((_this$config$parallel = this.config.parallelism) === null || _this$config$parallel === void 0 ? void 0 : _this$config$parallel.maxConcurrent) || 3);
|
|
50
|
+
case 5:
|
|
51
|
+
results = _context.sent;
|
|
52
|
+
return _context.abrupt("return", results);
|
|
53
|
+
case 7:
|
|
54
|
+
_context.prev = 7;
|
|
55
|
+
if (!((_this$config$remoteCa = this.config.remoteCache) !== null && _this$config$remoteCa !== void 0 && _this$config$remoteCa.cleanupOnComplete)) {
|
|
56
|
+
_context.next = 11;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
_context.next = 11;
|
|
60
|
+
return this.cleanupTempDirs();
|
|
61
|
+
case 11:
|
|
62
|
+
return _context.finish(7);
|
|
63
|
+
case 12:
|
|
64
|
+
case "end":
|
|
65
|
+
return _context.stop();
|
|
66
|
+
}
|
|
67
|
+
}, _callee, this, [[2,, 7, 12]]);
|
|
68
|
+
}));
|
|
69
|
+
function analyzeAll(_x, _x2) {
|
|
70
|
+
return _analyzeAll.apply(this, arguments);
|
|
71
|
+
}
|
|
72
|
+
return analyzeAll;
|
|
73
|
+
}()
|
|
74
|
+
}, {
|
|
75
|
+
key: "analyzeRepository",
|
|
76
|
+
value: function () {
|
|
77
|
+
var _analyzeRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(repo, since, until) {
|
|
78
|
+
var repoPath, analyzer, commits, analyses, _iterator, _step, commit, analysis, errorMessage;
|
|
79
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
80
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
_context2.prev = 0;
|
|
83
|
+
if (!(repo.enabled === false)) {
|
|
84
|
+
_context2.next = 4;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
console.log(chalk.gray(t('multi.repo.skipped', {
|
|
88
|
+
repo: repo.name
|
|
89
|
+
})));
|
|
90
|
+
return _context2.abrupt("return", {
|
|
91
|
+
repository: repo.name,
|
|
92
|
+
type: repo.type,
|
|
93
|
+
path: '',
|
|
94
|
+
analyses: [],
|
|
95
|
+
success: false,
|
|
96
|
+
error: 'disabled'
|
|
97
|
+
});
|
|
98
|
+
case 4:
|
|
99
|
+
console.log(chalk.blue(t('multi.repo.analyzing', {
|
|
100
|
+
repo: repo.name,
|
|
101
|
+
type: repo.type
|
|
102
|
+
})));
|
|
103
|
+
if (!(repo.type === 'local')) {
|
|
104
|
+
_context2.next = 11;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
repoPath = this.resolveLocalPath(repo.path);
|
|
108
|
+
if (existsSync(join(repoPath, '.git'))) {
|
|
109
|
+
_context2.next = 9;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
throw new Error("Not a git repository: ".concat(repoPath));
|
|
113
|
+
case 9:
|
|
114
|
+
_context2.next = 14;
|
|
115
|
+
break;
|
|
116
|
+
case 11:
|
|
117
|
+
_context2.next = 13;
|
|
118
|
+
return this.cloneRemoteRepository(repo);
|
|
119
|
+
case 13:
|
|
120
|
+
repoPath = _context2.sent;
|
|
121
|
+
case 14:
|
|
122
|
+
analyzer = new GitAnalyzer(repoPath, this.config); // Fetch remote branches for local repositories to ensure data is up-to-date
|
|
123
|
+
if (!(repo.type === 'local' && this.config.autoFetch !== false)) {
|
|
124
|
+
_context2.next = 19;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
console.log(chalk.cyan(t('multi.repo.fetching', {
|
|
128
|
+
repo: repo.name
|
|
129
|
+
})));
|
|
130
|
+
_context2.next = 19;
|
|
131
|
+
return analyzer.fetchRemote();
|
|
132
|
+
case 19:
|
|
133
|
+
_context2.next = 21;
|
|
134
|
+
return analyzer.getCommits(since, until, repo.branches);
|
|
135
|
+
case 21:
|
|
136
|
+
commits = _context2.sent;
|
|
137
|
+
analyses = [];
|
|
138
|
+
_iterator = _createForOfIteratorHelper(commits);
|
|
139
|
+
_context2.prev = 24;
|
|
140
|
+
_iterator.s();
|
|
141
|
+
case 26:
|
|
142
|
+
if ((_step = _iterator.n()).done) {
|
|
143
|
+
_context2.next = 34;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
commit = _step.value;
|
|
147
|
+
_context2.next = 30;
|
|
148
|
+
return analyzer.analyzeCommit(commit);
|
|
149
|
+
case 30:
|
|
150
|
+
analysis = _context2.sent;
|
|
151
|
+
if (analysis) {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
analysis.repository = repo.name;
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
+
analysis.repositoryType = repo.type;
|
|
156
|
+
analyses.push(analysis);
|
|
157
|
+
}
|
|
158
|
+
case 32:
|
|
159
|
+
_context2.next = 26;
|
|
160
|
+
break;
|
|
161
|
+
case 34:
|
|
162
|
+
_context2.next = 39;
|
|
163
|
+
break;
|
|
164
|
+
case 36:
|
|
165
|
+
_context2.prev = 36;
|
|
166
|
+
_context2.t0 = _context2["catch"](24);
|
|
167
|
+
_iterator.e(_context2.t0);
|
|
168
|
+
case 39:
|
|
169
|
+
_context2.prev = 39;
|
|
170
|
+
_iterator.f();
|
|
171
|
+
return _context2.finish(39);
|
|
172
|
+
case 42:
|
|
173
|
+
console.log(chalk.green(t('multi.repo.completed', {
|
|
174
|
+
repo: repo.name,
|
|
175
|
+
commits: String(analyses.length)
|
|
176
|
+
})));
|
|
177
|
+
return _context2.abrupt("return", {
|
|
178
|
+
repository: repo.name,
|
|
179
|
+
type: repo.type,
|
|
180
|
+
path: repoPath,
|
|
181
|
+
analyses: analyses,
|
|
182
|
+
success: true
|
|
183
|
+
});
|
|
184
|
+
case 46:
|
|
185
|
+
_context2.prev = 46;
|
|
186
|
+
_context2.t1 = _context2["catch"](0);
|
|
187
|
+
errorMessage = _context2.t1 instanceof Error ? _context2.t1.message : String(_context2.t1);
|
|
188
|
+
console.error(chalk.red(t('multi.repo.failed', {
|
|
189
|
+
repo: repo.name,
|
|
190
|
+
error: errorMessage
|
|
191
|
+
})));
|
|
192
|
+
return _context2.abrupt("return", {
|
|
193
|
+
repository: repo.name,
|
|
194
|
+
type: repo.type,
|
|
195
|
+
path: '',
|
|
196
|
+
analyses: [],
|
|
197
|
+
success: false,
|
|
198
|
+
error: errorMessage
|
|
199
|
+
});
|
|
200
|
+
case 51:
|
|
201
|
+
case "end":
|
|
202
|
+
return _context2.stop();
|
|
203
|
+
}
|
|
204
|
+
}, _callee2, this, [[0, 46], [24, 36, 39, 42]]);
|
|
205
|
+
}));
|
|
206
|
+
function analyzeRepository(_x3, _x4, _x5) {
|
|
207
|
+
return _analyzeRepository.apply(this, arguments);
|
|
208
|
+
}
|
|
209
|
+
return analyzeRepository;
|
|
210
|
+
}()
|
|
211
|
+
}, {
|
|
212
|
+
key: "cloneRemoteRepository",
|
|
213
|
+
value: function () {
|
|
214
|
+
var _cloneRemoteRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(repo) {
|
|
215
|
+
var _this$config$remoteCa2, _repo$cloneOptions, _repo$cloneOptions2, _repo$cloneOptions3, _this$config$parallel2;
|
|
216
|
+
var cacheDir, tempDir, git, cloneArgs, timeout;
|
|
217
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
218
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
219
|
+
case 0:
|
|
220
|
+
cacheDir = ((_this$config$remoteCa2 = this.config.remoteCache) === null || _this$config$remoteCa2 === void 0 ? void 0 : _this$config$remoteCa2.dir) || join(tmpdir(), 'openspec-stat-cache');
|
|
221
|
+
if (!existsSync(cacheDir)) {
|
|
222
|
+
mkdirSync(cacheDir, {
|
|
223
|
+
recursive: true
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
tempDir = mkdtempSync(join(cacheDir, "".concat(repo.name, "-")));
|
|
227
|
+
this.tempDirs.add(tempDir);
|
|
228
|
+
console.log(chalk.cyan(t('multi.repo.cloning', {
|
|
229
|
+
repo: repo.name
|
|
230
|
+
})));
|
|
231
|
+
git = simpleGit();
|
|
232
|
+
cloneArgs = [];
|
|
233
|
+
if (((_repo$cloneOptions = repo.cloneOptions) === null || _repo$cloneOptions === void 0 ? void 0 : _repo$cloneOptions.depth) !== null && ((_repo$cloneOptions2 = repo.cloneOptions) === null || _repo$cloneOptions2 === void 0 ? void 0 : _repo$cloneOptions2.depth) !== undefined) {
|
|
234
|
+
cloneArgs.push("--depth=".concat(repo.cloneOptions.depth));
|
|
235
|
+
}
|
|
236
|
+
if ((_repo$cloneOptions3 = repo.cloneOptions) !== null && _repo$cloneOptions3 !== void 0 && _repo$cloneOptions3.singleBranch) {
|
|
237
|
+
cloneArgs.push('--single-branch');
|
|
238
|
+
}
|
|
239
|
+
timeout = ((_this$config$parallel2 = this.config.parallelism) === null || _this$config$parallel2 === void 0 ? void 0 : _this$config$parallel2.timeout) || 600000;
|
|
240
|
+
_context3.next = 12;
|
|
241
|
+
return this.withTimeout(git.clone(repo.url, tempDir, cloneArgs), timeout, "Clone timeout for ".concat(repo.name));
|
|
242
|
+
case 12:
|
|
243
|
+
console.log(chalk.green(t('multi.repo.cloned', {
|
|
244
|
+
repo: repo.name
|
|
245
|
+
})));
|
|
246
|
+
return _context3.abrupt("return", tempDir);
|
|
247
|
+
case 14:
|
|
248
|
+
case "end":
|
|
249
|
+
return _context3.stop();
|
|
250
|
+
}
|
|
251
|
+
}, _callee3, this);
|
|
252
|
+
}));
|
|
253
|
+
function cloneRemoteRepository(_x6) {
|
|
254
|
+
return _cloneRemoteRepository.apply(this, arguments);
|
|
255
|
+
}
|
|
256
|
+
return cloneRemoteRepository;
|
|
257
|
+
}()
|
|
258
|
+
}, {
|
|
259
|
+
key: "resolveLocalPath",
|
|
260
|
+
value: function resolveLocalPath(path) {
|
|
261
|
+
if (path.startsWith('/') || path.match(/^[A-Za-z]:\\/)) {
|
|
262
|
+
return path;
|
|
263
|
+
}
|
|
264
|
+
return resolve(process.cwd(), path);
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
key: "processInBatches",
|
|
268
|
+
value: function () {
|
|
269
|
+
var _processInBatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(items, processor, concurrency) {
|
|
270
|
+
var results, i, batch, batchNumber, totalBatches, batchResults;
|
|
271
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
272
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
273
|
+
case 0:
|
|
274
|
+
results = [];
|
|
275
|
+
i = 0;
|
|
276
|
+
case 2:
|
|
277
|
+
if (!(i < items.length)) {
|
|
278
|
+
_context4.next = 14;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
batch = items.slice(i, i + concurrency);
|
|
282
|
+
batchNumber = Math.floor(i / concurrency) + 1;
|
|
283
|
+
totalBatches = Math.ceil(items.length / concurrency);
|
|
284
|
+
if (totalBatches > 1) {
|
|
285
|
+
console.log(chalk.gray(t('multi.progress.batch', {
|
|
286
|
+
current: String(batchNumber),
|
|
287
|
+
total: String(totalBatches)
|
|
288
|
+
})));
|
|
289
|
+
}
|
|
290
|
+
_context4.next = 9;
|
|
291
|
+
return Promise.all(batch.map(processor));
|
|
292
|
+
case 9:
|
|
293
|
+
batchResults = _context4.sent;
|
|
294
|
+
results.push.apply(results, _toConsumableArray(batchResults));
|
|
295
|
+
case 11:
|
|
296
|
+
i += concurrency;
|
|
297
|
+
_context4.next = 2;
|
|
298
|
+
break;
|
|
299
|
+
case 14:
|
|
300
|
+
return _context4.abrupt("return", results);
|
|
301
|
+
case 15:
|
|
302
|
+
case "end":
|
|
303
|
+
return _context4.stop();
|
|
304
|
+
}
|
|
305
|
+
}, _callee4);
|
|
306
|
+
}));
|
|
307
|
+
function processInBatches(_x7, _x8, _x9) {
|
|
308
|
+
return _processInBatches.apply(this, arguments);
|
|
309
|
+
}
|
|
310
|
+
return processInBatches;
|
|
311
|
+
}()
|
|
312
|
+
}, {
|
|
313
|
+
key: "withTimeout",
|
|
314
|
+
value: function () {
|
|
315
|
+
var _withTimeout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(promise, timeout, errorMessage) {
|
|
316
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
317
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
318
|
+
case 0:
|
|
319
|
+
return _context5.abrupt("return", Promise.race([promise, new Promise(function (_, reject) {
|
|
320
|
+
return setTimeout(function () {
|
|
321
|
+
return reject(new Error(errorMessage));
|
|
322
|
+
}, timeout);
|
|
323
|
+
})]));
|
|
324
|
+
case 1:
|
|
325
|
+
case "end":
|
|
326
|
+
return _context5.stop();
|
|
327
|
+
}
|
|
328
|
+
}, _callee5);
|
|
329
|
+
}));
|
|
330
|
+
function withTimeout(_x10, _x11, _x12) {
|
|
331
|
+
return _withTimeout.apply(this, arguments);
|
|
332
|
+
}
|
|
333
|
+
return withTimeout;
|
|
334
|
+
}()
|
|
335
|
+
}, {
|
|
336
|
+
key: "cleanupTempDirs",
|
|
337
|
+
value: function () {
|
|
338
|
+
var _cleanupTempDirs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
339
|
+
var _iterator2, _step2, dir;
|
|
340
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
341
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
342
|
+
case 0:
|
|
343
|
+
if (!(this.tempDirs.size === 0)) {
|
|
344
|
+
_context6.next = 2;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
return _context6.abrupt("return");
|
|
348
|
+
case 2:
|
|
349
|
+
console.log(chalk.gray(t('multi.cleanup.start')));
|
|
350
|
+
_iterator2 = _createForOfIteratorHelper(this.tempDirs);
|
|
351
|
+
try {
|
|
352
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
353
|
+
dir = _step2.value;
|
|
354
|
+
try {
|
|
355
|
+
if (existsSync(dir)) {
|
|
356
|
+
rmSync(dir, {
|
|
357
|
+
recursive: true,
|
|
358
|
+
force: true
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.warn("Failed to cleanup ".concat(dir, ":"), error);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} catch (err) {
|
|
366
|
+
_iterator2.e(err);
|
|
367
|
+
} finally {
|
|
368
|
+
_iterator2.f();
|
|
369
|
+
}
|
|
370
|
+
this.tempDirs.clear();
|
|
371
|
+
console.log(chalk.green(t('multi.cleanup.done')));
|
|
372
|
+
case 7:
|
|
373
|
+
case "end":
|
|
374
|
+
return _context6.stop();
|
|
375
|
+
}
|
|
376
|
+
}, _callee6, this);
|
|
377
|
+
}));
|
|
378
|
+
function cleanupTempDirs() {
|
|
379
|
+
return _cleanupTempDirs.apply(this, arguments);
|
|
380
|
+
}
|
|
381
|
+
return cleanupTempDirs;
|
|
382
|
+
}()
|
|
383
|
+
}, {
|
|
384
|
+
key: "registerCleanupHandlers",
|
|
385
|
+
value: function registerCleanupHandlers() {
|
|
386
|
+
var _this2 = this;
|
|
387
|
+
var cleanup = /*#__PURE__*/function () {
|
|
388
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
389
|
+
var _this2$config$remoteC;
|
|
390
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
391
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
392
|
+
case 0:
|
|
393
|
+
if (!((_this2$config$remoteC = _this2.config.remoteCache) !== null && _this2$config$remoteC !== void 0 && _this2$config$remoteC.autoCleanup)) {
|
|
394
|
+
_context7.next = 3;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
_context7.next = 3;
|
|
398
|
+
return _this2.cleanupTempDirs();
|
|
399
|
+
case 3:
|
|
400
|
+
case "end":
|
|
401
|
+
return _context7.stop();
|
|
402
|
+
}
|
|
403
|
+
}, _callee7);
|
|
404
|
+
}));
|
|
405
|
+
return function cleanup() {
|
|
406
|
+
return _ref.apply(this, arguments);
|
|
407
|
+
};
|
|
408
|
+
}();
|
|
409
|
+
|
|
410
|
+
// Only register handlers for interrupt signals
|
|
411
|
+
// Using once() to ensure handlers don't prevent normal exit
|
|
412
|
+
process.once('SIGINT', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
413
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
414
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
415
|
+
case 0:
|
|
416
|
+
_context8.next = 2;
|
|
417
|
+
return cleanup();
|
|
418
|
+
case 2:
|
|
419
|
+
process.exit(130);
|
|
420
|
+
case 3:
|
|
421
|
+
case "end":
|
|
422
|
+
return _context8.stop();
|
|
423
|
+
}
|
|
424
|
+
}, _callee8);
|
|
425
|
+
})));
|
|
426
|
+
process.once('SIGTERM', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
427
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
428
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
429
|
+
case 0:
|
|
430
|
+
_context9.next = 2;
|
|
431
|
+
return cleanup();
|
|
432
|
+
case 2:
|
|
433
|
+
process.exit(143);
|
|
434
|
+
case 3:
|
|
435
|
+
case "end":
|
|
436
|
+
return _context9.stop();
|
|
437
|
+
}
|
|
438
|
+
}, _callee9);
|
|
439
|
+
})));
|
|
440
|
+
|
|
441
|
+
// Note: We don't register uncaughtException handler as it prevents normal process exit
|
|
442
|
+
// Cleanup will still happen via cleanupOnComplete in analyzeAll()
|
|
443
|
+
}
|
|
444
|
+
}]);
|
|
445
|
+
return MultiRepoAnalyzer;
|
|
446
|
+
}();
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface Config {
|
|
|
7
7
|
codeFileExtensions?: string[];
|
|
8
8
|
excludeExtensions?: string[];
|
|
9
9
|
activeUserWeeks?: number;
|
|
10
|
+
autoFetch?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export interface CliOptions {
|
|
12
13
|
repo: string;
|
|
@@ -21,6 +22,7 @@ export interface CliOptions {
|
|
|
21
22
|
verbose?: boolean;
|
|
22
23
|
interactive?: boolean;
|
|
23
24
|
lang?: string;
|
|
25
|
+
noFetch?: boolean;
|
|
24
26
|
}
|
|
25
27
|
export interface CommitInfo {
|
|
26
28
|
hash: string;
|
|
@@ -86,3 +88,47 @@ export interface StatsResult {
|
|
|
86
88
|
proposals: Map<string, ProposalStats>;
|
|
87
89
|
totalCommits: number;
|
|
88
90
|
}
|
|
91
|
+
export interface RepositoryConfig {
|
|
92
|
+
name: string;
|
|
93
|
+
type: 'local' | 'remote';
|
|
94
|
+
path?: string;
|
|
95
|
+
url?: string;
|
|
96
|
+
cloneOptions?: {
|
|
97
|
+
depth?: number | null;
|
|
98
|
+
singleBranch?: boolean;
|
|
99
|
+
};
|
|
100
|
+
branches: string[];
|
|
101
|
+
enabled?: boolean;
|
|
102
|
+
}
|
|
103
|
+
export interface RemoteCacheConfig {
|
|
104
|
+
dir: string;
|
|
105
|
+
autoCleanup: boolean;
|
|
106
|
+
cleanupOnComplete: boolean;
|
|
107
|
+
cleanupOnError: boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface ParallelismConfig {
|
|
110
|
+
maxConcurrent: number;
|
|
111
|
+
timeout: number;
|
|
112
|
+
}
|
|
113
|
+
export interface MultiRepoConfig extends Config {
|
|
114
|
+
mode: 'single-repo' | 'multi-repo';
|
|
115
|
+
repositories?: RepositoryConfig[];
|
|
116
|
+
remoteCache?: RemoteCacheConfig;
|
|
117
|
+
parallelism?: ParallelismConfig;
|
|
118
|
+
}
|
|
119
|
+
export interface RepositoryResult {
|
|
120
|
+
repository: string;
|
|
121
|
+
type: 'local' | 'remote';
|
|
122
|
+
path: string;
|
|
123
|
+
analyses: CommitAnalysis[];
|
|
124
|
+
success: boolean;
|
|
125
|
+
error?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface MultiRepoStatsResult extends StatsResult {
|
|
128
|
+
repositories: string[];
|
|
129
|
+
repositoryDetails: Map<string, {
|
|
130
|
+
type: 'local' | 'remote';
|
|
131
|
+
commits: number;
|
|
132
|
+
error?: string;
|
|
133
|
+
}>;
|
|
134
|
+
}
|