Skip to content

Commit ce13a67

Browse files
authored
Merge pull request #1 from cangzhang/feat/plugin-init
feat: plugin init
2 parents e5c1242 + 9737390 commit ce13a67

23 files changed

+3631
-0
lines changed

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**@type {import('eslint').Linter.Config} */
2+
// eslint-disable-next-line no-undef
3+
module.exports = {
4+
root: true,
5+
parser: '@typescript-eslint/parser',
6+
plugins: [
7+
'@typescript-eslint',
8+
],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
rules: {
14+
'semi': [2, "always"],
15+
'@typescript-eslint/no-unused-vars': 0,
16+
'@typescript-eslint/no-explicit-any': 0,
17+
'@typescript-eslint/explicit-module-boundary-types': 0,
18+
'@typescript-eslint/no-non-null-assertion': 0,
19+
}
20+
};

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.build
3+
build
4+
web_modules/
5+
node_modules/
6+
.idea/
7+
build/
8+
out/
9+
src/typings/vscode.d.ts
10+
src/typings/vscode.proposed.d.ts

README.md

Whitespace-only changes.

package.json

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"name": "coding-hbuilderx",
3+
"description": "your extension description",
4+
"displayName": "your extension display name",
5+
"version": "0.0.0",
6+
"publisher": "your name",
7+
"engines": {
8+
"HBuilderX": "^2.7.0"
9+
},
10+
"categories": [
11+
"Other"
12+
],
13+
"main": "./out/extension",
14+
"activationEvents": [
15+
"onCommand:codingPlugin.helloWorld",
16+
"onView:codingPlugin.treeMR",
17+
"onView:codingPlugin.treeDepot",
18+
"onView:codingPlugin.webview"
19+
],
20+
"contributes": {
21+
"commands": [
22+
{
23+
"command": "codingPlugin.helloWorld",
24+
"title": "Hello World"
25+
},
26+
{
27+
"command": "codingPlugin.mrTreeItemClick",
28+
"title": "Click MR Tree Item"
29+
},
30+
{
31+
"command": "codingPlugin.depotTreeItemClick",
32+
"title": "Click Depot Tree Item"
33+
},
34+
{
35+
"command": "codingPlugin.createProjectAndDepot",
36+
"title": "Create Project and Depot"
37+
},
38+
{
39+
"command": "codingPlugin.createDepot",
40+
"title": "Create Depot"
41+
}
42+
],
43+
"menus": {
44+
"editor/context": [
45+
{
46+
"command": "codingPlugin.helloWorld",
47+
"group": "z_commands",
48+
"when": "editorTextFocus"
49+
},
50+
{
51+
"group": "z_commands"
52+
}
53+
],
54+
"view/item/context": [
55+
{
56+
"command": "codingPlugin.createDepot",
57+
"when": "viewItem == 'createDepot'"
58+
}
59+
]
60+
},
61+
"viewsContainers": {
62+
"activitybar": [
63+
{
64+
"id": "CODING-MR",
65+
"title": "CODING MR"
66+
},
67+
{
68+
"id": "CODING-DEPOT",
69+
"title": "CODING 仓库"
70+
}
71+
],
72+
"rightside": [
73+
{
74+
"id": "WebviewContainerId",
75+
"title": "WEBVIEW"
76+
}
77+
]
78+
},
79+
"views": {
80+
"CODING-MR": [
81+
{
82+
"id": "codingPlugin.treeMR",
83+
"name": "CODING MR"
84+
}
85+
],
86+
"CODING-DEPOT": [
87+
{
88+
"id": "codingPlugin.treeDepot",
89+
"name": "CODING 仓库"
90+
}
91+
],
92+
"WebviewContainerId": [
93+
{
94+
"id": "codingPlugin.webview",
95+
"title": "WEBVIEW"
96+
}
97+
]
98+
}
99+
},
100+
"extensionDependencies": [
101+
"plugin-manager"
102+
],
103+
"scripts": {
104+
"watch": "npm-run-all -p watch:*",
105+
"watch:extension": "tsc --watch -p ./src",
106+
"watch:webviews": "webpack --watch --mode development"
107+
},
108+
"dependencies": {
109+
"axios": "^0.21.0",
110+
"isomorphic-git": "^1.8.0",
111+
"querystring": "^0.2.0",
112+
"react": "^17.0.1",
113+
"react-dom": "^17.0.1"
114+
},
115+
"devDependencies": {
116+
"@types/node": "^14.14.7",
117+
"@types/react": "^16.9.56",
118+
"@types/react-dom": "^16.9.9",
119+
"@typescript-eslint/eslint-plugin": "^4.7.0",
120+
"@typescript-eslint/parser": "^4.7.0",
121+
"css-loader": "^5.0.1",
122+
"eslint": "^7.13.0",
123+
"npm-run-all": "^4.1.5",
124+
"style-loader": "^2.0.0",
125+
"ts-loader": "^8.0.11",
126+
"typescript": "^4.0.5",
127+
"webpack": "^5.4.0",
128+
"webpack-cli": "^4.2.0"
129+
}
130+
}

src/extension.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import hx from 'hbuilderx';
2+
import init from './init';
3+
import WebviewProvider from './webview';
4+
import CodingServer from './services/codingServer';
5+
import { proxyCtx } from './utils/proxy';
6+
7+
const accessToken = '1b7fca3bd7594a89b0f5e2a0250c1147';
8+
9+
async function activate(context: IContext) {
10+
// TODO: 认证,拿到用户信息
11+
12+
const webviewProvider = new WebviewProvider();
13+
const repoInfo = await CodingServer.getRepoParams();
14+
console.log('repoInfo ==> ', repoInfo);
15+
16+
if (!repoInfo) {
17+
hx.window.showWarningMessage('workspace中没有CODING的代码仓库');
18+
return;
19+
}
20+
21+
const codingServer = new CodingServer(
22+
{
23+
id: '123',
24+
user: {
25+
avatar: 'string',
26+
global_key: 'string',
27+
name: 'string',
28+
path: 'string',
29+
team: 'string'
30+
},
31+
accessToken,
32+
refreshToken: 'abc'
33+
},
34+
repoInfo || {
35+
team: 'codingcorp',
36+
project: 'mo-test',
37+
repo: 'mo-test'
38+
}
39+
);
40+
41+
let userInfo = null;
42+
if (repoInfo) {
43+
userInfo = await codingServer.getUserInfo(repoInfo.team);
44+
}
45+
46+
context.ctx = {
47+
webviewProvider,
48+
codingServer,
49+
repoInfo,
50+
userInfo
51+
};
52+
53+
proxyCtx(context);
54+
init(context);
55+
}
56+
57+
function deactivate() {
58+
console.log('plugin deactivate');
59+
}
60+
61+
export {
62+
activate,
63+
deactivate
64+
};

src/init.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import hx from 'hbuilderx';
2+
import DepotTreeDataProvider from './trees/depot';
3+
import MRTreeDataProvider from './trees/mr';
4+
import { getMRUrl } from './utils/repo';
5+
import { IDepot, IMRItem } from './typings/common';
6+
7+
export function registerCommands(context: IContext) {
8+
const { webviewProvider, repoInfo, codingServer } = context;
9+
const { team, project } = repoInfo;
10+
11+
context.subscriptions.push(hx.commands.registerCommand('codingPlugin.helloWorld', () => {
12+
hx.window.showInformationMessage('你好,这是我的第一个插件扩展。');
13+
}));
14+
15+
context.subscriptions.push(hx.commands.registerCommand('codingPlugin.mrTreeItemClick', function(param: IMRItem) {
16+
// webviewProvider.update(param[0]);
17+
hx.env.openExternal(getMRUrl(team, param));
18+
}));
19+
20+
context.subscriptions.push(hx.commands.registerCommand('codingPlugin.depotTreeItemClick', function(param: IDepot) {
21+
console.log('选中了: ', param);
22+
}));
23+
24+
context.subscriptions.push(hx.commands.registerCommand('codingPlugin.createProjectAndDepot', async function() {
25+
const project = await hx.window.showInputBox({
26+
prompt: '请输入项目名'
27+
});
28+
const depot = await hx.window.showInputBox({
29+
prompt: '请输入仓库名'
30+
});
31+
}));
32+
33+
context.subscriptions.push(hx.commands.registerCommand('codingPlugin.createDepot', async function(param: any) {
34+
const depot = await hx.window.showInputBox({
35+
prompt: '请输入仓库名'
36+
});
37+
const result = await codingServer.createDepot(team, depot, depot);
38+
// TODO: 拉取代码,更新workspace
39+
}));
40+
}
41+
42+
export function createTreeViews(context: IContext) {
43+
context.subscriptions.push(hx.window.createTreeView('codingPlugin.treeMR', {
44+
showCollapseAll: true,
45+
treeDataProvider: new MRTreeDataProvider(context)
46+
}));
47+
48+
context.subscriptions.push(hx.window.createTreeView('codingPlugin.treeDepot', {
49+
showCollapseAll: true,
50+
treeDataProvider: new DepotTreeDataProvider(context)
51+
}));
52+
}
53+
54+
export function workspaceInit() {
55+
hx.workspace.onDidChangeWorkspaceFolders(function(event: any) {
56+
if (event.added) {
57+
event.added.forEach((item: any) => console.log('新增了项目: ', item.name));
58+
}
59+
60+
if (event.removed) {
61+
event.removed.forEach((item: any) => console.log('移除了项目: ', item.name));
62+
}
63+
});
64+
}
65+
66+
export function clear(context: IContext) {
67+
context.subscriptions.forEach(({ dispose }) => dispose());
68+
}
69+
70+
export default function init(context: IContext) {
71+
registerCommands(context);
72+
createTreeViews(context);
73+
workspaceInit();
74+
}

0 commit comments

Comments
 (0)