Skip to content

Commit

Permalink
refactor(project): re-write project (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cui <[email protected]>
  • Loading branch information
BlackHole1 authored Oct 25, 2024
1 parent 09e7a3a commit c906a07
Show file tree
Hide file tree
Showing 79 changed files with 6,823 additions and 2,991 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,ts,.mjs}]
indent_style = space
indent_size = 4

[*.{json,yml,yaml}]
indent_style = space
indent_size = 2
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ jobs:

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies 📦
run: pnpm i

- name: Check
run: pnpm ts-check

- name: Build Editor 🔧
run: pnpm run build
working-directory: packages/editor
- name: Lint
run: pnpm lint

- name: Build App 🔧
- name: Build
run: pnpm run build
working-directory: packages/app
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,39 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*

# From: https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Editor-based Rest Client
.idea/httpRequests
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLinters/eslint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/subtitle-editor.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See: https://github.com/electron-userland/electron-builder/issues/6289#issuecomment-1042620422
shamefully-hoist = true
59 changes: 49 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
{
"cSpell.words": [
"antd",
"iife",
"refreshable",
"tsup",
"Vals",
"wavesurfer"
],
"editor.tabSize": 2
}
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"svelte",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
7 changes: 7 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
words:
- antd
- iife
- refreshable
- tsup
- Vals
- wavesurfer
4 changes: 4 additions & 0 deletions desktop/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
dist-dev
node_modules
index.html
22 changes: 22 additions & 0 deletions desktop/main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "subtitle-editor",
"version": "1.0.0",
"description": "",
"main": "./dist/index.mjs",
"scripts": {
"build": "vite build",
"start": "vite dev",
"ts-check": "tsc --noEmit"
},
"license": "MIT",
"type": "module",
"devDependencies": {
"@antfu/eslint-config": "overridden",
"electron": "^32.0.1",
"eslint": "overridden",
"vite": "^5.4.2",
"vite-plugin-electron": "^0.28.8"
},
"dependencies": {
}
}
39 changes: 39 additions & 0 deletions desktop/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path, { join } from "node:path";
import { app, BrowserWindow } from "electron";
import { registerIpcHandlers } from "./ipc";

const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);

async function createWindow() {
const mainWindow = new BrowserWindow({
width: 1600,
height: 1500,
show: false,
webPreferences: {
preload: path.join(__dirname, "preload.mjs"),
nodeIntegration: false,
},
});

mainWindow.once("ready-to-show", () => {
mainWindow.show();
});

if (__DEV__) {
await mainWindow.loadURL(RENDERER_URL);
mainWindow.webContents.openDevTools();
}
else {
await mainWindow.loadFile(join(__dirname, "..", "renderer", "index.html"));
}
}

app.whenReady().then(async () => {
registerIpcHandlers();
await createWindow();
});

app.on("window-all-closed", () => {
app.quit();
});
23 changes: 23 additions & 0 deletions desktop/main/src/ipc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { IpcMainInvokeEvent } from "electron";
import { readFile, writeFile } from "node:fs/promises";
import { ipcMain } from "electron";

type ElectronAPI = Omit<typeof electronAPI, "getPathOfFile">;
type HandleAPI = {
[k in keyof ElectronAPI]: (event: IpcMainInvokeEvent, ...args: Parameters<ElectronAPI[k]>) => ReturnType<ElectronAPI[k]>
};

const handle: HandleAPI = {
async getContentOfFile(_: IpcMainInvokeEvent, filePath: string): Promise<string> {
return await readFile(filePath, "utf-8");
},
async setFileContent(_: IpcMainInvokeEvent, filePath: string, fileContent: string): Promise<void> {
return await writeFile(filePath, fileContent, "utf-8");
},
};

export const registerIpcHandlers = () => {
Object.keys(handle).forEach((key) => {
ipcMain.handle(key, handle[key as keyof ElectronAPI]);
});
};
15 changes: 15 additions & 0 deletions desktop/main/src/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { contextBridge, ipcRenderer, webUtils } from "electron";

const prefix = __DEV__ ? "/@fs" : "";

contextBridge.exposeInMainWorld("electronAPI", {
async getContentOfFile(filePath: string) {
return await ipcRenderer.invoke("getContentOfFile", filePath.slice(prefix.length));
},
async setFileContent(filePath: string, fileContent: string) {
return await ipcRenderer.invoke("setFileContent", filePath.slice(prefix.length), fileContent);
},
getPathOfFile(file: File) {
return `${prefix}${webUtils.getPathForFile(file)}`;
},
});
3 changes: 2 additions & 1 deletion packages/app/tsconfig.json → desktop/main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": [
"src/**/*",
"typings/**/*",
"../editor/typings/**/*",
"../typings/**/*.d.ts",
],
}

2 changes: 2 additions & 0 deletions desktop/main/typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const __DEV__: boolean;
declare const RENDERER_URL: string;
Loading

0 comments on commit c906a07

Please sign in to comment.