@tomjs/create-app 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/README.zh_CN.md +5 -0
- package/dist/index.mjs +4 -4
- package/package.json +9 -2
- package/template-config/.husky/commit-msg +5 -0
- package/template-config/.husky/common.sh +9 -0
- package/template-config/.husky/pre-commit +5 -0
- package/template-electron-react/.eslintrc.js +7 -0
- package/template-electron-react/.vscode/.debug.env +1 -0
- package/template-electron-react/.vscode/.debug.script.mjs +23 -0
- package/template-electron-react/.vscode/extensions.json +6 -0
- package/template-electron-react/.vscode/launch.json +53 -0
- package/template-electron-react/.vscode/settings.json +13 -0
- package/template-electron-react/.vscode/tasks.json +31 -0
- package/template-electron-react/README.md +28 -0
- package/template-electron-react/_lintstagedrc.js +5 -0
- package/template-electron-react/electron/electron-env.d.ts +11 -0
- package/template-electron-react/electron/main/index.ts +117 -0
- package/template-electron-react/electron/preload/index.ts +0 -0
- package/template-electron-react/index.html +15 -0
- package/template-electron-react/package.json +61 -0
- package/template-electron-react/public/img/icon.png +0 -0
- package/template-electron-react/public/vite.svg +1 -0
- package/template-electron-react/scripts/builder.ts +38 -0
- package/template-electron-react/scripts/constants.ts +16 -0
- package/template-electron-react/scripts/release.ts +41 -0
- package/template-electron-react/src/App.css +45 -0
- package/template-electron-react/src/App.tsx +40 -0
- package/template-electron-react/src/assets/electron.svg +10 -0
- package/template-electron-react/src/assets/react.svg +1 -0
- package/template-electron-react/src/index.css +69 -0
- package/template-electron-react/src/main.tsx +11 -0
- package/template-electron-react/src/vite-env.d.ts +1 -0
- package/template-electron-react/tsconfig.json +10 -0
- package/template-electron-react/tsconfig.node.json +7 -0
- package/template-electron-react/vite.config.ts +111 -0
- package/template-electron-vue/.eslintrc.js +7 -0
- package/template-electron-vue/.vscode/.debug.env +1 -0
- package/template-electron-vue/.vscode/.debug.script.mjs +23 -0
- package/template-electron-vue/.vscode/extensions.json +6 -0
- package/template-electron-vue/.vscode/launch.json +53 -0
- package/template-electron-vue/.vscode/settings.json +13 -0
- package/template-electron-vue/.vscode/tasks.json +31 -0
- package/template-electron-vue/README.md +28 -0
- package/template-electron-vue/_lintstagedrc.js +6 -0
- package/template-electron-vue/electron/electron-env.d.ts +11 -0
- package/template-electron-vue/electron/main/index.ts +117 -0
- package/template-electron-vue/electron/preload/index.ts +0 -0
- package/template-electron-vue/index.html +15 -0
- package/template-electron-vue/package.json +58 -0
- package/template-electron-vue/public/img/icon.png +0 -0
- package/template-electron-vue/public/vite.svg +1 -0
- package/template-electron-vue/scripts/builder.ts +38 -0
- package/template-electron-vue/scripts/constants.ts +16 -0
- package/template-electron-vue/scripts/release.ts +41 -0
- package/template-electron-vue/src/App.vue +43 -0
- package/template-electron-vue/src/assets/electron.svg +10 -0
- package/template-electron-vue/src/assets/vue.svg +1 -0
- package/template-electron-vue/src/components/HelloWorld.vue +37 -0
- package/template-electron-vue/src/main.ts +6 -0
- package/template-electron-vue/src/style.css +80 -0
- package/template-electron-vue/src/vite-env.d.ts +1 -0
- package/template-electron-vue/tsconfig.json +10 -0
- package/template-electron-vue/tsconfig.node.json +7 -0
- package/template-electron-vue/vite.config.ts +111 -0
- package/template-react/index.html +10 -12
- package/template-react/src/App.tsx +2 -2
- package/template-vue/index.html +10 -12
package/README.md
CHANGED
|
@@ -53,6 +53,13 @@ Parameters:
|
|
|
53
53
|
- `-t --template` : specify the template, optional values: `vue` , `react`
|
|
54
54
|
- `-m --module` : `package.json` uses `type:"module"`, otherwise use `commonjs`
|
|
55
55
|
|
|
56
|
+
Support templates:
|
|
57
|
+
|
|
58
|
+
- vue
|
|
59
|
+
- vue + electron
|
|
60
|
+
- react
|
|
61
|
+
- react + electron
|
|
62
|
+
|
|
56
63
|
## Reference project
|
|
57
64
|
|
|
58
65
|
- [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
|
package/README.zh_CN.md
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
Scaffolding project in ${i}...`);let
|
|
4
|
-
`);let
|
|
2
|
+
import c from"fs";import a from"path";import{fileURLToPath as K}from"url";import{blue as D,cyan as q,green as B,red as $,reset as l,yellow as V}from"kolorist";import G from"minimist";import H from"prompts";import s from"fs";import k from"path";function T(e){return[["t","template"],["m","module"]].forEach(([t,r])=>{e[r]=e[r]??e[t]}),e}function _(e){let t=s.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function S(e){return e?.trim().replace(/\/+$/g,"")}function J(e,t){s.mkdirSync(t,{recursive:!0});for(let r of s.readdirSync(e)){let m=k.resolve(e,r),u=k.resolve(t,r);w(m,u)}}function w(e,t){s.statSync(e).isDirectory()?J(e,t):s.copyFileSync(e,t)}function E(e){if(s.existsSync(e))for(let t of s.readdirSync(e))t!==".git"&&s.rmSync(k.resolve(e,t),{recursive:!0,force:!0})}function j(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function A(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function C(e){if(!e)return;let r=e.split(" ")[0].split("/");return{name:r[0],version:r[1]}}var g=T(G(process.argv.slice(2),{string:["_"]})),F=process.cwd(),R=[{name:"vue",display:"Vue",color:B,variants:[{name:"vue",display:"Web",color:D},{name:"electron-vue",display:"Electron",color:V}]},{name:"react",display:"React",color:q,variants:[{name:"react",display:"Web",color:D},{name:"electron-react",display:"Electron",color:V}]}],M=R.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),Q={_gitignore:".gitignore","_lintstagedrc.js":".lintstagedrc.js"},h="my-app";async function X(){let e=S(g._[0]),t=g.template||g.t,r=e||h,m=()=>r==="."?a.basename(a.resolve()):r,u=await H([{type:e?null:"text",name:"projectName",message:l("Project name:"),initial:h,onState:n=>{r=S(n.value)||h}},{type:()=>!c.existsSync(r)||_(r)?null:"toggle",name:"overwrite",message:()=>(r==="."?"Current directory":`Target directory "${r}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(n,{overwrite:o})=>{if(o===!1)throw new Error($("\u2716")+" Operation cancelled");return null},name:"overwriteChecker"},{type:()=>j(m())?null:"text",name:"packageName",message:l("Package name:"),initial:()=>A(m()),validate:n=>j(n)||"Invalid package.json name"},{type:t&&M.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!M.includes(t)?l(`"${t}" isn't a valid template. Please choose from below: `):l("Select a framework:"),initial:0,choices:R.map(n=>{let o=n.color;return{title:o(n.display||n.name),value:n}})},{type:n=>n&&n.variants?"select":null,name:"variant",message:l("Select a variant:"),choices:n=>n.variants.map(o=>{let p=o.color;return{title:p(o.display||o.name),value:o.name}})},{type:()=>g.module!==void 0?null:"toggle",name:"isModuleType",message:l("Is it set to module type?"),initial:!1,active:"yes",inactive:"no"}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{framework:z,overwrite:O,packageName:W,variant:I}=u,i=a.join(F,r);O?E(i):c.existsSync(i)||c.mkdirSync(i,{recursive:!0}),console.log(`
|
|
3
|
+
Scaffolding project in ${i}...`);let L=I||z?.name||t,x=u.isModuleType??g.module,b=n=>a.join(K(import.meta.url),"../..",`template-${n}`),N=b(L);[N,b("config")].forEach(n=>{let o=c.readdirSync(n);for(let p of o){let f=Q[p]??p;x&&f.endsWith("rc.js")&&(f=f.replace(".js",".cjs"));let U=a.join(i,f);w(a.join(n,p),U)}});let d=JSON.parse(c.readFileSync(a.join(N,"package.json"),"utf-8"));d.name=W||m(),x?d.type="module":delete d.type,c.writeFileSync(a.join(i,"package.json"),JSON.stringify(d,null,2)+`
|
|
4
|
+
`);let P=C(process.env.npm_config_user_agent),y=P?P.name:"npm",v=a.relative(F,i);switch(console.log(`
|
|
5
5
|
Done. Now run:
|
|
6
|
-
`),i!==
|
|
6
|
+
`),i!==F&&console.log(` cd ${v.includes(" ")?`"${v}"`:v}`),y){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${y} install`),console.log(` ${y} run dev`);break}}X().catch(()=>{});
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/create-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "create tomjs web app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tomjs",
|
|
7
7
|
"front-end",
|
|
8
8
|
"create",
|
|
9
|
-
"app"
|
|
9
|
+
"app",
|
|
10
|
+
"vite",
|
|
11
|
+
"vue",
|
|
12
|
+
"react"
|
|
10
13
|
],
|
|
11
14
|
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/tomgao365/create-app.git"
|
|
18
|
+
},
|
|
12
19
|
"publishConfig": {
|
|
13
20
|
"access": "public",
|
|
14
21
|
"registry": "https://registry.npmjs.org"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VITE_DEV_SERVER_URL=http://127.0.0.1:6888/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { spawn } from 'node:child_process'
|
|
6
|
+
|
|
7
|
+
const pkg = createRequire(import.meta.url)('../package.json')
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
// write .debug.env
|
|
11
|
+
const envContent = Object.entries(pkg.debug.env).map(([key, val]) => `${key}=${val}`)
|
|
12
|
+
fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
|
|
13
|
+
|
|
14
|
+
// bootstrap
|
|
15
|
+
spawn(
|
|
16
|
+
// TODO: terminate `npm run dev` when Debug exits.
|
|
17
|
+
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
18
|
+
['run', 'dev'],
|
|
19
|
+
{
|
|
20
|
+
stdio: 'inherit',
|
|
21
|
+
env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }),
|
|
22
|
+
},
|
|
23
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"compounds": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Debug App",
|
|
9
|
+
"preLaunchTask": "Before Debug",
|
|
10
|
+
"configurations": [
|
|
11
|
+
"Debug Main Process",
|
|
12
|
+
"Debug Renderer Process"
|
|
13
|
+
],
|
|
14
|
+
"presentation": {
|
|
15
|
+
"hidden": false,
|
|
16
|
+
"group": "",
|
|
17
|
+
"order": 1
|
|
18
|
+
},
|
|
19
|
+
"stopAll": true
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"configurations": [
|
|
23
|
+
{
|
|
24
|
+
"name": "Debug Main Process",
|
|
25
|
+
"type": "node",
|
|
26
|
+
"request": "launch",
|
|
27
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
|
|
28
|
+
"windows": {
|
|
29
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
|
|
30
|
+
},
|
|
31
|
+
"runtimeArgs": [
|
|
32
|
+
"--remote-debugging-port=9229",
|
|
33
|
+
"."
|
|
34
|
+
],
|
|
35
|
+
"envFile": "${workspaceFolder}/.vscode/.debug.env",
|
|
36
|
+
"console": "integratedTerminal"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "Debug Renderer Process",
|
|
40
|
+
"port": 9229,
|
|
41
|
+
"request": "attach",
|
|
42
|
+
"type": "chrome",
|
|
43
|
+
"timeout": 60000,
|
|
44
|
+
"skipFiles": [
|
|
45
|
+
"<node_internals>/**",
|
|
46
|
+
"${workspaceRoot}/node_modules/**",
|
|
47
|
+
"${workspaceRoot}/dist-electron/**",
|
|
48
|
+
// Skip files in host(VITE_DEV_SERVER_URL)
|
|
49
|
+
"http://127.0.0.1:6888/**"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
3
|
+
"typescript.tsc.autoDetect": "off",
|
|
4
|
+
"json.schemas": [
|
|
5
|
+
{
|
|
6
|
+
"fileMatch": [
|
|
7
|
+
"/*electron-builder.json5",
|
|
8
|
+
"/*electron-builder.json"
|
|
9
|
+
],
|
|
10
|
+
"url": "https://json.schemastore.org/electron-builder"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
3
|
+
// for the documentation about the tasks.json format
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"tasks": [
|
|
6
|
+
{
|
|
7
|
+
"label": "Before Debug",
|
|
8
|
+
"type": "shell",
|
|
9
|
+
"command": "node .vscode/.debug.script.mjs",
|
|
10
|
+
"isBackground": true,
|
|
11
|
+
"problemMatcher": {
|
|
12
|
+
"owner": "typescript",
|
|
13
|
+
"fileLocation": "relative",
|
|
14
|
+
"pattern": {
|
|
15
|
+
// TODO: correct "regexp"
|
|
16
|
+
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
|
17
|
+
"file": 1,
|
|
18
|
+
"line": 3,
|
|
19
|
+
"column": 4,
|
|
20
|
+
"code": 5,
|
|
21
|
+
"message": 6
|
|
22
|
+
},
|
|
23
|
+
"background": {
|
|
24
|
+
"activeOnStart": true,
|
|
25
|
+
"beginsPattern": "^.*VITE v.* ready in \\d* ms.*$",
|
|
26
|
+
"endsPattern": "^.*\\[startup\\] Electron App.*$"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# electron-react
|
|
2
|
+
|
|
3
|
+
vite + electron + react
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
- source code
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
├── electron
|
|
11
|
+
│ ├── main > Electron-Main
|
|
12
|
+
│ ├── payload > Electron-payload
|
|
13
|
+
├── src > Electron-Renderer
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- output
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
├─┬ dist
|
|
20
|
+
│ ├── main.js > Electron-Main
|
|
21
|
+
│ ├── preload.js > Preload-Scripts
|
|
22
|
+
│ ├─┬ render > Electron-Renderer
|
|
23
|
+
│ │ └── index.html
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Reference project
|
|
27
|
+
|
|
28
|
+
- [electron-vite-react](https://github.com/electron-vite/electron-vite-react)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { release } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
4
|
+
|
|
5
|
+
// The built directory structure
|
|
6
|
+
//
|
|
7
|
+
// ├─┬ dist
|
|
8
|
+
// │ ├── main.js > Electron-Main
|
|
9
|
+
// │ ├── preload.js > Preload-Scripts
|
|
10
|
+
// │ ├─┬ render > Electron-Renderer
|
|
11
|
+
// │ │ └── index.html
|
|
12
|
+
//
|
|
13
|
+
process.env.DIST_ELECTRON = __dirname;
|
|
14
|
+
process.env.DIST = join(process.env.DIST_ELECTRON, 'render');
|
|
15
|
+
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
|
|
16
|
+
? join(process.env.DIST_ELECTRON, '../public')
|
|
17
|
+
: process.env.DIST;
|
|
18
|
+
|
|
19
|
+
// Disable GPU Acceleration for Windows 7
|
|
20
|
+
if (release().startsWith('6.1')) app.disableHardwareAcceleration();
|
|
21
|
+
|
|
22
|
+
// Set application name for Windows 10+ notifications
|
|
23
|
+
if (process.platform === 'win32') app.setAppUserModelId(app.getName());
|
|
24
|
+
|
|
25
|
+
if (!app.requestSingleInstanceLock()) {
|
|
26
|
+
app.quit();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Remove electron security warnings
|
|
31
|
+
// This warning only shows in development mode
|
|
32
|
+
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
|
|
33
|
+
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
|
34
|
+
|
|
35
|
+
let win: BrowserWindow | null = null;
|
|
36
|
+
// Here, you can also use other preload
|
|
37
|
+
const preload = join(__dirname, './preload.js');
|
|
38
|
+
const url = process.env.VITE_DEV_SERVER_URL as string;
|
|
39
|
+
const indexHtml = join(process.env.DIST, 'index.html');
|
|
40
|
+
|
|
41
|
+
async function createWindow() {
|
|
42
|
+
win = new BrowserWindow({
|
|
43
|
+
title: 'Main window',
|
|
44
|
+
width: 800,
|
|
45
|
+
height: 700,
|
|
46
|
+
webPreferences: {
|
|
47
|
+
preload,
|
|
48
|
+
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
|
|
49
|
+
// Consider using contextBridge.exposeInMainWorld
|
|
50
|
+
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
|
|
51
|
+
nodeIntegration: true,
|
|
52
|
+
contextIsolation: false,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (process.env.VITE_DEV_SERVER_URL) {
|
|
57
|
+
// electron-vite-vue#298
|
|
58
|
+
win.loadURL(url);
|
|
59
|
+
// Open devTool if the app is not packaged
|
|
60
|
+
// win.webContents.openDevTools();
|
|
61
|
+
} else {
|
|
62
|
+
win.loadFile(indexHtml);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Test actively push message to the Electron-Renderer
|
|
66
|
+
win.webContents.on('did-finish-load', () => {
|
|
67
|
+
win?.webContents.send('main-process-message', new Date().toLocaleString());
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Make all links open with the browser, not with the application
|
|
71
|
+
win.webContents.setWindowOpenHandler(({ url }) => {
|
|
72
|
+
if (url.startsWith('https:')) shell.openExternal(url);
|
|
73
|
+
return { action: 'deny' };
|
|
74
|
+
});
|
|
75
|
+
// win.webContents.on('will-navigate', (event, url) => { }) #344
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
app.whenReady().then(createWindow);
|
|
79
|
+
|
|
80
|
+
app.on('window-all-closed', () => {
|
|
81
|
+
win = null;
|
|
82
|
+
if (process.platform !== 'darwin') app.quit();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
app.on('second-instance', () => {
|
|
86
|
+
if (win) {
|
|
87
|
+
// Focus on the main window if the user tried to open another
|
|
88
|
+
if (win.isMinimized()) win.restore();
|
|
89
|
+
win.focus();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
app.on('activate', () => {
|
|
94
|
+
const allWindows = BrowserWindow.getAllWindows();
|
|
95
|
+
if (allWindows.length) {
|
|
96
|
+
allWindows[0].focus();
|
|
97
|
+
} else {
|
|
98
|
+
createWindow();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// New window example arg: new windows url
|
|
103
|
+
ipcMain.handle('open-win', (_, arg) => {
|
|
104
|
+
const childWindow = new BrowserWindow({
|
|
105
|
+
webPreferences: {
|
|
106
|
+
preload,
|
|
107
|
+
nodeIntegration: true,
|
|
108
|
+
contextIsolation: false,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (process.env.VITE_DEV_SERVER_URL) {
|
|
113
|
+
childWindow.loadURL(`${url}#${arg}`);
|
|
114
|
+
} else {
|
|
115
|
+
childWindow.loadFile(indexHtml, { hash: arg });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
|
|
8
|
+
<title>Vite + Electron + React + TS</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "electron-app",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "vite + electron + vue",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18"
|
|
7
|
+
},
|
|
8
|
+
"debug": {
|
|
9
|
+
"env": {
|
|
10
|
+
"VITE_DEV_SERVER_URL": "http://127.0.0.1:6888/"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/main.js",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "vite",
|
|
16
|
+
"build": "npm run clean && vue-tsc --noEmit && vite build",
|
|
17
|
+
"releaseOnly": "tsx ./scripts/release.ts",
|
|
18
|
+
"release": "npm run build && npm run releaseOnly",
|
|
19
|
+
"clean": "rimraf ./dist",
|
|
20
|
+
"preview": "vite preview",
|
|
21
|
+
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
|
|
22
|
+
"lint:eslint": "eslint \"src/**/*.{ts,tsx,vue}\" *.{js,cjs,ts} --fix --cache",
|
|
23
|
+
"lint:stylelint": "stylelint \"src/**/*.{css,scss,less,vue,html}\" --fix --cache",
|
|
24
|
+
"lint:prettier": "prettier --write .",
|
|
25
|
+
"prepare": "husky install"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"react": "^18.2.0",
|
|
29
|
+
"react-dom": "^18.2.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@commitlint/cli": "^18.4.2",
|
|
33
|
+
"@tomjs/commitlint": "^2.0.3",
|
|
34
|
+
"@tomjs/eslint": "^1.0.7",
|
|
35
|
+
"@tomjs/prettier": "^1.0.5",
|
|
36
|
+
"@tomjs/stylelint": "^1.0.5",
|
|
37
|
+
"@tomjs/tsconfig": "^1.0.7",
|
|
38
|
+
"@types/node": "^18.18.9",
|
|
39
|
+
"@types/react": "^18.2.37",
|
|
40
|
+
"@types/react-dom": "^18.2.15",
|
|
41
|
+
"@types/shelljs": "^0.8.15",
|
|
42
|
+
"@vitejs/plugin-react-swc": "^3.4.1",
|
|
43
|
+
"electron": "^27.1.0",
|
|
44
|
+
"electron-builder": "^24.6.4",
|
|
45
|
+
"eslint": "^8.53.0",
|
|
46
|
+
"husky": "^8.0.3",
|
|
47
|
+
"lint-staged": "^15.1.0",
|
|
48
|
+
"npm-run-all": "^4.1.5",
|
|
49
|
+
"prettier": "^3.1.0",
|
|
50
|
+
"rimraf": "^5.0.5",
|
|
51
|
+
"shelljs": "^0.8.5",
|
|
52
|
+
"stylelint": "^15.11.0",
|
|
53
|
+
"tree-kill": "^1.2.2",
|
|
54
|
+
"tsx": "^4.1.3",
|
|
55
|
+
"typescript": "^5.2.2",
|
|
56
|
+
"vite": "^4.5.0",
|
|
57
|
+
"vite-plugin-electron": "^0.15.4",
|
|
58
|
+
"vite-plugin-electron-renderer": "^0.14.5",
|
|
59
|
+
"vue-tsc": "^1.8.22"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Configuration } from 'electron-builder';
|
|
2
|
+
import pkg from '../package.json';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://www.electron.build/configuration/configuration
|
|
6
|
+
*/
|
|
7
|
+
export default {
|
|
8
|
+
appId: 'com.xxx.app',
|
|
9
|
+
productName: 'App',
|
|
10
|
+
directories: {
|
|
11
|
+
output: `build/${pkg.version}`,
|
|
12
|
+
app: 'dist',
|
|
13
|
+
},
|
|
14
|
+
files: ['main.js', 'preload.js', 'render'],
|
|
15
|
+
icon: 'public/img/icon.png',
|
|
16
|
+
artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
|
|
17
|
+
electronLanguages: ['zh-CN', 'en-US'],
|
|
18
|
+
win: {
|
|
19
|
+
target: [
|
|
20
|
+
{
|
|
21
|
+
target: 'nsis',
|
|
22
|
+
arch: ['x64'],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
mac: {
|
|
27
|
+
target: ['dmg'],
|
|
28
|
+
},
|
|
29
|
+
linux: {
|
|
30
|
+
target: ['AppImage'],
|
|
31
|
+
},
|
|
32
|
+
nsis: {
|
|
33
|
+
oneClick: false,
|
|
34
|
+
perMachine: false,
|
|
35
|
+
allowToChangeInstallationDirectory: true,
|
|
36
|
+
deleteAppDataOnUninstall: false,
|
|
37
|
+
},
|
|
38
|
+
} as Configuration;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 项目根路径
|
|
5
|
+
*/
|
|
6
|
+
export const ROOT_PATH = path.join(__dirname, '../');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 生成代码目录
|
|
10
|
+
*/
|
|
11
|
+
export const DIST_PATH = path.join(ROOT_PATH, '../dist');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* electron 依赖模块
|
|
15
|
+
*/
|
|
16
|
+
export const ELECTRON_DEPENDENCIES: string[] = [];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { build as electronBuild } from 'electron-builder';
|
|
5
|
+
import shell from 'shelljs';
|
|
6
|
+
import pkg from '../package.json';
|
|
7
|
+
import builderConfig from './builder';
|
|
8
|
+
import { DIST_PATH, ELECTRON_DEPENDENCIES } from './constants';
|
|
9
|
+
|
|
10
|
+
function genPkgJson() {
|
|
11
|
+
const pkgJson = {
|
|
12
|
+
name: pkg.name,
|
|
13
|
+
version: pkg.version,
|
|
14
|
+
author: os.userInfo().username,
|
|
15
|
+
description: pkg.description,
|
|
16
|
+
main: './main.js',
|
|
17
|
+
dependencies: Object.entries(Object.assign({}, pkg.dependencies, pkg.devDependencies))
|
|
18
|
+
.filter(([name]) => ELECTRON_DEPENDENCIES.includes(name))
|
|
19
|
+
.reduce((object, entry) => ({ ...object, [entry[0]]: entry[1] }), {}),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync(path.join(DIST_PATH, 'package.json'), JSON.stringify(pkgJson, undefined, 2));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function run() {
|
|
26
|
+
try {
|
|
27
|
+
genPkgJson();
|
|
28
|
+
// 安装依赖
|
|
29
|
+
shell.exec(`cd ${DIST_PATH} && npm install`);
|
|
30
|
+
console.log();
|
|
31
|
+
await electronBuild({ config: builderConfig });
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
run().then(() => {
|
|
39
|
+
console.log('Done!');
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#root {
|
|
2
|
+
max-width: 1280px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
padding: 2rem;
|
|
5
|
+
text-align: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.logo {
|
|
9
|
+
height: 6em;
|
|
10
|
+
padding: 1.5em;
|
|
11
|
+
will-change: filter;
|
|
12
|
+
transition: filter 300ms;
|
|
13
|
+
}
|
|
14
|
+
.logo:hover {
|
|
15
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
16
|
+
}
|
|
17
|
+
.logo.electron:hover {
|
|
18
|
+
filter: drop-shadow(0 0 2em #1b1c26aa);
|
|
19
|
+
}
|
|
20
|
+
.logo.react:hover {
|
|
21
|
+
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@keyframes logo-spin {
|
|
25
|
+
from {
|
|
26
|
+
transform: rotate(0deg);
|
|
27
|
+
}
|
|
28
|
+
to {
|
|
29
|
+
transform: rotate(360deg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
34
|
+
a:nth-of-type(2) .logo {
|
|
35
|
+
animation: logo-spin infinite 20s linear;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.card {
|
|
40
|
+
padding: 2em;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.read-the-docs {
|
|
44
|
+
color: #888;
|
|
45
|
+
}
|