@tomjs/create-app 0.0.7 → 0.0.9
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 +3 -2
- package/README.zh_CN.md +3 -2
- package/dist/index.mjs +4 -4
- package/package.json +3 -4
- package/template-electron-react/README.md +6 -6
- package/template-electron-react/electron/main/index.ts +7 -5
- package/template-electron-react/package.json +6 -8
- package/template-electron-react/scripts/builder.ts +1 -1
- package/template-electron-react/scripts/constants.ts +4 -1
- package/template-electron-react/scripts/release.ts +2 -2
- package/template-electron-react/vite.config.ts +5 -5
- package/template-electron-vue/README.md +6 -6
- package/template-electron-vue/electron/main/index.ts +8 -6
- package/template-electron-vue/package.json +8 -13
- package/template-electron-vue/scripts/builder.ts +1 -1
- package/template-electron-vue/scripts/constants.ts +4 -1
- package/template-electron-vue/scripts/release.ts +2 -2
- package/template-electron-vue/vite.config.ts +5 -5
- package/template-node/.eslintrc.cjs +7 -0
- package/template-node/README.md +3 -0
- package/template-node/_lintstagedrc.cjs +4 -0
- package/template-node/package.json +47 -0
- package/template-node/src/index.ts +14 -0
- package/template-node/tsconfig.json +7 -0
- package/template-node/tsup.config.ts +11 -0
- package/template-react/package.json +1 -0
- package/template-vue/package.json +1 -0
package/README.md
CHANGED
|
@@ -50,14 +50,15 @@ pnpm create @tomjs/app --template vue
|
|
|
50
50
|
|
|
51
51
|
Parameters:
|
|
52
52
|
|
|
53
|
-
- `-t --template` : specify the template
|
|
53
|
+
- `-t --template` : specify the template
|
|
54
54
|
|
|
55
55
|
Support templates:
|
|
56
56
|
|
|
57
57
|
- vue
|
|
58
|
-
- electron-vue
|
|
59
58
|
- react
|
|
59
|
+
- electron-vue
|
|
60
60
|
- electron-react
|
|
61
|
+
- node
|
|
61
62
|
|
|
62
63
|
## Reference project
|
|
63
64
|
|
package/README.zh_CN.md
CHANGED
|
@@ -51,14 +51,15 @@ pnpm create @tomjs/app my-app --template vue
|
|
|
51
51
|
|
|
52
52
|
参数说明:
|
|
53
53
|
|
|
54
|
-
- `-t --template
|
|
54
|
+
- `-t --template`:指定模板
|
|
55
55
|
|
|
56
56
|
支持模板:
|
|
57
57
|
|
|
58
58
|
- vue
|
|
59
|
-
- electron-vue
|
|
60
59
|
- react
|
|
60
|
+
- electron-vue
|
|
61
61
|
- electron-react
|
|
62
|
+
- node
|
|
62
63
|
|
|
63
64
|
## 参考项目
|
|
64
65
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
Scaffolding project in ${i}...`);let M
|
|
4
|
-
`);let
|
|
2
|
+
import l from"fs";import a from"path";import{fileURLToPath as K}from"url";import{blue as w,cyan as q,green as B,red as T,reset as p,yellow as $}from"kolorist";import G from"minimist";import H from"prompts";import s from"fs";import d from"path";function b(e){return[["t","template"]].forEach(([t,n])=>{e[n]=e[n]??e[t]}),e}function C(e){let t=s.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function y(e){return e?.trim().replace(/\/+$/g,"")}function J(e,t){s.mkdirSync(t,{recursive:!0});for(let n of s.readdirSync(e)){let m=d.resolve(e,n),g=d.resolve(t,n);v(m,g)}}function v(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(d.resolve(e,t),{recursive:!0,force:!0})}function k(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 D(e){if(!e)return;let n=e.split(" ")[0].split("/");return{name:n[0],version:n[1]}}var S=b(G(process.argv.slice(2),{string:["_"]})),F=process.cwd(),V=[{name:"vue",display:"Vue",color:B,variants:[{name:"vue",display:"Web",color:w},{name:"electron-vue",display:"Electron",color:$}]},{name:"react",display:"React",color:q,variants:[{name:"react",display:"Web",color:w},{name:"electron-react",display:"Electron",color:$}]},{name:"node",display:"Node",color:w}],R=V.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),Q={_gitignore:".gitignore","_lintstagedrc.cjs":".lintstagedrc.cjs"},h="my-app";async function X(){let e=y(S._[0]),t=S.template||S.t,n=e||h,m=()=>n==="."?a.basename(a.resolve()):n,g={};g=await H([{type:e?null:"text",name:"projectName",message:p("Project name:"),initial:h,onState:r=>{n=y(r.value)||h}},{type:()=>!l.existsSync(n)||C(n)?null:"toggle",name:"overwrite",message:()=>(n==="."?"Current directory":`Target directory "${n}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(r,{overwrite:o})=>{if(o===!1)throw console.log(T("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>k(m())?null:"text",name:"packageName",message:p("Package name:"),initial:()=>A(m()),validate:r=>k(r)||"Invalid package.json name"},{type:t&&R.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!R.includes(t)?p(`"${t}" isn't a valid template. Please choose from below: `):p("Select a framework:"),initial:0,choices:V.map(r=>{let o=r.color;return{title:o(r.display||r.name),value:r}})},{type:r=>r&&r.variants?"select":null,name:"variant",message:p("Select a variant:"),choices:r=>r?.variants?.map(o=>{let c=o.color;return{title:c(o.display||o.name),value:o.name}})}],{onCancel:()=>{throw console.log(T("\u2716")+" Operation cancelled"),new Error}});let{framework:z,overwrite:O,packageName:L,variant:M}=g,i=a.join(F,n);O?E(i):l.existsSync(i)||l.mkdirSync(i,{recursive:!0}),console.log(`
|
|
3
|
+
Scaffolding project in ${i}...`);let j=M||z?.name||t||"",x=r=>a.join(K(import.meta.url),"../..",`template-${r}`),N=x(j),U=j.includes("node");[N,x("config")].forEach(r=>{let o=l.readdirSync(r);for(let c of o){let W=Q[c]??c;if(U&&c.includes("stylelint"))return;let I=a.join(i,W);v(a.join(r,c),I)}});let P=JSON.parse(l.readFileSync(a.join(N,"package.json"),"utf-8"));P.name=L||m(),l.writeFileSync(a.join(i,"package.json"),JSON.stringify(P,null,2)+`
|
|
4
|
+
`);let _=D(process.env.npm_config_user_agent),u=_?_.name:"npm",f=a.relative(F,i);switch(console.log(`
|
|
5
5
|
Done. Now run:
|
|
6
|
-
`),i!==
|
|
6
|
+
`),i!==F&&console.log(` cd ${f.includes(" ")?`"${f}"`:f}`),u){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${u} install`),console.log(` ${u} run dev`);break}}X().catch(e=>{e.message&&console.error(e)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/create-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "create tomjs web app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tomjs",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"node": ">=18"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"cross-spawn": "^7.0.3",
|
|
37
36
|
"kolorist": "^1.8.0",
|
|
38
37
|
"minimist": "^1.2.8",
|
|
39
38
|
"prompts": "^2.4.2"
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"@tomjs/prettier": "^1.0.5",
|
|
46
45
|
"@tomjs/tsconfig": "^1.0.7",
|
|
47
46
|
"@types/minimist": "^1.2.5",
|
|
48
|
-
"@types/node": "^18.18.
|
|
47
|
+
"@types/node": "^18.18.11",
|
|
49
48
|
"@types/prompts": "^2.4.8",
|
|
50
49
|
"eslint": "^8.53.0",
|
|
51
50
|
"husky": "^8.0.3",
|
|
@@ -53,7 +52,7 @@
|
|
|
53
52
|
"np": "^8.0.4",
|
|
54
53
|
"npm-run-all": "^4.1.5",
|
|
55
54
|
"prettier": "^3.1.0",
|
|
56
|
-
"tsup": "^
|
|
55
|
+
"tsup": "^8.0.1",
|
|
57
56
|
"typescript": "^5.2.2"
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
@@ -8,18 +8,18 @@ vite + electron + react
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
├── electron
|
|
11
|
-
│ ├── main
|
|
12
|
-
│ ├── payload
|
|
13
|
-
├── src
|
|
11
|
+
│ ├── main > Electron-Main
|
|
12
|
+
│ ├── payload > Preload-Scripts
|
|
13
|
+
├── src > Electron-Renderer
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
- output
|
|
17
17
|
|
|
18
18
|
```
|
|
19
19
|
├─┬ dist
|
|
20
|
-
│ ├── main.
|
|
21
|
-
│ ├── preload.
|
|
22
|
-
│ ├─┬ render
|
|
20
|
+
│ ├── main.mjs > Electron-Main
|
|
21
|
+
│ ├── preload.mjs > Preload-Scripts
|
|
22
|
+
│ ├─┬ render > Electron-Renderer
|
|
23
23
|
│ │ └── index.html
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { release } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
4
5
|
|
|
5
6
|
// The built directory structure
|
|
6
7
|
//
|
|
7
8
|
// ├─┬ dist
|
|
8
|
-
// │ ├── main.
|
|
9
|
-
// │ ├── preload.
|
|
10
|
-
// │ ├─┬ render
|
|
9
|
+
// │ ├── main.mjs > Electron-Main
|
|
10
|
+
// │ ├── preload.mjs > Preload-Scripts
|
|
11
|
+
// │ ├─┬ render > Electron-Renderer
|
|
11
12
|
// │ │ └── index.html
|
|
12
13
|
//
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
15
|
process.env.DIST_ELECTRON = __dirname;
|
|
14
16
|
process.env.DIST = join(process.env.DIST_ELECTRON, 'render');
|
|
15
17
|
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
|
|
@@ -34,7 +36,7 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
34
36
|
|
|
35
37
|
let win: BrowserWindow | null = null;
|
|
36
38
|
// Here, you can also use other preload
|
|
37
|
-
const preload = join(__dirname, './preload.
|
|
39
|
+
const preload = join(__dirname, './preload.mjs');
|
|
38
40
|
const url = process.env.VITE_DEV_SERVER_URL as string;
|
|
39
41
|
const indexHtml = join(process.env.DIST, 'index.html');
|
|
40
42
|
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
"VITE_DEV_SERVER_URL": "http://127.0.0.1:6888/"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"main": "dist/main.
|
|
14
|
+
"main": "dist/main.mjs",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "vite",
|
|
17
|
-
"build": "npm run clean &&
|
|
18
|
-
"
|
|
19
|
-
"release": "npm run build && npm run releaseOnly",
|
|
17
|
+
"build": "npm run clean && vite build && npm run release",
|
|
18
|
+
"release": "tsx ./scripts/release.ts",
|
|
20
19
|
"clean": "rimraf ./dist",
|
|
21
20
|
"preview": "vite preview",
|
|
22
21
|
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
|
|
@@ -36,12 +35,12 @@
|
|
|
36
35
|
"@tomjs/prettier": "^1.0.5",
|
|
37
36
|
"@tomjs/stylelint": "^1.0.5",
|
|
38
37
|
"@tomjs/tsconfig": "^1.0.7",
|
|
39
|
-
"@types/node": "^18.18.
|
|
38
|
+
"@types/node": "^18.18.11",
|
|
40
39
|
"@types/react": "^18.2.37",
|
|
41
40
|
"@types/react-dom": "^18.2.15",
|
|
42
41
|
"@types/shelljs": "^0.8.15",
|
|
43
42
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
44
|
-
"electron": "^
|
|
43
|
+
"electron": "^28.0.0-beta.8",
|
|
45
44
|
"electron-builder": "^24.6.4",
|
|
46
45
|
"eslint": "^8.53.0",
|
|
47
46
|
"husky": "^8.0.3",
|
|
@@ -56,7 +55,6 @@
|
|
|
56
55
|
"typescript": "^5.2.2",
|
|
57
56
|
"vite": "^5.0.0",
|
|
58
57
|
"vite-plugin-electron": "^0.15.4",
|
|
59
|
-
"vite-plugin-electron-renderer": "^0.14.5"
|
|
60
|
-
"vue-tsc": "^1.8.22"
|
|
58
|
+
"vite-plugin-electron-renderer": "^0.14.5"
|
|
61
59
|
}
|
|
62
60
|
}
|
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
output: `build/${pkg.version}`,
|
|
12
12
|
app: 'dist',
|
|
13
13
|
},
|
|
14
|
-
files: ['main.
|
|
14
|
+
files: ['main.mjs', 'preload.mjs', 'render'],
|
|
15
15
|
icon: 'public/img/icon.png',
|
|
16
16
|
artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
|
|
17
17
|
electronLanguages: ['zh-CN', 'en-US'],
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* 项目根路径
|
|
@@ -8,7 +11,7 @@ export const ROOT_PATH = path.join(__dirname, '../');
|
|
|
8
11
|
/**
|
|
9
12
|
* 生成代码目录
|
|
10
13
|
*/
|
|
11
|
-
export const DIST_PATH = path.join(ROOT_PATH, '
|
|
14
|
+
export const DIST_PATH = path.join(ROOT_PATH, 'dist');
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* electron 依赖模块
|
|
@@ -13,7 +13,8 @@ function genPkgJson() {
|
|
|
13
13
|
version: pkg.version,
|
|
14
14
|
author: os.userInfo().username,
|
|
15
15
|
description: pkg.description,
|
|
16
|
-
|
|
16
|
+
type: 'module',
|
|
17
|
+
main: './main.mjs',
|
|
17
18
|
dependencies: Object.entries(Object.assign({}, pkg.dependencies, pkg.devDependencies))
|
|
18
19
|
.filter(([name]) => ELECTRON_DEPENDENCIES.includes(name))
|
|
19
20
|
.reduce((object, entry) => ({ ...object, [entry[0]]: entry[1] }), {}),
|
|
@@ -36,6 +37,5 @@ async function run() {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
run().then(() => {
|
|
39
|
-
console.log('Done!');
|
|
40
40
|
process.exit(0);
|
|
41
41
|
});
|
|
@@ -9,7 +9,7 @@ import pkg from './package.json';
|
|
|
9
9
|
|
|
10
10
|
// https://vitejs.dev/config/
|
|
11
11
|
export default defineConfig(({ command }) => {
|
|
12
|
-
['main.
|
|
12
|
+
['main.mjs', 'main.mjs.map', 'preload.mjs'].forEach(s => {
|
|
13
13
|
rmSync(`dist/${s}`, { recursive: true, force: true });
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -51,8 +51,8 @@ export default defineConfig(({ command }) => {
|
|
|
51
51
|
emptyOutDir: false,
|
|
52
52
|
lib: {
|
|
53
53
|
entry: 'electron/main/index.ts',
|
|
54
|
-
formats: ['
|
|
55
|
-
fileName: () => 'main.
|
|
54
|
+
formats: ['es'],
|
|
55
|
+
fileName: () => 'main.mjs',
|
|
56
56
|
},
|
|
57
57
|
rollupOptions: {
|
|
58
58
|
// Some third-party Node.js libraries may not be built correctly by Vite, especially `C/C++` addons,
|
|
@@ -83,8 +83,8 @@ export default defineConfig(({ command }) => {
|
|
|
83
83
|
emptyOutDir: false,
|
|
84
84
|
lib: {
|
|
85
85
|
entry: 'electron/preload/index.ts',
|
|
86
|
-
formats: ['
|
|
87
|
-
fileName: () => 'preload.
|
|
86
|
+
formats: ['es'],
|
|
87
|
+
fileName: () => 'preload.mjs',
|
|
88
88
|
},
|
|
89
89
|
rollupOptions: {
|
|
90
90
|
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
|
|
@@ -8,18 +8,18 @@ vite + electron + vue
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
├── electron
|
|
11
|
-
│ ├── main
|
|
12
|
-
│ ├── payload
|
|
13
|
-
├── src
|
|
11
|
+
│ ├── main > Electron-Main
|
|
12
|
+
│ ├── payload > Preload-Scripts
|
|
13
|
+
├── src > Electron-Renderer
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
- output
|
|
17
17
|
|
|
18
18
|
```
|
|
19
19
|
├─┬ dist
|
|
20
|
-
│ ├── main.
|
|
21
|
-
│ ├── preload.
|
|
22
|
-
│ ├─┬ render
|
|
20
|
+
│ ├── main.mjs > Electron-Main
|
|
21
|
+
│ ├── preload.mjs > Preload-Scripts
|
|
22
|
+
│ ├─┬ render > Electron-Renderer
|
|
23
23
|
│ │ └── index.html
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { release } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
4
5
|
|
|
5
6
|
// The built directory structure
|
|
6
7
|
//
|
|
7
8
|
// ├─┬ dist
|
|
8
|
-
// │ ├── main.
|
|
9
|
-
// │ ├── preload.
|
|
10
|
-
// │ ├─┬ render
|
|
9
|
+
// │ ├── main.mjs > Electron-Main
|
|
10
|
+
// │ ├── preload.mjs > Preload-Scripts
|
|
11
|
+
// │ ├─┬ render > Electron-Renderer
|
|
11
12
|
// │ │ └── index.html
|
|
12
13
|
//
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
15
|
process.env.DIST_ELECTRON = __dirname;
|
|
14
16
|
process.env.DIST = join(process.env.DIST_ELECTRON, 'render');
|
|
15
17
|
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
|
|
@@ -34,7 +36,7 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
34
36
|
|
|
35
37
|
let win: BrowserWindow | null = null;
|
|
36
38
|
// Here, you can also use other preload
|
|
37
|
-
const preload = join(__dirname, './preload.
|
|
39
|
+
const preload = join(__dirname, './preload.mjs');
|
|
38
40
|
const url = process.env.VITE_DEV_SERVER_URL as string;
|
|
39
41
|
const indexHtml = join(process.env.DIST, 'index.html');
|
|
40
42
|
|
|
@@ -42,7 +44,7 @@ async function createWindow() {
|
|
|
42
44
|
win = new BrowserWindow({
|
|
43
45
|
title: 'Main window',
|
|
44
46
|
width: 800,
|
|
45
|
-
height:
|
|
47
|
+
height: 700,
|
|
46
48
|
webPreferences: {
|
|
47
49
|
preload,
|
|
48
50
|
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
|
|
@@ -11,18 +11,13 @@
|
|
|
11
11
|
"VITE_DEV_SERVER_URL": "http://127.0.0.1:6888/"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"main": "dist/main.
|
|
14
|
+
"main": "dist/main.mjs",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"dev": "
|
|
17
|
-
"build": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"preview": "vite preview",
|
|
22
|
-
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
|
|
23
|
-
"lint:eslint": "eslint \"src/**/*.{ts,tsx,vue}\" *.{js,cjs,ts} --fix --cache",
|
|
24
|
-
"lint:stylelint": "stylelint \"src/**/*.{css,scss,less,vue,html}\" --fix --cache",
|
|
25
|
-
"lint:prettier": "prettier --write .",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"build": "tsup --minify",
|
|
18
|
+
"lint": "run-s lint:eslint lint:prettier",
|
|
19
|
+
"lint:eslint": "eslint \"src/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
|
|
20
|
+
"lint:prettier": "prettier --write \"src/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}",
|
|
26
21
|
"prepare": "husky install"
|
|
27
22
|
},
|
|
28
23
|
"dependencies": {
|
|
@@ -35,10 +30,10 @@
|
|
|
35
30
|
"@tomjs/prettier": "^1.0.5",
|
|
36
31
|
"@tomjs/stylelint": "^1.0.5",
|
|
37
32
|
"@tomjs/tsconfig": "^1.0.7",
|
|
38
|
-
"@types/node": "^18.18.
|
|
33
|
+
"@types/node": "^18.18.11",
|
|
39
34
|
"@types/shelljs": "^0.8.15",
|
|
40
35
|
"@vitejs/plugin-vue": "^4.5.0",
|
|
41
|
-
"electron": "^
|
|
36
|
+
"electron": "^28.0.0-beta.8",
|
|
42
37
|
"electron-builder": "^24.6.4",
|
|
43
38
|
"eslint": "^8.53.0",
|
|
44
39
|
"husky": "^8.0.3",
|
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
output: `build/${pkg.version}`,
|
|
12
12
|
app: 'dist',
|
|
13
13
|
},
|
|
14
|
-
files: ['main.
|
|
14
|
+
files: ['main.mjs', 'preload.mjs', 'render'],
|
|
15
15
|
icon: 'public/img/icon.png',
|
|
16
16
|
artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
|
|
17
17
|
electronLanguages: ['zh-CN', 'en-US'],
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* 项目根路径
|
|
@@ -8,7 +11,7 @@ export const ROOT_PATH = path.join(__dirname, '../');
|
|
|
8
11
|
/**
|
|
9
12
|
* 生成代码目录
|
|
10
13
|
*/
|
|
11
|
-
export const DIST_PATH = path.join(ROOT_PATH, '
|
|
14
|
+
export const DIST_PATH = path.join(ROOT_PATH, 'dist');
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* electron 依赖模块
|
|
@@ -13,7 +13,8 @@ function genPkgJson() {
|
|
|
13
13
|
version: pkg.version,
|
|
14
14
|
author: os.userInfo().username,
|
|
15
15
|
description: pkg.description,
|
|
16
|
-
main: './main.
|
|
16
|
+
main: './main.mjs',
|
|
17
|
+
type: 'module',
|
|
17
18
|
dependencies: Object.entries(Object.assign({}, pkg.dependencies, pkg.devDependencies))
|
|
18
19
|
.filter(([name]) => ELECTRON_DEPENDENCIES.includes(name))
|
|
19
20
|
.reduce((object, entry) => ({ ...object, [entry[0]]: entry[1] }), {}),
|
|
@@ -36,6 +37,5 @@ async function run() {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
run().then(() => {
|
|
39
|
-
console.log('Done!');
|
|
40
40
|
process.exit(0);
|
|
41
41
|
});
|
|
@@ -9,7 +9,7 @@ import pkg from './package.json';
|
|
|
9
9
|
|
|
10
10
|
// https://vitejs.dev/config/
|
|
11
11
|
export default defineConfig(({ command }) => {
|
|
12
|
-
['main.
|
|
12
|
+
['main.mjs', 'main.mjs.map', 'preload.mjs'].forEach(s => {
|
|
13
13
|
rmSync(`dist/${s}`, { recursive: true, force: true });
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -51,8 +51,8 @@ export default defineConfig(({ command }) => {
|
|
|
51
51
|
emptyOutDir: false,
|
|
52
52
|
lib: {
|
|
53
53
|
entry: 'electron/main/index.ts',
|
|
54
|
-
formats: ['
|
|
55
|
-
fileName: () => 'main.
|
|
54
|
+
formats: ['es'],
|
|
55
|
+
fileName: () => 'main.mjs',
|
|
56
56
|
},
|
|
57
57
|
rollupOptions: {
|
|
58
58
|
// Some third-party Node.js libraries may not be built correctly by Vite, especially `C/C++` addons,
|
|
@@ -83,8 +83,8 @@ export default defineConfig(({ command }) => {
|
|
|
83
83
|
emptyOutDir: false,
|
|
84
84
|
lib: {
|
|
85
85
|
entry: 'electron/preload/index.ts',
|
|
86
|
-
formats: ['
|
|
87
|
-
fileName: () => 'preload.
|
|
86
|
+
formats: ['es'],
|
|
87
|
+
fileName: () => 'preload.mjs',
|
|
88
88
|
},
|
|
89
89
|
rollupOptions: {
|
|
90
90
|
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "template-node",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "basic node template",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"start": "tsx ./src/index.ts",
|
|
22
|
+
"build": "tsup --minify",
|
|
23
|
+
"lint": "run-s lint:eslint lint:prettier",
|
|
24
|
+
"lint:eslint": "eslint \"src/**/*.ts\" *.{js,cjs,ts} --fix --cache",
|
|
25
|
+
"lint:prettier": "prettier --write .",
|
|
26
|
+
"prepare": "husky install"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"kolorist": "^1.8.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/tsconfig": "^1.0.7",
|
|
37
|
+
"@types/node": "^18.18.11",
|
|
38
|
+
"eslint": "^8.53.0",
|
|
39
|
+
"husky": "^8.0.3",
|
|
40
|
+
"lint-staged": "^15.1.0",
|
|
41
|
+
"npm-run-all": "^4.1.5",
|
|
42
|
+
"prettier": "^3.1.0",
|
|
43
|
+
"tsup": "^8.0.1",
|
|
44
|
+
"tsx": "^4.2.0",
|
|
45
|
+
"typescript": "^5.2.2"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { blue } from 'kolorist';
|
|
3
|
+
|
|
4
|
+
function run() {
|
|
5
|
+
console.log(blue('Hello World!'));
|
|
6
|
+
console.log(
|
|
7
|
+
`system: ${os.platform()} ${os.arch()} v${os.release()} ${os.cpus().length} cores ${Math.ceil(
|
|
8
|
+
os.totalmem() / 1024 / 1024 / 1024,
|
|
9
|
+
)}GB`,
|
|
10
|
+
);
|
|
11
|
+
console.log(`node: ${process.version} ${process.arch}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
run();
|