@tomjs/create-app 0.6.2 → 0.7.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 (52) hide show
  1. package/dist/index.mjs +6 -6
  2. package/package.json +1 -1
  3. package/template-electron-react/.vscode/launch.json +2 -3
  4. package/template-electron-react/.vscode/tasks.json +9 -3
  5. package/template-electron-react/electron/main/index.ts +1 -1
  6. package/template-electron-react/package.json +3 -3
  7. package/template-electron-vue/.vscode/launch.json +2 -3
  8. package/template-electron-vue/.vscode/tasks.json +9 -3
  9. package/template-electron-vue/electron/main/index.ts +1 -1
  10. package/template-electron-vue/package.json +4 -4
  11. package/template-node/package.json +1 -1
  12. package/template-vscode-react/.eslintrc.cjs +7 -0
  13. package/template-vscode-react/.vscode/launch.json +21 -0
  14. package/template-vscode-react/.vscode/tasks.json +36 -0
  15. package/template-vscode-react/README.md +87 -0
  16. package/template-vscode-react/_lintstagedrc.cjs +5 -0
  17. package/template-vscode-react/extension/index.ts +14 -0
  18. package/template-vscode-react/extension/panels/MainPanel.ts +172 -0
  19. package/template-vscode-react/index.html +14 -0
  20. package/template-vscode-react/package.json +71 -0
  21. package/template-vscode-react/src/App.css +7 -0
  22. package/template-vscode-react/src/App.tsx +51 -0
  23. package/template-vscode-react/src/main.tsx +9 -0
  24. package/template-vscode-react/src/utils/index.ts +1 -0
  25. package/template-vscode-react/src/utils/vscode.ts +84 -0
  26. package/template-vscode-react/src/vite-env.d.ts +1 -0
  27. package/template-vscode-react/tsconfig.json +10 -0
  28. package/template-vscode-react/tsconfig.node.json +7 -0
  29. package/template-vscode-react/vite.config.ts +21 -0
  30. package/template-vscode-vue/.eslintrc.cjs +7 -0
  31. package/template-vscode-vue/.vscode/launch.json +21 -0
  32. package/template-vscode-vue/.vscode/tasks.json +36 -0
  33. package/template-vscode-vue/README.md +87 -0
  34. package/template-vscode-vue/_lintstagedrc.cjs +6 -0
  35. package/template-vscode-vue/extension/index.ts +14 -0
  36. package/template-vscode-vue/extension/panels/MainPanel.ts +172 -0
  37. package/template-vscode-vue/index.html +14 -0
  38. package/template-vscode-vue/package.json +69 -0
  39. package/template-vscode-vue/src/App.vue +58 -0
  40. package/template-vscode-vue/src/main.ts +4 -0
  41. package/template-vscode-vue/src/utils/index.ts +1 -0
  42. package/template-vscode-vue/src/utils/vscode.ts +84 -0
  43. package/template-vscode-vue/src/vite-env.d.ts +1 -0
  44. package/template-vscode-vue/tsconfig.json +10 -0
  45. package/template-vscode-vue/tsconfig.node.json +7 -0
  46. package/template-vscode-vue/vite.config.ts +21 -0
  47. package/template-electron-react/scripts/builder.ts +0 -38
  48. package/template-electron-react/scripts/constants.ts +0 -19
  49. package/template-electron-react/scripts/release.ts +0 -40
  50. package/template-electron-vue/scripts/builder.ts +0 -38
  51. package/template-electron-vue/scripts/constants.ts +0 -19
  52. package/template-electron-vue/scripts/release.ts +0 -40
@@ -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.12"
42
+ },
43
+ "devDependencies": {
44
+ "@commitlint/cli": "^18.4.3",
45
+ "@tomjs/commitlint": "^2.0.8",
46
+ "@tomjs/eslint": "^1.1.4",
47
+ "@tomjs/prettier": "^1.0.9",
48
+ "@tomjs/stylelint": "^2.0.2",
49
+ "@tomjs/tsconfig": "^1.1.5",
50
+ "@tomjs/vite-plugin-vscode": "^1.0.0",
51
+ "@tomjs/vscode-extension-webview": "^1.0.1",
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
+ });
@@ -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
- });