openspec-stat 1.3.5 → 1.4.0

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.
Files changed (57) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/esm/branch-selector.js +87 -214
  4. package/dist/esm/cli.js +14 -64
  5. package/dist/esm/commands/init.js +17 -44
  6. package/dist/esm/commands/multi.js +123 -180
  7. package/dist/esm/commands/single.js +143 -152
  8. package/dist/esm/config.js +22 -64
  9. package/dist/esm/formatters.js +285 -520
  10. package/dist/esm/git-analyzer.js +116 -354
  11. package/dist/esm/i18n/index.js +22 -10
  12. package/dist/esm/i18n/locales/en.json +43 -43
  13. package/dist/esm/i18n/locales/zh-CN.json +43 -43
  14. package/dist/esm/multi/config-validator.d.ts +1 -1
  15. package/dist/esm/multi/config-validator.js +25 -26
  16. package/dist/esm/multi/config-wizard.js +217 -459
  17. package/dist/esm/multi/multi-repo-analyzer.d.ts +11 -1
  18. package/dist/esm/multi/multi-repo-analyzer.js +228 -426
  19. package/dist/esm/stats-aggregator.js +115 -193
  20. package/dist/esm/time-utils.js +11 -17
  21. package/dist/esm/ui/spinner.d.ts +12 -0
  22. package/dist/esm/ui/spinner.js +38 -0
  23. package/package.json +10 -6
  24. package/dist/cjs/branch-selector.d.ts +0 -7
  25. package/dist/cjs/branch-selector.js +0 -128
  26. package/dist/cjs/cli.d.ts +0 -2
  27. package/dist/cjs/cli.js +0 -19
  28. package/dist/cjs/commands/init.d.ts +0 -7
  29. package/dist/cjs/commands/init.js +0 -58
  30. package/dist/cjs/commands/multi.d.ts +0 -16
  31. package/dist/cjs/commands/multi.js +0 -172
  32. package/dist/cjs/commands/single.d.ts +0 -2
  33. package/dist/cjs/commands/single.js +0 -148
  34. package/dist/cjs/config.d.ts +0 -3
  35. package/dist/cjs/config.js +0 -66
  36. package/dist/cjs/formatters.d.ts +0 -7
  37. package/dist/cjs/formatters.js +0 -482
  38. package/dist/cjs/git-analyzer.d.ts +0 -11
  39. package/dist/cjs/git-analyzer.js +0 -165
  40. package/dist/cjs/i18n/index.d.ts +0 -7
  41. package/dist/cjs/i18n/index.js +0 -84
  42. package/dist/cjs/i18n/locales/en.json +0 -154
  43. package/dist/cjs/i18n/locales/zh-CN.json +0 -154
  44. package/dist/cjs/index.d.ts +0 -6
  45. package/dist/cjs/index.js +0 -50
  46. package/dist/cjs/multi/config-validator.d.ts +0 -3
  47. package/dist/cjs/multi/config-validator.js +0 -130
  48. package/dist/cjs/multi/config-wizard.d.ts +0 -50
  49. package/dist/cjs/multi/config-wizard.js +0 -331
  50. package/dist/cjs/multi/multi-repo-analyzer.d.ts +0 -14
  51. package/dist/cjs/multi/multi-repo-analyzer.js +0 -210
  52. package/dist/cjs/stats-aggregator.d.ts +0 -7
  53. package/dist/cjs/stats-aggregator.js +0 -155
  54. package/dist/cjs/time-utils.d.ts +0 -6
  55. package/dist/cjs/time-utils.js +0 -55
  56. package/dist/cjs/types.d.ts +0 -136
  57. package/dist/cjs/types.js +0 -17
@@ -1,470 +1,228 @@
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 _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; }
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- 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; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
- 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); }
8
- 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); } }
9
- 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); }); }; }
10
1
  import { input, select, confirm } from '@inquirer/prompts';
11
2
  import chalk from 'chalk';
12
3
  import { writeFileSync } from 'fs';
13
4
  import { t } from "../i18n/index.js";
14
- export function runConfigWizard() {
15
- return _runConfigWizard.apply(this, arguments);
16
- }
17
- function _runConfigWizard() {
18
- _runConfigWizard = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
19
- var isMultiRepo,
20
- configName,
21
- singleRepoConfig,
22
- repositories,
23
- addMore,
24
- repo,
25
- timeConfig,
26
- advancedConfig,
27
- config,
28
- confirmed,
29
- _args = arguments;
30
- return _regeneratorRuntime().wrap(function _callee$(_context) {
31
- while (1) switch (_context.prev = _context.next) {
32
- case 0:
33
- isMultiRepo = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
34
- console.log(chalk.blue.bold(isMultiRepo ? t('init.welcomeMulti') : t('init.welcome')));
35
- _context.next = 4;
36
- return input({
37
- message: t('init.configName'),
38
- default: isMultiRepo ? '.openspec-stats.multi.json' : '.openspec-stats.json'
39
- });
40
- case 4:
41
- configName = _context.sent;
42
- if (isMultiRepo) {
43
- _context.next = 11;
44
- break;
45
- }
46
- _context.next = 8;
47
- return createSingleRepoConfig();
48
- case 8:
49
- singleRepoConfig = _context.sent;
50
- saveConfig(configName, singleRepoConfig);
51
- return _context.abrupt("return");
52
- case 11:
53
- repositories = [];
54
- addMore = true;
55
- case 13:
56
- if (!addMore) {
57
- _context.next = 24;
58
- break;
59
- }
60
- console.log(chalk.cyan(t('init.addRepository', {
61
- number: String(repositories.length + 1)
62
- })));
63
- _context.next = 17;
64
- return addRepository();
65
- case 17:
66
- repo = _context.sent;
67
- repositories.push(repo);
68
- _context.next = 21;
69
- return confirm({
70
- message: t('init.addMore'),
71
- default: false
72
- });
73
- case 21:
74
- addMore = _context.sent;
75
- _context.next = 13;
76
- break;
77
- case 24:
78
- console.log(chalk.cyan(t('init.timeConfig')));
79
- _context.next = 27;
80
- return configureTimeRange();
81
- case 27:
82
- timeConfig = _context.sent;
83
- console.log(chalk.cyan(t('init.advanced')));
84
- _context.next = 31;
85
- return configureAdvanced();
86
- case 31:
87
- advancedConfig = _context.sent;
88
- config = _objectSpread(_objectSpread({
89
- mode: 'multi-repo',
90
- repositories: repositories
91
- }, timeConfig), advancedConfig);
92
- console.log(chalk.green(t('init.preview')));
93
- console.log(JSON.stringify(config, null, 2));
94
- _context.next = 37;
95
- return confirm({
96
- message: t('init.save'),
97
- default: true
98
- });
99
- case 37:
100
- confirmed = _context.sent;
101
- if (confirmed) {
102
- saveConfig(configName, config);
103
- console.log(chalk.green(t('init.saved', {
104
- path: configName
105
- })));
106
- console.log(chalk.blue(t('init.runCommand', {
107
- path: configName
108
- })));
109
- }
110
- case 39:
111
- case "end":
112
- return _context.stop();
113
- }
114
- }, _callee);
115
- }));
116
- return _runConfigWizard.apply(this, arguments);
117
- }
118
- function createSingleRepoConfig() {
119
- return _createSingleRepoConfig.apply(this, arguments);
120
- }
121
- function _createSingleRepoConfig() {
122
- _createSingleRepoConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
123
- var timeConfig, branches, advancedConfig;
124
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
125
- while (1) switch (_context2.prev = _context2.next) {
126
- case 0:
127
- console.log(chalk.cyan(t('init.timeConfig')));
128
- _context2.next = 3;
129
- return configureTimeRange();
130
- case 3:
131
- timeConfig = _context2.sent;
132
- _context2.next = 6;
133
- return input({
134
- message: t('init.branches'),
135
- default: 'origin/master'
136
- });
137
- case 6:
138
- branches = _context2.sent;
139
- _context2.next = 9;
140
- return configureAdvanced();
141
- case 9:
142
- advancedConfig = _context2.sent;
143
- return _context2.abrupt("return", _objectSpread(_objectSpread({
144
- defaultBranches: branches.split(',').map(function (b) {
145
- return b.trim();
146
- }).filter(Boolean)
147
- }, timeConfig), advancedConfig));
148
- case 11:
149
- case "end":
150
- return _context2.stop();
151
- }
152
- }, _callee2);
153
- }));
154
- return _createSingleRepoConfig.apply(this, arguments);
155
- }
156
- function addRepository() {
157
- return _addRepository.apply(this, arguments);
158
- }
159
- function _addRepository() {
160
- _addRepository = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
161
- var type, name, repo, useFullClone, depth, branchInput;
162
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
163
- while (1) switch (_context3.prev = _context3.next) {
164
- case 0:
165
- _context3.next = 2;
166
- return select({
167
- message: t('init.repoType'),
168
- choices: [{
169
- name: t('init.repoType.local'),
170
- value: 'local'
171
- }, {
172
- name: t('init.repoType.remote'),
173
- value: 'remote'
174
- }]
175
- });
176
- case 2:
177
- type = _context3.sent;
178
- _context3.next = 5;
179
- return input({
180
- message: t('init.repoName'),
181
- validate: function validate(value) {
182
- return value.length > 0 || 'Name is required';
183
- }
184
- });
185
- case 5:
186
- name = _context3.sent;
187
- repo = {
188
- name: name,
189
- type: type,
190
- branches: []
191
- };
192
- if (!(type === 'local')) {
193
- _context3.next = 13;
194
- break;
195
- }
196
- _context3.next = 10;
197
- return input({
198
- message: t('init.repoPath'),
199
- default: '.',
200
- validate: function validate(value) {
201
- return value.length > 0 || 'Path is required';
202
- }
203
- });
204
- case 10:
205
- repo.path = _context3.sent;
206
- _context3.next = 27;
207
- break;
208
- case 13:
209
- _context3.next = 15;
210
- return input({
211
- message: t('init.repoUrl'),
212
- validate: function validate(value) {
213
- if (!value.length) return 'URL is required';
214
- if (!value.match(/^(git@|https:\/\/)/)) {
215
- return t('init.repoUrlInvalid');
216
- }
217
- return true;
218
- }
219
- });
220
- case 15:
221
- repo.url = _context3.sent;
222
- _context3.next = 18;
223
- return confirm({
224
- message: t('init.useFullClone'),
225
- default: true
226
- });
227
- case 18:
228
- useFullClone = _context3.sent;
229
- if (useFullClone) {
230
- _context3.next = 26;
231
- break;
232
- }
233
- _context3.next = 22;
234
- return input({
235
- message: t('init.cloneDepth'),
236
- default: '100',
237
- validate: function validate(value) {
238
- return !isNaN(Number(value)) || 'Must be a number';
239
- }
240
- });
241
- case 22:
242
- depth = _context3.sent;
243
- repo.cloneOptions = {
244
- depth: Number(depth)
245
- };
246
- _context3.next = 27;
247
- break;
248
- case 26:
249
- repo.cloneOptions = {
250
- depth: null
251
- };
252
- case 27:
253
- _context3.next = 29;
254
- return input({
255
- message: t('init.branches'),
256
- default: 'origin/master'
257
- });
258
- case 29:
259
- branchInput = _context3.sent;
260
- repo.branches = branchInput.split(',').map(function (b) {
261
- return b.trim();
262
- }).filter(Boolean);
263
- return _context3.abrupt("return", repo);
264
- case 32:
265
- case "end":
266
- return _context3.stop();
267
- }
268
- }, _callee3);
269
- }));
270
- return _addRepository.apply(this, arguments);
5
+ export async function runConfigWizard(isMultiRepo = false) {
6
+ console.log(chalk.blue.bold(isMultiRepo ? t('init.welcomeMulti') : t('init.welcome')));
7
+ const configName = await input({
8
+ message: t('init.configName'),
9
+ default: isMultiRepo ? '.openspec-stats.multi.json' : '.openspec-stats.json'
10
+ });
11
+ if (!isMultiRepo) {
12
+ const singleRepoConfig = await createSingleRepoConfig();
13
+ saveConfig(configName, singleRepoConfig);
14
+ return;
15
+ }
16
+ const repositories = [];
17
+ let addMore = true;
18
+ while (addMore) {
19
+ console.log(chalk.cyan(t('init.addRepository', {
20
+ number: String(repositories.length + 1)
21
+ })));
22
+ const repo = await addRepository();
23
+ repositories.push(repo);
24
+ addMore = await confirm({
25
+ message: t('init.addMore'),
26
+ default: false
27
+ });
28
+ }
29
+ console.log(chalk.cyan(t('init.timeConfig')));
30
+ const timeConfig = await configureTimeRange();
31
+ console.log(chalk.cyan(t('init.advanced')));
32
+ const advancedConfig = await configureAdvanced();
33
+ const config = {
34
+ mode: 'multi-repo',
35
+ repositories,
36
+ ...timeConfig,
37
+ ...advancedConfig
38
+ };
39
+ console.log(chalk.green(t('init.preview')));
40
+ console.log(JSON.stringify(config, null, 2));
41
+ const confirmed = await confirm({
42
+ message: t('init.save'),
43
+ default: true
44
+ });
45
+ if (confirmed) {
46
+ saveConfig(configName, config);
47
+ console.log(chalk.green(t('init.saved', {
48
+ path: configName
49
+ })));
50
+ console.log(chalk.blue(t('init.runCommand', {
51
+ path: configName
52
+ })));
53
+ }
271
54
  }
272
- function configureTimeRange() {
273
- return _configureTimeRange.apply(this, arguments);
55
+ async function createSingleRepoConfig() {
56
+ console.log(chalk.cyan(t('init.timeConfig')));
57
+ const timeConfig = await configureTimeRange();
58
+ const branches = await input({
59
+ message: t('init.branches'),
60
+ default: 'origin/master'
61
+ });
62
+ const advancedConfig = await configureAdvanced();
63
+ return {
64
+ defaultBranches: branches.split(',').map(b => b.trim()).filter(Boolean),
65
+ ...timeConfig,
66
+ ...advancedConfig
67
+ };
274
68
  }
275
- function _configureTimeRange() {
276
- _configureTimeRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
277
- var useDefault, sinceHours, untilHours;
278
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
279
- while (1) switch (_context4.prev = _context4.next) {
280
- case 0:
281
- _context4.next = 2;
282
- return confirm({
283
- message: t('init.useDefaultTime'),
284
- default: true
285
- });
286
- case 2:
287
- useDefault = _context4.sent;
288
- if (!useDefault) {
289
- _context4.next = 5;
290
- break;
291
- }
292
- return _context4.abrupt("return", {
293
- defaultSinceHours: -30,
294
- defaultUntilHours: 20
295
- });
296
- case 5:
297
- _context4.next = 7;
298
- return input({
299
- message: t('init.sinceHours'),
300
- default: '-30',
301
- validate: function validate(value) {
302
- return !isNaN(Number(value)) || 'Must be a number';
303
- }
304
- });
305
- case 7:
306
- sinceHours = _context4.sent;
307
- _context4.next = 10;
308
- return input({
309
- message: t('init.untilHours'),
310
- default: '20',
311
- validate: function validate(value) {
312
- var num = Number(value);
313
- return !isNaN(num) && num >= 0 && num <= 23 || 'Must be 0-23';
314
- }
315
- });
316
- case 10:
317
- untilHours = _context4.sent;
318
- return _context4.abrupt("return", {
319
- defaultSinceHours: Number(sinceHours),
320
- defaultUntilHours: Number(untilHours)
321
- });
322
- case 12:
323
- case "end":
324
- return _context4.stop();
69
+ async function addRepository() {
70
+ const type = await select({
71
+ message: t('init.repoType'),
72
+ choices: [{
73
+ name: t('init.repoType.local'),
74
+ value: 'local'
75
+ }, {
76
+ name: t('init.repoType.remote'),
77
+ value: 'remote'
78
+ }]
79
+ });
80
+ const name = await input({
81
+ message: t('init.repoName'),
82
+ validate: value => value.length > 0 || 'Name is required'
83
+ });
84
+ const repo = {
85
+ name,
86
+ type: type,
87
+ branches: []
88
+ };
89
+ if (type === 'local') {
90
+ repo.path = await input({
91
+ message: t('init.repoPath'),
92
+ default: '.',
93
+ validate: value => value.length > 0 || 'Path is required'
94
+ });
95
+ } else {
96
+ repo.url = await input({
97
+ message: t('init.repoUrl'),
98
+ validate: value => {
99
+ if (!value.length) return 'URL is required';
100
+ if (!value.match(/^(git@|https:\/\/)/)) {
101
+ return t('init.repoUrlInvalid');
102
+ }
103
+ return true;
325
104
  }
326
- }, _callee4);
327
- }));
328
- return _configureTimeRange.apply(this, arguments);
329
- }
330
- function configureAdvanced() {
331
- return _configureAdvanced.apply(this, arguments);
105
+ });
106
+ const useFullClone = await confirm({
107
+ message: t('init.useFullClone'),
108
+ default: true
109
+ });
110
+ if (!useFullClone) {
111
+ const depth = await input({
112
+ message: t('init.cloneDepth'),
113
+ default: '100',
114
+ validate: value => !isNaN(Number(value)) || 'Must be a number'
115
+ });
116
+ repo.cloneOptions = {
117
+ depth: Number(depth)
118
+ };
119
+ } else {
120
+ repo.cloneOptions = {
121
+ depth: null
122
+ };
123
+ }
124
+ }
125
+ const branchInput = await input({
126
+ message: t('init.branches'),
127
+ default: 'origin/master'
128
+ });
129
+ repo.branches = branchInput.split(',').map(b => b.trim()).filter(Boolean);
130
+ return repo;
332
131
  }
333
- function _configureAdvanced() {
334
- _configureAdvanced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
335
- var configureAdvanced, config, maxConcurrent, addAuthorMapping;
336
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
337
- while (1) switch (_context5.prev = _context5.next) {
338
- case 0:
339
- _context5.next = 2;
340
- return confirm({
341
- message: t('init.configureAdvanced'),
342
- default: false
343
- });
344
- case 2:
345
- configureAdvanced = _context5.sent;
346
- if (configureAdvanced) {
347
- _context5.next = 5;
348
- break;
349
- }
350
- return _context5.abrupt("return", getDefaultAdvancedConfig());
351
- case 5:
352
- config = {};
353
- _context5.next = 8;
354
- return input({
355
- message: t('init.openspecDir'),
356
- default: 'openspec/'
357
- });
358
- case 8:
359
- config.openspecDir = _context5.sent;
360
- _context5.next = 11;
361
- return input({
362
- message: t('init.maxConcurrent'),
363
- default: '3',
364
- validate: function validate(value) {
365
- var num = Number(value);
366
- return !isNaN(num) && num > 0 || 'Must be positive number';
367
- }
368
- });
369
- case 11:
370
- maxConcurrent = _context5.sent;
371
- config.parallelism = {
372
- maxConcurrent: Number(maxConcurrent),
373
- timeout: 600000
374
- };
375
- config.remoteCache = {
376
- dir: '/tmp/openspec-stat-cache',
377
- autoCleanup: true,
378
- cleanupOnComplete: true,
379
- cleanupOnError: true
380
- };
381
- config.excludeExtensions = ['.md', '.txt', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.webp'];
382
- config.activeUserWeeks = 2;
383
- _context5.next = 18;
384
- return confirm({
385
- message: t('init.authorMapping'),
386
- default: false
387
- });
388
- case 18:
389
- addAuthorMapping = _context5.sent;
390
- if (!addAuthorMapping) {
391
- _context5.next = 25;
392
- break;
393
- }
394
- _context5.next = 22;
395
- return configureAuthorMapping();
396
- case 22:
397
- config.authorMapping = _context5.sent;
398
- _context5.next = 26;
399
- break;
400
- case 25:
401
- config.authorMapping = {};
402
- case 26:
403
- return _context5.abrupt("return", config);
404
- case 27:
405
- case "end":
406
- return _context5.stop();
407
- }
408
- }, _callee5);
409
- }));
410
- return _configureAdvanced.apply(this, arguments);
132
+ async function configureTimeRange() {
133
+ const useDefault = await confirm({
134
+ message: t('init.useDefaultTime'),
135
+ default: true
136
+ });
137
+ if (useDefault) {
138
+ return {
139
+ defaultSinceHours: -30,
140
+ defaultUntilHours: 20
141
+ };
142
+ }
143
+ const sinceHours = await input({
144
+ message: t('init.sinceHours'),
145
+ default: '-30',
146
+ validate: value => !isNaN(Number(value)) || 'Must be a number'
147
+ });
148
+ const untilHours = await input({
149
+ message: t('init.untilHours'),
150
+ default: '20',
151
+ validate: value => {
152
+ const num = Number(value);
153
+ return !isNaN(num) && num >= 0 && num <= 23 || 'Must be 0-23';
154
+ }
155
+ });
156
+ return {
157
+ defaultSinceHours: Number(sinceHours),
158
+ defaultUntilHours: Number(untilHours)
159
+ };
411
160
  }
412
- function configureAuthorMapping() {
413
- return _configureAuthorMapping.apply(this, arguments);
161
+ async function configureAdvanced() {
162
+ const configureAdvanced = await confirm({
163
+ message: t('init.configureAdvanced'),
164
+ default: false
165
+ });
166
+ if (!configureAdvanced) {
167
+ return getDefaultAdvancedConfig();
168
+ }
169
+ const config = {};
170
+ config.openspecDir = await input({
171
+ message: t('init.openspecDir'),
172
+ default: 'openspec/'
173
+ });
174
+ const maxConcurrent = await input({
175
+ message: t('init.maxConcurrent'),
176
+ default: '3',
177
+ validate: value => {
178
+ const num = Number(value);
179
+ return !isNaN(num) && num > 0 || 'Must be positive number';
180
+ }
181
+ });
182
+ config.parallelism = {
183
+ maxConcurrent: Number(maxConcurrent),
184
+ timeout: 600000
185
+ };
186
+ config.remoteCache = {
187
+ dir: '/tmp/openspec-stat-cache',
188
+ autoCleanup: true,
189
+ cleanupOnComplete: true,
190
+ cleanupOnError: true
191
+ };
192
+ config.excludeExtensions = ['.md', '.txt', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.webp'];
193
+ config.activeUserWeeks = 2;
194
+ const addAuthorMapping = await confirm({
195
+ message: t('init.authorMapping'),
196
+ default: false
197
+ });
198
+ if (addAuthorMapping) {
199
+ config.authorMapping = await configureAuthorMapping();
200
+ } else {
201
+ config.authorMapping = {};
202
+ }
203
+ return config;
414
204
  }
415
- function _configureAuthorMapping() {
416
- _configureAuthorMapping = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
417
- var mapping, addMore, gitIdentity, unifiedName;
418
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
419
- while (1) switch (_context6.prev = _context6.next) {
420
- case 0:
421
- console.log(chalk.gray(t('init.authorMappingInfo')));
422
- mapping = {};
423
- addMore = true;
424
- case 3:
425
- if (!addMore) {
426
- _context6.next = 18;
427
- break;
428
- }
429
- _context6.next = 6;
430
- return input({
431
- message: t('init.gitIdentity')
432
- });
433
- case 6:
434
- gitIdentity = _context6.sent;
435
- if (gitIdentity) {
436
- _context6.next = 9;
437
- break;
438
- }
439
- return _context6.abrupt("break", 18);
440
- case 9:
441
- _context6.next = 11;
442
- return input({
443
- message: t('init.unifiedName', {
444
- identity: gitIdentity
445
- })
446
- });
447
- case 11:
448
- unifiedName = _context6.sent;
449
- mapping[gitIdentity] = unifiedName;
450
- _context6.next = 15;
451
- return confirm({
452
- message: t('init.addMoreMapping'),
453
- default: false
454
- });
455
- case 15:
456
- addMore = _context6.sent;
457
- _context6.next = 3;
458
- break;
459
- case 18:
460
- return _context6.abrupt("return", mapping);
461
- case 19:
462
- case "end":
463
- return _context6.stop();
464
- }
465
- }, _callee6);
466
- }));
467
- return _configureAuthorMapping.apply(this, arguments);
205
+ async function configureAuthorMapping() {
206
+ console.log(chalk.gray(t('init.authorMappingInfo')));
207
+ const mapping = {};
208
+ let addMore = true;
209
+ while (addMore) {
210
+ const gitIdentity = await input({
211
+ message: t('init.gitIdentity')
212
+ });
213
+ if (!gitIdentity) break;
214
+ const unifiedName = await input({
215
+ message: t('init.unifiedName', {
216
+ identity: gitIdentity
217
+ })
218
+ });
219
+ mapping[gitIdentity] = unifiedName;
220
+ addMore = await confirm({
221
+ message: t('init.addMoreMapping'),
222
+ default: false
223
+ });
224
+ }
225
+ return mapping;
468
226
  }
469
227
  function getDefaultAdvancedConfig() {
470
228
  return {
@@ -487,7 +245,7 @@ function getDefaultAdvancedConfig() {
487
245
  function saveConfig(path, config) {
488
246
  writeFileSync(path, JSON.stringify(config, null, 2));
489
247
  }
490
- export var SINGLE_REPO_TEMPLATE = {
248
+ export const SINGLE_REPO_TEMPLATE = {
491
249
  defaultBranches: ['origin/master'],
492
250
  defaultSinceHours: -30,
493
251
  defaultUntilHours: 20,
@@ -499,7 +257,7 @@ export var SINGLE_REPO_TEMPLATE = {
499
257
  excludeExtensions: ['.md', '.txt', '.png', '.jpg'],
500
258
  activeUserWeeks: 2
501
259
  };
502
- export var MULTI_REPO_TEMPLATE = {
260
+ export const MULTI_REPO_TEMPLATE = {
503
261
  mode: 'multi-repo',
504
262
  repositories: [{
505
263
  name: 'example-local-repo',