@dreamor/atlas-cli 0.7.8 → 0.7.10

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.
@@ -1,19 +1,18 @@
1
1
  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
- import { ConfigError, SessionExpiredError } from '../../util/errors.js';
4
+ import { SessionExpiredError } from '../../util/errors.js';
5
5
  import { expandMonths } from '../../util/months.js';
6
6
  import { resolveSecureExportPath, secureWriteFile } from '../../util/secure-fs.js';
7
7
  import { annotateWithMonth, aggregateByAxis, filterByStaff, } from './_logic.js';
8
+ import { resolveProjectId } from '../../util/env.js';
8
9
  function getProjectId(opts) {
9
- const pid = opts.projectId ?? process.env.BANMA_PROJECT_ID ?? '';
10
- if (!pid)
11
- throw new ConfigError('请指定 --project-id 或设置 BANMA_PROJECT_ID 环境变量');
12
- return pid;
10
+ return resolveProjectId(opts.projectId);
13
11
  }
14
12
  async function fetchActual(pid, month) {
15
13
  const client = createClient();
16
- return client.post('/yuntu-service/manpower/weekly/summaryByTeam.json', { projectId: pid, month });
14
+ const data = await client.post('/yuntu-service/manpower/weekly/summaryByTeam.json', { projectId: pid, month });
15
+ return data ?? [];
17
16
  }
18
17
  export async function showCmd(staffId, opts) {
19
18
  const pid = getProjectId(opts);
@@ -1,15 +1,12 @@
1
1
  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
- import { ConfigError } from '../../util/errors.js';
5
4
  import { expandMonths } from '../../util/months.js';
6
5
  import { monthTsToKey } from '../../util/time.js';
7
6
  import { resolveSecureExportPath, secureWriteFile } from '../../util/secure-fs.js';
7
+ import { resolveProjectId } from '../../util/env.js';
8
8
  function getProjectId(opts) {
9
- const pid = opts.projectId ?? process.env.BANMA_PROJECT_ID ?? '';
10
- if (!pid)
11
- throw new ConfigError('请指定 --project-id 或设置 BANMA_PROJECT_ID 环境变量');
12
- return pid;
9
+ return resolveProjectId(opts.projectId);
13
10
  }
14
11
  /**
15
12
  * 月基线 API 返回 data 为数组,每项含 linePlanMonthDetailList
@@ -4,11 +4,9 @@ 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
8
  function getProjectId(opts) {
8
- const pid = opts.projectId ?? process.env.BANMA_PROJECT_ID ?? '';
9
- if (!pid)
10
- throw new ConfigError('请指定 --project-id 或设置 BANMA_PROJECT_ID 环境变量');
11
- return pid;
9
+ return resolveProjectId(opts.projectId);
12
10
  }
13
11
  export async function compareCmd(opts) {
14
12
  const pid = getProjectId(opts);
@@ -1,7 +1,34 @@
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { getLinkFile } from './paths.js';
3
+ import { ConfigError } from './errors.js';
1
4
  /** 获取 BANMA_PROJECT_ID 环境变量 */
2
5
  export function getBanmaProjectId() {
3
6
  return process.env.BANMA_PROJECT_ID;
4
7
  }
8
+ /**
9
+ * 解析项目 ID,优先级:
10
+ * 1. 命令行 --project-id 参数
11
+ * 2. BANMA_PROJECT_ID 环境变量
12
+ * 3. ~/.atlas/link.json(atlas link 绑定的项目)
13
+ */
14
+ export function resolveProjectId(cliProjectId) {
15
+ if (cliProjectId)
16
+ return cliProjectId;
17
+ if (process.env.BANMA_PROJECT_ID)
18
+ return process.env.BANMA_PROJECT_ID;
19
+ try {
20
+ const linkFile = getLinkFile();
21
+ if (existsSync(linkFile)) {
22
+ const link = JSON.parse(readFileSync(linkFile, 'utf-8'));
23
+ if (link.projectId)
24
+ return link.projectId;
25
+ }
26
+ }
27
+ catch {
28
+ // ignore
29
+ }
30
+ throw new ConfigError('请指定 --project-id、设置 BANMA_PROJECT_ID、或先用 atlas link <project> 绑定项目');
31
+ }
5
32
  /** 是否禁用自动升级 */
6
33
  export function isUpdateDisabled() {
7
34
  return process.env.ATLAS_DISABLE_UPDATE === '1';
@@ -1 +1 @@
1
- export const ATLAS_VERSION = '0.7.8';
1
+ export const ATLAS_VERSION = '0.7.10';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamor/atlas-cli",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "Atlas CLI - 斑马云图人力基线管理工具",
5
5
  "type": "module",
6
6
  "bin": {