Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update core template #171

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dist-ssr
.idea

# compiled
utils/core/hmr-core/**/*.js
utils/core/**/*.js
public/manifest.json
8 changes: 4 additions & 4 deletions react-app/manifest.ts → react-app/manifest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import packageJson from '../package.json';
import packageJson from '../package.json' assert { type: 'json' };

/**
* After changing, please reload the extension at `chrome://extensions`
*/
const manifest: chrome.runtime.ManifestV3 = {
const manifest = {
manifest_version: 3,
name: packageJson.name,
version: packageJson.version,
Expand All @@ -21,7 +21,7 @@ const manifest: chrome.runtime.ManifestV3 = {
default_icon: 'icon-34.png',
},
icons: {
'128': 'icon-128.png',
128: 'icon-128.png',
},
content_scripts: [
{
Expand All @@ -31,7 +31,7 @@ const manifest: chrome.runtime.ManifestV3 = {
],
web_accessible_resources: [
{
resources: ['assets/js/*.js', 'assets/svg/*.svg', 'icon-128.png', 'icon-34.png'],
resources: ['assets/js/*.js', 'assets/css/*.css', 'assets/svg/*.svg', 'icon-128.png', 'icon-34.png'],
matches: ['*://*/*'],
},
],
Expand Down
456 changes: 220 additions & 236 deletions react-app/package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"build:firefox": "tsc --noEmit && cross-env __FIREFOX__=true vite build",
"build:watch": "cross-env __DEV__=true vite build -w --mode development",
"build:firefox:watch": "cross-env __DEV__=true __FIREFOX__=true vite build -w --mode development",
"build:hmr": "rollup --config utils/core/hmr-core/reload/rollup.config.mjs",
"wss": "node utils/core/hmr-core/reload/initReloadServer.js",
"build:hmr": "rollup --config utils/core/reload/rollup.config.mjs",
"wss": "node utils/core/reload/initReloadServer.js",
"dev": "npm run build:hmr && (run-p wss build:watch)",
"dev:firefox": "npm run build:hmr && (run-p wss build:firefox:watch)",
"lint": "eslint src --ext .ts",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@types/ws": "8.5.7",
"@typescript-eslint/eslint-plugin": "6.7.5",
"@typescript-eslint/parser": "6.7.5",
"@vitejs/plugin-react": "4.1.0",
"@vitejs/plugin-react": "4.2.0",
"chokidar": "3.5.3",
"cross-env": "7.0.3",
"eslint": "8.51.0",
Expand All @@ -59,10 +59,10 @@
"fs-extra": "11.1.1",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
"rollup": "4.2.0",
"rollup": "4.3.0",
"ts-loader": "9.5.0",
"typescript": "5.2.2",
"vite": "4.4.11",
"vite": "5.0.2",
"ws": "8.14.2"
}
}
3 changes: 2 additions & 1 deletion react-app/src/pages/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import urls from '@utils/endpoints/urls';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { createHashRouter } from 'react-router-dom';
import '../internationalization';
import { toast } from 'react-toastify';
import '../internationalization';

const hashRouting = createHashRouter([
{
Expand All @@ -39,6 +39,7 @@ const hashRouting = createHashRouter([
element: <AuthPage />,
},
]);

const Popup = () => {
const { isDarkMode } = useTernaryDarkMode();

Expand Down
34 changes: 0 additions & 34 deletions react-app/utils/core/hmr-core/plugins/custom-dynamic-import.ts

This file was deleted.

38 changes: 0 additions & 38 deletions react-app/utils/core/hmr-core/plugins/make-manifest.ts

This file was deleted.

16 changes: 0 additions & 16 deletions react-app/utils/core/hmr-core/plugins/watch-rebuild.ts

This file was deleted.

5 changes: 0 additions & 5 deletions react-app/utils/core/hmr-core/reload/constant.ts

This file was deleted.

65 changes: 0 additions & 65 deletions react-app/utils/core/hmr-core/reload/initReloadServer.ts

This file was deleted.

15 changes: 0 additions & 15 deletions react-app/utils/core/hmr-core/reload/interpreter/types.ts

This file was deleted.

28 changes: 0 additions & 28 deletions react-app/utils/core/hmr-core/reload/rollup.config.mjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type ColorType = 'success' | 'info' | 'error' | 'warning' | keyof typeof COLORS;
export type ValueOf<T> = T[keyof T];
type ValueOf<T> = T[keyof T];

export default function colorLog(message: string, type?: ColorType) {
let color: ValueOf<typeof COLORS>;
Expand Down
19 changes: 19 additions & 0 deletions react-app/utils/core/plugins/custom-dynamic-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { PluginOption } from 'vite';

export default function customDynamicImport(): PluginOption {
return {
name: 'custom-dynamic-import',
renderDynamicImport({ moduleId }) {
if (!moduleId.includes('node_modules') && process.env.__FIREFOX__) {
return {
left: `import(browser.runtime.getURL('./') + `,
right: ".split('../').join(''));",
};
}
return {
left: 'import(',
right: ')',
};
},
};
}
49 changes: 49 additions & 0 deletions react-app/utils/core/plugins/make-manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as fs from 'fs';
import * as path from 'path';
import * as process from 'process';
import url from 'url';
import type { PluginOption } from 'vite';
import colorLog from '../log';
import ManifestParser from '../manifest-parser';

const { resolve } = path;

const rootDir = resolve(__dirname, '../../..');
const distDir = resolve(rootDir, 'dist');
const manifestFile = resolve(rootDir, 'manifest.js');

const getManifestWithCacheBurst = (): Promise<{ default: chrome.runtime.ManifestV3 }> => {
const withCacheBurst = (path: string) => `${path}?${Date.now().toString()}`;
/**
* In Windows, import() doesn't work without file:// protocol.
* So, we need to convert path to file:// protocol. (url.pathToFileURL)
*/
if (process.platform === 'win32') {
return import(withCacheBurst(url.pathToFileURL(manifestFile).href));
}
return import(withCacheBurst(manifestFile));
};

export default function makeManifest(): PluginOption {
function makeManifest(manifest: chrome.runtime.ManifestV3, to: string) {
if (!fs.existsSync(to)) {
fs.mkdirSync(to);
}
const manifestPath = resolve(to, 'manifest.json');

fs.writeFileSync(manifestPath, ManifestParser.convertManifestToString(manifest));

colorLog(`Manifest file copy complete: ${manifestPath}`, 'success');
}

return {
name: 'make-manifest',
buildStart() {
this.addWatchFile(manifestFile);
},
async writeBundle() {
const manifest = await getManifestWithCacheBurst();
makeManifest(manifest.default, distDir);
},
};
}
18 changes: 18 additions & 0 deletions react-app/utils/core/plugins/watch-rebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { PluginOption } from 'vite';
import { WebSocket } from 'ws';
import { LOCAL_RELOAD_SOCKET_URL } from '../reload/constant';
import MessageInterpreter from '../reload/interpreter';

export default function watchRebuild(): PluginOption {
const ws = new WebSocket(LOCAL_RELOAD_SOCKET_URL);
return {
name: 'watch-rebuild',
writeBundle() {
/**
* When the build is complete, send a message to the reload server.
* The reload server will send a message to the client to reload or refresh the extension.
*/
ws.send(MessageInterpreter.send({ type: 'build_complete' }));
},
};
}
2 changes: 2 additions & 0 deletions react-app/utils/core/reload/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const LOCAL_RELOAD_SOCKET_PORT = 8081;
export const LOCAL_RELOAD_SOCKET_URL = `ws://localhost:${LOCAL_RELOAD_SOCKET_PORT}`;
Loading