Skip to content

Commit 1bf0894

Browse files
authored
Update all tests (pt. 1) (#151)
1 parent fe1658f commit 1bf0894

File tree

782 files changed

+1999
-8582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

782 files changed

+1999
-8582
lines changed

aaa.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Get the absolute path of the root directory
4+
ROOT_DIR=$(pwd)
5+
6+
# Function to recursively remove .git folders
7+
remove_git_folders() {
8+
local dir="$1"
9+
10+
# Iterate over all directories in the current directory
11+
for subdir in "$dir"/*; do
12+
if [ -d "$subdir" ]; then
13+
# Skip node_modules directories
14+
if [[ $(basename "$subdir") == "node_modules" ]]; then
15+
continue
16+
fi
17+
18+
# Remove .git directory if it's not the root level
19+
if [[ $(basename "$subdir") == ".git" ]] && [[ "$subdir" != "$ROOT_DIR/.git" ]]; then
20+
echo "Removing $subdir"
21+
rm -rf "$subdir"
22+
fi
23+
24+
# Recurse into subdirectories
25+
remove_git_folders "$subdir"
26+
fi
27+
done
28+
}
29+
30+
# Start the recursive removal from the current directory
31+
remove_git_folders "$ROOT_DIR"

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default [
1919
'**/webpack.config.js',
2020
'**/postcss.config.js',
2121
'**/tailwind.config.js',
22-
'**/stylelint.config.js'
22+
'**/stylelint.config.json'
2323
]
2424
}
2525
]
File renamed without changes.
File renamed without changes.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import {useState, type FormEvent} from 'react'
2+
import OpenAI from 'openai'
3+
import chatgptLogo from '../images/chatgpt.png'
4+
import extensionJsLogo from '../images/extension_128.png'
5+
6+
const openai = new OpenAI({
7+
apiKey: process.env.EXTENSION_OPENAI_API_KEY!,
8+
dangerouslyAllowBrowser: true
9+
})
10+
11+
interface Message {
12+
content: string
13+
role: 'user' | 'assistant'
14+
}
15+
16+
function ActionApp() {
17+
const [messages, setMessages] = useState<Message[]>([
18+
{
19+
content:
20+
'Hello there! This is your ChatGPT extension sample, ' +
21+
'built with React, Tailwind.css, and DaisyUI. ' +
22+
'For it to work, create a .env file with your EXTENSION_OPENAI_API_KEY. ' +
23+
"You can get an API key from OpenAI's website????",
24+
role: 'assistant'
25+
},
26+
{
27+
content: 'https://platform.openai.com/api-keys',
28+
role: 'assistant'
29+
}
30+
])
31+
32+
const [isTyping, setIsTyping] = useState(false)
33+
34+
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
35+
e.preventDefault()
36+
37+
const form = e.target as HTMLFormElement
38+
const input = form[0] as HTMLInputElement
39+
40+
const newMessage: Message = {
41+
content: input.value,
42+
role: 'user'
43+
}
44+
45+
const newMessages = [...messages, newMessage]
46+
47+
setMessages(newMessages)
48+
setIsTyping(true)
49+
form.reset()
50+
51+
const completion = await openai.chat.completions.create({
52+
model: 'gpt-3.5-turbo',
53+
messages: newMessages
54+
})
55+
56+
setMessages([...newMessages, completion.choices[0].message as Message])
57+
setIsTyping(false)
58+
}
59+
60+
return (
61+
<section className="container mx-auto p-5 fixed inset-0">
62+
<div className="w-full h-full flex flex-col">
63+
<div className="flex-grow overflow-auto">
64+
{messages.length &&
65+
messages.map((msg, i) => (
66+
<div
67+
className={`chat ${
68+
msg.role === 'assistant' ? 'chat-start' : 'chat-end'
69+
}`}
70+
key={'chatKey' + i}
71+
>
72+
<div className="chat-image avatar">
73+
<div className="w-10 rounded-full">
74+
<img
75+
src={
76+
msg.role === 'assistant' ? chatgptLogo : extensionJsLogo
77+
}
78+
alt="avatar"
79+
/>
80+
</div>
81+
</div>
82+
<div className="chat-bubble">{msg.content}</div>
83+
</div>
84+
))}
85+
</div>
86+
87+
<form className="form-control items-center" onSubmit={handleSubmit}>
88+
<div className="input-group max-w-full w-[800px] relative flex items-center">
89+
{isTyping && (
90+
<small className="absolute -top-5 left-0.5 animate-pulse">
91+
ChatGPT Extension is typing...
92+
</small>
93+
)}
94+
95+
<input
96+
type="text"
97+
placeholder="Ask ChatGPT a question."
98+
className="input input-bordered flex-grow mr-2.5"
99+
required
100+
/>
101+
<button className="btn btn-square" type="submit">
102+
<svg
103+
xmlns="http://www.w3.org/2000/svg"
104+
className="h-6 w-6"
105+
fill="currentColor"
106+
viewBox="0 0 16 16"
107+
>
108+
<path d="M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z" />
109+
</svg>
110+
</button>
111+
</div>
112+
</form>
113+
</div>
114+
</section>
115+
)
116+
}
117+
118+
export default ActionApp

examples/chatgpt/action/index.html renamed to examples/action-chatgpt/action/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
<noscript>You need to enable JavaScript to run this extension.</noscript>
1010
<div id="root"></div>
1111
</body>
12-
<script src="./scripts.jsx"></script>
12+
<script src="./scripts.tsx"></script>
1313
</html>

examples/chatgpt/action/scripts.jsx renamed to examples/action-chatgpt/action/scripts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client'
33
import ActionApp from './ActionApp'
44
import './styles.css'
55

6-
const root = ReactDOM.createRoot(document.getElementById('root'))
6+
const root = ReactDOM.createRoot(document.getElementById('root')!)
77

88
root.render(
99
<React.StrictMode>
7.45 KB
Loading
598 Bytes
Loading
2.45 KB
Loading

examples/action-chatgpt/manifest.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"manifest_version": 3,
3+
"version": "0.0.1",
4+
"name": "Action ChatGPT Template",
5+
"description": "An Extension.js example.",
6+
"icons": {
7+
"16": "images/extension_16.png",
8+
"48": "images/extension_48.png",
9+
"128": "images/extension_128.png"
10+
},
11+
"action": {
12+
"default_icon": {
13+
"16": "images/extension_16.png",
14+
"48": "images/extension_48.png",
15+
"128": "images/extension_128.png"
16+
},
17+
"default_title": "ChatGPT",
18+
"default_popup": "action/index.html"
19+
}
20+
}
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
{
2-
"license": "MIT",
3-
"repository": {
4-
"type": "git",
5-
"url": "https://github.com/cezaraugusto/extension.git",
6-
"directory": "programs/create/templates/chatgpt"
7-
},
8-
"name": "chatgpt",
2+
"private": true,
3+
"name": "action-chatgpt",
94
"description": "An Extension.js example.",
105
"version": "0.0.1",
116
"author": {
127
"name": "Cezar Augusto",
138
"email": "[email protected]",
149
"url": "https://cezaraugusto.com"
1510
},
16-
"files": [
17-
"template",
18-
"template.json"
19-
],
20-
"keywords": [
21-
"extension",
22-
"browser-extension",
23-
"web-extension",
24-
"template"
25-
],
11+
"license": "MIT",
2612
"dependencies": {
2713
"daisyui": "^4.12.10",
2814
"openai": "^4.54.0",
@@ -32,6 +18,7 @@
3218
},
3319
"devDependencies": {
3420
"@types/react": "^18.0.9",
35-
"@types/react-dom": "^18.0.5"
21+
"@types/react-dom": "^18.0.5",
22+
"typescript": "5.3.3"
3623
}
3724
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = {
44
theme: {
55
extend: {}
66
},
7-
plugins: []
7+
plugins: [require('daisyui')]
88
}

examples/action/action/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
<h1>
2222
<img
2323
class="action"
24-
src="../images/extension.png"
24+
src="../images/extension_128.png"
2525
alt="The Extension logo"
2626
width="72px"
2727
/>
2828
<br />
2929
Welcome to your Action Extension
3030
</h1>
3131
<p>
32-
Learn more about creating browser extensions at
32+
Learn more about creating cross-browser extensions at
3333
<a href="https://extension.js.org" target="_blank"
3434
>https://extension.js.org</a
3535
>.

examples/action/action/styles.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ body {
33
justify-content: center;
44
align-items: center;
55
width: 300px;
6+
padding: 2em;
67
}
78

89
h1 {
910
font-size: 2.7em;
1011
}
1112

1213
.action {
13-
border-radius: 24px;
14-
border: 4px solid;
15-
background: white;
16-
border-color: #ccc;
17-
border-radius: 24px;
1814
filter: grayscale(1);
1915
transition:
2016
filter 2s,
7.45 KB
Loading
598 Bytes
Loading
2.45 KB
Loading
-1.01 KB
Binary file not shown.
-4.66 KB
Binary file not shown.

examples/action/manifest.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
{
22
"manifest_version": 3,
33
"version": "0.0.1",
4-
"name": "action",
4+
"name": "Action Template",
55
"description": "An Extension.js example.",
6-
"author": "Cezar Augusto",
6+
"icons": {
7+
"16": "images/extension_16.png",
8+
"48": "images/extension_48.png",
9+
"128": "images/extension_128.png"
10+
},
711
"action": {
812
"default_popup": "action/index.html",
913
"default_title": "Action",
1014
"default_icon": {
11-
"16": "test_16.png",
12-
"48": "test_48.png",
13-
"128": "public/icon.png"
15+
"16": "images/extension_16.png",
16+
"48": "images/extension_48.png",
17+
"128": "images/extension_128.png"
1418
}
1519
}
1620
}

examples/action/package.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"private": true,
3-
"license": "MIT",
4-
"repository": {
5-
"type": "git",
6-
"url": "https://github.com/extension-js/extension.git",
7-
"directory": "examples/action"
8-
},
93
"name": "action",
104
"description": "An Extension.js example.",
115
"version": "0.0.1",
@@ -14,10 +8,5 @@
148
"email": "[email protected]",
159
"url": "https://cezaraugusto.com"
1610
},
17-
"keywords": [
18-
"extension",
19-
"browser-extension",
20-
"web-extension",
21-
"template"
22-
]
11+
"license": "MIT"
2312
}

examples/action/public/icon.png

-1.01 KB
Binary file not shown.

examples/action/puzzle.png

-46.9 KB
Binary file not shown.

examples/action/test_16.png

-1.01 KB
Binary file not shown.

examples/action/test_32.png

-2.63 KB
Binary file not shown.

examples/action/test_48.png

-4.66 KB
Binary file not shown.

examples/action/test_64.png

-7.24 KB
Binary file not shown.

0 commit comments

Comments
 (0)