@ddm-center/create-plugin 0.0.1 → 0.0.2
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 +5 -26
- package/bin/create-plugin.js +5 -6
- package/package.json +1 -1
- package/templates/mixed-js/package.json.tpl +3 -0
- package/templates/mixed-js/src/i18n/index.js.tpl +1 -1
- package/templates/mixed-js/src/renderer/index.js.tpl +1 -1
- package/templates/mixed-js/src/renderer/views/Settings.vue.tpl +1 -0
- package/templates/mixed-ts/README.md.tpl +0 -11
- package/templates/mixed-ts/package.json.tpl +0 -34
- package/templates/mixed-ts/src/i18n/index.ts.tpl +0 -19
- package/templates/mixed-ts/src/main/index.ts.tpl +0 -39
- package/templates/mixed-ts/src/renderer/index.ts.tpl +0 -49
- package/templates/mixed-ts/src/renderer/views/Settings.vue.tpl +0 -43
- package/templates/mixed-ts/src/types/vue.d.ts.tpl +0 -4
- package/templates/mixed-ts/tsconfig.json.tpl +0 -17
- package/templates/mixed-ts/webpack.config.js.tpl +0 -56
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
它只创建一种推荐工程形态:`renderer + main` mixed 插件。单独 renderer 或单独 main 的插件可以在生成后自行删除不需要的入口。
|
|
6
6
|
|
|
7
|
-
## 创建
|
|
7
|
+
## 创建 JavaScript 插件
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm create @ddm-center/plugin my-plugin
|
|
10
|
+
npm create @ddm-center/plugin my-plugin
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
也可以显式指定 JavaScript:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm create @ddm-center/plugin my-plugin -- --js
|
|
@@ -20,21 +20,6 @@ npm create @ddm-center/plugin my-plugin -- --js
|
|
|
20
20
|
|
|
21
21
|
## 生成目录
|
|
22
22
|
|
|
23
|
-
TypeScript 模板会生成:
|
|
24
|
-
|
|
25
|
-
```text
|
|
26
|
-
ddm-plugin-my-plugin/
|
|
27
|
-
src/main/index.ts
|
|
28
|
-
src/renderer/index.ts
|
|
29
|
-
src/renderer/views/Settings.vue
|
|
30
|
-
src/i18n/index.ts
|
|
31
|
-
package.json
|
|
32
|
-
tsconfig.json
|
|
33
|
-
webpack.config.js
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
JavaScript 模板会生成:
|
|
37
|
-
|
|
38
23
|
```text
|
|
39
24
|
ddm-plugin-my-plugin/
|
|
40
25
|
src/main/index.js
|
|
@@ -53,12 +38,6 @@ npm install
|
|
|
53
38
|
npm run build
|
|
54
39
|
```
|
|
55
40
|
|
|
56
|
-
TypeScript 模板额外提供:
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
npm run typecheck
|
|
60
|
-
```
|
|
61
|
-
|
|
62
41
|
## 入口约定
|
|
63
42
|
|
|
64
43
|
生成的插件包含三个入口:
|
|
@@ -93,8 +72,8 @@ npm run typecheck
|
|
|
93
72
|
|
|
94
73
|
## 参数
|
|
95
74
|
|
|
96
|
-
- `--ts`:创建 TypeScript mixed 插件。
|
|
97
75
|
- `--js`:创建 JavaScript mixed 插件。
|
|
98
|
-
- `--language=ts`:等同于 `--ts`。
|
|
99
76
|
- `--language=js`:等同于 `--js`。
|
|
100
77
|
- `--force`:目标目录不为空时仍然写入。
|
|
78
|
+
|
|
79
|
+
当前脚手架暂不支持创建 TypeScript 工程。
|
package/bin/create-plugin.js
CHANGED
|
@@ -46,7 +46,7 @@ function parseArgs(argv) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* 没有传插件名时,用交互问题补齐。
|
|
50
50
|
*/
|
|
51
51
|
function ask(question) {
|
|
52
52
|
const rl = readline.createInterface({
|
|
@@ -112,14 +112,13 @@ async function main() {
|
|
|
112
112
|
const args = parseArgs(process.argv.slice(2));
|
|
113
113
|
const inputName = args.name || await ask('插件名称: ');
|
|
114
114
|
const pluginName = normalizePluginName(inputName);
|
|
115
|
-
const
|
|
116
|
-
const language = (languageInput || 'ts').toLowerCase();
|
|
115
|
+
const language = (args.language || 'js').toLowerCase();
|
|
117
116
|
|
|
118
|
-
if (!['js', '
|
|
119
|
-
throw new Error('
|
|
117
|
+
if (!['js', 'javascript'].includes(language)) {
|
|
118
|
+
throw new Error('当前脚手架只支持创建 JavaScript 插件工程,暂不支持 TypeScript 模板');
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
const templateName =
|
|
121
|
+
const templateName = 'mixed-js';
|
|
123
122
|
const targetDir = path.resolve(process.cwd(), pluginName.includes('/') ? pluginName.split('/').pop() : pluginName);
|
|
124
123
|
|
|
125
124
|
if (fs.existsSync(targetDir) && !args.force && fs.readdirSync(targetDir).length > 0) {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ export default function installI18n(registrar) {
|
|
|
5
5
|
return {
|
|
6
6
|
async install() {
|
|
7
7
|
registrar.addPluginLocaleMessage('zh-CN', {
|
|
8
|
-
title: '__PLUGIN_TITLE__',
|
|
8
|
+
title: '中文语言包: __PLUGIN_TITLE__',
|
|
9
9
|
});
|
|
10
10
|
registrar.addPluginLocaleMessage('en-US', {
|
|
11
11
|
title: '__PLUGIN_TITLE__',
|
|
@@ -25,7 +25,7 @@ export default function installRenderer() {
|
|
|
25
25
|
*/
|
|
26
26
|
appView.addToolbarMenu({
|
|
27
27
|
label: '__PLUGIN_TITLE__',
|
|
28
|
-
icon: '
|
|
28
|
+
icon: 'el-icon-watermelon',
|
|
29
29
|
click: async () => {
|
|
30
30
|
const result = await helloService.sayHello('__PLUGIN_TITLE__');
|
|
31
31
|
appView.notify({
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "__PLUGIN_NAME__",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "__PLUGIN_TITLE__ plugin for Dubbo Desktop Manager.",
|
|
5
|
-
"pluginNickName": "__PLUGIN_TITLE__",
|
|
6
|
-
"main": "dist/main.js",
|
|
7
|
-
"rendererMain": "dist/renderer.js",
|
|
8
|
-
"i18nMain": "dist/i18n.js",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "webpack --mode production",
|
|
11
|
-
"dev": "webpack --mode development --watch",
|
|
12
|
-
"typecheck": "tsc --noEmit"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@ddm-center/plugin-api": "^0.0.1",
|
|
17
|
-
"css-loader": "^6.11.0",
|
|
18
|
-
"ts-loader": "^9.5.1",
|
|
19
|
-
"typescript": "^5.4.5",
|
|
20
|
-
"vue": "^2.6.14",
|
|
21
|
-
"vue-loader": "^15.11.1",
|
|
22
|
-
"vue-style-loader": "^4.1.3",
|
|
23
|
-
"vue-template-compiler": "^2.6.14",
|
|
24
|
-
"webpack": "^5.92.0",
|
|
25
|
-
"webpack-cli": "^5.1.4"
|
|
26
|
-
},
|
|
27
|
-
"pluginSandbox": {
|
|
28
|
-
"permissions": {
|
|
29
|
-
"require": {
|
|
30
|
-
"allow": []
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { I18nRegistrar, PluginInstallable } from '@ddm-center/plugin-api';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* i18n 入口用于注册当前插件自己的语言包。
|
|
5
|
-
*/
|
|
6
|
-
function installI18n(registrar: I18nRegistrar): PluginInstallable {
|
|
7
|
-
return {
|
|
8
|
-
async install() {
|
|
9
|
-
registrar.addPluginLocaleMessage('zh-CN', {
|
|
10
|
-
title: '__PLUGIN_TITLE__',
|
|
11
|
-
});
|
|
12
|
-
registrar.addPluginLocaleMessage('en-US', {
|
|
13
|
-
title: '__PLUGIN_TITLE__',
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default installI18n;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import appMain from 'appMain';
|
|
2
|
-
import type { MainEntry } from '@ddm-center/plugin-api';
|
|
3
|
-
|
|
4
|
-
interface HelloResult {
|
|
5
|
-
message: string;
|
|
6
|
-
time: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 主进程入口由 DDM 宿主加载。
|
|
11
|
-
*/
|
|
12
|
-
const entry: MainEntry = () => {
|
|
13
|
-
return {
|
|
14
|
-
async install() {
|
|
15
|
-
appMain.logger.info('__PLUGIN_TITLE__ main installed');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 暴露给渲染进程调用的服务,渲染端通过 referenceService('helloService') 获取。
|
|
19
|
-
*/
|
|
20
|
-
appMain.exportPluginService('helloService', {
|
|
21
|
-
async sayHello(name?: string): Promise<HelloResult> {
|
|
22
|
-
return {
|
|
23
|
-
message: `Hello ${name || 'DDM'} from ${appMain.pluginName}`,
|
|
24
|
-
time: new Date().toISOString(),
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 插件卸载时宿主会优先调用 uninstall,可在这里释放资源。
|
|
32
|
-
*/
|
|
33
|
-
async uninstall() {
|
|
34
|
-
appMain.logger.info('__PLUGIN_TITLE__ main uninstalled');
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default entry;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import appView from 'appView';
|
|
2
|
-
import type { RendererEntry } from '@ddm-center/plugin-api';
|
|
3
|
-
import Settings from './views/Settings.vue';
|
|
4
|
-
|
|
5
|
-
interface HelloService {
|
|
6
|
-
sayHello(name?: string): Promise<{
|
|
7
|
-
message: string;
|
|
8
|
-
time: string;
|
|
9
|
-
}>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 渲染进程入口由 DDM 宿主加载。
|
|
14
|
-
*/
|
|
15
|
-
const entry: RendererEntry = () => {
|
|
16
|
-
return {
|
|
17
|
-
async install() {
|
|
18
|
-
/**
|
|
19
|
-
* 调用主进程通过 exportPluginService 暴露的服务。
|
|
20
|
-
*/
|
|
21
|
-
const helloService = appView.referenceService<HelloService>('helloService');
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 注册一个插件设置页,Settings 组件会被宿主自动注入插件上下文。
|
|
25
|
-
*/
|
|
26
|
-
appView.addPluginSettingPage({
|
|
27
|
-
label: '__PLUGIN_TITLE__',
|
|
28
|
-
component: Settings,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 注册标题栏菜单,演示渲染进程调用主进程服务后发通知。
|
|
33
|
-
*/
|
|
34
|
-
appView.addToolbarMenu({
|
|
35
|
-
label: '__PLUGIN_TITLE__',
|
|
36
|
-
icon: 'plugin',
|
|
37
|
-
click: async () => {
|
|
38
|
-
const result = await helloService.sayHello('__PLUGIN_TITLE__');
|
|
39
|
-
appView.notify({
|
|
40
|
-
title: '__PLUGIN_TITLE__',
|
|
41
|
-
body: result.message,
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default entry;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ddm-plugin-settings">
|
|
3
|
-
<h3>{{ title }}</h3>
|
|
4
|
-
<p>{{ message }}</p>
|
|
5
|
-
<el-button size="mini" type="primary" @click="loadMessage">调用主进程服务</el-button>
|
|
6
|
-
</div>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script lang="ts">
|
|
10
|
-
import Vue from 'vue';
|
|
11
|
-
import appView from 'appView';
|
|
12
|
-
|
|
13
|
-
interface HelloService {
|
|
14
|
-
sayHello(name?: string): Promise<{
|
|
15
|
-
message: string;
|
|
16
|
-
time: string;
|
|
17
|
-
}>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const helloService = appView.referenceService<HelloService>('helloService');
|
|
21
|
-
|
|
22
|
-
export default Vue.extend({
|
|
23
|
-
name: 'PluginSettings',
|
|
24
|
-
data() {
|
|
25
|
-
return {
|
|
26
|
-
title: '__PLUGIN_TITLE__',
|
|
27
|
-
message: 'Ready',
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
methods: {
|
|
31
|
-
async loadMessage() {
|
|
32
|
-
const result = await helloService.sayHello(this.title);
|
|
33
|
-
this.message = result.message;
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
</script>
|
|
38
|
-
|
|
39
|
-
<style scoped>
|
|
40
|
-
.ddm-plugin-settings {
|
|
41
|
-
padding: 12px;
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2019",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"strict": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"moduleResolution": "node",
|
|
9
|
-
"baseUrl": ".",
|
|
10
|
-
"paths": {
|
|
11
|
-
"appMain": ["node_modules/@ddm-center/plugin-api/appMain.d.ts"],
|
|
12
|
-
"appView": ["node_modules/@ddm-center/plugin-api/appView.d.ts"]
|
|
13
|
-
},
|
|
14
|
-
"types": ["@ddm-center/plugin-api"]
|
|
15
|
-
},
|
|
16
|
-
"include": ["src/**/*"]
|
|
17
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const { VueLoaderPlugin } = require('vue-loader');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
target: 'electron-renderer',
|
|
6
|
-
entry: {
|
|
7
|
-
main: './src/main/index.ts',
|
|
8
|
-
renderer: './src/renderer/index.ts',
|
|
9
|
-
i18n: './src/i18n/index.ts',
|
|
10
|
-
},
|
|
11
|
-
output: {
|
|
12
|
-
path: path.resolve(__dirname, 'dist'),
|
|
13
|
-
filename: '[name].js',
|
|
14
|
-
library: {
|
|
15
|
-
type: 'commonjs2',
|
|
16
|
-
export: 'default',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
resolve: {
|
|
20
|
-
extensions: ['.ts', '.js', '.vue', '.json'],
|
|
21
|
-
alias: {
|
|
22
|
-
'@': path.resolve(__dirname, 'src'),
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
externals: {
|
|
26
|
-
appMain: 'commonjs appMain',
|
|
27
|
-
appView: 'commonjs appView',
|
|
28
|
-
axios: 'commonjs axios',
|
|
29
|
-
constant: 'commonjs constant',
|
|
30
|
-
logger: 'commonjs logger',
|
|
31
|
-
appConfig: 'commonjs appConfig',
|
|
32
|
-
},
|
|
33
|
-
module: {
|
|
34
|
-
rules: [
|
|
35
|
-
{
|
|
36
|
-
test: /\.vue$/,
|
|
37
|
-
loader: 'vue-loader',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
test: /\.ts$/,
|
|
41
|
-
loader: 'ts-loader',
|
|
42
|
-
options: {
|
|
43
|
-
appendTsSuffixTo: [/\.vue$/],
|
|
44
|
-
},
|
|
45
|
-
exclude: /node_modules/,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
test: /\.css$/,
|
|
49
|
-
use: ['vue-style-loader', 'css-loader'],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
plugins: [
|
|
54
|
-
new VueLoaderPlugin(),
|
|
55
|
-
],
|
|
56
|
-
};
|