feat(cli): add server-plugin-full

and update declaration path
pull/56/head
moonrailgun 2 years ago
parent 8be2c2dedb
commit efa3f3634c

@ -1,6 +1,6 @@
{
"name": "tailchat-cli",
"version": "1.4.0",
"version": "1.4.3",
"description": "A Command line interface of tailchat",
"bin": {
"tailchat": "./bin/cli"
@ -49,7 +49,6 @@
"pretty-ms": "7.0.1",
"react": "18.2.0",
"tailchat-server-sdk": "^0.0.12",
"tailchat-shared": "workspace:*",
"yargs": "^17.4.0"
},
"devDependencies": {
@ -59,6 +58,7 @@
"@types/node": "16.11.7",
"@types/react": "18.0.20",
"@types/yargs": "^17.0.10",
"tailchat-shared": "workspace:*",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
}

@ -39,6 +39,13 @@ export const createCommand: CommandModule = {
const answers = await basic.runPrompts();
const results = await basic.runActions(answers);
console.log('results', results);
console.log('操作变更:');
console.log(results.changes.map((change) => change.path).join('\n'));
if (results.failures.length > 0) {
console.log('操作失败:');
console.log(results.failures);
}
},
};

@ -48,7 +48,7 @@ export const declarationCommand: CommandModule = {
content = await got
.get(
'https://raw.githubusercontent.com/msgbyte/tailchat/master/web/tailchat.d.ts'
'https://raw.githubusercontent.com/msgbyte/tailchat/master/client/web/tailchat.d.ts'
)
.then((res) => res.body);

@ -82,4 +82,31 @@ module.exports = function (
},
],
});
// 服务端插件的前端模板代码
plop.setGenerator('server-plugin-full', {
description: '服务端插件的完整模板代码',
prompts: [
{
type: 'input',
name: 'name',
require: true,
message: '插件名称',
},
...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: {},
},
],
});
};

@ -0,0 +1,7 @@
const path = require('path');
module.exports = {
externalDeps: ['react'],
pluginRoot: path.resolve(__dirname, './web'),
outDir: path.resolve(__dirname, '../../public'),
};

@ -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;

@ -0,0 +1,12 @@
{
"name": "tailchat-plugin-{{pickPluginName id}}",
"version": "1.0.0",
"main": "index.js",
"author": "{{author}}",
"description": "{{desc}}",
"license": "MIT",
"private": true,
"scripts": {},
"devDependencies": {},
"dependencies": {}
}

@ -0,0 +1,20 @@
import { TcService, TcDbService } from 'tailchat-server-sdk';
import type { {{pickPluginNameUp id}}Document, {{pickPluginNameUp id}}Model } from '../models/{{pickPluginName id}}';
/**
*
*/
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;

@ -101,7 +101,6 @@ importers:
pretty-ms: 7.0.1
react: 18.2.0
tailchat-server-sdk: link:../server/packages/sdk
tailchat-shared: link:../client/shared
yargs: 17.5.1
devDependencies:
'@types/fs-extra': 9.0.13
@ -110,6 +109,7 @@ importers:
'@types/node': 16.11.7
'@types/react': 18.0.20
'@types/yargs': 17.0.12
tailchat-shared: link:../client/shared
ts-node: 10.9.1_rk33jgomelnuriwr3foeinccb4
typescript: 4.8.2

Loading…
Cancel
Save