-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.sh
More file actions
103 lines (78 loc) · 2.12 KB
/
Component.sh
File metadata and controls
103 lines (78 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
COMPONENTS_PATH="src/lib/Components"
echo "Choose Action:"
echo "1. Create Component"
echo "2. Delete Component"
read -p "Enter choice [1-2]: " action
read -p "Enter Component Name (e.g., Button): " NAME
if [ -z "$NAME" ]; then
echo "❌ Component name required."
exit 1
fi
COMP_PATH="$COMPONENTS_PATH/$NAME"
create_component() {
if [ -d "$COMP_PATH" ]; then
echo "❌ Component already exists at $COMP_PATH"
exit 1
fi
mkdir -p "$COMP_PATH"
# Component file
cat <<EOF > "$COMP_PATH/$NAME.tsx"
import * as React from 'react';
import './$NAME.scss';
export interface ${NAME}Props extends React.ComponentPropsWithoutRef<'div'> {
}
function $NAME({ ...props }: ${NAME}Props) {
return (
<div {...props}>
$NAME
</div>
);
}
export default $NAME;
EOF
# Index file
echo "export { default as $NAME } from './$NAME';" > "$COMP_PATH/index.ts"
echo "export type { ${NAME}Props } from './$NAME';" >> "$COMP_PATH/index.ts"
# SCSS file
touch "$COMP_PATH/$NAME.scss"
# Test file
cat <<EOF > "$COMP_PATH/$NAME.test.tsx"
import { render } from '@testing-library/react';
import $NAME from './$NAME';
it('renders without crashing', () => {
render(<$NAME />);
});
EOF
# Storybook file
cat <<EOF > "$COMP_PATH/$NAME.stories.tsx"
import type { Meta, StoryFn } from '@storybook/react';
import $NAME from './$NAME';
export default {
title: 'General/$NAME',
component: $NAME,
decorators: [(story) => <div className="container">{story()}</div>],
} as Meta<typeof $NAME>;
export const Template: StoryFn<typeof $NAME> = (args) => <$NAME {...args} />;
EOF
# Add to global index.ts
echo "export * from './$NAME';" >> "$COMPONENTS_PATH/index.ts"
echo "✅ Component '$NAME' created at $COMP_PATH"
}
delete_component() {
if [ ! -d "$COMP_PATH" ]; then
echo "❌ Component does not exist."
exit 1
fi
rm -rf "$COMP_PATH"
sed -i '' "/.\/$NAME/d" "$COMPONENTS_PATH/index.ts"
echo "🗑️ Component '$NAME' deleted from $COMP_PATH"
}
if [ "$action" -eq 1 ]; then
create_component
elif [ "$action" -eq 2 ]; then
delete_component
else
echo "❌ Invalid action"
exit 1
fi