@dreamor/atlas-cli 0.7.10 → 0.7.11

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.
@@ -2,7 +2,7 @@ import { createClient } from '../../http/client.js';
2
2
  import { isJsonMode, jsonOk, log } from '../../util/output.js';
3
3
  import { enforceOutputLimit } from '../../util/output-limit.js';
4
4
  import { SessionExpiredError } from '../../util/errors.js';
5
- import { expandMonths } from '../../util/months.js';
5
+ import { expandMonths, expandMonthsDefault } from '../../util/months.js';
6
6
  import { resolveSecureExportPath, secureWriteFile } from '../../util/secure-fs.js';
7
7
  import { annotateWithMonth, aggregateByAxis, filterByStaff, } from './_logic.js';
8
8
  import { resolveProjectId } from '../../util/env.js';
@@ -16,7 +16,7 @@ async function fetchActual(pid, month) {
16
16
  }
17
17
  export async function showCmd(staffId, opts) {
18
18
  const pid = getProjectId(opts);
19
- const m = opts.month ?? expandMonths()[0];
19
+ const m = opts.month ?? expandMonthsDefault()[0];
20
20
  const data = await fetchActual(pid, m);
21
21
  const filtered = filterByStaff(data, staffId);
22
22
  if (opts.json || isJsonMode()) {
@@ -33,7 +33,8 @@ export async function showCmd(staffId, opts) {
33
33
  }
34
34
  export async function monthCmd(opts) {
35
35
  const pid = getProjectId(opts);
36
- const months = opts.month ? [opts.month] : expandMonths(opts.from, opts.to);
36
+ // 不传月份时默认最近 12 个月,与 baseline month 行为一致
37
+ const months = opts.month ? [opts.month] : (opts.from || opts.to ? expandMonths(opts.from, opts.to) : expandMonthsDefault());
37
38
  const all = [];
38
39
  const failedMonths = [];
39
40
  for (const m of months) {
@@ -62,7 +63,7 @@ export async function monthCmd(opts) {
62
63
  }
63
64
  export async function summaryCmd(opts) {
64
65
  const pid = getProjectId(opts);
65
- const months = opts.month ? [opts.month] : expandMonths(opts.from, opts.to);
66
+ const months = opts.month ? [opts.month] : (opts.from || opts.to ? expandMonths(opts.from, opts.to) : expandMonthsDefault());
66
67
  const all = [];
67
68
  const failedMonths = [];
68
69
  for (const m of months) {
@@ -4,7 +4,11 @@ import { enforceOutputLimit } from '../../util/output-limit.js';
4
4
  import { expandMonths } from '../../util/months.js';
5
5
  import { monthTsToKey } from '../../util/time.js';
6
6
  import { resolveSecureExportPath, secureWriteFile } from '../../util/secure-fs.js';
7
- import { resolveProjectId } from '../../util/env.js';
7
+ import { resolveProjectId, resolveProjectInfo } from '../../util/env.js';
8
+ function getProjectDisplay(opts) {
9
+ const info = resolveProjectInfo(opts.projectId);
10
+ return info.name ?? info.id;
11
+ }
8
12
  function getProjectId(opts) {
9
13
  return resolveProjectId(opts.projectId);
10
14
  }
@@ -54,7 +58,7 @@ export async function monthCmd(opts) {
54
58
  jsonOk({ projectId: pid, months: monthKeys, entries: allDetails, totalManpower: Math.round(total * 100) / 100 });
55
59
  return;
56
60
  }
57
- log(`项目 ${pid} 基线人力:`);
61
+ log(`项目 ${getProjectDisplay(opts)} 基线人力:`);
58
62
  for (const m of monthKeys) {
59
63
  log(` ${m}: ${(byMonth.get(m) ?? 0).toFixed(2)} 人月`);
60
64
  }
@@ -4,7 +4,7 @@ import { ConfigError, SessionExpiredError } from '../../util/errors.js';
4
4
  import { expandMonths } from '../../util/months.js';
5
5
  import { monthTsToKey } from '../../util/time.js';
6
6
  import { groupByAxis, mergeBaselineActual, } from './_logic.js';
7
- import { resolveProjectId } from '../../util/env.js';
7
+ import { resolveProjectId, resolveProjectInfo } from '../../util/env.js';
8
8
  function getProjectId(opts) {
9
9
  return resolveProjectId(opts.projectId);
10
10
  }
@@ -61,7 +61,8 @@ export async function compareCmd(opts) {
61
61
  jsonOk({ rows }, { failedMonths });
62
62
  return;
63
63
  }
64
- log(`项目 ${pid} 对比:${axis === 'month' ? '按月份' : axis === 'department' ? '按部门' : '按角色'}`);
64
+ const pinfo = resolveProjectInfo(opts.projectId);
65
+ log(`项目 ${pinfo.name ?? pid} 对比:${axis === 'month' ? '按月份' : axis === 'department' ? '按部门' : '按角色'}`);
65
66
  for (const r of rows) {
66
67
  const flag = opts.flagOverrun && r.actualManpower > r.baselineManpower ? ' ⚠️' : '';
67
68
  log(` ${String(r[axis])}: 基线 ${r.baselineManpower} / 实际 ${r.actualManpower} / 差异 ${r.diff > 0 ? '+' : ''}${r.diff}${flag}`);
@@ -29,6 +29,27 @@ export function resolveProjectId(cliProjectId) {
29
29
  }
30
30
  throw new ConfigError('请指定 --project-id、设置 BANMA_PROJECT_ID、或先用 atlas link <project> 绑定项目');
31
31
  }
32
+ /**
33
+ * 解析项目信息(ID + 名称),优先级同上。名称仅从 link 文件获取。
34
+ */
35
+ export function resolveProjectInfo(cliProjectId) {
36
+ if (cliProjectId)
37
+ return { id: cliProjectId };
38
+ if (process.env.BANMA_PROJECT_ID)
39
+ return { id: process.env.BANMA_PROJECT_ID };
40
+ try {
41
+ const linkFile = getLinkFile();
42
+ if (existsSync(linkFile)) {
43
+ const link = JSON.parse(readFileSync(linkFile, 'utf-8'));
44
+ if (link.projectId)
45
+ return { id: link.projectId, name: link.projectName };
46
+ }
47
+ }
48
+ catch {
49
+ // ignore
50
+ }
51
+ throw new ConfigError('请指定 --project-id、设置 BANMA_PROJECT_ID、或先用 atlas link <project> 绑定项目');
52
+ }
32
53
  /** 是否禁用自动升级 */
33
54
  export function isUpdateDisabled() {
34
55
  return process.env.ATLAS_DISABLE_UPDATE === '1';
@@ -39,3 +39,27 @@ export function expandMonths(from, to) {
39
39
  }
40
40
  return months;
41
41
  }
42
+ /**
43
+ * 不传月份时的默认范围:当前月及前后各 12 个月(最多 25 个月,低于 MAX_MONTHS)。
44
+ * 使 actual month 无参数时与 baseline month 行为一致。
45
+ */
46
+ export function expandMonthsDefault() {
47
+ const now = new Date();
48
+ const cy = now.getFullYear();
49
+ const cm = now.getMonth() + 1;
50
+ // 12 个月前
51
+ let fy = cy, fm = cm - 12;
52
+ while (fm < 1) {
53
+ fm += 12;
54
+ fy--;
55
+ }
56
+ // 12 个月后
57
+ let ty = cy, tm = cm + 12;
58
+ while (tm > 12) {
59
+ tm -= 12;
60
+ ty++;
61
+ }
62
+ const from = `${fy}-${String(fm).padStart(2, '0')}`;
63
+ const to = `${ty}-${String(tm).padStart(2, '0')}`;
64
+ return expandMonths(from, to);
65
+ }
@@ -1 +1 @@
1
- export const ATLAS_VERSION = '0.7.10';
1
+ export const ATLAS_VERSION = '0.7.11';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamor/atlas-cli",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "description": "Atlas CLI - 斑马云图人力基线管理工具",
5
5
  "type": "module",
6
6
  "bin": {