@tomjs/create-app 0.6.2 → 0.8.0

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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/README.zh_CN.md +1 -1
  3. package/dist/index.mjs +6 -6
  4. package/package.json +7 -7
  5. package/template-electron-react/.vscode/launch.json +2 -3
  6. package/template-electron-react/.vscode/tasks.json +9 -3
  7. package/template-electron-react/electron/main/index.ts +1 -1
  8. package/template-electron-react/package.json +9 -9
  9. package/template-electron-vue/.vscode/launch.json +2 -3
  10. package/template-electron-vue/.vscode/tasks.json +9 -3
  11. package/template-electron-vue/electron/main/index.ts +1 -1
  12. package/template-electron-vue/package.json +11 -11
  13. package/template-node/package.json +6 -6
  14. package/template-react/package.json +5 -5
  15. package/template-vscode-react/.eslintrc.cjs +7 -0
  16. package/template-vscode-react/.vscode/launch.json +21 -0
  17. package/template-vscode-react/.vscode/tasks.json +36 -0
  18. package/template-vscode-react/README.md +87 -0
  19. package/template-vscode-react/_lintstagedrc.cjs +5 -0
  20. package/template-vscode-react/extension/index.ts +14 -0
  21. package/template-vscode-react/extension/panels/MainPanel.ts +172 -0
  22. package/template-vscode-react/index.html +14 -0
  23. package/template-vscode-react/package.json +71 -0
  24. package/template-vscode-react/src/App.css +7 -0
  25. package/template-vscode-react/src/App.tsx +51 -0
  26. package/template-vscode-react/src/main.tsx +9 -0
  27. package/template-vscode-react/src/utils/index.ts +1 -0
  28. package/template-vscode-react/src/utils/vscode.ts +84 -0
  29. package/template-vscode-react/src/vite-env.d.ts +1 -0
  30. package/template-vscode-react/tsconfig.json +10 -0
  31. package/template-vscode-react/tsconfig.node.json +7 -0
  32. package/template-vscode-react/vite.config.ts +21 -0
  33. package/template-vscode-vue/.eslintrc.cjs +7 -0
  34. package/template-vscode-vue/.vscode/launch.json +21 -0
  35. package/template-vscode-vue/.vscode/tasks.json +36 -0
  36. package/template-vscode-vue/README.md +87 -0
  37. package/template-vscode-vue/_lintstagedrc.cjs +6 -0
  38. package/template-vscode-vue/extension/index.ts +14 -0
  39. package/template-vscode-vue/extension/panels/MainPanel.ts +172 -0
  40. package/template-vscode-vue/index.html +14 -0
  41. package/template-vscode-vue/package.json +69 -0
  42. package/template-vscode-vue/src/App.vue +58 -0
  43. package/template-vscode-vue/src/main.ts +4 -0
  44. package/template-vscode-vue/src/utils/index.ts +1 -0
  45. package/template-vscode-vue/src/utils/vscode.ts +84 -0
  46. package/template-vscode-vue/src/vite-env.d.ts +1 -0
  47. package/template-vscode-vue/tsconfig.json +10 -0
  48. package/template-vscode-vue/tsconfig.node.json +7 -0
  49. package/template-vscode-vue/vite.config.ts +21 -0
  50. package/template-vue/package.json +6 -6
  51. package/template-electron-react/scripts/builder.ts +0 -38
  52. package/template-electron-react/scripts/constants.ts +0 -19
  53. package/template-electron-react/scripts/release.ts +0 -40
  54. package/template-electron-vue/scripts/builder.ts +0 -38
  55. package/template-electron-vue/scripts/constants.ts +0 -19
  56. package/template-electron-vue/scripts/release.ts +0 -40
@@ -0,0 +1,172 @@
1
+ import { Disposable, Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode';
2
+ // import __getWebviewHtml from '@tomjs/vscode-extension-webview';
3
+
4
+ function uuid() {
5
+ let text = '';
6
+ const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
+ for (let i = 0; i < 32; i++) {
8
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
9
+ }
10
+ return text;
11
+ }
12
+
13
+ function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) {
14
+ return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList));
15
+ }
16
+
17
+ /**
18
+ * This class manages the state and behavior of HelloWorld webview panels.
19
+ *
20
+ * It contains all the data and methods for:
21
+ *
22
+ * - Creating and rendering HelloWorld webview panels
23
+ * - Properly cleaning up and disposing of webview resources when the panel is closed
24
+ * - Setting the HTML (and by proxy CSS/JavaScript) content of the webview panel
25
+ * - Setting message listeners so data can be passed between the webview and extension
26
+ */
27
+ export class MainPanel {
28
+ public static currentPanel: MainPanel | undefined;
29
+ private readonly _panel: WebviewPanel;
30
+ private _disposables: Disposable[] = [];
31
+
32
+ /**
33
+ * The HelloWorldPanel class private constructor (called only from the render method).
34
+ *
35
+ * @param panel A reference to the webview panel
36
+ * @param extensionUri The URI of the directory containing the extension
37
+ */
38
+ private constructor(panel: WebviewPanel, extensionUri: Uri) {
39
+ this._panel = panel;
40
+
41
+ // Set an event listener to listen for when the panel is disposed (i.e. when the user closes
42
+ // the panel or when the panel is closed programmatically)
43
+ this._panel.onDidDispose(() => this.dispose(), null, this._disposables);
44
+
45
+ // Set the HTML content for the webview panel
46
+ this._panel.webview.html = this._getWebviewContent(this._panel.webview, extensionUri);
47
+
48
+ // Set an event listener to listen for messages passed from the webview context
49
+ this._setWebviewMessageListener(this._panel.webview);
50
+ }
51
+
52
+ /**
53
+ * Renders the current webview panel if it exists otherwise a new webview panel
54
+ * will be created and displayed.
55
+ *
56
+ * @param extensionUri The URI of the directory containing the extension.
57
+ */
58
+ public static render(extensionUri: Uri) {
59
+ if (MainPanel.currentPanel) {
60
+ // If the webview panel already exists reveal it
61
+ MainPanel.currentPanel._panel.reveal(ViewColumn.One);
62
+ } else {
63
+ // If a webview panel does not already exist create and show a new one
64
+ const panel = window.createWebviewPanel(
65
+ // Panel view type
66
+ 'showHelloWorld',
67
+ // Panel title
68
+ 'Hello World',
69
+ // The editor column the panel should be displayed in
70
+ ViewColumn.One,
71
+ // Extra panel configurations
72
+ {
73
+ // Enable JavaScript in the webview
74
+ enableScripts: true,
75
+ // Restrict the webview to only load resources from the `dist/webview` directories
76
+ localResourceRoots: [Uri.joinPath(extensionUri, 'dist/webview')],
77
+ },
78
+ );
79
+
80
+ MainPanel.currentPanel = new MainPanel(panel, extensionUri);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Cleans up and disposes of webview resources when the webview panel is closed.
86
+ */
87
+ public dispose() {
88
+ MainPanel.currentPanel = undefined;
89
+
90
+ // Dispose of the current webview panel
91
+ this._panel.dispose();
92
+
93
+ // Dispose of all disposables (i.e. commands) for the current webview panel
94
+ while (this._disposables.length) {
95
+ const disposable = this._disposables.pop();
96
+ if (disposable) {
97
+ disposable.dispose();
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Defines and returns the HTML that should be rendered within the webview panel.
104
+ *
105
+ * @remarks This is also the place where references to the Vue webview build files
106
+ * are created and inserted into the webview HTML.
107
+ *
108
+ * @param webview A reference to the extension webview
109
+ * @param extensionUri The URI of the directory containing the extension
110
+ * @returns A template string literal containing the HTML that should be
111
+ * rendered within the webview panel
112
+ */
113
+ private _getWebviewContent(webview: Webview, extensionUri: Uri) {
114
+ // The CSS file from the Vue build output
115
+ const stylesUri = getUri(webview, extensionUri, ['dist', 'webview', 'assets', 'index.css']);
116
+ // The JS file from the Vue build output
117
+ const scriptUri = getUri(webview, extensionUri, ['dist', 'webview', 'assets', 'index.js']);
118
+
119
+ const nonce = uuid();
120
+
121
+ if (process.env.VITE_DEV_SERVER_URL) {
122
+ // @ts-ignore
123
+ return __getWebviewHtml({ serverUrl: process.env.VITE_DEV_SERVER_URL });
124
+ }
125
+
126
+ // Tip: Install the es6-string-html VS Code extension to enable code highlighting below
127
+ return /*html*/ `
128
+ <!doctype html>
129
+ <html lang="en">
130
+ <head>
131
+ <meta charset="UTF-8" />
132
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
133
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; script-src 'nonce-${nonce}';">
134
+ <script type="module" crossorigin nonce="${nonce}" src="${scriptUri}"></script>
135
+ <link rel="stylesheet" crossorigin href="${stylesUri}">
136
+ <title>Hello World</title>
137
+ </head>
138
+ <body>
139
+ <div id="app"></div>
140
+ </body>
141
+ </html>
142
+ `;
143
+ }
144
+
145
+ /**
146
+ * Sets up an event listener to listen for messages passed from the webview context and
147
+ * executes code based on the message that is recieved.
148
+ *
149
+ * @param webview A reference to the extension webview
150
+ * @param context A reference to the extension context
151
+ */
152
+ private _setWebviewMessageListener(webview: Webview) {
153
+ webview.onDidReceiveMessage(
154
+ (message: any) => {
155
+ const command = message.command;
156
+ const text = message.text;
157
+ console.log(`command: ${command}`);
158
+
159
+ switch (command) {
160
+ case 'hello':
161
+ // Code that should run in response to the hello message command
162
+ window.showInformationMessage(text);
163
+ return;
164
+ // Add more switch case statements here as more webview message commands
165
+ // are created within the webview context (i.e. inside media/main.js)
166
+ }
167
+ },
168
+ undefined,
169
+ this._disposables,
170
+ );
171
+ }
172
+ }
@@ -0,0 +1,14 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
7
+ <title>Vite + VSCode Extension + Vue</title>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="app"></div>
12
+ <script type="module" src="/src/main.ts"></script>
13
+ </body>
14
+ </html>
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "vscode-app",
3
+ "version": "0.0.0",
4
+ "description": "vite + vscode + vue",
5
+ "engines": {
6
+ "node": ">=14",
7
+ "vscode": "^1.56.0"
8
+ },
9
+ "main": "dist/extension/index.js",
10
+ "activationEvents": [
11
+ "onCommand:hello-world.showHelloWorld"
12
+ ],
13
+ "contributes": {
14
+ "commands": [
15
+ {
16
+ "command": "hello-world.showHelloWorld",
17
+ "title": "Hello World: Show"
18
+ }
19
+ ]
20
+ },
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/xxx/node-template.git"
28
+ },
29
+ "scripts": {
30
+ "dev": "vite",
31
+ "build": "npm run clean && vue-tsc --noEmit && vite build",
32
+ "clean": "rimraf ./dist",
33
+ "lint": "run-s lint:eslint lint:stylelint lint:prettier",
34
+ "lint:eslint": "eslint \"{src,extension,scripts}/**/*.{js,cjs,ts,tsx,vue}\" *.{js,cjs,ts} --fix --cache",
35
+ "lint:stylelint": "stylelint \"{src,extension,scripts}/**/*.{css,scss,less,html}\" --fix --cache",
36
+ "lint:prettier": "prettier --write .",
37
+ "prepare": "husky install"
38
+ },
39
+ "dependencies": {
40
+ "@vscode/webview-ui-toolkit": "^1.4.0",
41
+ "vue": "^3.3.13"
42
+ },
43
+ "devDependencies": {
44
+ "@commitlint/cli": "^18.4.3",
45
+ "@tomjs/commitlint": "^2.1.1",
46
+ "@tomjs/eslint": "^1.2.1",
47
+ "@tomjs/prettier": "^1.1.1",
48
+ "@tomjs/stylelint": "^2.1.1",
49
+ "@tomjs/tsconfig": "^1.2.1",
50
+ "@tomjs/vite-plugin-vscode": "^1.1.0",
51
+ "@tomjs/vscode-extension-webview": "^1.1.0",
52
+ "@types/node": "^18.19.3",
53
+ "@types/vscode": "^1.85.0",
54
+ "@types/vscode-webview": "^1.57.4",
55
+ "@vitejs/plugin-vue": "^4.5.2",
56
+ "cross-env": "^7.0.3",
57
+ "eslint": "^8.56.0",
58
+ "husky": "^8.0.3",
59
+ "lint-staged": "^15.2.0",
60
+ "npm-run-all": "^4.1.5",
61
+ "prettier": "^3.1.1",
62
+ "rimraf": "^5.0.5",
63
+ "stylelint": "^16.0.2",
64
+ "tsx": "^4.7.0",
65
+ "typescript": "~5.3.3",
66
+ "vite": "^5.0.10",
67
+ "vue-tsc": "^1.8.25"
68
+ }
69
+ }
@@ -0,0 +1,58 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue';
3
+ import { allComponents, provideVSCodeDesignSystem } from '@vscode/webview-ui-toolkit';
4
+ import { vscode } from './utils';
5
+
6
+ provideVSCodeDesignSystem().register(allComponents);
7
+
8
+ function onPostMessage() {
9
+ vscode.postMessage({
10
+ command: 'hello',
11
+ text: 'Hey there partner! 🤠',
12
+ });
13
+ }
14
+
15
+ const message = ref('');
16
+ const state = ref('');
17
+
18
+ const onSetState = () => {
19
+ vscode.setState(state.value);
20
+ };
21
+
22
+ const onGetState = () => {
23
+ state.value = vscode.getState() as string;
24
+ };
25
+ </script>
26
+
27
+ <template>
28
+ <main>
29
+ <h1>Hello Vue!</h1>
30
+ <vscode-button @click="onPostMessage">Test VSCode Message</vscode-button>
31
+ <div>
32
+ <vscode-text-field :value="message" @input="e => (message = e.target.value)">
33
+ Please enter a message
34
+ </vscode-text-field>
35
+ <div>Message is: {{ message }}</div>
36
+ </div>
37
+ <div>
38
+ <vscode-text-field :value="state" @input="e => (state = e.target.value)">
39
+ Please enter a state
40
+ </vscode-text-field>
41
+ <div>State is: {{ state }}</div>
42
+ <div>
43
+ <vscode-button @click="onSetState">setState</vscode-button>
44
+ <vscode-button style="margin-left: 8px" @click="onGetState">getState</vscode-button>
45
+ </div>
46
+ </div>
47
+ </main>
48
+ </template>
49
+
50
+ <style>
51
+ main {
52
+ display: flex;
53
+ flex-direction: column;
54
+ align-items: flex-start;
55
+ justify-content: center;
56
+ height: 100%;
57
+ }
58
+ </style>
@@ -0,0 +1,4 @@
1
+ import { createApp } from 'vue';
2
+ import App from './App.vue';
3
+
4
+ createApp(App).mount('#app');
@@ -0,0 +1 @@
1
+ export * from './vscode';
@@ -0,0 +1,84 @@
1
+ import type { WebviewApi } from 'vscode-webview';
2
+
3
+ /**
4
+ * A utility wrapper around the acquireVsCodeApi() function, which enables
5
+ * message passing and state management between the webview and extension
6
+ * contexts.
7
+ *
8
+ * This utility also enables webview code to be run in a web browser-based
9
+ * dev server by using native web browser features that mock the functionality
10
+ * enabled by acquireVsCodeApi.
11
+ */
12
+ class VSCodeAPIWrapper {
13
+ private readonly vsCodeApi: WebviewApi<unknown> | undefined;
14
+
15
+ constructor() {
16
+ console.log(typeof acquireVsCodeApi);
17
+ // Check if the acquireVsCodeApi function exists in the current development
18
+ // context (i.e. VS Code development window or web browser)
19
+ if (typeof acquireVsCodeApi === 'function') {
20
+ this.vsCodeApi = acquireVsCodeApi();
21
+ }
22
+ }
23
+
24
+ // private init() {
25
+ // // TODO 环境变量判断
26
+ // }
27
+
28
+ /**
29
+ * Post a message (i.e. send arbitrary data) to the owner of the webview.
30
+ *
31
+ * @remarks When running webview code inside a web browser, postMessage will instead
32
+ * log the given message to the console.
33
+ *
34
+ * @param message Abitrary data (must be JSON serializable) to send to the extension context.
35
+ */
36
+ public postMessage(message: unknown) {
37
+ if (this.vsCodeApi) {
38
+ this.vsCodeApi.postMessage(message);
39
+ } else {
40
+ window.parent.postMessage({ type: 'page:message', data: message }, '*');
41
+ console.log(message);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get the persistent state stored for this webview.
47
+ *
48
+ * @remarks When running webview source code inside a web browser, getState will retrieve state
49
+ * from local storage (https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
50
+ *
51
+ * @return The current state or `undefined` if no state has been set.
52
+ */
53
+ public getState(): unknown | undefined {
54
+ if (this.vsCodeApi) {
55
+ return this.vsCodeApi.getState();
56
+ } else {
57
+ const state = localStorage.getItem('vscodeState');
58
+ return state ? JSON.parse(state) : undefined;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Set the persistent state stored for this webview.
64
+ *
65
+ * @remarks When running webview source code inside a web browser, setState will set the given
66
+ * state using local storage (https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
67
+ *
68
+ * @param newState New persisted state. This must be a JSON serializable object. Can be retrieved
69
+ * using {@link getState}.
70
+ *
71
+ * @return The new state.
72
+ */
73
+ public setState<T extends unknown | undefined>(newState: T): T {
74
+ if (this.vsCodeApi) {
75
+ return this.vsCodeApi.setState(newState);
76
+ } else {
77
+ localStorage.setItem('vscodeState', JSON.stringify(newState));
78
+ return newState;
79
+ }
80
+ }
81
+ }
82
+
83
+ // Exports class singleton to prevent multiple invocations of acquireVsCodeApi.
84
+ export const vscode = new VSCodeAPIWrapper();
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@tomjs/tsconfig/vue-dom.json",
3
+ "compilerOptions": {},
4
+ "include": ["src"],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.node.json"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@tomjs/tsconfig/node.json",
3
+ "compilerOptions": {
4
+ "composite": true
5
+ },
6
+ "include": ["extension", "scripts", "package.json", "vite.config.ts"]
7
+ }
@@ -0,0 +1,21 @@
1
+ import path from 'node:path';
2
+ import { defineConfig } from 'vite';
3
+ import vscode from '@tomjs/vite-plugin-vscode';
4
+ import vue from '@vitejs/plugin-vue';
5
+ import pkg from './package.json';
6
+
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig(() => {
9
+ process.env.APP_BUILD_TIME = Date.now() + '';
10
+ process.env.APP_VERSION = pkg.version;
11
+
12
+ return {
13
+ resolve: {
14
+ alias: {
15
+ '@': path.join(__dirname, 'src'),
16
+ },
17
+ },
18
+ plugins: [vue(), vscode()],
19
+ clearScreen: false,
20
+ };
21
+ });
@@ -17,15 +17,15 @@
17
17
  "prepare": "husky install"
18
18
  },
19
19
  "dependencies": {
20
- "vue": "^3.3.12"
20
+ "vue": "^3.3.13"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@commitlint/cli": "^18.4.3",
24
- "@tomjs/commitlint": "^2.0.8",
25
- "@tomjs/eslint": "^1.1.4",
26
- "@tomjs/prettier": "^1.0.9",
27
- "@tomjs/stylelint": "^2.0.2",
28
- "@tomjs/tsconfig": "^1.1.5",
24
+ "@tomjs/commitlint": "^2.1.1",
25
+ "@tomjs/eslint": "^1.2.1",
26
+ "@tomjs/prettier": "^1.1.1",
27
+ "@tomjs/stylelint": "^2.1.1",
28
+ "@tomjs/tsconfig": "^1.2.1",
29
29
  "@types/node": "^18.19.3",
30
30
  "@vitejs/plugin-vue": "^4.5.2",
31
31
  "cross-env": "^7.0.3",
@@ -1,38 +0,0 @@
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/index.mjs', 'preload/index.mjs', 'renderer'],
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;
@@ -1,19 +0,0 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
-
4
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
-
6
- /**
7
- * 项目根路径
8
- */
9
- export const ROOT_PATH = path.join(__dirname, '../');
10
-
11
- /**
12
- * 生成代码目录
13
- */
14
- export const DIST_PATH = path.join(ROOT_PATH, 'dist');
15
-
16
- /**
17
- * electron 依赖模块
18
- */
19
- export const ELECTRON_DEPENDENCIES: string[] = [];
@@ -1,40 +0,0 @@
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/index.mjs',
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
- process.exit(0);
40
- });
@@ -1,38 +0,0 @@
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/index.mjs', 'preload/index.mjs', 'renderer'],
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;
@@ -1,19 +0,0 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
-
4
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
-
6
- /**
7
- * 项目根路径
8
- */
9
- export const ROOT_PATH = path.join(__dirname, '../');
10
-
11
- /**
12
- * 生成代码目录
13
- */
14
- export const DIST_PATH = path.join(ROOT_PATH, 'dist');
15
-
16
- /**
17
- * electron 依赖模块
18
- */
19
- export const ELECTRON_DEPENDENCIES: string[] = [];
@@ -1,40 +0,0 @@
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/index.mjs',
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
- process.exit(0);
40
- });