@tomjs/create-app 0.4.1 → 0.4.3
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/dist/index.mjs +6 -6
- package/package.json +3 -3
- package/template-electron-react/.vscode/launch.json +20 -0
- package/template-electron-react/README.md +4 -4
- package/template-electron-react/electron/main/index.ts +2 -4
- package/template-electron-react/package.json +6 -7
- package/template-electron-react/vite.config.ts +1 -12
- package/template-electron-vue/.vscode/launch.json +20 -0
- package/template-electron-vue/README.md +2 -2
- package/template-electron-vue/electron/main/index.ts +2 -4
- package/template-electron-vue/package.json +8 -8
- package/template-electron-vue/vite.config.ts +1 -14
- package/template-node/README.md +10 -17
- package/template-node/README.zh_CN.md +10 -17
- package/template-node/package.json +5 -6
- package/template-react/package.json +3 -3
- package/template-vue/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import a,{renameSync as Ce}from"fs";import Oe from"os";import i from"path";import{fileURLToPath as
|
|
3
|
-
`)}function $(e){
|
|
4
|
-
Scaffolding project in ${s}...`);let
|
|
2
|
+
import a,{renameSync as Ce}from"fs";import Oe from"os";import i from"path";import{fileURLToPath as Ne}from"url";import{blue as q,cyan as Fe,green as Te,red as fe,reset as w,yellow as X}from"kolorist";import{camelCase as De}from"lodash-es";import Ge from"minimist";import Ue from"prompts";import b from"shelljs";import pe from"os";import me from"path";import{blue as Re,red as C,reset as O}from"kolorist";import Pe from"minimist";import Y from"prompts";import l from"fs";import W from"path";function A(e){return[["t","template"],["g","git"]].forEach(([n,c])=>{e[c]=e[c]??e[n]}),e}function re(e){let n=l.readdirSync(e);return n.length===0||n.length===1&&n[0]===".git"}function J(e){return e?.trim().replace(/\/+$/g,"")}function be(e,n){l.mkdirSync(n,{recursive:!0});for(let c of l.readdirSync(e)){let y=W.resolve(e,c),m=W.resolve(n,c);M(y,m)}}function M(e,n){l.statSync(e).isDirectory()?be(e,n):l.copyFileSync(e,n)}function oe(e){if(l.existsSync(e))for(let n of l.readdirSync(e))n!==".git"&&l.rmSync(W.resolve(e,n),{recursive:!0,force:!0})}function z(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function ie(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function se(e){if(!e)return;let c=e.split(" ")[0].split("/");return{name:c[0],version:c[1]}}function v(e){if(l.existsSync(e))try{return JSON.parse(l.readFileSync(e,"utf8"))}catch(n){console.error(n)}}function x(e,n){l.writeFileSync(e,JSON.stringify(n,null,2)+`
|
|
3
|
+
`)}function $(e){l.existsSync(e)&&l.rmSync(e,{recursive:!0,force:!0})}function ce(e){l.existsSync(e)||l.mkdirSync(e,{recursive:!0})}var Ae=A(Pe(process.argv.slice(2),{string:["_"]})),ae={repo:"https://github.com",owner:pe.userInfo().username};function L(e){let{repo:n,owner:c}=e;return`${n}${n.endsWith("/")?"":"/"}${c}`}async function le(e){let n=await Y([{type:"text",name:"repo",message:O("Git repository url:"),initial:e?.repo||ae.repo},{type:"text",name:"owner",message:O("Git repository owner:"),initial:e?.owner||ae.owner}],{onCancel:()=>{throw console.log(C("\u2716")+" Operation cancelled"),new Error}});return{id:e?.id||Date.now().toString(),repo:n.repo,owner:n.owner}}var ue=me.join(pe.homedir(),".tomjs","create-app"),ge=me.join(ue,"config.json");function N(){return ce(ue),Object.assign({gitRepos:[]},v(ge))}function $e(e){let n=N();n.createTime?n.updateTime=Date.now():n.createTime=Date.now(),x(ge,Object.assign(n,e))}function V(e){$e({gitRepos:e})}async function K(){let{gitRepos:e}=N();(e.length===0||Ae.git)&&(e.length===0&&console.log(`You need to set the ${Re("git remote repository")} for the first time.`),await n());async function n(){let c=e.map(g=>({title:L(g),value:g.id})).concat([{title:"Add",value:"add"},{title:C("Exit"),value:"exit"}]),y=await Y({type:"select",name:"repoId",message:e.length===0?"You choose to add or exit:":"You can choose the repository to be operated, or choose to add or exit:",choices:c},{onCancel:()=>{throw console.log(C("\u2716")+" Operation cancelled"),new Error}}),{repoId:m}=y;if(m==="exit")return;if(m==="add"){let g=await le();return e.push(g),V(e),n()}let S=e.findIndex(g=>g.id===m),R=await Y([{type:"select",name:"action",message:O("Select an action?"),choices:[{title:"Edit",value:"edit"},{title:"Remove",value:"remove"},{title:"Exit",value:"exit"}]},{type:g=>g==="remove"&&"toggle",name:"confirmRemove",message:O("Where confirm to remove?"),initial:!0,active:"Yes",inactive:"No"}],{onCancel:()=>{throw console.log(C("\u2716")+" Operation cancelled"),new Error}}),{action:P,confirmRemove:F}=R;if(P==="exit")return K();if(P==="remove")return F&&(e.splice(S,1),V(e)),n();let T=await le(e[S]);return e[S]=T,V(e),n()}}var B=A(Ge(process.argv.slice(2),{string:["_"]})),H=process.cwd(),ve=[{name:"vue",display:"Vue",color:Te,variants:[{name:"vue",display:"Web",color:q},{name:"electron-vue",display:"Electron",color:X}]},{name:"react",display:"React",color:Fe,variants:[{name:"react",display:"Web",color:q},{name:"electron-react",display:"Electron",color:X}]},{name:"node",display:"Node",color:q,options:[{id:"test",name:"Test"},{id:"publish",name:"Git Repository + NPM"},{id:"vite",name:"Vite Plugin"},{id:"electron",name:"Electron"},{id:"examples",name:"Examples"}]}],de=ve.map(e=>e.variants&&e.variants.map(n=>n.name)||[e.name]).reduce((e,n)=>e.concat(n),[]),Q="my-app";function ye(e){let n=b.exec(`git config --get ${e}`,{silent:!0});if(n.code===0)return n.stdout.trim()}function he(e){return e.length>1?e.substring(e.indexOf("/")+1):e}async function _e(){let e=J(B._[0]),n=B.template||B.t,c=e||Q,y=()=>c==="."?i.basename(i.resolve()):c,m=he(c),{gitRepos:S}=N(),R=await Ue([{type:e?null:"text",name:"projectName",message:w("Project name:"),initial:Q,onState:t=>{c=J(t.value)||Q,m=he(c)}},{type:()=>!a.existsSync(m)||re(m)?null:"toggle",name:"overwrite",message:()=>(m==="."?"Current directory":`Target directory "${m}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"Yes",inactive:"No"},{type:(t,{overwrite:r})=>{if(r===!1)throw console.log(fe("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>z(y())?null:"text",name:"packageName",message:w("Package name:"),initial:()=>ie(y()),validate:t=>z(t)||"Invalid package.json name"},{type:n&&de.includes(n)?null:"select",name:"framework",message:typeof n=="string"&&!de.includes(n)?w(`"${n}" isn't a valid template. Please choose from below: `):w("Select a framework:"),initial:0,choices:ve.map(t=>{let r=t.color;return{title:r(t.display||t.name),value:t}})},{type:t=>t&&t.variants?"select":null,name:"variant",message:w("Select a variant:"),choices:t=>t?.variants?.map(r=>{let o=r.color;return{title:o(r.display||r.name),value:r.name}})},{type:(t,r)=>{let{framework:o}=r;return o&&Array.isArray(o.options)&&o.options.length?"multiselect":null},name:"options",message:w("Select optional options:"),instructions:!1,choices:(t,r)=>{let{framework:o}=r;return o?.options?.map(p=>({title:p.name,value:p.id}))}},{type:(t,r)=>S.length&&Array.isArray(r.options)&&r.options.includes("publish")?"select":null,name:"gitUserUrl",message:w("Which git repository to publish to?"),choices:S.map(t=>{let r=L(t);return{title:r,value:r}})}],{onCancel:()=>{throw console.log(fe("\u2716")+" Operation cancelled"),new Error}}),{framework:P,overwrite:F,packageName:T,variant:g,gitUserUrl:xe}=R,f=R.options||[],s=i.join(H,m);F?oe(s):a.existsSync(s)||a.mkdirSync(s,{recursive:!0}),console.log(`
|
|
4
|
+
Scaffolding project in ${s}...`);let Z=g||P?.name||n||"",D=t=>i.join(Ne(import.meta.url),"../..",`template-${t}`),we=D(Z),G=Z.includes("node");[we,D("config")].forEach(t=>{let r=a.readdirSync(t);for(let o of r){let p=o.startsWith("_")?o.replace("_","."):o;if(G&&!f.includes("examples")&&o.includes("stylelint"))continue;let u=i.join(s,p);M(i.join(t,o),u)}});let h=T||y(),j={name:"UserName",email:"name@github.com"};function ee(){let t=h.startsWith("@")?h.split("/")[0].substring(1):De(j.name);return`${xe||`https://github.com/${t}`}/${h.substring(h.indexOf("/")+1)}.git`}je(),G&&(Se(),ke(),Ee());let te=se(process.env.npm_config_user_agent),U=te?te.name:"npm";b.which("git")&&(b.exec(`cd ${s} && git init`),f.includes("publish")&&b.exec(`cd ${s} && git remote add origin ${ee()}`));let _=i.relative(H,s);switch(console.log(`
|
|
5
5
|
Done. Now run:
|
|
6
|
-
`),s!==
|
|
7
|
-
`,{encoding:"utf-8"});return}if(!a.existsSync(
|
|
8
|
-
- 'examples/*'`,{encoding:"utf-8"})}}
|
|
6
|
+
`),s!==H&&console.log(` cd ${_.includes(" ")?`"${_}"`:_}`),U){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${U} install`),console.log(` ${U} run dev`);break}function Se(){["LICENSE","README.md","README.zh_CN.md"].forEach(t=>{let r=i.join(s,t);if(!f.includes("publish")&&a.existsSync(r)){a.rmSync(r),t==="README.md"&&a.writeFileSync(r,`# ${h}
|
|
7
|
+
`,{encoding:"utf-8"});return}if(!a.existsSync(r))return;let o=a.readFileSync(r,"utf-8").replace(new RegExp("{{pkg.name}}","g"),h).replace(new RegExp("{{user.name}}","g"),j.name).replace(new RegExp("{{user.email}}","g"),j.email);a.writeFileSync(r,o)})}function k(t,...r){["dependencies","devDependencies"].forEach(o=>{Object.keys(t[o]||{}).forEach(p=>{r.find(u=>p.includes(u))&&delete t[o][p]})})}function je(){let t=v(i.join(s,"package.json"));t.name=h,f.includes("publish")?(b.which("git")&&(j.name=ye("user.name")||Oe.userInfo().username,j.email=ye("user.email")||"",t.author=Object.assign(t.author,j)),t.repository.url=`git+${ee()}`):(delete t.author,delete t.publishConfig,delete t.repository,delete t.scripts.prepublishOnly,delete t.devDependencies.np),G&&(f.includes("electron")||(k(t,"electron"),t.scripts["lint:eslint"]=t.scripts["lint:eslint"].replace(",electron","")),f.includes("vite")&&k(t,"vite")),x(i.join(s,"package.json"),t)}function I(t,r){let o=t.lastIndexOf("."),p=t.substring(0,o)+"."+r+t.substring(o),u=i.join(s,t),d=i.join(s,p);f.includes(r)?($(u),a.existsSync(d)&&Ce(d,u)):$(d)}function ke(){if(I("tsconfig.json","test"),I("jest.config.cjs","electron"),f.includes("test"))return;a.readdirSync(s).filter(o=>o.startsWith("jest.config")||["test"].includes(o)).forEach(o=>{$(i.join(s,o))});let t=i.join(s,"package.json"),r=v(t);delete r.scripts.test,r.scripts["lint:eslint"]=r.scripts["lint:eslint"].replace(",test",""),k(r,"jest"),x(t,r)}function Ee(){if(I(".lintstagedrc.cjs","examples"),!f.includes("examples")){let o=v(i.join(s,"package.json"));o.scripts.lint=o.scripts.lint.replace(" lint:stylelint",""),o.scripts["lint:eslint"]=o.scripts["lint:eslint"].replace(",examples",""),delete o.scripts["lint:stylelint"],k(o,"stylelint"),x(i.join(s,"package.json"),o);return}let t=i.join(s,"examples");a.mkdirSync(t);let r=f.includes("electron");["vue","react"].forEach(o=>{let p=D(r?`electron-${o}`:o),u=i.join(t,o);if(!a.existsSync(p)){console.log(`${X(p)} template is not exist`);return}a.cpSync(p,u,{recursive:!0});let d=v(i.join(u,"package.json"));Object.keys(d.scripts).forEach(E=>{(E.startsWith("lint")||["prepare"].includes(E))&&delete d.scripts[E]}),k(d,"eslint","prettier","stylelint","commitlint","husky","lint-staged","tsconfig","lint-staged","npm-run-all"),x(i.join(u,"package.json"),d),["_lintstagedrc.cjs"].forEach(E=>{let ne=i.join(u,E);a.existsSync(ne)&&a.rmSync(ne,{recursive:!0})})}),a.writeFileSync(i.join(s,"pnpm-workspace.yaml"),`packages:
|
|
8
|
+
- 'examples/*'`,{encoding:"utf-8"})}}K().then(async()=>_e().catch(e=>{e.message&&console.error(e)})).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.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "create tomjs web app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tomjs",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@tomjs/eslint": "^1.1.1",
|
|
56
56
|
"@tomjs/prettier": "^1.0.6",
|
|
57
57
|
"@tomjs/stylelint": "^1.1.1",
|
|
58
|
-
"@tomjs/tsconfig": "^1.
|
|
58
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
59
59
|
"@types/lodash-es": "^4.17.12",
|
|
60
60
|
"@types/minimist": "^1.2.5",
|
|
61
61
|
"@types/node": "^18.19.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"lint-staged": "^15.2.0",
|
|
67
67
|
"np": "^9.1.0",
|
|
68
68
|
"npm-run-all": "^4.1.5",
|
|
69
|
-
"prettier": "^3.1.
|
|
69
|
+
"prettier": "^3.1.1",
|
|
70
70
|
"stylelint": "^15.11.0",
|
|
71
71
|
"tsup": "^8.0.1",
|
|
72
72
|
"typescript": "~5.2.2"
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Debug Main Process",
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"cwd": "${workspaceRoot}",
|
|
12
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
|
|
13
|
+
"windows": {
|
|
14
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
|
|
15
|
+
},
|
|
16
|
+
"args": ["."],
|
|
17
|
+
"envFile": "${workspaceRoot}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
|
|
18
|
+
},
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -4,7 +4,7 @@ vite + electron + react
|
|
|
4
4
|
|
|
5
5
|
## Description
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Recommend `electron` and page `src` code directory structure
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
|--electron
|
|
@@ -13,11 +13,11 @@ vite + electron + react
|
|
|
13
13
|
| |--preload
|
|
14
14
|
| | |--index.ts
|
|
15
15
|
|--src
|
|
16
|
-
| |--App.
|
|
17
|
-
| |--main.
|
|
16
|
+
| |--App.vue
|
|
17
|
+
| |--main.ts
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
-
|
|
20
|
+
- Zero configuration, default dist output directory
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
|--dist
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { release } from 'node:os';
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { join } from 'node:path';
|
|
4
3
|
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
5
4
|
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
5
|
const isDev = process.env.NODE_ENV === 'development';
|
|
8
6
|
|
|
9
7
|
// Disable GPU Acceleration for Windows 7
|
|
@@ -24,7 +22,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
|
|
|
24
22
|
|
|
25
23
|
let win: BrowserWindow | null = null;
|
|
26
24
|
// package.json "type":"module", must use mjs extension
|
|
27
|
-
const preload = join(__dirname, '../preload/index.
|
|
25
|
+
const preload = join(__dirname, '../preload/index.js');
|
|
28
26
|
const serverUrl = process.env.APP_DEV_SERVER_URL as string;
|
|
29
27
|
const rendererDist = join(__dirname, '../renderer');
|
|
30
28
|
const indexHtml = join(rendererDist, 'index.html');
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-app",
|
|
3
3
|
"version": "0.0.0",
|
|
4
|
-
"type": "module",
|
|
5
4
|
"description": "vite + electron + vue",
|
|
6
5
|
"engines": {
|
|
7
6
|
"node": ">=18"
|
|
8
7
|
},
|
|
9
|
-
"main": "dist/main/index.
|
|
8
|
+
"main": "dist/main/index.js",
|
|
10
9
|
"scripts": {
|
|
11
10
|
"dev": "vite",
|
|
12
11
|
"build": "npm run clean && vite build && npm run release",
|
|
@@ -19,20 +18,20 @@
|
|
|
19
18
|
"prepare": "husky install"
|
|
20
19
|
},
|
|
21
20
|
"dependencies": {
|
|
21
|
+
"@tomjs/electron-devtools-installer": "^2.0.5",
|
|
22
22
|
"react": "^18.2.0",
|
|
23
23
|
"react-dom": "^18.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@commitlint/cli": "^18.4.3",
|
|
27
27
|
"@tomjs/commitlint": "^2.0.5",
|
|
28
|
-
"@tomjs/electron-devtools-installer": "^2.0.3",
|
|
29
28
|
"@tomjs/eslint": "^1.1.1",
|
|
30
29
|
"@tomjs/prettier": "^1.0.6",
|
|
31
30
|
"@tomjs/stylelint": "^1.1.1",
|
|
32
|
-
"@tomjs/tsconfig": "^1.
|
|
33
|
-
"@tomjs/vite-plugin-electron": "^1.
|
|
31
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
32
|
+
"@tomjs/vite-plugin-electron": "^1.3.5",
|
|
34
33
|
"@types/node": "^18.19.3",
|
|
35
|
-
"@types/react": "^18.2.
|
|
34
|
+
"@types/react": "^18.2.43",
|
|
36
35
|
"@types/react-dom": "^18.2.17",
|
|
37
36
|
"@types/shelljs": "^0.8.15",
|
|
38
37
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
@@ -42,7 +41,7 @@
|
|
|
42
41
|
"husky": "^8.0.3",
|
|
43
42
|
"lint-staged": "^15.2.0",
|
|
44
43
|
"npm-run-all": "^4.1.5",
|
|
45
|
-
"prettier": "^3.1.
|
|
44
|
+
"prettier": "^3.1.1",
|
|
46
45
|
"rimraf": "^5.0.5",
|
|
47
46
|
"shelljs": "^0.8.5",
|
|
48
47
|
"stylelint": "^15.11.0",
|
|
@@ -17,23 +17,12 @@ export default defineConfig(() => {
|
|
|
17
17
|
'@': path.join(__dirname, 'src'),
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
|
-
build: {
|
|
21
|
-
emptyOutDir: true,
|
|
22
|
-
},
|
|
23
20
|
plugins: [
|
|
24
21
|
react(),
|
|
25
|
-
electron(
|
|
26
|
-
main: {
|
|
27
|
-
entry: 'electron/main/index.ts',
|
|
28
|
-
},
|
|
29
|
-
preload: {
|
|
30
|
-
entry: 'electron/preload/index.ts',
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
22
|
+
electron(),
|
|
33
23
|
// Use Node.js API in the Renderer process
|
|
34
24
|
renderer(),
|
|
35
25
|
],
|
|
36
|
-
server: {},
|
|
37
26
|
clearScreen: false,
|
|
38
27
|
};
|
|
39
28
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Debug Main Process",
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"cwd": "${workspaceRoot}",
|
|
12
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
|
|
13
|
+
"windows": {
|
|
14
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
|
|
15
|
+
},
|
|
16
|
+
"args": ["."],
|
|
17
|
+
"envFile": "${workspaceRoot}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
|
|
18
|
+
},
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -4,7 +4,7 @@ vite + electron + vue
|
|
|
4
4
|
|
|
5
5
|
## Description
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Recommend `electron` and page `src` code directory structure
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
|--electron
|
|
@@ -17,7 +17,7 @@ vite + electron + vue
|
|
|
17
17
|
| |--main.ts
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
-
|
|
20
|
+
- Zero configuration, default dist output directory
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
|--dist
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { release } from 'node:os';
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { join } from 'node:path';
|
|
4
3
|
import { app, BrowserWindow, ipcMain, shell } from 'electron';
|
|
5
4
|
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
5
|
const isDev = process.env.NODE_ENV === 'development';
|
|
8
6
|
|
|
9
7
|
// Disable GPU Acceleration for Windows 7
|
|
@@ -24,7 +22,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
|
|
|
24
22
|
|
|
25
23
|
let win: BrowserWindow | null = null;
|
|
26
24
|
// package.json "type":"module", must use mjs extension
|
|
27
|
-
const preload = join(__dirname, '../preload/index.
|
|
25
|
+
const preload = join(__dirname, '../preload/index.js');
|
|
28
26
|
const serverUrl = process.env.APP_DEV_SERVER_URL as string;
|
|
29
27
|
const rendererDist = join(__dirname, '../renderer');
|
|
30
28
|
const indexHtml = join(rendererDist, 'index.html');
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-app",
|
|
3
3
|
"version": "0.0.0",
|
|
4
|
-
"type": "module",
|
|
5
4
|
"description": "vite + electron + vue",
|
|
6
5
|
"engines": {
|
|
7
6
|
"node": ">=18"
|
|
8
7
|
},
|
|
9
|
-
"main": "dist/main/index.
|
|
8
|
+
"main": "dist/main/index.js",
|
|
10
9
|
"scripts": {
|
|
11
10
|
"dev": "vite",
|
|
12
11
|
"build": "npm run clean && vue-tsc --noEmit && vite build && npm run release",
|
|
13
12
|
"release": "tsx ./scripts/release.ts",
|
|
14
13
|
"clean": "rimraf ./dist",
|
|
15
|
-
"lint": "run-s lint:eslint lint:prettier",
|
|
14
|
+
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
|
|
16
15
|
"lint:eslint": "eslint \"{src,electron,scripts}/**/*.{js,cjs,ts,vue}\" *.{js,cjs,ts} --fix --cache",
|
|
17
|
-
"lint:
|
|
16
|
+
"lint:stylelint": "stylelint \"{src,electron,scripts}/**/*.{css,scss,less,html}\" --fix --cache",
|
|
17
|
+
"lint:prettier": "prettier --write .",
|
|
18
18
|
"prepare": "husky install"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@tomjs/electron-devtools-installer": "^2.0.5",
|
|
21
22
|
"vue": "^3.3.11"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@commitlint/cli": "^18.4.3",
|
|
25
26
|
"@tomjs/commitlint": "^2.0.5",
|
|
26
|
-
"@tomjs/electron-devtools-installer": "^2.0.3",
|
|
27
27
|
"@tomjs/eslint": "^1.1.1",
|
|
28
28
|
"@tomjs/prettier": "^1.0.6",
|
|
29
29
|
"@tomjs/stylelint": "^1.1.1",
|
|
30
|
-
"@tomjs/tsconfig": "^1.
|
|
31
|
-
"@tomjs/vite-plugin-electron": "^1.
|
|
30
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
31
|
+
"@tomjs/vite-plugin-electron": "^1.3.5",
|
|
32
32
|
"@types/node": "^18.19.3",
|
|
33
33
|
"@types/shelljs": "^0.8.15",
|
|
34
34
|
"@vitejs/plugin-vue": "^4.5.2",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"husky": "^8.0.3",
|
|
39
39
|
"lint-staged": "^15.2.0",
|
|
40
40
|
"npm-run-all": "^4.1.5",
|
|
41
|
-
"prettier": "^3.1.
|
|
41
|
+
"prettier": "^3.1.1",
|
|
42
42
|
"rimraf": "^5.0.5",
|
|
43
43
|
"shelljs": "^0.8.5",
|
|
44
44
|
"stylelint": "^15.11.0",
|
|
@@ -11,30 +11,17 @@ export default defineConfig(() => {
|
|
|
11
11
|
process.env.APP_VERSION = pkg.version;
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
|
-
envPrefix: ['VITE_', 'APP_'],
|
|
15
14
|
resolve: {
|
|
16
15
|
alias: {
|
|
17
16
|
'@': path.join(__dirname, 'src'),
|
|
18
17
|
},
|
|
19
18
|
},
|
|
20
|
-
build: {
|
|
21
|
-
outDir: 'dist/render',
|
|
22
|
-
emptyOutDir: true,
|
|
23
|
-
},
|
|
24
19
|
plugins: [
|
|
25
20
|
vue(),
|
|
26
|
-
electron(
|
|
27
|
-
main: {
|
|
28
|
-
entry: 'electron/main/index.ts',
|
|
29
|
-
},
|
|
30
|
-
preload: {
|
|
31
|
-
entry: 'electron/preload/index.ts',
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
21
|
+
electron(),
|
|
34
22
|
// Use Node.js API in the Renderer process
|
|
35
23
|
renderer(),
|
|
36
24
|
],
|
|
37
|
-
server: {},
|
|
38
25
|
clearScreen: false,
|
|
39
26
|
};
|
|
40
27
|
});
|
package/template-node/README.md
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# {{pkg.name}}
|
|
2
2
|
|
|
3
|
-
{{badges}}
|
|
4
|
-
|
|
5
|
-
> Basic node template
|
|
3
|
+
[](https://www.npmjs.com/package/{{pkg.name}})   [](https://www.paka.dev/npm/{{pkg.name}})
|
|
6
4
|
|
|
7
5
|
**English** | [中文](./README.zh_CN.md)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
With `pnpm`
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pnpm add template-node
|
|
15
|
-
```
|
|
7
|
+
> Basic node template
|
|
16
8
|
|
|
17
|
-
|
|
9
|
+
## Install
|
|
18
10
|
|
|
19
11
|
```bash
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
# pnpm
|
|
13
|
+
pnpm add {{pkg.name}} -D
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
# yarn
|
|
16
|
+
yarn add {{pkg.name}} -D
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
npm i
|
|
18
|
+
# npm
|
|
19
|
+
npm i {{pkg.name}} --save-dev
|
|
27
20
|
```
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# {{pkg.name}}
|
|
2
2
|
|
|
3
|
-
{{badges}}
|
|
4
|
-
|
|
5
|
-
> 基础 node 模板
|
|
3
|
+
[](https://www.npmjs.com/package/{{pkg.name}})   [](https://www.paka.dev/npm/{{pkg.name}})
|
|
6
4
|
|
|
7
5
|
[English](./README.md) | **中文**
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
使用 `pnpm`
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pnpm add template-node
|
|
15
|
-
```
|
|
7
|
+
> 基础 node 模板
|
|
16
8
|
|
|
17
|
-
|
|
9
|
+
## 安装
|
|
18
10
|
|
|
19
11
|
```bash
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
# pnpm
|
|
13
|
+
pnpm add {{pkg.name}} -D
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
# yarn
|
|
16
|
+
yarn add {{pkg.name}} -D
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
npm i
|
|
18
|
+
# npm
|
|
19
|
+
npm i {{pkg.name}} --save-dev
|
|
27
20
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "{{pkg.name}}",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"description": "basic node.js template",
|
|
5
5
|
"keywords": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/xxx/template
|
|
35
|
+
"url": "git+https://github.com/xxx/node-template.git"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"dev": "tsup --watch",
|
|
@@ -47,8 +47,7 @@
|
|
|
47
47
|
"prepublishOnly": "npm run build && np --any-branch --no-yarn --yolo --no-publish --message \"chore: release v%s\""
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"kolorist": "^1.8.0"
|
|
51
|
-
"shelljs": "^0.8.5"
|
|
50
|
+
"kolorist": "^1.8.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@commitlint/cli": "^18.4.3",
|
|
@@ -58,7 +57,7 @@
|
|
|
58
57
|
"@tomjs/eslint": "^1.1.1",
|
|
59
58
|
"@tomjs/prettier": "^1.0.6",
|
|
60
59
|
"@tomjs/stylelint": "^1.1.1",
|
|
61
|
-
"@tomjs/tsconfig": "^1.
|
|
60
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
62
61
|
"@types/jest": "^29.5.11",
|
|
63
62
|
"@types/node": "^18.19.3",
|
|
64
63
|
"electron": "^28.0.0",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"lint-staged": "^15.2.0",
|
|
69
68
|
"np": "^9.1.0",
|
|
70
69
|
"npm-run-all": "^4.1.5",
|
|
71
|
-
"prettier": "^3.1.
|
|
70
|
+
"prettier": "^3.1.1",
|
|
72
71
|
"rimraf": "^5.0.5",
|
|
73
72
|
"stylelint": "^15.11.0",
|
|
74
73
|
"ts-jest": "^29.1.1",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"@tomjs/eslint": "^1.1.1",
|
|
27
27
|
"@tomjs/prettier": "^1.0.6",
|
|
28
28
|
"@tomjs/stylelint": "^1.1.1",
|
|
29
|
-
"@tomjs/tsconfig": "^1.
|
|
29
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
30
30
|
"@types/node": "^18.19.3",
|
|
31
|
-
"@types/react": "^18.2.
|
|
31
|
+
"@types/react": "^18.2.43",
|
|
32
32
|
"@types/react-dom": "^18.2.17",
|
|
33
33
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
34
34
|
"eslint": "^8.55.0",
|
|
35
35
|
"husky": "^8.0.3",
|
|
36
36
|
"lint-staged": "^15.2.0",
|
|
37
37
|
"npm-run-all": "^4.1.5",
|
|
38
|
-
"prettier": "^3.1.
|
|
38
|
+
"prettier": "^3.1.1",
|
|
39
39
|
"stylelint": "^15.11.0",
|
|
40
40
|
"typescript": "~5.2.2",
|
|
41
41
|
"vite": "^5.0.7"
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"@tomjs/eslint": "^1.1.1",
|
|
26
26
|
"@tomjs/prettier": "^1.0.6",
|
|
27
27
|
"@tomjs/stylelint": "^1.1.1",
|
|
28
|
-
"@tomjs/tsconfig": "^1.
|
|
28
|
+
"@tomjs/tsconfig": "^1.1.2",
|
|
29
29
|
"@types/node": "^18.19.3",
|
|
30
30
|
"@vitejs/plugin-vue": "^4.5.2",
|
|
31
31
|
"eslint": "^8.55.0",
|
|
32
32
|
"husky": "^8.0.3",
|
|
33
33
|
"lint-staged": "^15.2.0",
|
|
34
34
|
"npm-run-all": "^4.1.5",
|
|
35
|
-
"prettier": "^3.1.
|
|
35
|
+
"prettier": "^3.1.1",
|
|
36
36
|
"stylelint": "^15.11.0",
|
|
37
37
|
"typescript": "~5.2.2",
|
|
38
38
|
"vite": "^5.0.7",
|