@dreamor/atlas-cli 0.7.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 (39) hide show
  1. package/README.md +84 -0
  2. package/bin/atlas.js +5 -0
  3. package/dist/adapters/atlas/auth/index.js +2 -0
  4. package/dist/adapters/atlas/auth/login.js +107 -0
  5. package/dist/adapters/atlas/auth/session.js +154 -0
  6. package/dist/adapters/atlas/cli.js +502 -0
  7. package/dist/adapters/atlas/commands/_output_schema.js +100 -0
  8. package/dist/adapters/atlas/commands/actual/_logic.js +41 -0
  9. package/dist/adapters/atlas/commands/actual/index.js +117 -0
  10. package/dist/adapters/atlas/commands/auth.js +1 -0
  11. package/dist/adapters/atlas/commands/baseline/index.js +122 -0
  12. package/dist/adapters/atlas/commands/compare/_logic.js +39 -0
  13. package/dist/adapters/atlas/commands/compare/index.js +72 -0
  14. package/dist/adapters/atlas/commands/exec.js +58 -0
  15. package/dist/adapters/atlas/commands/project/index.js +179 -0
  16. package/dist/adapters/atlas/commands/schema.js +30 -0
  17. package/dist/adapters/atlas/commands/suggest.js +56 -0
  18. package/dist/adapters/atlas/commands/update.js +106 -0
  19. package/dist/adapters/atlas/daemon/index.js +64 -0
  20. package/dist/adapters/atlas/dict/index.js +41 -0
  21. package/dist/adapters/atlas/http/client.js +151 -0
  22. package/dist/adapters/atlas/http/index.js +1 -0
  23. package/dist/adapters/atlas/schema/actual.js +16 -0
  24. package/dist/adapters/atlas/schema/baseline.js +34 -0
  25. package/dist/adapters/atlas/schema/department.js +11 -0
  26. package/dist/adapters/atlas/schema/index.js +4 -0
  27. package/dist/adapters/atlas/schema/project.js +13 -0
  28. package/dist/adapters/atlas/util/constants.js +4 -0
  29. package/dist/adapters/atlas/util/env.js +8 -0
  30. package/dist/adapters/atlas/util/errors.js +45 -0
  31. package/dist/adapters/atlas/util/helpers.js +17 -0
  32. package/dist/adapters/atlas/util/months.js +41 -0
  33. package/dist/adapters/atlas/util/output-limit.js +20 -0
  34. package/dist/adapters/atlas/util/output.js +67 -0
  35. package/dist/adapters/atlas/util/paths.js +40 -0
  36. package/dist/adapters/atlas/util/secure-fs.js +41 -0
  37. package/dist/adapters/atlas/util/time.js +17 -0
  38. package/dist/adapters/atlas/util/version.js +1 -0
  39. package/package.json +54 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 路径工具:集中管理所有文件路径,统一遵从 ATLAS_HOME 环境变量。
3
+ *
4
+ * 避免各文件重复拼 ~/.atlas,避免未来改目录结构时遗漏调用点。
5
+ */
6
+ import { homedir } from 'os';
7
+ import { join, resolve } from 'path';
8
+ /** ~/.atlas 或 $ATLAS_HOME(经 path.resolve 防止相对路径误导) */
9
+ export function getAtlasHome() {
10
+ const raw = process.env.ATLAS_HOME || join(homedir(), '.atlas');
11
+ return resolve(raw);
12
+ }
13
+ /** ~/.atlas/cookies.json */
14
+ export function getCookieFile() {
15
+ return join(getAtlasHome(), 'cookies.json');
16
+ }
17
+ /** ~/.atlas/link.json */
18
+ export function getLinkFile() {
19
+ return join(getAtlasHome(), 'link.json');
20
+ }
21
+ /** ~/.atlas/daemon.token */
22
+ export function getDaemonTokenFile() {
23
+ return join(getAtlasHome(), 'daemon.token');
24
+ }
25
+ /** ~/.atlas/bin */
26
+ export function getBinDir() {
27
+ return join(getAtlasHome(), 'bin');
28
+ }
29
+ /** ~/.atlas/bin/atlas.cjs */
30
+ export function getTargetBinary() {
31
+ return join(getBinDir(), 'atlas.cjs');
32
+ }
33
+ /** ~/.atlas/cache/<key>.json */
34
+ export function getCacheFile(key) {
35
+ return join(getAtlasHome(), 'cache', `${key}.json`);
36
+ }
37
+ /** ~/.atlas/cache */
38
+ export function getCacheDir() {
39
+ return join(getAtlasHome(), 'cache');
40
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 安全文件系统工具。
3
+ *
4
+ * 统一按最小权限原则读写敏感文件:
5
+ * - 目录:0700(drwx------)
6
+ * - 文件:0600(-rw-------)
7
+ *
8
+ * 覆盖已有文件时额外 chmod 兜底。
9
+ */
10
+ import { mkdir, writeFile, chmod } from 'fs/promises';
11
+ import { resolve } from 'path';
12
+ import { ConfigError } from './errors.js';
13
+ /** 安全的目录创建:0700 */
14
+ export async function secureMkdir(dir, opts) {
15
+ await mkdir(dir, { recursive: opts?.recursive ?? true, mode: 0o700 });
16
+ }
17
+ /** 安全的文件写入:0600,覆盖已有 ✓ */
18
+ export async function secureWriteFile(file, data) {
19
+ await writeFile(file, data, { mode: 0o600 });
20
+ await chmod(file, 0o600);
21
+ }
22
+ /**
23
+ * 校验导出路径,防止 --out 任意写(H2 修复)。
24
+ *
25
+ * 策略:
26
+ * - 相对路径:解析为 `{cwd}/{path}`,允许
27
+ * - 绝对路径:必须在 `cwd` 目录树内
28
+ *
29
+ * @param cwdOverride 仅在测试中用于 mock 工作目录
30
+ * 返回解析后的绝对路径(可安全传入 writeFile)。
31
+ * 校验不通过时抛 ConfigError。
32
+ */
33
+ export function resolveSecureExportPath(out, cwdOverride) {
34
+ const currentDir = cwdOverride ?? process.cwd();
35
+ const resolved = resolve(currentDir, out);
36
+ if (!resolved.startsWith(currentDir)) {
37
+ throw new ConfigError(`--out 路径 "${resolved}" 不在当前工作目录 "${currentDir}" 内,已拒绝。` +
38
+ `请将导出文件放在当前目录或子目录中。`);
39
+ }
40
+ return resolved;
41
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 时间工具:处理 CST(UTC+8)时区相关的转换。
3
+ *
4
+ * API 返回的时间戳是中国标准时间(UTC+8)的午夜,
5
+ * 必须加 8h 偏移后取 UTC 年月,否则在非 UTC+8 的机器上月份偏 1。
6
+ */
7
+ /** API 时间戳 → YYYY-MM 月份键,CST 时区安全 */
8
+ export function monthTsToKey(ts) {
9
+ const d = new Date(ts + 8 * 3600 * 1000);
10
+ return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, '0')}`;
11
+ }
12
+ /** 当前月的 YYYY-MM 键 */
13
+ export function currentMonthKey() {
14
+ const d = new Date();
15
+ // 使用本地时间,不偏移;当前月即本地年月
16
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
17
+ }
@@ -0,0 +1 @@
1
+ export const ATLAS_VERSION = '0.7.0';
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dreamor/atlas-cli",
3
+ "version": "0.7.0",
4
+ "description": "Atlas CLI - 斑马云图人力基线管理工具",
5
+ "type": "module",
6
+ "directories": {
7
+ "bin": "bin"
8
+ },
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
12
+ "files": [
13
+ "bin/atlas.js",
14
+ "dist/adapters/**/*.js",
15
+ "!dist/adapters/atlas/tests/**",
16
+ "!dist/adapters/**/tests/**",
17
+ "README.md"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public",
21
+ "registry": "https://registry.npmjs.org/"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/dreamor/atlas-cli.git"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc -p tsconfig.json && rm -rf dist/adapters/atlas/bin && mkdir -p bin && echo '#!/usr/bin/env node\\nimport { buildProgram } from \"../dist/adapters/atlas/cli.js\";\\nconst program = buildProgram();\\nprogram.parse(process.argv);\\n' > bin/atlas.js && chmod +x bin/atlas.js",
29
+ "lint": "tsc --noEmit --pretty false",
30
+ "lint:watch": "tsc --noEmit --pretty false --watch",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest",
33
+ "verify": "node ./dist/adapters/atlas/cli.js --help",
34
+ "auth:login": "node --import tsx ./adapters/atlas/cli.ts auth login"
35
+ },
36
+ "dependencies": {
37
+ "commander": "^14.0.3",
38
+ "papaparse": "^5.5.3",
39
+ "undici": "^7.0.0",
40
+ "zod": "^3.23.8"
41
+ },
42
+ "optionalDependencies": {
43
+ "keytar": "^7.9.0",
44
+ "playwright": "^1.49.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^20.14.0",
48
+ "@types/papaparse": "^5.5.2",
49
+ "esbuild": "^0.28.1",
50
+ "tsx": "^4.19.0",
51
+ "typescript": "^5.6.0",
52
+ "vitest": "^2.1.0"
53
+ }
54
+ }