优化
This commit is contained in:
9
apps/cli/templates/client-plugin/{{id}}/manifest.json
Normal file
9
apps/cli/templates/client-plugin/{{id}}/manifest.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"label": "{{name}}",
|
||||
"name": "{{id}}",
|
||||
"url": "/plugins/{{id}}/index.js",
|
||||
"version": "0.0.0",
|
||||
"author": "{{author}}",
|
||||
"description": "{{desc}}",
|
||||
"requireRestart": true
|
||||
}
|
||||
16
apps/cli/templates/client-plugin/{{id}}/package.json
Normal file
16
apps/cli/templates/client-plugin/{{id}}/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@plugins/{{id}}",
|
||||
"main": "src/index.tsx",
|
||||
"version": "0.0.0",
|
||||
"description": "{{desc}}",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"sync:declaration": "tailchat declaration github"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/styled-components": "^5.1.26",
|
||||
"react": "18.2.0",
|
||||
"styled-components": "^5.3.6"
|
||||
}
|
||||
}
|
||||
4
apps/cli/templates/client-plugin/{{id}}/src/index.tsx
Normal file
4
apps/cli/templates/client-plugin/{{id}}/src/index.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
const PLUGIN_ID = '{{id}}';
|
||||
const PLUGIN_NAME = '{{name}}';
|
||||
|
||||
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||
8
apps/cli/templates/client-plugin/{{id}}/src/translate.ts
Normal file
8
apps/cli/templates/client-plugin/{{id}}/src/translate.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { localTrans } from '@capital/common';
|
||||
|
||||
export const Translate = {
|
||||
name: localTrans({
|
||||
'zh-CN': '{{name}}',
|
||||
'en-US': '{{name}}',
|
||||
}),
|
||||
};
|
||||
7
apps/cli/templates/client-plugin/{{id}}/tsconfig.json
Normal file
7
apps/cli/templates/client-plugin/{{id}}/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"importsNotUsedAsValues": "error"
|
||||
}
|
||||
}
|
||||
2
apps/cli/templates/client-plugin/{{id}}/types/tailchat.d.ts
vendored
Normal file
2
apps/cli/templates/client-plugin/{{id}}/types/tailchat.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare module '@capital/common';
|
||||
declare module '@capital/component';
|
||||
132
apps/cli/templates/plopfile.js
Normal file
132
apps/cli/templates/plopfile.js
Normal file
@@ -0,0 +1,132 @@
|
||||
const path = require('path');
|
||||
const _ = require('lodash')
|
||||
|
||||
function pickPluginName(text) {
|
||||
const [_1, _2, ...others] = text.split('.');
|
||||
return others.join('-');
|
||||
}
|
||||
function upperFirst(text) {
|
||||
return _.upperFirst(_.camelCase(text));
|
||||
}
|
||||
|
||||
module.exports = function (
|
||||
/** @type {import('plop').NodePlopAPI} */
|
||||
plop
|
||||
) {
|
||||
plop.setHelper('pickPluginName', pickPluginName);
|
||||
plop.setHelper('pickPluginNameUp', (text) => {
|
||||
return upperFirst(pickPluginName(text));
|
||||
});
|
||||
|
||||
const namePrompts = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
require: true,
|
||||
message: 'Plugin Name',
|
||||
}
|
||||
]
|
||||
|
||||
const serverPrompts = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'id',
|
||||
require: true,
|
||||
default: 'com.msgbyte.example',
|
||||
message: 'Plugin unique id, a unique string in reverse domain name format',
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'author',
|
||||
message: 'Plugin Author',
|
||||
default: 'anonymous',
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'desc',
|
||||
message: 'Plugin description',
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
|
||||
// 服务端插件的前端模板代码
|
||||
plop.setGenerator('client-plugin', {
|
||||
description: 'Pure frontend plugin template',
|
||||
prompts: [
|
||||
...namePrompts,
|
||||
...serverPrompts,
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: path.resolve(process.cwd(), './plugins'),
|
||||
base: './client-plugin',
|
||||
templateFiles: [
|
||||
'./client-plugin/**/*',
|
||||
],
|
||||
skipIfExists: true,
|
||||
globOptions: {},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 服务端插件的前端模板代码
|
||||
plop.setGenerator('server-plugin', {
|
||||
description: 'Pure backtend plugin template',
|
||||
prompts: serverPrompts,
|
||||
actions: [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: path.resolve(process.cwd(), './plugins'),
|
||||
base: './server-plugin',
|
||||
templateFiles: ['./server-plugin/**/*'],
|
||||
skipIfExists: true,
|
||||
globOptions: {},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 服务端插件的前端模板代码
|
||||
plop.setGenerator('server-plugin-web', {
|
||||
description: 'web plugin in backtend plugin template',
|
||||
prompts: [
|
||||
...namePrompts,
|
||||
...serverPrompts,
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: path.resolve(process.cwd(), './plugins'),
|
||||
base: './server-plugin-web',
|
||||
templateFiles: [
|
||||
'./server-plugin-web/**/*',
|
||||
'./server-plugin-web/*/.ministarrc.js',
|
||||
],
|
||||
skipIfExists: true,
|
||||
globOptions: {},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 服务端插件的前端模板代码
|
||||
plop.setGenerator('server-plugin-full', {
|
||||
description: 'Full backend plugin template',
|
||||
prompts: [
|
||||
...namePrompts,
|
||||
...serverPrompts,
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: path.resolve(process.cwd(), './plugins'),
|
||||
base: './server-plugin-full',
|
||||
templateFiles: [
|
||||
'./server-plugin-full/**/*',
|
||||
'./server-plugin-full/*/.ministarrc.js',
|
||||
],
|
||||
skipIfExists: true,
|
||||
globOptions: {},
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
17
apps/cli/templates/server-plugin-full/{{id}}/.ministarrc.js
Normal file
17
apps/cli/templates/server-plugin-full/{{id}}/.ministarrc.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const path = require('path');
|
||||
|
||||
const pluginRoot = path.resolve(__dirname, './web');
|
||||
const outDir = path.resolve(__dirname, '../../public');
|
||||
|
||||
module.exports = {
|
||||
externalDeps: [
|
||||
'react',
|
||||
'react-router',
|
||||
'axios',
|
||||
'styled-components',
|
||||
'zustand',
|
||||
'zustand/middleware/immer'
|
||||
],
|
||||
pluginRoot,
|
||||
outDir,
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import { db } from 'tailchat-server-sdk';
|
||||
const { getModelForClass, prop, modelOptions, TimeStamps } = db;
|
||||
|
||||
@modelOptions({
|
||||
options: {
|
||||
customName: 'p_{{pickPluginName id}}',
|
||||
},
|
||||
})
|
||||
export class {{pickPluginNameUp id}} extends TimeStamps implements db.Base {
|
||||
_id: db.Types.ObjectId;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export type {{pickPluginNameUp id}}Document = db.DocumentType<{{pickPluginNameUp id}}>;
|
||||
|
||||
const model = getModelForClass({{pickPluginNameUp id}});
|
||||
|
||||
export type {{pickPluginNameUp id}}Model = typeof model;
|
||||
|
||||
export default model;
|
||||
20
apps/cli/templates/server-plugin-full/{{id}}/package.json
Normal file
20
apps/cli/templates/server-plugin-full/{{id}}/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "tailchat-plugin-{{pickPluginName id}}",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"author": "{{author}}",
|
||||
"description": "{{desc}}",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build:web": "ministar buildPlugin all",
|
||||
"build:web:watch": "ministar watchPlugin all"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "18.0.20",
|
||||
"mini-star": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"tailchat-server-sdk": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { TcService, TcDbService } from 'tailchat-server-sdk';
|
||||
import type { {{pickPluginNameUp id}}Document, {{pickPluginNameUp id}}Model } from '../models/{{pickPluginName id}}';
|
||||
|
||||
/**
|
||||
* {{name}}
|
||||
*
|
||||
* {{desc}}
|
||||
*/
|
||||
interface {{pickPluginNameUp id}}Service
|
||||
extends TcService,
|
||||
TcDbService<{{pickPluginNameUp id}}Document, {{pickPluginNameUp id}}Model> {}
|
||||
class {{pickPluginNameUp id}}Service extends TcService {
|
||||
get serviceName() {
|
||||
return 'plugin:{{id}}';
|
||||
}
|
||||
|
||||
onInit() {
|
||||
this.registerLocalDb(require('../models/{{pickPluginName id}}').default);
|
||||
}
|
||||
}
|
||||
|
||||
export default {{pickPluginNameUp id}}Service;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"label": "{{name}}",
|
||||
"name": "{{id}}",
|
||||
"url": "{BACKEND}/plugins/{{id}}/index.js",
|
||||
"version": "0.0.0",
|
||||
"author": "{{author}}",
|
||||
"description": "{{desc}}",
|
||||
"requireRestart": true
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@plugins/{{id}}",
|
||||
"main": "src/index.tsx",
|
||||
"version": "0.0.0",
|
||||
"description": "{{desc}}",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"sync:declaration": "tailchat declaration github"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/styled-components": "^5.1.26",
|
||||
"react": "18.2.0",
|
||||
"styled-components": "^5.3.6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
const PLUGIN_ID = '{{id}}';
|
||||
const PLUGIN_NAME = '{{name}}';
|
||||
|
||||
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"importsNotUsedAsValues": "error"
|
||||
}
|
||||
}
|
||||
2
apps/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts
vendored
Normal file
2
apps/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare module '@capital/common';
|
||||
declare module '@capital/component';
|
||||
17
apps/cli/templates/server-plugin-web/{{id}}/.ministarrc.js
Normal file
17
apps/cli/templates/server-plugin-web/{{id}}/.ministarrc.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const path = require('path');
|
||||
|
||||
const pluginRoot = path.resolve(__dirname, './web');
|
||||
const outDir = path.resolve(__dirname, '../../public');
|
||||
|
||||
module.exports = {
|
||||
externalDeps: [
|
||||
'react',
|
||||
'react-router',
|
||||
'axios',
|
||||
'styled-components',
|
||||
'zustand',
|
||||
'zustand/middleware/immer'
|
||||
],
|
||||
pluginRoot,
|
||||
outDir,
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"label": "{{name}}",
|
||||
"name": "{{id}}",
|
||||
"url": "{BACKEND}/plugins/{{id}}/index.js",
|
||||
"version": "0.0.0",
|
||||
"author": "{{author}}",
|
||||
"description": "{{desc}}",
|
||||
"requireRestart": true
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@plugins/{{id}}",
|
||||
"main": "src/index.tsx",
|
||||
"version": "0.0.0",
|
||||
"description": "{{desc}}",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"sync:declaration": "tailchat declaration github"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/styled-components": "^5.1.26",
|
||||
"react": "18.2.0",
|
||||
"styled-components": "^5.3.6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
const PLUGIN_ID = '{{id}}';
|
||||
const PLUGIN_NAME = '{{name}}';
|
||||
|
||||
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||
@@ -0,0 +1,8 @@
|
||||
import { localTrans } from '@capital/common';
|
||||
|
||||
export const Translate = {
|
||||
name: localTrans({
|
||||
'zh-CN': '{{name}}',
|
||||
'en-US': '{{name}}',
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"importsNotUsedAsValues": "error"
|
||||
}
|
||||
}
|
||||
2
apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts
vendored
Normal file
2
apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare module '@capital/common';
|
||||
declare module '@capital/component';
|
||||
@@ -0,0 +1,20 @@
|
||||
import { db } from 'tailchat-server-sdk';
|
||||
const { getModelForClass, prop, modelOptions, TimeStamps } = db;
|
||||
|
||||
@modelOptions({
|
||||
options: {
|
||||
customName: 'p_{{pickPluginName id}}',
|
||||
},
|
||||
})
|
||||
export class {{pickPluginNameUp id}} extends TimeStamps implements db.Base {
|
||||
_id: db.Types.ObjectId;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export type {{pickPluginNameUp id}}Document = db.DocumentType<{{pickPluginNameUp id}}>;
|
||||
|
||||
const model = getModelForClass({{pickPluginNameUp id}});
|
||||
|
||||
export type {{pickPluginNameUp id}}Model = typeof model;
|
||||
|
||||
export default model;
|
||||
14
apps/cli/templates/server-plugin/{{id}}/package.json
Normal file
14
apps/cli/templates/server-plugin/{{id}}/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "tailchat-plugin-{{pickPluginName id}}",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"author": "{{author}}",
|
||||
"description": "{{desc}}",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {},
|
||||
"devDependencies": {},
|
||||
"dependencies": {
|
||||
"tailchat-server-sdk": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { TcService, TcDbService } from 'tailchat-server-sdk';
|
||||
import type { {{pickPluginNameUp id}}Document, {{pickPluginNameUp id}}Model } from '../models/{{pickPluginName id}}';
|
||||
|
||||
/**
|
||||
* {{desc}}
|
||||
*/
|
||||
interface {{pickPluginNameUp id}}Service
|
||||
extends TcService,
|
||||
TcDbService<{{pickPluginNameUp id}}Document, {{pickPluginNameUp id}}Model> {}
|
||||
class {{pickPluginNameUp id}}Service extends TcService {
|
||||
get serviceName() {
|
||||
return 'plugin:{{id}}';
|
||||
}
|
||||
|
||||
onInit() {
|
||||
this.registerLocalDb(require('../models/{{pickPluginName id}}').default);
|
||||
}
|
||||
}
|
||||
|
||||
export default {{pickPluginNameUp id}}Service;
|
||||
Reference in New Issue
Block a user