Skip to content

Commit

Permalink
format files with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutanin committed Jul 27, 2023
1 parent bdafc63 commit 8db0777
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 246 deletions.
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"bracketSpacing": true,
"arrowParens": "avoid",
"bracketSameLine": true,
"semi": false,
"ignore": ["**/*.json"]
"semi": false
}
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export default {
tailwindcss: {},
autoprefixer: {},
},
};
}
44 changes: 22 additions & 22 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import Chrome from "chrome";
import Chrome from 'chrome'

Check failure on line 1 in src/global.d.ts

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module 'chrome'

declare namespace chrome {
export default Chrome;
export default Chrome
}

declare module "virtual:reload-on-update-in-background-script" {
export const reloadOnUpdate: (watchPath: string) => void;
export default reloadOnUpdate;
declare module 'virtual:reload-on-update-in-background-script' {
export const reloadOnUpdate: (watchPath: string) => void

Check failure on line 8 in src/global.d.ts

View workflow job for this annotation

GitHub Actions / lint

'watchPath' is defined but never used. Allowed unused args must match /^_/u
export default reloadOnUpdate
}

declare module "virtual:reload-on-update-in-view" {
const refreshOnUpdate: (watchPath: string) => void;
export default refreshOnUpdate;
declare module 'virtual:reload-on-update-in-view' {
const refreshOnUpdate: (watchPath: string) => void

Check failure on line 13 in src/global.d.ts

View workflow job for this annotation

GitHub Actions / lint

'watchPath' is defined but never used. Allowed unused args must match /^_/u
export default refreshOnUpdate
}

declare module "*.svg" {
import React = require("react");
export const ReactComponent: React.SFC<React.SVGProps<SVGSVGElement>>;
const src: string;
export default src;
declare module '*.svg' {
import React = require('react')
export const ReactComponent: React.SFC<React.SVGProps<SVGSVGElement>>
const src: string
export default src
}

declare module "*.jpg" {
const content: string;
export default content;
declare module '*.jpg' {
const content: string
export default content
}

declare module "*.png" {
const content: string;
export default content;
declare module '*.png' {
const content: string
export default content
}

declare module "*.json" {
const content: string;
export default content;
declare module '*.json' {
const content: string
export default content
}
2 changes: 1 addition & 1 deletion src/pages/content/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "@assets/style/theme.scss";
@import '@assets/style/theme.scss';
@tailwind base;
@tailwind components;
@tailwind utilities;
8 changes: 3 additions & 5 deletions src/pages/popup/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ body {
width: 300px;
height: 260px;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

position: relative;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
}
12 changes: 6 additions & 6 deletions src/pages/popup/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<title>Popup</title>
</head>
</head>

<body>
<div id="app-container"></div>
<script type="module" src="./index.tsx"></script>
</body>
<body>
<div id="app-container"></div>
<script type="module" src="./index.tsx"></script>
</body>
</html>
50 changes: 11 additions & 39 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,21 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"types": [
"vite/client",
"node"
],
"types": ["vite/client", "node"],
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"./src/global.d.ts"
],
"typeRoots": ["./src/global.d.ts"],
"paths": {
"@src/*": [
"src/*"
],
"@assets/*": [
"src/assets/*"
],
"@pages/*": [
"src/pages/*"
],
"@lib/*": [
"src/lib/*"
],
"@hooks/*": [
"src/hooks/*"
],
"virtual:reload-on-update-in-background-script": [
"./src/global.d.ts"
],
"virtual:reload-on-update-in-view": [
"./src/global.d.ts"
]
"@src/*": ["src/*"],
"@assets/*": ["src/assets/*"],
"@pages/*": ["src/pages/*"],
"@lib/*": ["src/lib/*"],
"@hooks/*": ["src/hooks/*"],
"virtual:reload-on-update-in-background-script": ["./src/global.d.ts"],
"virtual:reload-on-update-in-view": ["./src/global.d.ts"]
}
},
"include": [
"src",
"utils",
"vite.config.ts",
"node_modules/@types"
]
"include": ["src", "utils", "vite.config.ts", "node_modules/@types"]
}
115 changes: 59 additions & 56 deletions utils/reload/initReloadServer.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
import { WebSocketServer } from 'ws';
import chokidar from 'chokidar';
import { clearTimeout } from 'timers';
import { WebSocketServer } from 'ws'
import chokidar from 'chokidar'
import { clearTimeout } from 'timers'

function debounce(callback, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => callback(...args), delay);
};
let timer
return function (...args) {
clearTimeout(timer)
timer = setTimeout(() => callback(...args), delay)
}
}

const LOCAL_RELOAD_SOCKET_PORT = 8081;
const LOCAL_RELOAD_SOCKET_URL = `ws://localhost:${LOCAL_RELOAD_SOCKET_PORT}`;
const UPDATE_PENDING_MESSAGE = "wait_update";
const UPDATE_REQUEST_MESSAGE = "do_update";
const UPDATE_COMPLETE_MESSAGE = "done_update";
const LOCAL_RELOAD_SOCKET_PORT = 8081
const LOCAL_RELOAD_SOCKET_URL = `ws://localhost:${LOCAL_RELOAD_SOCKET_PORT}`
const UPDATE_PENDING_MESSAGE = 'wait_update'
const UPDATE_REQUEST_MESSAGE = 'do_update'
const UPDATE_COMPLETE_MESSAGE = 'done_update'

class MessageInterpreter {
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor() { }
static send(message) {
return JSON.stringify(message);
}
static receive(serializedMessage) {
return JSON.parse(serializedMessage);
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor() {}
static send(message) {
return JSON.stringify(message)
}
static receive(serializedMessage) {
return JSON.parse(serializedMessage)
}
}

const clientsThatNeedToUpdate = new Set();
const clientsThatNeedToUpdate = new Set()
function initReloadServer() {
const wss = new WebSocketServer({ port: LOCAL_RELOAD_SOCKET_PORT });
wss.on("listening", () => console.log(`[HRS] Server listening at ${LOCAL_RELOAD_SOCKET_URL}`));
wss.on("connection", (ws) => {
clientsThatNeedToUpdate.add(ws);
ws.addEventListener("close", () => clientsThatNeedToUpdate.delete(ws));
ws.addEventListener("message", (event) => {
const message = MessageInterpreter.receive(String(event.data));
if (message.type === UPDATE_COMPLETE_MESSAGE) {
ws.close();
}
});
});
const wss = new WebSocketServer({ port: LOCAL_RELOAD_SOCKET_PORT })
wss.on('listening', () => console.log(`[HRS] Server listening at ${LOCAL_RELOAD_SOCKET_URL}`))
wss.on('connection', ws => {
clientsThatNeedToUpdate.add(ws)
ws.addEventListener('close', () => clientsThatNeedToUpdate.delete(ws))
ws.addEventListener('message', event => {
const message = MessageInterpreter.receive(String(event.data))
if (message.type === UPDATE_COMPLETE_MESSAGE) {
ws.close()
}
})
})
}
/** CHECK:: src file was updated **/
const debounceSrc = debounce(function (path) {
// Normalize path on Windows
const pathConverted = path.replace(/\\/g, "/");
clientsThatNeedToUpdate.forEach((ws) => ws.send(MessageInterpreter.send({
// Normalize path on Windows
const pathConverted = path.replace(/\\/g, '/')
clientsThatNeedToUpdate.forEach(ws =>
ws.send(
MessageInterpreter.send({
type: UPDATE_PENDING_MESSAGE,
path: pathConverted,
})));
// Delay waiting for public assets to be copied
}, 400);
chokidar.watch("src").on("all", (event, path) => debounceSrc(path));
}),
),
)
// Delay waiting for public assets to be copied
}, 400)
chokidar.watch('src').on('all', (event, path) => debounceSrc(path))
/** CHECK:: build was completed **/
const debounceDist = debounce(() => {
clientsThatNeedToUpdate.forEach((ws) => {
ws.send(MessageInterpreter.send({ type: UPDATE_REQUEST_MESSAGE }));
});
}, 100);
chokidar.watch("dist").on("all", (event) => {
// Ignore unlink, unlinkDir and change events
// that happen in beginning of build:watch and
// that will cause ws.send() if it takes more than 400ms
// to build (which it might). This fixes:
// https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite/issues/100
if (event !== "add" && event !== "addDir")
return;
debounceDist();
});
initReloadServer();
clientsThatNeedToUpdate.forEach(ws => {
ws.send(MessageInterpreter.send({ type: UPDATE_REQUEST_MESSAGE }))
})
}, 100)
chokidar.watch('dist').on('all', event => {
// Ignore unlink, unlinkDir and change events
// that happen in beginning of build:watch and
// that will cause ws.send() if it takes more than 400ms
// to build (which it might). This fixes:
// https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite/issues/100
if (event !== 'add' && event !== 'addDir') return
debounceDist()
})
initReloadServer()
Loading

0 comments on commit 8db0777

Please sign in to comment.