@vibecuting/component-project-helper 0.1.12 → 0.1.14
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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/scripts/discover-components.mjs +4 -0
- package/scripts/postinstall.mjs +29 -11
- package/scripts/runtime-root.mjs +4 -1
- package/src/discovery/index.test.ts +33 -0
- package/src/discovery/index.ts +4 -0
- package/src/lifecycle/postinstall.ts +29 -11
- package/src/runtime/index.test.ts +26 -0
- package/src/runtime/index.ts +4 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ NPM 地址:
|
|
|
10
10
|
|
|
11
11
|
- 作为可发布的 npm 包承载组件工程辅助逻辑。
|
|
12
12
|
- 提供组件注解、schema、发现器、Markdown 生成和安装期生命周期逻辑。
|
|
13
|
-
-
|
|
13
|
+
- 安装时会优先把当前工程识别为包含 `src/components` 或 `src/video/chapters` 的独立项目,再扫描 `src/components/**/*.tsx`、`src/video/chapters/**/*.tsx` 以及 `node_modules/@vibecuting/*/src/**/*.tsx`,把组件元数据生成到 `.agents/skills/project-allow-component/components/`。
|
|
14
14
|
- 通过 `postinstall` / `preuninstall` 维护生成文件和清理清单。
|
|
15
15
|
- 安装时会给宿主工程的 `package.json` 补上 `update-component-skills`,它会调用同一套 `postinstall` 逻辑。
|
|
16
16
|
- 宿主工程也可以直接运行 `pnpm update-component-skills` 手动刷新同一套生成结果。
|
package/package.json
CHANGED
package/scripts/postinstall.mjs
CHANGED
|
@@ -11,6 +11,16 @@ import {
|
|
|
11
11
|
import { renderComponentProjectMarkdown } from './render-markdown.mjs'
|
|
12
12
|
import { ComponentProjectGeneratedManifestSchema } from './schemas.mjs'
|
|
13
13
|
|
|
14
|
+
const supportsColor =
|
|
15
|
+
Boolean(process.stdout.isTTY) && process.env.NO_COLOR !== '1' && process.env.CI !== 'true'
|
|
16
|
+
|
|
17
|
+
const color = {
|
|
18
|
+
cyan: (value) => (supportsColor ? `\u001b[36m${value}\u001b[0m` : value),
|
|
19
|
+
green: (value) => (supportsColor ? `\u001b[32m${value}\u001b[0m` : value),
|
|
20
|
+
yellow: (value) => (supportsColor ? `\u001b[33m${value}\u001b[0m` : value),
|
|
21
|
+
dim: (value) => (supportsColor ? `\u001b[2m${value}\u001b[0m` : value),
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
async function ensureDirectory(dir) {
|
|
15
25
|
await fs.mkdir(dir, { recursive: true })
|
|
16
26
|
}
|
|
@@ -34,14 +44,16 @@ export async function runComponentProjectPostinstall(projectRoot = resolveCompon
|
|
|
34
44
|
const manifestPath = resolveComponentProjectGeneratedManifestPath(projectRoot)
|
|
35
45
|
const components = await discoverComponentProjectComponents(projectRoot)
|
|
36
46
|
|
|
37
|
-
console.log('[component-project-helper] postinstall start')
|
|
38
|
-
console.log(`[component-project-helper] project root: ${projectRoot}`)
|
|
39
|
-
console.log(`[component-project-helper] docs dir: ${docsDir}`)
|
|
40
|
-
console.log(`[component-project-helper] manifest path: ${manifestPath}`)
|
|
47
|
+
console.log(color.cyan('[component-project-helper] postinstall start'))
|
|
48
|
+
console.log(color.dim(`[component-project-helper] project root: ${projectRoot}`))
|
|
49
|
+
console.log(color.dim(`[component-project-helper] docs dir: ${docsDir}`))
|
|
50
|
+
console.log(color.dim(`[component-project-helper] manifest path: ${manifestPath}`))
|
|
41
51
|
console.log(
|
|
42
|
-
|
|
52
|
+
color.green(
|
|
53
|
+
`[component-project-helper] discovered ${components.length} component(s): ${
|
|
43
54
|
components.map((component) => component.name).join(', ') || '(none)'
|
|
44
|
-
|
|
55
|
+
}`,
|
|
56
|
+
),
|
|
45
57
|
)
|
|
46
58
|
|
|
47
59
|
await ensureDirectory(docsDir)
|
|
@@ -52,19 +64,23 @@ export async function runComponentProjectPostinstall(projectRoot = resolveCompon
|
|
|
52
64
|
await fs.writeFile(filePath, renderComponentProjectMarkdown(component), 'utf8')
|
|
53
65
|
files.push(filePath)
|
|
54
66
|
console.log(
|
|
55
|
-
|
|
67
|
+
color.green(
|
|
68
|
+
`[component-project-helper] wrote ${path.relative(projectRoot, filePath)} <- ${component.sourceFile}`,
|
|
69
|
+
),
|
|
56
70
|
)
|
|
57
71
|
}
|
|
58
72
|
|
|
59
73
|
console.log(
|
|
60
|
-
|
|
74
|
+
color.yellow(
|
|
75
|
+
`[component-project-helper] cleaning stale docs relative to manifest ${path.relative(
|
|
61
76
|
projectRoot,
|
|
62
77
|
manifestPath,
|
|
63
|
-
|
|
78
|
+
)}`,
|
|
79
|
+
),
|
|
64
80
|
)
|
|
65
81
|
await removeStaleGeneratedFiles(manifestPath, files)
|
|
66
82
|
await ensureComponentProjectSkillsScript(projectRoot)
|
|
67
|
-
console.log('[component-project-helper] ensured update-component-skills script')
|
|
83
|
+
console.log(color.green('[component-project-helper] ensured update-component-skills script'))
|
|
68
84
|
console.log('[component-project-helper] ensured stale docs cleaned')
|
|
69
85
|
|
|
70
86
|
const manifest = ComponentProjectGeneratedManifestSchema.parse({
|
|
@@ -75,7 +91,9 @@ export async function runComponentProjectPostinstall(projectRoot = resolveCompon
|
|
|
75
91
|
})
|
|
76
92
|
await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8')
|
|
77
93
|
console.log(
|
|
78
|
-
|
|
94
|
+
color.cyan(
|
|
95
|
+
`[component-project-helper] postinstall complete, manifest files: ${files.length}`,
|
|
96
|
+
),
|
|
79
97
|
)
|
|
80
98
|
}
|
|
81
99
|
|
package/scripts/runtime-root.mjs
CHANGED
|
@@ -3,7 +3,10 @@ import fs from 'node:fs'
|
|
|
3
3
|
import process from 'node:process'
|
|
4
4
|
|
|
5
5
|
function hasComponentProjectSourceDir(directory) {
|
|
6
|
-
return
|
|
6
|
+
return (
|
|
7
|
+
fs.existsSync(path.join(directory, 'src', 'components')) ||
|
|
8
|
+
fs.existsSync(path.join(directory, 'src', 'video', 'chapters'))
|
|
9
|
+
)
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
function findComponentProjectInstallRoot(startDirectory) {
|
|
@@ -151,3 +151,36 @@ test('discovers decorated components from installed video-project-core', async (
|
|
|
151
151
|
},
|
|
152
152
|
])
|
|
153
153
|
})
|
|
154
|
+
|
|
155
|
+
test('ignores test files from installed packages', async () => {
|
|
156
|
+
const projectRoot = await fs.mkdtemp(path.join(tmpdir(), 'component-project-helper-tests-'))
|
|
157
|
+
const packageTestDir = path.join(
|
|
158
|
+
projectRoot,
|
|
159
|
+
'node_modules',
|
|
160
|
+
'@vibecuting',
|
|
161
|
+
'video-project-helper',
|
|
162
|
+
'src',
|
|
163
|
+
)
|
|
164
|
+
await fs.mkdir(packageTestDir, { recursive: true })
|
|
165
|
+
|
|
166
|
+
await fs.writeFile(
|
|
167
|
+
path.join(packageTestDir, 'index.test.ts'),
|
|
168
|
+
`
|
|
169
|
+
@VideoComponent({
|
|
170
|
+
name: 'ShouldBeIgnored',
|
|
171
|
+
description: 'This fixture lives in a test file and must not be discovered',
|
|
172
|
+
sourceFile: 'node_modules/@vibecuting/video-project-helper/src/index.test.ts',
|
|
173
|
+
aspectRatio: '16:9',
|
|
174
|
+
sceneType: 'scene',
|
|
175
|
+
tags: ['test'],
|
|
176
|
+
propsTypeName: 'ShouldBeIgnoredProps',
|
|
177
|
+
})
|
|
178
|
+
export const ShouldBeIgnored = () => null
|
|
179
|
+
`,
|
|
180
|
+
'utf8',
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
const discovered = await discoverComponentProjectComponents(projectRoot)
|
|
184
|
+
|
|
185
|
+
expect(discovered).toEqual([])
|
|
186
|
+
})
|
package/src/discovery/index.ts
CHANGED
|
@@ -12,6 +12,16 @@ import {
|
|
|
12
12
|
} from '../runtime'
|
|
13
13
|
import { ensureComponentProjectSkillsScript } from './package-json'
|
|
14
14
|
|
|
15
|
+
const supportsColor =
|
|
16
|
+
Boolean(process.stdout.isTTY) && process.env.NO_COLOR !== '1' && process.env.CI !== 'true'
|
|
17
|
+
|
|
18
|
+
const color = {
|
|
19
|
+
cyan: (value: string): string => (supportsColor ? `\u001b[36m${value}\u001b[0m` : value),
|
|
20
|
+
green: (value: string): string => (supportsColor ? `\u001b[32m${value}\u001b[0m` : value),
|
|
21
|
+
yellow: (value: string): string => (supportsColor ? `\u001b[33m${value}\u001b[0m` : value),
|
|
22
|
+
dim: (value: string): string => (supportsColor ? `\u001b[2m${value}\u001b[0m` : value),
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
async function ensureDirectory(dir: string): Promise<void> {
|
|
16
26
|
await fs.mkdir(dir, { recursive: true })
|
|
17
27
|
}
|
|
@@ -40,14 +50,16 @@ export async function runComponentProjectPostinstall(
|
|
|
40
50
|
const manifestPath = resolveComponentProjectGeneratedManifestPath(projectRoot)
|
|
41
51
|
const components = await discoverComponentProjectComponents(projectRoot)
|
|
42
52
|
|
|
43
|
-
console.log('[component-project-helper] postinstall start')
|
|
44
|
-
console.log(`[component-project-helper] project root: ${projectRoot}`)
|
|
45
|
-
console.log(`[component-project-helper] docs dir: ${docsDir}`)
|
|
46
|
-
console.log(`[component-project-helper] manifest path: ${manifestPath}`)
|
|
53
|
+
console.log(color.cyan('[component-project-helper] postinstall start'))
|
|
54
|
+
console.log(color.dim(`[component-project-helper] project root: ${projectRoot}`))
|
|
55
|
+
console.log(color.dim(`[component-project-helper] docs dir: ${docsDir}`))
|
|
56
|
+
console.log(color.dim(`[component-project-helper] manifest path: ${manifestPath}`))
|
|
47
57
|
console.log(
|
|
48
|
-
|
|
58
|
+
color.green(
|
|
59
|
+
`[component-project-helper] discovered ${components.length} component(s): ${
|
|
49
60
|
components.map((component) => component.name).join(', ') || '(none)'
|
|
50
|
-
|
|
61
|
+
}`,
|
|
62
|
+
),
|
|
51
63
|
)
|
|
52
64
|
|
|
53
65
|
await ensureDirectory(docsDir)
|
|
@@ -60,19 +72,23 @@ export async function runComponentProjectPostinstall(
|
|
|
60
72
|
await fs.writeFile(filePath, markdown, 'utf8')
|
|
61
73
|
files.push(filePath)
|
|
62
74
|
console.log(
|
|
63
|
-
|
|
75
|
+
color.green(
|
|
76
|
+
`[component-project-helper] wrote ${path.relative(projectRoot, filePath)} <- ${component.sourceFile}`,
|
|
77
|
+
),
|
|
64
78
|
)
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
console.log(
|
|
68
|
-
|
|
82
|
+
color.yellow(
|
|
83
|
+
`[component-project-helper] cleaning stale docs relative to manifest ${path.relative(
|
|
69
84
|
projectRoot,
|
|
70
85
|
manifestPath,
|
|
71
|
-
|
|
86
|
+
)}`,
|
|
87
|
+
),
|
|
72
88
|
)
|
|
73
89
|
await removeStaleGeneratedFiles(manifestPath, files)
|
|
74
90
|
await ensureComponentProjectSkillsScript(projectRoot)
|
|
75
|
-
console.log('[component-project-helper] ensured update-component-skills script')
|
|
91
|
+
console.log(color.green('[component-project-helper] ensured update-component-skills script'))
|
|
76
92
|
|
|
77
93
|
const manifest = ComponentProjectGeneratedManifestSchema.parse({
|
|
78
94
|
projectRoot,
|
|
@@ -83,7 +99,9 @@ export async function runComponentProjectPostinstall(
|
|
|
83
99
|
|
|
84
100
|
await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8')
|
|
85
101
|
console.log(
|
|
86
|
-
|
|
102
|
+
color.cyan(
|
|
103
|
+
`[component-project-helper] postinstall complete, manifest files: ${files.length}`,
|
|
104
|
+
),
|
|
87
105
|
)
|
|
88
106
|
}
|
|
89
107
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { afterEach, expect, test, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { resolveComponentProjectInstallRoot } from './index'
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.unstubAllEnvs()
|
|
10
|
+
vi.restoreAllMocks()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('resolves a video project template root before a parent monorepo root', async () => {
|
|
14
|
+
const workspaceRoot = await fs.mkdtemp(path.join(tmpdir(), 'component-project-helper-runtime-'))
|
|
15
|
+
const monorepoRoot = path.join(workspaceRoot, 'repo')
|
|
16
|
+
const videoProjectRoot = path.join(monorepoRoot, 'project-templates', 'video-project')
|
|
17
|
+
|
|
18
|
+
await fs.mkdir(path.join(monorepoRoot, 'src', 'components'), { recursive: true })
|
|
19
|
+
await fs.mkdir(path.join(videoProjectRoot, 'src', 'video', 'chapters'), { recursive: true })
|
|
20
|
+
|
|
21
|
+
vi.stubEnv('INIT_CWD', path.join(videoProjectRoot, 'src', 'video'))
|
|
22
|
+
vi.stubEnv('npm_config_local_prefix', '')
|
|
23
|
+
vi.spyOn(process, 'cwd').mockReturnValue(path.join(videoProjectRoot, 'src', 'video'))
|
|
24
|
+
|
|
25
|
+
expect(resolveComponentProjectInstallRoot()).toBe(videoProjectRoot)
|
|
26
|
+
})
|
package/src/runtime/index.ts
CHANGED
|
@@ -3,7 +3,10 @@ import fs from 'node:fs'
|
|
|
3
3
|
import process from 'node:process'
|
|
4
4
|
|
|
5
5
|
function hasComponentProjectSourceDir(directory: string): boolean {
|
|
6
|
-
return
|
|
6
|
+
return (
|
|
7
|
+
fs.existsSync(path.join(directory, 'src', 'components')) ||
|
|
8
|
+
fs.existsSync(path.join(directory, 'src', 'video', 'chapters'))
|
|
9
|
+
)
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
function findComponentProjectInstallRoot(startDirectory: string): string | undefined {
|