@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.
- package/README.md +1 -1
- package/README.zh_CN.md +1 -1
- package/dist/index.mjs +6 -6
- package/package.json +7 -7
- package/template-electron-react/.vscode/launch.json +2 -3
- package/template-electron-react/.vscode/tasks.json +9 -3
- package/template-electron-react/electron/main/index.ts +1 -1
- package/template-electron-react/package.json +9 -9
- package/template-electron-vue/.vscode/launch.json +2 -3
- package/template-electron-vue/.vscode/tasks.json +9 -3
- package/template-electron-vue/electron/main/index.ts +1 -1
- package/template-electron-vue/package.json +11 -11
- package/template-node/package.json +6 -6
- package/template-react/package.json +5 -5
- package/template-vscode-react/.eslintrc.cjs +7 -0
- package/template-vscode-react/.vscode/launch.json +21 -0
- package/template-vscode-react/.vscode/tasks.json +36 -0
- package/template-vscode-react/README.md +87 -0
- package/template-vscode-react/_lintstagedrc.cjs +5 -0
- package/template-vscode-react/extension/index.ts +14 -0
- package/template-vscode-react/extension/panels/MainPanel.ts +172 -0
- package/template-vscode-react/index.html +14 -0
- package/template-vscode-react/package.json +71 -0
- package/template-vscode-react/src/App.css +7 -0
- package/template-vscode-react/src/App.tsx +51 -0
- package/template-vscode-react/src/main.tsx +9 -0
- package/template-vscode-react/src/utils/index.ts +1 -0
- package/template-vscode-react/src/utils/vscode.ts +84 -0
- package/template-vscode-react/src/vite-env.d.ts +1 -0
- package/template-vscode-react/tsconfig.json +10 -0
- package/template-vscode-react/tsconfig.node.json +7 -0
- package/template-vscode-react/vite.config.ts +21 -0
- package/template-vscode-vue/.eslintrc.cjs +7 -0
- package/template-vscode-vue/.vscode/launch.json +21 -0
- package/template-vscode-vue/.vscode/tasks.json +36 -0
- package/template-vscode-vue/README.md +87 -0
- package/template-vscode-vue/_lintstagedrc.cjs +6 -0
- package/template-vscode-vue/extension/index.ts +14 -0
- package/template-vscode-vue/extension/panels/MainPanel.ts +172 -0
- package/template-vscode-vue/index.html +14 -0
- package/template-vscode-vue/package.json +69 -0
- package/template-vscode-vue/src/App.vue +58 -0
- package/template-vscode-vue/src/main.ts +4 -0
- package/template-vscode-vue/src/utils/index.ts +1 -0
- package/template-vscode-vue/src/utils/vscode.ts +84 -0
- package/template-vscode-vue/src/vite-env.d.ts +1 -0
- package/template-vscode-vue/tsconfig.json +10 -0
- package/template-vscode-vue/tsconfig.node.json +7 -0
- package/template-vscode-vue/vite.config.ts +21 -0
- package/template-vue/package.json +6 -6
- package/template-electron-react/scripts/builder.ts +0 -38
- package/template-electron-react/scripts/constants.ts +0 -19
- package/template-electron-react/scripts/release.ts +0 -40
- package/template-electron-vue/scripts/builder.ts +0 -38
- package/template-electron-vue/scripts/constants.ts +0 -19
- 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 + React</title>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<div id="app"></div>
|
|
12
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,71 @@
|
|
|
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 && 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}\" *.{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
|
+
"react": "^18.2.0",
|
|
42
|
+
"react-dom": "^18.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@commitlint/cli": "^18.4.3",
|
|
46
|
+
"@tomjs/commitlint": "^2.1.1",
|
|
47
|
+
"@tomjs/eslint": "^1.2.1",
|
|
48
|
+
"@tomjs/prettier": "^1.1.1",
|
|
49
|
+
"@tomjs/stylelint": "^2.1.1",
|
|
50
|
+
"@tomjs/tsconfig": "^1.2.1",
|
|
51
|
+
"@tomjs/vite-plugin-vscode": "^1.1.0",
|
|
52
|
+
"@tomjs/vscode-extension-webview": "^1.1.0",
|
|
53
|
+
"@types/node": "^18.19.3",
|
|
54
|
+
"@types/react": "^18.2.45",
|
|
55
|
+
"@types/react-dom": "^18.2.18",
|
|
56
|
+
"@types/vscode": "^1.85.0",
|
|
57
|
+
"@types/vscode-webview": "^1.57.4",
|
|
58
|
+
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
59
|
+
"cross-env": "^7.0.3",
|
|
60
|
+
"eslint": "^8.56.0",
|
|
61
|
+
"husky": "^8.0.3",
|
|
62
|
+
"lint-staged": "^15.2.0",
|
|
63
|
+
"npm-run-all": "^4.1.5",
|
|
64
|
+
"prettier": "^3.1.1",
|
|
65
|
+
"rimraf": "^5.0.5",
|
|
66
|
+
"stylelint": "^16.0.2",
|
|
67
|
+
"tsx": "^4.7.0",
|
|
68
|
+
"typescript": "~5.3.3",
|
|
69
|
+
"vite": "^5.0.10"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { VSCodeButton, VSCodeTextField } from '@vscode/webview-ui-toolkit/react';
|
|
3
|
+
import { vscode } from './utils/vscode';
|
|
4
|
+
|
|
5
|
+
import './App.css';
|
|
6
|
+
|
|
7
|
+
function App() {
|
|
8
|
+
function onPostMessage() {
|
|
9
|
+
vscode.postMessage({
|
|
10
|
+
command: 'hello',
|
|
11
|
+
text: 'Hey there partner! 🤠',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const [message, setMessage] = useState('');
|
|
16
|
+
const [state, setState] = useState('');
|
|
17
|
+
|
|
18
|
+
const onSetState = () => {
|
|
19
|
+
vscode.setState(state);
|
|
20
|
+
};
|
|
21
|
+
const onGetState = () => {
|
|
22
|
+
setState(vscode.getState() as string);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<main>
|
|
27
|
+
<h1>Hello React!</h1>
|
|
28
|
+
<VSCodeButton onClick={onPostMessage}>Test VSCode Message</VSCodeButton>
|
|
29
|
+
<div>
|
|
30
|
+
<VSCodeTextField value={message} onInput={e => setMessage(e.target.value)}>
|
|
31
|
+
Please enter a message
|
|
32
|
+
</VSCodeTextField>
|
|
33
|
+
<div>Message is: {message}</div>
|
|
34
|
+
</div>
|
|
35
|
+
<div>
|
|
36
|
+
<VSCodeTextField value={state} onInput={e => setState(e.target.value)}>
|
|
37
|
+
Please enter a state
|
|
38
|
+
</VSCodeTextField>
|
|
39
|
+
<div>State is: {state}</div>
|
|
40
|
+
<div>
|
|
41
|
+
<VSCodeButton onClick={onSetState}>setState</VSCodeButton>
|
|
42
|
+
<VSCodeButton style={{ marginLeft: '8px' }} onClick={onGetState}>
|
|
43
|
+
getState
|
|
44
|
+
</VSCodeButton>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</main>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default 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,21 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import vscode from '@tomjs/vite-plugin-vscode';
|
|
4
|
+
import react from '@vitejs/plugin-react-swc';
|
|
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: [react(), vscode()],
|
|
19
|
+
clearScreen: false,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// A launch configuration that compiles the extension and then opens it inside a new window
|
|
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
|
+
{
|
|
6
|
+
"version": "0.2.0",
|
|
7
|
+
"configurations": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Debug Extension",
|
|
10
|
+
"type": "extensionHost",
|
|
11
|
+
"request": "launch",
|
|
12
|
+
"args": [
|
|
13
|
+
"--extensionDevelopmentPath=${workspaceFolder}"
|
|
14
|
+
],
|
|
15
|
+
"outFiles": [
|
|
16
|
+
"${workspaceFolder}/dist/extension/*.js"
|
|
17
|
+
],
|
|
18
|
+
"preLaunchTask": "${defaultBuildTask}"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
2
|
+
// for the documentation about the tasks.json format
|
|
3
|
+
{
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"tasks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "npm",
|
|
8
|
+
"script": "dev",
|
|
9
|
+
"problemMatcher": {
|
|
10
|
+
"owner": "typescript",
|
|
11
|
+
"fileLocation": "relative",
|
|
12
|
+
"pattern": {
|
|
13
|
+
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
|
14
|
+
"file": 1,
|
|
15
|
+
"line": 3,
|
|
16
|
+
"column": 4,
|
|
17
|
+
"code": 5,
|
|
18
|
+
"message": 6
|
|
19
|
+
},
|
|
20
|
+
"background": {
|
|
21
|
+
"activeOnStart": true,
|
|
22
|
+
"beginsPattern": "^.*extension build start*$",
|
|
23
|
+
"endsPattern": "^.*extension (build|rebuild) success.*$"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"isBackground": true,
|
|
27
|
+
"presentation": {
|
|
28
|
+
"reveal": "never"
|
|
29
|
+
},
|
|
30
|
+
"group": {
|
|
31
|
+
"kind": "build",
|
|
32
|
+
"isDefault": true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# extension-vue
|
|
2
|
+
|
|
3
|
+
vite + extension + vue
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
- Recommend `extension` and page `src` code directory structure
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
|--extension // extension code
|
|
11
|
+
| |--index.ts
|
|
12
|
+
|--src // front-end code
|
|
13
|
+
| |--App.vue
|
|
14
|
+
| |--main.ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Zero configuration, default dist output directory
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
|--dist
|
|
21
|
+
| |--extension
|
|
22
|
+
| | |--index.js
|
|
23
|
+
| | |--index.js.map
|
|
24
|
+
| |--webview
|
|
25
|
+
| | |--index.html
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Debug
|
|
29
|
+
|
|
30
|
+
Run `Debug Extension` through `vscode` to debug. For debugging tools, refer to [Official Documentation](https://code.visualstudio.com/docs/editor/debugging)
|
|
31
|
+
|
|
32
|
+
`launch.json` is configured as follows:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"version": "0.2.0",
|
|
37
|
+
"configurations": [
|
|
38
|
+
{
|
|
39
|
+
"name": "Debug Extension",
|
|
40
|
+
"type": "extensionHost",
|
|
41
|
+
"request": "launch",
|
|
42
|
+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
|
|
43
|
+
"outFiles": ["${workspaceFolder}/dist/extension/*.js"],
|
|
44
|
+
"preLaunchTask": "${defaultBuildTask}"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`tasks.json` is configured as follows:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"version": "2.0.0",
|
|
55
|
+
"tasks": [
|
|
56
|
+
{
|
|
57
|
+
"type": "npm",
|
|
58
|
+
"script": "dev",
|
|
59
|
+
"problemMatcher": {
|
|
60
|
+
"owner": "typescript",
|
|
61
|
+
"fileLocation": "relative",
|
|
62
|
+
"pattern": {
|
|
63
|
+
"regexp": "^([a-zA-Z]\\:/?([\\w\\-]/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
|
64
|
+
"file": 1,
|
|
65
|
+
"line": 3,
|
|
66
|
+
"column": 4,
|
|
67
|
+
"code": 5,
|
|
68
|
+
"message": 6
|
|
69
|
+
},
|
|
70
|
+
"background": {
|
|
71
|
+
"activeOnStart": true,
|
|
72
|
+
"beginsPattern": "^.*extension build start*$",
|
|
73
|
+
"endsPattern": "^.*extension (build|rebuild) success.*$"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"isBackground": true,
|
|
77
|
+
"presentation": {
|
|
78
|
+
"reveal": "never"
|
|
79
|
+
},
|
|
80
|
+
"group": {
|
|
81
|
+
"kind": "build",
|
|
82
|
+
"isDefault": true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { commands, ExtensionContext } from 'vscode';
|
|
2
|
+
import { MainPanel } from './panels/MainPanel';
|
|
3
|
+
|
|
4
|
+
export function activate(context: ExtensionContext) {
|
|
5
|
+
// Create the show hello world command
|
|
6
|
+
const showHelloWorldCommand = commands.registerCommand('hello-world.showHelloWorld', async () => {
|
|
7
|
+
MainPanel.render(context.extensionUri);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Add command to the extension context
|
|
11
|
+
context.subscriptions.push(showHelloWorldCommand);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function deactivate() {}
|