@ranger1/dx 0.1.30 → 0.1.31

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.
@@ -4,7 +4,7 @@ import os from 'node:os'
4
4
 
5
5
  import { logger } from './logger.js'
6
6
 
7
- async function collectMarkdownFiles(dir) {
7
+ async function collectTemplateFiles(dir) {
8
8
  const out = []
9
9
 
10
10
  async function walk(current) {
@@ -18,11 +18,19 @@ async function collectMarkdownFiles(dir) {
18
18
  for (const entry of entries) {
19
19
  const full = join(current, entry.name)
20
20
  if (entry.isDirectory()) {
21
+ // 跳过 __pycache__ 和其他缓存目录
22
+ if (entry.name === '__pycache__' || entry.name === '.pytest_cache') {
23
+ continue
24
+ }
21
25
  await walk(full)
22
26
  continue
23
27
  }
24
28
  if (!entry.isFile()) continue
25
- if (!entry.name.toLowerCase().endsWith('.md')) continue
29
+ const lowerName = entry.name.toLowerCase()
30
+ // 拷贝 .md 和 .py 文件
31
+ if (!lowerName.endsWith('.md') && !lowerName.endsWith('.py')) continue
32
+ // 跳过 Python 编译文件
33
+ if (lowerName.endsWith('.pyc') || lowerName.endsWith('.pyo') || lowerName.endsWith('.pyd')) continue
26
34
  out.push(full)
27
35
  }
28
36
  }
@@ -47,15 +55,30 @@ async function assertDirExists(path, label) {
47
55
  }
48
56
  }
49
57
 
50
- async function copyMarkdownTree({ srcDir, dstDir }) {
51
- const files = await collectMarkdownFiles(srcDir)
58
+ async function copyTemplateTree({ srcDir, dstDir }) {
59
+ const files = await collectTemplateFiles(srcDir)
60
+ let mdCount = 0
61
+ let pyCount = 0
62
+
52
63
  for (const file of files) {
53
64
  const rel = relative(srcDir, file)
54
65
  const target = join(dstDir, rel)
55
66
  await ensureDir(dirname(target))
56
67
  await fs.copyFile(file, target)
68
+
69
+ if (file.endsWith('.md')) {
70
+ mdCount++
71
+ } else if (file.endsWith('.py')) {
72
+ pyCount++
73
+ try {
74
+ await fs.chmod(target, 0o755)
75
+ } catch {
76
+ // 忽略权限设置失败
77
+ }
78
+ }
57
79
  }
58
- return files.length
80
+
81
+ return { total: files.length, md: mdCount, py: pyCount }
59
82
  }
60
83
 
61
84
  function resolveTemplateRoot(packageRoot) {
@@ -98,10 +121,10 @@ export async function runOpenCodeInitial(options = {}) {
98
121
  await ensureDir(dstAgents)
99
122
  await ensureDir(dstCommands)
100
123
 
101
- const agentsCount = await copyMarkdownTree({ srcDir: srcAgents, dstDir: dstAgents })
102
- const commandsCount = await copyMarkdownTree({ srcDir: srcCommands, dstDir: dstCommands })
124
+ const agentsStats = await copyTemplateTree({ srcDir: srcAgents, dstDir: dstAgents })
125
+ const commandsStats = await copyTemplateTree({ srcDir: srcCommands, dstDir: dstCommands })
103
126
 
104
127
  logger.success(`已初始化 OpenCode 模板到: ${dstRoot}`)
105
- logger.info(`agents: ${agentsCount} 个 .md 文件`)
106
- logger.info(`commands: ${commandsCount} 个 .md 文件`)
128
+ logger.info(`agents: ${agentsStats.md} 个 .md 文件${agentsStats.py > 0 ? ` + ${agentsStats.py} 个 .py 文件` : ''}`)
129
+ logger.info(`commands: ${commandsStats.md} 个 .md 文件${commandsStats.py > 0 ? ` + ${commandsStats.py} 个 .py 文件` : ''}`)
107
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {