-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
222 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ export default { | |
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import Chrome from "chrome"; | ||
import Chrome from '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 | ||
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 | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.