@tomjs/create-app 0.4.4 → 0.4.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/dist/index.mjs CHANGED
@@ -4,5 +4,5 @@ import a,{renameSync as Ce}from"fs";import Oe from"os";import i from"path";impor
4
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
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:
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
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.4",
3
+ "version": "0.4.6",
4
4
  "description": "create tomjs web app",
5
5
  "keywords": [
6
6
  "tomjs",
@@ -64,7 +64,7 @@
64
64
  "eslint": "^8.55.0",
65
65
  "husky": "^8.0.3",
66
66
  "lint-staged": "^15.2.0",
67
- "np": "^9.1.0",
67
+ "np": "^9.2.0",
68
68
  "npm-run-all": "^4.1.5",
69
69
  "prettier": "^3.1.1",
70
70
  "stylelint": "^15.11.0",
@@ -5,16 +5,20 @@
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
7
  {
8
- "name": "Debug Main Process",
8
+ "name": "Main Debug",
9
9
  "type": "node",
10
10
  "request": "launch",
11
- "cwd": "${workspaceRoot}",
12
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
11
+ "cwd": "${workspaceFolder}",
12
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
13
13
  "windows": {
14
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
14
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
15
15
  },
16
- "args": ["."],
17
- "envFile": "${workspaceRoot}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
16
+ "args": [
17
+ "."
18
+ ],
19
+ "envFile": "${workspaceFolder}/node_modules/@tomjs/vite-plugin-electron/debug/.env",
20
+ "outputCapture": "std",
21
+ "console": "integratedTerminal"
18
22
  },
19
23
  ]
20
24
  }
@@ -13,7 +13,7 @@ vite + electron + react
13
13
  | |--preload
14
14
  | | |--index.ts
15
15
  |--src
16
- | |--App.vue
16
+ | |--App.tsx
17
17
  | |--main.ts
18
18
  ```
19
19
 
@@ -31,6 +31,69 @@ vite + electron + react
31
31
  | | |--index.html
32
32
  ```
33
33
 
34
+ ## Debug
35
+
36
+ ### Web debugging
37
+
38
+ Use [@tomjs/electron-devtools-installer](https://npmjs.com/package/@tomjs/electron-devtools-installer) to install the `Chrome Devtools` plugins and use it like web development
39
+
40
+ ```ts
41
+ import { app } from 'electron';
42
+
43
+ app.whenReady().then(() => {
44
+ const { installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = await import(
45
+ '@tomjs/electron-devtools-installer'
46
+ );
47
+
48
+ installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
49
+ .then(exts => {
50
+ console.log(
51
+ 'Added Extension: ',
52
+ exts.map(s => s.name),
53
+ );
54
+ })
55
+ .catch(err => {
56
+ console.log('Failed to install extensions');
57
+ console.error(err);
58
+ });
59
+ });
60
+ ```
61
+
62
+ ### Main thread debugging
63
+
64
+ #### Turn on debugging
65
+
66
+ Start code compilation through the following configuration or `ELECTRON_DEBUG=1 vite dev`
67
+
68
+ - Enable by setting `APP_ELECTRON_DEBUG=1` in `.env.development` file
69
+ - `vite.config.js` configures `electron({ debug: true })` to be turned on
70
+
71
+ #### VSCODE
72
+
73
+ Run `Debug Main Process` through `vscode` to debug the main thread. For debugging tools, refer to [Official Documentation](https://code.visualstudio.com/docs/editor/debugging)
74
+
75
+ `launch.json` is configured as follows:
76
+
77
+ ```json
78
+ {
79
+ "version": "0.2.0",
80
+ "configurations": [
81
+ {
82
+ "name": "Debug Main Process",
83
+ "type": "node",
84
+ "request": "launch",
85
+ "cwd": "${workspaceFolder}",
86
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
87
+ "windows": {
88
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
89
+ },
90
+ "args": ["."],
91
+ "envFile": "${workspaceFolder}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
92
+ }
93
+ ]
94
+ }
95
+ ```
96
+
34
97
  ## Reference project
35
98
 
36
99
  - [electron-vite-react](https://github.com/electron-vite/electron-vite-react)
@@ -1,6 +1,7 @@
1
1
  import { release } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
  import { app, BrowserWindow, ipcMain, shell } from 'electron';
4
+ import '../polyfills';
4
5
 
5
6
  const isDev = process.env.NODE_ENV === 'development';
6
7
 
@@ -22,7 +23,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
22
23
 
23
24
  let win: BrowserWindow | null = null;
24
25
  // package.json "type":"module", must use mjs extension
25
- const preload = join(__dirname, '../preload/index.js');
26
+ const preload = join(__dirname, '../preload/index.mjs');
26
27
  const serverUrl = process.env.APP_DEV_SERVER_URL as string;
27
28
  const rendererDist = join(__dirname, '../renderer');
28
29
  const indexHtml = join(rendererDist, 'index.html');
@@ -0,0 +1,4 @@
1
+ import { dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ global.__dirname = dirname(fileURLToPath(import.meta.url));
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "electron-app",
3
3
  "version": "0.0.0",
4
+ "type": "module",
4
5
  "description": "vite + electron + vue",
5
6
  "engines": {
6
7
  "node": ">=18"
7
8
  },
8
- "main": "dist/main/index.js",
9
+ "main": "dist/main/index.mjs",
9
10
  "scripts": {
10
11
  "dev": "vite",
11
12
  "build": "npm run clean && vite build && npm run release",
@@ -29,7 +30,7 @@
29
30
  "@tomjs/prettier": "^1.0.6",
30
31
  "@tomjs/stylelint": "^1.1.1",
31
32
  "@tomjs/tsconfig": "^1.1.2",
32
- "@tomjs/vite-plugin-electron": "^1.3.6",
33
+ "@tomjs/vite-plugin-electron": "^1.3.8",
33
34
  "@types/node": "^18.19.3",
34
35
  "@types/react": "^18.2.43",
35
36
  "@types/react-dom": "^18.2.17",
@@ -5,16 +5,20 @@
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
7
  {
8
- "name": "Debug Main Process",
8
+ "name": "Main Debug",
9
9
  "type": "node",
10
10
  "request": "launch",
11
- "cwd": "${workspaceRoot}",
12
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
11
+ "cwd": "${workspaceFolder}",
12
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
13
13
  "windows": {
14
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
14
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
15
15
  },
16
- "args": ["."],
17
- "envFile": "${workspaceRoot}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
16
+ "args": [
17
+ "."
18
+ ],
19
+ "envFile": "${workspaceFolder}/node_modules/@tomjs/vite-plugin-electron/debug/.env",
20
+ "outputCapture": "std",
21
+ "console": "integratedTerminal"
18
22
  },
19
23
  ]
20
24
  }
@@ -31,6 +31,64 @@ vite + electron + vue
31
31
  | | |--index.html
32
32
  ```
33
33
 
34
+ ## Debug
35
+
36
+ ### Web debugging
37
+
38
+ Use [@tomjs/electron-devtools-installer](https://npmjs.com/package/@tomjs/electron-devtools-installer) to install the `Chrome Devtools` plugins and use it like web development
39
+
40
+ ```ts
41
+ import { app } from 'electron';
42
+
43
+ app.whenReady().then(() => {
44
+ const { installExtension, VUEJS_DEVTOOLS } = await import('@tomjs/electron-devtools-installer');
45
+
46
+ installExtension(VUEJS_DEVTOOLS)
47
+ .then(ext => {
48
+ console.log('Added Extension: ', ext.name);
49
+ })
50
+ .catch(err => {
51
+ console.log('Failed to install extensions');
52
+ console.error(err);
53
+ });
54
+ });
55
+ ```
56
+
57
+ ### Main thread debugging
58
+
59
+ #### Turn on debugging
60
+
61
+ Start code compilation through the following configuration or `ELECTRON_DEBUG=1 vite dev`
62
+
63
+ - Enable by setting `APP_ELECTRON_DEBUG=1` in `.env.development` file
64
+ - `vite.config.js` configures `electron({ debug: true })` to be turned on
65
+
66
+ #### VSCODE
67
+
68
+ Run `Debug Main Process` through `vscode` to debug the main thread. For debugging tools, refer to [Official Documentation](https://code.visualstudio.com/docs/editor/debugging)
69
+
70
+ `launch.json` is configured as follows:
71
+
72
+ ```json
73
+ {
74
+ "version": "0.2.0",
75
+ "configurations": [
76
+ {
77
+ "name": "Debug Main Process",
78
+ "type": "node",
79
+ "request": "launch",
80
+ "cwd": "${workspaceFolder}",
81
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
82
+ "windows": {
83
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
84
+ },
85
+ "args": ["."],
86
+ "envFile": "${workspaceFolder}/node_modules/@tomjs/vite-plugin-electron/debug/.env"
87
+ }
88
+ ]
89
+ }
90
+ ```
91
+
34
92
  ## Reference project
35
93
 
36
94
  - [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue)
@@ -1,6 +1,7 @@
1
1
  import { release } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
  import { app, BrowserWindow, ipcMain, shell } from 'electron';
4
+ import '../polyfills';
4
5
 
5
6
  const isDev = process.env.NODE_ENV === 'development';
6
7
 
@@ -22,7 +23,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
22
23
 
23
24
  let win: BrowserWindow | null = null;
24
25
  // package.json "type":"module", must use mjs extension
25
- const preload = join(__dirname, '../preload/index.js');
26
+ const preload = join(__dirname, '../preload/index.mjs');
26
27
  const serverUrl = process.env.APP_DEV_SERVER_URL as string;
27
28
  const rendererDist = join(__dirname, '../renderer');
28
29
  const indexHtml = join(rendererDist, 'index.html');
@@ -0,0 +1,4 @@
1
+ import { dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ global.__dirname = dirname(fileURLToPath(import.meta.url));
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "electron-app",
3
3
  "version": "0.0.0",
4
+ "type": "module",
4
5
  "description": "vite + electron + vue",
5
6
  "engines": {
6
7
  "node": ">=18"
7
8
  },
8
- "main": "dist/main/index.js",
9
+ "main": "dist/main/index.mjs",
9
10
  "scripts": {
10
11
  "dev": "vite",
11
12
  "build": "npm run clean && vue-tsc --noEmit && vite build && npm run release",
@@ -28,7 +29,7 @@
28
29
  "@tomjs/prettier": "^1.0.6",
29
30
  "@tomjs/stylelint": "^1.1.1",
30
31
  "@tomjs/tsconfig": "^1.1.2",
31
- "@tomjs/vite-plugin-electron": "^1.3.6",
32
+ "@tomjs/vite-plugin-electron": "^1.3.8",
32
33
  "@types/node": "^18.19.3",
33
34
  "@types/shelljs": "^0.8.15",
34
35
  "@vitejs/plugin-vue": "^4.5.2",
@@ -65,7 +65,7 @@
65
65
  "husky": "^8.0.3",
66
66
  "jest": "^29.7.0",
67
67
  "lint-staged": "^15.2.0",
68
- "np": "^9.1.0",
68
+ "np": "^9.2.0",
69
69
  "npm-run-all": "^4.1.5",
70
70
  "prettier": "^3.1.1",
71
71
  "rimraf": "^5.0.5",