@vibecuting/component-project-helper 0.1.14 → 0.1.16
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/package.json
CHANGED
package/scripts/postinstall.mjs
CHANGED
|
@@ -97,8 +97,16 @@ export async function runComponentProjectPostinstall(projectRoot = resolveCompon
|
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
async function isDirectRun() {
|
|
101
|
+
if (!process.argv[1]) {
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const entryPath = await fs.realpath(process.argv[1])
|
|
106
|
+
const currentPath = await fs.realpath(new URL(import.meta.url).pathname)
|
|
107
|
+
return entryPath === currentPath
|
|
108
|
+
}
|
|
101
109
|
|
|
102
|
-
if (isDirectRun) {
|
|
110
|
+
if (await isDirectRun()) {
|
|
103
111
|
await runComponentProjectPostinstall()
|
|
104
112
|
}
|
package/scripts/preuninstall.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
|
-
import
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
3
|
|
|
4
4
|
import { resolveComponentProjectGeneratedManifestPath } from './runtime-root.mjs'
|
|
5
5
|
import { ComponentProjectGeneratedManifestSchema } from './schemas.mjs'
|
|
@@ -30,8 +30,16 @@ export async function runComponentProjectPreuninstall(
|
|
|
30
30
|
await removeComponentProjectSkillsScript(projectRoot)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
async function isDirectRun() {
|
|
34
|
+
if (!process.argv[1]) {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const entryPath = await fs.realpath(process.argv[1])
|
|
39
|
+
const currentPath = await fs.realpath(fileURLToPath(import.meta.url))
|
|
40
|
+
return entryPath === currentPath
|
|
41
|
+
}
|
|
34
42
|
|
|
35
|
-
if (isDirectRun) {
|
|
43
|
+
if (await isDirectRun()) {
|
|
36
44
|
await runComponentProjectPreuninstall()
|
|
37
45
|
}
|
|
@@ -43,3 +43,26 @@ test('attaches normalized metadata to decorated function components', () => {
|
|
|
43
43
|
expect(decorated).toBe(SceneTitle)
|
|
44
44
|
expect(getComponentProjectComponentMetadata(SceneTitle)).toEqual(metadata)
|
|
45
45
|
})
|
|
46
|
+
|
|
47
|
+
test('attaches metadata to components with required props', () => {
|
|
48
|
+
type RequiredProps = {
|
|
49
|
+
title: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const metadata = defineComponentProjectComponentMetadata({
|
|
53
|
+
name: 'RequiredPropsScene',
|
|
54
|
+
description: 'Exercises required props support',
|
|
55
|
+
sourceFile: 'src/components/RequiredPropsScene.tsx',
|
|
56
|
+
aspectRatio: '16:9',
|
|
57
|
+
sceneType: 'scene',
|
|
58
|
+
tags: ['required', 'props'],
|
|
59
|
+
propsTypeName: 'RequiredProps',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const RequiredPropsScene = (_props: RequiredProps) => null
|
|
63
|
+
|
|
64
|
+
const decorated = VideoComponent(metadata)(RequiredPropsScene)
|
|
65
|
+
|
|
66
|
+
expect(decorated).toBe(RequiredPropsScene)
|
|
67
|
+
expect(getComponentProjectComponentMetadata(RequiredPropsScene)).toEqual(metadata)
|
|
68
|
+
})
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata'
|
|
2
2
|
|
|
3
|
-
import type { ComponentType } from 'react'
|
|
4
|
-
|
|
5
3
|
import {
|
|
6
4
|
ComponentProjectComponentMetadataSchema,
|
|
7
5
|
type ComponentProjectComponentMetadata,
|
|
@@ -20,7 +18,7 @@ export function defineComponentProjectComponentMetadata(
|
|
|
20
18
|
export function VideoComponent(metadata: ComponentProjectComponentMetadata) {
|
|
21
19
|
const normalized = defineComponentProjectComponentMetadata(metadata)
|
|
22
20
|
|
|
23
|
-
return function componentProjectDecorator<T extends
|
|
21
|
+
return function componentProjectDecorator<T extends (...args: any[]) => unknown>(target: T): T {
|
|
24
22
|
Reflect.defineMetadata(COMPONENT_PROJECT_METADATA_KEY, normalized, target)
|
|
25
23
|
return target
|
|
26
24
|
}
|
|
@@ -105,10 +105,23 @@ export async function runComponentProjectPostinstall(
|
|
|
105
105
|
)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
async function isDirectRun(): Promise<boolean> {
|
|
109
|
+
if (!process.argv[1]) {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const [entryPath, currentPath] = await Promise.all([
|
|
114
|
+
fs.realpath(process.argv[1]),
|
|
115
|
+
fs.realpath(fileURLToPath(import.meta.url)),
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
return entryPath === currentPath
|
|
119
|
+
}
|
|
120
|
+
|
|
108
121
|
async function main(): Promise<void> {
|
|
109
122
|
await runComponentProjectPostinstall()
|
|
110
123
|
}
|
|
111
124
|
|
|
112
|
-
if (
|
|
125
|
+
if (await isDirectRun()) {
|
|
113
126
|
await main()
|
|
114
127
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
|
-
import path from 'node:path'
|
|
3
2
|
import { fileURLToPath } from 'node:url'
|
|
4
3
|
|
|
5
4
|
import { ComponentProjectGeneratedManifestSchema } from '../schemas'
|
|
@@ -37,6 +36,19 @@ async function main(): Promise<void> {
|
|
|
37
36
|
await runComponentProjectPreuninstall()
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
async function isDirectRun(): Promise<boolean> {
|
|
40
|
+
if (!process.argv[1]) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const [entryPath, currentPath] = await Promise.all([
|
|
45
|
+
fs.realpath(process.argv[1]),
|
|
46
|
+
fs.realpath(fileURLToPath(import.meta.url)),
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
return entryPath === currentPath
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (await isDirectRun()) {
|
|
41
53
|
await main()
|
|
42
54
|
}
|