Skip to content

Commit 40a5602

Browse files
Merge pull request #25 from dineshsutihar/feature/style
feat(dev-tools): Configure Prettier and Husky for automated code
2 parents f923f92 + 10c922d commit 40a5602

File tree

13 files changed

+755
-171
lines changed

13 files changed

+755
-171
lines changed

frontend/.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

frontend/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
packages
4+
package-lock.json

frontend/.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": false,
4+
"trailingComma": "es5"
5+
}

frontend/background.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
21
chrome.runtime.onMessage.addListener((request, _, sendResponse) => {
3-
if (request.type === "TRANSLATE_CODE") {
4-
const BACKEND_URL = process.env.BACKEND_URL;
5-
6-
chrome.storage.sync.get(['targetLanguage'], (result) => {
7-
const targetLanguage = result.targetLanguage || 'Java';
8-
fetch(BACKEND_URL, {
9-
method: 'POST',
10-
headers: {
11-
'Content-Type': 'application/json',
12-
},
13-
body: JSON.stringify({
14-
code: request.code,
15-
targetLanguage: targetLanguage,
16-
}),
17-
})
18-
.then(response => {
19-
if (!response.ok) {
20-
throw new Error(`Network response was not ok: ${response.statusText}`);
21-
}
22-
return response.json();
23-
})
24-
.then(data => {
25-
26-
if (data.error) {
27-
sendResponse({ error: data.error });
28-
} else {
29-
sendResponse({ translation: data.translation });
30-
}
31-
})
32-
.catch(error => {
2+
if (request.type === "TRANSLATE_CODE") {
3+
const BACKEND_URL = process.env.BACKEND_URL;
334

34-
console.error("Error calling backend:", error);
35-
sendResponse({ error: `Failed to connect to the translation service: ${error.message}` });
36-
});
5+
chrome.storage.sync.get(["targetLanguage"], (result) => {
6+
const targetLanguage = result.targetLanguage || "Java";
7+
fetch(BACKEND_URL, {
8+
method: "POST",
9+
headers: {
10+
"Content-Type": "application/json",
11+
},
12+
body: JSON.stringify({
13+
code: request.code,
14+
targetLanguage: targetLanguage,
15+
}),
16+
})
17+
.then((response) => {
18+
if (!response.ok) {
19+
throw new Error(
20+
`Network response was not ok: ${response.statusText}`
21+
);
22+
}
23+
return response.json();
24+
})
25+
.then((data) => {
26+
if (data.error) {
27+
sendResponse({ error: data.error });
28+
} else {
29+
sendResponse({ translation: data.translation });
30+
}
31+
})
32+
.catch((error) => {
33+
console.error("Error calling backend:", error);
34+
sendResponse({
35+
error: `Failed to connect to the translation service: ${error.message}`,
36+
});
3737
});
38+
});
3839

39-
return true;
40-
}
41-
});
40+
return true;
41+
}
42+
});

frontend/build.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import esbuild from 'esbuild';
2-
import 'dotenv/config';
1+
import esbuild from "esbuild";
2+
import "dotenv/config";
33

44
const define = {};
55
for (const k in process.env) {
6-
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
6+
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
77
}
88

9-
esbuild.build({
10-
entryPoints: ['scripts/content.js', 'background.js'],
9+
esbuild
10+
.build({
11+
entryPoints: ["scripts/content.js", "background.js"],
1112
bundle: true,
12-
outdir: 'dist',
13+
outdir: "dist",
1314
define: define,
14-
}).catch(() => process.exit(1));
15+
})
16+
.catch(() => process.exit(1));
1517

16-
console.log('Build complete. Files are in the /dist folder.');
18+
console.log("Build complete. Files are in the /dist folder.");

0 commit comments

Comments
 (0)